X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FEarlyIfConversion.cpp;h=f3536d74111e5dac8d2261a322060232028b571f;hb=f463d691458692a8652d446e41762ab317b5fc19;hp=9950951376188ae453454d35d9bd65c5f1846a2e;hpb=e67bd6c248e21e9b55a7d86b8ccfaef1ed70bf8a;p=oota-llvm.git diff --git a/lib/CodeGen/EarlyIfConversion.cpp b/lib/CodeGen/EarlyIfConversion.cpp index 99509513761..f3536d74111 100644 --- a/lib/CodeGen/EarlyIfConversion.cpp +++ b/lib/CodeGen/EarlyIfConversion.cpp @@ -226,7 +226,7 @@ bool SSAIfConv::canSpeculateInstrs(MachineBasicBlock *MBB) { } // Check for any dependencies on Head instructions. - for (const MachineOperand MO : I->operands()) { + for (const MachineOperand &MO : I->operands()) { if (MO.isRegMask()) { DEBUG(dbgs() << "Won't speculate regmask: " << *I); return false; @@ -479,11 +479,20 @@ void SSAIfConv::rewritePHIOperands() { // Convert all PHIs to select instructions inserted before FirstTerm. for (unsigned i = 0, e = PHIs.size(); i != e; ++i) { PHIInfo &PI = PHIs[i]; + unsigned DstReg = 0; + DEBUG(dbgs() << "If-converting " << *PI.PHI); - unsigned PHIDst = PI.PHI->getOperand(0).getReg(); - unsigned DstReg = MRI->createVirtualRegister(MRI->getRegClass(PHIDst)); - TII->insertSelect(*Head, FirstTerm, HeadDL, DstReg, Cond, PI.TReg, PI.FReg); - DEBUG(dbgs() << " --> " << *std::prev(FirstTerm)); + if (PI.TReg == PI.FReg) { + // We do not need the select instruction if both incoming values are + // equal. + DstReg = PI.TReg; + } else { + unsigned PHIDst = PI.PHI->getOperand(0).getReg(); + DstReg = MRI->createVirtualRegister(MRI->getRegClass(PHIDst)); + TII->insertSelect(*Head, FirstTerm, HeadDL, + DstReg, Cond, PI.TReg, PI.FReg); + DEBUG(dbgs() << " --> " << *std::prev(FirstTerm)); + } // Rewrite PHI operands TPred -> (DstReg, Head), remove FPred. for (unsigned i = PI.PHI->getNumOperands(); i != 1; i -= 2) { @@ -529,11 +538,11 @@ void SSAIfConv::convertIf(SmallVectorImpl &RemovedBlocks) { // Fix up the CFG, temporarily leave Head without any successors. Head->removeSuccessor(TBB); - Head->removeSuccessor(FBB); + Head->removeSuccessor(FBB, true); if (TBB != Tail) - TBB->removeSuccessor(Tail); + TBB->removeSuccessor(Tail, true); if (FBB != Tail) - FBB->removeSuccessor(Tail); + FBB->removeSuccessor(Tail, true); // Fix up Head's terminators. // It should become a single branch or a fallthrough.