• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /freebsd-12-stable/contrib/llvm-project/llvm/lib/Transforms/Utils/

Lines Matching refs:BI

203   bool SimplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder);
204 bool SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder);
371 BranchInst *BI = dyn_cast<BranchInst>(PBB->getTerminator());
372 if (!BI || BI->isConditional() || BI->getSuccessor(0) != BB)
686 } else if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
687 if (BI->isConditional())
688 Cond = dyn_cast<Instruction>(BI->getCondition());
707 } else if (BranchInst *BI = dyn_cast<BranchInst>(TI))
708 if (BI->isConditional() && BI->getCondition()->hasOneUse())
709 if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) {
737 BranchInst *BI = cast<BranchInst>(TI);
738 ICmpInst *ICI = cast<ICmpInst>(BI->getCondition());
739 BasicBlock *Succ = BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_NE);
742 return BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_EQ);
981 if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
983 ICmpInst *ICI = cast<ICmpInst>(BI->getCondition());
1237 /// guarantees that BI's block dominates BB1 and BB2.
1238 static bool HoistThenElseCodeToIf(BranchInst *BI,
1245 BasicBlock *BB1 = BI->getSuccessor(0); // The true destination.
1246 BasicBlock *BB2 = BI->getSuccessor(1); // The false destination
1267 BasicBlock *BIParent = BI->getParent();
1272 // broken BB), instead clone it, and remove BI.
1295 BIParent->getInstList().splice(BI->getIterator(),
1297 BIParent->getInstList().splice(BI->getIterator(),
1304 BIParent->getInstList().splice(BI->getIterator(),
1378 BIParent->getInstList().insert(BI->getIterator(), NT);
1414 Builder.CreateSelect(BI->getCondition(), BB1V, BB2V,
1415 BB1V->getName() + "." + BB2V->getName(), BI));
1429 EraseTerminatorAndDCECond(BI);
1962 static bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB,
1965 Value *BrCond = BI->getCondition();
1969 BasicBlock *BB = BI->getParent();
1975 if (ThenBB != BI->getSuccessor(0)) {
1976 assert(ThenBB == BI->getSuccessor(1) && "No edge from 'if' block?");
1979 assert(EndBB == BI->getSuccessor(!Invert) && "No edge from to end block");
2099 IRBuilder<NoFolder> Builder(BI);
2105 BrCond, TrueV, FalseV, "spec.store.select", BI);
2107 SpeculatedStore->applyMergedLocation(BI->getDebugLoc(),
2117 BB->getInstList().splice(BI->getIterator(), ThenBB->getInstList(),
2121 IRBuilder<NoFolder> Builder(BI);
2139 BrCond, TrueV, FalseV, "spec.select", BI);
2180 static bool FoldCondBranchOnPHI(BranchInst *BI, const DataLayout &DL,
2182 BasicBlock *BB = BI->getParent();
2183 PHINode *PN = dyn_cast<PHINode>(BI->getCondition());
2216 BasicBlock *RealDest = BI->getSuccessor(!CB->getZExtValue());
2232 CritEdgeBranch->setDebugLoc(BI->getDebugLoc());
2242 for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) {
2291 return FoldCondBranchOnPHI(BI, DL, AC) || true;
2456 static bool SimplifyCondBranchToTwoReturns(BranchInst *BI,
2458 assert(BI->isConditional() && "Must be a conditional branch");
2459 BasicBlock *TrueSucc = BI->getSuccessor(0);
2460 BasicBlock *FalseSucc = BI->getSuccessor(1);
2472 Builder.SetInsertPoint(BI);
2477 TrueSucc->removePredecessor(BI->getParent());
2478 FalseSucc->removePredecessor(BI->getParent());
2480 EraseTerminatorAndDCECond(BI);
2492 TrueValue = TVPN->getIncomingValueForBlock(BI->getParent());
2495 FalseValue = FVPN->getIncomingValueForBlock(BI->getParent());
2511 TrueSucc->removePredecessor(BI->getParent());
2512 FalseSucc->removePredecessor(BI->getParent());
2515 Value *BrCond = BI->getCondition();
2523 Builder.CreateSelect(BrCond, TrueValue, FalseValue, "retval", BI);
2533 << "\n " << *BI << "NewRet = " << *RI << "TRUEBLOCK: "
2536 EraseTerminatorAndDCECond(BI);
2558 /// Return true if either PBI or BI has branch weight available, and store
2559 /// the weights in {Pred|Succ}{True|False}Weight. If one of PBI and BI does
2561 static bool extractPredSuccWeights(BranchInst *PBI, BranchInst *BI,
2569 BI->extractProfMetadata(SuccTrueWeight, SuccFalseWeight);
2584 bool llvm::FoldBranchToCommonDest(BranchInst *BI, MemorySSAUpdater *MSSAU,
2586 BasicBlock *BB = BI->getParent();
2591 if (BI->isConditional())
2592 Cond = dyn_cast<Instruction>(BI->getCondition());
2601 (BI->getSuccessor(0) == PBI->getSuccessor(0) ||
2602 BI->getSuccessor(0) == PBI->getSuccessor(1))) {
2632 if (&*CondIt != BI)
2652 // I is used in the same BB. Since BI uses Cond and doesn't have more slots
2674 BasicBlock *TrueDest = BI->getSuccessor(0);
2675 BasicBlock *FalseDest = (BI->isConditional()) ? BI->getSuccessor(1) : nullptr;
2688 (BI->isConditional() && !SafeToMergeTerminators(BI, PBI)) ||
2689 (!BI->isConditional() &&
2690 !isProfitableToFoldUnconditional(BI, PBI, Cond, PHIs)))
2697 if (BI->isConditional()) {
2739 // We already make sure Cond is the last instruction before BI. Therefore,
2771 if (BI->isConditional()) {
2778 extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
2785 // BI: br i1 %y, TrueDest, FalseDest
2786 // TrueWeight is TrueWeight for PBI * TrueWeight for BI.
2788 // FalseWeight is FalseWeight for PBI * TotalWeight for BI +
2789 // TrueWeight for PBI * FalseWeight for BI.
2802 // BI: br i1 %y, TrueDest, FalseDest
2803 // TrueWeight is TrueWeight for PBI * TotalWeight for BI +
2804 // FalseWeight for PBI * TrueWeight for BI.
2808 // FalseWeight is FalseWeight for PBI * FalseWeight for BI.
2870 // If BI was a loop latch, it may have had associated loop metadata.
2872 if (MDNode *LoopMD = BI->getMetadata(LLVMContext::MD_loop))
2876 // could replace PBI's branch probabilities with BI's.
3230 static bool tryWidenCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
3234 // 2) We can sink side effecting instructions into BI's fallthrough
3236 // BI's condition.
3240 IfTrueBB != BI->getParent() || !BI->getParent()->getSinglePredecessor())
3250 if (BI->getSuccessor(1) != IfFalseBB && // no inf looping
3251 BI->getSuccessor(1)->getTerminatingDeoptimizeCall() && // profitability
3252 NoSideEffects(*BI->getParent())) {
3253 BI->getSuccessor(1)->removePredecessor(BI->getParent());
3254 BI->setSuccessor(1, IfFalseBB);
3257 if (BI->getSuccessor(0) != IfFalseBB && // no inf looping
3258 BI->getSuccessor(0)->getTerminatingDeoptimizeCall() && // profitability
3259 NoSideEffects(*BI->getParent())) {
3260 BI->getSuccessor(0)->removePredecessor(BI->getParent());
3261 BI->setSuccessor(0, IfFalseBB);
3269 /// that PBI and BI are both conditional branches, and BI is in one of the
3270 /// successor blocks of PBI - PBI branches to BI.
3271 static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
3274 assert(PBI->isConditional() && BI->isConditional());
3275 BasicBlock *BB = BI->getParent();
3280 if (PBI->getCondition() == BI->getCondition() &&
3287 BI->setCondition(
3299 BI->getCondition()->getName() + ".pr", &BB->front());
3305 if ((PBI = dyn_cast<BranchInst>(P->getTerminator())) && PBI != BI &&
3306 PBI->isConditional() && PBI->getCondition() == BI->getCondition() &&
3313 NewPN->addIncoming(BI->getCondition(), P);
3317 BI->setCondition(NewPN);
3325 if (tryWidenCondBranchToCondBranch(PBI, BI))
3328 if (auto *CE = dyn_cast<ConstantExpr>(BI->getCondition()))
3335 if (MergeCondStores && mergeConditionalStores(PBI, BI, DL, TTI))
3343 if (&*BB->instructionsWithoutDebug().begin() != BI)
3347 if (PBI->getSuccessor(0) == BI->getSuccessor(0)) {
3350 } else if (PBI->getSuccessor(0) == BI->getSuccessor(1)) {
3353 } else if (PBI->getSuccessor(1) == BI->getSuccessor(0)) {
3356 } else if (PBI->getSuccessor(1) == BI->getSuccessor(1)) {
3398 BasicBlock *OtherDest = BI->getSuccessor(BIOp ^ 1);
3401 << "AND: " << *BI->getParent());
3421 // BI may have other predecessors. Because of this, we leave
3430 Value *BICond = BI->getCondition();
3446 extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
3466 // block that are identical to the entries for BI's block.
3750 static bool SimplifyBranchOnICmpChain(BranchInst *BI, IRBuilder<> &Builder,
3752 Instruction *Cond = dyn_cast<Instruction>(BI->getCondition());
3792 BasicBlock *DefaultBB = BI->getSuccessor(1);
3793 BasicBlock *EdgeBB = BI->getSuccessor(0);
3797 BasicBlock *BB = BI->getParent();
3813 BB->splitBasicBlock(BI->getIterator(), "switch.early.test");
3834 Builder.SetInsertPoint(BI);
3859 EraseTerminatorAndDCECond(BI);
4177 if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) {
4178 if (BI->isUnconditional())
4181 CondBranchPreds.push_back(BI);
4209 BranchInst *BI = CondBranchPreds.pop_back_val();
4212 if (isa<ReturnInst>(BI->getSuccessor(0)->getTerminator()) &&
4213 isa<ReturnInst>(BI->getSuccessor(1)->getTerminator()) &&
4214 SimplifyCondBranchToTwoReturns(BI, Builder))
4283 if (auto *BI = dyn_cast<BranchInst>(TI)) {
4284 if (BI->isUnconditional()) {
4285 assert(BI->getSuccessor(0) == BB && "Incorrect CFG");
4290 Value* Cond = BI->getCondition();
4291 if (BI->getSuccessor(0) == BB) {
4293 Builder.CreateBr(BI->getSuccessor(1));
4295 assert(BI->getSuccessor(1) == BB && "Incorrect CFG");
4297 Builder.CreateBr(BI->getSuccessor(0));
4299 EraseTerminatorAndDCECond(BI);
5801 static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
5820 if (!BI2 || !BI2->isIdenticalTo(BI))
5849 IRBuilder<> Builder(BI);
5851 BI->eraseFromParent();
5857 bool SimplifyCFGOpt::SimplifyUncondBranch(BranchInst *BI,
5859 BasicBlock *BB = BI->getParent();
5860 BasicBlock *Succ = BI->getSuccessor(0);
5894 if (I->isTerminator() && TryToMergeLandingPad(LPad, BI, BB))
5902 if (FoldBranchToCommonDest(BI, nullptr, Options.BonusInstThreshold))
5918 bool SimplifyCFGOpt::SimplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
5919 BasicBlock *BB = BI->getParent();
5925 if (isValueEqualityComparison(BI)) {
5930 if (SimplifyEqualityComparisonWithOnlyPredecessor(BI, OnlyPred, Builder))
5936 if (&*I == BI) {
5937 if (FoldValueComparisonIntoPredecessors(BI, Builder))
5939 } else if (&*I == cast<Instruction>(BI->getCondition())) {
5941 if (&*I == BI && FoldValueComparisonIntoPredecessors(BI, Builder))
5947 if (SimplifyBranchOnICmpChain(BI, Builder, DL))
5951 // blocks' conditions imply BI's condition, we know the direction of BI.
5952 Optional<bool> Imp = isImpliedByDomCondition(BI->getCondition(), BI, DL);
5955 auto *OldCond = BI->getCondition();
5958 BI->setCondition(TorF);
5966 if (FoldBranchToCommonDest(BI, nullptr, Options.BonusInstThreshold))
5970 // from BI. We know that the condbr dominates the two blocks, so see if
5973 if (BI->getSuccessor(0)->getSinglePredecessor()) {
5974 if (BI->getSuccessor(1)->getSinglePredecessor()) {
5975 if (HoistThenElseCodeToIf(BI, TTI))
5980 Instruction *Succ0TI = BI->getSuccessor(0)->getTerminator();
5982 Succ0TI->getSuccessor(0) == BI->getSuccessor(1))
5983 if (SpeculativelyExecuteBB(BI, BI->getSuccessor(0), TTI))
5986 } else if (BI->getSuccessor(1)->getSinglePredecessor()) {
5989 Instruction *Succ1TI = BI->getSuccessor(1)->getTerminator();
5991 Succ1TI->getSuccessor(0) == BI->getSuccessor(0))
5992 if (SpeculativelyExecuteBB(BI, BI->getSuccessor(1), TTI))
5998 if (PHINode *PN = dyn_cast<PHINode>(BI->getCondition()))
5999 if (PN->getParent() == BI->getParent())
6000 if (FoldCondBranchOnPHI(BI, DL, Options.AC))
6006 if (PBI != BI && PBI->isConditional())
6007 if (SimplifyCondBranchToCondBranch(PBI, BI, DL, TTI))
6014 if (PBI != BI && PBI->isConditional())
6015 if (mergeConditionalStores(PBI, BI, DL, TTI))
6081 if (BranchInst *BI = dyn_cast<BranchInst>(T)) {
6085 if (BI->isUnconditional())
6088 Builder.CreateBr(BI->getSuccessor(0) == BB ? BI->getSuccessor(1)
6089 : BI->getSuccessor(0));
6090 BI->eraseFromParent();
6142 if (auto *BI = dyn_cast<BranchInst>(BB->getTerminator())) {
6143 if (BI->isUnconditional()) {
6144 if (SimplifyUncondBranch(BI, Builder))
6147 if (SimplifyCondBranch(BI, Builder))