glsl/opt_algebraic: disable invalid optimization
authorMarcin Ślusarz <marcin.slusarz@intel.com>
Fri, 13 Aug 2021 14:39:09 +0000 (16:39 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 17 Aug 2021 08:17:52 +0000 (08:17 +0000)
commit89bc8ff4083029187f099af531e4db0e223c62ca
tree8a12f659bbcb7aa8b2e1fcd9a5cc01a4d24913c1
parentf9e3ae6a019dd8c8fece3f699ae9a66201d1f19d
glsl/opt_algebraic: disable invalid optimization

When operators other than eq and ne are involved we can't really
move operands around and negate them because such transformation
may change the value of the whole expression.

Some examples:

For unsigned var:
0 >= 1u + var would eventually become 0xffffffff >= var,
which would always evaluate to true, when original expression
was true only for var == 0xffffffff.

For signed var:
0 >= 1 + var would become -1 >= var, which would evaluate to
false for var == 2147483647, when original expression evaluated
to true (because signed overflow is defined to wrap around in
glsl, 1 + 2147483647 == -2147483648, so 0 >= -2147483648).

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5226
Fixes: 34ec1a24d61 ("glsl: Optimize (x + y cmp 0) into (x cmp -y).")
Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12359>
src/compiler/glsl/opt_algebraic.cpp