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 60b3e5b3f0)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40979>
This commit is contained in:
Daniel Schürmann 2026-03-25 13:17:15 +01:00 committed by Eric Engestrom
parent 7809c26b56
commit b4cfec4973
2 changed files with 5 additions and 1 deletions

View file

@ -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

View file

@ -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<Instruction>& instr : ctx.program->blocks[i].instructions) {
if (instr->isSOPP()) {
/* Discard early exits and loop breaks and continues should work fine with