@@ -4397,8 +4397,14 @@ static bool shouldUnrollLoopWithInstruction(Instruction &I,
4397
4397
return true ;
4398
4398
}
4399
4399
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) {
4402
4408
// Estimate the size of the loop.
4403
4409
InstructionCost LoopCost = 0 ;
4404
4410
@@ -4424,7 +4430,9 @@ static unsigned getLoopSize(Loop *L, AArch64TTIImpl &TTI,
4424
4430
}
4425
4431
}
4426
4432
4427
- return *LoopCost.getValue ();
4433
+ if (FinalSize)
4434
+ *FinalSize = *LoopCost.getValue ();
4435
+ return true ;
4428
4436
}
4429
4437
4430
4438
static bool shouldUnrollMultiExitLoop (Loop *L, ScalarEvolution &SE,
@@ -4443,7 +4451,7 @@ static bool shouldUnrollMultiExitLoop(Loop *L, ScalarEvolution &SE,
4443
4451
return false ;
4444
4452
4445
4453
// Estimate the size of the loop.
4446
- if (!getLoopSize (L, TTI, 5 ))
4454
+ if (!isLoopSizeWithinBudget (L, TTI, 5 , nullptr ))
4447
4455
return false ;
4448
4456
4449
4457
// Small search loops with multiple exits can be highly beneficial to unroll.
@@ -4485,6 +4493,9 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
4485
4493
SE.getSmallConstantMaxTripCount (L) <= 32 ))
4486
4494
return ;
4487
4495
4496
+ if (findStringMetadataForLoop (L, " llvm.loop.isvectorized" ))
4497
+ return ;
4498
+
4488
4499
if (SE.getSymbolicMaxBackedgeTakenCount (L) != SE.getBackedgeTakenCount (L))
4489
4500
return ;
4490
4501
@@ -4496,8 +4507,8 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
4496
4507
BasicBlock *Header = L->getHeader ();
4497
4508
if (Header == L->getLoopLatch ()) {
4498
4509
// 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) )
4501
4512
return ;
4502
4513
4503
4514
SmallPtrSet<Value *, 8 > LoadedValues;
@@ -4609,6 +4620,11 @@ void AArch64TTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
4609
4620
if (EnableFalkorHWPFUnrollFix)
4610
4621
getFalkorUnrollingPreferences (L, SE, UP);
4611
4622
break ;
4623
+ case AArch64Subtarget::NeoverseV1:
4624
+ case AArch64Subtarget::NeoverseV2:
4625
+ if (!SmallMultiExitLoopUF.getNumOccurrences ())
4626
+ SmallMultiExitLoopUnrollFactor = 4 ;
4627
+ break ;
4612
4628
default :
4613
4629
break ;
4614
4630
}
0 commit comments