From 60b3e5b3f09a483603bde9d65ee0420705de905a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Wed, 25 Mar 2026 13:17:15 +0100 Subject: [PATCH] aco/lower_branches: Don't remove branches which jump over loops Entering a loop with empty exec mask might lead to not be able to execute the break condition and lead to infinite loops. Totals from 81 (0.04% of 202440) affected shaders: (Navi48) Instrs: 3040566 -> 3040716 (+0.00%) CodeSize: 17506768 -> 17507188 (+0.00%) Latency: 16342966 -> 16345166 (+0.01%) InvThroughput: 3112932 -> 3113286 (+0.01%) Branches: 82229 -> 82365 (+0.17%) Cc: mesa-stable Part-of: --- src/amd/compiler/aco_lower_branches.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/amd/compiler/aco_lower_branches.cpp b/src/amd/compiler/aco_lower_branches.cpp index 443decfa9b5..f4d36566f46 100644 --- a/src/amd/compiler/aco_lower_branches.cpp +++ b/src/amd/compiler/aco_lower_branches.cpp @@ -379,6 +379,10 @@ can_remove_branch(branch_ctx& ctx, Block& block, Pseudo_branch_instruction* bran if (uniform_branch && !ctx.program->blocks[i].instructions.empty()) return false; + /* Don't enter loops with empty exec mask. */ + if (ctx.program->blocks[i].loop_nest_depth > block.loop_nest_depth) + return false; + for (aco_ptr& instr : ctx.program->blocks[i].instructions) { if (instr->isSOPP()) { /* Discard early exits and loop breaks and continues should work fine with