[llvm] a85b37d - [M68k] Add support for lowering ATOMIC_SWAP
Min-Yih Hsu via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 27 10:59:45 PDT 2023
Author: Min-Yih Hsu
Date: 2023-03-27T10:58:52-07:00
New Revision: a85b37d0ca819776c6034c2dbda2b21e54e3393a
URL: https://github.com/llvm/llvm-project/commit/a85b37d0ca819776c6034c2dbda2b21e54e3393a
DIFF: https://github.com/llvm/llvm-project/commit/a85b37d0ca819776c6034c2dbda2b21e54e3393a.diff
LOG: [M68k] Add support for lowering ATOMIC_SWAP
Lower to calling __sync_lock_test_and_set_* for target < M68020.
Added:
Modified:
llvm/lib/Target/M68k/M68kISelLowering.cpp
llvm/test/CodeGen/M68k/Atomics/rmw.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/M68k/M68kISelLowering.cpp b/llvm/lib/Target/M68k/M68kISelLowering.cpp
index 8fce8bcba548e..c49b83fdc6eb0 100644
--- a/llvm/lib/Target/M68k/M68kISelLowering.cpp
+++ b/llvm/lib/Target/M68k/M68kISelLowering.cpp
@@ -178,6 +178,7 @@ M68kTargetLowering::M68kTargetLowering(const M68kTargetMachine &TM,
ISD::ATOMIC_LOAD_MAX,
ISD::ATOMIC_LOAD_UMIN,
ISD::ATOMIC_LOAD_UMAX,
+ ISD::ATOMIC_SWAP,
},
{MVT::i8, MVT::i16, MVT::i32}, LibCall);
diff --git a/llvm/test/CodeGen/M68k/Atomics/rmw.ll b/llvm/test/CodeGen/M68k/Atomics/rmw.ll
index 1ab8fac6486f6..e9c19a1ad5e6e 100644
--- a/llvm/test/CodeGen/M68k/Atomics/rmw.ll
+++ b/llvm/test/CodeGen/M68k/Atomics/rmw.ll
@@ -506,3 +506,85 @@ define i16 @atomicrmw_umax_i16(i16 %val, ptr %ptr) {
%old = atomicrmw umax ptr %ptr, i16 %val seq_cst
ret i16 %old
}
+
+define i16 @atomicrmw_xchg_i16(i16 %val, ptr %ptr) {
+; NO-ATOMIC-LABEL: atomicrmw_xchg_i16:
+; NO-ATOMIC: .cfi_startproc
+; NO-ATOMIC-NEXT: ; %bb.0: ; %entry
+; NO-ATOMIC-NEXT: suba.l #12, %sp
+; NO-ATOMIC-NEXT: .cfi_def_cfa_offset -16
+; NO-ATOMIC-NEXT: move.w (18,%sp), %d0
+; NO-ATOMIC-NEXT: and.l #65535, %d0
+; NO-ATOMIC-NEXT: move.l %d0, (4,%sp)
+; NO-ATOMIC-NEXT: move.l (20,%sp), (%sp)
+; NO-ATOMIC-NEXT: jsr __sync_lock_test_and_set_2 at PLT
+; NO-ATOMIC-NEXT: adda.l #12, %sp
+; NO-ATOMIC-NEXT: rts
+;
+; ATOMIC-LABEL: atomicrmw_xchg_i16:
+; ATOMIC: .cfi_startproc
+; ATOMIC-NEXT: ; %bb.0: ; %entry
+; ATOMIC-NEXT: suba.l #8, %sp
+; ATOMIC-NEXT: .cfi_def_cfa_offset -12
+; ATOMIC-NEXT: movem.l %d2-%d3, (0,%sp) ; 12-byte Folded Spill
+; ATOMIC-NEXT: move.w (14,%sp), %d1
+; ATOMIC-NEXT: move.l (16,%sp), %a0
+; ATOMIC-NEXT: move.w (%a0), %d2
+; ATOMIC-NEXT: move.w %d2, %d0
+; ATOMIC-NEXT: .LBB10_1: ; %atomicrmw.start
+; ATOMIC-NEXT: ; =>This Inner Loop Header: Depth=1
+; ATOMIC-NEXT: cas.w %d0, %d1, (%a0)
+; ATOMIC-NEXT: move.w %d0, %d3
+; ATOMIC-NEXT: sub.w %d2, %d3
+; ATOMIC-NEXT: seq %d2
+; ATOMIC-NEXT: sub.b #1, %d2
+; ATOMIC-NEXT: move.w %d0, %d2
+; ATOMIC-NEXT: bne .LBB10_1
+; ATOMIC-NEXT: ; %bb.2: ; %atomicrmw.end
+; ATOMIC-NEXT: movem.l (0,%sp), %d2-%d3 ; 12-byte Folded Reload
+; ATOMIC-NEXT: adda.l #8, %sp
+; ATOMIC-NEXT: rts
+entry:
+ %old = atomicrmw xchg ptr %ptr, i16 %val monotonic
+ ret i16 %old
+}
+
+define i32 @atomicrmw_xchg_i32(i32 %val, ptr %ptr) {
+; NO-ATOMIC-LABEL: atomicrmw_xchg_i32:
+; NO-ATOMIC: .cfi_startproc
+; NO-ATOMIC-NEXT: ; %bb.0: ; %entry
+; NO-ATOMIC-NEXT: suba.l #12, %sp
+; NO-ATOMIC-NEXT: .cfi_def_cfa_offset -16
+; NO-ATOMIC-NEXT: move.l (16,%sp), (4,%sp)
+; NO-ATOMIC-NEXT: move.l (20,%sp), (%sp)
+; NO-ATOMIC-NEXT: jsr __sync_lock_test_and_set_4 at PLT
+; NO-ATOMIC-NEXT: adda.l #12, %sp
+; NO-ATOMIC-NEXT: rts
+;
+; ATOMIC-LABEL: atomicrmw_xchg_i32:
+; ATOMIC: .cfi_startproc
+; ATOMIC-NEXT: ; %bb.0: ; %entry
+; ATOMIC-NEXT: suba.l #8, %sp
+; ATOMIC-NEXT: .cfi_def_cfa_offset -12
+; ATOMIC-NEXT: movem.l %d2-%d3, (0,%sp) ; 12-byte Folded Spill
+; ATOMIC-NEXT: move.l (12,%sp), %d1
+; ATOMIC-NEXT: move.l (16,%sp), %a0
+; ATOMIC-NEXT: move.l (%a0), %d2
+; ATOMIC-NEXT: move.l %d2, %d0
+; ATOMIC-NEXT: .LBB11_1: ; %atomicrmw.start
+; ATOMIC-NEXT: ; =>This Inner Loop Header: Depth=1
+; ATOMIC-NEXT: cas.l %d0, %d1, (%a0)
+; ATOMIC-NEXT: move.l %d0, %d3
+; ATOMIC-NEXT: sub.l %d2, %d3
+; ATOMIC-NEXT: seq %d2
+; ATOMIC-NEXT: sub.b #1, %d2
+; ATOMIC-NEXT: move.l %d0, %d2
+; ATOMIC-NEXT: bne .LBB11_1
+; ATOMIC-NEXT: ; %bb.2: ; %atomicrmw.end
+; ATOMIC-NEXT: movem.l (0,%sp), %d2-%d3 ; 12-byte Folded Reload
+; ATOMIC-NEXT: adda.l #8, %sp
+; ATOMIC-NEXT: rts
+entry:
+ %old = atomicrmw xchg ptr %ptr, i32 %val monotonic
+ ret i32 %old
+}
More information about the llvm-commits
mailing list