Lines Matching defs:PBI

2061     Instruction *PBI = &*I;
2062 // Check whether Inst and PBI generate the same value.
2063 if (Inst->isIdenticalTo(PBI)) {
2064 Inst->replaceAllUsesWith(PBI);
2087 if (BranchInst *PBI = dyn_cast<BranchInst>(PB->getTerminator()))
2088 if (PBI->isConditional() &&
2089 (BI->getSuccessor(0) == PBI->getSuccessor(0) ||
2090 BI->getSuccessor(0) == PBI->getSuccessor(1))) {
2163 BranchInst *PBI = dyn_cast<BranchInst>(PredBlock->getTerminator());
2169 if (!PBI || PBI->isUnconditional() ||
2171 !SafeToMergeTerminators(BI, PBI)) ||
2173 !isProfitableToFoldUnconditional(BI, PBI, Cond, PHIs)))
2181 if (PBI->getSuccessor(0) == TrueDest)
2183 else if (PBI->getSuccessor(1) == FalseDest)
2185 else if (PBI->getSuccessor(0) == FalseDest)
2187 else if (PBI->getSuccessor(1) == TrueDest)
2192 if (PBI->getSuccessor(0) != TrueDest && PBI->getSuccessor(1) != TrueDest)
2196 DEBUG(dbgs() << "FOLDING BRANCH TO COMMON DEST:\n" << *PBI << *BB);
2197 IRBuilder<> Builder(PBI);
2201 Value *NewCond = PBI->getCondition();
2208 PBI->getCondition()->getName()+".not");
2211 PBI->setCondition(NewCond);
2212 PBI->swapSuccessors();
2237 PredBlock->getInstList().insert(PBI->getIterator(), NewBonusInst);
2247 PredBlock->getInstList().insert(PBI->getIterator(), New);
2253 cast<Instruction>(Builder.CreateBinOp(Opc, PBI->getCondition(),
2255 PBI->setCondition(NewCond);
2258 bool PredHasWeights = ExtractBranchMetadata(PBI, PredTrueWeight,
2264 if (PBI->getSuccessor(0) == BB) {
2266 // PBI: br i1 %x, BB, FalseDest
2268 //TrueWeight is TrueWeight for PBI * TrueWeight for BI.
2270 //FalseWeight is FalseWeight for PBI * TotalWeight for BI +
2271 // TrueWeight for PBI * FalseWeight for BI.
2278 PBI->setSuccessor(0, TrueDest);
2280 if (PBI->getSuccessor(1) == BB) {
2282 // PBI: br i1 %x, TrueDest, BB
2284 //TrueWeight is TrueWeight for PBI * TotalWeight for BI +
2285 // FalseWeight for PBI * TrueWeight for BI.
2288 //FalseWeight is FalseWeight for PBI * FalseWeight for BI.
2292 PBI->setSuccessor(1, FalseDest);
2299 PBI->setMetadata(LLVMContext::MD_prof,
2303 PBI->setMetadata(LLVMContext::MD_prof, nullptr);
2308 PHIs[i]->getIncomingValueForBlock(PBI->getParent()));
2311 if (PBI->getSuccessor(0) == TrueDest) {
2316 cast<Instruction>(Builder.CreateNot(PBI->getCondition(),
2325 PBI->getCondition(), MergedCond,
2333 PBI->getCondition(), New,
2337 cast<Instruction>(Builder.CreateNot(PBI->getCondition(),
2346 PHIs[i]->setIncomingValue(PHIs[i]->getBasicBlockIndex(PBI->getParent()),
2349 // Change PBI from Conditional to Unconditional.
2350 BranchInst *New_PBI = BranchInst::Create(TrueDest, PBI);
2351 EraseTerminatorInstAndDCECond(PBI);
2352 PBI = New_PBI;
2356 // could replace PBI's branch probabilities with BI's.
2361 I->clone()->insertBefore(PBI);
2553 static bool mergeConditionalStores(BranchInst *PBI, BranchInst *QBI) {
2559 // PBI and QBI.
2568 // PBI or PBI or a combination of the two
2582 BasicBlock *PTB = PBI->getSuccessor(0);
2583 BasicBlock *PFB = PBI->getSuccessor(1);
2614 !HasOnePredAndOneSucc(PFB, PBI->getParent(), QBI->getParent()) ||
2617 if ((PTB && !HasOnePredAndOneSucc(PTB, PBI->getParent(), QBI->getParent())) ||
2655 /// that PBI and BI are both conditional branches, and BI is in one of the
2656 /// successor blocks of PBI - PBI branches to BI.
2657 static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
2659 assert(PBI->isConditional() && BI->isConditional());
2665 if (PBI->getCondition() == BI->getCondition() &&
2666 PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
2671 bool CondIsTrue = PBI->getSuccessor(0) == BB;
2685 // Okay, we're going to insert the PHI node. Since PBI is not the only
2690 if ((PBI = dyn_cast<BranchInst>(P->getTerminator())) &&
2691 PBI != BI && PBI->isConditional() &&
2692 PBI->getCondition() == BI->getCondition() &&
2693 PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
2694 bool CondIsTrue = PBI->getSuccessor(0) == BB;
2711 // If BI is reached from the true path of PBI and PBI's condition implies
2713 if (PBI->getSuccessor(0) == BI->getParent() &&
2714 isImpliedCondition(PBI->getCondition(), BI->getCondition(), DL) &&
2715 PBI->getSuccessor(0) != PBI->getSuccessor(1) &&
2727 if (MergeCondStores && mergeConditionalStores(PBI, BI))
2741 if (PBI->getSuccessor(0) == BI->getSuccessor(0))
2743 else if (PBI->getSuccessor(0) == BI->getSuccessor(1))
2745 else if (PBI->getSuccessor(1) == BI->getSuccessor(0))
2747 else if (PBI->getSuccessor(1) == BI->getSuccessor(1))
2755 if (PBI->getSuccessor(PBIOp) == BB)
2766 BasicBlock *CommonDest = PBI->getSuccessor(PBIOp);
2779 unsigned PBBIdx = PN->getBasicBlockIndex(PBI->getParent());
2789 DEBUG(dbgs() << "FOLDING BRs:" << *PBI->getParent()
2809 DEBUG(dbgs() << *PBI->getParent()->getParent());
2812 // it alone, but modify PBI.
2815 Value *PBICond = PBI->getCondition();
2816 IRBuilder<true, NoFolder> Builder(PBI);
2827 // Modify PBI to branch on the new condition to the new dests.
2828 PBI->setCondition(Cond);
2829 PBI->setSuccessor(0, CommonDest);
2830 PBI->setSuccessor(1, OtherDest);
2832 // Update branch weight for PBI.
2834 bool PredHasWeights = ExtractBranchMetadata(PBI, PredTrueWeight,
2852 PBI->setMetadata(LLVMContext::MD_prof,
2857 // OtherDest may have phi nodes. If so, add an entry from PBI's
2859 AddPredecessorToBlock(OtherDest, PBI->getParent(), BB);
2861 // We know that the CommonDest already had an edge from PBI to
2863 // entries for BB and PBI's BB. If so, insert a select to make
2869 unsigned PBBIdx = PN->getBasicBlockIndex(PBI->getParent());
2872 // Insert a select in PBI to pick the right value.
2879 DEBUG(dbgs() << "INTO: " << *PBI->getParent());
2880 DEBUG(dbgs() << *PBI->getParent()->getParent());
4999 if (BranchInst *PBI = dyn_cast<BranchInst>((*PI)->getTerminator()))
5000 if (PBI != BI && PBI->isConditional())
5001 if (SimplifyCondBranchToCondBranch(PBI, BI, DL))
5007 if (BranchInst *PBI = dyn_cast<BranchInst>(PrevBB->getTerminator()))
5008 if (PBI != BI && PBI->isConditional())
5009 if (mergeConditionalStores(PBI, BI))