Skip to content

Commit 1d8f13a

Browse files
Ting WangTing Wang
Ting Wang
authored and
Ting Wang
committed
[PowerPC] add a peephole to remove redundant swap instructions after vector splats on P8
Vector store on P8 little endian will have swap instruction added before the store in PPCISelLowring. If the vector is generated by splat, the swap instruction can be eliminated. Reviewed By: shchenz Differential Revision: https://reviews.llvm.org/D139691
1 parent 41fdb4c commit 1d8f13a

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

llvm/lib/Target/PowerPC/PPCMIPeephole.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,18 @@ bool PPCMIPeephole::simplifyCode() {
641641
DefMI->getOperand(0).setReg(MI.getOperand(0).getReg());
642642
LLVM_DEBUG(dbgs() << "Removing redundant splat: ");
643643
LLVM_DEBUG(MI.dump());
644+
} else if (Immed == 2 &&
645+
(DefOpc == PPC::VSPLTB || DefOpc == PPC::VSPLTH ||
646+
DefOpc == PPC::VSPLTW || DefOpc == PPC::XXSPLTW)) {
647+
// Swap of various vector splats, convert to copy.
648+
ToErase = &MI;
649+
Simplified = true;
650+
LLVM_DEBUG(dbgs() << "Optimizing swap(vsplt[b|h|w]|xxspltw) => "
651+
"copy(vsplt[b|h|w]|xxspltw): ");
652+
LLVM_DEBUG(MI.dump());
653+
BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(PPC::COPY),
654+
MI.getOperand(0).getReg())
655+
.add(MI.getOperand(1));
644656
}
645657
break;
646658
}

llvm/test/CodeGen/PowerPC/VSX-XForm-Scalars.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ define void @testExpandPostRAPseudo(ptr nocapture readonly %ptr) {
1414
; CHECK-P8: lfiwzx f0, 0, r3
1515
; CHECK-P8: ld r4, .LC0@toc@l(r4)
1616
; CHECK-P8: xxspltw vs0, vs0, 1
17-
; CHECK-P8: xxswapd vs0, vs0
1817
; CHECK-P8; stxvd2x vs0, 0, r4
1918
; CHECK-P8: lis r4, 1024
2019
; CHECK-P8: lfiwax f0, 0, r3

llvm/test/CodeGen/PowerPC/aix-vsx-splatimm.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ define void @test_aix_splatimm(i32 %arg, i32 %arg1, i32 %arg2) {
4747
; CHECK-NEXT: li 3, 0
4848
; CHECK-NEXT: mullw 4, 4, 5
4949
; CHECK-NEXT: vsplth 2, 2, 3
50-
; CHECK-NEXT: xxswapd 0, 34
50+
; CHECK-NEXT: stxvd2x 34, 0, 3
5151
; CHECK-NEXT: neg 4, 4
5252
; CHECK-NEXT: mtvsrd 35, 4
53-
; CHECK-NEXT: stxvd2x 0, 0, 3
5453
; CHECK-NEXT: vsplth 3, 3, 3
55-
; CHECK-NEXT: xxswapd 1, 35
56-
; CHECK-NEXT: stxvd2x 1, 0, 3
54+
; CHECK-NEXT: stxvd2x 35, 0, 3
5755
bb:
5856
br i1 undef, label %bb22, label %bb3
5957

llvm/test/CodeGen/PowerPC/canonical-merge-shuffles.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,7 @@ define dso_local void @testByteSplat() #0 {
11961196
; CHECK-P7-NEXT: lvx v3, 0, r3
11971197
; CHECK-P7-NEXT: vperm v2, v3, v3, v2
11981198
; CHECK-P7-NEXT: vspltb v2, v2, 15
1199-
; CHECK-P7-NEXT: xxswapd vs0, v2
1200-
; CHECK-P7-NEXT: stxvd2x vs0, 0, r3
1199+
; CHECK-P7-NEXT: stxvd2x v2, 0, r3
12011200
; CHECK-P7-NEXT: blr
12021201
;
12031202
; P8-AIX-LABEL: testByteSplat:

llvm/test/CodeGen/PowerPC/load-and-splat.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ define dso_local void @test2(ptr nocapture %c, ptr nocapture readonly %a) local_
8484
; P8-NEXT: addi r4, r4, 12
8585
; P8-NEXT: lfiwzx f0, 0, r4
8686
; P8-NEXT: xxspltw vs0, vs0, 1
87-
; P8-NEXT: xxswapd vs0, vs0
8887
; P8-NEXT: stxvd2x vs0, 0, r3
8988
; P8-NEXT: blr
9089
;
@@ -141,7 +140,6 @@ define dso_local void @test3(ptr nocapture %c, ptr nocapture readonly %a) local_
141140
; P8-NEXT: addi r4, r4, 12
142141
; P8-NEXT: lfiwzx f0, 0, r4
143142
; P8-NEXT: xxspltw vs0, vs0, 1
144-
; P8-NEXT: xxswapd vs0, vs0
145143
; P8-NEXT: stxvd2x vs0, 0, r3
146144
; P8-NEXT: blr
147145
;

0 commit comments

Comments
 (0)