[llvm] 5b4015e - [Transforms][NFC] Drop uses of BranchInst in headers (#186580)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 14 04:03:38 PDT 2026
Author: Alexis Engelke
Date: 2026-03-14T11:03:33Z
New Revision: 5b4015e559614ac1fd7349dd4ccfa429974a9711
URL: https://github.com/llvm/llvm-project/commit/5b4015e559614ac1fd7349dd4ccfa429974a9711
DIFF: https://github.com/llvm/llvm-project/commit/5b4015e559614ac1fd7349dd4ccfa429974a9711.diff
LOG: [Transforms][NFC] Drop uses of BranchInst in headers (#186580)
Replace BranchInst with CondBrInst/UncondBrInst/Instruction in headers
and handle the related fall out.
The removed code in simplifyUncondBranch was made dead in
0895b836d74ed333468ddece2102140494eb33b6, where FoldBranchToCommonDest
was changed to only handle conditional branches.
Added:
Modified:
llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
llvm/include/llvm/Transforms/IPO/IROutliner.h
llvm/include/llvm/Transforms/Scalar/GVN.h
llvm/include/llvm/Transforms/Scalar/JumpThreading.h
llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/include/llvm/Transforms/Utils/GuardUtils.h
llvm/include/llvm/Transforms/Utils/Local.h
llvm/include/llvm/Transforms/Utils/LoopConstrainer.h
llvm/include/llvm/Transforms/Utils/LoopUtils.h
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/lib/Transforms/Scalar/GuardWidening.cpp
llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/lib/Transforms/Scalar/LoopPredication.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/lib/Transforms/Utils/FlattenCFG.cpp
llvm/lib/Transforms/Utils/GuardUtils.cpp
llvm/lib/Transforms/Utils/LoopConstrainer.cpp
llvm/lib/Transforms/Utils/LoopSimplify.cpp
llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/unittests/Transforms/Vectorize/VPlanTestBase.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h b/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
index 5a682e8c7b5eb..d70d281ce7267 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h
@@ -198,7 +198,7 @@ class InstCostVisitor : public InstVisitor<InstCostVisitor, Constant *> {
Cost estimateBasicBlocks(SmallVectorImpl<BasicBlock *> &WorkList);
Cost estimateSwitchInst(SwitchInst &I);
- Cost estimateBranchInst(BranchInst &I);
+ Cost estimateCondBrInst(CondBrInst &I);
// Transitively Incoming Values (TIV) is a set of Values that can "feed" a
// value to the initial PHI-node. It is defined like this:
diff --git a/llvm/include/llvm/Transforms/IPO/IROutliner.h b/llvm/include/llvm/Transforms/IPO/IROutliner.h
index ed2754fabbd05..dccbe5a2038e0 100644
--- a/llvm/include/llvm/Transforms/IPO/IROutliner.h
+++ b/llvm/include/llvm/Transforms/IPO/IROutliner.h
@@ -370,7 +370,8 @@ class IROutliner {
struct InstructionAllowed : public InstVisitor<InstructionAllowed, bool> {
InstructionAllowed() = default;
- bool visitBranchInst(BranchInst &BI) { return EnableBranches; }
+ bool visitUncondBrInst(UncondBrInst &BI) { return EnableBranches; }
+ bool visitCondBrInst(CondBrInst &BI) { return EnableBranches; }
bool visitPHINode(PHINode &PN) { return EnableBranches; }
// TODO: Handle allocas.
bool visitAllocaInst(AllocaInst &AI) { return false; }
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h b/llvm/include/llvm/Transforms/Scalar/GVN.h
index bc0f108ac8260..f79896e993d9b 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -37,8 +37,8 @@ class AAResults;
class AssumeInst;
class AssumptionCache;
class BasicBlock;
-class BranchInst;
class CallInst;
+class CondBrInst;
class ExtractValueInst;
class Function;
class FunctionPass;
@@ -401,7 +401,7 @@ class GVNPass : public PassInfoMixin<GVNPass> {
bool
propagateEquality(Value *LHS, Value *RHS,
const std::variant<BasicBlockEdge, Instruction *> &Root);
- bool processFoldableCondBr(BranchInst *BI);
+ bool processFoldableCondBr(CondBrInst *BI);
void addDeadBlock(BasicBlock *BB);
void assignValNumForDeadCode();
void assignBlockRPONumber(Function &F);
diff --git a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
index 1a19eb94e60ea..348cefb4360e4 100644
--- a/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
+++ b/llvm/include/llvm/Transforms/Scalar/JumpThreading.h
@@ -31,7 +31,7 @@ namespace llvm {
class AAResults;
class BasicBlock;
class BinaryOperator;
-class BranchInst;
+class CondBrInst;
class CmpInst;
class Constant;
class Function;
@@ -173,7 +173,7 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
LLVM_ABI bool processGuards(BasicBlock *BB);
LLVM_ABI bool threadGuard(BasicBlock *BB, IntrinsicInst *Guard,
- BranchInst *BI);
+ CondBrInst *BI);
private:
BasicBlock *splitBlockPreds(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
index 8a80e7f1d8e9b..460dcdd8a2c00 100644
--- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -26,7 +26,7 @@
#include <cassert>
namespace llvm {
-class BranchInst;
+class CondBrInst;
class LandingPadInst;
class Loop;
class PHINode;
@@ -603,7 +603,7 @@ LLVM_ABI void SplitBlockAndInsertForEachLane(
///
/// This does no checking to see if the true/false blocks have large or unsavory
/// instructions in them.
-LLVM_ABI BranchInst *GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,
+LLVM_ABI CondBrInst *GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,
BasicBlock *&IfFalse);
// Split critical edges where the source of the edge is an indirectbr
@@ -634,7 +634,7 @@ LLVM_ABI bool SplitIndirectBrCriticalEdges(Function &F,
// Utility function for inverting branch condition and for swapping its
// successors
-LLVM_ABI void InvertBranch(BranchInst *PBI, IRBuilderBase &Builder);
+LLVM_ABI void InvertBranch(CondBrInst *PBI, IRBuilderBase &Builder);
// Check whether the function only has simple terminator:
// br/brcond/unreachable/ret
diff --git a/llvm/include/llvm/Transforms/Utils/GuardUtils.h b/llvm/include/llvm/Transforms/Utils/GuardUtils.h
index 7ab5d9ef4f238..f2a9ee1b9260b 100644
--- a/llvm/include/llvm/Transforms/Utils/GuardUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/GuardUtils.h
@@ -14,7 +14,7 @@
namespace llvm {
-class BranchInst;
+class CondBrInst;
class CallInst;
class Function;
class Value;
@@ -32,12 +32,12 @@ void makeGuardControlFlowExplicit(Function *DeoptIntrinsic, CallInst *Guard,
/// Given a branch we know is widenable (defined per Analysis/GuardUtils.h),
/// widen it such that condition 'NewCond' is also known to hold on the taken
/// path. Branch remains widenable after transform.
-void widenWidenableBranch(BranchInst *WidenableBR, Value *NewCond);
+void widenWidenableBranch(CondBrInst *WidenableBR, Value *NewCond);
/// Given a branch we know is widenable (defined per Analysis/GuardUtils.h),
/// *set* it's condition such that (only) 'Cond' is known to hold on the taken
/// path and that the branch remains widenable after transform.
-void setWidenableBranchCond(BranchInst *WidenableBR, Value *Cond);
+void setWidenableBranchCond(CondBrInst *WidenableBR, Value *Cond);
} // llvm
diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h
index 9acfd872e574b..8456d986957b2 100644
--- a/llvm/include/llvm/Transforms/Utils/Local.h
+++ b/llvm/include/llvm/Transforms/Utils/Local.h
@@ -33,9 +33,9 @@ class AAResults;
class AllocaInst;
class AssumptionCache;
class BasicBlock;
-class BranchInst;
class CallBase;
class CallInst;
+class CondBrInst;
class DIBuilder;
class DomTreeUpdater;
class Function;
@@ -202,7 +202,7 @@ LLVM_ABI bool FlattenCFG(BasicBlock *BB, AAResults *AA = nullptr);
/// If this basic block is ONLY a setcc and a branch, and if a predecessor
/// branches to us and one of our successors, fold the setcc into the
/// predecessor and use logical operations to pick the right destination.
-LLVM_ABI bool foldBranchToCommonDest(BranchInst *BI,
+LLVM_ABI bool foldBranchToCommonDest(CondBrInst *BI,
llvm::DomTreeUpdater *DTU = nullptr,
MemorySSAUpdater *MSSAU = nullptr,
const TargetTransformInfo *TTI = nullptr,
diff --git a/llvm/include/llvm/Transforms/Utils/LoopConstrainer.h b/llvm/include/llvm/Transforms/Utils/LoopConstrainer.h
index 64db907e9a0f4..ca3a928b92c11 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopConstrainer.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopConstrainer.h
@@ -16,7 +16,7 @@
namespace llvm {
class BasicBlock;
-class BranchInst;
+class CondBrInst;
class DominatorTree;
class IntegerType;
class Loop;
@@ -39,7 +39,7 @@ struct LoopStructure {
// `Latch's terminator instruction is `LatchBr', and it's `LatchBrExitIdx'th
// successor is `LatchExit', the exit block of the loop.
- BranchInst *LatchBr = nullptr;
+ CondBrInst *LatchBr = nullptr;
BasicBlock *LatchExit = nullptr;
unsigned LatchBrExitIdx = std::numeric_limits<unsigned>::max();
@@ -67,7 +67,7 @@ struct LoopStructure {
Result.Tag = Tag;
Result.Header = cast<BasicBlock>(Map(Header));
Result.Latch = cast<BasicBlock>(Map(Latch));
- Result.LatchBr = cast<BranchInst>(Map(LatchBr));
+ Result.LatchBr = cast<CondBrInst>(Map(LatchBr));
Result.LatchExit = cast<BasicBlock>(Map(LatchExit));
Result.LatchBrExitIdx = LatchBrExitIdx;
Result.IndVarBase = Map(IndVarBase);
diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
index 1e48eeca72952..ccba9ee16885b 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -403,7 +403,7 @@ bool setLoopProbability(Loop *L, BranchProbability P);
/// - The probability \c P that control flows from \p B to its first target
/// label such that `1 - P` is the probability of control flowing to its
/// second target label, or vice-versa if \p ForFirstTarget is false.
-BranchProbability getBranchProbability(BranchInst *B, bool ForFirstTarget);
+BranchProbability getBranchProbability(CondBrInst *B, bool ForFirstTarget);
/// Calculates the edge probability from Src to Dst.
/// Dst has to be a successor to Src.
@@ -416,11 +416,8 @@ BranchProbability getBranchProbability(BasicBlock *Src, BasicBlock *Dst);
/// Set branch weight metadata for \p B to indicate that \p P and `1 - P` are
/// the probabilities of control flowing to its first and second target labels,
-/// respectively, or vice-versa if \p ForFirstTarget is false. Return false if
-/// the implementation cannot set the probability (e.g., \p B must have exactly
-/// two target labels, so it must be a conditional branch). Otherwise, return
-/// true.
-bool setBranchProbability(BranchInst *B, BranchProbability P,
+/// respectively, or vice-versa if \p ForFirstTarget is false.
+void setBranchProbability(CondBrInst *B, BranchProbability P,
bool ForFirstTarget);
/// Check inner loop (L) backedge count is known to be invariant on all
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 5a53017f478d6..cd914db8434ef 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -229,8 +229,8 @@ Cost InstCostVisitor::getCodeSizeSavingsForUser(Instruction *User, Value *Use,
Cost CodeSize = 0;
if (auto *I = dyn_cast<SwitchInst>(User)) {
CodeSize = estimateSwitchInst(*I);
- } else if (auto *I = dyn_cast<BranchInst>(User)) {
- CodeSize = estimateBranchInst(*I);
+ } else if (auto *I = dyn_cast<CondBrInst>(User)) {
+ CodeSize = estimateCondBrInst(*I);
} else {
C = visit(*User);
if (!C)
@@ -280,7 +280,7 @@ Cost InstCostVisitor::estimateSwitchInst(SwitchInst &I) {
return estimateBasicBlocks(WorkList);
}
-Cost InstCostVisitor::estimateBranchInst(BranchInst &I) {
+Cost InstCostVisitor::estimateCondBrInst(CondBrInst &I) {
assert(LastVisited != KnownConstants.end() && "Invalid iterator!");
if (I.getCondition() != LastVisited->first)
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index c18cafd75a0a5..7cab4be169123 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2704,10 +2704,7 @@ bool GVNPass::processInstruction(Instruction *I) {
// For conditional branches, we can perform simple conditional propagation on
// the condition value itself.
- if (BranchInst *BI = dyn_cast<BranchInst>(I)) {
- if (!BI->isConditional())
- return false;
-
+ if (CondBrInst *BI = dyn_cast<CondBrInst>(I)) {
if (isa<Constant>(BI->getCondition()))
return processFoldableCondBr(BI);
@@ -3309,10 +3306,7 @@ void GVNPass::addDeadBlock(BasicBlock *BB) {
// dead blocks with "UndefVal" in an hope these PHIs will optimized away.
//
// Return true iff *NEW* dead code are found.
-bool GVNPass::processFoldableCondBr(BranchInst *BI) {
- if (!BI || BI->isUnconditional())
- return false;
-
+bool GVNPass::processFoldableCondBr(CondBrInst *BI) {
// If a branch has two identical successors, we cannot declare either dead.
if (BI->getSuccessor(0) == BI->getSuccessor(1))
return false;
diff --git a/llvm/lib/Transforms/Scalar/GuardWidening.cpp b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
index ddb99a5af6089..c597d68bf06ff 100644
--- a/llvm/lib/Transforms/Scalar/GuardWidening.cpp
+++ b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
@@ -311,7 +311,7 @@ class GuardWideningImpl {
getCondition(ToWiden), *InsertPt);
if (isGuardAsWidenableBranch(ToWiden)) {
- setWidenableBranchCond(cast<BranchInst>(ToWiden), Result);
+ setWidenableBranchCond(cast<CondBrInst>(ToWiden), Result);
return;
}
setCondition(ToWiden, Result);
diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index 308c267969113..98da1e9225172 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -226,7 +226,7 @@ class InductiveRangeCheck {
/// NB! There may be conditions feeding into \p BI that aren't inductive range
/// checks, and hence don't end up in \p Checks.
static void extractRangeChecksFromBranch(
- BranchInst *BI, Loop *L, ScalarEvolution &SE, BranchProbabilityInfo *BPI,
+ CondBrInst *BI, Loop *L, ScalarEvolution &SE, BranchProbabilityInfo *BPI,
std::optional<uint64_t> EstimatedTripCount,
SmallVectorImpl<InductiveRangeCheck> &Checks, bool &Changed);
};
@@ -516,10 +516,10 @@ void InductiveRangeCheck::extractRangeChecksFromCond(
}
void InductiveRangeCheck::extractRangeChecksFromBranch(
- BranchInst *BI, Loop *L, ScalarEvolution &SE, BranchProbabilityInfo *BPI,
+ CondBrInst *BI, Loop *L, ScalarEvolution &SE, BranchProbabilityInfo *BPI,
std::optional<uint64_t> EstimatedTripCount,
SmallVectorImpl<InductiveRangeCheck> &Checks, bool &Changed) {
- if (BI->isUnconditional() || BI->getParent() == L->getLoopLatch())
+ if (BI->getParent() == L->getLoopLatch())
return;
unsigned IndexLoopSucc = L->contains(BI->getSuccessor(0)) ? 0 : 1;
@@ -972,7 +972,7 @@ InductiveRangeCheckElimination::estimatedTripCount(const Loop &L) {
auto *Latch = L.getLoopLatch();
if (!Latch)
return std::nullopt;
- auto *LatchBr = dyn_cast<BranchInst>(Latch->getTerminator());
+ auto *LatchBr = dyn_cast<CondBrInst>(Latch->getTerminator());
if (!LatchBr)
return std::nullopt;
@@ -1012,7 +1012,7 @@ bool InductiveRangeCheckElimination::run(
bool Changed = false;
for (auto *BBI : L->getBlocks())
- if (BranchInst *TBI = dyn_cast<BranchInst>(BBI->getTerminator()))
+ if (CondBrInst *TBI = dyn_cast<CondBrInst>(BBI->getTerminator()))
InductiveRangeCheck::extractRangeChecksFromBranch(
TBI, L, SE, BPI, EstimatedTripCount, RangeChecks, Changed);
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index e8b4ba5f5106f..c6f25157c12d1 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -3057,7 +3057,7 @@ bool JumpThreadingPass::processGuards(BasicBlock *BB) {
if (!Parent || Parent != Pred2->getSinglePredecessor())
return false;
- if (auto *BI = dyn_cast<BranchInst>(Parent->getTerminator()))
+ if (auto *BI = dyn_cast<CondBrInst>(Parent->getTerminator()))
for (auto &I : *BB)
if (isGuard(&I) && threadGuard(BB, cast<IntrinsicInst>(&I), BI))
return true;
@@ -3069,9 +3069,7 @@ bool JumpThreadingPass::processGuards(BasicBlock *BB) {
/// to one of its branches, in case if diamond's condition implies guard's
/// condition.
bool JumpThreadingPass::threadGuard(BasicBlock *BB, IntrinsicInst *Guard,
- BranchInst *BI) {
- assert(BI->getNumSuccessors() == 2 && "Wrong number of successors?");
- assert(BI->isConditional() && "Unconditional branch has 2 successors?");
+ CondBrInst *BI) {
Value *GuardCond = Guard->getArgOperand(0);
Value *BranchCond = BI->getCondition();
BasicBlock *TrueDest = BI->getSuccessor(0);
diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
index b14900d6dd635..5c61d03199eeb 100644
--- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp
@@ -970,7 +970,7 @@ bool LoopPredication::isLoopProfitableToPredicate() {
/// If we can (cheaply) find a widenable branch which controls entry into the
/// loop, return it.
-static BranchInst *FindWidenableTerminatorAboveLoop(Loop *L, LoopInfo &LI) {
+static CondBrInst *FindWidenableTerminatorAboveLoop(Loop *L, LoopInfo &LI) {
// Walk back through any unconditional executed blocks and see if we can find
// a widenable condition which seems to control execution of this loop. Note
// that we predict that maythrow calls are likely untaken and thus that it's
@@ -990,7 +990,7 @@ static BranchInst *FindWidenableTerminatorAboveLoop(Loop *L, LoopInfo &LI) {
} while (true);
if (BasicBlock *Pred = BB->getSinglePredecessor()) {
- if (auto *BI = dyn_cast<BranchInst>(Pred->getTerminator()))
+ if (auto *BI = dyn_cast<CondBrInst>(Pred->getTerminator()))
if (BI->getSuccessor(0) == BB && isWidenableBranch(BI))
return BI;
}
@@ -1121,7 +1121,7 @@ bool LoopPredication::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
continue;
// Can't rewrite non-branch yet.
- auto *BI = dyn_cast<BranchInst>(ExitingBB->getTerminator());
+ auto *BI = dyn_cast<CondBrInst>(ExitingBB->getTerminator());
if (!BI)
continue;
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 6472e1771ec73..c33ceed7ebc20 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1733,7 +1733,7 @@ void llvm::SplitBlockAndInsertForEachLane(
}
}
-BranchInst *llvm::GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,
+CondBrInst *llvm::GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,
BasicBlock *&IfFalse) {
PHINode *SomePHI = dyn_cast<PHINode>(BB->begin());
BasicBlock *Pred1 = nullptr;
@@ -1756,28 +1756,29 @@ BranchInst *llvm::GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,
return nullptr;
}
- // We can only handle branches. Other control flow will be lowered to
- // branches if possible anyway.
- BranchInst *Pred1Br = dyn_cast<BranchInst>(Pred1->getTerminator());
- BranchInst *Pred2Br = dyn_cast<BranchInst>(Pred2->getTerminator());
- if (!Pred1Br || !Pred2Br)
- return nullptr;
+ Instruction *Pred1Term = Pred1->getTerminator();
+ Instruction *Pred2Term = Pred2->getTerminator();
// Eliminate code duplication by ensuring that Pred1Br is conditional if
// either are.
- if (Pred2Br->isConditional()) {
+ if (isa<CondBrInst>(Pred2Term)) {
// If both branches are conditional, we don't have an "if statement". In
// reality, we could transform this case, but since the condition will be
// required anyway, we stand no chance of eliminating it, so the xform is
// probably not profitable.
- if (Pred1Br->isConditional())
+ if (isa<CondBrInst>(Pred1Term))
return nullptr;
std::swap(Pred1, Pred2);
- std::swap(Pred1Br, Pred2Br);
+ std::swap(Pred1Term, Pred2Term);
}
- if (Pred1Br->isConditional()) {
+ // We can only handle branches. Other control flow will be lowered to
+ // branches if possible anyway.
+ if (!isa<UncondBrInst>(Pred2Term))
+ return nullptr;
+
+ if (auto *Pred1Br = dyn_cast<CondBrInst>(Pred1Term)) {
// The only thing we have to watch out for here is to make sure that Pred2
// doesn't have incoming edges from other blocks. If it does, the condition
// doesn't dominate BB.
@@ -1803,6 +1804,9 @@ BranchInst *llvm::GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,
return Pred1Br;
}
+ if (!isa<UncondBrInst>(Pred1Term))
+ return nullptr;
+
// Ok, if we got here, both predecessors end with an unconditional branch to
// BB. Don't panic! If both blocks only have a single (identical)
// predecessor, and THAT is a conditional branch, then we're all ok!
@@ -1811,10 +1815,9 @@ BranchInst *llvm::GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,
return nullptr;
// Otherwise, if this is a conditional branch, then we can use it!
- BranchInst *BI = dyn_cast<BranchInst>(CommonPred->getTerminator());
+ CondBrInst *BI = dyn_cast<CondBrInst>(CommonPred->getTerminator());
if (!BI) return nullptr;
- assert(BI->isConditional() && "Two successors but not conditional?");
if (BI->getSuccessor(0) == Pred1) {
IfTrue = Pred1;
IfFalse = Pred2;
@@ -1825,7 +1828,7 @@ BranchInst *llvm::GetIfCondition(BasicBlock *BB, BasicBlock *&IfTrue,
return BI;
}
-void llvm::InvertBranch(BranchInst *PBI, IRBuilderBase &Builder) {
+void llvm::InvertBranch(CondBrInst *PBI, IRBuilderBase &Builder) {
Value *NewCond = PBI->getCondition();
// If this is a "cmp" instruction, only used for branching (and nowhere
// else), then we can simply invert the predicate.
@@ -1842,8 +1845,7 @@ void llvm::InvertBranch(BranchInst *PBI, IRBuilderBase &Builder) {
bool llvm::hasOnlySimpleTerminator(const Function &F) {
for (auto &BB : F) {
auto *Term = BB.getTerminator();
- if (!(isa<ReturnInst>(Term) || isa<UnreachableInst>(Term) ||
- isa<BranchInst>(Term)))
+ if (!isa<ReturnInst, UnreachableInst, UncondBrInst, CondBrInst>(Term))
return false;
}
return true;
diff --git a/llvm/lib/Transforms/Utils/FlattenCFG.cpp b/llvm/lib/Transforms/Utils/FlattenCFG.cpp
index 1d9408d6db433..1208fe182b880 100644
--- a/llvm/lib/Transforms/Utils/FlattenCFG.cpp
+++ b/llvm/lib/Transforms/Utils/FlattenCFG.cpp
@@ -412,7 +412,7 @@ bool FlattenCFGOpt::MergeIfRegion(BasicBlock *BB, IRBuilder<> &Builder) {
return false;
BasicBlock *IfTrue2, *IfFalse2;
- BranchInst *DomBI2 = GetIfCondition(BB, IfTrue2, IfFalse2);
+ CondBrInst *DomBI2 = GetIfCondition(BB, IfTrue2, IfFalse2);
if (!DomBI2)
return false;
Instruction *CInst2 = dyn_cast<Instruction>(DomBI2->getCondition());
@@ -424,7 +424,7 @@ bool FlattenCFGOpt::MergeIfRegion(BasicBlock *BB, IRBuilder<> &Builder) {
return false;
BasicBlock *IfTrue1, *IfFalse1;
- BranchInst *DomBI1 = GetIfCondition(SecondEntryBlock, IfTrue1, IfFalse1);
+ CondBrInst *DomBI1 = GetIfCondition(SecondEntryBlock, IfTrue1, IfFalse1);
if (!DomBI1)
return false;
Instruction *CInst1 = dyn_cast<Instruction>(DomBI1->getCondition());
@@ -485,7 +485,7 @@ bool FlattenCFGOpt::MergeIfRegion(BasicBlock *BB, IRBuilder<> &Builder) {
// Merge \param SecondEntryBlock into \param FirstEntryBlock.
FirstEntryBlock->back().eraseFromParent();
FirstEntryBlock->splice(FirstEntryBlock->end(), SecondEntryBlock);
- BranchInst *PBI = cast<BranchInst>(FirstEntryBlock->getTerminator());
+ CondBrInst *PBI = cast<CondBrInst>(FirstEntryBlock->getTerminator());
assert(PBI->getCondition() == CInst2);
BasicBlock *SaveInsertBB = Builder.GetInsertBlock();
BasicBlock::iterator SaveInsertPt = Builder.GetInsertPoint();
diff --git a/llvm/lib/Transforms/Utils/GuardUtils.cpp b/llvm/lib/Transforms/Utils/GuardUtils.cpp
index 46ad951d0a812..299518ebb630e 100644
--- a/llvm/lib/Transforms/Utils/GuardUtils.cpp
+++ b/llvm/lib/Transforms/Utils/GuardUtils.cpp
@@ -36,7 +36,7 @@ void llvm::makeGuardControlFlowExplicit(Function *DeoptIntrinsic,
auto *DeoptBlockTerm =
SplitBlockAndInsertIfThen(Guard->getArgOperand(0), Guard, true);
- auto *CheckBI = cast<BranchInst>(CheckBB->getTerminator());
+ auto *CheckBI = cast<CondBrInst>(CheckBB->getTerminator());
// SplitBlockAndInsertIfThen inserts control flow that branches to
// DeoptBlockTerm if the condition is true. We want the opposite.
@@ -78,8 +78,7 @@ void llvm::makeGuardControlFlowExplicit(Function *DeoptIntrinsic,
}
}
-
-void llvm::widenWidenableBranch(BranchInst *WidenableBR, Value *NewCond) {
+void llvm::widenWidenableBranch(CondBrInst *WidenableBR, Value *NewCond) {
assert(isWidenableBranch(WidenableBR) && "precondition");
// The tempting trivially option is to produce something like this:
@@ -105,7 +104,7 @@ void llvm::widenWidenableBranch(BranchInst *WidenableBR, Value *NewCond) {
assert(isWidenableBranch(WidenableBR) && "preserve widenabiliy");
}
-void llvm::setWidenableBranchCond(BranchInst *WidenableBR, Value *NewCond) {
+void llvm::setWidenableBranchCond(CondBrInst *WidenableBR, Value *NewCond) {
assert(isWidenableBranch(WidenableBR) && "precondition");
Use *C, *WC;
diff --git a/llvm/lib/Transforms/Utils/LoopConstrainer.cpp b/llvm/lib/Transforms/Utils/LoopConstrainer.cpp
index fff6a7bca26a3..aa2f842a39728 100644
--- a/llvm/lib/Transforms/Utils/LoopConstrainer.cpp
+++ b/llvm/lib/Transforms/Utils/LoopConstrainer.cpp
@@ -156,8 +156,8 @@ LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L,
return std::nullopt;
}
- BranchInst *LatchBr = dyn_cast<BranchInst>(Latch->getTerminator());
- if (!LatchBr || LatchBr->isUnconditional()) {
+ CondBrInst *LatchBr = dyn_cast<CondBrInst>(Latch->getTerminator());
+ if (!LatchBr) {
FailureReason = "latch terminator not conditional branch";
return std::nullopt;
}
@@ -603,7 +603,7 @@ LoopConstrainer::RewrittenRangeInfo LoopConstrainer::changeIterationSpaceEnd(
RRI.PseudoExit = BasicBlock::Create(Ctx, Twine(LS.Tag) + ".pseudo.exit", &F,
BBInsertLocation);
- BranchInst *PreheaderJump = cast<BranchInst>(Preheader->getTerminator());
+ Instruction *PreheaderJump = Preheader->getTerminator();
bool Increasing = LS.IndVarIncreasing;
bool IsSignedPredicate = LS.IsSignedPredicate;
@@ -647,8 +647,8 @@ LoopConstrainer::RewrittenRangeInfo LoopConstrainer::changeIterationSpaceEnd(
Value *IterationsLeft = B.CreateICmp(Pred, IndVarBase, LoopExitAt);
B.CreateCondBr(IterationsLeft, RRI.PseudoExit, LS.LatchExit);
- BranchInst *BranchToContinuation =
- BranchInst::Create(ContinuationBlock, RRI.PseudoExit);
+ UncondBrInst *BranchToContinuation =
+ UncondBrInst::Create(ContinuationBlock, RRI.PseudoExit);
// We emit PHI nodes into `RRI.PseudoExit' that compute the "latest" value of
// each of the PHI nodes in the loop header. This feeds into the initial
@@ -690,7 +690,7 @@ BasicBlock *LoopConstrainer::createPreheader(const LoopStructure &LS,
BasicBlock *OldPreheader,
const char *Tag) const {
BasicBlock *Preheader = BasicBlock::Create(Ctx, Tag, &F, LS.Header);
- BranchInst::Create(LS.Header, Preheader);
+ UncondBrInst::Create(LS.Header, Preheader);
LS.Header->replacePhiUsesWith(OldPreheader, Preheader);
diff --git a/llvm/lib/Transforms/Utils/LoopSimplify.cpp b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
index 798a11af774a2..3b11fa39d01a6 100644
--- a/llvm/lib/Transforms/Utils/LoopSimplify.cpp
+++ b/llvm/lib/Transforms/Utils/LoopSimplify.cpp
@@ -629,8 +629,9 @@ static bool simplifyOneLoop(Loop *L, SmallVectorImpl<Loop *> &Worklist,
if (HasUniqueExitBlock()) {
for (BasicBlock *ExitingBlock : ExitingBlocks) {
if (!ExitingBlock->getSinglePredecessor()) continue;
- BranchInst *BI = dyn_cast<BranchInst>(ExitingBlock->getTerminator());
- if (!BI || !BI->isConditional()) continue;
+ CondBrInst *BI = dyn_cast<CondBrInst>(ExitingBlock->getTerminator());
+ if (!BI)
+ continue;
CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition());
if (!CI || CI->getParent() != ExitingBlock) continue;
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
index 0cfd4a59bb4e0..68751cf95bc7a 100644
--- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
@@ -376,7 +376,7 @@ static void ConnectEpilog(Loop *L, Value *ModVal, BasicBlock *NewExit,
MDBuilder MDB(B.getContext());
BranchWeights = MDB.createBranchWeights(1, Count - 1);
}
- BranchInst *RemainderLoopGuard =
+ CondBrInst *RemainderLoopGuard =
B.CreateCondBr(BrLoopExit, EpilogPreHeader, Exit, BranchWeights);
if (!OriginalLoopProb.isUnknown()) {
setBranchProbability(RemainderLoopGuard,
@@ -454,7 +454,7 @@ static Loop *CloneLoopBlocks(Loop *L, Value *NewIter,
// Subtle: NewIter can be 0 if we wrapped when computing the trip count,
// thus we must compare the post-increment (wrapping) value.
BasicBlock *FirstLoopBB = cast<BasicBlock>(VMap[Header]);
- BranchInst *LatchBR = cast<BranchInst>(NewBB->getTerminator());
+ CondBrInst *LatchBR = cast<CondBrInst>(NewBB->getTerminator());
IRBuilder<> Builder(LatchBR);
PHINode *NewIdx =
PHINode::Create(NewIter->getType(), 2, suffix + ".iter");
@@ -484,7 +484,7 @@ static Loop *CloneLoopBlocks(Loop *L, Value *NewIter,
MDBuilder MDB(Builder.getContext());
BranchWeights = MDB.createBranchWeights(BackEdgeWeight, ExitWeight);
}
- BranchInst *RemainderLoopLatch =
+ CondBrInst *RemainderLoopLatch =
Builder.CreateCondBr(IdxCmp, FirstLoopBB, InsertBot, BranchWeights);
if (!OriginalLoopProb.isUnknown() && UseEpilogRemainder) {
// Compute the total frequency of the original loop body from the
@@ -693,9 +693,9 @@ bool llvm::UnrollRuntimeLoopRemainder(
BasicBlock *Latch = L->getLoopLatch();
BasicBlock *Header = L->getHeader();
- BranchInst *LatchBR = cast<BranchInst>(Latch->getTerminator());
+ CondBrInst *LatchBR = dyn_cast<CondBrInst>(Latch->getTerminator());
- if (!LatchBR || LatchBR->isUnconditional()) {
+ if (!LatchBR) {
// The loop-rotate pass can be helpful to avoid this in many cases.
LLVM_DEBUG(
dbgs()
@@ -770,7 +770,7 @@ bool llvm::UnrollRuntimeLoopRemainder(
}
BasicBlock *PreHeader = L->getLoopPreheader();
- BranchInst *PreHeaderBR = cast<BranchInst>(PreHeader->getTerminator());
+ Instruction *PreHeaderBR = PreHeader->getTerminator();
SCEVExpander Expander(*SE, "loop-unroll");
if (!AllowExpensiveTripCount &&
Expander.isHighCostExpansion(TripCountSC, L, SCEVExpansionBudget, TTI,
@@ -861,7 +861,7 @@ bool llvm::UnrollRuntimeLoopRemainder(
// in epilog case and around prolog remainder loop in prolog case.
// Compute the number of extra iterations required, which is:
// extra iterations = run-time trip count % loop unroll factor
- PreHeaderBR = cast<BranchInst>(PreHeader->getTerminator());
+ PreHeaderBR = PreHeader->getTerminator();
IRBuilder<> B(PreHeaderBR);
Value *TripCount = Expander.expandCodeFor(TripCountSC, TripCountSC->getType(),
PreHeaderBR);
@@ -902,7 +902,7 @@ bool llvm::UnrollRuntimeLoopRemainder(
MDBuilder MDB(B.getContext());
BranchWeights = MDB.createBranchWeights(EpilogHeaderWeights);
}
- BranchInst *UnrollingLoopGuard =
+ CondBrInst *UnrollingLoopGuard =
B.CreateCondBr(BranchVal, RemainderLoop, UnrollingLoop, BranchWeights);
if (!OriginalLoopProb.isUnknown() && UseEpilogRemainder) {
// The original loop's first iteration always happens. Compute the
@@ -1050,7 +1050,7 @@ bool llvm::UnrollRuntimeLoopRemainder(
// thus we must compare the post-increment (wrapping) value.
IRBuilder<> B2(NewPreHeader->getTerminator());
Value *TestVal = B2.CreateSub(TripCount, ModVal, "unroll_iter");
- BranchInst *LatchBR = cast<BranchInst>(Latch->getTerminator());
+ CondBrInst *LatchBR = cast<CondBrInst>(Latch->getTerminator());
PHINode *NewIdx = PHINode::Create(TestVal->getType(), 2, "niter");
NewIdx->insertBefore(Header->getFirstNonPHIIt());
B2.SetInsertPoint(LatchBR);
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 2d7cb2a035957..c68f478339090 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -730,14 +730,12 @@ void llvm::breakLoopBackedge(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
// Update the CFG and domtree. We chose to special case a couple of
// of common cases for code quality and test readability reasons.
[&]() -> void {
- if (auto *BI = dyn_cast<BranchInst>(Latch->getTerminator())) {
- if (!BI->isConditional()) {
- DomTreeUpdater DTU(&DT, DomTreeUpdater::UpdateStrategy::Eager);
- (void)changeToUnreachable(BI, /*PreserveLCSSA*/ true, &DTU,
- MSSAU.get());
- return;
- }
-
+ if (auto *BI = dyn_cast<UncondBrInst>(Latch->getTerminator())) {
+ DomTreeUpdater DTU(&DT, DomTreeUpdater::UpdateStrategy::Eager);
+ (void)changeToUnreachable(BI, /*PreserveLCSSA*/ true, &DTU, MSSAU.get());
+ return;
+ }
+ if (auto *BI = dyn_cast<CondBrInst>(Latch->getTerminator())) {
// Conditional latch/exit - note that latch can be shared by inner
// and outer loop so the other target doesn't need to an exit
if (L->isLoopExiting(Latch)) {
@@ -793,13 +791,13 @@ void llvm::breakLoopBackedge(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
/// Checks if \p L has an exiting latch branch. There may also be other
/// exiting blocks. Returns branch instruction terminating the loop
/// latch if above check is successful, nullptr otherwise.
-static BranchInst *getExpectedExitLoopLatchBranch(Loop *L) {
+static CondBrInst *getExpectedExitLoopLatchBranch(Loop *L) {
BasicBlock *Latch = L->getLoopLatch();
if (!Latch)
return nullptr;
- BranchInst *LatchBR = dyn_cast<BranchInst>(Latch->getTerminator());
- if (!LatchBR || LatchBR->getNumSuccessors() != 2 || !L->isLoopExiting(Latch))
+ CondBrInst *LatchBR = dyn_cast<CondBrInst>(Latch->getTerminator());
+ if (!LatchBR || !L->isLoopExiting(Latch))
return nullptr;
assert((LatchBR->getSuccessor(0) == L->getHeader() ||
@@ -827,7 +825,7 @@ static std::optional<unsigned> estimateLoopTripCount(Loop *L) {
// ignoring other exiting blocks. This can overestimate the trip count
// if we exit through another exit, but can never underestimate it.
// TODO: incorporate information from other exits
- BranchInst *ExitingBranch = getExpectedExitLoopLatchBranch(L);
+ CondBrInst *ExitingBranch = getExpectedExitLoopLatchBranch(L);
if (!ExitingBranch) {
LLVM_DEBUG(dbgs() << "estimateLoopTripCount: Failed to find exiting "
<< "latch branch of required form in " << DbgLoop(L)
@@ -895,7 +893,7 @@ llvm::getLoopEstimatedTripCount(Loop *L,
// - To satsify the condition for the outer loop, the latch must have a third
// successor that is an exit for the outer loop. But that violates the
// condition for both loops.
- BranchInst *ExitingBranch = getExpectedExitLoopLatchBranch(L);
+ CondBrInst *ExitingBranch = getExpectedExitLoopLatchBranch(L);
if (!ExitingBranch)
return std::nullopt;
@@ -952,7 +950,7 @@ bool llvm::setLoopEstimatedTripCount(
//
// FIXME: See comments in getLoopEstimatedTripCount for why this is required
// here regardless of EstimatedLoopInvocationWeight.
- BranchInst *LatchBranch = getExpectedExitLoopLatchBranch(L);
+ CondBrInst *LatchBranch = getExpectedExitLoopLatchBranch(L);
if (!LatchBranch)
return false;
@@ -990,7 +988,7 @@ bool llvm::setLoopEstimatedTripCount(
}
BranchProbability llvm::getLoopProbability(Loop *L) {
- BranchInst *LatchBranch = getExpectedExitLoopLatchBranch(L);
+ CondBrInst *LatchBranch = getExpectedExitLoopLatchBranch(L);
if (!LatchBranch)
return BranchProbability::getUnknown();
bool FirstTargetIsLoop = LatchBranch->getSuccessor(0) == L->getHeader();
@@ -998,17 +996,16 @@ BranchProbability llvm::getLoopProbability(Loop *L) {
}
bool llvm::setLoopProbability(Loop *L, BranchProbability P) {
- BranchInst *LatchBranch = getExpectedExitLoopLatchBranch(L);
+ CondBrInst *LatchBranch = getExpectedExitLoopLatchBranch(L);
if (!LatchBranch)
return false;
bool FirstTargetIsLoop = LatchBranch->getSuccessor(0) == L->getHeader();
- return setBranchProbability(LatchBranch, P, FirstTargetIsLoop);
+ setBranchProbability(LatchBranch, P, FirstTargetIsLoop);
+ return true;
}
-BranchProbability llvm::getBranchProbability(BranchInst *B,
+BranchProbability llvm::getBranchProbability(CondBrInst *B,
bool ForFirstTarget) {
- if (B->getNumSuccessors() != 2)
- return BranchProbability::getUnknown();
uint64_t Weight0, Weight1;
if (!extractBranchWeights(*B, Weight0, Weight1))
return BranchProbability::getUnknown();
@@ -1054,17 +1051,14 @@ BranchProbability llvm::getBranchProbability(BasicBlock *Src, BasicBlock *Dst) {
return BranchProbability(Numerator, Total);
}
-bool llvm::setBranchProbability(BranchInst *B, BranchProbability P,
+void llvm::setBranchProbability(CondBrInst *B, BranchProbability P,
bool ForFirstTarget) {
- if (B->getNumSuccessors() != 2)
- return false;
BranchProbability Prob0 = P;
BranchProbability Prob1 = P.getCompl();
if (!ForFirstTarget)
std::swap(Prob0, Prob1);
setBranchWeights(*B, {Prob0.getNumerator(), Prob1.getNumerator()},
/*IsExpected=*/false);
- return true;
}
bool llvm::hasIterationCountInvariantInParent(Loop *InnerLoop,
@@ -2244,8 +2238,8 @@ Value *llvm::addDiffRuntimeChecks(
std::optional<IVConditionInfo>
llvm::hasPartialIVCondition(const Loop &L, unsigned MSSAThreshold,
const MemorySSA &MSSA, AAResults &AA) {
- auto *TI = dyn_cast<BranchInst>(L.getHeader()->getTerminator());
- if (!TI || !TI->isConditional())
+ auto *TI = dyn_cast<CondBrInst>(L.getHeader()->getTerminator());
+ if (!TI)
return {};
auto *CondI = dyn_cast<Instruction>(TI->getCondition());
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 809856fe9f1fd..105ba9151d8f3 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3737,7 +3737,7 @@ static bool foldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
BasicBlock *BB = PN->getParent();
BasicBlock *IfTrue, *IfFalse;
- BranchInst *DomBI = GetIfCondition(BB, IfTrue, IfFalse);
+ CondBrInst *DomBI = GetIfCondition(BB, IfTrue, IfFalse);
if (!DomBI)
return false;
Value *IfCond = DomBI->getCondition();
@@ -4000,7 +4000,7 @@ shouldFoldCondBranchesToCommonDestination(BranchInst *BI, BranchInst *PBI,
return std::nullopt;
}
-static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
+static bool performBranchToCommonDestFolding(CondBrInst *BI, CondBrInst *PBI,
DomTreeUpdater *DTU,
MemorySSAUpdater *MSSAU,
const TargetTransformInfo *TTI) {
@@ -4049,7 +4049,7 @@ static bool performBranchToCommonDestFolding(BranchInst *BI, BranchInst *PBI,
MDWeights.push_back(PredTrueWeight * SuccTrueWeight);
// FalseWeight is FalseWeight for PBI * TotalWeight for BI +
// TrueWeight for PBI * FalseWeight for BI.
- // We assume that total weights of a BranchInst can fit into 32 bits.
+ // We assume that total weights of a CondBrInst can fit into 32 bits.
// Therefore, we will not have overflow using 64-bit arithmetic.
MDWeights.push_back(PredFalseWeight * (SuccFalseWeight + SuccTrueWeight) +
PredTrueWeight * SuccFalseWeight);
@@ -4124,15 +4124,10 @@ static bool isVectorOp(Instruction &I) {
/// If this basic block is simple enough, and if a predecessor branches to us
/// and one of our successors, fold the block into the predecessor and use
/// logical operations to pick the right destination.
-bool llvm::foldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
+bool llvm::foldBranchToCommonDest(CondBrInst *BI, DomTreeUpdater *DTU,
MemorySSAUpdater *MSSAU,
const TargetTransformInfo *TTI,
unsigned BonusInstThreshold) {
- // If this block ends with an unconditional branch,
- // let speculativelyExecuteBB() deal with it.
- if (!BI->isConditional())
- return false;
-
BasicBlock *BB = BI->getParent();
TargetTransformInfo::TargetCostKind CostKind =
BB->getParent()->hasMinSize() ? TargetTransformInfo::TCK_CodeSize
@@ -4241,7 +4236,7 @@ bool llvm::foldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
// Ok, we have the budget. Perform the transformation.
for (BasicBlock *PredBlock : Preds) {
- auto *PBI = cast<BranchInst>(PredBlock->getTerminator());
+ auto *PBI = cast<CondBrInst>(PredBlock->getTerminator());
return performBranchToCommonDestFolding(BI, PBI, DTU, MSSAU, TTI);
}
return false;
@@ -8495,14 +8490,6 @@ bool SimplifyCFGOpt::simplifyUncondBranch(UncondBrInst *BI,
return true;
}
- // If this basic block is ONLY a compare and a branch, and if a predecessor
- // branches to us and our successor, fold the comparison into the
- // predecessor and use logical operations to update the incoming value
- // for PHI nodes in common successor.
- if (Options.SpeculateBlocks &&
- foldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
- Options.BonusInstThreshold))
- return requestResimplify();
return false;
}
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTestBase.h b/llvm/unittests/Transforms/Vectorize/VPlanTestBase.h
index 3a585e958c3f3..2322cf340ff07 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTestBase.h
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTestBase.h
@@ -96,7 +96,7 @@ class VPlanTestBase : public testing::Test {
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), false);
F = Function::Create(FTy, GlobalValue::ExternalLinkage, "f", M.get());
ScalarHeader = BasicBlock::Create(C, "scalar.header", F);
- BranchInst::Create(ScalarHeader, ScalarHeader);
+ UncondBrInst::Create(ScalarHeader, ScalarHeader);
}
VPlan &getPlan() {
More information about the llvm-commits
mailing list