[Mesa-dev] [PATCH 17/20] nir: add helper to return inversion op of a comparision
Timothy Arceri
tarceri at itsqueeze.com
Fri Dec 7 03:08:17 UTC 2018
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_0 = load_const (0x00000000 /* 0.000000 */)
vec1 32 ssa_1 = load_const (0x00000008 /* 0.000000 */)
loop {
...
vec1 32 ssa_28 = ige ssa_26, ssa_3
vec1 32 ssa_29 = ige ssa_27, ssa_1
vec1 32 ssa_30 = iadd ssa_29, ssa_28
vec1 ssa_31 = ieq ssa_30, ssa_0
if ssa_31 {
...
break
} else {
...
}
...
}
So in order to find the trip count we need to find the inverse of
ige.
---
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 5446e7a120..2dd7dd7b20 100644
--- a/src/compiler/nir/nir_loop_analyze.c
+++ b/src/compiler/nir/nir_loop_analyze.c
@@ -665,6 +665,35 @@ calculate_iterations(nir_const_value *initial, nir_const_value *step,
return -1;
}
+static nir_op
+inverse_comparision(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 comparision!");
+ }
+}
+
static bool
is_supported_terminator_condition(nir_alu_instr *alu)
{
--
2.19.2
More information about the mesa-dev
mailing list