[Mlir-commits] [mlir] [mlir][RemoveDeadValues] Simplify branch op handling using ub.poison (PR #182711)

Fedor Nikolaev llvmlistbot at llvm.org
Thu Feb 26 03:11:22 PST 2026


================
@@ -35,20 +35,26 @@ module @named_module_acceptable {
 func.func @acceptable_ir_has_cleanable_loop_of_conditional_and_branch_op(%arg0: i1) {
   %non_live = arith.constant 0 : i32
   // CHECK-NOT: arith.constant
+  // CHECK-CANONICALIZE-NOT: arith.constant
   cf.br ^bb1(%non_live : i32)
-  // CHECK: cf.br ^[[BB1:bb[0-9]+]]
+  // CHECK: cf.br ^[[BB1:bb[0-9]+]](%{{.*}} : i32)
+  // CHECK-CANONICALIZE: cf.br ^[[BB1:bb[0-9]+]](%{{.*}} : i32)
 ^bb1(%non_live_1 : i32):
-  // CHECK: ^[[BB1]]:
+  // CHECK: ^[[BB1]](%{{.*}}: i32):
+  // CHECK-CANONICALIZE: ^[[BB1]](%{{.*}}: i32):
   %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
+  // CHECK: cf.br ^[[BB3:bb[0-9]+]](%{{.*}}, %{{.*}} : i32, i32)
+  // CHECK-CANONICALIZE: cf.br ^[[BB3:bb[0-9]+]](%{{.*}}, %{{.*}} : i32, i32)
----------------
felichita wrote:

The canonicalizer doesn't  simplify the IR at all in this case. Unfortunately, the output before and after canonicalization is identical.
```
  func.func @acceptable_ir_has_cleanable_loop_of_conditional_and_branch_op(%arg0: i1) {
    %0 = ub.poison : i32
    cf.br ^bb1(%0 : i32)
  ^bb1(%1: i32):  // 2 preds: ^bb0, ^bb2
    %2 = ub.poison : i32
    %3 = ub.poison : i32
    cf.br ^bb2(%2, %3 : i32, i32)
  ^bb2(%4: i32, %5: i32):  // pred: ^bb1
    %6 = ub.poison : i32
    %7 = ub.poison : i32
    cf.cond_br %arg0, ^bb1(%6 : i32), ^bb3(%7 : i32)
  ^bb3(%8: i32):  // pred: ^bb2
    return
  }
}
```

The existing `simplifyBrToBlockWithSinglePred` pattern only handles blocks with a single predecessor. There is no pattern that handles the case you described above, when all predecessor values for a block argument are the same `ub.poison`.

To fix the regression, I would need to add a new canonicalization pattern to `ControlFlowOps.cpp` that replaces uses of a block argument with the common incoming value...

https://github.com/llvm/llvm-project/pull/182711


More information about the Mlir-commits mailing list