[llvm-branch-commits] [llvm] 4fc169f - [SimplifyCFG] removeUnreachableBlocks() already knows how to preserve DomTree

Roman Lebedev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Dec 16 14:08:25 PST 2020


Author: Roman Lebedev
Date: 2020-12-17T01:03:49+03:00
New Revision: 4fc169f6644fa60be543fb46b4b94b20a035ca40

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

LOG: [SimplifyCFG] removeUnreachableBlocks() already knows how to preserve DomTree

... so just ensure that we pass DomTreeUpdater it into it.

Apparently, there were no dedicated tests just for that functionality,
so i'm adding one here.

Added: 
    llvm/test/Transforms/SimplifyCFG/unreachable-selfloop.ll

Modified: 
    llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
index deb6494f6b07..9444df8039ad 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -25,6 +25,7 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/AssumptionCache.h"
 #include "llvm/Analysis/CFG.h"
+#include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/IR/Attributes.h"
@@ -195,7 +196,9 @@ static bool iterativelySimplifyCFG(Function &F, const TargetTransformInfo &TTI,
 static bool simplifyFunctionCFGImpl(Function &F, const TargetTransformInfo &TTI,
                                     DominatorTree *DT,
                                     const SimplifyCFGOptions &Options) {
-  bool EverChanged = removeUnreachableBlocks(F);
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
+
+  bool EverChanged = removeUnreachableBlocks(F, DT ? &DTU : nullptr);
   EverChanged |= mergeEmptyReturnBlocks(F);
   EverChanged |= iterativelySimplifyCFG(F, TTI, Options);
 
@@ -207,12 +210,12 @@ static bool simplifyFunctionCFGImpl(Function &F, const TargetTransformInfo &TTI,
   // iterate between the two optimizations.  We structure the code like this to
   // avoid rerunning iterativelySimplifyCFG if the second pass of
   // removeUnreachableBlocks doesn't do anything.
-  if (!removeUnreachableBlocks(F))
+  if (!removeUnreachableBlocks(F, DT ? &DTU : nullptr))
     return true;
 
   do {
     EverChanged = iterativelySimplifyCFG(F, TTI, Options);
-    EverChanged |= removeUnreachableBlocks(F);
+    EverChanged |= removeUnreachableBlocks(F, DT ? &DTU : nullptr);
   } while (EverChanged);
 
   return true;

diff  --git a/llvm/test/Transforms/SimplifyCFG/unreachable-selfloop.ll b/llvm/test/Transforms/SimplifyCFG/unreachable-selfloop.ll
new file mode 100644
index 000000000000..3119e3f189b9
--- /dev/null
+++ b/llvm/test/Transforms/SimplifyCFG/unreachable-selfloop.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
+
+define void @fn() {
+; CHECK-LABEL: @fn(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    ret void
+;
+entry:
+  ret void
+
+unreachable_bb0:
+  br label %unreachable_bb1
+unreachable_bb1:
+  br label %unreachable_bb0
+}


        


More information about the llvm-branch-commits mailing list