GlobalOpt: Don't swap private for internal linkage
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 1 Jul 2014 15:26:50 +0000 (15:26 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 1 Jul 2014 15:26:50 +0000 (15:26 +0000)
There were transforms whose *intent* was to downgrade the linkage of
external objects to have internal linkage.

However, it fired on things with private linkage as well.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212104 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/GlobalOpt.cpp
test/Transforms/GlobalOpt/2009-03-06-Anonymous.ll

index 63a6058b9693f996cc03cd097546677c5b262559..c1d0d3bcdb1758597ae06c0fc844ef2b251eea7e 100644 (file)
@@ -1908,7 +1908,7 @@ bool GlobalOpt::OptimizeFunctions(Module &M) {
   for (Module::iterator FI = M.begin(), E = M.end(); FI != E; ) {
     Function *F = FI++;
     // Functions without names cannot be referenced outside this module.
-    if (!F->hasName() && !F->isDeclaration())
+    if (!F->hasName() && !F->isDeclaration() && !F->hasLocalLinkage())
       F->setLinkage(GlobalValue::InternalLinkage);
     F->removeDeadConstantUsers();
     if (F->isDefTriviallyDead()) {
@@ -1953,7 +1953,7 @@ bool GlobalOpt::OptimizeGlobalVars(Module &M) {
        GVI != E; ) {
     GlobalVariable *GV = GVI++;
     // Global variables without names cannot be referenced outside this module.
-    if (!GV->hasName() && !GV->isDeclaration())
+    if (!GV->hasName() && !GV->isDeclaration() && !GV->hasLocalLinkage())
       GV->setLinkage(GlobalValue::InternalLinkage);
     // Simplify the initializer.
     if (GV->hasInitializer())
@@ -2858,7 +2858,7 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) {
        I != E;) {
     Module::alias_iterator J = I++;
     // Aliases without names cannot be referenced outside this module.
-    if (!J->hasName() && !J->isDeclaration())
+    if (!J->hasName() && !J->isDeclaration() && !J->hasLocalLinkage())
       J->setLinkage(GlobalValue::InternalLinkage);
     // If the aliasee may change at link time, nothing can be done - bail out.
     if (J->mayBeOverridden())
index db2673af74218a203c4ea1b57cd200edf6c31a82..930a96e2182f25a2103f973f418716e25ad13f06 100644 (file)
@@ -1,13 +1,23 @@
 ; RUN: opt < %s -globalopt -S | FileCheck %s
 
 global i32 0
-; CHECK: @0 = internal global i32 0
-define i32* @1() {
+; CHECK-DAG: @0 = internal global i32 0
+
+private global i32 0
+; CHECK-DAG: @1 = private global i32 0
+
+define i32* @2() {
        ret i32* @0
 }
-; CHECK: define internal fastcc i32* @1()
+; CHECK-DAG: define internal fastcc i32* @2()
+
 define i32* @f() {
 entry:
-       call i32* @1()
+       call i32* @2()
        ret i32* %0
 }
+
+define i32* @g() {
+entry:
+       ret i32* @1
+}