[Mlir-commits] [mlir] [mlir][memref] Fix mem2reg crash on zero-extent alloca (PR #216851)

Federico Bruzzone llvmlistbot at llvm.org
Mon Aug 17 17:05:38 PDT 2026


================
@@ -309,3 +309,38 @@ func.func @two_consecutive_merge_points(%cond1: i1, %cond2: i1) -> i32 {
   // CHECK: return %[[RESULT]] : i32
   return %result : i32
 }
+
+// -----
+
+// A memref with a zero extent holds no elements and cannot be promoted.
+
+// CHECK-LABEL: func.func @zero_extent_alloca
+func.func @zero_extent_alloca() {
+  // CHECK: memref.alloca() : memref<0xf32>
+  %alloca = memref.alloca() : memref<0xf32>
+  return
+}
+
+// -----
+
+// CHECK-LABEL: func.func @zero_extent_alloca_multi_dim
+func.func @zero_extent_alloca_multi_dim() {
+  // CHECK: memref.alloca() : memref<2x0x3xf32>
+  %alloca = memref.alloca() : memref<2x0x3xf32>
+  return
+}
+
+// -----
+
+// Same for the scalable path: the extent is `vector.vscale * 0`, a constant
+// zero, so the scalable vector type cannot be built either.
----------------
FedericoBruzzone wrote:

```suggestion
// A memref with a `vector.vscale * 0` extent holds no elements and cannot be promoted.
```

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


More information about the Mlir-commits mailing list