<div dir="ltr"><div>Replacing min with max without changing any real code always looks a biit weird but it does make sense. :-)</div><div><br></div><div>Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Dec 6, 2018 at 9:08 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">Following commits will introduce additional fields such as<br>
guessed_trip_count. Renaming these will help avoid confusion<br>
as our unrolling feature set grows.<br>
<br>
Reviewed-by: Thomas Helland <<a href="mailto:thomashelland90@gmail.com" target="_blank">thomashelland90@gmail.com</a>><br>
---<br>
 src/compiler/nir/nir.h                 |  8 +++++---<br>
 src/compiler/nir/nir_loop_analyze.c    | 14 +++++++-------<br>
 src/compiler/nir/nir_opt_loop_unroll.c | 14 +++++++-------<br>
 3 files changed, 19 insertions(+), 17 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
index db935c8496..ce4a81fbe1 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -1886,9 +1886,11 @@ typedef struct {<br>
    /* Number of instructions in the loop */<br>
    unsigned num_instructions;<br>
<br>
-   /* How many times the loop is run (if known) */<br>
-   unsigned trip_count;<br>
-   bool is_trip_count_known;<br>
+   /* Maximum number of times the loop is run (if known) */<br>
+   unsigned max_trip_count;<br>
+<br>
+   /* Do we know the exact number of times the loop will be run */<br>
+   bool exact_trip_count_known;<br>
<br>
    /* Unroll the loop regardless of its size */<br>
    bool force_unroll;<br>
diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c<br>
index c779383b36..700d1fe552 100644<br>
--- a/src/compiler/nir/nir_loop_analyze.c<br>
+++ b/src/compiler/nir/nir_loop_analyze.c<br>
@@ -527,7 +527,7 @@ find_trip_count(loop_info_state *state)<br>
 {<br>
    bool trip_count_known = true;<br>
    nir_loop_terminator *limiting_terminator = NULL;<br>
-   int min_trip_count = -1;<br>
+   int max_trip_count = -1;<br>
<br>
    list_for_each_entry(nir_loop_terminator, terminator,<br>
                        &state->loop->info->loop_terminator_list,<br>
@@ -606,8 +606,8 @@ find_trip_count(loop_info_state *state)<br>
           * iterations than previously (we have identified a more limiting<br>
           * terminator) set the trip count and limiting terminator.<br>
           */<br>
-         if (min_trip_count == -1 || iterations < min_trip_count) {<br>
-            min_trip_count = iterations;<br>
+         if (max_trip_count == -1 || iterations < max_trip_count) {<br>
+            max_trip_count = iterations;<br>
             limiting_terminator = terminator;<br>
          }<br>
          break;<br>
@@ -617,9 +617,9 @@ find_trip_count(loop_info_state *state)<br>
       }<br>
    }<br>
<br>
-   state->loop->info->is_trip_count_known = trip_count_known;<br>
-   if (min_trip_count > -1)<br>
-      state->loop->info->trip_count = min_trip_count;<br>
+   state->loop->info->exact_trip_count_known = trip_count_known;<br>
+   if (max_trip_count > -1)<br>
+      state->loop->info->max_trip_count = max_trip_count;<br>
    state->loop->info->limiting_terminator = limiting_terminator;<br>
 }<br>
<br>
@@ -639,7 +639,7 @@ force_unroll_array_access(loop_info_state *state, nir_deref_instr *deref)<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->trip_count)<br>
+      if (glsl_get_length(parent->type) == state->loop->info->max_trip_count)<br>
          return true;<br>
<br>
       if (deref->mode & state->indirect_mask)<br>
diff --git a/src/compiler/nir/nir_opt_loop_unroll.c b/src/compiler/nir/nir_opt_loop_unroll.c<br>
index ea2012e292..0e9966320b 100644<br>
--- a/src/compiler/nir/nir_opt_loop_unroll.c<br>
+++ b/src/compiler/nir/nir_opt_loop_unroll.c<br>
@@ -181,7 +181,7 @@ simple_unroll(nir_loop *loop)<br>
    nir_cf_list unrolled_lp_body;<br>
<br>
    /* Clone loop header and append to the loop body */<br>
-   for (unsigned i = 0; i < loop->info->trip_count; i++) {<br>
+   for (unsigned i = 0; i < loop->info->max_trip_count; i++) {<br>
       /* Clone loop body */<br>
       nir_cf_list_clone(&unrolled_lp_body, &loop_body, loop->cf_node.parent,<br>
                         remap_table);<br>
@@ -340,7 +340,7 @@ complex_unroll(nir_loop *loop, nir_loop_terminator *unlimit_term,<br>
        * trip count == 1 we execute the code above the break twice and the<br>
        * code below it once so we need clone things twice and so on.<br>
        */<br>
-      num_times_to_clone = loop->info->trip_count + 1;<br>
+      num_times_to_clone = loop->info->max_trip_count + 1;<br>
    } else {<br>
       /* Pluck out the loop header */<br>
       nir_cf_extract(&lp_header, nir_before_block(header_blk),<br>
@@ -368,7 +368,7 @@ complex_unroll(nir_loop *loop, nir_loop_terminator *unlimit_term,<br>
<br>
       nir_cf_node_remove(&limiting_term->nif->cf_node);<br>
<br>
-      num_times_to_clone = loop->info->trip_count;<br>
+      num_times_to_clone = loop->info->max_trip_count;<br>
    }<br>
<br>
    /* In the terminator that we have no trip count for move everything after<br>
@@ -568,14 +568,14 @@ is_loop_small_enough_to_unroll(nir_shader *shader, nir_loop_info *li)<br>
 {<br>
    unsigned max_iter = shader->options->max_unroll_iterations;<br>
<br>
-   if (li->trip_count > max_iter)<br>
+   if (li->max_trip_count > max_iter)<br>
       return false;<br>
<br>
    if (li->force_unroll)<br>
       return true;<br>
<br>
    bool loop_not_too_large =<br>
-      li->num_instructions * li->trip_count <= max_iter * LOOP_UNROLL_LIMIT;<br>
+      li->num_instructions * li->max_trip_count <= max_iter * LOOP_UNROLL_LIMIT;<br>
<br>
    return loop_not_too_large;<br>
 }<br>
@@ -641,7 +641,7 @@ process_loops(nir_shader *sh, nir_cf_node *cf_node, bool *has_nested_loop_out)<br>
       if (!is_loop_small_enough_to_unroll(sh, loop->info))<br>
          goto exit;<br>
<br>
-      if (loop->info->is_trip_count_known) {<br>
+      if (loop->info->exact_trip_count_known) {<br>
          simple_unroll(loop);<br>
          progress = true;<br>
       } else {<br>
@@ -665,7 +665,7 @@ process_loops(nir_shader *sh, nir_cf_node *cf_node, bool *has_nested_loop_out)<br>
              * limiting terminator just do a simple unroll as the second<br>
              * terminator can never be reached.<br>
              */<br>
-            if (loop->info->trip_count == 0 && !limiting_term_second) {<br>
+            if (loop->info->max_trip_count == 0 && !limiting_term_second) {<br>
                simple_unroll(loop);<br>
             } else {<br>
                complex_unroll(loop, terminator, limiting_term_second);<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>