Mesa (main): glsl: Lower if to conditional select instead of conditional assignment

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Feb 11 17:59:12 UTC 2022


Module: Mesa
Branch: main
Commit: afee5dc63f8fc2fc086e321d8b7379145e86813d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=afee5dc63f8fc2fc086e321d8b7379145e86813d

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Jan 14 18:48:50 2022 -0800

glsl: Lower if to conditional select instead of conditional assignment

Platforms that don't have flow control also don't have anything that
could be written that has a side effect.  It should be safe to implement
these condition writes as

    foo = csel(condition, bar, foo);

This should eliminate the last thing in the GLSL compiler that can
create new conditions on assignments.  Everything else that can store
something in ir_assignment::condition derives it from a pre-existing
condition.

v2: Fix bad rebase.

Reviewed-by: Matt Turner <mattst88 at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14573>

---

 src/compiler/glsl/lower_if_to_cond_assign.cpp | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/compiler/glsl/lower_if_to_cond_assign.cpp b/src/compiler/glsl/lower_if_to_cond_assign.cpp
index 06522dc7c6a..3ff44ee1c87 100644
--- a/src/compiler/glsl/lower_if_to_cond_assign.cpp
+++ b/src/compiler/glsl/lower_if_to_cond_assign.cpp
@@ -201,14 +201,18 @@ move_block_to_cond_assign(void *mem_ctx,
                                                 cond_expr->clone(mem_ctx, NULL),
                                                 assign->rhs);
                } else {
-                  assign->condition = cond_expr->clone(mem_ctx, NULL);
+                  assign->rhs =
+                     new(mem_ctx) ir_expression(ir_triop_csel,
+                                                cond_expr->clone(mem_ctx, NULL),
+                                                assign->rhs,
+                                                assign->lhs->as_dereference());
                }
             } else {
-               assign->condition =
-                  new(mem_ctx) ir_expression(ir_binop_logic_and,
-                                             glsl_type::bool_type,
+               assign->rhs =
+                  new(mem_ctx) ir_expression(ir_triop_csel,
                                              cond_expr->clone(mem_ctx, NULL),
-                                             assign->condition);
+                                             assign->rhs,
+                                             assign->lhs->as_dereference());
             }
          }
       }



More information about the mesa-commit mailing list