Skip to content

Commit

Permalink
AMDGPU: Fix hazard with v_accvgpr_write_b32 and inline asm VGPR defs
Browse files Browse the repository at this point in the history
If inline asm has a VGPR def, it must have come from a VGPR write
somewhere inside the asm. This should be further extended to all
read after write hazards.
  • Loading branch information
arsenm committed Oct 13, 2022
1 parent c23ac22 commit 575eed3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,7 @@ int GCNHazardRecognizer::checkMAIHazards908(MachineInstr *MI) {
unsigned Opc = MI->getOpcode();

auto IsVALUFn = [](const MachineInstr &MI) {
return SIInstrInfo::isVALU(MI);
return SIInstrInfo::isVALU(MI) || MI.isInlineAsm();
};

if (Opc != AMDGPU::V_ACCVGPR_READ_B32_e64) { // MFMA or v_accvgpr_write
Expand Down
58 changes: 58 additions & 0 deletions llvm/test/CodeGen/AMDGPU/mai-hazards.mir
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,64 @@ body: |
$vgpr0 = V_MOV_B32_e32 1, implicit $exec
$agpr0 = V_ACCVGPR_WRITE_B32_e64 killed $vgpr0, implicit $exec
...
---
# GCN-LABEL: name: asm_write_vgpr_accvgpr_write_read
# GCN: INLINEASM
# GCN-NEXT: S_NOP 1
# GCN-NEXT: V_ACCVGPR_WRITE_B32_e64
name: asm_write_vgpr_accvgpr_write_read
body: |
bb.0:
INLINEASM &"; def $0", 1 /* sideeffect attdialect */, 1966090 /* regdef:VGPR_32 */, def $vgpr0
$agpr0 = V_ACCVGPR_WRITE_B32_e64 killed $vgpr0, implicit $exec
...

---
# GCN-LABEL: name: asm_write_vgpr_accvgpr_write_read_partialnop
# GCN: INLINEASM
# GCN-NEXT: S_NOP 0
# GCN-NEXT: S_NOP 0
# GCN-NEXT: V_ACCVGPR_WRITE_B32_e64
name: asm_write_vgpr_accvgpr_write_read_partialnop
body: |
bb.0:
INLINEASM &"; def $0", 1 /* sideeffect attdialect */, 1966090 /* regdef:VGPR_32 */, def $vgpr0
S_NOP 0
$agpr0 = V_ACCVGPR_WRITE_B32_e64 killed $vgpr0, implicit $exec
...

---
# GCN-LABEL: name: asm_write_vgpr_accvgpr_write_read_otherreg
# GCN: INLINEASM
# GCN-NEXT: V_ACCVGPR_WRITE_B32_e64
name: asm_write_vgpr_accvgpr_write_read_otherreg
body: |
bb.0:
liveins: $vgpr0
INLINEASM &"; def $0", 1 /* sideeffect attdialect */, 1966090 /* regdef:VGPR_32 */, def $vgpr1
$agpr0 = V_ACCVGPR_WRITE_B32_e64 killed $vgpr0, implicit $exec
...

---
# GCN-LABEL: name: bundle_write_vgpr_accvgpr_write_read
# GCN: BUNDLE
# GCN-NEXT: S_NOP 0
# GCN-NEXT: V_MOV_B32
# GCN-NEXT: }
# GCN-NEXT: S_NOP 1
# GCN-NEXT: V_ACCVGPR_WRITE_B32_e64
name: bundle_write_vgpr_accvgpr_write_read
body: |
bb.0:
$vgpr0 = BUNDLE {
S_NOP 0
$vgpr0 = V_MOV_B32_e32 0, implicit $exec
}
$agpr0 = V_ACCVGPR_WRITE_B32_e64 killed $vgpr0, implicit $exec
...

---

# GCN-LABEL: name: mfma_write_agpr_mfma_read_same_agpr
Expand Down

0 comments on commit 575eed3

Please sign in to comment.