Index: lib/Target/PowerPC/PPCInstrInfo.h =================================================================== --- lib/Target/PowerPC/PPCInstrInfo.h +++ lib/Target/PowerPC/PPCInstrInfo.h @@ -414,7 +414,8 @@ MachineInstr **KilledDef = nullptr) const; void replaceInstrWithLI(MachineInstr &MI, const LoadImmediateInfo &LII) const; - bool instrHasImmForm(const MachineInstr &MI, ImmInstrInfo &III) const; + bool instrHasImmForm(const MachineInstr &MI, ImmInstrInfo &III, + bool PostRA) const; /// getRegNumForOperand - some operands use different numbering schemes /// for the same registers. For example, a VSX instruction may have any of Index: lib/Target/PowerPC/PPCInstrInfo.cpp =================================================================== --- lib/Target/PowerPC/PPCInstrInfo.cpp +++ lib/Target/PowerPC/PPCInstrInfo.cpp @@ -2319,7 +2319,7 @@ Opc == PPC::RLDICL_32 || Opc == PPC::RLDICL_32_64 || Opc == PPC::RLWINM || Opc == PPC::RLWINMo || Opc == PPC::RLWINM8 || Opc == PPC::RLWINM8o; - if (!instrHasImmForm(MI, III) && !ConvertibleImmForm) + if (!instrHasImmForm(MI, III, true) && !ConvertibleImmForm) return nullptr; // Don't convert or %X, %Y, %Y since that's just a register move. @@ -2421,7 +2421,7 @@ *KilledDef = DefMI; ImmInstrInfo III; - bool HasImmForm = instrHasImmForm(MI, III); + bool HasImmForm = instrHasImmForm(MI, III, PostRA); // If this is a reg+reg instruction that has a reg+imm form, // and one of the operands is produced by an add-immediate, // try to convert it. @@ -2645,7 +2645,7 @@ } bool PPCInstrInfo::instrHasImmForm(const MachineInstr &MI, - ImmInstrInfo &III) const { + ImmInstrInfo &III, bool PostRA) const { unsigned Opc = MI.getOpcode(); // The vast majority of the instructions would need their operand 2 replaced // with an immediate when switching to the reg+imm form. A marked exception @@ -2946,7 +2946,9 @@ case PPC::STFDUX: III.ImmOpcode = PPC::STFDU; break; } break; - // Power9 only. + // Power9 only. Some of these are being replaced by pseudo-instructions which + // are expanded post-ra. We cannot do anything about these if we are already + // post-ra. case PPC::LXVX: case PPC::LXSSPX: case PPC::LXSDX: @@ -2969,11 +2971,15 @@ III.ImmMustBeMultipleOf = 16; break; case PPC::LXSSPX: - III.ImmOpcode = PPC::LXSSP; + if (PostRA) + return false; + III.ImmOpcode = PPC::DFLOADf32; III.ImmMustBeMultipleOf = 4; break; case PPC::LXSDX: - III.ImmOpcode = PPC::LXSD; + if (PostRA) + return false; + III.ImmOpcode = PPC::DFLOADf64; III.ImmMustBeMultipleOf = 4; break; case PPC::STXVX: @@ -2981,11 +2987,15 @@ III.ImmMustBeMultipleOf = 16; break; case PPC::STXSSPX: - III.ImmOpcode = PPC::STXSSP; + if (PostRA) + return false; + III.ImmOpcode = PPC::DFSTOREf32; III.ImmMustBeMultipleOf = 4; break; case PPC::STXSDX: - III.ImmOpcode = PPC::STXSD; + if (PostRA) + return false; + III.ImmOpcode = PPC::DFSTOREf64; III.ImmMustBeMultipleOf = 4; break; } Index: test/CodeGen/PowerPC/convert-rr-to-ri-instrs.mir =================================================================== --- test/CodeGen/PowerPC/convert-rr-to-ri-instrs.mir +++ test/CodeGen/PowerPC/convert-rr-to-ri-instrs.mir @@ -3265,15 +3265,15 @@ %4 = INSERT_SUBREG %5, killed %3, 1 %6 = LI8 100 %7 = LXSDX %0, killed %6, implicit $rm :: (load 8 from %ir.arrayidx, !tbaa !12) - ; CHECK: LXSD 100, %0 - ; CHECK-LATE: lxsd 0, 100(3) + ; CHECK: DFLOADf64 100, %0 + ; FIXME: We should be able to transform this in pre-emit based on reg number %8 = ADDI %2, 2 %10 = IMPLICIT_DEF %9 = INSERT_SUBREG %10, killed %8, 1 %11 = LI8 -120 %12 = LXSDX %0, killed %11, implicit $rm :: (load 8 from %ir.arrayidx3, !tbaa !12) - ; CHECK: LXSD -120, %0 - ; CHECK-LATE: lxsd 1, -120(3) + ; CHECK: DFLOADf64 -120, %0 + ; FIXME: We should be able to transform this in pre-emit based on reg number %13 = XSADDDP killed %7, killed %12, implicit $rm $f1 = COPY %13 BLR8 implicit $lr8, implicit $rm, implicit $f1 @@ -3338,15 +3338,15 @@ %4 = INSERT_SUBREG %5, killed %3, 1 %6 = LI8 96 %7 = LXSSPX %0, killed %6 :: (load 4 from %ir.arrayidx, !tbaa !14) - ; CHECK: LXSSP 96, %0 - ; CHECK-LATE: lxssp 0, 96(3) + ; CHECK: DFLOADf32 96, %0 + ; FIXME: We should be able to transform this in pre-emit based on reg number %8 = ADDI %2, 2 %10 = IMPLICIT_DEF %9 = INSERT_SUBREG %10, killed %8, 1 %11 = LI8 -92 %12 = LXSSPX %0, killed %11 :: (load 4 from %ir.arrayidx3, !tbaa !14) - ; CHECK: LXSSP -92, %0 - ; CHECK-LATE: lxssp 1, -92(3) + ; CHECK: DFLOADf32 -92, %0 + ; FIXME: We should be able to transform this in pre-emit based on reg number %13 = XSADDSP killed %7, killed %12 $f1 = COPY %13 BLR8 implicit $lr8, implicit $rm, implicit $f1 @@ -6031,8 +6031,8 @@ %0 = COPY $x3 %3 = LI8 444 STXSSPX %1, %0, killed %3 :: (store 4 into %ir.arrayidx, !tbaa !14) - ; CHECK: STXSSP %1, 444, %0 - ; CHECK-LATE: stxssp 1, 444(3) + ; CHECK: DFSTOREf32 %1, 444, %0 + ; FIXME: We should be able to transform this in pre-emit based on reg number BLR8 implicit $lr8, implicit $rm ... @@ -6083,8 +6083,8 @@ %0 = COPY $x3 %3 = LI8 4 STXSDX %1, %0, killed %3, implicit $rm :: (store 8 into %ir.arrayidx, !tbaa !12) - ; CHECK: STXSD %1, 4, %0 - ; CHECK-LATE: stxsd 1, 4(3) + ; CHECK: DFSTOREf64 %1, 4, %0 + ; FIXME: We should be able to transform this in pre-emit based on reg number BLR8 implicit $lr8, implicit $rm ...