Skip to content

Commit ddca666

Browse files
committed
[ARM] Fix shouldExpandAtomicLoadInIR for subtargets without ldrexd.
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.
1 parent f10f16a commit ddca666

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20976,8 +20976,16 @@ Instruction *ARMTargetLowering::emitTrailingFence(IRBuilderBase &Builder,
2097620976
// things go wrong. Cortex M doesn't have ldrexd/strexd though, so don't emit
2097720977
// anything for those.
2097820978
bool ARMTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const {
20979+
bool has64BitAtomicStore;
20980+
if (Subtarget->isMClass())
20981+
has64BitAtomicStore = false;
20982+
else if (Subtarget->isThumb())
20983+
has64BitAtomicStore = Subtarget->hasV7Ops();
20984+
else
20985+
has64BitAtomicStore = Subtarget->hasV6Ops();
20986+
2097920987
unsigned Size = SI->getValueOperand()->getType()->getPrimitiveSizeInBits();
20980-
return (Size == 64) && !Subtarget->isMClass();
20988+
return Size == 64 && has64BitAtomicStore;
2098120989
}
2098220990

2098320991
// Loads and stores less than 64-bits are already atomic; ones above that
@@ -20989,9 +20997,17 @@ bool ARMTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const {
2098920997
// sections A8.8.72-74 LDRD)
2099020998
TargetLowering::AtomicExpansionKind
2099120999
ARMTargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const {
21000+
bool has64BitAtomicLoad;
21001+
if (Subtarget->isMClass())
21002+
has64BitAtomicLoad = false;
21003+
else if (Subtarget->isThumb())
21004+
has64BitAtomicLoad = Subtarget->hasV7Ops();
21005+
else
21006+
has64BitAtomicLoad = Subtarget->hasV6Ops();
21007+
2099221008
unsigned Size = LI->getType()->getPrimitiveSizeInBits();
20993-
return ((Size == 64) && !Subtarget->isMClass()) ? AtomicExpansionKind::LLOnly
20994-
: AtomicExpansionKind::None;
21009+
return (Size == 64 && has64BitAtomicLoad) ? AtomicExpansionKind::LLOnly
21010+
: AtomicExpansionKind::None;
2099521011
}
2099621012

2099721013
// For the real atomic operations, we have ldrex/strex up to 32 bits,

llvm/test/CodeGen/ARM/atomic-load-store.ll

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,15 @@ define i64 @test_old_load_64bit(i64* %p) {
270270
;
271271
; THUMBONE-LABEL: test_old_load_64bit:
272272
; THUMBONE: @ %bb.0:
273-
; THUMBONE-NEXT: ldaexd r0, r1, [r0]
274-
; THUMBONE-NEXT: bx lr
273+
; THUMBONE-NEXT: push {r7, lr}
274+
; THUMBONE-NEXT: sub sp, #8
275+
; THUMBONE-NEXT: movs r2, #0
276+
; THUMBONE-NEXT: str r2, [sp]
277+
; THUMBONE-NEXT: str r2, [sp, #4]
278+
; THUMBONE-NEXT: mov r3, r2
279+
; THUMBONE-NEXT: bl __sync_val_compare_and_swap_8
280+
; THUMBONE-NEXT: add sp, #8
281+
; THUMBONE-NEXT: pop {r7, pc}
275282
;
276283
; ARMV4-LABEL: test_old_load_64bit:
277284
; ARMV4: @ %bb.0:

0 commit comments

Comments
 (0)