Skip to content

Commit 5f9db08

Browse files
codemzsZeeshan Siddiqui
and
Zeeshan Siddiqui
authored
Allow SymbolUserOpInterface operators to be used in RemoveDeadValues Pass (#117405)
This change removes the restriction on `SymbolUserOpInterface` operators so they can be used with operators that implement `SymbolOpInterface`, example: `memref.global` implements `SymbolOpInterface` so it can be used with `memref.get_global` which implements `SymbolUserOpInterface` ``` // Define a global constant array memref.global "private" constant @global_array : memref<10xi32> = dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32> // Access this global constant within a function func @use_global() { %0 = memref.get_global @global_array : memref<10xi32> } ``` Reference: #116519 and https://discourse.llvm.org/t/question-on-criteria-for-acceptable-ir-in-removedeadvaluespass/83131 --------- Co-authored-by: Zeeshan Siddiqui <[email protected]>
1 parent 14b9ca3 commit 5f9db08

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

mlir/lib/Transforms/RemoveDeadValues.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,8 @@ void RemoveDeadValues::runOnOperation() {
577577
WalkResult acceptableIR = module->walk([&](Operation *op) {
578578
if (op == module)
579579
return WalkResult::advance();
580-
if (isa<BranchOpInterface>(op) ||
581-
(isa<SymbolUserOpInterface>(op) && !isa<CallOpInterface>(op))) {
582-
op->emitError() << "cannot optimize an IR with "
583-
"non-call symbol user ops or branch ops\n";
580+
if (isa<BranchOpInterface>(op)) {
581+
op->emitError() << "cannot optimize an IR with branch ops\n";
584582
return WalkResult::interrupt();
585583
}
586584
return WalkResult::advance();

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
// The IR is updated regardless of memref.global private constant
44
//
55
module {
6-
memref.global "private" constant @__something_global : memref<i32> = dense<0>
6+
// CHECK: memref.global "private" constant @__constant_4xi32 : memref<4xi32> = dense<[1, 2, 3, 4]> {alignment = 16 : i64}
7+
memref.global "private" constant @__constant_4xi32 : memref<4xi32> = dense<[1, 2, 3, 4]> {alignment = 16 : i64}
78
func.func @main(%arg0: i32) -> i32 {
89
%0 = tensor.empty() : tensor<10xbf16>
10+
// CHECK-NOT: memref.get_global
11+
%1 = memref.get_global @__constant_4xi32 : memref<4xi32>
912
// CHECK-NOT: tensor.empty
1013
return %arg0 : i32
1114
}
@@ -29,7 +32,7 @@ module @named_module_acceptable {
2932
//
3033
func.func @dont_touch_unacceptable_ir_has_cleanable_simple_op_with_branch_op(%arg0: i1) {
3134
%non_live = arith.constant 0 : i32
32-
// expected-error @+1 {{cannot optimize an IR with non-call symbol user ops or branch ops}}
35+
// expected-error @+1 {{cannot optimize an IR with branch ops}}
3336
cf.cond_br %arg0, ^bb1(%non_live : i32), ^bb2(%non_live : i32)
3437
^bb1(%non_live_0 : i32):
3538
cf.br ^bb3

0 commit comments

Comments
 (0)