nir/opt_if: Remove unneeded phis if we make progress
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 25 Jun 2018 23:18:19 +0000 (16:18 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 26 Jun 2018 17:47:26 +0000 (10:47 -0700)
Now that SSA values can be derefs and they have special rules, we have
to be a bit more careful about our LCSSA phis.  In particular, we need
to clean up in case LCSSA ended up creating a phi node for a deref.
This fixes validation issues with some Vulkan CTS tests with the new
deref instructions.

Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
src/compiler/nir/nir.h
src/compiler/nir/nir_opt_if.c
src/compiler/nir/nir_opt_remove_phis.c

index be7b92dd7d29d5fe98b7b5e42e27e57a6224bce4..c16ce547642b54c53a8b565b5fc7a8f017a9a9d2 100644 (file)
@@ -2903,6 +2903,7 @@ bool nir_opt_move_load_ubo(nir_shader *shader);
 
 bool nir_opt_peephole_select(nir_shader *shader, unsigned limit);
 
+bool nir_opt_remove_phis_impl(nir_function_impl *impl);
 bool nir_opt_remove_phis(nir_shader *shader);
 
 bool nir_opt_shrink_load(nir_shader *shader);
index 863ca630fbd0c6284adc6c4bfd75730699c488ac..ec5bf1c902742b4f980d8a980d5e7eac45e9e2b3 100644 (file)
@@ -403,6 +403,13 @@ nir_opt_if(nir_shader *shader)
           * that don't dominate their uses.
           */
          nir_lower_regs_to_ssa_impl(function->impl);
+
+         /* Calling nir_convert_loop_to_lcssa() in opt_peel_loop_initial_if()
+          * adds extra phi nodes which may not be valid if they're used for
+          * something such as a deref.  Remove any unneeded phis.
+          */
+         nir_opt_remove_phis_impl(function->impl);
+
          progress = true;
       }
    }
index b20ff729156cbb2e8306a36c2b510df6f4cd96be..e2d3994c49ed1ffebb5cfd36ef2dc67df6f2bf35 100644 (file)
@@ -139,8 +139,8 @@ remove_phis_block(nir_block *block, nir_builder *b)
    return progress;
 }
 
-static bool
-remove_phis_impl(nir_function_impl *impl)
+bool
+nir_opt_remove_phis_impl(nir_function_impl *impl)
 {
    bool progress = false;
    nir_builder bld;
@@ -165,7 +165,7 @@ nir_opt_remove_phis(nir_shader *shader)
 
    nir_foreach_function(function, shader)
       if (function->impl)
-         progress = remove_phis_impl(function->impl) || progress;
+         progress = nir_opt_remove_phis_impl(function->impl) || progress;
 
    return progress;
 }