Skip to content

Commit ed69966

Browse files
syzaaratru
authored andcommitted
[PowerPC] Fix mask for __st[d/w/h/b]cx builtins (#104453)
These builtins are currently returning CR0 which will have the format [0, 0, flag_true_if_saved, XER]. We only want to return flag_true_if_saved. This patch adds a shift to remove the XER bit before returning. (cherry picked from commit 327edbe)
1 parent d9806ff commit ed69966

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

llvm/lib/Target/PowerPC/PPCInstr64Bit.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -2014,9 +2014,9 @@ def SLBSYNC : XForm_0<31, 338, (outs), (ins), "slbsync", IIC_SprSLBSYNC, []>;
20142014
} // IsISA3_0
20152015

20162016
def : Pat<(int_ppc_stdcx ForceXForm:$dst, g8rc:$A),
2017-
(STDCX g8rc:$A, ForceXForm:$dst)>;
2017+
(RLWINM (STDCX g8rc:$A, ForceXForm:$dst), 31, 31, 31)>;
20182018
def : Pat<(PPCStoreCond ForceXForm:$dst, g8rc:$A, 8),
2019-
(STDCX g8rc:$A, ForceXForm:$dst)>;
2019+
(RLWINM (STDCX g8rc:$A, ForceXForm:$dst), 31, 31, 31)>;
20202020

20212021
def : Pat<(i64 (int_ppc_mfspr timm:$SPR)),
20222022
(MFSPR8 $SPR)>;

llvm/lib/Target/PowerPC/PPCInstrInfo.td

+6-6
Original file line numberDiff line numberDiff line change
@@ -5286,13 +5286,13 @@ def : Pat<(i64 (bitreverse i64:$A)),
52865286
(OR8 (RLDICR DWBytes7654.DWord, 32, 31), DWBytes3210.DWord)>;
52875287

52885288
def : Pat<(int_ppc_stwcx ForceXForm:$dst, gprc:$A),
5289-
(STWCX gprc:$A, ForceXForm:$dst)>;
5289+
(RLWINM (STWCX gprc:$A, ForceXForm:$dst), 31, 31, 31)>;
52905290
def : Pat<(PPCStoreCond ForceXForm:$dst, gprc:$A, 4),
5291-
(STWCX gprc:$A, ForceXForm:$dst)>;
5291+
(RLWINM (STWCX gprc:$A, ForceXForm:$dst), 31, 31, 31)>;
52925292
def : Pat<(int_ppc_stbcx ForceXForm:$dst, gprc:$A),
5293-
(STBCX gprc:$A, ForceXForm:$dst)>;
5293+
(RLWINM (STBCX gprc:$A, ForceXForm:$dst), 31, 31, 31)>;
52945294
def : Pat<(PPCStoreCond ForceXForm:$dst, gprc:$A, 1),
5295-
(STBCX gprc:$A, ForceXForm:$dst)>;
5295+
(RLWINM (STBCX gprc:$A, ForceXForm:$dst), 31, 31, 31)>;
52965296

52975297
def : Pat<(int_ppc_fcfid f64:$A),
52985298
(XSCVSXDDP $A)>;
@@ -5322,9 +5322,9 @@ def : Pat<(int_ppc_mtmsr gprc:$RS),
53225322

53235323
let Predicates = [IsISA2_07] in {
53245324
def : Pat<(int_ppc_sthcx ForceXForm:$dst, gprc:$A),
5325-
(STHCX gprc:$A, ForceXForm:$dst)>;
5325+
(RLWINM (STHCX gprc:$A, ForceXForm:$dst), 31, 31, 31)>;
53265326
def : Pat<(PPCStoreCond ForceXForm:$dst, gprc:$A, 2),
5327-
(STHCX gprc:$A, ForceXForm:$dst)>;
5327+
(RLWINM (STHCX gprc:$A, ForceXForm:$dst), 31, 31, 31)>;
53285328
}
53295329
def : Pat<(int_ppc_dcbtstt ForceXForm:$dst),
53305330
(DCBTST 16, ForceXForm:$dst)>;

llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-LoadReserve-StoreCond-64bit-only.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ define dso_local i64 @test_stdcx(ptr %a, i64 %b) {
2626
; CHECK-NEXT: stdcx. 4, 0, 3
2727
; CHECK-NEXT: mfocrf 3, 128
2828
; CHECK-NEXT: srwi 3, 3, 28
29-
; CHECK-NEXT: extsw 3, 3
29+
; CHECK-NEXT: rlwinm 3, 3, 31, 31, 31
3030
; CHECK-NEXT: blr
3131
entry:
3232
%0 = tail call i32 @llvm.ppc.stdcx(ptr %a, i64 %b)

llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-LoadReserve-StoreCond.ll

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ define dso_local signext i32 @test_stwcx(ptr %a, i32 signext %b) {
3636
; CHECK-64-NEXT: stwcx. 4, 0, 3
3737
; CHECK-64-NEXT: mfocrf 3, 128
3838
; CHECK-64-NEXT: srwi 3, 3, 28
39-
; CHECK-64-NEXT: extsw 3, 3
39+
; CHECK-64-NEXT: rlwinm 3, 3, 31, 31, 31
4040
; CHECK-64-NEXT: blr
4141
;
4242
; CHECK-32-LABEL: test_stwcx:
4343
; CHECK-32: # %bb.0: # %entry
4444
; CHECK-32-NEXT: stwcx. 4, 0, 3
4545
; CHECK-32-NEXT: mfocrf 3, 128
4646
; CHECK-32-NEXT: srwi 3, 3, 28
47+
; CHECK-32-NEXT: rlwinm 3, 3, 31, 31, 31
4748
; CHECK-32-NEXT: blr
4849
entry:
4950
%0 = tail call i32 @llvm.ppc.stwcx(ptr %a, i32 %b)
@@ -57,14 +58,15 @@ define dso_local signext i32 @test_sthcx(ptr %a, i16 signext %val) {
5758
; CHECK-64-NEXT: sthcx. 4, 0, 3
5859
; CHECK-64-NEXT: mfocrf 3, 128
5960
; CHECK-64-NEXT: srwi 3, 3, 28
60-
; CHECK-64-NEXT: extsw 3, 3
61+
; CHECK-64-NEXT: rlwinm 3, 3, 31, 31, 31
6162
; CHECK-64-NEXT: blr
6263
;
6364
; CHECK-32-LABEL: test_sthcx:
6465
; CHECK-32: # %bb.0: # %entry
6566
; CHECK-32-NEXT: sthcx. 4, 0, 3
6667
; CHECK-32-NEXT: mfocrf 3, 128
6768
; CHECK-32-NEXT: srwi 3, 3, 28
69+
; CHECK-32-NEXT: rlwinm 3, 3, 31, 31, 31
6870
; CHECK-32-NEXT: blr
6971
entry:
7072
%0 = sext i16 %val to i32
@@ -79,14 +81,15 @@ define signext i32 @test_stbcx(ptr %addr, i8 signext %val) {
7981
; CHECK-64-NEXT: stbcx. 4, 0, 3
8082
; CHECK-64-NEXT: mfocrf 3, 128
8183
; CHECK-64-NEXT: srwi 3, 3, 28
82-
; CHECK-64-NEXT: extsw 3, 3
84+
; CHECK-64-NEXT: rlwinm 3, 3, 31, 31, 31
8385
; CHECK-64-NEXT: blr
8486
;
8587
; CHECK-32-LABEL: test_stbcx:
8688
; CHECK-32: # %bb.0: # %entry
8789
; CHECK-32-NEXT: stbcx. 4, 0, 3
8890
; CHECK-32-NEXT: mfocrf 3, 128
8991
; CHECK-32-NEXT: srwi 3, 3, 28
92+
; CHECK-32-NEXT: rlwinm 3, 3, 31, 31, 31
9093
; CHECK-32-NEXT: blr
9194
entry:
9295
%conv = sext i8 %val to i32

0 commit comments

Comments
 (0)