[MLIR][SCF] Fix nested if merging bug
The current nested if merging has a bug. Specifically, consider the following code: ``` %r = scf.if %arg3 -> (i32) { scf.if %arg1 { "test.op"() : () -> () } scf.yield %arg0 : i32 } else { scf.yield %arg2 : i32 } ``` When the above gets merged, it will become: ``` %r = scf.if %arg3 && %arg1-> (i32) { "test.op"() : () -> () scf.yield %arg0 : i32 } else { scf.yield %arg2 : i32 } ``` However, this means that when only %arg3 is true, we will incorrectly return %arg2 instead of %arg0. This change updates the behavior of the pass to only enable nested if merging where the outer yield contains only values from the inner if, or values defined outside of the if. In the case of the latter, they can turned into a select of only the outer if condition, thus maintaining correctness. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D122108
Loading
Please sign in to comment