Information on Reduce-Branching-Through-Overcompute pass and how to extend the pass if needed

Hello @Lunderberg,

Your insights will be highly helpful here.

I had couple of questions on the “ReduceBranchingThroughOvercompute” pass and the test file “test_tir_transform_reduce_branching_through_overcompute.py”:

  1. The test cases in this file are on lowered IR where the “ReduceBranchingThroughOvercompute” pass is used. Will the pass work if there are blocks in the IR?

  2. If it does not work with blocks, is there any scope to extend the pass to make it work with blocks? And can you give a brief idea over how we can achieve it?

  3. There are some test cases present in the “test_tir_transform_reduce_branching_through_overcompute.py” file which eliminates the if statement when T.assume is present and does the over compute. Will the pass work to eliminate both if and else statement (leveraging from assumptions present in T.assume) when the value assigned to the variable is different in the if and else?

  4. How do we use the pass to eliminate both the if and else statements? If the pass does not eliminate both if and else statements is there any way to extend it for the scenario mentioned in the below image?

(I have seen an example which eliminates if and else condition only if the variable is assigned same value inside the if and else condition example : TestIntroduceNoOp which is completely different scenario)

For example, I wanted to do something like this but at the block level:

if_then_else_elimination

Here I have modified the existing “TestIntroduceAdditionOfKnownZeroInBuffer” test in the test “test_tir_transform_reduce_branching_through_overcompute.py”. Here the condition i>=14 A[i] will be 0 as per the assumption and hence we can overcompute and eliminate the if then else expression. But the pass does not eliminate the if then else in this example.