Skip to content

Commit 4190352

Browse files
fixup! only support unconditional branches
1 parent 32b627f commit 4190352

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7474,30 +7474,14 @@ template <> struct DenseMapInfo<const CaseHandleWrapper *> {
74747474
return LHS == RHS;
74757475

74767476
auto IsBranchEq = [](BranchInst *A, BranchInst *B) {
7477-
if (A->isConditional() != B->isConditional())
7478-
return false;
7479-
7480-
if (A->isConditional()) {
7481-
// If the conditions are instructions, check equality up to
7482-
// commutativity. Otherwise, check that the two Values are the same.
7483-
Value *AC = A->getCondition();
7484-
Value *BC = B->getCondition();
7485-
auto *ACI = dyn_cast<Instruction>(AC);
7486-
auto *BCI = dyn_cast<Instruction>(BC);
7477+
assert(A->isUnconditional() && B->isUnconditional() &&
7478+
"Only supporting unconditional branches for now");
7479+
assert(A->getNumSuccessors() == 1 && B->getNumSuccessors() == 1 &&
7480+
"Expected unconditional branches to have one successor");
74877481

7488-
if (ACI && BCI && !areIdenticalUpToCommutativity(ACI, BCI))
7489-
return false;
7490-
if ((!ACI || !BCI) && AC != BC)
7491-
return false;
7492-
}
7493-
7494-
if (A->getNumSuccessors() != B->getNumSuccessors())
7482+
if (A->getSuccessor(0) != B->getSuccessor(0))
74957483
return false;
74967484

7497-
for (unsigned I = 0; I < A->getNumSuccessors(); ++I)
7498-
if (A->getSuccessor(I) != B->getSuccessor(I))
7499-
return false;
7500-
75017485
return true;
75027486
};
75037487

@@ -7546,14 +7530,20 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
75467530
// SI need to be updated.
75477531
if (BB->hasNPredecessorsOrMore(2))
75487532
continue;
7549-
// FIXME: Relax that the terminator is a BranchInst by checking for equality
7550-
// on other kinds of terminators.
7533+
75517534
Instruction *T = BB->getTerminator();
7552-
if (!T || !isa<BranchInst>(T))
7535+
if (!T)
7536+
continue;
7537+
7538+
// FIXME: Relax that the terminator is a BranchInst by checking for equality
7539+
// on other kinds of terminators. We decide to only support unconditional
7540+
// branches for now for compile time reasons.
7541+
auto *BI = dyn_cast<BranchInst>(T);
7542+
if (!BI || BI->isConditional())
75537543
continue;
75547544

75557545
// Preprocess incoming PHI values for successors of BB.
7556-
for (BasicBlock *Succ : cast<BranchInst>(T)->successors()) {
7546+
for (BasicBlock *Succ : BI->successors()) {
75577547
for (PHINode &Phi : Succ->phis()) {
75587548
auto IncomingVals = PhiPredIVs.find(&Phi);
75597549
Value *Incoming = Phi.getIncomingValueForBlock(BB);

0 commit comments

Comments
 (0)