Skip to content

Commit aabed37

Browse files
committed
[NFCI-ish][SimplifyCFG] FoldBranchToCommonDest(): really don't deal with uncond branches
While we already ignore uncond branches, we could still potentially end up with a conditional branches with identical destinations due to the visitation order, or because we were called as an utility. But if we have such a disguised uncond branch, we still probably shouldn't deal with it here.
1 parent 0895b83 commit aabed37

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
27752775
unsigned BonusInstThreshold) {
27762776
// If this block ends with an unconditional branch,
27772777
// let SpeculativelyExecuteBB() deal with it.
2778-
if (!BI->isConditional())
2778+
if (!BI->isConditional() || is_splat(successors(BI)))
27792779
return false;
27802780

27812781
BasicBlock *BB = BI->getParent();
@@ -2863,7 +2863,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
28632863
// Check that we have two conditional branches. If there is a PHI node in
28642864
// the common successor, verify that the same value flows in from both
28652865
// blocks.
2866-
if (!PBI || PBI->isUnconditional() || !SafeToMergeTerminators(BI, PBI))
2866+
if (!PBI || PBI->isUnconditional() || is_splat(successors(PBI)) ||
2867+
!SafeToMergeTerminators(BI, PBI))
28672868
continue;
28682869

28692870
// Determine if the two branches share a common destination.

0 commit comments

Comments
 (0)