From 11ef52212adfafbdc389d474b21ce97815d5b51d Mon Sep 17 00:00:00 2001 From: Timur Kristóf Date: Tue, 21 Dec 2021 15:24:21 +0100 Subject: aco/optimizer_postRA: Fix applying VCC to branches. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: a93092d0edc92eea8e8e96709ad9857f05c45cef Signed-off-by: Timur Kristóf Reviewed-by: Daniel Schürmann Part-of: (cherry picked from commit b293299776069676af1bc76aeb1d48223e0e7de2) --- .pick_status.json | 2 +- src/amd/compiler/aco_optimizer_postRA.cpp | 25 ++++++++----------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 1d6b515ff61..bc4d21e9ee1 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -895,7 +895,7 @@ "description": "aco/optimizer_postRA: Fix applying VCC to branches.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "a93092d0edc92eea8e8e96709ad9857f05c45cef" }, diff --git a/src/amd/compiler/aco_optimizer_postRA.cpp b/src/amd/compiler/aco_optimizer_postRA.cpp index 2b59ad54e06..5019eb619f0 100644 --- a/src/amd/compiler/aco_optimizer_postRA.cpp +++ b/src/amd/compiler/aco_optimizer_postRA.cpp @@ -50,18 +50,6 @@ Idx clobbered{UINT32_MAX, 1}; Idx const_or_undef{UINT32_MAX, 2}; Idx written_by_multiple_instrs{UINT32_MAX, 3}; -bool -is_instr_after(Idx second, Idx first) -{ - if (first == not_written_in_block && second != not_written_in_block) - return true; - - if (!first.found() || !second.found()) - return false; - - return second.block > first.block || (second.block == first.block && second.instr > first.instr); -} - struct pr_opt_ctx { Program* program; Block* current_block; @@ -215,16 +203,19 @@ try_apply_branch_vcc(pr_opt_ctx& ctx, aco_ptr& instr) Idx op0_instr_idx = last_writer_idx(ctx, instr->operands[0]); Idx last_vcc_wr_idx = last_writer_idx(ctx, vcc, ctx.program->lane_mask); - Idx last_exec_wr_idx = last_writer_idx(ctx, exec, ctx.program->lane_mask); /* We need to make sure: + * - the instructions that wrote the operand register and VCC are both found * - the operand register used by the branch, and VCC were both written in the current block - * - VCC was NOT written after the operand register - * - EXEC is sane and was NOT written after the operand register + * - EXEC hasn't been clobbered since the last VCC write + * - VCC hasn't been clobbered since the operand register was written + * (ie. the last VCC writer precedes the op0 writer) */ if (!op0_instr_idx.found() || !last_vcc_wr_idx.found() || - !is_instr_after(last_vcc_wr_idx, last_exec_wr_idx) || - !is_instr_after(op0_instr_idx, last_vcc_wr_idx)) + op0_instr_idx.block != ctx.current_block->index || + last_vcc_wr_idx.block != ctx.current_block->index || + is_clobbered_since(ctx, exec, ctx.program->lane_mask, last_vcc_wr_idx) || + is_clobbered_since(ctx, vcc, ctx.program->lane_mask, op0_instr_idx)) return; Instruction* op0_instr = ctx.get(op0_instr_idx); -- cgit v1.2.3