@@ -755,7 +755,7 @@ static unsigned getFullUnrollBoostingFactor(const EstimatedUnrollCost &Cost,
755
755
static std::optional<unsigned >
756
756
shouldPragmaUnroll (Loop *L, const PragmaInfo &PInfo,
757
757
const unsigned TripMultiple, const unsigned TripCount,
758
- const UnrollCostEstimator UCE,
758
+ unsigned MaxTripCount, const UnrollCostEstimator UCE,
759
759
const TargetTransformInfo::UnrollingPreferences &UP) {
760
760
761
761
// Using unroll pragma
@@ -776,6 +776,11 @@ shouldPragmaUnroll(Loop *L, const PragmaInfo &PInfo,
776
776
if (PInfo.PragmaFullUnroll && TripCount != 0 )
777
777
return TripCount;
778
778
779
+ // Small MaxTripCount is clearly calculated with "pragma unroll".
780
+ if (PInfo.PragmaEnableUnroll && !TripCount && MaxTripCount &&
781
+ MaxTripCount <= UnrollMaxUpperBound)
782
+ return MaxTripCount;
783
+
779
784
// if didn't return until here, should continue to other priorties
780
785
return std::nullopt;
781
786
}
@@ -902,7 +907,7 @@ bool llvm::computeUnrollCount(
902
907
// 1st priority is unroll count set by "unroll-count" option.
903
908
// 2nd priority is unroll count set by pragma.
904
909
if (auto UnrollFactor = shouldPragmaUnroll (L, PInfo, TripMultiple, TripCount,
905
- UCE, UP)) {
910
+ MaxTripCount, UCE, UP)) {
906
911
UP.Count = *UnrollFactor;
907
912
908
913
if (UserUnrollCount || (PragmaCount > 0 )) {
0 commit comments