Skip to content

[LoopUnroll] Make use of MaxTripCount for loops with "#pragma unroll" #74703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ static unsigned getFullUnrollBoostingFactor(const EstimatedUnrollCost &Cost,
static std::optional<unsigned>
shouldPragmaUnroll(Loop *L, const PragmaInfo &PInfo,
const unsigned TripMultiple, const unsigned TripCount,
const UnrollCostEstimator UCE,
unsigned MaxTripCount, const UnrollCostEstimator UCE,
const TargetTransformInfo::UnrollingPreferences &UP) {

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

if (PInfo.PragmaEnableUnroll && !TripCount && MaxTripCount &&
MaxTripCount <= UnrollMaxUpperBound)
return MaxTripCount;

// if didn't return until here, should continue to other priorties
return std::nullopt;
}
Expand Down Expand Up @@ -902,7 +906,7 @@ bool llvm::computeUnrollCount(
// 1st priority is unroll count set by "unroll-count" option.
// 2nd priority is unroll count set by pragma.
if (auto UnrollFactor = shouldPragmaUnroll(L, PInfo, TripMultiple, TripCount,
UCE, UP)) {
MaxTripCount, UCE, UP)) {
UP.Count = *UnrollFactor;

if (UserUnrollCount || (PragmaCount > 0)) {
Expand Down
Loading