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

Ivan Butygin llvmlistbot at llvm.org
Wed Sep 30 03:09:04 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,
----------------
Hardcode84 wrote:

We can probably check if step is postitive with `arith.cmpi` and then remap `scf.for` bounds and IV to be postitive using `arith.select`s. And if step is constant, all those selects should fold away.

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


More information about the Mlir-commits mailing list