[Mlir-commits] [mlir] [mlir][DialectUtils] Fix 0 step handling in `constantTripCount` (PR #177329)

Matthias Springer llvmlistbot at llvm.org
Sun Jan 25 11:42:08 PST 2026


================
@@ -357,9 +357,15 @@ func.func @regression(%arg0: memref<i64>, %arg1: index) {
 // -----
 
 // Regression test: Make sure that we do not crash.
-// The step is 0, the loop will be eliminated.
+
 // CHECK-LABEL: func @zero_step(
-//       CHECK-NOT:   scf.for
+//       CHECK:   %[[c0:.*]] = arith.constant 0
+//       CHECK:   %[[c1:.*]] = arith.constant 1
+//       CHECK:   %[[poison:.*]] = ub.poison
----------------
matthias-springer wrote:

The loop peeling is fundamentally incompatible with "step size 0" loops. I added a comment to clarify that.

Loop peeling sets the new UB to `%ub - (%ub - %lb) mod %step`. In case of a step size of 0, that's a division by zero, which will be canonicalized to `ub.poison` (if detected statically). There's no way to prevent this division from zero, apart from special-casing the IR with an `scf.if`.

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


More information about the Mlir-commits mailing list