Skip to content

Commit c5e7906

Browse files
committed
Address review comments
1 parent fb755c0 commit c5e7906

File tree

2 files changed

+344
-6
lines changed

2 files changed

+344
-6
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4397,8 +4397,14 @@ static bool shouldUnrollLoopWithInstruction(Instruction &I,
43974397
return true;
43984398
}
43994399

4400-
static unsigned getLoopSize(Loop *L, AArch64TTIImpl &TTI,
4401-
InstructionCost Budget) {
4400+
// This function returns true if the loop:
4401+
// 1. Contains only those instructions that should be unrolled,
4402+
// 2. Has a valid cost,
4403+
// 3. Has a cost within the supplied budget.
4404+
// Otherwise it returns false.
4405+
static bool isLoopSizeWithinBudget(Loop *L, AArch64TTIImpl &TTI,
4406+
InstructionCost Budget,
4407+
unsigned *FinalSize) {
44024408
// Estimate the size of the loop.
44034409
InstructionCost LoopCost = 0;
44044410

@@ -4424,7 +4430,9 @@ static unsigned getLoopSize(Loop *L, AArch64TTIImpl &TTI,
44244430
}
44254431
}
44264432

4427-
return *LoopCost.getValue();
4433+
if (FinalSize)
4434+
*FinalSize = *LoopCost.getValue();
4435+
return true;
44284436
}
44294437

44304438
static bool shouldUnrollMultiExitLoop(Loop *L, ScalarEvolution &SE,
@@ -4443,7 +4451,7 @@ static bool shouldUnrollMultiExitLoop(Loop *L, ScalarEvolution &SE,
44434451
return false;
44444452

44454453
// Estimate the size of the loop.
4446-
if (!getLoopSize(L, TTI, 5))
4454+
if (!isLoopSizeWithinBudget(L, TTI, 5, nullptr))
44474455
return false;
44484456

44494457
// Small search loops with multiple exits can be highly beneficial to unroll.
@@ -4485,6 +4493,9 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
44854493
SE.getSmallConstantMaxTripCount(L) <= 32))
44864494
return;
44874495

4496+
if (findStringMetadataForLoop(L, "llvm.loop.isvectorized"))
4497+
return;
4498+
44884499
if (SE.getSymbolicMaxBackedgeTakenCount(L) != SE.getBackedgeTakenCount(L))
44894500
return;
44904501

@@ -4496,8 +4507,8 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
44964507
BasicBlock *Header = L->getHeader();
44974508
if (Header == L->getLoopLatch()) {
44984509
// Estimate the size of the loop.
4499-
unsigned Size = getLoopSize(L, TTI, 8);
4500-
if (!Size)
4510+
unsigned Size;
4511+
if (!isLoopSizeWithinBudget(L, TTI, 8, &Size))
45014512
return;
45024513

45034514
SmallPtrSet<Value *, 8> LoadedValues;
@@ -4609,6 +4620,11 @@ void AArch64TTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
46094620
if (EnableFalkorHWPFUnrollFix)
46104621
getFalkorUnrollingPreferences(L, SE, UP);
46114622
break;
4623+
case AArch64Subtarget::NeoverseV1:
4624+
case AArch64Subtarget::NeoverseV2:
4625+
if (!SmallMultiExitLoopUF.getNumOccurrences())
4626+
SmallMultiExitLoopUnrollFactor = 4;
4627+
break;
46124628
default:
46134629
break;
46144630
}

0 commit comments

Comments
 (0)