[llvm] [AMDGPU] Fix checkVALUHazardsHelper distance accounting on branchy CFG (PR #203770)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 15 07:59:19 PDT 2026


================
@@ -932,65 +932,77 @@ int GCNHazardRecognizer::createsVALUHazard(const MachineInstr &MI) const {
   return -1;
 }
 
-int GCNHazardRecognizer::checkVALUHazardsHelper(
-    const MachineOperand &Def, const MachineRegisterInfo &MRI) const {
-  // Helper to check for the hazard where VMEM instructions that store more
-  // than 8 bytes can have their store data overwritten by the next
-  // instruction. On gfx940-family the window depends on the producer's
+int GCNHazardRecognizer::checkPreGFX940VALUHazardsHelper(Register Reg) const {
+  // Pre-gfx940 wide stores need a single wait-state bubble before a VALU that
+  // overwrites store data. createsVALUHazard already excludes MUBUF/MTBUF
+  // stores with an SGPR SOFFSET.
+  const SIRegisterInfo *TRI = ST.getRegisterInfo();
+
+  auto IsHazard = [this, TRI, Reg](const MachineInstr &MI) {
+    int DataIdx = createsVALUHazard(MI);
+    return DataIdx >= 0 &&
+           TRI->regsOverlap(MI.getOperand(DataIdx).getReg(), Reg);
+  };
+
+  return std::max(0, 1 - getWaitStatesSince(IsHazard, 1));
+}
+
+int GCNHazardRecognizer::checkGFX940FamilyVALUHazardsHelper(
+    Register Reg) const {
----------------
shiltian wrote:

The format seems off here.

https://github.com/llvm/llvm-project/pull/203770


More information about the llvm-commits mailing list