Skip to content

Commit db6a3d6

Browse files
committed
!fixup Add AddAdditionalAccumulators TTI flag
1 parent e682785 commit db6a3d6

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,8 @@ class TargetTransformInfo {
638638
/// Fall back to the generic logic to determine whether multi-exit unrolling
639639
/// is profitable if set to false.
640640
bool RuntimeUnrollMultiExit;
641+
/// Allow unrolling to add parallel reduction phis.
642+
bool AddAdditionalAccumulators;
641643
};
642644

643645
/// Get target-customized preferences for the generic loop unrolling

llvm/include/llvm/Transforms/Utils/UnrollLoop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct UnrollLoopOptions {
7979
const Instruction *Heart = nullptr;
8080
unsigned SCEVExpansionBudget;
8181
bool RuntimeUnrollMultiExit = false;
82+
bool AddAdditionalAccumulators = false;
8283
};
8384

8485
LLVM_ABI LoopUnrollResult UnrollLoop(Loop *L, UnrollLoopOptions ULO,

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4984,6 +4984,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
49844984
SE.getSmallConstantTripMultiple(L, L->getExitingBlock()) % 2 == 0) {
49854985
UP.Partial = true;
49864986
UP.MaxCount = 4;
4987+
UP.AddAdditionalAccumulators = true;
49874988
}
49884989

49894990
const SCEV *BTC = SE.getSymbolicMaxBackedgeTakenCount(L);
@@ -5004,6 +5005,7 @@ getAppleRuntimeUnrollPreferences(Loop *L, ScalarEvolution &SE,
50045005
if (HasParellelizableReductions) {
50055006
UP.Runtime = true;
50065007
UP.DefaultUnrollRuntimeCount = 4;
5008+
UP.AddAdditionalAccumulators = true;
50075009
}
50085010

50095011
// Try to unroll small loops, of few-blocks with low budget, if they have

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
220220
UP.MaxIterationsCountToAnalyze = UnrollMaxIterationsCountToAnalyze;
221221
UP.SCEVExpansionBudget = SCEVCheapExpansionBudget;
222222
UP.RuntimeUnrollMultiExit = false;
223+
UP.AddAdditionalAccumulators = false;
223224

224225
// Override with any target specific settings
225226
TTI.getUnrollingPreferences(L, SE, UP, &ORE);
@@ -1354,6 +1355,7 @@ tryToUnrollLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
13541355
ULO.Heart = getLoopConvergenceHeart(L);
13551356
ULO.SCEVExpansionBudget = UP.SCEVExpansionBudget;
13561357
ULO.RuntimeUnrollMultiExit = UP.RuntimeUnrollMultiExit;
1358+
ULO.AddAdditionalAccumulators = UP.AddAdditionalAccumulators;
13571359
LoopUnrollResult UnrollResult = UnrollLoop(
13581360
L, ULO, LI, &SE, &DT, &AC, &TTI, &ORE, PreserveLCSSA, &RemainderLoop, AA);
13591361
if (UnrollResult == LoopUnrollResult::Unmodified)

llvm/lib/Transforms/Utils/LoopUnroll.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,10 @@ llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
671671
// to not exit.
672672
DenseMap<PHINode *, RecurrenceDescriptor> Reductions;
673673
bool CanAddAdditionalAccumulators =
674-
UnrollAddParallelReductions && !CompletelyUnroll &&
675-
L->getNumBlocks() == 1 &&
674+
(UnrollAddParallelReductions.getNumOccurrences() > 0
675+
? UnrollAddParallelReductions
676+
: ULO.AddAdditionalAccumulators) &&
677+
!CompletelyUnroll && L->getNumBlocks() == 1 &&
676678
(ULO.Runtime ||
677679
(ExitInfos.contains(Header) && ((ExitInfos[Header].TripCount != 0 &&
678680
ExitInfos[Header].BreakoutTrip == 0))));

0 commit comments

Comments
 (0)