Module: Mesa
Branch: main
Commit: e1eabab6fecce8fef330a303ba7fddcbaf261b17
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=e1eabab6fecce8fef330a303ba7fddcbaf261b17

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>

---

 src/amd/compiler/aco_optimizer_postRA.cpp | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/amd/compiler/aco_optimizer_postRA.cpp 
b/src/amd/compiler/aco_optimizer_postRA.cpp
index 510b9e196da..6435a54ef4e 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);

Reply via email to