OSDN Git Service

nir/algebraic: Mark other comparison exact when removing a == a
authorIan Romanick <ian.d.romanick@intel.com>
Thu, 24 Oct 2019 21:41:20 +0000 (14:41 -0700)
committerDylan Baker <dylan@pnwbakers.com>
Thu, 14 Nov 2019 16:43:09 +0000 (08:43 -0800)
commit4fbe772b2376bca71a8618e17713e4379a461a96
tree972d4444450ab20089b5e59d1d9e355072934e02
parent17ad67c6dcc9d910c10bd40807114b891b6636a8
nir/algebraic: Mark other comparison exact when removing a == a

This prevents some additional optimizations that would change the
original result.  This includes things like (b < a && b < c) => b <
min(a, c) and !(a < b) => b >= a.  Both of these optimizations were
specifically observed in the piglit tests added in piglit!160.

This was discovered while investigating
https://gitlab.freedesktop.org/mesa/mesa/issues/1958.  However, the
problem in that issue was Chrome or Angle is replacing calls to isnan()
with some stuff that we (correctly) optimize to false.  If they had left
the calls to isnan() alone, everything would have just worked.

No shader-db changes on any Intel platform.

I also tried marking the comparison generated by the isnan() function
precise.  The precise marker "infects" every computation involved in
calculating the parameter to the isnan() function, and this severely
hurt all of the (few) shaders in shader-db that use isnan().

I also considered adding a new ir_unop_isnan opcode that would implement
the functionality.  During GLSL IR-to-NIR translation, the resulting
comparison operation would be marked exact (and the samething would need
to happen in SPIR-V translation).

This approach taken by this patch seemed easier, but we may want to do
the ir_unop_isnan thing anyway.

Fixes: d55835b8bdf ("nir/algebraic: Add optimizations for "a == a && a CMP b"")
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
(cherry picked from commit 9be4a422a055d1e829d56c3cc91e1fc2f6e8fb31)
src/compiler/nir/nir_opt_algebraic.py