Module: Mesa
Branch: main
Commit: 96c19d23c95700c51a50c2c979067cc552abe441
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=96c19d23c95700c51a50c2c979067cc552abe441

Author: Timothy Arceri <[email protected]>
Date:   Thu Aug 11 11:09:26 2022 +1000

nir: update nir_is_supported_terminator_condition()

Ever since 4246c2869c3c and 7d85dc4f350b loop unrolling can no
longer depend on inot being eliminated from the loop
terminator condition so we need to be able to handle it.

Here we simply check to see if the inot contains a simple
terminator condition we previously handled. We also update
the previous users of this function to use a newly name
copy of the previous behaviour
nir_is_terminator_condition_with_two_inputs().

Reviewed-by: Ian Romanick <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18006>

---

 src/compiler/nir/nir_inline_uniforms.c               |  2 +-
 src/compiler/nir/nir_loop_analyze.c                  |  4 ++--
 src/compiler/nir/nir_loop_analyze.h                  | 15 ++++++++++++++-
 src/gallium/frontends/lavapipe/lvp_inline_uniforms.c |  2 +-
 4 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/compiler/nir/nir_inline_uniforms.c 
b/src/compiler/nir/nir_inline_uniforms.c
index 57c29fc07bd..c2331bbb213 100644
--- a/src/compiler/nir/nir_inline_uniforms.c
+++ b/src/compiler/nir/nir_inline_uniforms.c
@@ -196,7 +196,7 @@ add_inlinable_uniforms(const nir_src *cond, nir_loop_info 
*info,
       /* Limit terminator condition to loop unroll support case which is a 
simple
        * comparison (ie. "i < count" is supported, but "i + 1 < count" is not).
        */
-      if (nir_is_supported_terminator_condition(cond_scalar)) {
+      if (nir_is_terminator_condition_with_two_inputs(cond_scalar)) {
          nir_alu_instr *alu = nir_instr_as_alu(cond->ssa->parent_instr);
 
          /* One side of comparison is induction variable, the other side is
diff --git a/src/compiler/nir/nir_loop_analyze.c 
b/src/compiler/nir/nir_loop_analyze.c
index 3b54a068429..f9840da2469 100644
--- a/src/compiler/nir/nir_loop_analyze.c
+++ b/src/compiler/nir/nir_loop_analyze.c
@@ -1035,7 +1035,7 @@ try_find_trip_count_vars_in_iand(nir_ssa_scalar *cond,
    bool found_induction_var = false;
    for (unsigned i = 0; i < 2; i++) {
       nir_ssa_scalar src = nir_ssa_scalar_chase_alu_src(iand, i);
-      if (nir_is_supported_terminator_condition(src) &&
+      if (nir_is_terminator_condition_with_two_inputs(src) &&
           get_induction_and_limit_vars(src, ind, limit, limit_rhs, state)) {
          *cond = src;
          found_induction_var = true;
@@ -1097,7 +1097,7 @@ find_trip_count(loop_info_state *state, unsigned 
execution_mode)
       }
 
       if (!basic_ind.def) {
-         if (nir_is_supported_terminator_condition(cond)) {
+         if (nir_is_terminator_condition_with_two_inputs(cond)) {
             get_induction_and_limit_vars(cond, &basic_ind,
                                          &limit, &limit_rhs, state);
          }
diff --git a/src/compiler/nir/nir_loop_analyze.h 
b/src/compiler/nir/nir_loop_analyze.h
index b09540150be..13170448b5c 100644
--- a/src/compiler/nir/nir_loop_analyze.h
+++ b/src/compiler/nir/nir_loop_analyze.h
@@ -94,7 +94,7 @@ nir_is_trivial_loop_if(nir_if *nif, nir_block *break_block)
 }
 
 static inline bool
-nir_is_supported_terminator_condition(nir_ssa_scalar cond)
+nir_is_terminator_condition_with_two_inputs(nir_ssa_scalar cond)
 {
    if (!nir_ssa_scalar_is_alu(cond))
       return false;
@@ -104,4 +104,17 @@ nir_is_supported_terminator_condition(nir_ssa_scalar cond)
           nir_op_infos[alu->op].num_inputs == 2;
 }
 
+static inline bool
+nir_is_supported_terminator_condition(nir_ssa_scalar cond)
+{
+   if (!nir_ssa_scalar_is_alu(cond))
+      return false;
+
+   nir_alu_instr *alu = nir_instr_as_alu(cond.def->parent_instr);
+   return nir_alu_instr_is_comparison(alu) &&
+          (nir_op_infos[alu->op].num_inputs == 2 ||
+           (alu->op == nir_op_inot &&
+            
nir_is_terminator_condition_with_two_inputs(nir_ssa_scalar_chase_alu_src(cond, 
0))));
+}
+
 #endif /* NIR_LOOP_ANALYZE_H */
diff --git a/src/gallium/frontends/lavapipe/lvp_inline_uniforms.c 
b/src/gallium/frontends/lavapipe/lvp_inline_uniforms.c
index c133b3db51d..76c0b517530 100644
--- a/src/gallium/frontends/lavapipe/lvp_inline_uniforms.c
+++ b/src/gallium/frontends/lavapipe/lvp_inline_uniforms.c
@@ -178,7 +178,7 @@ add_inlinable_uniforms(const nir_src *cond, nir_loop_info 
*info,
       /* Limit terminator condition to loop unroll support case which is a 
simple
        * comparison (ie. "i < count" is supported, but "i + 1 < count" is not).
        */
-      if (nir_is_supported_terminator_condition(cond_scalar)) {
+      if (nir_is_terminator_condition_with_two_inputs(cond_scalar)) {
          nir_alu_instr *alu = nir_instr_as_alu(cond->ssa->parent_instr);
 
          /* One side of comparison is induction variable, the other side is

Reply via email to