[Mlir-commits] [mlir] [mlir][cf] Canonicalize block args with uniform incoming values (PR #183966)
Fedor Nikolaev
llvmlistbot at llvm.org
Wed Mar 4 02:32:25 PST 2026
================
@@ -686,3 +686,87 @@ func.func @no_merge_self_arg_loop(%step: i1) -> i1 {
^exit(%result: i1):
return %result : i1
}
+
+// Verify that block arguments are replaced with a uniform incoming value
+// when all predecessors pass the same SSA value
+
+// CHECK-LABEL: func @fold_uniform_branch_block_arg
+// CHECK-SAME: %[[COND:.*]]: i1, %[[C:.*]]: i32
+func.func @fold_uniform_branch_block_arg(%cond: i1, %c: i32) -> i32 {
+ cf.cond_br %cond, ^bb1, ^bb2
+^bb1:
+ "foo.op"() : () -> ()
+ cf.br ^bb3(%c : i32)
+^bb2:
+ "foo.op"() : () -> ()
+ cf.br ^bb3(%c : i32)
+^bb3(%arg0: i32):
+ // CHECK: ^bb3:
+ // CHECK: return %[[C]]
+ return %arg0 : i32
+}
+
+// Verify that block arguments are not folded when incoming values differ
+// across predecessors.
+
+// CHECK-LABEL: func @no_fold_non_uniform_block_arg
+// CHECK-SAME: %[[COND:.*]]: i1, %[[A:.*]]: i32, %[[B:.*]]: i32
+func.func @no_fold_non_uniform_block_arg(%cond: i1, %a: i32, %b: i32) -> i32 {
+ cf.cond_br %cond, ^bb1, ^bb2
+^bb1:
+ "foo.op"() : () -> ()
+ cf.br ^bb3(%a : i32)
+^bb2:
+ "foo.op"() : () -> ()
+ cf.br ^bb3(%b : i32)
+^bb3(%arg0: i32):
+ // CHECK: ^bb3(%[[ARG0:.*]]: i32):
+ // CHECK-NEXT: return %[[ARG0]]
+ return %arg0 : i32
+}
+
+// Verify no folding when the same block appears multiple times as a
+// successor with different operands.
+
+// CHECK-LABEL: func @no_fold_same_dest_different_args
+func.func @no_fold_same_dest_different_args(%a: i32, %b: i32) -> i32 {
+ "test.producing_br"(%a, %b)[^bb1, ^bb1]
----------------
felichita wrote:
Done
https://github.com/llvm/llvm-project/pull/183966
More information about the Mlir-commits
mailing list