Mesa (staging/21.2): glsl/opt_algebraic: disable invalid optimization

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Aug 18 16:12:33 UTC 2021


Module: Mesa
Branch: staging/21.2
Commit: 8d4f8e7e6a0492fbbafe7faef7232f29e99b1a38
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8d4f8e7e6a0492fbbafe7faef7232f29e99b1a38

Author: Marcin Ślusarz <marcin.slusarz at intel.com>
Date:   Fri Aug 13 16:39:09 2021 +0200

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 at intel.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12359>
(cherry picked from commit 89bc8ff4083029187f099af531e4db0e223c62ca)

---

 .pick_status.json                   | 2 +-
 src/compiler/glsl/opt_algebraic.cpp | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index 8f2b50250f4..06a2ea0dfbd 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -130,7 +130,7 @@
         "description": "glsl/opt_algebraic: disable invalid optimization",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "34ec1a24d61f8b2f6ed58efa9fe7ea8cec917612"
     },
diff --git a/src/compiler/glsl/opt_algebraic.cpp b/src/compiler/glsl/opt_algebraic.cpp
index 7cef4fc6ef9..14d6e13839b 100644
--- a/src/compiler/glsl/opt_algebraic.cpp
+++ b/src/compiler/glsl/opt_algebraic.cpp
@@ -708,8 +708,6 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
       }
       break;
 
-   case ir_binop_less:
-   case ir_binop_gequal:
    case ir_binop_equal:
    case ir_binop_nequal:
       for (int add_pos = 0; add_pos < 2; add_pos++) {



More information about the mesa-commit mailing list