Skip to content

Commit ee5dcdc

Browse files
Menookerbanach-spacejoker-eph
authored
[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@gmail.com> Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
1 parent 96493c5 commit ee5dcdc

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

mlir/lib/Transforms/RemoveDeadValues.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,9 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
750750
}
751751

752752
// 4. Operands
753-
for (auto &o : list.operands) {
754-
o.op->eraseOperands(o.nonLive);
753+
for (OperationToCleanup &o : list.operands) {
754+
if (o.op->getNumOperands() > 0)
755+
o.op->eraseOperands(o.nonLive);
755756
}
756757

757758
// 5. Results

mlir/test/Transforms/remove-dead-values.mlir

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,28 @@ module {
511511
// CHECK: linalg.yield %[[yield]] : f32
512512
// CHECK-NOT: arith.subf
513513

514+
515+
// -----
516+
517+
// check that ops with zero operands are correctly handled
518+
519+
module {
520+
func.func @test_zero_operands(%I: memref<10xindex>, %I2: memref<10xf32>) {
521+
%v0 = arith.constant 0 : index
522+
%result = memref.alloca_scope -> index {
523+
%c = arith.addi %v0, %v0 : index
524+
memref.store %c, %I[%v0] : memref<10xindex>
525+
memref.alloca_scope.return %c: index
526+
}
527+
func.return
528+
}
529+
}
530+
531+
// CHECK-LABEL: func @test_zero_operands
532+
// CHECK: memref.alloca_scope
533+
// CHECK: memref.store
534+
// CHECK-NOT: memref.alloca_scope.return
535+
514536
// -----
515537

516538
// CHECK-LABEL: func.func @test_atomic_yield
@@ -525,3 +547,4 @@ func.func @test_atomic_yield(%I: memref<10xf32>, %idx : index) {
525547
}
526548
func.return
527549
}
550+

0 commit comments

Comments
 (0)