[llvm-branch-commits] [llvm] b7c463d - [SimplifyCFG] Teach FoldBranchToCommonDest() to preserve DomTree, part 2

Roman Lebedev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Dec 31 16:30:31 PST 2020


Author: Roman Lebedev
Date: 2021-01-01T03:25:23+03:00
New Revision: b7c463d7b8dda2c2b3e9a4db51f94dc94542ee68

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

LOG: [SimplifyCFG] Teach FoldBranchToCommonDest() to preserve DomTree, part 2

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/test/Transforms/SimplifyCFG/branch-fold.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index f1e6c50130c8..d081908c49e9 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3121,6 +3121,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
         assert(PBI_C->getType()->isIntegerTy(1));
         Instruction *MergedCond = nullptr;
         if (PBI->getSuccessor(0) == UniqueSucc) {
+          Updates.push_back(
+              {DominatorTree::Delete, PredBlock, PBI->getSuccessor(1)});
           // Create (PBI_Cond and PBI_C) or (!PBI_Cond and BI_Value)
           // PBI_C is true: PBI_Cond or (!PBI_Cond and BI_Value)
           //       is false: !PBI_Cond and BI_Value
@@ -3133,6 +3135,9 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
             MergedCond = cast<Instruction>(Builder.CreateBinOp(
                 Instruction::Or, PBI->getCondition(), MergedCond, "or.cond"));
         } else {
+          assert(PBI->getSuccessor(1) == UniqueSucc && "Unexpected branch");
+          Updates.push_back(
+              {DominatorTree::Delete, PredBlock, PBI->getSuccessor(0)});
           // Create (PBI_Cond and BI_Value) or (!PBI_Cond and PBI_C)
           // PBI_C is true: (PBI_Cond and BI_Value) or (!PBI_Cond)
           //       is false: PBI_Cond and BI_Value

diff  --git a/llvm/test/Transforms/SimplifyCFG/branch-fold.ll b/llvm/test/Transforms/SimplifyCFG/branch-fold.ll
index 7097dea424e1..a4ac23bada70 100644
--- a/llvm/test/Transforms/SimplifyCFG/branch-fold.ll
+++ b/llvm/test/Transforms/SimplifyCFG/branch-fold.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
 
 define void @test(i32* %P, i32* %Q, i1 %A, i1 %B) {
 ; CHECK: test


        


More information about the llvm-branch-commits mailing list