Skip to content

Commit e2b5611

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 eb14d2a commit e2b5611

14 files changed

+21832
-4343
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

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

1678616786
auto Op = RMW->getOperation();
1678716787
switch (Op) {
16788-
case AtomicRMWInst::Xchg: {
16788+
case AtomicRMWInst::Xchg:
1678916789
// PCIe supports add and xchg for system atomics.
1679016790
return isAtomicRMWLegalXChgTy(RMW)
1679116791
? TargetLowering::AtomicExpansionKind::None
1679216792
: TargetLowering::AtomicExpansionKind::CmpXChg;
16793-
}
1679416793
case AtomicRMWInst::Add:
16795-
case AtomicRMWInst::And:
16796-
case AtomicRMWInst::UIncWrap:
16797-
case AtomicRMWInst::UDecWrap:
16794+
// PCIe supports add and xchg for system atomics.
1679816795
return atomicSupportedIfLegalIntType(RMW);
1679916796
case AtomicRMWInst::Sub:
16797+
case AtomicRMWInst::And:
1680016798
case AtomicRMWInst::Or:
16801-
case AtomicRMWInst::Xor: {
16802-
// Atomic sub/or/xor do not work over PCI express, but atomic add
16803-
// does. InstCombine transforms these with 0 to or, so undo that.
16804-
if (HasSystemScope && AMDGPU::isFlatGlobalAddrSpace(AS)) {
16805-
if (Constant *ConstVal = dyn_cast<Constant>(RMW->getValOperand());
16806-
ConstVal && ConstVal->isNullValue())
16807-
return AtomicExpansionKind::Expand;
16799+
case AtomicRMWInst::Xor:
16800+
case AtomicRMWInst::Max:
16801+
case AtomicRMWInst::Min:
16802+
case AtomicRMWInst::UMax:
16803+
case AtomicRMWInst::UMin:
16804+
case AtomicRMWInst::UIncWrap:
16805+
case AtomicRMWInst::UDecWrap: {
16806+
if (AMDGPU::isFlatGlobalAddrSpace(AS) ||
16807+
AS == AMDGPUAS::BUFFER_FAT_POINTER) {
16808+
// Always expand system scope atomics.
16809+
if (HasSystemScope) {
16810+
if (Op == AtomicRMWInst::Sub || Op == AtomicRMWInst::Or ||
16811+
Op == AtomicRMWInst::Xor) {
16812+
// Atomic sub/or/xor do not work over PCI express, but atomic add
16813+
// does. InstCombine transforms these with 0 to or, so undo that.
16814+
if (Constant *ConstVal = dyn_cast<Constant>(RMW->getValOperand());
16815+
ConstVal && ConstVal->isNullValue())
16816+
return AtomicExpansionKind::Expand;
16817+
}
16818+
16819+
return AtomicExpansionKind::CmpXChg;
16820+
}
1680816821
}
1680916822

1681016823
return atomicSupportedIfLegalIntType(RMW);
@@ -16959,19 +16972,6 @@ SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
1695916972

1696016973
return AtomicExpansionKind::CmpXChg;
1696116974
}
16962-
case AtomicRMWInst::Min:
16963-
case AtomicRMWInst::Max:
16964-
case AtomicRMWInst::UMin:
16965-
case AtomicRMWInst::UMax: {
16966-
if (AMDGPU::isFlatGlobalAddrSpace(AS) ||
16967-
AS == AMDGPUAS::BUFFER_FAT_POINTER) {
16968-
// Always expand system scope min/max atomics.
16969-
if (HasSystemScope)
16970-
return AtomicExpansionKind::CmpXChg;
16971-
}
16972-
16973-
return atomicSupportedIfLegalIntType(RMW);
16974-
}
1697516975
case AtomicRMWInst::Nand:
1697616976
case AtomicRMWInst::FSub:
1697716977
default:

0 commit comments

Comments
 (0)