Home | History | Annotate | Download | only in Utils

Lines Matching defs:PBI

2151     Instruction *PBI = &I;
2152 // Check whether Inst and PBI generate the same value.
2153 if (Inst->isIdenticalTo(PBI)) {
2154 Inst->replaceAllUsesWith(PBI);
2162 /// Return true if either PBI or BI has branch weight available, and store
2163 /// the weights in {Pred|Succ}{True|False}Weight. If one of PBI and BI does
2165 static bool extractPredSuccWeights(BranchInst *PBI, BranchInst *BI,
2171 PBI->extractProfMetadata(PredTrueWeight, PredFalseWeight);
2200 if (BranchInst *PBI = dyn_cast<BranchInst>(PB->getTerminator()))
2201 if (PBI->isConditional() &&
2202 (BI->getSuccessor(0) == PBI->getSuccessor(0) ||
2203 BI->getSuccessor(0) == PBI->getSuccessor(1))) {
2276 BranchInst *PBI = dyn_cast<BranchInst>(PredBlock->getTerminator());
2282 if (!PBI || PBI->isUnconditional() ||
2283 (BI->isConditional() && !SafeToMergeTerminators(BI, PBI)) ||
2285 !isProfitableToFoldUnconditional(BI, PBI, Cond, PHIs)))
2293 if (PBI->getSuccessor(0) == TrueDest) {
2295 } else if (PBI->getSuccessor(1) == FalseDest) {
2297 } else if (PBI->getSuccessor(0) == FalseDest) {
2300 } else if (PBI->getSuccessor(1) == TrueDest) {
2307 if (PBI->getSuccessor(0) != TrueDest && PBI->getSuccessor(1) != TrueDest)
2311 DEBUG(dbgs() << "FOLDING BRANCH TO COMMON DEST:\n" << *PBI << *BB);
2312 IRBuilder<> Builder(PBI);
2316 Value *NewCond = PBI->getCondition();
2323 Builder.CreateNot(NewCond, PBI->getCondition()->getName() + ".not");
2326 PBI->setCondition(NewCond);
2327 PBI->swapSuccessors();
2352 PredBlock->getInstList().insert(PBI->getIterator(), NewBonusInst);
2362 PredBlock->getInstList().insert(PBI->getIterator(), New);
2368 Builder.CreateBinOp(Opc, PBI->getCondition(), New, "or.cond"));
2369 PBI->setCondition(NewCond);
2373 extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
2377 if (PBI->getSuccessor(0) == BB) {
2379 // PBI: br i1 %x, BB, FalseDest
2381 // TrueWeight is TrueWeight for PBI * TrueWeight for BI.
2383 // FalseWeight is FalseWeight for PBI * TotalWeight for BI +
2384 // TrueWeight for PBI * FalseWeight for BI.
2392 PBI->setSuccessor(0, TrueDest);
2394 if (PBI->getSuccessor(1) == BB) {
2396 // PBI: br i1 %x, TrueDest, BB
2398 // TrueWeight is TrueWeight for PBI * TotalWeight for BI +
2399 // FalseWeight for PBI * TrueWeight for BI.
2403 // FalseWeight is FalseWeight for PBI * FalseWeight for BI.
2407 PBI->setSuccessor(1, FalseDest);
2415 PBI->setMetadata(
2419 PBI->setMetadata(LLVMContext::MD_prof, nullptr);
2424 PHIs[i]->getIncomingValueForBlock(PBI->getParent()));
2427 if (PBI->getSuccessor(0) == TrueDest) {
2432 Builder.CreateNot(PBI->getCondition(), "not.cond"));
2437 Instruction::Or, PBI->getCondition(), MergedCond, "or.cond"));
2443 Instruction::And, PBI->getCondition(), New, "and.cond"));
2446 Builder.CreateNot(PBI->getCondition(), "not.cond"));
2452 PHIs[i]->setIncomingValue(PHIs[i]->getBasicBlockIndex(PBI->getParent()),
2455 // Change PBI from Conditional to Unconditional.
2456 BranchInst *New_PBI = BranchInst::Create(TrueDest, PBI);
2457 EraseTerminatorInstAndDCECond(PBI);
2458 PBI = New_PBI;
2462 // could replace PBI's branch probabilities with BI's.
2467 I.clone()->insertBefore(PBI);
2658 static bool mergeConditionalStores(BranchInst *PBI, BranchInst *QBI) {
2664 // PBI and QBI.
2673 // PBI or PBI or a combination of the two
2687 BasicBlock *PTB = PBI->getSuccessor(0);
2688 BasicBlock *PFB = PBI->getSuccessor(1);
2718 !HasOnePredAndOneSucc(PFB, PBI->getParent(), QBI->getParent()) ||
2721 if ((PTB && !HasOnePredAndOneSucc(PTB, PBI->getParent(), QBI->getParent())) ||
2759 /// that PBI and BI are both conditional branches, and BI is in one of the
2760 /// successor blocks of PBI - PBI branches to BI.
2761 static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
2763 assert(PBI->isConditional() && BI->isConditional());
2769 if (PBI->getCondition() == BI->getCondition() &&
2770 PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
2775 bool CondIsTrue = PBI->getSuccessor(0) == BB;
2789 // Okay, we're going to insert the PHI node. Since PBI is not the only
2794 if ((PBI = dyn_cast<BranchInst>(P->getTerminator())) && PBI != BI &&
2795 PBI->isConditional() && PBI->getCondition() == BI->getCondition() &&
2796 PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
2797 bool CondIsTrue = PBI->getSuccessor(0) == BB;
2818 if (MergeCondStores && mergeConditionalStores(PBI, BI))
2832 if (PBI->getSuccessor(0) == BI->getSuccessor(0)) {
2835 } else if (PBI->getSuccessor(0) == BI->getSuccessor(1)) {
2838 } else if (PBI->getSuccessor(1) == BI->getSuccessor(0)) {
2841 } else if (PBI->getSuccessor(1) == BI->getSuccessor(1)) {
2851 if (PBI->getSuccessor(PBIOp) == BB)
2862 BasicBlock *CommonDest = PBI->getSuccessor(PBIOp);
2875 unsigned PBBIdx = PN->getBasicBlockIndex(PBI->getParent());
2885 DEBUG(dbgs() << "FOLDING BRs:" << *PBI->getParent()
2904 DEBUG(dbgs() << *PBI->getParent()->getParent());
2907 // it alone, but modify PBI.
2910 Value *PBICond = PBI->getCondition();
2911 IRBuilder<NoFolder> Builder(PBI);
2922 // Modify PBI to branch on the new condition to the new dests.
2923 PBI->setCondition(Cond);
2924 PBI->setSuccessor(0, CommonDest);
2925 PBI->setSuccessor(1, OtherDest);
2927 // Update branch weight for PBI.
2931 extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
2947 PBI->setMetadata(LLVMContext::MD_prof,
2952 // OtherDest may have phi nodes. If so, add an entry from PBI's
2954 AddPredecessorToBlock(OtherDest, PBI->getParent(), BB);
2956 // We know that the CommonDest already had an edge from PBI to
2958 // entries for BB and PBI's BB. If so, insert a select to make
2964 unsigned PBBIdx = PN->getBasicBlockIndex(PBI->getParent());
2967 // Insert a select in PBI to pick the right value.
2971 // Although the select has the same condition as PBI, the original branch
2972 // weights for PBI do not apply to the new select because the select's
2974 // the outgoing edges of PBI.
2994 DEBUG(dbgs() << "INTO: " << *PBI->getParent());
2995 DEBUG(dbgs() << *PBI->getParent()->getParent());
5301 auto *PBI = dyn_cast_or_null<BranchInst>(Dom->getTerminator());
5302 if (PBI && PBI->isConditional() &&
5303 PBI->getSuccessor(0) != PBI->getSuccessor(1) &&
5304 (PBI->getSuccessor(0) == BB || PBI->getSuccessor(1) == BB)) {
5305 bool CondIsFalse = PBI->getSuccessor(1) == BB;
5307 PBI->getCondition(), BI->getCondition(), DL, CondIsFalse);
5363 if (BranchInst *PBI = dyn_cast<BranchInst>((*PI)->getTerminator()))
5364 if (PBI != BI && PBI->isConditional())
5365 if (SimplifyCondBranchToCondBranch(PBI, BI, DL))
5371 if (BranchInst *PBI = dyn_cast<BranchInst>(PrevBB->getTerminator()))
5372 if (PBI != BI && PBI->isConditional())
5373 if (mergeConditionalStores(PBI, BI))