Skip to content

Commit d0dc993

Browse files
committed
[LoopUnroll] Unroll small loops with 'pragma unroll' when its trip count is destroyed by preious optimization
1 parent 0e5655e commit d0dc993

File tree

2 files changed

+793
-47
lines changed

2 files changed

+793
-47
lines changed

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ static unsigned getFullUnrollBoostingFactor(const EstimatedUnrollCost &Cost,
755755
static std::optional<unsigned>
756756
shouldPragmaUnroll(Loop *L, const PragmaInfo &PInfo,
757757
const unsigned TripMultiple, const unsigned TripCount,
758-
const UnrollCostEstimator UCE,
758+
unsigned MaxTripCount, const UnrollCostEstimator UCE,
759759
const TargetTransformInfo::UnrollingPreferences &UP) {
760760

761761
// Using unroll pragma
@@ -776,6 +776,10 @@ shouldPragmaUnroll(Loop *L, const PragmaInfo &PInfo,
776776
if (PInfo.PragmaFullUnroll && TripCount != 0)
777777
return TripCount;
778778

779+
if (PInfo.PragmaEnableUnroll && !TripCount && MaxTripCount &&
780+
MaxTripCount <= UnrollMaxUpperBound)
781+
return MaxTripCount;
782+
779783
// if didn't return until here, should continue to other priorties
780784
return std::nullopt;
781785
}
@@ -902,7 +906,7 @@ bool llvm::computeUnrollCount(
902906
// 1st priority is unroll count set by "unroll-count" option.
903907
// 2nd priority is unroll count set by pragma.
904908
if (auto UnrollFactor = shouldPragmaUnroll(L, PInfo, TripMultiple, TripCount,
905-
UCE, UP)) {
909+
MaxTripCount, UCE, UP)) {
906910
UP.Count = *UnrollFactor;
907911

908912
if (UserUnrollCount || (PragmaCount > 0)) {

0 commit comments

Comments
 (0)