Skip to content

Commit 2502f11

Browse files
committed
[AMDGPU][SIMemoryLegalizer] Add a hidden option --amdgcn-disable-soft-waitcnt to work around the memory-legalizer-atomic-fence tests getting optimized out
1 parent 63e4bf2 commit 2502f11

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ static cl::opt<bool> AmdgcnSkipCacheInvalidations(
3434
"amdgcn-skip-cache-invalidations", cl::init(false), cl::Hidden,
3535
cl::desc("Use this to skip inserting cache invalidating instructions."));
3636

37+
static cl::opt<bool> AmdgcnDisableSoftWaitcnt(
38+
"amdgcn-disable-soft-waitcnt", cl::init(false), cl::Hidden,
39+
cl::desc("Use this option to disable 'soft' waitcnt instructions in the "
40+
"memory-legalizer."));
41+
3742
namespace {
3843

3944
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
@@ -271,6 +276,10 @@ class SICacheControl {
271276
/// Whether to insert cache invalidating instructions.
272277
bool InsertCacheInv;
273278

279+
/// Either regular or soft waitcnt opcode.
280+
unsigned WAITCNT_Opcode;
281+
unsigned WAITCNT_VSCNT_Opcode;
282+
274283
SICacheControl(const GCNSubtarget &ST);
275284

276285
/// Sets named bit \p BitName to "true" if present in instruction \p MI.
@@ -832,6 +841,11 @@ SICacheControl::SICacheControl(const GCNSubtarget &ST) : ST(ST) {
832841
TII = ST.getInstrInfo();
833842
IV = getIsaVersion(ST.getCPU());
834843
InsertCacheInv = !AmdgcnSkipCacheInvalidations;
844+
WAITCNT_Opcode =
845+
AmdgcnDisableSoftWaitcnt ? AMDGPU::S_WAITCNT : AMDGPU::S_WAITCNT_soft;
846+
WAITCNT_VSCNT_Opcode = AmdgcnDisableSoftWaitcnt
847+
? AMDGPU::S_WAITCNT_VSCNT
848+
: AMDGPU::S_WAITCNT_VSCNT_soft;
835849
}
836850

837851
bool SICacheControl::enableNamedBit(const MachineBasicBlock::iterator MI,
@@ -1055,8 +1069,7 @@ bool SIGfx6CacheControl::insertWait(MachineBasicBlock::iterator &MI,
10551069
VMCnt ? 0 : getVmcntBitMask(IV),
10561070
getExpcntBitMask(IV),
10571071
LGKMCnt ? 0 : getLgkmcntBitMask(IV));
1058-
BuildMI(MBB, MI, DL, TII->get(AMDGPU::S_WAITCNT_soft))
1059-
.addImm(WaitCntImmediate);
1072+
BuildMI(MBB, MI, DL, TII->get(WAITCNT_Opcode)).addImm(WaitCntImmediate);
10601073
Changed = true;
10611074
}
10621075

@@ -1964,13 +1977,12 @@ bool SIGfx10CacheControl::insertWait(MachineBasicBlock::iterator &MI,
19641977
VMCnt ? 0 : getVmcntBitMask(IV),
19651978
getExpcntBitMask(IV),
19661979
LGKMCnt ? 0 : getLgkmcntBitMask(IV));
1967-
BuildMI(MBB, MI, DL, TII->get(AMDGPU::S_WAITCNT_soft))
1968-
.addImm(WaitCntImmediate);
1980+
BuildMI(MBB, MI, DL, TII->get(WAITCNT_Opcode)).addImm(WaitCntImmediate);
19691981
Changed = true;
19701982
}
19711983

19721984
if (VSCnt) {
1973-
BuildMI(MBB, MI, DL, TII->get(AMDGPU::S_WAITCNT_VSCNT_soft))
1985+
BuildMI(MBB, MI, DL, TII->get(WAITCNT_VSCNT_Opcode))
19741986
.addReg(AMDGPU::SGPR_NULL, RegState::Undef)
19751987
.addImm(0);
19761988
Changed = true;

llvm/test/CodeGen/AMDGPU/GlobalISel/memory-legalizer-atomic-fence.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
; RUN: llc -global-isel -mtriple=amdgcn-amd- -mcpu=gfx600 -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX6,GFX68 %s
2-
; RUN: llc -global-isel -mtriple=amdgcn-amd- -mcpu=gfx803 -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX8,GFX68 %s
3-
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx803 -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX8,GFX68 %s
4-
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX10,GFX10WGP %s
5-
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 -mattr=+cumode -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX10,GFX10CU %s
6-
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX10,GFX10WGP %s
7-
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -mattr=+cumode -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX10,GFX10CU %s
1+
; RUN: llc -global-isel -mtriple=amdgcn-amd- -mcpu=gfx600 --amdgcn-disable-soft-waitcnt -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX6,GFX68 %s
2+
; RUN: llc -global-isel -mtriple=amdgcn-amd- -mcpu=gfx803 --amdgcn-disable-soft-waitcnt -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX8,GFX68 %s
3+
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx803 --amdgcn-disable-soft-waitcnt -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX8,GFX68 %s
4+
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 --amdgcn-disable-soft-waitcnt -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX10,GFX10WGP %s
5+
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1010 --amdgcn-disable-soft-waitcnt -mattr=+cumode -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX10,GFX10CU %s
6+
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 --amdgcn-disable-soft-waitcnt -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX10,GFX10WGP %s
7+
; RUN: llc -global-isel -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 --amdgcn-disable-soft-waitcnt -mattr=+cumode -verify-machineinstrs < %s | FileCheck -check-prefixes=FUNC,GCN,GFX10,GFX10CU %s
88

99
; FUNC-LABEL: {{^}}system_one_as_acquire:
1010
; GCN: %bb.0

0 commit comments

Comments
 (0)