summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2016-12-19 21:29:51 -0800
committerJason Ekstrand <[email protected]>2016-12-22 16:27:19 -0800
commitd55835b8bdf031ef3c254a9b7ec1776ad348582b (patch)
tree9a9c37683a2f87d7dfa3e3fe03dec931670c29b3
parent8962cc96ec2bc1eb561a438512adc5042e2c8d34 (diff)
nir/algebraic: Add optimizations for "a == a && a CMP b"
This sequence shows up The Talos Principal, at least under Vulkan, and prevents loop analysis from properly computing trip counts in a few loops. Reviewed-by: Ian Romanick <[email protected]>
-rw-r--r--src/compiler/nir/nir_opt_algebraic.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
index 698ac673658..ff10d701f5e 100644
--- a/src/compiler/nir/nir_opt_algebraic.py
+++ b/src/compiler/nir/nir_opt_algebraic.py
@@ -464,6 +464,14 @@ def bitfield_reverse(u):
optimizations += [(bitfield_reverse('x@32'), ('bitfield_reverse', 'x'))]
+# For any float comparison operation, "cmp", if you have "a == a && a cmp b"
+# then the "a == a" is redundant because it's equivalent to "a is not NaN"
+# and, if a is a NaN then the second comparison will fail anyway.
+for op in ['flt', 'fge', 'feq']:
+ optimizations += [
+ (('iand', ('feq', a, a), (op, a, b)), (op, a, b)),
+ (('iand', ('feq', a, a), (op, b, a)), (op, b, a)),
+ ]
# Add optimizations to handle the case where the result of a ternary is
# compared to a constant. This way we can take things like