From b4cfec4973f8da86b920f85ba7d4769c440f64fd 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 (cherry picked from commit 60b3e5b3f09a483603bde9d65ee0420705de905a) Part-of: --- .pick_status.json | 2 +- src/amd/compiler/aco_lower_branches.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index fe831fed8ba..c76e6ed16c1 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2114,7 +2114,7 @@ "description": "aco/lower_branches: Don't remove branches which jump over loops", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/amd/compiler/aco_lower_branches.cpp b/src/amd/compiler/aco_lower_branches.cpp index a9b73700384..41d69ad9fac 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