@@ -797,7 +797,7 @@ static unsigned getFullUnrollBoostingFactor(const EstimatedUnrollCost &Cost,
797797static std::optional<unsigned >
798798shouldPragmaUnroll (Loop *L, const PragmaInfo &PInfo,
799799 const unsigned TripMultiple, const unsigned TripCount,
800- const UnrollCostEstimator UCE,
800+ unsigned MaxTripCount, const UnrollCostEstimator UCE,
801801 const TargetTransformInfo::UnrollingPreferences &UP) {
802802
803803 // Using unroll pragma
@@ -827,6 +827,10 @@ shouldPragmaUnroll(Loop *L, const PragmaInfo &PInfo,
827827 return TripCount;
828828 }
829829
830+ if (PInfo.PragmaEnableUnroll && !TripCount && MaxTripCount &&
831+ MaxTripCount <= UnrollMaxUpperBound)
832+ return MaxTripCount;
833+
830834 // if didn't return until here, should continue to other priorties
831835 return std::nullopt ;
832836}
@@ -953,7 +957,7 @@ bool llvm::computeUnrollCount(
953957 // 1st priority is unroll count set by "unroll-count" option.
954958 // 2nd priority is unroll count set by pragma.
955959 if (auto UnrollFactor = shouldPragmaUnroll (L, PInfo, TripMultiple, TripCount,
956- UCE, UP)) {
960+ MaxTripCount, UCE, UP)) {
957961 UP.Count = *UnrollFactor;
958962
959963 if (UserUnrollCount || (PragmaCount > 0 )) {
0 commit comments