Skip to content

Commit f7226e9

Browse files
committed
AMDGPU: Expand remaining system atomic operations
System scope atomics need to use cmpxchg loops if we know nothing about the allocation the address is from. 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. This is a pre-commit which will introduce performance regressions. Subsequent changes will add handling of new atomicrmw metadata, which will avoid the expansion. Note this still isn't conservative enough; we do need to expand some device scope atomics if the memory is in fine-grained remote memory.
1 parent 95e4db8 commit f7226e9

14 files changed

+22181
-4549
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16919,26 +16919,39 @@ SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
1691916919

1692016920
auto Op = RMW->getOperation();
1692116921
switch (Op) {
16922-
case AtomicRMWInst::Xchg: {
16922+
case AtomicRMWInst::Xchg:
1692316923
// PCIe supports add and xchg for system atomics.
1692416924
return isAtomicRMWLegalXChgTy(RMW)
1692516925
? TargetLowering::AtomicExpansionKind::None
1692616926
: TargetLowering::AtomicExpansionKind::CmpXChg;
16927-
}
1692816927
case AtomicRMWInst::Add:
16929-
case AtomicRMWInst::And:
16930-
case AtomicRMWInst::UIncWrap:
16931-
case AtomicRMWInst::UDecWrap:
16928+
// PCIe supports add and xchg for system atomics.
1693216929
return atomicSupportedIfLegalIntType(RMW);
1693316930
case AtomicRMWInst::Sub:
16931+
case AtomicRMWInst::And:
1693416932
case AtomicRMWInst::Or:
16935-
case AtomicRMWInst::Xor: {
16936-
// Atomic sub/or/xor do not work over PCI express, but atomic add
16937-
// does. InstCombine transforms these with 0 to or, so undo that.
16938-
if (HasSystemScope && AMDGPU::isFlatGlobalAddrSpace(AS)) {
16939-
if (Constant *ConstVal = dyn_cast<Constant>(RMW->getValOperand());
16940-
ConstVal && ConstVal->isNullValue())
16941-
return AtomicExpansionKind::Expand;
16933+
case AtomicRMWInst::Xor:
16934+
case AtomicRMWInst::Max:
16935+
case AtomicRMWInst::Min:
16936+
case AtomicRMWInst::UMax:
16937+
case AtomicRMWInst::UMin:
16938+
case AtomicRMWInst::UIncWrap:
16939+
case AtomicRMWInst::UDecWrap: {
16940+
if (AMDGPU::isFlatGlobalAddrSpace(AS) ||
16941+
AS == AMDGPUAS::BUFFER_FAT_POINTER) {
16942+
// Always expand system scope atomics.
16943+
if (HasSystemScope) {
16944+
if (Op == AtomicRMWInst::Sub || Op == AtomicRMWInst::Or ||
16945+
Op == AtomicRMWInst::Xor) {
16946+
// Atomic sub/or/xor do not work over PCI express, but atomic add
16947+
// does. InstCombine transforms these with 0 to or, so undo that.
16948+
if (Constant *ConstVal = dyn_cast<Constant>(RMW->getValOperand());
16949+
ConstVal && ConstVal->isNullValue())
16950+
return AtomicExpansionKind::Expand;
16951+
}
16952+
16953+
return AtomicExpansionKind::CmpXChg;
16954+
}
1694216955
}
1694316956

1694416957
return atomicSupportedIfLegalIntType(RMW);
@@ -17093,19 +17106,6 @@ SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
1709317106

1709417107
return AtomicExpansionKind::CmpXChg;
1709517108
}
17096-
case AtomicRMWInst::Min:
17097-
case AtomicRMWInst::Max:
17098-
case AtomicRMWInst::UMin:
17099-
case AtomicRMWInst::UMax: {
17100-
if (AMDGPU::isFlatGlobalAddrSpace(AS) ||
17101-
AS == AMDGPUAS::BUFFER_FAT_POINTER) {
17102-
// Always expand system scope min/max atomics.
17103-
if (HasSystemScope)
17104-
return AtomicExpansionKind::CmpXChg;
17105-
}
17106-
17107-
return atomicSupportedIfLegalIntType(RMW);
17108-
}
1710917109
case AtomicRMWInst::Nand:
1711017110
case AtomicRMWInst::FSub:
1711117111
default:

0 commit comments

Comments
 (0)