1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

Reapply [GlobalOpt] Remove unreachable blocks before optimizing a function.

This commit reapplies r307215 now that we found out and fixed
the cause of the cfi test failure (in r307871).

llvm-svn: 307920
This commit is contained in:
Davide Italiano 2017-07-13 15:40:59 +00:00
parent fe7144fbfd
commit 2fbf9c5782
2 changed files with 35 additions and 0 deletions

View File

@ -2026,6 +2026,24 @@ OptimizeFunctions(Module &M, TargetLibraryInfo *TLI,
continue;
}
// LLVM's definition of dominance allows instructions that are cyclic
// in unreachable blocks, e.g.:
// %pat = select i1 %condition, @global, i16* %pat
// because any instruction dominates an instruction in a block that's
// not reachable from entry.
// So, remove unreachable blocks from the function, because a) there's
// no point in analyzing them and b) GlobalOpt should otherwise grow
// some more complicated logic to break these cycles.
// Removing unreachable blocks might invalidate the dominator so we
// recalculate it.
if (!F->isDeclaration()) {
if (removeUnreachableBlocks(*F)) {
auto &DT = LookupDomTree(*F);
DT.recalculate(*F);
Changed = true;
}
}
Changed |= processGlobal(*F, TLI, LookupDomTree);
if (!F->hasLocalLinkage())

View File

@ -0,0 +1,17 @@
; RUN: opt -S -globalopt %s | FileCheck %s
; CHECK-LABEL: define void @beth
; CHECK-NEXT: entry:
; CHECK-NEXT: ret void
; CHEC-NEXT: }
@glob = external global i16, align 1
define void @beth() {
entry:
ret void
notreachable:
%patatino = select i1 undef, i16* @glob, i16* %patatino
br label %notreachable
}