From 800a4957bb2546cfffd9c8e040ba4442ee6979f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Fri, 23 Jan 2026 12:36:33 +0100 Subject: [PATCH] aco/lower_branches: Consider branch target of nested conditional branches Totals from 1470 (1.74% of 84383) affected shaders: (Navi48) Instrs: 5128451 -> 5126842 (-0.03%) CodeSize: 29359832 -> 29353656 (-0.02%); split: -0.02%, +0.00% Latency: 41047203 -> 41040786 (-0.02%) InvThroughput: 6040459 -> 6039619 (-0.01%); split: -0.01%, +0.00% Branches: 146219 -> 144648 (-1.07%) Part-of: --- src/amd/compiler/aco_lower_branches.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/amd/compiler/aco_lower_branches.cpp b/src/amd/compiler/aco_lower_branches.cpp index a9b73700384..074f4591f1d 100644 --- a/src/amd/compiler/aco_lower_branches.cpp +++ b/src/amd/compiler/aco_lower_branches.cpp @@ -392,8 +392,12 @@ can_remove_branch(branch_ctx& ctx, Block& block, Pseudo_branch_instruction* bran ctx.program->blocks[i].kind & (block_kind_break | block_kind_continue); bool discard_early_exit = ctx.program->blocks[instr->salu().imm].kind & block_kind_discard_early_exit; - if (is_break_continue || discard_early_exit) + if (is_break_continue || discard_early_exit) { + /* If the branch target is the same, we can be sure that it will be taken. */ + if (instr->salu().imm == target) + return true; continue; + } } return false; } else if (instr->isSALU()) {