summaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <[email protected]>2019-06-12 16:48:21 -0700
committerCaio Marcelo de Oliveira Filho <[email protected]>2019-06-26 14:13:02 -0700
commit085c0f1f13ca14e8d91c9dec64debcd95334389d (patch)
treefb44a2094775883bc1142b1b90947390f0c65394 /src/compiler
parent5a143965b8f4119501e973d15f7f72673b3ce416 (diff)
nir/algebraic: Add helpers and a rule involving wrapping
The helpers are needed so we can use the syntax `instr(cond)` in the algebraic rules. Add simple rule for dropping a pair of mul-div of the same value when wrapping is guaranteed to not happen. Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/nir/nir_opt_algebraic.py3
-rw-r--r--src/compiler/nir/nir_search_helpers.h12
2 files changed, 15 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 45e8779e16e..8b786887052 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -761,6 +761,9 @@ optimizations.extend([
(('~fadd', '#a', ('fneg', ('fadd', 'b(is_not_const)', '#c'))), ('fadd', ('fadd', a, ('fneg', c)), ('fneg', b))),
(('iadd', '#a', ('iadd', 'b(is_not_const)', '#c')), ('iadd', ('iadd', a, c), b)),
+ # Drop mul-div by the same value when there's no wrapping.
+ (('idiv', ('imul(no_signed_wrap)', a, b), b), a),
+
# By definition...
(('bcsel', ('ige', ('find_lsb', a), 0), ('find_lsb', a), -1), ('find_lsb', a)),
(('bcsel', ('ige', ('ifind_msb', a), 0), ('ifind_msb', a), -1), ('ifind_msb', a)),
diff --git a/src/compiler/nir/nir_search_helpers.h b/src/compiler/nir/nir_search_helpers.h
index acd53a4960d..658ed2b1d5b 100644
--- a/src/compiler/nir/nir_search_helpers.h
+++ b/src/compiler/nir/nir_search_helpers.h
@@ -288,4 +288,16 @@ is_lower_half_zero(nir_alu_instr *instr, unsigned src,
return true;
}
+static inline bool
+no_signed_wrap(nir_alu_instr *instr)
+{
+ return instr->no_signed_wrap;
+}
+
+static inline bool
+no_unsigned_wrap(nir_alu_instr *instr)
+{
+ return instr->no_unsigned_wrap;
+}
+
#endif /* _NIR_SEARCH_ */