Module: Mesa
Branch: staging/19.1
Commit: cad015acb5d3c97c157ae3dbb21b7ac653995286
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=cad015acb5d3c97c157ae3dbb21b7ac653995286

Author: Jason Ekstrand <[email protected]>
Date:   Wed Jul 10 15:14:42 2019 -0500

nir/opt_if: Clean up single-src phis in opt_if_loop_terminator

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=111071
Fixes: 2a74296f24ba "nir: add opt_if_loop_terminator()"
Reviewed-by: Timothy Arceri <[email protected]>
(cherry picked from commit 7a19e05e8c84152af3a15868f5ef781142ac8e23)

---

 src/compiler/nir/nir.h                 | 1 +
 src/compiler/nir/nir_opt_if.c          | 7 +++++++
 src/compiler/nir/nir_opt_remove_phis.c | 8 ++++++++
 3 files changed, 16 insertions(+)

diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index c53979a2e42..35eac775e74 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -3649,6 +3649,7 @@ bool nir_opt_peephole_select(nir_shader *shader, unsigned 
limit,
                              bool indirect_load_ok, bool expensive_alu_ok);
 
 bool nir_opt_remove_phis(nir_shader *shader);
+bool nir_opt_remove_phis_block(nir_block *block);
 
 bool nir_opt_shrink_load(nir_shader *shader);
 
diff --git a/src/compiler/nir/nir_opt_if.c b/src/compiler/nir/nir_opt_if.c
index f674185f1e2..912580be840 100644
--- a/src/compiler/nir/nir_opt_if.c
+++ b/src/compiler/nir/nir_opt_if.c
@@ -1040,6 +1040,13 @@ opt_if_loop_terminator(nir_if *nif)
    if (!nir_is_trivial_loop_if(nif, break_blk))
       return false;
 
+   /* Even though this if statement has a jump on one side, we may still have
+    * phis afterwards.  Single-source phis can be produced by loop unrolling
+    * or dead control-flow passes and are perfectly legal.  Run a quick phi
+    * removal on the block after the if to clean up any such phis.
+    */
+   
nir_opt_remove_phis_block(nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node)));
+
    /* Finally, move the continue from branch after the if-statement. */
    nir_cf_list tmp;
    nir_cf_extract(&tmp, nir_before_block(first_continue_from_blk),
diff --git a/src/compiler/nir/nir_opt_remove_phis.c 
b/src/compiler/nir/nir_opt_remove_phis.c
index 9efbf422624..b03a0ab41b3 100644
--- a/src/compiler/nir/nir_opt_remove_phis.c
+++ b/src/compiler/nir/nir_opt_remove_phis.c
@@ -139,6 +139,14 @@ remove_phis_block(nir_block *block, nir_builder *b)
    return progress;
 }
 
+bool
+nir_opt_remove_phis_block(nir_block *block)
+{
+   nir_builder b;
+   nir_builder_init(&b, nir_cf_node_get_function(&block->cf_node));
+   return remove_phis_block(block, &b);
+}
+
 static bool
 nir_opt_remove_phis_impl(nir_function_impl *impl)
 {

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to