<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 19, 2019 at 3:09 AM Timothy Arceri <<a href="mailto:tarceri@itsqueeze.com">tarceri@itsqueeze.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This helps reduce the amount of abstraction in this pass and allows<br>
us to retain more information about the src such as any swizzles.<br>
Retaining the swizzle information is required for a bugfix in the<br>
following patch.<br>
<br>
Fixes: 6772a17acc8e ("nir: Add a loop analysis pass")<br>
---<br>
 src/compiler/nir/nir_loop_analyze.c | 37 +++++++++++++++--------------<br>
 1 file changed, 19 insertions(+), 18 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c<br>
index e85a404da1b..57d2d94cad2 100644<br>
--- a/src/compiler/nir/nir_loop_analyze.c<br>
+++ b/src/compiler/nir/nir_loop_analyze.c<br>
@@ -543,25 +543,26 @@ guess_loop_limit(loop_info_state *state, nir_const_value *limit_val,<br>
 }<br>
<br>
 static bool<br>
-try_find_limit_of_alu(nir_loop_variable *limit, nir_const_value *limit_val,<br>
-                      nir_loop_terminator *terminator, loop_info_state *state)<br>
+try_find_limit_of_alu(nir_alu_src *limit, nir_const_value *limit_val,<br>
+                      nir_loop_terminator *terminator)<br>
 {<br>
-   if(!is_var_alu(limit))<br>
+   if(limit->src.ssa->parent_instr->type != nir_instr_type_alu)<br>
       return false;<br>
<br>
-   nir_alu_instr *limit_alu = nir_instr_as_alu(limit->def->parent_instr);<br>
+   nir_alu_instr *limit_alu = nir_instr_as_alu(limit->src.ssa->parent_instr);<br>
<br>
    if (limit_alu->op == nir_op_imin ||<br>
        limit_alu->op == nir_op_fmin) {<br>
-      limit = get_loop_var(limit_alu->src[0].src.ssa, state);<br>
+      limit = &limit_alu->src[0];<br>
<br>
-      if (!is_var_constant(limit))<br>
-         limit = get_loop_var(limit_alu->src[1].src.ssa, state);<br>
+      if (limit->src.ssa->parent_instr->type != nir_instr_type_load_const)<br>
+         limit = &limit_alu->src[1];<br></blockquote><div><br></div><div>This is still horribly broken w.r.t swizzles because we're not tracking the component as we make this or the jump above for [if]min.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
-      if (!is_var_constant(limit))<br>
+      if (limit->src.ssa->parent_instr->type != nir_instr_type_load_const)<br>
          return false;<br>
<br>
-      *limit_val = nir_instr_as_load_const(limit->def->parent_instr)->value[0];<br>
+      *limit_val =<br>
+         nir_instr_as_load_const(limit->src.ssa->parent_instr)->value[0];<br>
<br>
       terminator->exact_trip_count_unknown = true;<br>
<br>
@@ -777,19 +778,19 @@ is_supported_terminator_condition(nir_alu_instr *alu)<br>
<br>
 static bool<br>
 get_induction_and_limit_vars(nir_alu_instr *alu, nir_loop_variable **ind,<br>
-                             nir_loop_variable **limit,<br>
+                             nir_alu_src **limit,<br>
                              loop_info_state *state)<br>
 {<br>
    bool limit_rhs = true;<br>
<br>
    /* We assume that the limit is the "right" operand */<br>
    *ind = get_loop_var(alu->src[0].src.ssa, state);<br>
-   *limit = get_loop_var(alu->src[1].src.ssa, state);<br>
+   *limit = &alu->src[1];<br>
<br>
    if ((*ind)->type != basic_induction) {<br>
       /* We had it the wrong way, flip things around */<br>
       *ind = get_loop_var(alu->src[1].src.ssa, state);<br>
-      *limit = get_loop_var(alu->src[0].src.ssa, state);<br>
+      *limit = &alu->src[0];<br>
       limit_rhs = false;<br>
    }<br>
<br>
@@ -799,7 +800,7 @@ get_induction_and_limit_vars(nir_alu_instr *alu, nir_loop_variable **ind,<br>
 static void<br>
 try_find_trip_count_vars_in_iand(nir_alu_instr **alu,<br>
                                  nir_loop_variable **ind,<br>
-                                 nir_loop_variable **limit,<br>
+                                 nir_alu_src **limit,<br>
                                  bool *limit_rhs,<br>
                                  loop_info_state *state)<br>
 {<br>
@@ -848,7 +849,7 @@ try_find_trip_count_vars_in_iand(nir_alu_instr **alu,<br>
<br>
    /* Try the other iand src if needed */<br>
    if (*ind == NULL || (*ind && (*ind)->type != basic_induction) ||<br>
-       !is_var_constant(*limit)) {<br>
+       (*limit)->src.ssa->parent_instr->type != nir_instr_type_load_const) {<br>
       src = iand->src[1].src.ssa;<br>
       if (src->parent_instr->type == nir_instr_type_alu) {<br>
          nir_alu_instr *tmp_alu = nir_instr_as_alu(src->parent_instr);<br>
@@ -891,7 +892,7 @@ find_trip_count(loop_info_state *state)<br>
<br>
       bool limit_rhs;<br>
       nir_loop_variable *basic_ind = NULL;<br>
-      nir_loop_variable *limit;<br>
+      nir_alu_src *limit;<br>
       if (alu->op == nir_op_inot || alu->op == nir_op_ieq) {<br>
          nir_alu_instr *new_alu = alu;<br>
          try_find_trip_count_vars_in_iand(&new_alu, &basic_ind, &limit,<br>
@@ -931,13 +932,13 @@ find_trip_count(loop_info_state *state)<br>
<br>
       /* Attempt to find a constant limit for the loop */<br>
       nir_const_value limit_val;<br>
-      if (is_var_constant(limit)) {<br>
+      if (limit->src.ssa->parent_instr->type == nir_instr_type_load_const) {<br>
          limit_val =<br>
-            nir_instr_as_load_const(limit->def->parent_instr)->value[0];<br>
+            nir_instr_as_load_const(limit->src.ssa->parent_instr)->value[0];<br>
       } else {<br>
          trip_count_known = false;<br>
<br>
-         if (!try_find_limit_of_alu(limit, &limit_val, terminator, state)) {<br>
+         if (!try_find_limit_of_alu(limit, &limit_val, terminator)) {<br>
             /* Guess loop limit based on array access */<br>
             if (!guess_loop_limit(state, &limit_val, basic_ind)) {<br>
                continue;<br>
-- <br>
2.21.0<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a></blockquote></div></div>