Skip to content

Commit 71f1ab5

Browse files
committed
[PowerPC] Remove unnecessary XSRSP instruction
MI peephole will remove unnecessary FRSP instructions. This patch removes such unnecessary XSRSP. Reviewed By: steven.zhang Differential Revision: https://reviews.llvm.org/D77208
1 parent 20cb7a9 commit 71f1ab5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

llvm/lib/Target/PowerPC/PPCMIPeephole.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,12 @@ bool PPCMIPeephole::simplifyCode(void) {
541541
if (!P1 || !P2)
542542
break;
543543

544-
// Remove the passed FRSP instruction if it only feeds this MI and
545-
// set any uses of that FRSP (in this MI) to the source of the FRSP.
544+
// Remove the passed FRSP/XSRSP instruction if it only feeds this MI
545+
// and set any uses of that FRSP/XSRSP (in this MI) to the source of
546+
// the FRSP/XSRSP.
546547
auto removeFRSPIfPossible = [&](MachineInstr *RoundInstr) {
547-
if (RoundInstr->getOpcode() == PPC::FRSP &&
548+
unsigned Opc = RoundInstr->getOpcode();
549+
if ((Opc == PPC::FRSP || Opc == PPC::XSRSP) &&
548550
MRI->hasOneNonDBGUse(RoundInstr->getOperand(0).getReg())) {
549551
Simplified = true;
550552
Register ConvReg1 = RoundInstr->getOperand(1).getReg();
@@ -554,7 +556,7 @@ bool PPCMIPeephole::simplifyCode(void) {
554556
if (Use.getOperand(i).isReg() &&
555557
Use.getOperand(i).getReg() == FRSPDefines)
556558
Use.getOperand(i).setReg(ConvReg1);
557-
LLVM_DEBUG(dbgs() << "Removing redundant FRSP:\n");
559+
LLVM_DEBUG(dbgs() << "Removing redundant FRSP/XSRSP:\n");
558560
LLVM_DEBUG(RoundInstr->dump());
559561
LLVM_DEBUG(dbgs() << "As it feeds instruction:\n");
560562
LLVM_DEBUG(MI.dump());

llvm/test/CodeGen/PowerPC/mi-simplify-code.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ body: |
5656
# CHECK-LABEL: remove_xsrsp
5757
# CHECK: sldi 4, 4, 2
5858
# CHECK-NEXT: lfsux 0, 3, 4
59-
# CHECK-NEXT: xsrsp 0, 0
59+
# CHECK-NOT: xsrsp
6060
# CHECK-NEXT: lfs 1, 8(3)
6161
# CHECK-NEXT: xxmrghd 0, 1, 0
6262
# CHECK-NEXT: xvcvdpsp 34, 0

0 commit comments

Comments
 (0)