@@ -221,6 +221,7 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
221221 UP.MaxIterationsCountToAnalyze = UnrollMaxIterationsCountToAnalyze;
222222 UP.SCEVExpansionBudget = SCEVCheapExpansionBudget;
223223 UP.RuntimeUnrollMultiExit = false ;
224+ UP.RelaxPragmaUnrollThresholds = false ;
224225
225226 // Override with any target specific settings
226227 TTI.getUnrollingPreferences (L, SE, UP, &ORE);
@@ -939,6 +940,10 @@ bool llvm::computeUnrollCount(
939940
940941 const bool ExplicitUnroll = PragmaCount > 0 || PragmaFullUnroll ||
941942 PragmaEnableUnroll || UserUnrollCount;
943+ // If enabled, relax unrolling thresholds when pragma unroll is used.
944+ const bool RelaxUnrollThrehsholds = UP.RelaxPragmaUnrollThresholds &&
945+ (PragmaEnableUnroll && !UserUnrollCount &&
946+ !PragmaFullUnroll && PragmaCount == 0 );
942947
943948 PragmaInfo PInfo (UserUnrollCount, PragmaFullUnroll, PragmaCount,
944949 PragmaEnableUnroll);
@@ -967,7 +972,7 @@ bool llvm::computeUnrollCount(
967972 UP.Runtime |= (PragmaCount > 0 );
968973 return ExplicitUnroll;
969974 } else {
970- if (ExplicitUnroll && TripCount != 0 ) {
975+ if (RelaxUnrollThrehsholds || ( ExplicitUnroll && TripCount != 0 ) ) {
971976 // If the loop has an unrolling pragma, we want to be more aggressive with
972977 // unrolling limits. Set thresholds to at least the PragmaUnrollThreshold
973978 // value which is larger than the default limits.
@@ -1077,7 +1082,8 @@ bool llvm::computeUnrollCount(
10771082 }
10781083
10791084 // Don't unroll a small upper bound loop unless user or TTI asked to do so.
1080- if (MaxTripCount && !UP.Force && MaxTripCount < UP.MaxUpperBound ) {
1085+ if (!RelaxUnrollThrehsholds && MaxTripCount && !UP.Force &&
1086+ MaxTripCount < UP.MaxUpperBound ) {
10811087 UP.Count = 0 ;
10821088 return false ;
10831089 }
0 commit comments