Mesa (19.0): nir: Take if_uses into account when repairing SSA

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Apr 11 03:34:49 UTC 2019


Module: Mesa
Branch: 19.0
Commit: b493686860342734875ae1e133b004de98ad53e4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b493686860342734875ae1e133b004de98ad53e4

Author: Caio Marcelo de Oliveira Filho <caio.oliveira at intel.com>
Date:   Thu Apr  4 12:46:42 2019 -0700

nir: Take if_uses into account when repairing SSA

If a def is used as an condition before its definition, we should also
consider this a case to repair.  When repairing, make sure we rewrite
any if conditions too.

Found in while inspecting a SPIR-V conversion from a 'continue block'
that contains a conditional branch.  We pull the continue block up to
the beggining of the loop, and the condition in the branch ends up
defined afterwards.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Fixes: 364212f1ede4b "nir: Add a pass to repair SSA form"
(cherry picked from commit c037dbb0efad573aab1467befd35d2c4f4cdbbce)

---

 src/compiler/nir/nir_repair_ssa.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/compiler/nir/nir_repair_ssa.c b/src/compiler/nir/nir_repair_ssa.c
index b4d22d91c27..f182818374d 100644
--- a/src/compiler/nir/nir_repair_ssa.c
+++ b/src/compiler/nir/nir_repair_ssa.c
@@ -77,6 +77,15 @@ repair_ssa_def(nir_ssa_def *def, void *void_state)
       }
    }
 
+   nir_foreach_if_use(src, def) {
+      nir_block *block_before_if =
+         nir_cf_node_as_block(nir_cf_node_prev(&src->parent_if->cf_node));
+      if (!nir_block_dominates(def->parent_instr->block, block_before_if)) {
+         is_valid = false;
+         break;
+      }
+   }
+
    if (is_valid)
       return true;
 
@@ -98,6 +107,15 @@ repair_ssa_def(nir_ssa_def *def, void *void_state)
       }
    }
 
+   nir_foreach_if_use_safe(src, def) {
+      nir_block *block_before_if =
+         nir_cf_node_as_block(nir_cf_node_prev(&src->parent_if->cf_node));
+      if (!nir_block_dominates(def->parent_instr->block, block_before_if)) {
+         nir_if_rewrite_condition(src->parent_if, nir_src_for_ssa(
+            nir_phi_builder_value_get_block_def(val, block_before_if)));
+      }
+   }
+
    return true;
 }
 




More information about the mesa-commit mailing list