[Mlir-commits] [mlir] [mlir][scf] Require positive step when uplifting scf.while (PR #226719)

Matthias Springer llvmlistbot at llvm.org
Mon Sep 28 18:05:32 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,
----------------
matthias-springer wrote:

This is correct. `scf.for` requires the step to be strictly positive. But I'm a bit worried about the case where the step is dynamic. Will this change pessimize existing code?

Maybe the original authors/maintainers of this code can chime in? @Hardcode84

https://github.com/llvm/llvm-project/pull/226719


More information about the Mlir-commits mailing list