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 <ian.d.romanick@intel.com>
This commit is contained in:
Jason Ekstrand 2016-12-19 21:29:51 -08:00
parent 8962cc96ec
commit d55835b8bd
1 changed files with 8 additions and 0 deletions

View File

@ -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