@@ -5259,20 +5259,26 @@ void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
52595259 bool IsNonSignedExtInstrNeedPromoted = false ;
52605260 int NewOpcode = -1 ;
52615261
5262- auto CheckAndSetNewOpcode = [&](int NewOpc) {
5263- if (!IsNonSignedExtInstrNeedPromoted) {
5264- NewOpcode = NewOpc;
5265- IsNonSignedExtInstrNeedPromoted = true ;
5266- }
5267- };
5262+ #define MapOpCode (A ) \
5263+ case A: \
5264+ NewOpcode = A##8 ; \
5265+ IsNonSignedExtInstrNeedPromoted = true ; \
5266+ break
5267+
5268+ switch (Opcode) {
5269+ MapOpCode (PPC::OR);
5270+ MapOpCode (PPC::ISEL);
5271+ MapOpCode (PPC::ORI);
5272+ MapOpCode (PPC::XORI);
5273+ MapOpCode (PPC::ORIS);
5274+ MapOpCode (PPC::XORIS);
5275+ MapOpCode (PPC::AND);
5276+ }
5277+ #undef MapOpCode
52685278
52695279 switch (Opcode) {
52705280 case PPC::OR:
5271- CheckAndSetNewOpcode (PPC::OR8);
5272- [[fallthrough]];
52735281 case PPC::ISEL:
5274- CheckAndSetNewOpcode (PPC::ISEL8);
5275- [[fallthrough]];
52765282 case PPC::OR8:
52775283 case PPC::PHI:
52785284 if (BinOpDepth < MAX_BINOP_DEPTH) {
@@ -5314,17 +5320,9 @@ void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
53145320 return ;
53155321 }
53165322 case PPC::ORI:
5317- CheckAndSetNewOpcode (PPC::ORI8);
5318- [[fallthrough]];
53195323 case PPC::XORI:
5320- CheckAndSetNewOpcode (PPC::XORI8);
5321- [[fallthrough]];
53225324 case PPC::ORIS:
5323- CheckAndSetNewOpcode (PPC::ORIS8);
5324- [[fallthrough]];
53255325 case PPC::XORIS:
5326- CheckAndSetNewOpcode (PPC::XORIS8);
5327- [[fallthrough]];
53285326 case PPC::ORI8:
53295327 case PPC::XORI8:
53305328 case PPC::ORIS8:
@@ -5334,87 +5332,84 @@ void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
53345332 break ;
53355333 }
53365334 case PPC::AND:
5337- CheckAndSetNewOpcode (PPC::AND8);
5338- [[fallthrough]];
53395335 case PPC::AND8: {
53405336 if (BinOpDepth < MAX_BINOP_DEPTH) {
53415337 Register SrcReg1 = MI->getOperand (1 ).getReg ();
5342- promoteInstr32To64ForElimEXTSW (SrcReg1, MRI, BinOpDepth, LV);
5338+ promoteInstr32To64ForElimEXTSW (SrcReg1, MRI, BinOpDepth + 1 , LV);
53435339 Register SrcReg2 = MI->getOperand (2 ).getReg ();
5344- promoteInstr32To64ForElimEXTSW (SrcReg2, MRI, BinOpDepth, LV);
5340+ promoteInstr32To64ForElimEXTSW (SrcReg2, MRI, BinOpDepth + 1 , LV);
53455341 }
53465342 break ;
53475343 }
5348- default :
5349- break ;
53505344 }
53515345
53525346 const PPCInstrInfo *TII =
53535347 MI->getMF ()->getSubtarget <PPCSubtarget>().getInstrInfo ();
5354- if (TII->isSExt32To64 (Opcode) || IsNonSignedExtInstrNeedPromoted) {
5348+ if (!TII->isSExt32To64 (Opcode) && !IsNonSignedExtInstrNeedPromoted)
5349+ return ;
53555350
5356- const TargetRegisterClass *RC = MRI->getRegClass (Reg);
5351+ const TargetRegisterClass *RC = MRI->getRegClass (Reg);
53575352
5358- if (RC == &PPC::G8RCRegClass || RC == &PPC::G8RC_and_G8RC_NOX0RegClass)
5359- return ;
5353+ if (RC == &PPC::G8RCRegClass || RC == &PPC::G8RC_and_G8RC_NOX0RegClass)
5354+ return ;
53605355
5361- // The TableGen function `get64BitInstrFromSignedExt32BitInstr` is used to
5362- // map the 32-bit instruction with the `SExt32To64` flag to the 64-bit
5363- // instruction with the same opcode.
5364- if (!IsNonSignedExtInstrNeedPromoted)
5365- NewOpcode = PPC::get64BitInstrFromSignedExt32BitInstr (Opcode);
5356+ // The TableGen function `get64BitInstrFromSignedExt32BitInstr` is used to
5357+ // map the 32-bit instruction with the `SExt32To64` flag to the 64-bit
5358+ // instruction with the same opcode.
5359+ if (!IsNonSignedExtInstrNeedPromoted)
5360+ NewOpcode = PPC::get64BitInstrFromSignedExt32BitInstr (Opcode);
53665361
5367- assert (NewOpcode != -1 &&
5368- " Must have a 64-bit opcode to map the 32-bit opcode!" );
5362+ assert (NewOpcode != -1 &&
5363+ " Must have a 64-bit opcode to map the 32-bit opcode!" );
53695364
5370- const TargetRegisterInfo *TRI = MRI->getTargetRegisterInfo ();
5371- const MCInstrDesc &MCID = TII->get (NewOpcode);
5372- const TargetRegisterClass *NewRC =
5373- TRI->getRegClass (MCID.operands ()[0 ].RegClass );
5365+ const TargetRegisterInfo *TRI = MRI->getTargetRegisterInfo ();
5366+ const MCInstrDesc &MCID = TII->get (NewOpcode);
5367+ const TargetRegisterClass *NewRC =
5368+ TRI->getRegClass (MCID.operands ()[0 ].RegClass );
53745369
5375- Register SrcReg = MI->getOperand (0 ).getReg ();
5376- const TargetRegisterClass *SrcRC = MRI->getRegClass (SrcReg);
5370+ Register SrcReg = MI->getOperand (0 ).getReg ();
5371+ const TargetRegisterClass *SrcRC = MRI->getRegClass (SrcReg);
53775372
5378- // If the register class of the defined register in the 32-bit instruction
5379- // is the same as the register class of the defined register in the promoted
5380- // 64-bit instruction, we do not need to promote the instruction.
5381- if (NewRC == SrcRC)
5382- return ;
5373+ // If the register class of the defined register in the 32-bit instruction
5374+ // is the same as the register class of the defined register in the promoted
5375+ // 64-bit instruction, we do not need to promote the instruction.
5376+ if (NewRC == SrcRC)
5377+ return ;
53835378
5384- DebugLoc DL = MI->getDebugLoc ();
5385- auto MBB = MI->getParent ();
5379+ DebugLoc DL = MI->getDebugLoc ();
5380+ auto MBB = MI->getParent ();
5381+
5382+ // Since the pseudo-opcode of the instruction is promoted from 32-bit to
5383+ // 64-bit, if the source reg class of the original instruction belongs to
5384+ // PPC::GRCRegClass or PPC::GPRC_and_GPRC_NOR0RegClass, we need to promote
5385+ // the operand to PPC::G8CRegClass or PPC::G8RC_and_G8RC_NOR0RegClass,
5386+ // respectively.
5387+ DenseMap<unsigned , Register> PromoteRegs;
5388+ for (unsigned i = 1 ; i < MI->getNumOperands (); i++) {
5389+ MachineOperand &Operand = MI->getOperand (i);
5390+ if (!Operand.isReg ())
5391+ continue ;
53865392
5387- // Since the pseudo-opcode of the instruction is promoted from 32-bit to
5388- // 64-bit, if the source reg class of the original instruction belongs to
5389- // PPC::GRCRegClass or PPC::GPRC_and_GPRC_NOR0RegClass, we need to promote
5390- // the operand to PPC::G8CRegClass or PPC::G8RC_and_G8RC_NOR0RegClass,
5391- // respectively.
5392- DenseMap<unsigned , Register> PromoteRegs;
5393- for (unsigned i = 1 ; i < MI->getNumOperands (); i++) {
5394- MachineOperand &Operand = MI->getOperand (i);
5395- if (Operand.isReg ()) {
5396- Register OperandReg = Operand.getReg ();
5397- if (!OperandReg.isVirtual ())
5398- continue ;
5399-
5400- const TargetRegisterClass *NewUsedRegRC =
5401- TRI->getRegClass (MCID.operands ()[i].RegClass );
5402- const TargetRegisterClass *OrgRC = MRI->getRegClass (OperandReg);
5403- if (NewUsedRegRC != OrgRC &&
5404- (OrgRC == &PPC::GPRCRegClass ||
5405- OrgRC == &PPC::GPRC_and_GPRC_NOR0RegClass)) {
5406- // Promote the used 32-bit register to 64-bit register.
5407- Register TmpReg = MRI->createVirtualRegister (NewUsedRegRC);
5408- Register DstTmpReg = MRI->createVirtualRegister (NewUsedRegRC);
5409- BuildMI (*MBB, MI, DL, TII->get (PPC::IMPLICIT_DEF), TmpReg);
5410- BuildMI (*MBB, MI, DL, TII->get (PPC::INSERT_SUBREG), DstTmpReg)
5411- .addReg (TmpReg)
5412- .addReg (OperandReg)
5413- .addImm (PPC::sub_32);
5414- PromoteRegs[i] = DstTmpReg;
5415- }
5416- }
5393+ Register OperandReg = Operand.getReg ();
5394+ if (!OperandReg.isVirtual ())
5395+ continue ;
5396+
5397+ const TargetRegisterClass *NewUsedRegRC =
5398+ TRI->getRegClass (MCID.operands ()[i].RegClass );
5399+ const TargetRegisterClass *OrgRC = MRI->getRegClass (OperandReg);
5400+ if (NewUsedRegRC != OrgRC && (OrgRC == &PPC::GPRCRegClass ||
5401+ OrgRC == &PPC::GPRC_and_GPRC_NOR0RegClass)) {
5402+ // Promote the used 32-bit register to 64-bit register.
5403+ Register TmpReg = MRI->createVirtualRegister (NewUsedRegRC);
5404+ Register DstTmpReg = MRI->createVirtualRegister (NewUsedRegRC);
5405+ BuildMI (*MBB, MI, DL, TII->get (PPC::IMPLICIT_DEF), TmpReg);
5406+ BuildMI (*MBB, MI, DL, TII->get (PPC::INSERT_SUBREG), DstTmpReg)
5407+ .addReg (TmpReg)
5408+ .addReg (OperandReg)
5409+ .addImm (PPC::sub_32);
5410+ PromoteRegs[i] = DstTmpReg;
54175411 }
5412+ }
54185413
54195414 Register NewDefinedReg = MRI->createVirtualRegister (NewRC);
54205415
@@ -5431,12 +5426,12 @@ void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
54315426
54325427 for (unsigned i = 1 ; i < Iter->getNumOperands (); i++) {
54335428 MachineOperand &Operand = Iter->getOperand (i);
5434- if (Operand.isReg ()) {
5435- Register OperandReg = Operand. getReg () ;
5436- if (!OperandReg. isVirtual ())
5437- continue ;
5438- LV-> recomputeForSingleDefVirtReg (OperandReg) ;
5439- }
5429+ if (! Operand.isReg ())
5430+ continue ;
5431+ Register OperandReg = Operand. getReg ();
5432+ if (!OperandReg. isVirtual ())
5433+ continue ;
5434+ LV-> recomputeForSingleDefVirtReg (OperandReg);
54405435 }
54415436
54425437 MI->eraseFromParent ();
@@ -5448,7 +5443,6 @@ void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
54485443 BuildMI (*MBB, ++Iter, DL, TII->get (PPC::COPY), SrcReg)
54495444 .addReg (NewDefinedReg, RegState::Kill, PPC::sub_32);
54505445 LV->recomputeForSingleDefVirtReg (NewDefinedReg);
5451- }
54525446 return ;
54535447}
54545448
0 commit comments