From 5cf9292ce341d2002f5d6e0189d54e29f9e71afe Mon Sep 17 00:00:00 2001 From: Stanislav Mekhanoshin Date: Fri, 12 Feb 2021 14:19:10 -0800 Subject: [PATCH] [AMDGPU] Add two TSFlags: IsAtomicNoRtn and IsAtomicRtn We are using AtomicNoRet map in multiple places to determine if an instruction atomic, rtn or nortn atomic. This method does not work always since we have some instructions which only has rtn or nortn version. One such instruction is ds_wrxchg_rtn_b32 which does not have nortn version. This has caused changes in memory legalizer tests. Differential Revision: https://reviews.llvm.org/D96639 --- llvm/lib/Target/AMDGPU/BUFInstructions.td | 2 ++ llvm/lib/Target/AMDGPU/DSInstructions.td | 4 +++ llvm/lib/Target/AMDGPU/FLATInstructions.td | 3 ++ llvm/lib/Target/AMDGPU/MIMGInstructions.td | 29 ++++++++++--------- llvm/lib/Target/AMDGPU/SIDefines.h | 8 ++++- .../lib/Target/AMDGPU/SIFormMemoryClauses.cpp | 3 +- llvm/lib/Target/AMDGPU/SIInsertWaitcnts.cpp | 16 +++++----- llvm/lib/Target/AMDGPU/SIInstrFormats.td | 10 +++++++ llvm/lib/Target/AMDGPU/SIInstrInfo.h | 29 +++++++++++++++++-- llvm/lib/Target/AMDGPU/SIInstrInfo.td | 9 ------ llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp | 2 +- .../AMDGPU/memory-legalizer-local-agent.ll | 18 ++++-------- .../AMDGPU/memory-legalizer-local-system.ll | 18 ++++-------- .../memory-legalizer-local-workgroup.ll | 18 ++++-------- 14 files changed, 95 insertions(+), 74 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/BUFInstructions.td b/llvm/lib/Target/AMDGPU/BUFInstructions.td index 5dc5481df49e..4a67630c0809 100644 --- a/llvm/lib/Target/AMDGPU/BUFInstructions.td +++ b/llvm/lib/Target/AMDGPU/BUFInstructions.td @@ -696,6 +696,7 @@ class MUBUF_AtomicNoRet_Pseudo.ret; let glc_value = 0; let dlc_value = 0; + let IsAtomicNoRet = 1; let AsmMatchConverter = "cvtMubufAtomic"; } @@ -714,6 +715,7 @@ class MUBUF_AtomicRet_Pseudo.ret; let glc_value = 1; let dlc_value = 0; + let IsAtomicRet = 1; let Constraints = "$vdata = $vdata_in"; let DisableEncoding = "$vdata_in"; let AsmMatchConverter = "cvtMubufAtomicReturn"; diff --git a/llvm/lib/Target/AMDGPU/DSInstructions.td b/llvm/lib/Target/AMDGPU/DSInstructions.td index 328c81005df4..9f71017d81df 100644 --- a/llvm/lib/Target/AMDGPU/DSInstructions.td +++ b/llvm/lib/Target/AMDGPU/DSInstructions.td @@ -102,6 +102,7 @@ class DS_1A1D_NORET let has_data1 = 0; let has_vdst = 0; + let IsAtomicNoRet = 1; } multiclass DS_1A1D_NORET_mc { @@ -121,6 +122,7 @@ class DS_1A2D_NORET " $addr, $data0, $data1$offset$gds"> { let has_vdst = 0; + let IsAtomicNoRet = 1; } multiclass DS_1A2D_NORET_mc { @@ -161,6 +163,7 @@ class DS_1A1D_RET let hasPostISelHook = 1; let has_data1 = 0; + let IsAtomicRet = 1; } multiclass DS_1A1D_RET_mc { let hasPostISelHook = 1; + let IsAtomicRet = 1; } multiclass DS_1A2D_RET_mc { // 64-bit atomics - def "" : MIMGBaseOpcode { - let Atomic = 1; - let AtomicX2 = isCmpSwap; - } + let IsAtomicRet = 1 in { + def "" : MIMGBaseOpcode { + let Atomic = 1; + let AtomicX2 = isCmpSwap; + } - let BaseOpcode = !cast(NAME) in { - // _V* variants have different dst size, but the size is encoded implicitly, - // using dmask and tfe. Only 32-bit variant is registered with disassembler. - // Other variants are reconstructed by disassembler using dmask and tfe. - let VDataDwords = !if(isCmpSwap, 2, 1) in - defm _V1 : MIMG_Atomic_Addr_Helper_m ; - let VDataDwords = !if(isCmpSwap, 4, 2) in - defm _V2 : MIMG_Atomic_Addr_Helper_m ; - } + let BaseOpcode = !cast(NAME) in { + // _V* variants have different dst size, but the size is encoded implicitly, + // using dmask and tfe. Only 32-bit variant is registered with disassembler. + // Other variants are reconstructed by disassembler using dmask and tfe. + let VDataDwords = !if(isCmpSwap, 2, 1) in + defm _V1 : MIMG_Atomic_Addr_Helper_m ; + let VDataDwords = !if(isCmpSwap, 4, 2) in + defm _V2 : MIMG_Atomic_Addr_Helper_m ; + } + } // End IsAtomicRet = 1 } class MIMG_Sampler_Helper isMIMG(Inst)) { if (Inst.mayStore()) { setExpScore(&Inst, TII, TRI, MRI, 0, CurrScore); - } else if (AMDGPU::getAtomicNoRetOp(Inst.getOpcode()) != -1) { + } else if (SIInstrInfo::isAtomicRet(Inst)) { setExpScore( &Inst, TII, TRI, MRI, AMDGPU::getNamedOperandIdx(Inst.getOpcode(), AMDGPU::OpName::data), @@ -582,7 +582,7 @@ void WaitcntBrackets::updateByEvent(const SIInstrInfo *TII, } else if (TII->isMUBUF(Inst)) { if (Inst.mayStore()) { setExpScore(&Inst, TII, TRI, MRI, 0, CurrScore); - } else if (AMDGPU::getAtomicNoRetOp(Inst.getOpcode()) != -1) { + } else if (SIInstrInfo::isAtomicRet(Inst)) { setExpScore( &Inst, TII, TRI, MRI, AMDGPU::getNamedOperandIdx(Inst.getOpcode(), AMDGPU::OpName::data), @@ -1246,8 +1246,7 @@ void SIInsertWaitcnts::updateEventWaitcntAfter(MachineInstr &Inst, ++FlatASCount; if (!ST->hasVscnt()) ScoreBrackets->updateByEvent(TII, TRI, MRI, VMEM_ACCESS, Inst); - else if (Inst.mayLoad() && - AMDGPU::getAtomicRetOp(Inst.getOpcode()) == -1) + else if (Inst.mayLoad() && !SIInstrInfo::isAtomicNoRet(Inst)) ScoreBrackets->updateByEvent(TII, TRI, MRI, VMEM_READ_ACCESS, Inst); else ScoreBrackets->updateByEvent(TII, TRI, MRI, VMEM_WRITE_ACCESS, Inst); @@ -1275,8 +1274,7 @@ void SIInsertWaitcnts::updateEventWaitcntAfter(MachineInstr &Inst, Inst.getOpcode() != AMDGPU::BUFFER_GL1_INV) { if (!ST->hasVscnt()) ScoreBrackets->updateByEvent(TII, TRI, MRI, VMEM_ACCESS, Inst); - else if ((Inst.mayLoad() && - AMDGPU::getAtomicRetOp(Inst.getOpcode()) == -1) || + else if ((Inst.mayLoad() && !SIInstrInfo::isAtomicNoRet(Inst)) || /* IMAGE_GET_RESINFO / IMAGE_GET_LOD */ (TII->isMIMG(Inst) && !Inst.mayLoad() && !Inst.mayStore())) ScoreBrackets->updateByEvent(TII, TRI, MRI, VMEM_READ_ACCESS, Inst); @@ -1284,7 +1282,7 @@ void SIInsertWaitcnts::updateEventWaitcntAfter(MachineInstr &Inst, ScoreBrackets->updateByEvent(TII, TRI, MRI, VMEM_WRITE_ACCESS, Inst); if (ST->vmemWriteNeedsExpWaitcnt() && - (Inst.mayStore() || AMDGPU::getAtomicNoRetOp(Inst.getOpcode()) != -1)) { + (Inst.mayStore() || SIInstrInfo::isAtomicRet(Inst))) { ScoreBrackets->updateByEvent(TII, TRI, MRI, VMW_GPR_LOCK, Inst); } } else if (TII->isSMRD(Inst)) { diff --git a/llvm/lib/Target/AMDGPU/SIInstrFormats.td b/llvm/lib/Target/AMDGPU/SIInstrFormats.td index 7ce042b67aba..92d148c1677e 100644 --- a/llvm/lib/Target/AMDGPU/SIInstrFormats.td +++ b/llvm/lib/Target/AMDGPU/SIInstrFormats.td @@ -135,6 +135,12 @@ class InstSI