Skip to content

Commit

Permalink
[SimplifyCFG] removeUnreachableBlocks() already knows how to preserve…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
LebedevRI committed Dec 16, 2020
1 parent aa2009f commit 4fc169f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/Transforms/SimplifyCFG/unreachable-selfloop.ll
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 4fc169f

Please sign in to comment.