aco: reset prefetch in the correct block after removing the exit
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 20 Sep 2023 18:27:39 +0000 (19:27 +0100)
committerMarge Bot <emma+marge@anholt.net>
Mon, 25 Sep 2023 14:18:46 +0000 (14:18 +0000)
fossil-db (navi31):
Totals from 279 (0.35% of 79332) affected shaders:
(no stat changes)

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Fixes: c778803d673f ("aco/assembler: change prefetch mode on GFX10.3+ during loops if beneficial")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25312>

src/amd/compiler/aco_assembler.cpp

index 47e379b..a866f26 100644 (file)
@@ -48,7 +48,7 @@ struct asm_context {
    std::map<unsigned, constaddr_info> constaddrs;
    std::map<unsigned, constaddr_info> resumeaddrs;
    std::vector<struct aco_symbol>* symbols;
-   Block* loop_header;
+   Block* loop_header = NULL;
    const int16_t* opcode;
    // TODO: keep track of branch instructions referring blocks
    // and, when emitting the block, correct the offset in instr
@@ -1235,7 +1235,11 @@ fix_constaddrs(asm_context& ctx, std::vector<uint32_t>& out)
 void
 align_block(asm_context& ctx, std::vector<uint32_t>& code, Block& block)
 {
-   if (block.kind & block_kind_loop_exit && ctx.loop_header) {
+   /* Blocks with block_kind_loop_exit might be eliminated after jump threading, so we instead find
+    * loop exits using loop_nest_depth.
+    */
+   if (ctx.loop_header && !block.linear_preds.empty() &&
+       block.loop_nest_depth < ctx.loop_header->loop_nest_depth) {
       Block* loop_header = ctx.loop_header;
       ctx.loop_header = NULL;
       std::vector<uint32_t> nops;