Merge more kinds of consecutive if-statements
There is a NIR optimization pass that merges consecutive if-statements that have the same condition and no intervening code. It may also be beneficial to merge if-statements with the same condition an a small number of intervening instructions. For example, some CS:GO fragment shaders have sequences like
if (some_uniform) {
// Piles of code
} else {
// Some code
}
// 3 or 4 instructions worth of code
if (some_uniform) {
// Some code
}
It seems like it would be better to duplicate the code between the two if-statements (with some threshold similar to various if-flattening passes), then merge the two if-statements. Perhaps this sort of merging should only occur (or maybe the threshold adjusted) when the condition is uniform.
I'm tagging @tarceri, @cwabbott0, and @jekstrand for input and perhaps pointers to existing code that I don't know about.