[MLIR] `remove-dead-values` produce invalid IR for dead block argument with mixed-liveness predecessors
remove-dead-values can produce invalid IR when a dead successor block argument has multiple predecessors whose incoming values have different liveness.
Input Program
input.mlir
module {
func.func @multi_pred_mixed(%arg0: i1, %arg1: i32) -> i32 {
%c0_i32 = arith.constant 0 : i32
cf.cond_br %arg0, ^bb1, ^bb2
^bb1: // pred: ^bb0
cf.br ^bb3(%c0_i32 : i32)
^bb2: // pred: ^bb0
cf.br ^bb3(%arg1 : i32)
^bb3(%0: i32): // 2 preds: ^bb1, ^bb2
return %arg1 : i32
}
}
Current Result
input.mlir:10:5: error: branch has 1 operands for successor #0, but target block has 0
cf.br ^join(%x : i32)
^
input.mlir:10:5: note: see current operation: "cf.br"(%arg1)[^bb3] : (i32) -> ()
%arg is unused, so the pass removes the block argument. But it only removes the corresponding operand from one predecessor, leaving the other branch still passing an operand to a block with no arguments.
Expected behavior: produce valid IR
Version: ef88536bbf62469eb2396d719d237b3191cf4843
@llvm/issue-subscribers-mlir
Author: MonSec-2077
Input Program
input.mlir
module {
func.func @<!-- -->multi_pred_mixed(%arg0: i1, %arg1: i32) -> i32 {
%c0_i32 = arith.constant 0 : i32
cf.cond_br %arg0, ^bb1, ^bb2
^bb1: // pred: ^bb0
cf.br ^bb3(%c0_i32 : i32)
^bb2: // pred: ^bb0
cf.br ^bb3(%arg1 : i32)
^bb3(%0: i32): // 2 preds: ^bb1, ^bb2
return %arg1 : i32
}
}
Current Result
input.mlir:10:5: error: branch has 1 operands for successor #<!-- -->0, but target block has 0
cf.br ^join(%x : i32)
^
input.mlir:10:5: note: see current operation: "cf.br"(%arg1)[^bb3] : (i32) -> ()
%arg is unused, so the pass removes the block argument. But it only removes the corresponding operand from one predecessor, leaving the other branch still passing an operand to a block with no arguments.
Expected behavior: produce valid IR
Version: ef88536bbf62469eb2396d719d237b3191cf4843
hi, can I take a look at this if it's fine?
hi, can I take a look at this if it's fine?
Just prepare pull request and mention it on this page.
You may, but look at open PRs touching remove-dead-value first.