Mesa (master): nir: add helper to return inversion op of a comparison

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Mar 12 01:37:13 UTC 2019


Module: Mesa
Branch: master
Commit: f219f6114ddbd43c239f22151b698bd1b5b7f86e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f219f6114ddbd43c239f22151b698bd1b5b7f86e

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Thu Dec  6 11:17:45 2018 +1100

nir: add helper to return inversion op of a comparison

This will be used to help find the trip count of loops that look
like the following:

   while (a < x && i < 8) {
      ...
      i++;
   }

Where the NIR will end up looking something like this:

   vec1 32 ssa_1 = load_const (0x00000004 /* 0.000000 */)
   loop {
      ...
      vec1 1 ssa_12 = ilt ssa_225, ssa_11
      vec1 1 ssa_17 = ilt ssa_226, ssa_1
      vec1 1 ssa_18 = iand ssa_12, ssa_17
      vec1 1 ssa_19 = inot ssa_18

      if ssa_19 {
         ...
         break
      } else {
         ...
      }
   }

So in order to find the trip count we need to find the inverse of
ilt.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/compiler/nir/nir_loop_analyze.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/compiler/nir/nir_loop_analyze.c b/src/compiler/nir/nir_loop_analyze.c
index 0ea7ad4e5eb..8b8e5f2e865 100644
--- a/src/compiler/nir/nir_loop_analyze.c
+++ b/src/compiler/nir/nir_loop_analyze.c
@@ -734,6 +734,35 @@ calculate_iterations(nir_const_value *initial, nir_const_value *step,
    return -1;
 }
 
+static nir_op
+inverse_comparison(nir_alu_instr *alu)
+{
+   switch (alu->op) {
+   case nir_op_fge:
+      return nir_op_flt;
+   case nir_op_ige:
+      return nir_op_ilt;
+   case nir_op_uge:
+      return nir_op_ult;
+   case nir_op_flt:
+      return nir_op_fge;
+   case nir_op_ilt:
+      return nir_op_ige;
+   case nir_op_ult:
+      return nir_op_uge;
+   case nir_op_feq:
+      return nir_op_fne;
+   case nir_op_ieq:
+      return nir_op_ine;
+   case nir_op_fne:
+      return nir_op_feq;
+   case nir_op_ine:
+      return nir_op_ieq;
+   default:
+      unreachable("Unsuported comparison!");
+   }
+}
+
 static bool
 is_supported_terminator_condition(nir_alu_instr *alu)
 {




More information about the mesa-commit mailing list