[Mesa-dev] [PATCH 3/3] rSQUASH/i965/opt_move_comparisons: rework phi handling

Jason Ekstrand jason at jlekstrand.net
Wed Jan 11 20:48:28 UTC 2017


---
 src/compiler/nir/nir_opt_move_comparisons.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/compiler/nir/nir_opt_move_comparisons.c b/src/compiler/nir/nir_opt_move_comparisons.c
index 2bfd940..617c2ca 100644
--- a/src/compiler/nir/nir_opt_move_comparisons.c
+++ b/src/compiler/nir/nir_opt_move_comparisons.c
@@ -84,8 +84,7 @@ move_comparison_source(nir_src *src, nir_block *block, nir_instr *before)
 
    if (src_instr->block == block &&
        src_instr->type == nir_instr_type_alu &&
-       is_comparison(nir_instr_as_alu(src_instr)->op) &&
-       (!before || before->type != nir_instr_type_phi)) {
+       is_comparison(nir_instr_as_alu(src_instr)->op)) {
 
       exec_node_remove(&src_instr->node);
 
@@ -135,7 +134,18 @@ move_comparisons(nir_block *block)
    }
 
    nir_foreach_instr_reverse(instr, block) {
-      if (instr->type == nir_instr_type_alu) {
+      /* The sources of phi instructions happen after the predecessor block
+       * but before this block.  (Yes, that's between blocks).  This means
+       * that we don't need to move them in order for them to be correct.
+       * We could move them to encourage comparisons that are used in a phi to
+       * the end of the block, doing so correctly would make the pass
+       * substantially more complicated and wouldn't gain us anything since
+       * the phi can't use a flag value anyway.
+       */
+      if (instr->type == nir_instr_type_phi) {
+         /* We're going backwards so everything else is a phi too */
+         break;
+      } else if (instr->type == nir_instr_type_alu) {
          /* Walk ALU instruction sources backwards so that bcsel's boolean
           * condition is processed last.
           */
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list