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

Author: Georg Lehmann <dadschoo...@gmail.com>
Date:   Sat Nov 11 10:53:31 2023 +0100

aco: fix detecting sgprs read by SMEM hazard

s_waitcnt_lgkmcnt is SOPK, not SOPP and there are other SOPK instructions
that don't mitigate the hazard.

Reviewed-by: Rhys Perry <pendingchao...@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26163>

---

 src/amd/compiler/aco_insert_NOPs.cpp | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/amd/compiler/aco_insert_NOPs.cpp 
b/src/amd/compiler/aco_insert_NOPs.cpp
index 2ab28fb95ec..8777a2f4e86 100644
--- a/src/amd/compiler/aco_insert_NOPs.cpp
+++ b/src/amd/compiler/aco_insert_NOPs.cpp
@@ -1026,20 +1026,18 @@ handle_instruction_gfx10(State& state, NOP_ctx_gfx10& 
ctx, aco_ptr<Instruction>&
          bld.sop1(aco_opcode::s_mov_b32, Definition(sgpr_null, s1), 
Operand::zero());
       }
    } else if (instr->isSALU()) {
-      if (instr->format != Format::SOPP) {
+      /* Reducing lgkmcnt count to 0 always mitigates the hazard. */
+      if (instr->opcode == aco_opcode::s_waitcnt_lgkmcnt) {
+         const SOPK_instruction& sopk = instr->sopk();
+         if (sopk.imm == 0 && sopk.operands[0].physReg() == sgpr_null)
+            ctx.sgprs_read_by_SMEM.reset();
+      } else if (instr->opcode == aco_opcode::s_waitcnt) {
+         wait_imm imm(state.program->gfx_level, instr->sopp().imm);
+         if (imm.lgkm == 0)
+            ctx.sgprs_read_by_SMEM.reset();
+      } else if (instr->format != Format::SOPP && instr->definitions.size()) {
          /* SALU can mitigate the hazard */
          ctx.sgprs_read_by_SMEM.reset();
-      } else {
-         /* Reducing lgkmcnt count to 0 always mitigates the hazard. */
-         const SOPP_instruction& sopp = instr->sopp();
-         if (sopp.opcode == aco_opcode::s_waitcnt_lgkmcnt) {
-            if (sopp.imm == 0 && sopp.operands[0].physReg() == sgpr_null)
-               ctx.sgprs_read_by_SMEM.reset();
-         } else if (sopp.opcode == aco_opcode::s_waitcnt) {
-            wait_imm imm(state.program->gfx_level, instr->sopp().imm);
-            if (imm.lgkm == 0)
-               ctx.sgprs_read_by_SMEM.reset();
-         }
       }
    }
 

Reply via email to