[Mlir-commits] [mlir] [mlir][affine] Clamp negative static trip counts to zero (PR #227134)
Jeremy Kun
llvmlistbot at llvm.org
Fri Oct 2 17:00:15 PDT 2026
================
@@ -965,6 +965,27 @@ func.func @no_hoist_from_zero_trip_count_loop(%x: i32) -> i32 {
// -----
+// The bounds are not constant, but the upper bound is below the lower bound, so
+// this loop never executes either.
+
+// CHECK-LABEL: func @no_hoist_from_zero_trip_count_loop_nonconstant_bounds
+func.func @no_hoist_from_zero_trip_count_loop_nonconstant_bounds(%x: i32, %n: index) -> i32 {
+ %alloc = memref.alloc() : memref<1xi32>
+ %c42 = arith.constant 42 : i32
+ affine.store %c42, %alloc[0] : memref<1xi32>
+ affine.for %i = affine_map<(d0) -> (d0)>(%n) to affine_map<(d0) -> (d0 - 2)>(%n) {
+ affine.store %x, %alloc[0] : memref<1xi32>
+ }
+ // CHECK: affine.store %c42{{.*}}, %alloc[0]
+ // CHECK: affine.for
+ // CHECK-NEXT: affine.store %arg0, %alloc[0]
----------------
j2kun wrote:
nit: avoid hard-coding the variable names into the check statements, as the specific choice of names is not guaranteed by MLIR and it makes these tests more brittle.
https://github.com/llvm/llvm-project/pull/227134
More information about the Mlir-commits
mailing list