Skip to content

nir/lower_returns: Deal with single-arg phis after if.

Bas Nieuwenhuizen requested to merge bnieuwenhuizen/mesa:lower-return-phi into main

if we have

   if ... {
      return;
   } else {
      // block X
   }
   // block Y
   phi(X: ...)

then nir_lower_returns tries to move block Y into the else body, except nir_cf_extract doesn't move the phi. As the return is removed in the then-body the phi suddenly has the wrong number of arguments (and the phi doesn't dominate its uses anymore).

In this case we know that the phi has to be single arg, so we can just rewrite the users of the phis and drop them.

Hit this in my RT adventures, not sure if this is actually reachable right now, as single arg phis tend to be kind of exceptional outside of CSSA and we typically call nir_lower_returns pretty early.

Edited by Bas Nieuwenhuizen

Merge request reports