From d8414302e89b43a60a40386a565459d62da4377d Mon Sep 17 00:00:00 2001 From: Giovanni Mascellani Date: Thu, 29 Feb 2024 16:00:51 +0100 Subject: [PATCH] vkd3d-shader/ir: Move `continue's to the false branch when possible. --- libs/vkd3d-shader/ir.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c index 7230d0e8..c495955d 100644 --- a/libs/vkd3d-shader/ir.c +++ b/libs/vkd3d-shader/ir.c @@ -4115,11 +4115,29 @@ static enum vkd3d_result vsir_cfg_build_structured_program(struct vsir_cfg *cfg) * next block, in which case we make sure it's the * false branch. */ if (action_true.jump_type == JUMP_NONE) + { + invert_condition = true; + } + else if (stack_depth >= 2) + { + struct vsir_cfg_structure_list *inner_loop_frame = stack[stack_depth - 2]; + struct vsir_cfg_structure *inner_loop = &inner_loop_frame->structures[inner_loop_frame->count - 1]; + + assert(inner_loop->type == STRUCTURE_TYPE_LOOP); + + /* Otherwise, if one of the branches is + * continueing the inner loop we're inside, + * make sure it's the false branch (because it + * will be optimized out later). */ + if (action_true.jump_type == JUMP_CONTINUE && action_true.target == inner_loop->u.loop.idx) + invert_condition = true; + } + + if (invert_condition) { struct vsir_cfg_edge_action tmp = action_true; action_true = action_false; action_false = tmp; - invert_condition = true; } assert(action_true.jump_type != JUMP_NONE);