[llvm] [LoopUnroll] Remove `Count` from `UnrollingPreferences` (NFC) (PR #203413)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 15:46:26 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-openmp
Author: Justin Fargnoli (justinfargnoli)
<details>
<summary>Changes</summary>
`UnrollingPreferences` is a way for targets to specify their preferences to the unroller. The unroller uses `UnrollingPreferences` to guide what kinds of unrolling to consider while also co-opting it to encode the specific kind of unrolling it's chosen to attempt.
One preference targets can set is the `Count`, or the number of times the loop in question will be unrolled:
```
/// A forced unrolling factor (the number of concatenated bodies of the
/// original loop in the unrolled loop body). When set to 0, the unrolling
/// transformation will select an unrolling factor based on the current cost
/// threshold and other factors.
unsigned Count;
```
However, there are no in-tree uses of this functionality, and it does not work. [Loop peeling](https://github.com/llvm/llvm-project/blob/112fb2f79d7983be203957cad6b148865182ed47/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L1072) ([2](https://github.com/llvm/llvm-project/blob/112fb2f79d7983be203957cad6b148865182ed47/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L1149)), [pragma unrolling](https://github.com/llvm/llvm-project/blob/112fb2f79d7983be203957cad6b148865182ed47/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L1090), [full unrolling](https://github.com/llvm/llvm-project/blob/112fb2f79d7983be203957cad6b148865182ed47/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L1115), [upper-bound unrolling](https://github.com/llvm/llvm-project/blob/112fb2f79d7983be203957cad6b148865182ed47/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L1137), [partial unrolling](https://github.com/llvm/llvm-project/blob/112fb2f79d7983be203957cad6b148865182ed47/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L1162), and [runtime unrolling](https://github.com/llvm/llvm-project/blob/112fb2f79d7983be203957cad6b148865182ed47/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp#L1202) all override the value of `UP.Count` that targets would've set. This appears to have been broken since LLVM 3.9 days as a result of ea2aef4a1d4beded20033fa4fc223936c7ffe5d8.
This PR removes `Count` from `UnrollingPreferences` and instead encodes it as a return value of the `computeUnrollCount()` family of functions.
If [out-of-tree targets want to begin setting `Count`](https://github.com/llvm/llvm-project/pull/185979#discussion_r3022857799), their best bet is likely to use [`llvm.loop.unroll.count`](https://llvm.org/docs/LangRef.html#llvm-loop-unroll-count-metadata).
---
Patch is 37.11 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/203413.diff
7 Files Affected:
- (modified) llvm/include/llvm/Analysis/TargetTransformInfo.h (-5)
- (modified) llvm/include/llvm/Transforms/Scalar.h (+3-3)
- (modified) llvm/include/llvm/Transforms/Utils/UnrollLoop.h (+6-7)
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+3-4)
- (modified) llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp (+58-49)
- (modified) llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp (+85-116)
- (modified) llvm/test/Transforms/LoopUnroll/RISCV/runtime-unroll-max-trip-count.ll (+4-3)
``````````diff
diff --git a/llvm/include/llvm/Analysis/TargetTransformInfo.h b/llvm/include/llvm/Analysis/TargetTransformInfo.h
index 7d58473b81265..b9eee423525f5 100644
--- a/llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ b/llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -665,11 +665,6 @@ class TargetTransformInfo {
/// OptSizeThreshold, but used for partial/runtime unrolling (set to
/// UINT_MAX to disable).
unsigned PartialOptSizeThreshold;
- /// A forced unrolling factor (the number of concatenated bodies of the
- /// original loop in the unrolled loop body). When set to 0, the unrolling
- /// transformation will select an unrolling factor based on the current cost
- /// threshold and other factors.
- unsigned Count;
/// Default unroll count for loops with run-time trip count.
unsigned DefaultUnrollRuntimeCount;
// Set the maximum unrolling factor. The unrolling factor may be selected
diff --git a/llvm/include/llvm/Transforms/Scalar.h b/llvm/include/llvm/Transforms/Scalar.h
index f57a86c772bb1..24a127b1ffb17 100644
--- a/llvm/include/llvm/Transforms/Scalar.h
+++ b/llvm/include/llvm/Transforms/Scalar.h
@@ -75,9 +75,9 @@ LLVM_ABI Pass *createLoopTermFoldPass();
LLVM_ABI Pass *createLoopUnrollPass(int OptLevel = 2,
bool OnlyWhenForced = false,
bool ForgetAllSCEV = false,
- int Threshold = -1, int Count = -1,
- int AllowPartial = -1, int Runtime = -1,
- int UpperBound = -1, int AllowPeeling = -1);
+ int Threshold = -1, int AllowPartial = -1,
+ int Runtime = -1, int UpperBound = -1,
+ int AllowPeeling = -1);
//===----------------------------------------------------------------------===//
//
diff --git a/llvm/include/llvm/Transforms/Utils/UnrollLoop.h b/llvm/include/llvm/Transforms/Utils/UnrollLoop.h
index b200a351807cc..bcb0bd3e9bac4 100644
--- a/llvm/include/llvm/Transforms/Utils/UnrollLoop.h
+++ b/llvm/include/llvm/Transforms/Utils/UnrollLoop.h
@@ -139,9 +139,8 @@ LLVM_ABI TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences(
Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI,
BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
llvm::OptimizationRemarkEmitter &ORE, int OptLevel,
- std::optional<unsigned> UserThreshold, std::optional<unsigned> UserCount,
- std::optional<bool> UserAllowPartial, std::optional<bool> UserRuntime,
- std::optional<bool> UserUpperBound,
+ std::optional<unsigned> UserThreshold, std::optional<bool> UserAllowPartial,
+ std::optional<bool> UserRuntime, std::optional<bool> UserUpperBound,
std::optional<unsigned> UserFullUnrollMaxCount);
/// Produce an estimate of the unrolled cost of the specified loop. This
@@ -172,14 +171,14 @@ class UnrollCostEstimator {
uint64_t getRolledLoopSize() const { return LoopSize.getValue(); }
- /// Returns loop size estimation for unrolled loop, given the unrolling
- /// configuration specified by UP.
+ /// Returns loop size estimation for an unrolled loop with the given unroll
+ /// count and the unrolling configuration specified by UP.
LLVM_ABI uint64_t
getUnrolledLoopSize(const TargetTransformInfo::UnrollingPreferences &UP,
- unsigned CountOverwrite = 0) const;
+ unsigned Count) const;
};
-LLVM_ABI void
+LLVM_ABI unsigned
computeUnrollCount(Loop *L, const TargetTransformInfo &TTI, DominatorTree &DT,
LoopInfo *LI, AssumptionCache *AC, ScalarEvolution &SE,
const SmallPtrSetImpl<const Value *> &EphValues,
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 92eb7de0d882f..749be53439a0a 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -7389,7 +7389,6 @@ static int32_t computeHeuristicUnrollFactor(CanonicalLoopInfo *CLI) {
/*BlockFrequencyInfo=*/nullptr,
/*ProfileSummaryInfo=*/nullptr, ORE, static_cast<int>(OptLevel),
/*UserThreshold=*/std::nullopt,
- /*UserCount=*/std::nullopt,
/*UserAllowPartial=*/true,
/*UserAllowRuntime=*/true,
/*UserUpperBound=*/std::nullopt,
@@ -7464,9 +7463,9 @@ static int32_t computeHeuristicUnrollFactor(CanonicalLoopInfo *CLI) {
bool MaxOrZero = false;
unsigned TripMultiple = 0;
- computeUnrollCount(L, TTI, DT, &LI, &AC, SE, EphValues, &ORE, TripCount,
- MaxTripCount, MaxOrZero, TripMultiple, UCE, UP, PP);
- unsigned Factor = UP.Count;
+ unsigned Factor =
+ computeUnrollCount(L, TTI, DT, &LI, &AC, SE, EphValues, &ORE, TripCount,
+ MaxTripCount, MaxOrZero, TripMultiple, UCE, UP, PP);
LLVM_DEBUG(dbgs() << "Suggesting unroll factor of " << Factor << "\n");
// This function returns 1 to signal to not unroll a loop.
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp
index e2bca3dd37304..d9dc9e004b26e 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp
@@ -128,57 +128,65 @@ static unsigned unrollAndJamCountPragmaValue(const Loop *L) {
return 0;
}
-// Returns loop size estimation for unrolled loop.
+// Returns loop size estimation for an unrolled-and-jammed loop with the given
+// unroll count.
static uint64_t
getUnrollAndJammedLoopSize(unsigned LoopSize,
- TargetTransformInfo::UnrollingPreferences &UP) {
+ const TargetTransformInfo::UnrollingPreferences &UP,
+ unsigned Count) {
assert(LoopSize >= UP.BEInsns && "LoopSize should not be less than BEInsns!");
- return static_cast<uint64_t>(LoopSize - UP.BEInsns) * UP.Count + UP.BEInsns;
+ return static_cast<uint64_t>(LoopSize - UP.BEInsns) * Count + UP.BEInsns;
}
-// Calculates unroll and jam count and writes it to UP.Count. Returns true if
-// unroll count was set explicitly.
-static bool computeUnrollAndJamCount(
+// Calculates unroll and jam count.
+static unsigned computeUnrollAndJamCount(
Loop *L, Loop *SubLoop, const TargetTransformInfo &TTI, DominatorTree &DT,
LoopInfo *LI, AssumptionCache *AC, ScalarEvolution &SE,
const SmallPtrSetImpl<const Value *> &EphValues,
OptimizationRemarkEmitter *ORE, unsigned OuterTripCount,
unsigned OuterTripMultiple, const UnrollCostEstimator &OuterUCE,
unsigned InnerTripCount, unsigned InnerLoopSize,
- TargetTransformInfo::UnrollingPreferences &UP,
+ bool &IsExplicitUnrollAndJam, TargetTransformInfo::UnrollingPreferences &UP,
TargetTransformInfo::PeelingPreferences &PP) {
unsigned OuterLoopSize = OuterUCE.getRolledLoopSize();
+ IsExplicitUnrollAndJam = false;
+
// Use computeUnrollCount from the loop unroller to get a count for
// unrolling the outer loop. This uses UP.Threshold / UP.PartialThreshold /
// UP.MaxCount to come up with sensible loop values.
// We have already checked that the loop has no unroll.* pragmas.
- computeUnrollCount(L, TTI, DT, LI, AC, SE, EphValues, ORE, OuterTripCount,
- /*MaxTripCount*/ 0, /*MaxOrZero*/ false, OuterTripMultiple,
- OuterUCE, UP, PP);
+ unsigned Count =
+ computeUnrollCount(L, TTI, DT, LI, AC, SE, EphValues, ORE, OuterTripCount,
+ /*MaxTripCount*/ 0, /*MaxOrZero*/ false,
+ OuterTripMultiple, OuterUCE, UP, PP);
- // Override with any explicit Count from the "unroll-and-jam-count" option.
+ // Override with any explicit count from the "unroll-and-jam-count" option.
bool UserUnrollCount = UnrollAndJamCount.getNumOccurrences() > 0;
if (UserUnrollCount) {
- UP.Count = UnrollAndJamCount;
+ Count = UnrollAndJamCount;
UP.Force = true;
if (UP.AllowRemainder &&
- getUnrollAndJammedLoopSize(OuterLoopSize, UP) < UP.Threshold &&
- getUnrollAndJammedLoopSize(InnerLoopSize, UP) <
- UP.UnrollAndJamInnerLoopThreshold)
- return true;
+ getUnrollAndJammedLoopSize(OuterLoopSize, UP, Count) < UP.Threshold &&
+ getUnrollAndJammedLoopSize(InnerLoopSize, UP, Count) <
+ UP.UnrollAndJamInnerLoopThreshold) {
+ IsExplicitUnrollAndJam = true;
+ return Count;
+ }
}
// Check for unroll_and_jam pragmas
unsigned PragmaCount = unrollAndJamCountPragmaValue(L);
if (PragmaCount > 0) {
- UP.Count = PragmaCount;
+ Count = PragmaCount;
UP.Runtime = true;
UP.Force = true;
if ((UP.AllowRemainder || (OuterTripMultiple % PragmaCount == 0)) &&
- getUnrollAndJammedLoopSize(OuterLoopSize, UP) < UP.Threshold &&
- getUnrollAndJammedLoopSize(InnerLoopSize, UP) <
- UP.UnrollAndJamInnerLoopThreshold)
- return true;
+ getUnrollAndJammedLoopSize(OuterLoopSize, UP, Count) < UP.Threshold &&
+ getUnrollAndJammedLoopSize(InnerLoopSize, UP, Count) <
+ UP.UnrollAndJamInnerLoopThreshold) {
+ IsExplicitUnrollAndJam = true;
+ return Count;
+ }
}
bool PragmaEnableUnroll = hasUnrollAndJamEnablePragma(L);
@@ -190,35 +198,36 @@ static bool computeUnrollAndJamCount(
if (ExplicitUnrollAndJam)
UP.UnrollAndJamInnerLoopThreshold = PragmaUnrollAndJamThreshold;
- if (!UP.AllowRemainder && getUnrollAndJammedLoopSize(InnerLoopSize, UP) >=
- UP.UnrollAndJamInnerLoopThreshold) {
+ if (!UP.AllowRemainder &&
+ getUnrollAndJammedLoopSize(InnerLoopSize, UP, Count) >=
+ UP.UnrollAndJamInnerLoopThreshold) {
LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; can't create remainder and "
"inner loop too large\n");
- UP.Count = 0;
- return false;
+ return 0;
}
// We have a sensible limit for the outer loop, now adjust it for the inner
// loop and UP.UnrollAndJamInnerLoopThreshold. If the outer limit was set
// explicitly, we want to stick to it.
if (!ExplicitUnrollAndJamCount && UP.AllowRemainder) {
- while (UP.Count != 0 && getUnrollAndJammedLoopSize(InnerLoopSize, UP) >=
- UP.UnrollAndJamInnerLoopThreshold)
- UP.Count--;
+ while (Count != 0 && getUnrollAndJammedLoopSize(InnerLoopSize, UP, Count) >=
+ UP.UnrollAndJamInnerLoopThreshold)
+ Count--;
}
// If we are explicitly unroll and jamming, we are done. Otherwise there are a
// number of extra performance heuristics to check.
- if (ExplicitUnrollAndJam)
- return true;
+ if (ExplicitUnrollAndJam) {
+ IsExplicitUnrollAndJam = true;
+ return Count;
+ }
// If the inner loop count is known and small, leave the entire loop nest to
// be the unroller
if (InnerTripCount && InnerLoopSize * InnerTripCount < UP.Threshold) {
LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; small inner loop count is "
"being left for the unroller\n");
- UP.Count = 0;
- return false;
+ return 0;
}
// Check for situations where UnJ is likely to be unprofitable. Including
@@ -226,8 +235,7 @@ static bool computeUnrollAndJamCount(
if (SubLoop->getBlocks().size() != 1) {
LLVM_DEBUG(
dbgs() << "Won't unroll-and-jam; More than one inner loop block\n");
- UP.Count = 0;
- return false;
+ return 0;
}
// Limit to loops where there is something to gain from unrolling and
@@ -246,11 +254,10 @@ static bool computeUnrollAndJamCount(
}
if (NumInvariant == 0) {
LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; No loop invariant loads\n");
- UP.Count = 0;
- return false;
+ return 0;
}
- return false;
+ return Count;
}
static LoopUnrollResult
@@ -260,7 +267,7 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,
OptimizationRemarkEmitter &ORE, int OptLevel) {
TargetTransformInfo::UnrollingPreferences UP = gatherUnrollingPreferences(
L, SE, TTI, nullptr, nullptr, ORE, OptLevel, std::nullopt, std::nullopt,
- std::nullopt, std::nullopt, std::nullopt, std::nullopt);
+ std::nullopt, std::nullopt, std::nullopt);
TargetTransformInfo::PeelingPreferences PP =
gatherPeelingPreferences(L, SE, TTI, std::nullopt, std::nullopt);
@@ -348,19 +355,21 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,
unsigned InnerTripCount = SE.getSmallConstantTripCount(SubLoop, SubLoopLatch);
// Decide if, and by how much, to unroll
- bool IsCountSetExplicitly = computeUnrollAndJamCount(
- L, SubLoop, TTI, DT, LI, &AC, SE, EphValues, &ORE, OuterTripCount,
- OuterTripMultiple, OuterUCE, InnerTripCount, InnerLoopSize, UP, PP);
- if (UP.Count <= 1)
+ bool IsExplicitUnrollAndJam = false;
+ unsigned Count = computeUnrollAndJamCount(
+ L, SubLoop, TTI, DT, LI, &AC, SE, EphValues, &ORE, OuterTripCount,
+ OuterTripMultiple, OuterUCE, InnerTripCount, InnerLoopSize,
+ IsExplicitUnrollAndJam, UP, PP);
+ if (Count <= 1)
return LoopUnrollResult::Unmodified;
// Unroll factor (Count) must be less or equal to TripCount.
- if (OuterTripCount && UP.Count > OuterTripCount)
- UP.Count = OuterTripCount;
+ if (OuterTripCount && Count > OuterTripCount)
+ Count = OuterTripCount;
Loop *EpilogueOuterLoop = nullptr;
LoopUnrollResult UnrollResult = UnrollAndJamLoop(
- L, UP.Count, OuterTripCount, OuterTripMultiple, UP.UnrollRemainder, LI,
- &SE, &DT, &AC, &TTI, &ORE, &EpilogueOuterLoop);
+ L, Count, OuterTripCount, OuterTripMultiple, UP.UnrollRemainder, LI, &SE,
+ &DT, &AC, &TTI, &ORE, &EpilogueOuterLoop);
// Assign new loop attributes.
if (EpilogueOuterLoop) {
@@ -391,9 +400,9 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,
}
}
- // If loop has an unroll count pragma or unrolled by explicitly set count
- // mark loop as unrolled to prevent unrolling beyond that requested.
- if (UnrollResult != LoopUnrollResult::FullyUnrolled && IsCountSetExplicitly)
+ // If unroll-and-jam was explicitly requested, mark the loop as already
+ // unrolled to prevent unrolling beyond that request.
+ if (UnrollResult != LoopUnrollResult::FullyUnrolled && IsExplicitUnrollAndJam)
L->setLoopAlreadyUnrolled();
return UnrollResult;
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 7034e595a4435..8ec94a96a7771 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -190,9 +190,8 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI,
BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
OptimizationRemarkEmitter &ORE, int OptLevel,
- std::optional<unsigned> UserThreshold, std::optional<unsigned> UserCount,
- std::optional<bool> UserAllowPartial, std::optional<bool> UserRuntime,
- std::optional<bool> UserUpperBound,
+ std::optional<unsigned> UserThreshold, std::optional<bool> UserAllowPartial,
+ std::optional<bool> UserRuntime, std::optional<bool> UserUpperBound,
std::optional<unsigned> UserFullUnrollMaxCount) {
TargetTransformInfo::UnrollingPreferences UP;
@@ -203,7 +202,6 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
UP.OptSizeThreshold = UnrollOptSizeThreshold;
UP.PartialThreshold = 150;
UP.PartialOptSizeThreshold = UnrollOptSizeThreshold;
- UP.Count = 0;
UP.DefaultUnrollRuntimeCount = 8;
UP.MaxCount = std::numeric_limits<unsigned>::max();
UP.MaxUpperBound = UnrollMaxUpperBound;
@@ -269,8 +267,6 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
UP.Threshold = *UserThreshold;
UP.PartialThreshold = *UserThreshold;
}
- if (UserCount)
- UP.Count = *UserCount;
if (UserAllowPartial)
UP.Partial = *UserAllowPartial;
if (UserRuntime)
@@ -737,14 +733,10 @@ bool UnrollCostEstimator::canUnroll(OptimizationRemarkEmitter *ORE,
}
uint64_t UnrollCostEstimator::getUnrolledLoopSize(
- const TargetTransformInfo::UnrollingPreferences &UP,
- unsigned CountOverwrite) const {
+ const TargetTransformInfo::UnrollingPreferences &UP, unsigned Count) const {
unsigned LS = LoopSize.getValue();
assert(LS >= UP.BEInsns && "LoopSize should not be less than BEInsns!");
- if (CountOverwrite)
- return static_cast<uint64_t>(LS - UP.BEInsns) * CountOverwrite + UP.BEInsns;
- else
- return static_cast<uint64_t>(LS - UP.BEInsns) * UP.Count + UP.BEInsns;
+ return static_cast<uint64_t>(LS - UP.BEInsns) * Count + UP.BEInsns;
}
// Returns true if the loop has an unroll(full) pragma.
@@ -972,70 +964,65 @@ shouldPartialUnroll(const unsigned LoopSize, const unsigned TripCount,
<< "-unroll-allow-partial not given\n");
return 0;
}
- unsigned count = UP.Count;
- if (count == 0)
- count = TripCount;
+ unsigned Count = TripCount;
if (UP.PartialThreshold != NoThreshold) {
// Reduce unroll count to be modulo of TripCount for partial unrolling.
- if (UCE.getUnrolledLoopSize(UP, count) > UP.PartialThreshold) {
+ if (UCE.getUnrolledLoopSize(UP, Count) > UP.PartialThreshold) {
unsigned NewCount =
(std::max(UP.PartialThreshold, UP.BEInsns + 1) - UP.BEInsns) /
(LoopSize - UP.BEInsns);
LLVM_DEBUG(dbgs().indent(2)
<< "Unrolled size exceeds threshold; reducing count "
- << "from " << count << " to " << NewCount << ".\n");
- count = NewCount;
+ << "from " << Count << " to " << NewCount << ".\n");
+ Count = NewCount;
}
- if (count > UP.MaxCount)
- count = UP.MaxCount;
- while (count != 0 && TripCount % count != 0)
- count--;
- if (UP.AllowRemainder && count <= 1) {
+ if (Count > UP.MaxCount)
+ Count = UP.MaxCount;
+ while (Count != 0 && TripCount % Count != 0)
+ Count--;
+ if (UP.AllowRemainder && Count <= 1) {
// If there is no Count that is modulo of TripCount, set Count to
// largest power-of-two factor that satisfies the threshold limit.
// As we'll create fixup loop, do the type of unrolling only if
// remainder loop is allowed.
// Note: DefaultUnrollRuntimeCount is used as a reasonable starting point
// even though this is partial unrolling (not runtime unrolling).
- count = UP.DefaultUnrollRuntimeCount;
- while (count != 0 &&
- UCE.getUnrolledLoopSize(UP, count) > UP.PartialThreshold)
- count >>= 1;
+ Count = UP.DefaultUnrollRuntimeCount;
+ while (Count != 0 &&
+ UCE.getUnrolledLoopSize(UP, Count) > UP.PartialThreshold)
+ Count >>= 1;
}
- if (count < 2) {
+ if (Count < 2) {
LLVM_DEBUG(dbgs().indent(2)
<< "Will not partially unroll: no profitable count.\n");
- count = 0;
+ Count = 0;
}
} else {
- count = TripCount;
+ Count = TripCount;
}
- if (count > UP.MaxCount)
- count = UP.MaxCount;
+ if (Count > UP.MaxCount)
+ Count = UP.MaxCount;
LLVM_DEBUG(dbgs().indent(2)
- << "Partially unrolling with count: " << count << "\n");
+ << "Partially unrolling with count: " << Count << "\n");
- return count;
+ return Count;
}
-// Calculates unroll count and writes it to UP.Count.
-// Unless IgnoreUser is true, will also use metadata and command-line options
-// that are specific to the LoopUnroll pass (which, for instance, are
+// Calculates and returns the unroll count, using metadata and command-line
+// options that are specific to the LoopUnroll pass (which, for instance, are
// irrelevant for the LoopUnrollAndJam pass).
// FIXME: This function is used by LoopUnroll and LoopUnrollAndJam, but consumes
// many LoopUnroll-specific options. The shared functionality should be
// refactored into it own function.
-void llvm::computeUnrollCount(Loop *L, const TargetTransformInfo &TTI,
- DominatorTree &DT, LoopInfo *LI,
- AssumptionCache *AC, ScalarEvolution &SE,
- ...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/203413
More information about the llvm-commits
mailing list