Module: Mesa Branch: staging/23.0 Commit: 7a49d1fc29e2c123d7a45fe6e176d44a163c0be5 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=7a49d1fc29e2c123d7a45fe6e176d44a163c0be5
Author: Georg Lehmann <[email protected]> Date: Sun Feb 26 15:54:18 2023 +0100 aco/optimizer_postRA: assume all registers are untrackable in loop headers Register writes from the pre-header might not be correct for any but the first loop iteration because they can be clobbered inside the loop. Foz-DB Navi21: Totals from 18 (0.01% of 134913) affected shaders: CodeSize: 251384 -> 251508 (+0.05%) Instrs: 47644 -> 47664 (+0.04%) Latency: 801801 -> 801852 (+0.01%) InvThroughput: 177579 -> 177593 (+0.01%) Copies: 4752 -> 4771 (+0.40%) Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/8376 Fixes: d3b0f781103 ("aco/optimizer_postRA: Initialize loop header with preheader information") Reviewed-by: Timur Kristóf <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21540> (cherry picked from commit e1eabab6fecce8fef330a303ba7fddcbaf261b17) --- .pick_status.json | 2 +- src/amd/compiler/aco_optimizer_postRA.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index e2a833f969a..fc7425f8723 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -310,7 +310,7 @@ "description": "aco/optimizer_postRA: assume all registers are untrackable in loop headers", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "d3b0f781103ffcef4e18257b8289948e9d37dd99" }, diff --git a/src/amd/compiler/aco_optimizer_postRA.cpp b/src/amd/compiler/aco_optimizer_postRA.cpp index 91fc663927c..d4d476cc6d9 100644 --- a/src/amd/compiler/aco_optimizer_postRA.cpp +++ b/src/amd/compiler/aco_optimizer_postRA.cpp @@ -109,13 +109,13 @@ struct pr_opt_ctx { std::fill(instr_idx_by_regs[block->index].begin(), instr_idx_by_regs[block->index].end(), not_written_yet); } else if (block->kind & block_kind_loop_header) { - /* Initialize with content from loop preheader */ - memcpy(&instr_idx_by_regs[block->index][0], &instr_idx_by_regs[block->index - 1][0], - max_reg_cnt * sizeof(Idx)); - - /* Assume exec writes on back-edges */ - instr_idx_by_regs[block->index][126] = overwritten_untrackable; - instr_idx_by_regs[block->index][127] = overwritten_untrackable; + /* Instructions inside the loop may overwrite registers of temporaries that are + * not live inside the loop, but we can't detect that because we haven't processed + * the blocks in the loop yet. As a workaround, mark all registers as untrackable. + * TODO: Consider improving this in the future. + */ + std::fill(instr_idx_by_regs[block->index].begin(), instr_idx_by_regs[block->index].end(), + overwritten_untrackable); } else { reset_block_regs(block->linear_preds, block->index, 0, max_sgpr_cnt); reset_block_regs(block->linear_preds, block->index, 251, 3);
