Lines Matching defs:PBI
3689 /// Return true if either PBI or BI has branch weight available, and store
3690 /// the weights in {Pred|Succ}{True|False}Weight. If one of PBI and BI does
3692 static bool extractPredSuccWeights(BranchInst *PBI, BranchInst *BI,
3698 extractBranchWeights(*PBI, PredTrueWeight, PredFalseWeight);
3716 shouldFoldCondBranchesToCommonDestination(BranchInst *BI, BranchInst *PBI,
3718 assert(BI && PBI && BI->isConditional() && PBI->isConditional() &&
3720 assert(is_contained(predecessors(BI->getParent()), PBI->getParent()) &&
3727 if (TTI && !PBI->getMetadata(LLVMContext::MD_unpredictable) &&
3728 extractBranchWeights(*PBI, PTWeight, PFWeight) &&
3735 if (PBI->getSuccessor(0) == BI->getSuccessor(0)) {
3739 } else if (PBI->getSuccessor(1) == BI->getSuccessor(1)) {
3743 } else if (PBI->getSuccessor(0) == BI->getSuccessor(1)) {
3747 } else if (PBI->getSuccessor(1) == BI->getSuccessor(0)) {
3755 static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
3760 BasicBlock *PredBlock = PBI->getParent();
3767 *shouldFoldCondBranchesToCommonDestination(BI, PBI, TTI);
3769 LLVM_DEBUG(dbgs() << "FOLDING BRANCH TO COMMON DEST:\n" << *PBI << *BB);
3771 IRBuilder<> Builder(PBI);
3780 InvertBranch(PBI, Builder);
3784 PBI->getSuccessor(0) == BB ? BI->getSuccessor(0) : BI->getSuccessor(1);
3793 if (extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
3797 if (PBI->getSuccessor(0) == BB) {
3798 // PBI: br i1 %x, BB, FalseDest
3800 // TrueWeight is TrueWeight for PBI * TrueWeight for BI.
3802 // FalseWeight is FalseWeight for PBI * TotalWeight for BI +
3803 // TrueWeight for PBI * FalseWeight for BI.
3810 // PBI: br i1 %x, TrueDest, BB
3812 // TrueWeight is TrueWeight for PBI * TotalWeight for BI +
3813 // FalseWeight for PBI * TrueWeight for BI.
3816 // FalseWeight is FalseWeight for PBI * FalseWeight for BI.
3824 setBranchWeights(PBI, MDWeights[0], MDWeights[1], /*IsExpected=*/false);
3827 // could replace PBI's branch probabilities with BI's.
3829 PBI->setMetadata(LLVMContext::MD_prof, nullptr);
3832 PBI->setSuccessor(PBI->getSuccessor(0) != BB, UniqueSucc);
3839 // We need to copy it to the new latch, that is, PBI.
3841 PBI->setMetadata(LLVMContext::MD_loop, LoopMD);
3860 PBI->setCondition(
3861 createLogicalOp(Builder, Opc, PBI->getCondition(), BICond, "or.cond"));
3907 BranchInst *PBI = dyn_cast<BranchInst>(PredBlock->getTerminator());
3912 if (!PBI || PBI->isUnconditional() || !SafeToMergeTerminators(BI, PBI))
3919 if (auto Recipe = shouldFoldCondBranchesToCommonDestination(BI, PBI, TTI))
3929 if (InvertPredCond && (!PBI->getCondition()->hasOneUse() ||
3930 !isa<CmpInst>(PBI->getCondition())))
3997 auto *PBI = cast<BranchInst>(PredBlock->getTerminator());
3998 return performBranchToCommonDestFolding(BI, PBI, DTU, MSSAU, TTI);
4220 static bool mergeConditionalStores(BranchInst *PBI, BranchInst *QBI,
4228 // PBI and QBI.
4237 // PBI or PBI or a combination of the two
4250 BasicBlock *PTB = PBI->getSuccessor(0);
4251 BasicBlock *PFB = PBI->getSuccessor(1);
4289 if (!HasOnePredAndOneSucc(PFB, PBI->getParent(), QBI->getParent()) ||
4292 if ((PTB && !HasOnePredAndOneSucc(PTB, PBI->getParent(), QBI->getParent())) ||
4331 /// "widening" PBI, but doesn't require us to reason about hosting safety.
4332 static bool tryWidenCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
4336 // values from the PBI edge.
4340 BasicBlock *IfTrueBB = PBI->getSuccessor(0);
4341 BasicBlock *IfFalseBB = PBI->getSuccessor(1);
4342 if (!isWidenableBranch(PBI) || IfTrueBB != BI->getParent() ||
4387 /// that PBI and BI are both conditional branches, and BI is in one of the
4388 /// successor blocks of PBI - PBI branches to BI.
4389 static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
4393 assert(PBI->isConditional() && BI->isConditional());
4399 if (PBI->getCondition() == BI->getCondition() &&
4400 PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
4406 bool CondIsTrue = PBI->getSuccessor(0) == BB;
4415 // "widening" PBI, but doesn't require us to reason about hosting safety.
4416 if (tryWidenCondBranchToCondBranch(PBI, BI, DTU))
4422 if (MergeCondStores && mergeConditionalStores(PBI, BI, DTU, DL, TTI))
4434 if (PBI->getSuccessor(0) == BI->getSuccessor(0)) {
4437 } else if (PBI->getSuccessor(0) == BI->getSuccessor(1)) {
4440 } else if (PBI->getSuccessor(1) == BI->getSuccessor(0)) {
4443 } else if (PBI->getSuccessor(1) == BI->getSuccessor(1)) {
4453 if (PBI->getSuccessor(PBIOp) == BB)
4458 if (!PBI->getMetadata(LLVMContext::MD_unpredictable) &&
4459 extractBranchWeights(*PBI, PredWeights) &&
4475 BasicBlock *CommonDest = PBI->getSuccessor(PBIOp);
4476 BasicBlock *RemovedDest = PBI->getSuccessor(PBIOp ^ 1);
4487 LLVM_DEBUG(dbgs() << "FOLDING BRs:" << *PBI->getParent()
4510 LLVM_DEBUG(dbgs() << *PBI->getParent()->getParent());
4513 // it alone, but modify PBI.
4516 Value *PBICond = PBI->getCondition();
4517 IRBuilder<NoFolder> Builder(PBI);
4529 // Modify PBI to branch on the new condition to the new dests.
4530 PBI->setCondition(Cond);
4531 PBI->setSuccessor(0, CommonDest);
4532 PBI->setSuccessor(1, OtherDest);
4535 Updates.push_back({DominatorTree::Insert, PBI->getParent(), OtherDest});
4536 Updates.push_back({DominatorTree::Delete, PBI->getParent(), RemovedDest});
4541 // Update branch weight for PBI.
4545 extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
4561 setBranchWeights(PBI, NewWeights[0], NewWeights[1], /*IsExpected=*/false);
4564 // OtherDest may have phi nodes. If so, add an entry from PBI's
4566 AddPredecessorToBlock(OtherDest, PBI->getParent(), BB);
4568 // We know that the CommonDest already had an edge from PBI to
4570 // entries for BB and PBI's BB. If so, insert a select to make
4574 unsigned PBBIdx = PN.getBasicBlockIndex(PBI->getParent());
4577 // Insert a select in PBI to pick the right value.
4581 // Although the select has the same condition as PBI, the original branch
4582 // weights for PBI do not apply to the new select because the select's
4584 // the outgoing edges of PBI.
4603 LLVM_DEBUG(dbgs() << "INTO: " << *PBI->getParent());
4604 LLVM_DEBUG(dbgs() << *PBI->getParent()->getParent());
7551 if (BranchInst *PBI = dyn_cast<BranchInst>(Pred->getTerminator()))
7552 if (PBI != BI && PBI->isConditional())
7553 if (SimplifyCondBranchToCondBranch(PBI, BI, DTU, DL, TTI))
7559 if (BranchInst *PBI = dyn_cast<BranchInst>(PrevBB->getTerminator()))
7560 if (PBI != BI && PBI->isConditional())
7561 if (mergeConditionalStores(PBI, BI, DTU, DL, TTI))