Skip to content

nir/dead_cf: Remove if statement if one branch has infinite loop

Danylo Piliaiev requested to merge GL/mesa:fix/infinite-loop-in-if-stmt into main

If one branch has infinite loop it's not enough to remove this branch. Removing it may break previous optimizations which were made on assumption that the branch with infinite loop doesn't dominate other blocks.

Closes: #2357 (closed)

No regressions in CI:

Consider such NIR:

vec1 1 ssa_1 = ...
if ssa_1 {
    block block_2:
    vec2 32 ssa_2 = %some_calculation_result%
    vec2 32 ssa_3 = intrinsic load_deref (ssa_2)
} else {
    block block_3:
    loop {
	block block_4:

vec1 1 ssa_4 = load_const (true)
if ssa_4 {
    vec1 32 ssa_5 = intrinsic load_deref (ssa_2) 

Here while ssa_2 is defined in one of the branches it's ok for block_6 to use it since other branch doesn't dominate anything. Previously opt_dead_cf removed the loop, breaking previous assumption. With my changes if statement is removed leaving only the contents of the branch without the infinite loop.

Edited by Tapani Pälli

Merge request reports