nir/algebraic: Optimize comparisons and up-casts
authorJason Ekstrand <jason@jlekstrand.net>
Sat, 13 Jul 2019 04:26:59 +0000 (23:26 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Wed, 17 Jul 2019 18:44:35 +0000 (18:44 +0000)
commit812b341578040496c76cc05e7c9cc05fe57ce834
tree75c5e5a848ecfffb97f5396c8f0be9d9a6db7f4d
parente8505e982a3f911440cad8a963313d2d62d27fc6
nir/algebraic: Optimize comparisons and up-casts

These seem like obvious enough optimizations in the world of multiple
integer bit sizes.  The only known thing which hits these at the moment
is some Vulkan CTS tests for 16-bit SSBO values which like to up-cast
and check for equality.  However, it's something that's bound to come up
as we start seeing more integers in shaders.

The optimizations of comparisons of casted values with constants are
something which we would ideally do with range analysis.  However,
lacking that, we can do it in opt_algebraic as long as one side is a
constant.

In dEQP-VK.ssbo.phys.layout.random.16bit.scalar.13, this commit, along
with the previous commit, reduce the number of instructions emitted on
Skylake from 55328 to 44546, a reduction of 20%.

Acked-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/compiler/nir/nir_opt_algebraic.py