<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Thu, Dec 6, 2018 at 9:09 PM 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">Here we rework force_unroll_array_access() so that we can reused<br></blockquote><div><br></div><div>"reuse"<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">
the induction variable detection in a following patch.<br>
<br>
Reviewed-by: Thomas Helland <<a href="mailto:thomashelland90@gmail.com" target="_blank">thomashelland90@gmail.com</a>><br>
---<br>
 src/compiler/nir/nir_loop_analyze.c | 49 ++++++++++++++++++++---------<br>
 1 file changed, 35 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c<br>
index 700d1fe552..eef224e4d5 100644<br>
--- a/src/compiler/nir/nir_loop_analyze.c<br>
+++ b/src/compiler/nir/nir_loop_analyze.c<br>
@@ -350,6 +350,38 @@ find_loop_terminators(loop_info_state *state)<br>
    return success;<br>
 }<br>
<br>
+/* This function looks for an array access within a loop that uses an<br>
+ * induction variable for the array index. If found it returns the size of the<br>
+ * array, otherwise 0 is returned. If we find an induction var we pass it back<br>
+ * to the caller via array_index_out.<br>
+ */<br>
+static unsigned<br>
+find_array_access_via_induction(loop_info_state *state,<br>
+                                nir_deref_instr *deref,<br>
+                                nir_loop_variable **array_index_out)<br>
+{<br>
+   for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) {<br>
+      if (d->deref_type != nir_deref_type_array)<br>
+         continue;<br>
+<br>
+      assert(d->arr.index.is_ssa);<br>
+      nir_loop_variable *array_index = get_loop_var(d->arr.index.ssa, state);<br>
+<br>
+      if (array_index->type != basic_induction)<br>
+         continue;<br>
+<br>
+      if (array_index_out)<br>
+         *array_index_out = array_index;<br>
+<br>
+      nir_deref_instr *parent = nir_deref_instr_parent(d);<br>
+      assert(glsl_type_is_array_or_matrix(parent->type));<br>
+<br>
+      return glsl_get_length(parent->type);<br>
+   }<br>
+<br>
+   return 0;<br>
+}<br>
+<br>
 static int32_t<br>
 get_iteration(nir_op cond_op, nir_const_value *initial, nir_const_value *step,<br>
               nir_const_value *limit)<br>
@@ -626,20 +658,9 @@ find_trip_count(loop_info_state *state)<br>
 static bool<br>
 force_unroll_array_access(loop_info_state *state, nir_deref_instr *deref)<br>
 {<br>
-   for (nir_deref_instr *d = deref; d; d = nir_deref_instr_parent(d)) {<br>
-      if (d->deref_type != nir_deref_type_array)<br>
-         continue;<br>
-<br>
-      assert(d->arr.index.is_ssa);<br>
-      nir_loop_variable *array_index = get_loop_var(d->arr.index.ssa, state);<br>
-<br>
-      if (array_index->type != basic_induction)<br>
-         continue;<br>
-<br>
-      nir_deref_instr *parent = nir_deref_instr_parent(d);<br>
-      assert(glsl_type_is_array(parent->type) ||<br>
-             glsl_type_is_matrix(parent->type));<br>
-      if (glsl_get_length(parent->type) == state->loop->info->max_trip_count)<br>
+   unsigned array_size = find_array_access_via_induction(state, deref, NULL);<br>
+   if (array_size) {<br>
+      if (array_size == state->loop->info->max_trip_count)<br>
          return true;<br>
<br>
       if (deref->mode & state->indirect_mask)<br>
-- <br>
2.19.2<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><br>
</blockquote></div></div>