@@ -108,6 +108,8 @@ struct BlockSplitInfo {
108108 MachineInstr *OrigBranch;
109109 MachineInstr *SplitBefore;
110110 MachineInstr *SplitCond;
111+ unsigned OrigSubreg;
112+ unsigned SplitCondSubreg;
111113 bool InvertNewBranch;
112114 bool InvertOrigBranch;
113115 bool BranchToFallThrough;
@@ -220,7 +222,7 @@ static bool splitMBB(BlockSplitInfo &BSI) {
220222 // Add the branches to ThisMBB.
221223 BuildMI (*ThisMBB, ThisMBB->end (), BSI.SplitBefore ->getDebugLoc (),
222224 TII->get (NewBROpcode))
223- .addReg (BSI.SplitCond ->getOperand (0 ).getReg ())
225+ .addReg (BSI.SplitCond ->getOperand (0 ).getReg (), 0 , BSI. SplitCondSubreg )
224226 .addMBB (NewBRTarget);
225227 BuildMI (*ThisMBB, ThisMBB->end (), BSI.SplitBefore ->getDebugLoc (),
226228 TII->get (PPC::B))
@@ -234,6 +236,7 @@ static bool splitMBB(BlockSplitInfo &BSI) {
234236 assert (FirstTerminator->getOperand (0 ).isReg () &&
235237 " Can't update condition of unconditional branch." );
236238 FirstTerminator->getOperand (0 ).setReg (BSI.NewCond ->getOperand (0 ).getReg ());
239+ FirstTerminator->getOperand (0 ).setSubReg (BSI.OrigSubreg );
237240 }
238241 if (BSI.InvertOrigBranch )
239242 FirstTerminator->setDesc (TII->get (InvertedOpcode));
@@ -471,6 +474,7 @@ PPCReduceCRLogicals::createCRLogicalOpInfo(MachineInstr &MIParam) {
471474 } else {
472475 MachineInstr *Def1 = lookThroughCRCopy (MIParam.getOperand (1 ).getReg (),
473476 Ret.SubregDef1 , Ret.CopyDefs .first );
477+ Ret.SubregDef1 = MIParam.getOperand (1 ).getSubReg ();
474478 assert (Def1 && " Must be able to find a definition of operand 1." );
475479 Ret.DefsSingleUse &=
476480 MRI->hasOneNonDBGUse (Def1->getOperand (0 ).getReg ());
@@ -481,6 +485,7 @@ PPCReduceCRLogicals::createCRLogicalOpInfo(MachineInstr &MIParam) {
481485 MachineInstr *Def2 = lookThroughCRCopy (MIParam.getOperand (2 ).getReg (),
482486 Ret.SubregDef2 ,
483487 Ret.CopyDefs .second );
488+ Ret.SubregDef2 = MIParam.getOperand (2 ).getSubReg ();
484489 assert (Def2 && " Must be able to find a definition of operand 2." );
485490 Ret.DefsSingleUse &=
486491 MRI->hasOneNonDBGUse (Def2->getOperand (0 ).getReg ());
@@ -535,26 +540,15 @@ PPCReduceCRLogicals::createCRLogicalOpInfo(MachineInstr &MIParam) {
535540MachineInstr *PPCReduceCRLogicals::lookThroughCRCopy (unsigned Reg,
536541 unsigned &Subreg,
537542 MachineInstr *&CpDef) {
538- Subreg = -1 ;
539543 if (!Register::isVirtualRegister (Reg))
540544 return nullptr ;
541545 MachineInstr *Copy = MRI->getVRegDef (Reg);
542546 CpDef = Copy;
543547 if (!Copy->isCopy ())
544548 return Copy;
545549 Register CopySrc = Copy->getOperand (1 ).getReg ();
546- Subreg = Copy->getOperand (1 ).getSubReg ();
547550 if (!CopySrc.isVirtual ()) {
548551 const TargetRegisterInfo *TRI = &TII->getRegisterInfo ();
549- // Set the Subreg
550- if (CopySrc == PPC::CR0EQ || CopySrc == PPC::CR6EQ)
551- Subreg = PPC::sub_eq;
552- if (CopySrc == PPC::CR0LT || CopySrc == PPC::CR6LT)
553- Subreg = PPC::sub_lt;
554- if (CopySrc == PPC::CR0GT || CopySrc == PPC::CR6GT)
555- Subreg = PPC::sub_gt;
556- if (CopySrc == PPC::CR0UN || CopySrc == PPC::CR6UN)
557- Subreg = PPC::sub_un;
558552 // Loop backwards and return the first MI that modifies the physical CR Reg.
559553 MachineBasicBlock::iterator Me = Copy, B = Copy->getParent ()->begin ();
560554 while (Me != B)
@@ -682,16 +676,21 @@ bool PPCReduceCRLogicals::splitBlockOnBinaryCROp(CRLogicalOpInfo &CRI) {
682676 computeBranchTargetAndInversion (Opc, Branch->getOpcode (), UsingDef1,
683677 InvertNewBranch, InvertOrigBranch,
684678 TargetIsFallThrough);
685- MachineInstr *SplitCond =
686- UsingDef1 ? CRI.CopyDefs .second : CRI.CopyDefs .first ;
679+ MachineInstr *NewCond = CRI.CopyDefs .first ;
680+ MachineInstr *SplitCond = CRI.CopyDefs .second ;
681+ if (!UsingDef1) {
682+ std::swap (NewCond, SplitCond);
683+ std::swap (CRI.SubregDef1 , CRI.SubregDef2 );
684+ }
687685 LLVM_DEBUG (dbgs () << " We will " << (InvertNewBranch ? " invert" : " copy" ));
688686 LLVM_DEBUG (dbgs () << " the original branch and the target is the "
689687 << (TargetIsFallThrough ? " fallthrough block\n "
690688 : " orig. target block\n " ));
691689 LLVM_DEBUG (dbgs () << " Original branch instruction: " ; Branch->dump ());
692- BlockSplitInfo BSI { Branch, SplitBefore, SplitCond, InvertNewBranch,
693- InvertOrigBranch, TargetIsFallThrough, MBPI, CRI.MI ,
694- UsingDef1 ? CRI.CopyDefs .first : CRI.CopyDefs .second };
690+ BlockSplitInfo BSI{
691+ Branch, SplitBefore, SplitCond, CRI.SubregDef1 ,
692+ CRI.SubregDef2 , InvertNewBranch, InvertOrigBranch, TargetIsFallThrough,
693+ MBPI, CRI.MI , NewCond};
695694 bool Changed = splitMBB (BSI);
696695 // If we've split on a CR logical that is fed by a CR logical,
697696 // recompute the source CR logical as it may be usable for splitting.
0 commit comments