[Mesa-dev] [PATCH 2/3] nir: match constant bools with @bool type

Timothy Arceri tarceri at itsqueeze.com
Thu Jul 19 03:29:51 UTC 2018


For simplicity we only allow this to work for scalar types.
---
 src/compiler/nir/nir_search.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/compiler/nir/nir_search.c b/src/compiler/nir/nir_search.c
index 743ffdf232c..c0224ca4360 100644
--- a/src/compiler/nir/nir_search.c
+++ b/src/compiler/nir/nir_search.c
@@ -49,10 +49,11 @@ static const uint8_t identity_swizzle[] = { 0, 1, 2, 3 };
  * Used for satisfying 'a at type' constraints.
  */
 static bool
-src_is_type(nir_src src, nir_alu_type type)
+src_is_type(nir_alu_src alu_src, nir_alu_type type, unsigned num_components)
 {
    assert(type != nir_type_invalid);
 
+   nir_src src = alu_src.src;
    if (!src.is_ssa)
       return false;
 
@@ -69,13 +70,18 @@ src_is_type(nir_src src, nir_alu_type type)
          case nir_op_iand:
          case nir_op_ior:
          case nir_op_ixor:
-            return src_is_type(src_alu->src[0].src, nir_type_bool) &&
-                   src_is_type(src_alu->src[1].src, nir_type_bool);
+            return src_is_type(src_alu->src[0], nir_type_bool,
+                               nir_ssa_alu_instr_src_components(src_alu, 0)) &&
+                   src_is_type(src_alu->src[1], nir_type_bool,
+                               nir_ssa_alu_instr_src_components(src_alu, 1));
          case nir_op_inot:
-            return src_is_type(src_alu->src[0].src, nir_type_bool);
+            return src_is_type(src_alu->src[0], nir_type_bool,
+                               nir_ssa_alu_instr_src_components(src_alu, 0));
          case nir_op_bcsel:
-            return src_is_type(src_alu->src[1].src, nir_type_bool) &&
-                   src_is_type(src_alu->src[2].src, nir_type_bool);
+            return src_is_type(src_alu->src[1], nir_type_bool,
+                               nir_ssa_alu_instr_src_components(src_alu, 1)) &&
+                   src_is_type(src_alu->src[2], nir_type_bool,
+                               nir_ssa_alu_instr_src_components(src_alu, 2));
          default:
             break;
          }
@@ -89,6 +95,14 @@ src_is_type(nir_src src, nir_alu_type type)
          return intr->intrinsic == nir_intrinsic_load_front_face ||
                 intr->intrinsic == nir_intrinsic_load_helper_invocation;
       }
+   } else if (src.ssa->parent_instr->type == nir_instr_type_load_const) {
+      nir_load_const_instr *load =
+         nir_instr_as_load_const(src.ssa->parent_instr);
+
+      if (type == nir_type_bool && num_components == 1) {
+         return load->value.u32[alu_src.swizzle[0]] == NIR_TRUE ||
+                load->value.u32[alu_src.swizzle[0]] == NIR_FALSE;
+      }
    }
 
    /* don't know */
@@ -162,7 +176,8 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,
             return false;
 
          if (var->type != nir_type_invalid &&
-             !src_is_type(instr->src[src].src, var->type))
+             !src_is_type(instr->src[src], var->type,
+                          nir_ssa_alu_instr_src_components(instr, src)))
             return false;
 
          state->variables_seen |= (1 << var->variable);
-- 
2.17.1



More information about the mesa-dev mailing list