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

Roman Lebedev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 29 13:53:09 PST 2020


Author: Roman Lebedev
Date: 2020-12-30T00:48:10+03:00
New Revision: fe9bdd962152d6b3d1203f2b6129df122c462599

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

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

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/test/Transforms/SimplifyCFG/InfLoop.ll
    llvm/test/Transforms/SimplifyCFG/implied-cond-matching-imm.ll
    llvm/test/Transforms/SimplifyCFG/iterative-simplify.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 7b08b95356fb..41af29b82791 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -970,12 +970,15 @@ bool SimplifyCFGOpt::SimplifyEqualityComparisonWithOnlyPredecessor(
   if (!TheRealDest)
     TheRealDest = ThisDef;
 
+  SmallVector<DominatorTree::UpdateType, 2> Updates;
+
   // Remove PHI node entries for dead edges.
   BasicBlock *CheckEdge = TheRealDest;
   for (BasicBlock *Succ : successors(TIBB))
-    if (Succ != CheckEdge)
+    if (Succ != CheckEdge) {
       Succ->removePredecessor(TIBB);
-    else
+      Updates.push_back({DominatorTree::Delete, TIBB, Succ});
+    } else
       CheckEdge = nullptr;
 
   // Insert the new branch.
@@ -987,6 +990,8 @@ bool SimplifyCFGOpt::SimplifyEqualityComparisonWithOnlyPredecessor(
                     << "\n");
 
   EraseTerminatorAndDCECond(TI);
+  if (DTU)
+    DTU->applyUpdatesPermissive(Updates);
   return true;
 }
 

diff  --git a/llvm/test/Transforms/SimplifyCFG/InfLoop.ll b/llvm/test/Transforms/SimplifyCFG/InfLoop.ll
index a56076e42ce1..32c6b0353286 100644
--- a/llvm/test/Transforms/SimplifyCFG/InfLoop.ll
+++ b/llvm/test/Transforms/SimplifyCFG/InfLoop.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -disable-output
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -disable-output
 ; END.
 
 target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"

diff  --git a/llvm/test/Transforms/SimplifyCFG/implied-cond-matching-imm.ll b/llvm/test/Transforms/SimplifyCFG/implied-cond-matching-imm.ll
index 60ef81365982..d7f5694ad737 100644
--- a/llvm/test/Transforms/SimplifyCFG/implied-cond-matching-imm.ll
+++ b/llvm/test/Transforms/SimplifyCFG/implied-cond-matching-imm.ll
@@ -1,4 +1,4 @@
-; RUN: opt %s -S -simplifycfg | FileCheck %s
+; RUN: opt %s -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s
 
 ; cmp1 implies cmp2 is false
 ; CHECK-LABEL: @test1

diff  --git a/llvm/test/Transforms/SimplifyCFG/iterative-simplify.ll b/llvm/test/Transforms/SimplifyCFG/iterative-simplify.ll
index 60728b9a9578..ef2482134e7d 100644
--- a/llvm/test/Transforms/SimplifyCFG/iterative-simplify.ll
+++ b/llvm/test/Transforms/SimplifyCFG/iterative-simplify.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | not grep bb17
+; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | not grep bb17
 ; PR1786
 
 define i32 @main() {


        


More information about the llvm-branch-commits mailing list