Skip to content

Commit bd7bbe4

Browse files
committed
AMDGPU: Expand remaining system atomic operations
System scope atomics need to use cmpxchg loops. aea5980 started this, this expands the set to cover the remaining integer operations. Don't expand xchg and add, those theoretically should work over PCIe.
1 parent 676c495 commit bd7bbe4

File tree

9 files changed

+12867
-2023
lines changed

9 files changed

+12867
-2023
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16018,7 +16018,8 @@ SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
1601816018
SSID == SyncScope::System ||
1601916019
SSID == RMW->getContext().getOrInsertSyncScopeID("one-as");
1602016020

16021-
switch (RMW->getOperation()) {
16021+
auto Op = RMW->getOperation();
16022+
switch (Op) {
1602216023
case AtomicRMWInst::FAdd: {
1602316024
Type *Ty = RMW->getType();
1602416025

@@ -16096,19 +16097,29 @@ SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
1609616097

1609716098
return AtomicExpansionKind::CmpXChg;
1609816099
}
16099-
case AtomicRMWInst::FMin:
16100-
case AtomicRMWInst::FMax:
16101-
case AtomicRMWInst::Min:
16100+
case AtomicRMWInst::Xchg:
16101+
case AtomicRMWInst::Add:
16102+
// PCIe supports add and xchg for system atomics.
16103+
break;
16104+
case AtomicRMWInst::Sub:
16105+
case AtomicRMWInst::And:
16106+
case AtomicRMWInst::Or:
16107+
case AtomicRMWInst::Xor:
1610216108
case AtomicRMWInst::Max:
16109+
case AtomicRMWInst::Min:
16110+
case AtomicRMWInst::UMax:
1610316111
case AtomicRMWInst::UMin:
16104-
case AtomicRMWInst::UMax: {
16112+
case AtomicRMWInst::FMin:
16113+
case AtomicRMWInst::FMax:
16114+
case AtomicRMWInst::UIncWrap:
16115+
case AtomicRMWInst::UDecWrap: {
1610516116
if (AMDGPU::isFlatGlobalAddrSpace(AS) ||
1610616117
AS == AMDGPUAS::BUFFER_FAT_POINTER) {
16107-
if (RMW->getType()->isFloatTy() &&
16118+
if (AtomicRMWInst::isFPOperation(Op) &&
1610816119
unsafeFPAtomicsDisabled(RMW->getFunction()))
1610916120
return AtomicExpansionKind::CmpXChg;
1611016121

16111-
// Always expand system scope min/max atomics.
16122+
// Always expand system scope atomics.
1611216123
if (HasSystemScope)
1611316124
return AtomicExpansionKind::CmpXChg;
1611416125
}

0 commit comments

Comments
 (0)