mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-10 22:46:25 +00:00
[GlobalOpt] Dead Eliminate declarations
GlobalOpt is already dead-code-eliminating global definitions. With this change it also takes care of declarations. Hopefully this should make it now a strict superset of GlobalDCE. This is important for LTO/ThinLTO as we don't want the linker to see "undefined reference" when it processes the input files: it could prevent proper internalization (or even load an extra file from a static archive, changing the behavior of the program!). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281653 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
26eccc1ec7
commit
12be25f90c
@ -1653,7 +1653,7 @@ static bool deleteIfDead(GlobalValue &GV,
|
||||
SmallSet<const Comdat *, 8> &NotDiscardableComdats) {
|
||||
GV.removeDeadConstantUsers();
|
||||
|
||||
if (!GV.isDiscardableIfUnused())
|
||||
if (!GV.isDiscardableIfUnused() && !GV.isDeclaration())
|
||||
return false;
|
||||
|
||||
if (const Comdat *C = GV.getComdat())
|
||||
@ -1662,7 +1662,7 @@ static bool deleteIfDead(GlobalValue &GV,
|
||||
|
||||
bool Dead;
|
||||
if (auto *F = dyn_cast<Function>(&GV))
|
||||
Dead = F->isDefTriviallyDead();
|
||||
Dead = (F->isDeclaration() && F->use_empty()) || F->isDefTriviallyDead();
|
||||
else
|
||||
Dead = GV.use_empty();
|
||||
if (!Dead)
|
||||
|
7
test/Transforms/GlobalOpt/deaddeclaration.ll
Normal file
7
test/Transforms/GlobalOpt/deaddeclaration.ll
Normal file
@ -0,0 +1,7 @@
|
||||
; RUN: opt < %s -globalopt -S | FileCheck %s
|
||||
|
||||
; CHECK-NOT: aa
|
||||
; CHECK-NOT: bb
|
||||
|
||||
declare void @aa()
|
||||
@bb = external global i8
|
Loading…
x
Reference in New Issue
Block a user