[Mlir-commits] [mlir] [mlir][scf] Require positive step when uplifting scf.while (PR #226719)
Ziliang Zhang
llvmlistbot at llvm.org
Wed Sep 30 01:57:50 PDT 2026
================
@@ -165,6 +165,14 @@ FailureOr<scf::ForOp> mlir::scf::upliftWhileToForLoop(RewriterBase &rewriter,
if (!step || !dom.properlyDominates(step, loop))
return rewriter.notifyMatchFailure(loop, "Invalid 'addi' form");
+ // `scf.for` requires a strictly positive step, and the exit-value
+ // reconstruction below relies on that same precondition.
+ APInt stepValue;
+ if (!matchPattern(step, m_ConstantInt(&stepValue)) ||
+ !stepValue.isStrictlyPositive())
+ return rewriter.notifyMatchFailure(loop,
----------------
ziliangzl wrote:
Yes, this can pessimize cases where a dynamic step happens to be positive at runtime, because such loops will remain as scf.while.
However, without proving that the step is positive, the uplift is not semantics-preserving: scf.while permits zero or negative steps, while scf.for requires a strictly positive step.
https://github.com/llvm/llvm-project/pull/226719
More information about the Mlir-commits
mailing list