From afee5dc63f8fc2fc086e321d8b7379145e86813d Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 14 Jan 2022 18:48:50 -0800 Subject: [PATCH] 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 Part-of: --- 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()); } } }