[Mlir-commits] [mlir] [mlir][RemoveDeadValues] Simplify branch op handling using ub.poison (PR #182711)
Matthias Springer
llvmlistbot at llvm.org
Thu Feb 26 03:31:39 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)
----------------
matthias-springer wrote:
To give some background on `RemoveDeadValues`: this pass has broken for a long time and we have fixed numerous bugs over the last year. In the beginning, by patching up issues, as you tried in the beginning. But we always ran into more problems.
It turned out that a better design is to keep this pass as minimal as possible. Ideally, the canonicalizer pass would already perform all of these optimizations, but it has only local knowledge about the IR. That's because it cannot perform a dataflow analysis, which would give additional insight about the liveness of values.
The new, improved design is to use `RemoveDeadValues` to just "inject" the required information into the IR. E.g., by swapping out uses with `ub.poison`. Afterwards, the canonicalizer pass can take over.
https://github.com/llvm/llvm-project/pull/182711
More information about the Mlir-commits
mailing list