Home | History | Annotate | Download | only in Utils

Lines Matching defs:BI

147   bool SimplifyUncondBranch(BranchInst *BI, IRBuilder <> &Builder);
148 bool SimplifyCondBranch(BranchInst *BI, IRBuilder <>&Builder);
287 BranchInst *BI = dyn_cast<BranchInst>(PBB->getTerminator());
288 if (!BI || BI->isConditional() || BI->getSuccessor(0) != BB)
536 } else if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
537 if (BI->isConditional())
538 Cond = dyn_cast<Instruction>(BI->getCondition());
557 } else if (BranchInst *BI = dyn_cast<BranchInst>(TI))
558 if (BI->isConditional() && BI->getCondition()->hasOneUse())
559 if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) {
589 BranchInst *BI = cast<BranchInst>(TI);
590 ICmpInst *ICI = cast<ICmpInst>(BI->getCondition());
591 BasicBlock *Succ = BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_NE);
595 return BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_EQ);
825 if (BranchInst* BI = dyn_cast<BranchInst>(TI)) {
827 ICmpInst *ICI = cast<ICmpInst>(BI->getCondition());
1076 /// guarantees that BI's block dominates BB1 and BB2.
1077 static bool HoistThenElseCodeToIf(BranchInst *BI,
1084 BasicBlock *BB1 = BI->getSuccessor(0); // The true destination.
1085 BasicBlock *BB2 = BI->getSuccessor(1); // The false destination
1104 BasicBlock *BIParent = BI->getParent();
1109 // broken BB), instead clone it, and remove BI.
1119 BIParent->getInstList().splice(BI->getIterator(), BB1->getInstList(), I1);
1177 BIParent->getInstList().insert(BI->getIterator(), NT);
1203 (Builder.CreateSelect(BI->getCondition(), BB1V, BB2V,
1217 EraseTerminatorInstAndDCECond(BI);
1490 static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB,
1493 Value *BrCond = BI->getCondition();
1497 BasicBlock *BB = BI->getParent();
1503 if (ThenBB != BI->getSuccessor(0)) {
1504 assert(ThenBB == BI->getSuccessor(1) && "No edge from 'if' block?");
1507 assert(EndBB == BI->getSuccessor(!Invert) && "No edge from to end block");
1625 IRBuilder<true, NoFolder> Builder(BI);
1641 BB->getInstList().splice(BI->getIterator(), ThenBB->getInstList(),
1645 BI);
1688 BranchInst *BI = cast<BranchInst>(BB->getTerminator());
1691 for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) {
1713 static bool FoldCondBranchOnPHI(BranchInst *BI, const DataLayout &DL) {
1714 BasicBlock *BB = BI->getParent();
1715 PHINode *PN = dyn_cast<PHINode>(BI->getCondition());
1741 BasicBlock *RealDest = BI->getSuccessor(!CB->getZExtValue());
1764 for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) {
1803 return FoldCondBranchOnPHI(BI, DL) | true;
1951 static bool SimplifyCondBranchToTwoReturns(BranchInst *BI,
1953 assert(BI->isConditional() && "Must be a conditional branch");
1954 BasicBlock *TrueSucc = BI->getSuccessor(0);
1955 BasicBlock *FalseSucc = BI->getSuccessor(1);
1967 Builder.SetInsertPoint(BI);
1972 TrueSucc->removePredecessor(BI->getParent());
1973 FalseSucc->removePredecessor(BI->getParent());
1975 EraseTerminatorInstAndDCECond(BI);
1987 TrueValue = TVPN->getIncomingValueForBlock(BI->getParent());
1990 FalseValue = FVPN->getIncomingValueForBlock(BI->getParent());
2006 TrueSucc->removePredecessor(BI->getParent());
2007 FalseSucc->removePredecessor(BI->getParent());
2010 Value *BrCond = BI->getCondition();
2028 << "\n " << *BI << "NewRet = " << *RI
2031 EraseTerminatorInstAndDCECond(BI);
2039 static bool ExtractBranchMetadata(BranchInst *BI,
2041 assert(BI->isConditional() &&
2043 MDNode *ProfileData = BI->getMetadata(LLVMContext::MD_prof);
2075 bool llvm::FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold) {
2076 BasicBlock *BB = BI->getParent();
2079 if (BI->isConditional())
2080 Cond = dyn_cast<Instruction>(BI->getCondition());
2089 (BI->getSuccessor(0) == PBI->getSuccessor(0) ||
2090 BI->getSuccessor(0) == PBI->getSuccessor(1))) {
2118 if (&*CondIt != BI)
2137 // I is used in the same BB. Since BI uses Cond and doesn't have more slots
2156 BasicBlock *TrueDest = BI->getSuccessor(0);
2157 BasicBlock *FalseDest = (BI->isConditional()) ? BI->getSuccessor(1) : nullptr;
2170 (BI->isConditional() &&
2171 !SafeToMergeTerminators(BI, PBI)) ||
2172 (!BI->isConditional() &&
2173 !isProfitableToFoldUnconditional(BI, PBI, Cond, PHIs)))
2180 if (BI->isConditional()) {
2219 // We already make sure Cond is the last instruction before BI. Therefore,
2251 if (BI->isConditional()) {
2260 bool SuccHasWeights = ExtractBranchMetadata(BI, SuccTrueWeight,
2267 // BI: br i1 %y, TrueDest, 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.
2283 // BI: br i1 %y, TrueDest, FalseDest
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.
2300 MDBuilder(BI->getContext()).
2356 // could replace PBI's branch probabilities with BI's.
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());
2660 BasicBlock *BB = BI->getParent();
2665 if (PBI->getCondition() == BI->getCondition() &&
2672 BI->setCondition(ConstantInt::get(Type::getInt1Ty(BB->getContext()),
2684 BI->getCondition()->getName() + ".pr", &BB->front());
2691 PBI != BI && PBI->isConditional() &&
2692 PBI->getCondition() == BI->getCondition() &&
2698 NewPN->addIncoming(BI->getCondition(), P);
2702 BI->setCondition(NewPN);
2707 if (auto *CE = dyn_cast<ConstantExpr>(BI->getCondition()))
2711 // If BI is reached from the true path of PBI and PBI's condition implies
2712 // BI's condition, we know the direction of the BI branch.
2713 if (PBI->getSuccessor(0) == BI->getParent() &&
2714 isImpliedCondition(PBI->getCondition(), BI->getCondition(), DL) &&
2718 auto *OldCond = BI->getCondition();
2719 BI->setCondition(ConstantInt::getTrue(BB->getContext()));
2727 if (MergeCondStores && mergeConditionalStores(PBI, BI))
2737 if (&*BBI != 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))
2787 BasicBlock *OtherDest = BI->getSuccessor(BIOp ^ 1);
2790 << "AND: " << *BI->getParent());
2811 // BI may have other predecessors. Because of this, we leave
2820 Value *BICond = BI->getCondition();
2836 bool SuccHasWeights = ExtractBranchMetadata(BI, SuccTrueWeight,
2853 MDBuilder(BI->getContext())
2858 // block that are identical to the entries for BI's block.
3134 static bool SimplifyBranchOnICmpChain(BranchInst *BI, IRBuilder<> &Builder,
3136 Instruction *Cond = dyn_cast<Instruction>(BI->getCondition());
3173 BasicBlock *DefaultBB = BI->getSuccessor(1);
3174 BasicBlock *EdgeBB = BI->getSuccessor(0);
3177 BasicBlock *BB = BI->getParent();
3187 BB->splitBasicBlock(BI->getIterator(), "switch.early.test");
3208 Builder.SetInsertPoint(BI);
3234 EraseTerminatorInstAndDCECond(BI);
3395 if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) {
3396 if (BI->isUnconditional())
3399 CondBranchPreds.push_back(BI);
3424 BranchInst *BI = CondBranchPreds.pop_back_val();
3427 if (isa<ReturnInst>(BI->getSuccessor(0)->getTerminator()) &&
3428 isa<ReturnInst>(BI->getSuccessor(1)->getTerminator()) &&
3429 SimplifyCondBranchToTwoReturns(BI, Builder))
3488 if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
3489 if (BI->isUnconditional()) {
3490 if (BI->getSuccessor(0) == BB) {
3496 if (BI->getSuccessor(0) == BB) {
3497 Builder.CreateBr(BI->getSuccessor(1));
3498 EraseTerminatorInstAndDCECond(BI);
3499 } else if (BI->getSuccessor(1) == BB) {
3500 Builder.CreateBr(BI->getSuccessor(0));
3501 EraseTerminatorInstAndDCECond(BI);
4814 static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
4832 if (!BI2 || !BI2->isIdenticalTo(BI))
4861 IRBuilder<> Builder(BI);
4863 BI->eraseFromParent();
4869 bool SimplifyCFGOpt::SimplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder){
4870 BasicBlock *BB = BI->getParent();
4872 if (SinkCommon && SinkThenElseCodeToEnd(BI))
4898 TryToMergeLandingPad(LPad, BI, BB))
4906 if (FoldBranchToCommonDest(BI, BonusInstThreshold))
4922 bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
4923 BasicBlock *BB = BI->getParent();
4926 if (isValueEqualityComparison(BI)) {
4931 if (SimplifyEqualityComparisonWithOnlyPredecessor(BI, OnlyPred, Builder))
4940 if (&*I == BI) {
4941 if (FoldValueComparisonIntoPredecessors(BI, Builder))
4943 } else if (&*I == cast<Instruction>(BI->getCondition())){
4948 if (&*I == BI && FoldValueComparisonIntoPredecessors(BI, Builder))
4954 if (SimplifyBranchOnICmpChain(BI, Builder, DL))
4960 if (FoldBranchToCommonDest(BI, BonusInstThreshold))
4964 // from BI
4967 if (BI->getSuccessor(0)->getSinglePredecessor()) {
4968 if (BI->getSuccessor(1)->getSinglePredecessor()) {
4969 if (HoistThenElseCodeToIf(BI, TTI))
4974 TerminatorInst *Succ0TI = BI->getSuccessor(0)->getTerminator();
4976 Succ0TI->getSuccessor(0) == BI->getSuccessor(1))
4977 if (SpeculativelyExecuteBB(BI, BI->getSuccessor(0), TTI))
4980 } else if (BI->getSuccessor(1)->getSinglePredecessor()) {
4983 TerminatorInst *Succ1TI = BI->getSuccessor(1)->getTerminator();
4985 Succ1TI->getSuccessor(0) == BI->getSuccessor(0))
4986 if (SpeculativelyExecuteBB(BI, BI->getSuccessor(1), TTI))
4992 if (PHINode *PN = dyn_cast<PHINode>(BI->getCondition()))
4993 if (PN->getParent() == BI->getParent())
4994 if (FoldCondBranchOnPHI(BI, DL))
5000 if (PBI != BI && PBI->isConditional())
5001 if (SimplifyCondBranchToCondBranch(PBI, BI, DL))
5008 if (PBI != BI && PBI->isConditional())
5009 if (mergeConditionalStores(PBI, BI))
5065 if (BranchInst *BI = dyn_cast<BranchInst>(T)) {
5069 if (BI->isUnconditional())
5072 Builder.CreateBr(BI->getSuccessor(0) == BB ? BI->getSuccessor(1) :
5073 BI->getSuccessor(0));
5074 BI->eraseFromParent();
5125 if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) {
5126 if (BI->isUnconditional()) {
5127 if (SimplifyUncondBranch(BI, Builder)) return true;
5129 if (SimplifyCondBranch(BI, Builder)) return true;