@@ -4546,21 +4546,17 @@ static bool shouldUnrollLoopWithInstruction(Instruction &I,
4546
4546
}
4547
4547
4548
4548
// 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.
4552
4551
// 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) {
4556
4555
// Estimate the size of the loop.
4557
4556
InstructionCost LoopCost = 0 ;
4558
4557
4559
4558
for (auto *BB : L->getBlocks ()) {
4560
4559
for (auto &I : *BB) {
4561
- if (!shouldUnrollLoopWithInstruction (I, TTI))
4562
- return false ;
4563
-
4564
4560
SmallVector<const Value *, 4 > Operands (I.operand_values ());
4565
4561
InstructionCost Cost =
4566
4562
TTI.getInstructionCost (&I, Operands, TTI::TCK_CodeSize);
@@ -4595,11 +4591,8 @@ static bool shouldUnrollMultiExitLoop(Loop *L, ScalarEvolution &SE,
4595
4591
if (MaxTC > 0 && MaxTC <= 32 )
4596
4592
return false ;
4597
4593
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 ))
4603
4596
return false ;
4604
4597
4605
4598
// Small search loops with multiple exits can be highly beneficial to unroll.
@@ -4631,7 +4624,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
4631
4624
if (!L->isInnermost () || L->getNumBlocks () > 8 )
4632
4625
return ;
4633
4626
4634
- // This is handled by common code.
4627
+ // Loops with multiple exits are handled by common code.
4635
4628
if (!L->getExitBlock ())
4636
4629
return ;
4637
4630
@@ -4656,7 +4649,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
4656
4649
if (Header == L->getLoopLatch ()) {
4657
4650
// Estimate the size of the loop.
4658
4651
unsigned Size;
4659
- if (!canUnrollLoopWithinBudget (L, TTI, 8 , &Size))
4652
+ if (!isLoopSizeWithinBudget (L, TTI, 8 , &Size))
4660
4653
return ;
4661
4654
4662
4655
SmallPtrSet<Value *, 8 > LoadedValues;
@@ -4753,6 +4746,16 @@ void AArch64TTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
4753
4746
// Disable partial & runtime unrolling on -Os.
4754
4747
UP.PartialOptSizeThreshold = 0 ;
4755
4748
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
+
4756
4759
// Apply subtarget-specific unrolling preferences.
4757
4760
switch (ST->getProcFamily ()) {
4758
4761
case AArch64Subtarget::AppleA14:
@@ -4782,16 +4785,6 @@ void AArch64TTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
4782
4785
return ;
4783
4786
}
4784
4787
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
-
4795
4788
// Enable runtime unrolling for in-order models
4796
4789
// If mcpu is omitted, getProcFamily() returns AArch64Subtarget::Others, so by
4797
4790
// checking for that case, we can ensure that the default behaviour is
0 commit comments