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.

llvm-svn: 212104

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

index 63a6058..c1d0d3b 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 db2673a..930a96e 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
+}