Lines Matching defs:BI

268   bool simplifyUncondBranch(BranchInst *BI, IRBuilder<> &Builder);
269 bool simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder);
278 bool SpeculativelyExecuteBB(BranchInst *BI, BasicBlock *ThenBB);
282 bool SimplifyBranchOnICmpChain(BranchInst *BI, IRBuilder<> &Builder,
441 BranchInst *BI = dyn_cast<BranchInst>(PBB->getTerminator());
442 if (!BI || BI->isConditional() || BI->getSuccessor(0) != BB)
761 } else if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
762 if (BI->isConditional())
763 Cond = dyn_cast<Instruction>(BI->getCondition());
782 } else if (BranchInst *BI = dyn_cast<BranchInst>(TI))
783 if (BI->isConditional() && BI->getCondition()->hasOneUse())
784 if (ICmpInst *ICI = dyn_cast<ICmpInst>(BI->getCondition())) {
812 BranchInst *BI = cast<BranchInst>(TI);
813 ICmpInst *ICI = cast<ICmpInst>(BI->getCondition());
814 BasicBlock *Succ = BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_NE);
817 return BI->getSuccessor(ICI->getPredicate() == ICmpInst::ICMP_EQ);
1077 if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
1079 ICmpInst *ICI = cast<ICmpInst>(BI->getCondition());
1589 /// In that case, only the original BI will be replaced and selects for PHIs are
1689 // broken BB), instead clone it, and remove BI.
1782 auto *BI = dyn_cast<BranchInst>(TI);
1791 if (BI) {
1793 assert(BI->getSuccessor(0) == I1->getParent());
1794 assert(BI->getSuccessor(1) == I2->getParent());
1801 if (isa<InvokeInst>(I1) && (!BI || !isSafeToHoistInvoke(BB1, BB2, I1, I2)))
1819 if (!BI || passingValueIsAlwaysUndefined(BB1V, &PN) ||
1857 if (BI) {
1876 BI->getCondition(), BB1V, BB2V,
1877 BB1V->getName() + "." + BB2V->getName(), BI));
3000 bool SimplifyCFGOpt::SpeculativelyExecuteBB(BranchInst *BI,
3006 Value *BrCond = BI->getCondition();
3010 BasicBlock *BB = BI->getParent();
3018 if (ThenBB != BI->getSuccessor(0)) {
3019 assert(ThenBB == BI->getSuccessor(1) && "No edge from 'if' block?");
3022 assert(EndBB == BI->getSuccessor(!Invert) && "No edge from to end block");
3026 if (!BI->getMetadata(LLVMContext::MD_unpredictable)) {
3028 if (extractBranchWeights(*BI, TWeight, FWeight) &&
3132 IRBuilder<NoFolder> Builder(BI);
3139 BrCond, TrueV, FalseV, "spec.store.select", BI);
3141 SpeculatedStore->applyMergedLocation(BI->getDebugLoc(),
3208 BB->splice(BI->getIterator(), ThenBB, ThenBB->begin(),
3212 IRBuilder<NoFolder> Builder(BI);
3229 Value *V = Builder.CreateSelect(BrCond, TrueV, FalseV, "spec.select", BI);
3292 auto *BI = dyn_cast<BranchInst>(From->getTerminator());
3293 if (BI && BI->isConditional() && BI->getCondition() == V &&
3294 BI->getSuccessor(0) != BI->getSuccessor(1))
3295 return BI->getSuccessor(0) == To ? ConstantInt::getTrue(BI->getContext())
3296 : ConstantInt::getFalse(BI->getContext());
3305 FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
3309 BasicBlock *BB = BI->getParent();
3310 Value *Cond = BI->getCondition();
3343 BasicBlock *RealDest = BI->getSuccessor(!CB->getZExtValue());
3383 for (BasicBlock::iterator BBI = BB->begin(); &*BBI != BI; ++BBI) {
3433 for (; &*SrcDbgCursor != BI; ++SrcDbgCursor)
3435 InsertPt->cloneDebugInfoFrom(BI);
3440 EdgeBI->setDebugLoc(BI->getDebugLoc());
3462 static bool FoldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
3470 Result = FoldCondBranchOnValueKnownInPredecessorImpl(BI, DTU, DL, AC);
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,
3700 extractBranchWeights(*BI, SuccTrueWeight, SuccFalseWeight);
3716 shouldFoldCondBranchesToCommonDestination(BranchInst *BI, BranchInst *PBI,
3718 assert(BI && PBI && BI->isConditional() && PBI->isConditional() &&
3720 assert(is_contained(predecessors(BI->getParent()), PBI->getParent()) &&
3735 if (PBI->getSuccessor(0) == BI->getSuccessor(0)) {
3738 return {{BI->getSuccessor(0), Instruction::Or, false}};
3739 } else if (PBI->getSuccessor(1) == BI->getSuccessor(1)) {
3742 return {{BI->getSuccessor(1), Instruction::And, false}};
3743 } else if (PBI->getSuccessor(0) == BI->getSuccessor(1)) {
3746 return {{BI->getSuccessor(1), Instruction::And, true}};
3747 } else if (PBI->getSuccessor(1) == BI->getSuccessor(0)) {
3750 return {{BI->getSuccessor(0), Instruction::Or, true}};
3755 static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
3759 BasicBlock *BB = BI->getParent();
3767 *shouldFoldCondBranchesToCommonDestination(BI, PBI, TTI);
3784 PBI->getSuccessor(0) == BB ? BI->getSuccessor(0) : BI->getSuccessor(1);
3793 if (extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
3799 // BI: br i1 %y, UniqueSucc, 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.
3811 // BI: br i1 %y, TrueDest, UniqueSucc
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.
3827 // could replace PBI's branch probabilities with BI's.
3838 // If BI was a loop latch, it may have had associated loop metadata.
3840 if (MDNode *LoopMD = BI->getMetadata(LLVMContext::MD_loop))
3859 Value *BICond = VMap[BI->getCondition()];
3878 bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
3884 if (!BI->isConditional())
3887 BasicBlock *BB = BI->getParent();
3892 Instruction *Cond = dyn_cast<Instruction>(BI->getCondition());
3912 if (!PBI || PBI->isUnconditional() || !SafeToMergeTerminators(BI, PBI))
3919 if (auto Recipe = shouldFoldCondBranchesToCommonDestination(BI, PBI, TTI))
3927 Type *Ty = BI->getCondition()->getType();
3998 return performBranchToCommonDestFolding(BI, PBI, DTU, MSSAU, TTI);
4332 static bool tryWidenCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
4337 // 2) We can sink side effecting instructions into BI's fallthrough
4339 // BI's condition.
4342 if (!isWidenableBranch(PBI) || IfTrueBB != BI->getParent() ||
4343 !BI->getParent()->getSinglePredecessor())
4358 if (BI->getSuccessor(1) != IfFalseBB && // no inf looping
4359 BI->getSuccessor(1)->getTerminatingDeoptimizeCall() && // profitability
4360 NoSideEffects(*BI->getParent())) {
4361 auto *OldSuccessor = BI->getSuccessor(1);
4362 OldSuccessor->removePredecessor(BI->getParent());
4363 BI->setSuccessor(1, IfFalseBB);
4366 {{DominatorTree::Insert, BI->getParent(), IfFalseBB},
4367 {DominatorTree::Delete, BI->getParent(), OldSuccessor}});
4370 if (BI->getSuccessor(0) != IfFalseBB && // no inf looping
4371 BI->getSuccessor(0)->getTerminatingDeoptimizeCall() && // profitability
4372 NoSideEffects(*BI->getParent())) {
4373 auto *OldSuccessor = BI->getSuccessor(0);
4374 OldSuccessor->removePredecessor(BI->getParent());
4375 BI->setSuccessor(0, IfFalseBB);
4378 {{DominatorTree::Insert, BI->getParent(), IfFalseBB},
4379 {DominatorTree::Delete, BI->getParent(), OldSuccessor}});
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());
4394 BasicBlock *BB = BI->getParent();
4399 if (PBI->getCondition() == BI->getCondition() &&
4407 BI->setCondition(
4416 if (tryWidenCondBranchToCondBranch(PBI, BI, DTU))
4422 if (MergeCondStores && mergeConditionalStores(PBI, BI, DTU, DL, TTI))
4430 if (&*BB->instructionsWithoutDebug(false).begin() != BI)
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)) {
4485 BasicBlock *OtherDest = BI->getSuccessor(BIOp ^ 1);
4488 << "AND: " << *BI->getParent());
4512 // BI may have other predecessors. Because of this, we leave
4521 Value *BICond = BI->getCondition();
4545 extractPredSuccWeights(PBI, BI, PredTrueWeight, PredFalseWeight,
4565 // block that are identical to the entries for BI's block.
4878 bool SimplifyCFGOpt::SimplifyBranchOnICmpChain(BranchInst *BI,
4881 Instruction *Cond = dyn_cast<Instruction>(BI->getCondition());
4921 BasicBlock *DefaultBB = BI->getSuccessor(1);
4922 BasicBlock *EdgeBB = BI->getSuccessor(0);
4926 BasicBlock *BB = BI->getParent();
4938 BasicBlock *NewBB = SplitBlock(BB, BI, DTU, /*LI=*/nullptr,
4952 if (!isGuaranteedNotToBeUndefOrPoison(ExtraCase, AC, BI, nullptr))
4974 Builder.SetInsertPoint(BI);
4999 EraseTerminatorAndDCECond(BI);
5350 if (auto *BI = dyn_cast<BranchInst>(TI)) {
5353 if (all_of(BI->successors(),
5359 assert(BI->isConditional() && "Can't get here with an uncond branch.");
5360 Value* Cond = BI->getCondition();
5361 assert(BI->getSuccessor(0) != BI->getSuccessor(1) &&
5364 if (BI->getSuccessor(0) == BB) {
5366 Builder.CreateBr(BI->getSuccessor(1));
5368 assert(BI->getSuccessor(1) == BB && "Incorrect CFG");
5370 Builder.CreateBr(BI->getSuccessor(0));
5375 EraseTerminatorAndDCECond(BI);
7239 static bool TryToMergeLandingPad(LandingPadInst *LPad, BranchInst *BI,
7258 if (!BI2 || !BI2->isIdenticalTo(BI))
7290 IRBuilder<> Builder(BI);
7292 BI->eraseFromParent();
7305 bool SimplifyCFGOpt::simplifyUncondBranch(BranchInst *BI,
7307 BasicBlock *BB = BI->getParent();
7308 BasicBlock *Succ = BI->getSuccessor(0);
7342 if (I->isTerminator() && TryToMergeLandingPad(LPad, BI, BB, DTU))
7351 FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
7388 static bool mergeNestedCondBranch(BranchInst *BI, DomTreeUpdater *DTU) {
7389 BasicBlock *BB = BI->getParent();
7390 BasicBlock *BB1 = BI->getSuccessor(0);
7391 BasicBlock *BB2 = BI->getSuccessor(1);
7416 IRBuilder<> Builder(BI);
7417 BI->setCondition(
7418 Builder.CreateXor(BI->getCondition(), BB1BI->getCondition()));
7420 BI->setSuccessor(0, BB4);
7422 BI->setSuccessor(1, BB3);
7434 if (extractBranchWeights(*BI, BBTWeight, BBFWeight))
7452 setBranchWeights(BI, Weights[0], Weights[1], /*IsExpected=*/false);
7457 bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
7459 !isa<ConstantInt>(BI->getCondition()) &&
7460 BI->getSuccessor(0) != BI->getSuccessor(1) &&
7463 BasicBlock *BB = BI->getParent();
7465 BI->getFunction()->hasFnAttribute(Attribute::OptForFuzzing))
7469 if (isValueEqualityComparison(BI)) {
7474 if (SimplifyEqualityComparisonWithOnlyPredecessor(BI, OnlyPred, Builder))
7480 if (&*I == BI) {
7481 if (FoldValueComparisonIntoPredecessors(BI, Builder))
7483 } else if (&*I == cast<Instruction>(BI->getCondition())) {
7485 if (&*I == BI && FoldValueComparisonIntoPredecessors(BI, Builder))
7491 if (SimplifyBranchOnICmpChain(BI, Builder, DL))
7495 // blocks' conditions imply BI's condition, we know the direction of BI.
7496 std::optional<bool> Imp = isImpliedByDomCondition(BI->getCondition(), BI, DL);
7499 auto *OldCond = BI->getCondition();
7502 BI->setCondition(TorF);
7511 FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
7516 // from BI. We know that the condbr dominates the two blocks, so see if
7519 if (BI->getSuccessor(0)->getSinglePredecessor()) {
7520 if (BI->getSuccessor(1)->getSinglePredecessor()) {
7522 BI->getParent(), !Options.HoistCommonInsts))
7527 Instruction *Succ0TI = BI->getSuccessor(0)->getTerminator();
7529 Succ0TI->getSuccessor(0) == BI->getSuccessor(1))
7530 if (SpeculativelyExecuteBB(BI, BI->getSuccessor(0)))
7533 } else if (BI->getSuccessor(1)->getSinglePredecessor()) {
7536 Instruction *Succ1TI = BI->getSuccessor(1)->getTerminator();
7538 Succ1TI->getSuccessor(0) == BI->getSuccessor(0))
7539 if (SpeculativelyExecuteBB(BI, BI->getSuccessor(1)))
7546 if (FoldCondBranchOnValueKnownInPredecessor(BI, DTU, DL, Options.AC))
7552 if (PBI != BI && PBI->isConditional())
7553 if (SimplifyCondBranchToCondBranch(PBI, BI, DTU, DL, TTI))
7560 if (PBI != BI && PBI->isConditional())
7561 if (mergeConditionalStores(PBI, BI, DTU, DL, TTI))
7565 if (mergeNestedCondBranch(BI, DTU))
7717 if (BranchInst *BI = dyn_cast<BranchInst>(T)) {
7721 if (BI->isUnconditional())
7726 Value *Cond = BI->getCondition();
7728 if (BI->getSuccessor(0) == BB)
7734 Builder.CreateBr(BI->getSuccessor(0) == BB ? BI->getSuccessor(1)
7735 : BI->getSuccessor(0));
7737 BI->eraseFromParent();