Lines Matching defs:PBI
3944 /// Return true if either PBI or BI has branch weight available, and store
3945 /// the weights in {Pred|Succ}{True|False}Weight. If one of PBI and BI does
3947 static bool extractPredSuccWeights(BranchInst *PBI, BranchInst *BI,
3953 extractBranchWeights(*PBI, PredTrueWeight, PredFalseWeight);
3971 shouldFoldCondBranchesToCommonDestination(BranchInst *BI, BranchInst *PBI,
3973 assert(BI && PBI && BI->isConditional() && PBI->isConditional() &&
3975 assert(is_contained(predecessors(BI->getParent()), PBI->getParent()) &&
3982 if (TTI && !PBI->getMetadata(LLVMContext::MD_unpredictable) &&
3983 extractBranchWeights(*PBI, PTWeight, PFWeight) &&
3990 if (PBI->getSuccessor(0) == BI->getSuccessor(0)) {
3994 } else if (PBI->getSuccessor(1) == BI->getSuccessor(1)) {
3998 } else if (PBI->getSuccessor(0) == BI->getSuccessor(1)) {
4002 } else if (PBI->getSuccessor(1) == BI->getSuccessor(0)) {
4010 static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
4015 BasicBlock *PredBlock = PBI->getParent();
4022 *shouldFoldCondBranchesToCommonDestination(BI, PBI, TTI);
4024 LLVM_DEBUG(dbgs() << "FOLDING BRANCH TO COMMON DEST:\n" << *PBI << *BB);
4026 IRBuilder<> Builder(PBI);
4035 InvertBranch(PBI, Builder);
4039 PBI->getSuccessor(0) == BB ? BI->getSuccessor(0) : BI->getSuccessor(1);
4048 if (extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
4052 if (PBI->getSuccessor(0) == BB) {
4053 // PBI: br i1 %x, BB, FalseDest
4055 // TrueWeight is TrueWeight for PBI * TrueWeight for BI.
4057 // FalseWeight is FalseWeight for PBI * TotalWeight for BI +
4058 // TrueWeight for PBI * FalseWeight for BI.
4065 // PBI: br i1 %x, TrueDest, BB
4067 // TrueWeight is TrueWeight for PBI * TotalWeight for BI +
4068 // FalseWeight for PBI * TrueWeight for BI.
4071 // FalseWeight is FalseWeight for PBI * FalseWeight for BI.
4079 setBranchWeights(PBI, MDWeights[0], MDWeights[1], /*IsExpected=*/false);
4082 // could replace PBI's branch probabilities with BI's.
4084 PBI->setMetadata(LLVMContext::MD_prof, nullptr);
4087 PBI->setSuccessor(PBI->getSuccessor(0) != BB, UniqueSucc);
4094 // We need to copy it to the new latch, that is, PBI.
4096 PBI->setMetadata(LLVMContext::MD_loop, LoopMD);
4115 PBI->setCondition(
4116 createLogicalOp(Builder, Opc, PBI->getCondition(), BICond, "or.cond"));
4162 BranchInst *PBI = dyn_cast<BranchInst>(PredBlock->getTerminator());
4167 if (!PBI || PBI->isUnconditional() || !safeToMergeTerminators(BI, PBI))
4174 if (auto Recipe = shouldFoldCondBranchesToCommonDestination(BI, PBI, TTI))
4184 if (InvertPredCond && (!PBI->getCondition()->hasOneUse() ||
4185 !isa<CmpInst>(PBI->getCondition())))
4252 auto *PBI = cast<BranchInst>(PredBlock->getTerminator());
4253 return performBranchToCommonDestFolding(BI, PBI, DTU, MSSAU, TTI);
4475 static bool mergeConditionalStores(BranchInst *PBI, BranchInst *QBI,
4483 // PBI and QBI.
4492 // PBI or PBI or a combination of the two
4505 BasicBlock *PTB = PBI->getSuccessor(0);
4506 BasicBlock *PFB = PBI->getSuccessor(1);
4544 if (!HasOnePredAndOneSucc(PFB, PBI->getParent(), QBI->getParent()) ||
4547 if ((PTB && !HasOnePredAndOneSucc(PTB, PBI->getParent(), QBI->getParent())) ||
4586 /// "widening" PBI, but doesn't require us to reason about hosting safety.
4587 static bool tryWidenCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
4591 // values from the PBI edge.
4595 BasicBlock *IfTrueBB = PBI->getSuccessor(0);
4596 BasicBlock *IfFalseBB = PBI->getSuccessor(1);
4597 if (!isWidenableBranch(PBI) || IfTrueBB != BI->getParent() ||
4642 /// that PBI and BI are both conditional branches, and BI is in one of the
4643 /// successor blocks of PBI - PBI branches to BI.
4644 static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
4648 assert(PBI->isConditional() && BI->isConditional());
4654 if (PBI->getCondition() == BI->getCondition() &&
4655 PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
4661 bool CondIsTrue = PBI->getSuccessor(0) == BB;
4670 // "widening" PBI, but doesn't require us to reason about hosting safety.
4671 if (tryWidenCondBranchToCondBranch(PBI, BI, DTU))
4677 if (MergeCondStores && mergeConditionalStores(PBI, BI, DTU, DL, TTI))
4689 if (PBI->getSuccessor(0) == BI->getSuccessor(0)) {
4692 } else if (PBI->getSuccessor(0) == BI->getSuccessor(1)) {
4695 } else if (PBI->getSuccessor(1) == BI->getSuccessor(0)) {
4698 } else if (PBI->getSuccessor(1) == BI->getSuccessor(1)) {
4708 if (PBI->getSuccessor(PBIOp) == BB)
4713 if (!PBI->getMetadata(LLVMContext::MD_unpredictable) &&
4714 extractBranchWeights(*PBI, PredWeights) &&
4730 BasicBlock *CommonDest = PBI->getSuccessor(PBIOp);
4731 BasicBlock *RemovedDest = PBI->getSuccessor(PBIOp ^ 1);
4742 LLVM_DEBUG(dbgs() << "FOLDING BRs:" << *PBI->getParent()
4765 LLVM_DEBUG(dbgs() << *PBI->getParent()->getParent());
4768 // it alone, but modify PBI.
4771 Value *PBICond = PBI->getCondition();
4772 IRBuilder<NoFolder> Builder(PBI);
4784 // Modify PBI to branch on the new condition to the new dests.
4785 PBI->setCondition(Cond);
4786 PBI->setSuccessor(0, CommonDest);
4787 PBI->setSuccessor(1, OtherDest);
4790 Updates.push_back({DominatorTree::Insert, PBI->getParent(), OtherDest});
4791 Updates.push_back({DominatorTree::Delete, PBI->getParent(), RemovedDest});
4796 // Update branch weight for PBI.
4800 extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
4816 setBranchWeights(PBI, NewWeights[0], NewWeights[1], /*IsExpected=*/false);
4819 // OtherDest may have phi nodes. If so, add an entry from PBI's
4821 addPredecessorToBlock(OtherDest, PBI->getParent(), BB);
4823 // We know that the CommonDest already had an edge from PBI to
4825 // entries for BB and PBI's BB. If so, insert a select to make
4829 unsigned PBBIdx = PN.getBasicBlockIndex(PBI->getParent());
4832 // Insert a select in PBI to pick the right value.
4836 // Although the select has the same condition as PBI, the original branch
4837 // weights for PBI do not apply to the new select because the select's
4839 // the outgoing edges of PBI.
4858 LLVM_DEBUG(dbgs() << "INTO: " << *PBI->getParent());
4859 LLVM_DEBUG(dbgs() << *PBI->getParent()->getParent());
8146 if (BranchInst *PBI = dyn_cast<BranchInst>(Pred->getTerminator()))
8147 if (PBI != BI && PBI->isConditional())
8148 if (SimplifyCondBranchToCondBranch(PBI, BI, DTU, DL, TTI))
8154 if (BranchInst *PBI = dyn_cast<BranchInst>(PrevBB->getTerminator()))
8155 if (PBI != BI && PBI->isConditional())
8156 if (mergeConditionalStores(PBI, BI, DTU, DL, TTI))