Skip to content

Commit d2ba565

Browse files
committed
Address review comments
1 parent bd128f7 commit d2ba565

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
@@ -4546,21 +4546,17 @@ static bool shouldUnrollLoopWithInstruction(Instruction &I,
45464546
}
45474547

45484548
// This function returns true if the loop:
4549-
// 1. Contains only those instructions that should be unrolled,
4550-
// 2. Has a valid cost,
4551-
// 3. Has a cost within the supplied budget.
4549+
// 1. Has a valid cost, and
4550+
// 2. Has a cost within the supplied budget.
45524551
// Otherwise it returns false.
4553-
static bool canUnrollLoopWithinBudget(Loop *L, AArch64TTIImpl &TTI,
4554-
InstructionCost Budget,
4555-
unsigned *FinalSize) {
4552+
static bool isLoopSizeWithinBudget(Loop *L, AArch64TTIImpl &TTI,
4553+
InstructionCost Budget,
4554+
unsigned *FinalSize) {
45564555
// Estimate the size of the loop.
45574556
InstructionCost LoopCost = 0;
45584557

45594558
for (auto *BB : L->getBlocks()) {
45604559
for (auto &I : *BB) {
4561-
if (!shouldUnrollLoopWithInstruction(I, TTI))
4562-
return false;
4563-
45644560
SmallVector<const Value *, 4> Operands(I.operand_values());
45654561
InstructionCost Cost =
45664562
TTI.getInstructionCost(&I, Operands, TTI::TCK_CodeSize);
@@ -4595,11 +4591,8 @@ static bool shouldUnrollMultiExitLoop(Loop *L, ScalarEvolution &SE,
45954591
if (MaxTC > 0 && MaxTC <= 32)
45964592
return false;
45974593

4598-
if (findStringMetadataForLoop(L, "llvm.loop.isvectorized"))
4599-
return false;
4600-
4601-
// Estimate the size of the loop.
4602-
if (!canUnrollLoopWithinBudget(L, TTI, 5, nullptr))
4594+
// Make sure the loop size is <= 5.
4595+
if (!isLoopSizeWithinBudget(L, TTI, 5, nullptr))
46034596
return false;
46044597

46054598
// Small search loops with multiple exits can be highly beneficial to unroll.
@@ -4631,7 +4624,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
46314624
if (!L->isInnermost() || L->getNumBlocks() > 8)
46324625
return;
46334626

4634-
// This is handled by common code.
4627+
// Loops with multiple exits are handled by common code.
46354628
if (!L->getExitBlock())
46364629
return;
46374630

@@ -4656,7 +4649,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
46564649
if (Header == L->getLoopLatch()) {
46574650
// Estimate the size of the loop.
46584651
unsigned Size;
4659-
if (!canUnrollLoopWithinBudget(L, TTI, 8, &Size))
4652+
if (!isLoopSizeWithinBudget(L, TTI, 8, &Size))
46604653
return;
46614654

46624655
SmallPtrSet<Value *, 8> LoadedValues;
@@ -4753,6 +4746,16 @@ void AArch64TTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
47534746
// Disable partial & runtime unrolling on -Os.
47544747
UP.PartialOptSizeThreshold = 0;
47554748

4749+
// Scan the loop: don't unroll loops with calls as this could prevent
4750+
// inlining. Don't unroll vector loops either, as they don't benefit much from
4751+
// unrolling.
4752+
for (auto *BB : L->getBlocks()) {
4753+
for (auto &I : *BB) {
4754+
if (!shouldUnrollLoopWithInstruction(I, *this))
4755+
return;
4756+
}
4757+
}
4758+
47564759
// Apply subtarget-specific unrolling preferences.
47574760
switch (ST->getProcFamily()) {
47584761
case AArch64Subtarget::AppleA14:
@@ -4782,16 +4785,6 @@ void AArch64TTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
47824785
return;
47834786
}
47844787

4785-
// Scan the loop: don't unroll loops with calls as this could prevent
4786-
// inlining. Don't unroll vector loops either, as they don't benefit much from
4787-
// unrolling.
4788-
for (auto *BB : L->getBlocks()) {
4789-
for (auto &I : *BB) {
4790-
if (!shouldUnrollLoopWithInstruction(I, *this))
4791-
return;
4792-
}
4793-
}
4794-
47954788
// Enable runtime unrolling for in-order models
47964789
// If mcpu is omitted, getProcFamily() returns AArch64Subtarget::Others, so by
47974790
// checking for that case, we can ensure that the default behaviour is

0 commit comments

Comments
 (0)