Skip to content

Commit 6731a07

Browse files
authored
Reland: [LoopUnroll] Make use of MaxTripCount for loops with pragma unroll (llvm#2294)
2 parents e1655cc + 3786716 commit 6731a07

File tree

2 files changed

+943
-2
lines changed

2 files changed

+943
-2
lines changed

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ static unsigned getFullUnrollBoostingFactor(const EstimatedUnrollCost &Cost,
797797
static std::optional<unsigned>
798798
shouldPragmaUnroll(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

Comments
 (0)