Skip to content

Commit 3378514

Browse files
authored
[RISCV] Use any_extend for type legalizing atomic_compare_swap with Zacas. (#77669)
With Zacas we will use amocas.w which doesn't require the input to be sign extended.
1 parent 1c34257 commit 3378514

File tree

3 files changed

+6
-22
lines changed

3 files changed

+6
-22
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19364,6 +19364,11 @@ bool RISCVTargetLowering::isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
1936419364
return false;
1936519365
}
1936619366

19367+
ISD::NodeType RISCVTargetLowering::getExtendForAtomicCmpSwapArg() const {
19368+
// Zacas will use amocas.w which does not require extension.
19369+
return Subtarget.hasStdExtZacas() ? ISD::ANY_EXTEND : ISD::SIGN_EXTEND;
19370+
}
19371+
1936719372
Register RISCVTargetLowering::getExceptionPointerRegister(
1936819373
const Constant *PersonalityFn) const {
1936919374
return RISCV::X10;

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,9 +633,7 @@ class RISCVTargetLowering : public TargetLowering {
633633
return ISD::SIGN_EXTEND;
634634
}
635635

636-
ISD::NodeType getExtendForAtomicCmpSwapArg() const override {
637-
return ISD::SIGN_EXTEND;
638-
}
636+
ISD::NodeType getExtendForAtomicCmpSwapArg() const override;
639637

640638
bool shouldTransformSignedTruncationCheck(EVT XVT,
641639
unsigned KeptBits) const override;

llvm/test/CodeGen/RISCV/atomic-cmpxchg.ll

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,7 +3320,6 @@ define void @cmpxchg_i32_monotonic_monotonic(ptr %ptr, i32 %cmp, i32 %val) nounw
33203320
;
33213321
; RV64IA-ZACAS-LABEL: cmpxchg_i32_monotonic_monotonic:
33223322
; RV64IA-ZACAS: # %bb.0:
3323-
; RV64IA-ZACAS-NEXT: sext.w a1, a1
33243323
; RV64IA-ZACAS-NEXT: amocas.w a1, a2, (a0)
33253324
; RV64IA-ZACAS-NEXT: ret
33263325
;
@@ -3412,7 +3411,6 @@ define void @cmpxchg_i32_acquire_monotonic(ptr %ptr, i32 %cmp, i32 %val) nounwin
34123411
;
34133412
; RV64IA-WMO-ZACAS-LABEL: cmpxchg_i32_acquire_monotonic:
34143413
; RV64IA-WMO-ZACAS: # %bb.0:
3415-
; RV64IA-WMO-ZACAS-NEXT: sext.w a1, a1
34163414
; RV64IA-WMO-ZACAS-NEXT: amocas.w.aq a1, a2, (a0)
34173415
; RV64IA-WMO-ZACAS-NEXT: ret
34183416
;
@@ -3430,7 +3428,6 @@ define void @cmpxchg_i32_acquire_monotonic(ptr %ptr, i32 %cmp, i32 %val) nounwin
34303428
;
34313429
; RV64IA-TSO-ZACAS-LABEL: cmpxchg_i32_acquire_monotonic:
34323430
; RV64IA-TSO-ZACAS: # %bb.0:
3433-
; RV64IA-TSO-ZACAS-NEXT: sext.w a1, a1
34343431
; RV64IA-TSO-ZACAS-NEXT: amocas.w a1, a2, (a0)
34353432
; RV64IA-TSO-ZACAS-NEXT: ret
34363433
%res = cmpxchg ptr %ptr, i32 %cmp, i32 %val acquire monotonic
@@ -3510,7 +3507,6 @@ define void @cmpxchg_i32_acquire_acquire(ptr %ptr, i32 %cmp, i32 %val) nounwind
35103507
;
35113508
; RV64IA-WMO-ZACAS-LABEL: cmpxchg_i32_acquire_acquire:
35123509
; RV64IA-WMO-ZACAS: # %bb.0:
3513-
; RV64IA-WMO-ZACAS-NEXT: sext.w a1, a1
35143510
; RV64IA-WMO-ZACAS-NEXT: amocas.w.aq a1, a2, (a0)
35153511
; RV64IA-WMO-ZACAS-NEXT: ret
35163512
;
@@ -3528,7 +3524,6 @@ define void @cmpxchg_i32_acquire_acquire(ptr %ptr, i32 %cmp, i32 %val) nounwind
35283524
;
35293525
; RV64IA-TSO-ZACAS-LABEL: cmpxchg_i32_acquire_acquire:
35303526
; RV64IA-TSO-ZACAS: # %bb.0:
3531-
; RV64IA-TSO-ZACAS-NEXT: sext.w a1, a1
35323527
; RV64IA-TSO-ZACAS-NEXT: amocas.w a1, a2, (a0)
35333528
; RV64IA-TSO-ZACAS-NEXT: ret
35343529
%res = cmpxchg ptr %ptr, i32 %cmp, i32 %val acquire acquire
@@ -3608,7 +3603,6 @@ define void @cmpxchg_i32_release_monotonic(ptr %ptr, i32 %cmp, i32 %val) nounwin
36083603
;
36093604
; RV64IA-WMO-ZACAS-LABEL: cmpxchg_i32_release_monotonic:
36103605
; RV64IA-WMO-ZACAS: # %bb.0:
3611-
; RV64IA-WMO-ZACAS-NEXT: sext.w a1, a1
36123606
; RV64IA-WMO-ZACAS-NEXT: amocas.w.rl a1, a2, (a0)
36133607
; RV64IA-WMO-ZACAS-NEXT: ret
36143608
;
@@ -3626,7 +3620,6 @@ define void @cmpxchg_i32_release_monotonic(ptr %ptr, i32 %cmp, i32 %val) nounwin
36263620
;
36273621
; RV64IA-TSO-ZACAS-LABEL: cmpxchg_i32_release_monotonic:
36283622
; RV64IA-TSO-ZACAS: # %bb.0:
3629-
; RV64IA-TSO-ZACAS-NEXT: sext.w a1, a1
36303623
; RV64IA-TSO-ZACAS-NEXT: amocas.w a1, a2, (a0)
36313624
; RV64IA-TSO-ZACAS-NEXT: ret
36323625
%res = cmpxchg ptr %ptr, i32 %cmp, i32 %val release monotonic
@@ -3706,7 +3699,6 @@ define void @cmpxchg_i32_release_acquire(ptr %ptr, i32 %cmp, i32 %val) nounwind
37063699
;
37073700
; RV64IA-WMO-ZACAS-LABEL: cmpxchg_i32_release_acquire:
37083701
; RV64IA-WMO-ZACAS: # %bb.0:
3709-
; RV64IA-WMO-ZACAS-NEXT: sext.w a1, a1
37103702
; RV64IA-WMO-ZACAS-NEXT: amocas.w.aqrl a1, a2, (a0)
37113703
; RV64IA-WMO-ZACAS-NEXT: ret
37123704
;
@@ -3724,7 +3716,6 @@ define void @cmpxchg_i32_release_acquire(ptr %ptr, i32 %cmp, i32 %val) nounwind
37243716
;
37253717
; RV64IA-TSO-ZACAS-LABEL: cmpxchg_i32_release_acquire:
37263718
; RV64IA-TSO-ZACAS: # %bb.0:
3727-
; RV64IA-TSO-ZACAS-NEXT: sext.w a1, a1
37283719
; RV64IA-TSO-ZACAS-NEXT: amocas.w a1, a2, (a0)
37293720
; RV64IA-TSO-ZACAS-NEXT: ret
37303721
%res = cmpxchg ptr %ptr, i32 %cmp, i32 %val release acquire
@@ -3804,7 +3795,6 @@ define void @cmpxchg_i32_acq_rel_monotonic(ptr %ptr, i32 %cmp, i32 %val) nounwin
38043795
;
38053796
; RV64IA-WMO-ZACAS-LABEL: cmpxchg_i32_acq_rel_monotonic:
38063797
; RV64IA-WMO-ZACAS: # %bb.0:
3807-
; RV64IA-WMO-ZACAS-NEXT: sext.w a1, a1
38083798
; RV64IA-WMO-ZACAS-NEXT: amocas.w.aqrl a1, a2, (a0)
38093799
; RV64IA-WMO-ZACAS-NEXT: ret
38103800
;
@@ -3822,7 +3812,6 @@ define void @cmpxchg_i32_acq_rel_monotonic(ptr %ptr, i32 %cmp, i32 %val) nounwin
38223812
;
38233813
; RV64IA-TSO-ZACAS-LABEL: cmpxchg_i32_acq_rel_monotonic:
38243814
; RV64IA-TSO-ZACAS: # %bb.0:
3825-
; RV64IA-TSO-ZACAS-NEXT: sext.w a1, a1
38263815
; RV64IA-TSO-ZACAS-NEXT: amocas.w a1, a2, (a0)
38273816
; RV64IA-TSO-ZACAS-NEXT: ret
38283817
%res = cmpxchg ptr %ptr, i32 %cmp, i32 %val acq_rel monotonic
@@ -3902,7 +3891,6 @@ define void @cmpxchg_i32_acq_rel_acquire(ptr %ptr, i32 %cmp, i32 %val) nounwind
39023891
;
39033892
; RV64IA-WMO-ZACAS-LABEL: cmpxchg_i32_acq_rel_acquire:
39043893
; RV64IA-WMO-ZACAS: # %bb.0:
3905-
; RV64IA-WMO-ZACAS-NEXT: sext.w a1, a1
39063894
; RV64IA-WMO-ZACAS-NEXT: amocas.w.aqrl a1, a2, (a0)
39073895
; RV64IA-WMO-ZACAS-NEXT: ret
39083896
;
@@ -3920,7 +3908,6 @@ define void @cmpxchg_i32_acq_rel_acquire(ptr %ptr, i32 %cmp, i32 %val) nounwind
39203908
;
39213909
; RV64IA-TSO-ZACAS-LABEL: cmpxchg_i32_acq_rel_acquire:
39223910
; RV64IA-TSO-ZACAS: # %bb.0:
3923-
; RV64IA-TSO-ZACAS-NEXT: sext.w a1, a1
39243911
; RV64IA-TSO-ZACAS-NEXT: amocas.w a1, a2, (a0)
39253912
; RV64IA-TSO-ZACAS-NEXT: ret
39263913
%res = cmpxchg ptr %ptr, i32 %cmp, i32 %val acq_rel acquire
@@ -4000,7 +3987,6 @@ define void @cmpxchg_i32_seq_cst_monotonic(ptr %ptr, i32 %cmp, i32 %val) nounwin
40003987
;
40013988
; RV64IA-WMO-ZACAS-LABEL: cmpxchg_i32_seq_cst_monotonic:
40023989
; RV64IA-WMO-ZACAS: # %bb.0:
4003-
; RV64IA-WMO-ZACAS-NEXT: sext.w a1, a1
40043990
; RV64IA-WMO-ZACAS-NEXT: amocas.w.aqrl a1, a2, (a0)
40053991
; RV64IA-WMO-ZACAS-NEXT: ret
40063992
;
@@ -4018,7 +4004,6 @@ define void @cmpxchg_i32_seq_cst_monotonic(ptr %ptr, i32 %cmp, i32 %val) nounwin
40184004
;
40194005
; RV64IA-TSO-ZACAS-LABEL: cmpxchg_i32_seq_cst_monotonic:
40204006
; RV64IA-TSO-ZACAS: # %bb.0:
4021-
; RV64IA-TSO-ZACAS-NEXT: sext.w a1, a1
40224007
; RV64IA-TSO-ZACAS-NEXT: amocas.w a1, a2, (a0)
40234008
; RV64IA-TSO-ZACAS-NEXT: ret
40244009
%res = cmpxchg ptr %ptr, i32 %cmp, i32 %val seq_cst monotonic
@@ -4098,7 +4083,6 @@ define void @cmpxchg_i32_seq_cst_acquire(ptr %ptr, i32 %cmp, i32 %val) nounwind
40984083
;
40994084
; RV64IA-WMO-ZACAS-LABEL: cmpxchg_i32_seq_cst_acquire:
41004085
; RV64IA-WMO-ZACAS: # %bb.0:
4101-
; RV64IA-WMO-ZACAS-NEXT: sext.w a1, a1
41024086
; RV64IA-WMO-ZACAS-NEXT: amocas.w.aqrl a1, a2, (a0)
41034087
; RV64IA-WMO-ZACAS-NEXT: ret
41044088
;
@@ -4116,7 +4100,6 @@ define void @cmpxchg_i32_seq_cst_acquire(ptr %ptr, i32 %cmp, i32 %val) nounwind
41164100
;
41174101
; RV64IA-TSO-ZACAS-LABEL: cmpxchg_i32_seq_cst_acquire:
41184102
; RV64IA-TSO-ZACAS: # %bb.0:
4119-
; RV64IA-TSO-ZACAS-NEXT: sext.w a1, a1
41204103
; RV64IA-TSO-ZACAS-NEXT: amocas.w a1, a2, (a0)
41214104
; RV64IA-TSO-ZACAS-NEXT: ret
41224105
%res = cmpxchg ptr %ptr, i32 %cmp, i32 %val seq_cst acquire
@@ -4196,7 +4179,6 @@ define void @cmpxchg_i32_seq_cst_seq_cst(ptr %ptr, i32 %cmp, i32 %val) nounwind
41964179
;
41974180
; RV64IA-WMO-ZACAS-LABEL: cmpxchg_i32_seq_cst_seq_cst:
41984181
; RV64IA-WMO-ZACAS: # %bb.0:
4199-
; RV64IA-WMO-ZACAS-NEXT: sext.w a1, a1
42004182
; RV64IA-WMO-ZACAS-NEXT: amocas.w.aqrl a1, a2, (a0)
42014183
; RV64IA-WMO-ZACAS-NEXT: ret
42024184
;
@@ -4214,7 +4196,6 @@ define void @cmpxchg_i32_seq_cst_seq_cst(ptr %ptr, i32 %cmp, i32 %val) nounwind
42144196
;
42154197
; RV64IA-TSO-ZACAS-LABEL: cmpxchg_i32_seq_cst_seq_cst:
42164198
; RV64IA-TSO-ZACAS: # %bb.0:
4217-
; RV64IA-TSO-ZACAS-NEXT: sext.w a1, a1
42184199
; RV64IA-TSO-ZACAS-NEXT: amocas.w a1, a2, (a0)
42194200
; RV64IA-TSO-ZACAS-NEXT: ret
42204201
%res = cmpxchg ptr %ptr, i32 %cmp, i32 %val seq_cst seq_cst

0 commit comments

Comments
 (0)