Skip to content

Commit cb0c034

Browse files
[PowerPC] Fix issue where vsrq is given incorrect shift vector
The new Power10 instruction vsrq was being given the wrong shift vector. The original code assumed that the shift would be found in bits 121 to 127. This is not correct. The shift is found in bits 57 to 63. This can be fixed by swaping the first and second double words. Reviewed By: nemanjai, #powerpc Differential Revision: https://reviews.llvm.org/D94113
1 parent 816dba4 commit cb0c034

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

llvm/lib/Target/PowerPC/PPCInstrPrefix.td

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,18 +2521,6 @@ let Predicates = [IsISA3_1] in {
25212521
(EXTRACT_SUBREG (XVTLSBB (COPY_TO_REGCLASS $XB, VSRC)), sub_lt)>;
25222522
def : Pat<(i32 (int_ppc_vsx_xvtlsbb v16i8:$XB, 0)),
25232523
(EXTRACT_SUBREG (XVTLSBB (COPY_TO_REGCLASS $XB, VSRC)), sub_eq)>;
2524-
def : Pat<(v1i128 (shl v1i128:$VRA, v1i128:$VRB)),
2525-
(v1i128 (VSLQ v1i128:$VRA, v1i128:$VRB))>;
2526-
def : Pat<(v1i128 (PPCshl v1i128:$VRA, v1i128:$VRB)),
2527-
(v1i128 (VSLQ v1i128:$VRA, v1i128:$VRB))>;
2528-
def : Pat<(v1i128 (srl v1i128:$VRA, v1i128:$VRB)),
2529-
(v1i128 (VSRQ v1i128:$VRA, v1i128:$VRB))>;
2530-
def : Pat<(v1i128 (PPCsrl v1i128:$VRA, v1i128:$VRB)),
2531-
(v1i128 (VSRQ v1i128:$VRA, v1i128:$VRB))>;
2532-
def : Pat<(v1i128 (sra v1i128:$VRA, v1i128:$VRB)),
2533-
(v1i128 (VSRAQ v1i128:$VRA, v1i128:$VRB))>;
2534-
def : Pat<(v1i128 (PPCsra v1i128:$VRA, v1i128:$VRB)),
2535-
(v1i128 (VSRAQ v1i128:$VRA, v1i128:$VRB))>;
25362524

25372525
def : Pat <(v1i128 (PPClxvrzx xoaddr:$src, 8)),
25382526
(v1i128 (COPY_TO_REGCLASS (LXVRBX xoaddr:$src), VRRC))>;
@@ -2570,6 +2558,35 @@ let AddedComplexity = 400, Predicates = [IsISA3_1, IsLittleEndian] in {
25702558
(STXVRDX $src, xoaddr:$dst)>;
25712559
}
25722560

2561+
// FIXME: The swap is overkill when the shift amount is a constant.
2562+
// We should just fix the constant in the DAG.
2563+
let AddedComplexity = 400, Predicates = [IsISA3_1, HasVSX] in {
2564+
def : Pat<(v1i128 (shl v1i128:$VRA, v1i128:$VRB)),
2565+
(v1i128 (VSLQ v1i128:$VRA,
2566+
(XXPERMDI (COPY_TO_REGCLASS $VRB, VSRC),
2567+
(COPY_TO_REGCLASS $VRB, VSRC), 2)))>;
2568+
def : Pat<(v1i128 (PPCshl v1i128:$VRA, v1i128:$VRB)),
2569+
(v1i128 (VSLQ v1i128:$VRA,
2570+
(XXPERMDI (COPY_TO_REGCLASS $VRB, VSRC),
2571+
(COPY_TO_REGCLASS $VRB, VSRC), 2)))>;
2572+
def : Pat<(v1i128 (srl v1i128:$VRA, v1i128:$VRB)),
2573+
(v1i128 (VSRQ v1i128:$VRA,
2574+
(XXPERMDI (COPY_TO_REGCLASS $VRB, VSRC),
2575+
(COPY_TO_REGCLASS $VRB, VSRC), 2)))>;
2576+
def : Pat<(v1i128 (PPCsrl v1i128:$VRA, v1i128:$VRB)),
2577+
(v1i128 (VSRQ v1i128:$VRA,
2578+
(XXPERMDI (COPY_TO_REGCLASS $VRB, VSRC),
2579+
(COPY_TO_REGCLASS $VRB, VSRC), 2)))>;
2580+
def : Pat<(v1i128 (sra v1i128:$VRA, v1i128:$VRB)),
2581+
(v1i128 (VSRAQ v1i128:$VRA,
2582+
(XXPERMDI (COPY_TO_REGCLASS $VRB, VSRC),
2583+
(COPY_TO_REGCLASS $VRB, VSRC), 2)))>;
2584+
def : Pat<(v1i128 (PPCsra v1i128:$VRA, v1i128:$VRB)),
2585+
(v1i128 (VSRAQ v1i128:$VRA,
2586+
(XXPERMDI (COPY_TO_REGCLASS $VRB, VSRC),
2587+
(COPY_TO_REGCLASS $VRB, VSRC), 2)))>;
2588+
}
2589+
25732590
class xxevalPattern <dag pattern, bits<8> imm> :
25742591
Pat<(v4i32 pattern), (XXEVAL $vA, $vB, $vC, imm)> {}
25752592

llvm/test/CodeGen/PowerPC/p10-vector-shift.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
define dso_local <1 x i128> @test_vec_vslq(<1 x i128> %a, <1 x i128> %b) {
1414
; CHECK-LABEL: test_vec_vslq:
1515
; CHECK: # %bb.0: # %entry
16+
; CHECK-NEXT: xxswapd v3, v3
1617
; CHECK-NEXT: vslq v2, v2, v3
1718
; CHECK-NEXT: blr
1819
entry:
@@ -24,6 +25,7 @@ entry:
2425
define dso_local <1 x i128> @test_vec_vsrq(<1 x i128> %a, <1 x i128> %b) {
2526
; CHECK-LABEL: test_vec_vsrq:
2627
; CHECK: # %bb.0: # %entry
28+
; CHECK-NEXT: xxswapd v3, v3
2729
; CHECK-NEXT: vsrq v2, v2, v3
2830
; CHECK-NEXT: blr
2931
entry:
@@ -35,6 +37,7 @@ entry:
3537
define dso_local <1 x i128> @test_vec_vsraq(<1 x i128> %a, <1 x i128> %b) {
3638
; CHECK-LABEL: test_vec_vsraq:
3739
; CHECK: # %bb.0: # %entry
40+
; CHECK-NEXT: xxswapd v3, v3
3841
; CHECK-NEXT: vsraq v2, v2, v3
3942
; CHECK-NEXT: blr
4043
entry:
@@ -46,6 +49,7 @@ entry:
4649
define dso_local <1 x i128> @test_vec_vslq2(<1 x i128> %a, <1 x i128> %b) {
4750
; CHECK-LABEL: test_vec_vslq2:
4851
; CHECK: # %bb.0: # %entry
52+
; CHECK-NEXT: xxswapd v3, v3
4953
; CHECK-NEXT: vslq v2, v2, v3
5054
; CHECK-NEXT: blr
5155
entry:
@@ -56,6 +60,7 @@ entry:
5660
define dso_local <1 x i128> @test_vec_vsrq2(<1 x i128> %a, <1 x i128> %b) {
5761
; CHECK-LABEL: test_vec_vsrq2:
5862
; CHECK: # %bb.0: # %entry
63+
; CHECK-NEXT: xxswapd v3, v3
5964
; CHECK-NEXT: vsrq v2, v2, v3
6065
; CHECK-NEXT: blr
6166
entry:
@@ -66,6 +71,7 @@ entry:
6671
define dso_local <1 x i128> @test_vec_vsraq2(<1 x i128> %a, <1 x i128> %b) {
6772
; CHECK-LABEL: test_vec_vsraq2:
6873
; CHECK: # %bb.0: # %entry
74+
; CHECK-NEXT: xxswapd v3, v3
6975
; CHECK-NEXT: vsraq v2, v2, v3
7076
; CHECK-NEXT: blr
7177
entry:

0 commit comments

Comments
 (0)