[Mlir-commits] [mlir] [mlir][scf] Fix front peeling skipped due to float rounding in trip count (PR #231100)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Oct 12 22:28:27 PDT 2026
================
@@ -238,8 +238,13 @@ LogicalResult mlir::scf::peelForLoopFirstIteration(RewriterBase &b, ForOp forOp,
auto ubInt = getConstantIntValue(forOp.getUpperBound());
auto stepInt = getConstantIntValue(forOp.getStep());
- // Peeling is not needed if there is one or less iteration.
- if (lbInt && ubInt && stepInt && ceil(float(*ubInt - *lbInt) / *stepInt) <= 1)
+ // Peeling is not needed if there is at most one iteration.
+ // Per the scf.for semantics, the trip count is
+ // max(0, ceil((UB - LB) / Step)), so for a positive step there is more than
+ // one iteration exactly when UB - LB > Step.
+ // Compare the integers directly: going through float is lossy and wrongly skipped
+ // peeling of loops with two iterations.
----------------
StarOne01 wrote:
done
https://github.com/llvm/llvm-project/pull/231100
More information about the Mlir-commits
mailing list