Mesa (master): nir/opt_remove_phis: optimize out phis with undef

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 19 13:46:43 UTC 2020


Module: Mesa
Branch: master
Commit: 60dae98456830a6a1d0b28e22555e9faec948a32
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=60dae98456830a6a1d0b28e22555e9faec948a32

Author: Rhys Perry <pendingchaos02 at gmail.com>
Date:   Mon Aug 17 12:18:24 2020 +0100

nir/opt_remove_phis: optimize out phis with undef

This removes some phis that loop unrolling can create.

fossil-db (Navi):
Totals from 349 (0.26% of 135946) affected shaders:
SpillSGPRs: 52 -> 41 (-21.15%)
CodeSize: 3179968 -> 3169920 (-0.32%); split: -0.33%, +0.01%
Instrs: 626965 -> 624712 (-0.36%); split: -0.37%, +0.01%

Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6348>

---

 src/compiler/nir/nir_opt_remove_phis.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/compiler/nir/nir_opt_remove_phis.c b/src/compiler/nir/nir_opt_remove_phis.c
index 966a982516e..db58c618f6b 100644
--- a/src/compiler/nir/nir_opt_remove_phis.c
+++ b/src/compiler/nir/nir_opt_remove_phis.c
@@ -52,7 +52,7 @@ matching_mov(nir_alu_instr *mov1, nir_ssa_def *ssa)
  * This is a pass for removing phi nodes that look like:
  * a = phi(b, b, b, ...)
  *
- * Note that we can't ignore undef sources here, or else we may create a
+ * Note that we can't always ignore undef sources here, or else we may create a
  * situation where the definition of b isn't dominated by its uses. We're
  * allowed to do this since the definition of b must dominate all of the
  * phi node's predecessors, which means it must dominate the phi node as well
@@ -98,6 +98,9 @@ remove_phis_block(nir_block *block, nir_builder *b)
          if (def == NULL) {
             def  = src->src.ssa;
             mov = get_parent_mov(def);
+         } else if (src->src.ssa->parent_instr->type == nir_instr_type_ssa_undef &&
+                    nir_block_dominates(def->parent_instr->block, src->pred)) {
+            /* Ignore this undef source. */
          } else {
             if (src->src.ssa != def && !matching_mov(mov, src->src.ssa)) {
                srcs_same = false;
@@ -153,6 +156,8 @@ nir_opt_remove_phis_impl(nir_function_impl *impl)
    nir_builder bld;
    nir_builder_init(&bld, impl);
 
+   nir_metadata_require(impl, nir_metadata_dominance);
+
    nir_foreach_block(block, impl) {
       progress |= remove_phis_block(block, &bld);
    }



More information about the mesa-commit mailing list