[PATCH] D27560: Always run GlobalDCE at O0
Mehdi AMINI via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 7 18:22:44 PST 2016
mehdi_amini created this revision.
mehdi_amini added a reviewer: chandlerc.
mehdi_amini added subscribers: llvm-commits, dexonsmith.
Clang can emit unreachable call-graph from valid C++ code. There
is no point keeping this into the binary, and also sometimes the
generated code is broken and does not link, for example:
#include <iostream>
#include <string>
namespace {
struct VA {
};
struct A : virtual public VA {
A() {
static bool b = false;
std::string str;
}
};
}
int main(int argc, char* argv[]) {
A::A a;
}
See: http://lists.llvm.org/pipermail/cfe-dev/2016-October/051152.html
https://reviews.llvm.org/D27560
Files:
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/test/Other/GlobalDCE_at_O0.ll
Index: llvm/test/Other/GlobalDCE_at_O0.ll
===================================================================
--- /dev/null
+++ llvm/test/Other/GlobalDCE_at_O0.ll
@@ -0,0 +1,7 @@
+; RUN: opt < %s -O0 -S | FileCheck %s
+
+; CHECK-NOT: @test1
+
+define internal i32 @test1() {
+ ret i32 42
+}
Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
===================================================================
--- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -405,6 +405,9 @@
else if (!GlobalExtensions->empty() || !Extensions.empty())
MPM.add(createBarrierNoopPass());
+ // Clang may generate unreachable call-graphs, let's prune it.
+ MPM.add(createGlobalDCEPass());
+
if (PrepareForThinLTO)
// Rename anon globals to be able to export them in the summary.
MPM.add(createNameAnonGlobalPass());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27560.80706.patch
Type: text/x-patch
Size: 894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161208/d47dabf3/attachment.bin>
More information about the llvm-commits
mailing list