[llvm-branch-commits] [llvm] aabed37 - [NFCI-ish][SimplifyCFG] FoldBranchToCommonDest(): really don't deal with uncond branches

Roman Lebedev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 22 06:29:31 PST 2021


Author: Roman Lebedev
Date: 2021-01-22T17:23:10+03:00
New Revision: aabed3718ae25476c0f6b7e70c83ba4658f00e5c

URL: https://github.com/llvm/llvm-project/commit/aabed3718ae25476c0f6b7e70c83ba4658f00e5c
DIFF: https://github.com/llvm/llvm-project/commit/aabed3718ae25476c0f6b7e70c83ba4658f00e5c.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index d0028c013fa3..5ca8a0b33176 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2775,7 +2775,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
                                   unsigned BonusInstThreshold) {
   // If this block ends with an unconditional branch,
   // let SpeculativelyExecuteBB() deal with it.
-  if (!BI->isConditional())
+  if (!BI->isConditional() || is_splat(successors(BI)))
     return false;
 
   BasicBlock *BB = BI->getParent();
@@ -2863,7 +2863,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
     // Check that we have two conditional branches.  If there is a PHI node in
     // the common successor, verify that the same value flows in from both
     // blocks.
-    if (!PBI || PBI->isUnconditional() || !SafeToMergeTerminators(BI, PBI))
+    if (!PBI || PBI->isUnconditional() || is_splat(successors(PBI)) ||
+        !SafeToMergeTerminators(BI, PBI))
       continue;
 
     // Determine if the two branches share a common destination.


        


More information about the llvm-branch-commits mailing list