Skip to content
Open
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
2 changes: 2 additions & 0 deletions llvm/include/llvm/Analysis/TargetTransformInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ class TargetTransformInfo {
/// Fall back to the generic logic to determine whether multi-exit unrolling
/// is profitable if set to false.
bool RuntimeUnrollMultiExit;
// Relax conditions for unrolling when user requests unrolling via pragma.
bool RelaxPragmaUnrollThresholds;
};

/// Get target-customized preferences for the generic loop unrolling
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ void AMDGPUTTIImpl::getUnrollingPreferences(
UP.MaxCount = std::numeric_limits<unsigned>::max();
UP.Partial = true;

// Relax conditions for unrolling when user requests unrolling via pragma.
UP.RelaxPragmaUnrollThresholds = true;

// Conditional branch in a loop back edge needs 3 additional exec
// manipulations in average.
UP.BEInsns += 3;
Expand Down
10 changes: 8 additions & 2 deletions llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
UP.MaxIterationsCountToAnalyze = UnrollMaxIterationsCountToAnalyze;
UP.SCEVExpansionBudget = SCEVCheapExpansionBudget;
UP.RuntimeUnrollMultiExit = false;
UP.RelaxPragmaUnrollThresholds = false;

// Override with any target specific settings
TTI.getUnrollingPreferences(L, SE, UP, &ORE);
Expand Down Expand Up @@ -939,6 +940,10 @@ bool llvm::computeUnrollCount(

const bool ExplicitUnroll = PragmaCount > 0 || PragmaFullUnroll ||
PragmaEnableUnroll || UserUnrollCount;
// If enabled, relax unrolling thresholds when pragma unroll is used.
const bool RelaxUnrollThrehsholds = UP.RelaxPragmaUnrollThresholds &&
(PragmaEnableUnroll && !UserUnrollCount &&
!PragmaFullUnroll && PragmaCount == 0);

PragmaInfo PInfo(UserUnrollCount, PragmaFullUnroll, PragmaCount,
PragmaEnableUnroll);
Expand Down Expand Up @@ -967,7 +972,7 @@ bool llvm::computeUnrollCount(
UP.Runtime |= (PragmaCount > 0);
return ExplicitUnroll;
} else {
if (ExplicitUnroll && TripCount != 0) {
if (RelaxUnrollThrehsholds || (ExplicitUnroll && TripCount != 0)) {
// If the loop has an unrolling pragma, we want to be more aggressive with
// unrolling limits. Set thresholds to at least the PragmaUnrollThreshold
// value which is larger than the default limits.
Expand Down Expand Up @@ -1077,7 +1082,8 @@ bool llvm::computeUnrollCount(
}

// Don't unroll a small upper bound loop unless user or TTI asked to do so.
if (MaxTripCount && !UP.Force && MaxTripCount < UP.MaxUpperBound) {
if (!RelaxUnrollThrehsholds && MaxTripCount && !UP.Force &&
MaxTripCount < UP.MaxUpperBound) {
UP.Count = 0;
return false;
}
Expand Down