nir/lower_returns: Deal with single-arg phis after if.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 7 Jun 2021 00:50:09 +0000 (02:50 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 8 Jun 2021 11:29:53 +0000 (11:29 +0000)
commit6b7ff241f4254bee50566b20cac15d6745d30623
tree2b3954c5436849dbad77deb8fe5099438cfe2c88
parent9d772a545aadfd6f06b6ebe03b020c86d11921a9
nir/lower_returns: Deal with single-arg phis after if.

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.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11207>
src/compiler/nir/nir_lower_returns.c