[llvm] r281653 - [GlobalOpt] Dead Eliminate declarations
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 15 13:26:27 PDT 2016
Author: mehdi_amini
Date: Thu Sep 15 15:26:27 2016
New Revision: 281653
URL: http://llvm.org/viewvc/llvm-project?rev=281653&view=rev
Log:
[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!).
Added:
llvm/trunk/test/Transforms/GlobalOpt/deaddeclaration.ll
Modified:
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=281653&r1=281652&r2=281653&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Thu Sep 15 15:26:27 2016
@@ -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)
Added: llvm/trunk/test/Transforms/GlobalOpt/deaddeclaration.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalOpt/deaddeclaration.ll?rev=281653&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalOpt/deaddeclaration.ll (added)
+++ llvm/trunk/test/Transforms/GlobalOpt/deaddeclaration.ll Thu Sep 15 15:26:27 2016
@@ -0,0 +1,7 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+
+; CHECK-NOT: aa
+; CHECK-NOT: bb
+
+declare void @aa()
+ at bb = external global i8
More information about the llvm-commits
mailing list