Skip to content

AMDGPU: Refine gfx950 xdl-write-vgpr hazard cases #117285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2232,8 +2232,8 @@ int GCNHazardRecognizer::checkMAIHazards908(MachineInstr *MI) {
}

static int
GFX940_XDL_N_PassWritesVGPROverlappedSMFMASrcCWaitStates(int NumPasses,
bool IsGFX950) {
GFX940_XDL_N_PassWritesVGPROverlappedXDLOrSMFMASrcCWaitStates(int NumPasses,
bool IsGFX950) {
// xdl def cycles | gfx940 | gfx950
// 2 pass | 3 4
// 4 pass | 5 6
Expand All @@ -2242,6 +2242,17 @@ GFX940_XDL_N_PassWritesVGPROverlappedSMFMASrcCWaitStates(int NumPasses,
return NumPasses + 1 + IsGFX950;
}

static int
GFX940_XDL_N_PassWritesVGPROverlappedSGEMMDGEMMSrcCWaitStates(int NumPasses,
bool IsGFX950) {
// xdl def cycles | gfx940 | gfx950
// 2 pass | 3 3
// 4 pass | 5 6
// 8 pass | 9 10
// 16 pass | 17 18
return NumPasses + 1 + (NumPasses != 2 && IsGFX950);
}

static int
GFX940_SMFMA_N_PassWritesVGPROverlappedSMFMASrcCWaitStates(int NumPasses) {
// 2 pass -> 2
Expand Down Expand Up @@ -2379,8 +2390,11 @@ int GCNHazardRecognizer::checkMAIHazards90A(MachineInstr *MI) {

NeedWaitStates =
isXDL(ST, *MI1)
? GFX940_XDL_N_PassWritesVGPROverlappedSMFMASrcCWaitStates(
NumPasses, ST.hasGFX950Insts())
? (isXDL(ST, *MI)
? GFX940_XDL_N_PassWritesVGPROverlappedXDLOrSMFMASrcCWaitStates(
NumPasses, ST.hasGFX950Insts())
: GFX940_XDL_N_PassWritesVGPROverlappedSGEMMDGEMMSrcCWaitStates(
NumPasses, ST.hasGFX950Insts()))
: GFX940_SMFMA_N_PassWritesVGPROverlappedSMFMASrcCWaitStates(
NumPasses);
break;
Expand Down
15 changes: 5 additions & 10 deletions llvm/test/CodeGen/AMDGPU/mai-hazards-gfx940.mir
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ body: |
...
# GCN-LABEL: name: sgemm4x4_mfma_write_vgpr_mfma_read_overlap
# GCN: V_MFMA
# GFX940-NEXT: S_NOP 2
# GFX950-NEXT: S_NOP 3
# GCN-NEXT: S_NOP 2
# GCN-NEXT: V_MFMA
name: sgemm4x4_mfma_write_vgpr_mfma_read_overlap
body: |
Expand Down Expand Up @@ -348,8 +347,7 @@ body: |
...
# GCN-LABEL: name: sgemm4x4_mfma_write_vgpr_dgemm_mfma_read_overlap
# GCN: V_MFMA
# GFX940-NEXT: S_NOP 2
# GFX950-NEXT: S_NOP 3
# GCN-NEXT: S_NOP 2
# GCN-NEXT: V_MFMA
name: sgemm4x4_mfma_write_vgpr_dgemm_mfma_read_overlap
body: |
Expand Down Expand Up @@ -1403,8 +1401,7 @@ body: |
...
# GCN-LABEL: name: sgemm4x4_mfma_write_agpr_dgemm_mfma_read_overlap
# GCN: V_MFMA
# GFX940-NEXT: S_NOP 2
# GFX950-NEXT: S_NOP 3
# GCN-NEXT: S_NOP 2
# GCN-NEXT: V_MFMA
name: sgemm4x4_mfma_write_agpr_dgemm_mfma_read_overlap
body: |
Expand Down Expand Up @@ -1885,8 +1882,7 @@ body: |
...
# GCN-LABEL: name: xdl_sgemm4x4_mfma_write_agpr_mfma_read_overlap
# GCN: V_MFMA
# GFX940-NEXT: S_NOP 2
# GFX950-NEXT: S_NOP 3
# GCN-NEXT: S_NOP 2
# GCN-NEXT: V_MFMA
name: xdl_sgemm4x4_mfma_write_agpr_mfma_read_overlap
body: |
Expand Down Expand Up @@ -2220,8 +2216,7 @@ body: |
# 2 pass source
# GCN-LABEL: name: xdl_mfma_2pass_write_vgpr_sgemm_mfma_read_overlap_srcc
# GCN: V_MFMA
# GFX940-NEXT: S_NOP 2
# GFX950-NEXT: S_NOP 3
# GCN-NEXT: S_NOP 2
# GCN-NEXT: V_MFMA
name: xdl_mfma_2pass_write_vgpr_sgemm_mfma_read_overlap_srcc
body: |
Expand Down
Loading