diff --git a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp --- a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp +++ b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp @@ -544,7 +544,8 @@ // Remove the passed FRSP instruction if it only feeds this MI and // set any uses of that FRSP (in this MI) to the source of the FRSP. auto removeFRSPIfPossible = [&](MachineInstr *RoundInstr) { - if (RoundInstr->getOpcode() == PPC::FRSP && + unsigned Opc = RoundInstr->getOpcode(); + if ((Opc == PPC::FRSP || Opc == PPC::XSRSP) && MRI->hasOneNonDBGUse(RoundInstr->getOperand(0).getReg())) { Simplified = true; Register ConvReg1 = RoundInstr->getOperand(1).getReg(); diff --git a/llvm/test/CodeGen/PowerPC/mi-simplify-code.mir b/llvm/test/CodeGen/PowerPC/mi-simplify-code.mir --- a/llvm/test/CodeGen/PowerPC/mi-simplify-code.mir +++ b/llvm/test/CodeGen/PowerPC/mi-simplify-code.mir @@ -56,7 +56,7 @@ # CHECK-LABEL: remove_xsrsp # CHECK: sldi 4, 4, 2 # CHECK-NEXT: lfsux 0, 3, 4 -# CHECK-NEXT: xsrsp 0, 0 +# CHECK-NOT: xsrsp # CHECK-NEXT: lfs 1, 8(3) # CHECK-NEXT: xxmrghd 0, 1, 0 # CHECK-NEXT: xvcvdpsp 34, 0