Skip to content

Commit

Permalink
[ARM] Fix shouldExpandAtomicLoadInIR for subtargets without ldrexd.
Browse files Browse the repository at this point in the history
Regression from 2f497ec; we should not try to generate ldrexd on
targets that don't have it.

Also, while I'm here, fix shouldExpandAtomicStoreInIR, for consistency.
That doesn't really have any practical effect, though.  On Thumb targets
where we need to use __sync_* libcalls, there is no libcall for stores,
so SelectionDAG calls __sync_lock_test_and_set_8 anyway.
  • Loading branch information
efriedma-quic committed Mar 18, 2022
1 parent f10f16a commit ddca666
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
22 changes: 19 additions & 3 deletions llvm/lib/Target/ARM/ARMISelLowering.cpp
Expand Up @@ -20976,8 +20976,16 @@ Instruction *ARMTargetLowering::emitTrailingFence(IRBuilderBase &Builder,
// things go wrong. Cortex M doesn't have ldrexd/strexd though, so don't emit
// anything for those.
bool ARMTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const {
bool has64BitAtomicStore;
if (Subtarget->isMClass())
has64BitAtomicStore = false;
else if (Subtarget->isThumb())
has64BitAtomicStore = Subtarget->hasV7Ops();
else
has64BitAtomicStore = Subtarget->hasV6Ops();

unsigned Size = SI->getValueOperand()->getType()->getPrimitiveSizeInBits();
return (Size == 64) && !Subtarget->isMClass();
return Size == 64 && has64BitAtomicStore;
}

// Loads and stores less than 64-bits are already atomic; ones above that
Expand All @@ -20989,9 +20997,17 @@ bool ARMTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const {
// sections A8.8.72-74 LDRD)
TargetLowering::AtomicExpansionKind
ARMTargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const {
bool has64BitAtomicLoad;
if (Subtarget->isMClass())
has64BitAtomicLoad = false;
else if (Subtarget->isThumb())
has64BitAtomicLoad = Subtarget->hasV7Ops();
else
has64BitAtomicLoad = Subtarget->hasV6Ops();

unsigned Size = LI->getType()->getPrimitiveSizeInBits();
return ((Size == 64) && !Subtarget->isMClass()) ? AtomicExpansionKind::LLOnly
: AtomicExpansionKind::None;
return (Size == 64 && has64BitAtomicLoad) ? AtomicExpansionKind::LLOnly
: AtomicExpansionKind::None;
}

// For the real atomic operations, we have ldrex/strex up to 32 bits,
Expand Down
11 changes: 9 additions & 2 deletions llvm/test/CodeGen/ARM/atomic-load-store.ll
Expand Up @@ -270,8 +270,15 @@ define i64 @test_old_load_64bit(i64* %p) {
;
; THUMBONE-LABEL: test_old_load_64bit:
; THUMBONE: @ %bb.0:
; THUMBONE-NEXT: ldaexd r0, r1, [r0]
; THUMBONE-NEXT: bx lr
; THUMBONE-NEXT: push {r7, lr}
; THUMBONE-NEXT: sub sp, #8
; THUMBONE-NEXT: movs r2, #0
; THUMBONE-NEXT: str r2, [sp]
; THUMBONE-NEXT: str r2, [sp, #4]
; THUMBONE-NEXT: mov r3, r2
; THUMBONE-NEXT: bl __sync_val_compare_and_swap_8
; THUMBONE-NEXT: add sp, #8
; THUMBONE-NEXT: pop {r7, pc}
;
; ARMV4-LABEL: test_old_load_64bit:
; ARMV4: @ %bb.0:
Expand Down

0 comments on commit ddca666

Please sign in to comment.