nir/opt_remove_phis: handle phis with no sources
authorRhys Perry <pendingchaos02@gmail.com>
Mon, 23 Sep 2019 13:48:22 +0000 (14:48 +0100)
committerRhys Perry <pendingchaos02@gmail.com>
Wed, 25 Sep 2019 00:58:30 +0000 (00:58 +0000)
This can happen with loops with unreachable exits which are later
optimized away.

Fixes assertion in dEQP-VK.graphicsfuzz.unreachable-loops with RADV.

Cc: mesa-stable@lists.freedesktop.org
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir_opt_remove_phis.c

index a31861167986d6ba956f350803133761d0a052b4..36e01ff724541944366beb7a227fc816d58fc142 100644 (file)
@@ -109,12 +109,13 @@ remove_phis_block(nir_block *block, nir_builder *b)
       if (!srcs_same)
          continue;
 
-      /* We must have found at least one definition, since there must be at
-       * least one forward edge.
-       */
-      assert(def != NULL);
+      if (!def) {
+         /* In this case, the phi had no sources. So turn it into an undef. */
 
-      if (mov) {
+         b->cursor = nir_after_phis(block);
+         def = nir_ssa_undef(b, phi->dest.ssa.num_components,
+                             phi->dest.ssa.bit_size);
+      } else if (mov) {
          /* If the sources were all movs from the same source with the same
           * swizzle, then we can't just pick a random move because it may not
           * dominate the phi node. Instead, we need to emit our own move after