[Mlir-commits] [mlir] [MLIR] Removing dead values for branches (PR #117501)
Mehdi Amini
llvmlistbot at llvm.org
Mon Nov 25 03:37:16 PST 2024
================
@@ -28,22 +28,58 @@ module @named_module_acceptable {
// -----
-// The IR remains untouched because of the presence of a branch op `cf.cond_br`.
+// The IR is optimized regardless of the presence of a branch op `cf.cond_br`.
//
-func.func @dont_touch_unacceptable_ir_has_cleanable_simple_op_with_branch_op(%arg0: i1) {
+func.func @acceptable_ir_has_cleanable_simple_op_with_branch_op(%arg0: i1) {
%non_live = arith.constant 0 : i32
- // expected-error @+1 {{cannot optimize an IR with branch ops}}
+ // CHECK-NOT: non_live
cf.cond_br %arg0, ^bb1(%non_live : i32), ^bb2(%non_live : i32)
^bb1(%non_live_0 : i32):
+ // CHECK-NOT: non_live_0
cf.br ^bb3
^bb2(%non_live_1 : i32):
+ // CHECK-NOT: non_live_1
cf.br ^bb3
^bb3:
return
}
// -----
+// Arguments of unconditional branch op `cf.br` are properly removed.
+//
+func.func @acceptable_ir_has_cleanable_simple_op_with_unconditional_branch_op(%arg0: i1) {
+ %non_live = arith.constant 0 : i32
+ // CHECK-NOT: non_live
+ cf.br ^bb1(%non_live : i32)
+^bb1(%non_live_1 : i32):
+ // CHECK-NOT: non_live_1
+ cf.br ^bb3
+^bb3:
+ return
+}
+
+// -----
+
+// Checking that iter_args are properly handled
+//
+func.func @cleanable_loop_iter_args_value(%arg0: index) -> index {
+ %c0 = arith.constant 0 : index
+ %c1 = arith.constant 1 : index
+ %c10 = arith.constant 10 : index
+ %non_live = arith.constant 0 : index
+ // CHECK-NOT: non_live
----------------
joker-eph wrote:
The names are never propagated, I don't quite see how these check could test anything actually?
I believe you need to actually check that there is a single item_args.
https://github.com/llvm/llvm-project/pull/117501
More information about the Mlir-commits
mailing list