Skip to content

Commit 4671915

Browse files
committed
Address review comments
1 parent d1e9466 commit 4671915

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4586,21 +4586,17 @@ static bool shouldUnrollLoopWithInstruction(Instruction &I,
45864586
}
45874587

45884588
// This function returns true if the loop:
4589-
// 1. Contains only those instructions that should be unrolled,
4590-
// 2. Has a valid cost,
4591-
// 3. Has a cost within the supplied budget.
4589+
// 1. Has a valid cost, and
4590+
// 2. Has a cost within the supplied budget.
45924591
// Otherwise it returns false.
4593-
static bool canUnrollLoopWithinBudget(Loop *L, AArch64TTIImpl &TTI,
4594-
InstructionCost Budget,
4595-
unsigned *FinalSize) {
4592+
static bool isLoopSizeWithinBudget(Loop *L, AArch64TTIImpl &TTI,
4593+
InstructionCost Budget,
4594+
unsigned *FinalSize) {
45964595
// Estimate the size of the loop.
45974596
InstructionCost LoopCost = 0;
45984597

45994598
for (auto *BB : L->getBlocks()) {
46004599
for (auto &I : *BB) {
4601-
if (!shouldUnrollLoopWithInstruction(I, TTI))
4602-
return false;
4603-
46044600
SmallVector<const Value *, 4> Operands(I.operand_values());
46054601
InstructionCost Cost =
46064602
TTI.getInstructionCost(&I, Operands, TTI::TCK_CodeSize);
@@ -4635,11 +4631,8 @@ static bool shouldUnrollMultiExitLoop(Loop *L, ScalarEvolution &SE,
46354631
if (MaxTC > 0 && MaxTC <= 32)
46364632
return false;
46374633

4638-
if (findStringMetadataForLoop(L, "llvm.loop.isvectorized"))
4639-
return false;
4640-
4641-
// Estimate the size of the loop.
4642-
if (!canUnrollLoopWithinBudget(L, TTI, 5, nullptr))
4634+
// Make sure the loop size is <= 5.
4635+
if (!isLoopSizeWithinBudget(L, TTI, 5, nullptr))
46434636
return false;
46444637

46454638
// Small search loops with multiple exits can be highly beneficial to unroll.
@@ -4671,7 +4664,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
46714664
if (!L->isInnermost() || L->getNumBlocks() > 8)
46724665
return;
46734666

4674-
// This is handled by common code.
4667+
// Loops with multiple exits are handled by common code.
46754668
if (!L->getExitBlock())
46764669
return;
46774670

@@ -4696,7 +4689,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
46964689
if (Header == L->getLoopLatch()) {
46974690
// Estimate the size of the loop.
46984691
unsigned Size;
4699-
if (!canUnrollLoopWithinBudget(L, TTI, 8, &Size))
4692+
if (!isLoopSizeWithinBudget(L, TTI, 8, &Size))
47004693
return;
47014694

47024695
SmallPtrSet<Value *, 8> LoadedValues;
@@ -4793,6 +4786,16 @@ void AArch64TTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
47934786
// Disable partial & runtime unrolling on -Os.
47944787
UP.PartialOptSizeThreshold = 0;
47954788

4789+
// Scan the loop: don't unroll loops with calls as this could prevent
4790+
// inlining. Don't unroll vector loops either, as they don't benefit much from
4791+
// unrolling.
4792+
for (auto *BB : L->getBlocks()) {
4793+
for (auto &I : *BB) {
4794+
if (!shouldUnrollLoopWithInstruction(I, *this))
4795+
return;
4796+
}
4797+
}
4798+
47964799
// Apply subtarget-specific unrolling preferences.
47974800
switch (ST->getProcFamily()) {
47984801
case AArch64Subtarget::AppleA14:
@@ -4822,16 +4825,6 @@ void AArch64TTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
48224825
return;
48234826
}
48244827

4825-
// Scan the loop: don't unroll loops with calls as this could prevent
4826-
// inlining. Don't unroll vector loops either, as they don't benefit much from
4827-
// unrolling.
4828-
for (auto *BB : L->getBlocks()) {
4829-
for (auto &I : *BB) {
4830-
if (!shouldUnrollLoopWithInstruction(I, *this))
4831-
return;
4832-
}
4833-
}
4834-
48354828
// Enable runtime unrolling for in-order models
48364829
// If mcpu is omitted, getProcFamily() returns AArch64Subtarget::Others, so by
48374830
// checking for that case, we can ensure that the default behaviour is

0 commit comments

Comments
 (0)