Skip to content

Commit 9e10655

Browse files
fixup! refactor for general approach
1 parent 4e56067 commit 9e10655

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7455,7 +7455,7 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
74557455
// FIXME: Relax that the terminator is a BranchInst by checking for equality
74567456
// on other kinds of terminators.
74577457
Instruction *T = BB->getTerminator();
7458-
if (T && BB->size() == 1 && isa<BranchInst>(T))
7458+
if (T && isa<BranchInst>(T))
74597459
BBs.insert(BB);
74607460
}
74617461

@@ -7491,6 +7491,16 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
74917491
return true;
74927492
};
74937493

7494+
auto IsBBEqualTo = [&IsBranchEq](BasicBlock *A, BasicBlock *B) {
7495+
// FIXME: Support more than just a single BranchInst. One way we could do
7496+
// this is by taking a hashing approach.
7497+
if (A->size() != 1 || B->size() != 1)
7498+
return false;
7499+
7500+
return IsBranchEq(cast<BranchInst>(A->getTerminator()),
7501+
cast<BranchInst>(B->getTerminator()));
7502+
};
7503+
74947504
// Construct a map from candidate basic block to an equivalent basic block
74957505
// to replace it with. All equivalent basic blocks should be replaced with
74967506
// the same basic block. To do this, if there is no equivalent BB in the map,
@@ -7502,8 +7512,7 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
75027512
for (BasicBlock *BB : BBs) {
75037513
bool Inserted = false;
75047514
for (auto KV : ReplaceWith) {
7505-
if (IsBranchEq(cast<BranchInst>(BB->getTerminator()),
7506-
cast<BranchInst>(KV.first->getTerminator()))) {
7515+
if (IsBBEqualTo(BB, KV.first)) {
75077516
ReplaceWith[BB] = KV.first;
75087517
Inserted = true;
75097518
break;

0 commit comments

Comments
 (0)