Skip to content

Commit 493d7e3

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 95e460a commit 493d7e3

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
@@ -16764,26 +16764,39 @@ SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
1676416764

1676516765
auto Op = RMW->getOperation();
1676616766
switch (Op) {
16767-
case AtomicRMWInst::Xchg: {
16767+
case AtomicRMWInst::Xchg:
1676816768
// PCIe supports add and xchg for system atomics.
1676916769
return isAtomicRMWLegalXChgTy(RMW)
1677016770
? TargetLowering::AtomicExpansionKind::None
1677116771
: TargetLowering::AtomicExpansionKind::CmpXChg;
16772-
}
1677316772
case AtomicRMWInst::Add:
16774-
case AtomicRMWInst::And:
16775-
case AtomicRMWInst::UIncWrap:
16776-
case AtomicRMWInst::UDecWrap:
16773+
// PCIe supports add and xchg for system atomics.
1677716774
return atomicSupportedIfLegalIntType(RMW);
1677816775
case AtomicRMWInst::Sub:
16776+
case AtomicRMWInst::And:
1677916777
case AtomicRMWInst::Or:
16780-
case AtomicRMWInst::Xor: {
16781-
// Atomic sub/or/xor do not work over PCI express, but atomic add
16782-
// does. InstCombine transforms these with 0 to or, so undo that.
16783-
if (HasSystemScope && AMDGPU::isFlatGlobalAddrSpace(AS)) {
16784-
if (Constant *ConstVal = dyn_cast<Constant>(RMW->getValOperand());
16785-
ConstVal && ConstVal->isNullValue())
16786-
return AtomicExpansionKind::Expand;
16778+
case AtomicRMWInst::Xor:
16779+
case AtomicRMWInst::Max:
16780+
case AtomicRMWInst::Min:
16781+
case AtomicRMWInst::UMax:
16782+
case AtomicRMWInst::UMin:
16783+
case AtomicRMWInst::UIncWrap:
16784+
case AtomicRMWInst::UDecWrap: {
16785+
if (AMDGPU::isFlatGlobalAddrSpace(AS) ||
16786+
AS == AMDGPUAS::BUFFER_FAT_POINTER) {
16787+
// Always expand system scope atomics.
16788+
if (HasSystemScope) {
16789+
if (Op == AtomicRMWInst::Sub || Op == AtomicRMWInst::Or ||
16790+
Op == AtomicRMWInst::Xor) {
16791+
// Atomic sub/or/xor do not work over PCI express, but atomic add
16792+
// does. InstCombine transforms these with 0 to or, so undo that.
16793+
if (Constant *ConstVal = dyn_cast<Constant>(RMW->getValOperand());
16794+
ConstVal && ConstVal->isNullValue())
16795+
return AtomicExpansionKind::Expand;
16796+
}
16797+
16798+
return AtomicExpansionKind::CmpXChg;
16799+
}
1678716800
}
1678816801

1678916802
return atomicSupportedIfLegalIntType(RMW);
@@ -16938,19 +16951,6 @@ SITargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *RMW) const {
1693816951

1693916952
return AtomicExpansionKind::CmpXChg;
1694016953
}
16941-
case AtomicRMWInst::Min:
16942-
case AtomicRMWInst::Max:
16943-
case AtomicRMWInst::UMin:
16944-
case AtomicRMWInst::UMax: {
16945-
if (AMDGPU::isFlatGlobalAddrSpace(AS) ||
16946-
AS == AMDGPUAS::BUFFER_FAT_POINTER) {
16947-
// Always expand system scope min/max atomics.
16948-
if (HasSystemScope)
16949-
return AtomicExpansionKind::CmpXChg;
16950-
}
16951-
16952-
return atomicSupportedIfLegalIntType(RMW);
16953-
}
1695416954
case AtomicRMWInst::Nand:
1695516955
case AtomicRMWInst::FSub:
1695616956
default:

0 commit comments

Comments
 (0)