[Mlir-commits] [mlir] [MLIR] Removing dead values for branches (PR #117501)
Renat Idrisov
llvmlistbot at llvm.org
Wed Dec 4 10:18:05 PST 2024
================
@@ -28,22 +28,50 @@ module @named_module_acceptable {
// -----
-// The IR remains untouched because of the presence of a branch op `cf.cond_br`.
+// The IR contains both conditional and unconditional branches with a loop
+// in which the last cf.cond_br is referncing the first cf.br
//
-func.func @dont_touch_unacceptable_ir_has_cleanable_simple_op_with_branch_op(%arg0: i1) {
+func.func @acceptable_ir_has_cleanable_loop_of_conditional_and_branch_op(%arg0: i1) {
%non_live = arith.constant 0 : i32
- // expected-error @+1 {{cannot optimize an IR with branch ops}}
- cf.cond_br %arg0, ^bb1(%non_live : i32), ^bb2(%non_live : i32)
-^bb1(%non_live_0 : i32):
- cf.br ^bb3
-^bb2(%non_live_1 : i32):
- cf.br ^bb3
-^bb3:
+ // CHECK-NOT: arith.constant
+ cf.br ^bb1(%non_live : i32)
+^bb1(%non_live_1 : i32):
+ // CHECK: ^[[BB1:bb[0-9]+]]:
+ %non_live_5 = arith.constant 1 : i32
+ cf.br ^bb3(%non_live_1, %non_live_5 : i32, i32)
+ // CHECK: cf.br ^[[BB3:bb[0-9]+]]
+ // CHECK-NOT: i32
+^bb3(%non_live_2 : i32, %non_live_6 : i32):
+ // CHECK: ^[[BB3]]:
+ cf.cond_br %arg0, ^bb1(%non_live_2 : i32), ^bb4(%non_live_2 : i32)
+ // CHECK: cf.cond_br %arg0, ^[[BB1]], ^[[BB4:bb[0-9]+]]
----------------
parsifal-47 wrote:
Correct, the difference between `^[[BB4:bb[0-9]+]]` and `^[[BB1]]` that the first one is matching the branch name which was generated by optimization, and the second one is using the name. If I understand the question correctly.
https://github.com/llvm/llvm-project/pull/117501
More information about the Mlir-commits
mailing list