[Mlir-commits] [mlir] ee5dcdc - [mlir] fix assertion failure in remove-dead-values (#144849)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Jun 22 07:03:40 PDT 2025


Author: Menooker
Date: 2025-06-22T23:03:36+09:00
New Revision: ee5dcdc275b136172a5bfa85a098ae506a836c85

URL: https://github.com/llvm/llvm-project/commit/ee5dcdc275b136172a5bfa85a098ae506a836c85
DIFF: https://github.com/llvm/llvm-project/commit/ee5dcdc275b136172a5bfa85a098ae506a836c85.diff

LOG: [mlir] fix assertion failure in remove-dead-values (#144849)

Simple IR patterns will trigger assertion error:

```
  func.func @test_zero_operands(%I: memref<10xindex>, %I2: memref<10xf32>) {
    %v0 = arith.constant 0 : index
    %result = memref.alloca_scope -> index {
      %c = arith.addi %v0, %v0 : index
      memref.store %c, %I[%v0] : memref<10xindex>
      memref.alloca_scope.return %c: index
    }
    func.return
  }
```

with error: `mlir/include/mlir/IR/Operation.h:988:
mlir::detail::OperandStorage& mlir::Operation::getOperandStorage():
Assertion `hasOperandStorage && "expected operation to have operand
storage"' failed.`

This PR will fix this issue.

---------

Co-authored-by: Andrzej WarzyƄski <andrzej.warzynski at gmail.com>
Co-authored-by: Mehdi Amini <joker.eph at gmail.com>

Added: 
    

Modified: 
    mlir/lib/Transforms/RemoveDeadValues.cpp
    mlir/test/Transforms/remove-dead-values.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index ad21ce8f18700..0a02a01977cac 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -750,8 +750,9 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
   }
 
   // 4. Operands
-  for (auto &o : list.operands) {
-    o.op->eraseOperands(o.nonLive);
+  for (OperationToCleanup &o : list.operands) {
+    if (o.op->getNumOperands() > 0)
+      o.op->eraseOperands(o.nonLive);
   }
 
   // 5. Results

diff  --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index e55a9160f5b34..3af95db3c0e24 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -511,6 +511,28 @@ module {
 // CHECK: linalg.yield %[[yield]] : f32
 // CHECK-NOT: arith.subf
 
+
+// -----
+
+// check that ops with zero operands are correctly handled
+
+module {
+  func.func @test_zero_operands(%I: memref<10xindex>, %I2: memref<10xf32>) {
+    %v0 = arith.constant 0 : index
+    %result = memref.alloca_scope -> index {
+      %c = arith.addi %v0, %v0 : index
+      memref.store %c, %I[%v0] : memref<10xindex>
+      memref.alloca_scope.return %c: index
+    }
+    func.return
+  }
+}
+
+// CHECK-LABEL: func @test_zero_operands
+// CHECK: memref.alloca_scope
+// CHECK: memref.store
+// CHECK-NOT: memref.alloca_scope.return
+
 // -----
 
 // CHECK-LABEL: func.func @test_atomic_yield
@@ -525,3 +547,4 @@ func.func @test_atomic_yield(%I: memref<10xf32>, %idx : index) {
   }
   func.return
 }
+


        


More information about the Mlir-commits mailing list