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

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

LOG: [SimplifyCFG] Teach tryToSimplifyUncondBranchWithICmpInIt() to preserve 
DomTree

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
    llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
    llvm/test/Transforms/SimplifyCFG/switch_create.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp 
b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index bf61d34f7322..f513db3783fb 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -4052,6 +4052,8 @@ bool 
SimplifyCFGOpt::tryToSimplifyUncondBranchWithICmpInIt(
   ICI->replaceAllUsesWith(DefaultCst);
   ICI->eraseFromParent();
 
+  SmallVector<DominatorTree::UpdateType, 2> Updates;
+
   // Okay, the switch goes to this block on a default value.  Add an edge from
   // the switch to the merge point on the compared value.
   BasicBlock *NewBB =
@@ -4065,13 +4067,17 @@ bool 
SimplifyCFGOpt::tryToSimplifyUncondBranchWithICmpInIt(
       SIW.setSuccessorWeight(0, *NewW);
     }
     SIW.addCase(Cst, NewBB, NewW);
+    Updates.push_back({DominatorTree::Insert, Pred, NewBB});
   }
 
   // NewBB branches to the phi block, add the uncond branch and the phi entry.
   Builder.SetInsertPoint(NewBB);
   Builder.SetCurrentDebugLocation(SI->getDebugLoc());
   Builder.CreateBr(SuccBlock);
+  Updates.push_back({DominatorTree::Insert, NewBB, SuccBlock});
   PHIUse->addIncoming(NewCst, NewBB);
+  if (DTU)
+    DTU->applyUpdatesPermissive(Updates);
   return true;
 }
 

diff  --git a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll 
b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
index 66a34bab3e5b..078d0aa2f1de 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-branchweights.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -simplifycfg -S -o - < %s | FileCheck %s
+; RUN: opt -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S -o - < 
%s | FileCheck %s
 
 declare void @helper(i32)
 

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll 
b/llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
index dc07eb20568d..cdc334e474b6 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch_create-custom-dl.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -simplifycfg < %s | FileCheck %s
+; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | 
FileCheck %s
 target datalayout="p:40:64:64:32"
 
 declare void @foo1()

diff  --git a/llvm/test/Transforms/SimplifyCFG/switch_create.ll 
b/llvm/test/Transforms/SimplifyCFG/switch_create.ll
index 10689a03c398..a4c84a66cafb 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch_create.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch_create.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -simplifycfg < %s | FileCheck %s
-; RUN: opt -S -data-layout="p:32:32-p1:16:16" -simplifycfg < %s | FileCheck 
-check-prefix=CHECK -check-prefix=DL %s
+; RUN: opt -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 < %s | 
FileCheck %s
+; RUN: opt -S -data-layout="p:32:32-p1:16:16" -simplifycfg 
-simplifycfg-require-and-preserve-domtree=1 < %s | FileCheck 
-check-prefix=CHECK -check-prefix=DL %s
 
 declare void @foo1()
 


        
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to