Skip to content

Commit d3ef867

Browse files
authored
[LoopUnroll] Make UnrollMaxUpperBound to be overridable by target (#76029)
The UnrollMaxUpperBound should be target dependent, since different chips provide different register set which brings different ability of storing more temporary values of a program. So I add a MaxUpperBound value in UnrollingPreference which can be override by targets. All uses of UnrollMaxUpperBound are replaced with UP.MaxUpperBound. The default value is still 8 and the command line argument '--unroll-max-upperbound' takes final effect if provided.
1 parent db8a119 commit d3ef867

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/include/llvm/Analysis/TargetTransformInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,10 @@ class TargetTransformInfo {
560560
// (set to UINT_MAX to disable). This does not apply in cases where the
561561
// loop is being fully unrolled.
562562
unsigned MaxCount;
563+
/// Set the maximum upper bound of trip count. Allowing the MaxUpperBound
564+
/// to be overrided by a target gives more flexiblity on certain cases.
565+
/// By default, MaxUpperBound uses UnrollMaxUpperBound which value is 8.
566+
unsigned MaxUpperBound;
563567
/// Set the maximum unrolling factor for full unrolling. Like MaxCount, but
564568
/// applies even if full unrolling is selected. This allows a target to fall
565569
/// back to Partial unrolling if full unrolling is above FullUnrollMaxCount.

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
200200
UP.Count = 0;
201201
UP.DefaultUnrollRuntimeCount = 8;
202202
UP.MaxCount = std::numeric_limits<unsigned>::max();
203+
UP.MaxUpperBound = UnrollMaxUpperBound;
203204
UP.FullUnrollMaxCount = std::numeric_limits<unsigned>::max();
204205
UP.BEInsns = 2;
205206
UP.Partial = false;
@@ -237,6 +238,8 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
237238
UP.MaxPercentThresholdBoost = UnrollMaxPercentThresholdBoost;
238239
if (UnrollMaxCount.getNumOccurrences() > 0)
239240
UP.MaxCount = UnrollMaxCount;
241+
if (UnrollMaxUpperBound.getNumOccurrences() > 0)
242+
UP.MaxUpperBound = UnrollMaxUpperBound;
240243
if (UnrollFullMaxCount.getNumOccurrences() > 0)
241244
UP.FullUnrollMaxCount = UnrollFullMaxCount;
242245
if (UnrollAllowPartial.getNumOccurrences() > 0)
@@ -777,7 +780,7 @@ shouldPragmaUnroll(Loop *L, const PragmaInfo &PInfo,
777780
return TripCount;
778781

779782
if (PInfo.PragmaEnableUnroll && !TripCount && MaxTripCount &&
780-
MaxTripCount <= UnrollMaxUpperBound)
783+
MaxTripCount <= UP.MaxUpperBound)
781784
return MaxTripCount;
782785

783786
// if didn't return until here, should continue to other priorties
@@ -952,7 +955,7 @@ bool llvm::computeUnrollCount(
952955
// cost of exact full unrolling. As such, if we have an exact count and
953956
// found it unprofitable, we'll never chose to bounded unroll.
954957
if (!TripCount && MaxTripCount && (UP.UpperBound || MaxOrZero) &&
955-
MaxTripCount <= UnrollMaxUpperBound) {
958+
MaxTripCount <= UP.MaxUpperBound) {
956959
UP.Count = MaxTripCount;
957960
if (auto UnrollFactor = shouldFullUnroll(L, TTI, DT, SE, EphValues,
958961
MaxTripCount, UCE, UP)) {
@@ -1026,7 +1029,7 @@ bool llvm::computeUnrollCount(
10261029
}
10271030

10281031
// Don't unroll a small upper bound loop unless user or TTI asked to do so.
1029-
if (MaxTripCount && !UP.Force && MaxTripCount < UnrollMaxUpperBound) {
1032+
if (MaxTripCount && !UP.Force && MaxTripCount < UP.MaxUpperBound) {
10301033
UP.Count = 0;
10311034
return false;
10321035
}

0 commit comments

Comments
 (0)