Lines Matching refs:BI
162 bool SimplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder);
163 bool SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder);
313 BranchInst *BI = dyn_cast<BranchInst>(PBB->getTerminator()); in DominatesMergePoint() local
314 if (!BI || BI->isConditional() || BI->getSuccessor(0) != BB) in DominatesMergePoint()
630 } else if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { in EraseTerminatorInstAndDCECond() local
631 if (BI->isConditional()) in EraseTerminatorInstAndDCECond()
632 Cond = dyn_cast<Instruction>(BI->getCondition()); in EraseTerminatorInstAndDCECond()
653 } else if (BranchInst *BI = dyn_cast<BranchInst>(TI)) in isValueEqualityComparison() local
654 if (BI->isConditional() && BI->getCondition()->hasOneUse()) in isValueEqualityComparison()
655 if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) { in isValueEqualityComparison()
684 BranchInst *BI = cast<BranchInst>(TI); in GetValueEqualityComparisonCases() local
685 ICmpInst *ICI = cast<ICmpInst>(BI->getCondition()); in GetValueEqualityComparisonCases()
686 BasicBlock *Succ = BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_NE); in GetValueEqualityComparisonCases()
689 return BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_EQ); in GetValueEqualityComparisonCases()
920 if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { in GetBranchWeights() local
922 ICmpInst *ICI = cast<ICmpInst>(BI->getCondition()); in GetBranchWeights()
1173 static bool HoistThenElseCodeToIf(BranchInst *BI, in HoistThenElseCodeToIf() argument
1180 BasicBlock *BB1 = BI->getSuccessor(0); // The true destination. in HoistThenElseCodeToIf()
1181 BasicBlock *BB2 = BI->getSuccessor(1); // The false destination in HoistThenElseCodeToIf()
1200 BasicBlock *BIParent = BI->getParent(); in HoistThenElseCodeToIf()
1215 BIParent->getInstList().splice(BI->getIterator(), BB1->getInstList(), I1); in HoistThenElseCodeToIf()
1277 BIParent->getInstList().insert(BI->getIterator(), NT); in HoistThenElseCodeToIf()
1304 Builder.CreateSelect(BI->getCondition(), BB1V, BB2V, in HoistThenElseCodeToIf()
1305 BB1V->getName() + "." + BB2V->getName(), BI)); in HoistThenElseCodeToIf()
1318 EraseTerminatorInstAndDCECond(BI); in HoistThenElseCodeToIf()
1595 static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB, in SpeculativelyExecuteBB() argument
1598 Value *BrCond = BI->getCondition(); in SpeculativelyExecuteBB()
1602 BasicBlock *BB = BI->getParent(); in SpeculativelyExecuteBB()
1608 if (ThenBB != BI->getSuccessor(0)) { in SpeculativelyExecuteBB()
1609 assert(ThenBB == BI->getSuccessor(1) && "No edge from 'if' block?"); in SpeculativelyExecuteBB()
1612 assert(EndBB == BI->getSuccessor(!Invert) && "No edge from to end block"); in SpeculativelyExecuteBB()
1729 IRBuilder<NoFolder> Builder(BI); in SpeculativelyExecuteBB()
1735 BrCond, TrueV, FalseV, TrueV->getName() + "." + FalseV->getName(), BI); in SpeculativelyExecuteBB()
1745 BB->getInstList().splice(BI->getIterator(), ThenBB->getInstList(), in SpeculativelyExecuteBB()
1749 IRBuilder<NoFolder> Builder(BI); in SpeculativelyExecuteBB()
1768 BrCond, TrueV, FalseV, TrueV->getName() + "." + FalseV->getName(), BI); in SpeculativelyExecuteBB()
1779 BranchInst *BI = cast<BranchInst>(BB->getTerminator()); in BlockIsSimpleEnoughToThreadThrough() local
1782 for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) { in BlockIsSimpleEnoughToThreadThrough()
1806 static bool FoldCondBranchOnPHI(BranchInst *BI, const DataLayout &DL) { in FoldCondBranchOnPHI() argument
1807 BasicBlock *BB = BI->getParent(); in FoldCondBranchOnPHI()
1808 PHINode *PN = dyn_cast<PHINode>(BI->getCondition()); in FoldCondBranchOnPHI()
1841 BasicBlock *RealDest = BI->getSuccessor(!CB->getZExtValue()); in FoldCondBranchOnPHI()
1866 for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) { in FoldCondBranchOnPHI()
1910 return FoldCondBranchOnPHI(BI, DL) | true; in FoldCondBranchOnPHI()
2060 static bool SimplifyCondBranchToTwoReturns(BranchInst *BI, in SimplifyCondBranchToTwoReturns() argument
2062 assert(BI->isConditional() && "Must be a conditional branch"); in SimplifyCondBranchToTwoReturns()
2063 BasicBlock *TrueSucc = BI->getSuccessor(0); in SimplifyCondBranchToTwoReturns()
2064 BasicBlock *FalseSucc = BI->getSuccessor(1); in SimplifyCondBranchToTwoReturns()
2076 Builder.SetInsertPoint(BI); in SimplifyCondBranchToTwoReturns()
2081 TrueSucc->removePredecessor(BI->getParent()); in SimplifyCondBranchToTwoReturns()
2082 FalseSucc->removePredecessor(BI->getParent()); in SimplifyCondBranchToTwoReturns()
2084 EraseTerminatorInstAndDCECond(BI); in SimplifyCondBranchToTwoReturns()
2096 TrueValue = TVPN->getIncomingValueForBlock(BI->getParent()); in SimplifyCondBranchToTwoReturns()
2099 FalseValue = FVPN->getIncomingValueForBlock(BI->getParent()); in SimplifyCondBranchToTwoReturns()
2115 TrueSucc->removePredecessor(BI->getParent()); in SimplifyCondBranchToTwoReturns()
2116 FalseSucc->removePredecessor(BI->getParent()); in SimplifyCondBranchToTwoReturns()
2119 Value *BrCond = BI->getCondition(); in SimplifyCondBranchToTwoReturns()
2127 Builder.CreateSelect(BrCond, TrueValue, FalseValue, "retval", BI); in SimplifyCondBranchToTwoReturns()
2137 << "\n " << *BI << "NewRet = " << *RI in SimplifyCondBranchToTwoReturns()
2140 EraseTerminatorInstAndDCECond(BI); in SimplifyCondBranchToTwoReturns()
2165 static bool extractPredSuccWeights(BranchInst *PBI, BranchInst *BI, in extractPredSuccWeights() argument
2173 BI->extractProfMetadata(SuccTrueWeight, SuccFalseWeight); in extractPredSuccWeights()
2188 bool llvm::FoldBranchToCommonDest(BranchInst *BI, unsigned BonusInstThreshold) { in FoldBranchToCommonDest() argument
2189 BasicBlock *BB = BI->getParent(); in FoldBranchToCommonDest()
2192 if (BI->isConditional()) in FoldBranchToCommonDest()
2193 Cond = dyn_cast<Instruction>(BI->getCondition()); in FoldBranchToCommonDest()
2202 (BI->getSuccessor(0) == PBI->getSuccessor(0) || in FoldBranchToCommonDest()
2203 BI->getSuccessor(0) == PBI->getSuccessor(1))) { in FoldBranchToCommonDest()
2231 if (&*CondIt != BI) in FoldBranchToCommonDest()
2269 BasicBlock *TrueDest = BI->getSuccessor(0); in FoldBranchToCommonDest()
2270 BasicBlock *FalseDest = (BI->isConditional()) ? BI->getSuccessor(1) : nullptr; in FoldBranchToCommonDest()
2283 (BI->isConditional() && !SafeToMergeTerminators(BI, PBI)) || in FoldBranchToCommonDest()
2284 (!BI->isConditional() && in FoldBranchToCommonDest()
2285 !isProfitableToFoldUnconditional(BI, PBI, Cond, PHIs))) in FoldBranchToCommonDest()
2292 if (BI->isConditional()) { in FoldBranchToCommonDest()
2366 if (BI->isConditional()) { in FoldBranchToCommonDest()
2373 extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight, in FoldBranchToCommonDest()
2417 MDBuilder(BI->getContext()).createBranchWeights(MDWeights)); in FoldBranchToCommonDest()
2761 static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI, in SimplifyCondBranchToCondBranch() argument
2763 assert(PBI->isConditional() && BI->isConditional()); in SimplifyCondBranchToCondBranch()
2764 BasicBlock *BB = BI->getParent(); in SimplifyCondBranchToCondBranch()
2769 if (PBI->getCondition() == BI->getCondition() && in SimplifyCondBranchToCondBranch()
2776 BI->setCondition( in SimplifyCondBranchToCondBranch()
2788 BI->getCondition()->getName() + ".pr", &BB->front()); in SimplifyCondBranchToCondBranch()
2794 if ((PBI = dyn_cast<BranchInst>(P->getTerminator())) && PBI != BI && in SimplifyCondBranchToCondBranch()
2795 PBI->isConditional() && PBI->getCondition() == BI->getCondition() && in SimplifyCondBranchToCondBranch()
2802 NewPN->addIncoming(BI->getCondition(), P); in SimplifyCondBranchToCondBranch()
2806 BI->setCondition(NewPN); in SimplifyCondBranchToCondBranch()
2811 if (auto *CE = dyn_cast<ConstantExpr>(BI->getCondition())) in SimplifyCondBranchToCondBranch()
2818 if (MergeCondStores && mergeConditionalStores(PBI, BI)) in SimplifyCondBranchToCondBranch()
2828 if (&*BBI != BI) in SimplifyCondBranchToCondBranch()
2832 if (PBI->getSuccessor(0) == BI->getSuccessor(0)) { in SimplifyCondBranchToCondBranch()
2835 } else if (PBI->getSuccessor(0) == BI->getSuccessor(1)) { in SimplifyCondBranchToCondBranch()
2838 } else if (PBI->getSuccessor(1) == BI->getSuccessor(0)) { in SimplifyCondBranchToCondBranch()
2841 } else if (PBI->getSuccessor(1) == BI->getSuccessor(1)) { in SimplifyCondBranchToCondBranch()
2883 BasicBlock *OtherDest = BI->getSuccessor(BIOp ^ 1); in SimplifyCondBranchToCondBranch()
2886 << "AND: " << *BI->getParent()); in SimplifyCondBranchToCondBranch()
2915 Value *BICond = BI->getCondition(); in SimplifyCondBranchToCondBranch()
2931 extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight, in SimplifyCondBranchToCondBranch()
2948 MDBuilder(BI->getContext()) in SimplifyCondBranchToCondBranch()
2988 MDBuilder(BI->getContext()) in SimplifyCondBranchToCondBranch()
3251 static bool SimplifyBranchOnICmpChain(BranchInst *BI, IRBuilder<> &Builder, in SimplifyBranchOnICmpChain() argument
3253 Instruction *Cond = dyn_cast<Instruction>(BI->getCondition()); in SimplifyBranchOnICmpChain()
3293 BasicBlock *DefaultBB = BI->getSuccessor(1); in SimplifyBranchOnICmpChain()
3294 BasicBlock *EdgeBB = BI->getSuccessor(0); in SimplifyBranchOnICmpChain()
3298 BasicBlock *BB = BI->getParent(); in SimplifyBranchOnICmpChain()
3309 BB->splitBasicBlock(BI->getIterator(), "switch.early.test"); in SimplifyBranchOnICmpChain()
3330 Builder.SetInsertPoint(BI); in SimplifyBranchOnICmpChain()
3355 EraseTerminatorInstAndDCECond(BI); in SimplifyBranchOnICmpChain()
3672 if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) { in SimplifyReturn() local
3673 if (BI->isUnconditional()) in SimplifyReturn()
3676 CondBranchPreds.push_back(BI); in SimplifyReturn()
3704 BranchInst *BI = CondBranchPreds.pop_back_val(); in SimplifyReturn() local
3707 if (isa<ReturnInst>(BI->getSuccessor(0)->getTerminator()) && in SimplifyReturn()
3708 isa<ReturnInst>(BI->getSuccessor(1)->getTerminator()) && in SimplifyReturn()
3709 SimplifyCondBranchToTwoReturns(BI, Builder)) in SimplifyReturn()
3778 if (auto *BI = dyn_cast<BranchInst>(TI)) { in SimplifyUnreachable() local
3779 if (BI->isUnconditional()) { in SimplifyUnreachable()
3780 if (BI->getSuccessor(0) == BB) { in SimplifyUnreachable()
3786 if (BI->getSuccessor(0) == BB) { in SimplifyUnreachable()
3787 Builder.CreateBr(BI->getSuccessor(1)); in SimplifyUnreachable()
3788 EraseTerminatorInstAndDCECond(BI); in SimplifyUnreachable()
3789 } else if (BI->getSuccessor(1) == BB) { in SimplifyUnreachable()
3790 Builder.CreateBr(BI->getSuccessor(0)); in SimplifyUnreachable()
3791 EraseTerminatorInstAndDCECond(BI); in SimplifyUnreachable()
5146 static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI, in TryToMergeLandingPad() argument
5165 if (!BI2 || !BI2->isIdenticalTo(BI)) in TryToMergeLandingPad()
5194 IRBuilder<> Builder(BI); in TryToMergeLandingPad()
5196 BI->eraseFromParent(); in TryToMergeLandingPad()
5202 bool SimplifyCFGOpt::SimplifyUncondBranch(BranchInst *BI, in SimplifyUncondBranch() argument
5204 BasicBlock *BB = BI->getParent(); in SimplifyUncondBranch()
5206 if (SinkCommon && SinkThenElseCodeToEnd(BI)) in SimplifyUncondBranch()
5238 if (I->isTerminator() && TryToMergeLandingPad(LPad, BI, BB)) in SimplifyUncondBranch()
5246 if (FoldBranchToCommonDest(BI, BonusInstThreshold)) in SimplifyUncondBranch()
5262 bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) { in SimplifyCondBranch() argument
5263 BasicBlock *BB = BI->getParent(); in SimplifyCondBranch()
5266 if (isValueEqualityComparison(BI)) { in SimplifyCondBranch()
5271 if (SimplifyEqualityComparisonWithOnlyPredecessor(BI, OnlyPred, Builder)) in SimplifyCondBranch()
5280 if (&*I == BI) { in SimplifyCondBranch()
5281 if (FoldValueComparisonIntoPredecessors(BI, Builder)) in SimplifyCondBranch()
5283 } else if (&*I == cast<Instruction>(BI->getCondition())) { in SimplifyCondBranch()
5288 if (&*I == BI && FoldValueComparisonIntoPredecessors(BI, Builder)) in SimplifyCondBranch()
5294 if (SimplifyBranchOnICmpChain(BI, Builder, DL)) in SimplifyCondBranch()
5307 PBI->getCondition(), BI->getCondition(), DL, CondIsFalse); in SimplifyCondBranch()
5310 auto *OldCond = BI->getCondition(); in SimplifyCondBranch()
5314 BI->setCondition(CI); in SimplifyCondBranch()
5324 if (FoldBranchToCommonDest(BI, BonusInstThreshold)) in SimplifyCondBranch()
5331 if (BI->getSuccessor(0)->getSinglePredecessor()) { in SimplifyCondBranch()
5332 if (BI->getSuccessor(1)->getSinglePredecessor()) { in SimplifyCondBranch()
5333 if (HoistThenElseCodeToIf(BI, TTI)) in SimplifyCondBranch()
5338 TerminatorInst *Succ0TI = BI->getSuccessor(0)->getTerminator(); in SimplifyCondBranch()
5340 Succ0TI->getSuccessor(0) == BI->getSuccessor(1)) in SimplifyCondBranch()
5341 if (SpeculativelyExecuteBB(BI, BI->getSuccessor(0), TTI)) in SimplifyCondBranch()
5344 } else if (BI->getSuccessor(1)->getSinglePredecessor()) { in SimplifyCondBranch()
5347 TerminatorInst *Succ1TI = BI->getSuccessor(1)->getTerminator(); in SimplifyCondBranch()
5349 Succ1TI->getSuccessor(0) == BI->getSuccessor(0)) in SimplifyCondBranch()
5350 if (SpeculativelyExecuteBB(BI, BI->getSuccessor(1), TTI)) in SimplifyCondBranch()
5356 if (PHINode *PN = dyn_cast<PHINode>(BI->getCondition())) in SimplifyCondBranch()
5357 if (PN->getParent() == BI->getParent()) in SimplifyCondBranch()
5358 if (FoldCondBranchOnPHI(BI, DL)) in SimplifyCondBranch()
5364 if (PBI != BI && PBI->isConditional()) in SimplifyCondBranch()
5365 if (SimplifyCondBranchToCondBranch(PBI, BI, DL)) in SimplifyCondBranch()
5372 if (PBI != BI && PBI->isConditional()) in SimplifyCondBranch()
5373 if (mergeConditionalStores(PBI, BI)) in SimplifyCondBranch()
5434 if (BranchInst *BI = dyn_cast<BranchInst>(T)) { in removeUndefIntroducingPredecessor() local
5438 if (BI->isUnconditional()) in removeUndefIntroducingPredecessor()
5441 Builder.CreateBr(BI->getSuccessor(0) == BB ? BI->getSuccessor(1) in removeUndefIntroducingPredecessor()
5442 : BI->getSuccessor(0)); in removeUndefIntroducingPredecessor()
5443 BI->eraseFromParent(); in removeUndefIntroducingPredecessor()
5493 if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) { in run() local
5494 if (BI->isUnconditional()) { in run()
5495 if (SimplifyUncondBranch(BI, Builder)) in run()
5498 if (SimplifyCondBranch(BI, Builder)) in run()