[llvm] Add flag to enable expensive trip counts for runtime unroll. (PR #171735)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 30 07:00:16 PST 2026
================
@@ -178,6 +178,11 @@ static cl::opt<unsigned> PragmaUnrollFullMaxIterations(
"pragma-unroll-full-max-iterations", cl::init(1'000'000), cl::Hidden,
cl::desc("Maximum allowed iterations to unroll under pragma unroll full."));
+static cl::opt<bool> UnrollRuntimeExpensiveTripCount(
----------------
carlobertolli wrote:
There's a "user requested" flag in the unroller that is part of the decision of when to unroll. I am not aware of a "force unroll" control that disables the checks I described. This code here does not have it, is what I mean
```
if (!AllowExpensiveTripCount &&
Expander.isHighCostExpansion(TripCountSC, L, SCEVExpansionBudget, TTI,
PreHeaderBR)) {
LLVM_DEBUG(dbgs() << "High cost for expanding trip count scev!\n");
return false;
}
```
The only way to stop SCEV budget check is to use the AllowExpensiveTripCount: user preference is not taken into account.
The problem with this specific case is that the trip count is unknown at compile time and the unroller factors in the decision about whether to unroll or not to unroll also based on the complexity of the loop count expression.
Two alternative solutions:
1. Change decision to always runtime unroll if the user requested it with a pragma. I would make this an AMDGPU-only because it is likely to suddenly change behavior across targets in production code.
2. Increase SCEV budget to meet the needs of the loop I wrote in my previous comment and only for AMDGPU (same rationale).
I don't have a preference for either, but I do need a solution to this problem.
https://github.com/llvm/llvm-project/pull/171735
More information about the llvm-commits
mailing list