From: Rafael Espindola Date: Tue, 22 Dec 2015 19:50:22 +0000 (+0000) Subject: Delete dead GlobalAliases. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=937ba4cad8c9d5c8d5d2de06e535299a85ff42c6;p=oota-llvm.git Delete dead GlobalAliases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256276 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index 06a319017ee..2873ee72169 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -2993,10 +2993,17 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) { for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end(); I != E;) { - Module::alias_iterator J = I++; + GlobalAlias *J = &*I++; + // Aliases without names cannot be referenced outside this module. if (!J->hasName() && !J->isDeclaration() && !J->hasLocalLinkage()) J->setLinkage(GlobalValue::InternalLinkage); + + if (deleteIfDead(*J)) { + Changed = true; + continue; + } + // If the aliasee may change at link time, nothing can be done - bail out. if (J->mayBeOverridden()) continue; diff --git a/test/Transforms/GlobalOpt/alias-resolve.ll b/test/Transforms/GlobalOpt/alias-resolve.ll index f11fdb5e2bb..46b90ec29b9 100644 --- a/test/Transforms/GlobalOpt/alias-resolve.ll +++ b/test/Transforms/GlobalOpt/alias-resolve.ll @@ -13,8 +13,8 @@ ; CHECK: @weak1 = weak alias void (), void ()* @bar2 @bar4 = private unnamed_addr constant [2 x i8*] zeroinitializer -@foo4 = linkonce_odr unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @bar4, i32 0, i32 1) -; CHECK: @foo4 = linkonce_odr unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @bar4, i32 0, i32 1) +@foo4 = weak_odr unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @bar4, i32 0, i32 1) +; CHECK: @foo4 = weak_odr unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @bar4, i32 0, i32 1) define void @bar2() { ret void diff --git a/test/Transforms/GlobalOpt/deadglobal.ll b/test/Transforms/GlobalOpt/deadglobal.ll index 9563a23b2c2..f5eed44cbb6 100644 --- a/test/Transforms/GlobalOpt/deadglobal.ll +++ b/test/Transforms/GlobalOpt/deadglobal.ll @@ -1,11 +1,14 @@ ; RUN: opt < %s -globalopt -S | FileCheck %s @G1 = internal global i32 123 ; [#uses=1] +@A1 = internal alias i32, i32* @G1 ; CHECK-NOT: @G1 ; CHECK: @G2 ; CHECK-NOT: @G3 +; CHECK-NOT: @A1 + define void @foo1() { ; CHECK: define void @foo ; CHECK-NEXT: ret diff --git a/test/Transforms/GlobalOpt/localize-constexpr.ll b/test/Transforms/GlobalOpt/localize-constexpr.ll index 6754533a50c..3fa7db89b04 100644 --- a/test/Transforms/GlobalOpt/localize-constexpr.ll +++ b/test/Transforms/GlobalOpt/localize-constexpr.ll @@ -13,7 +13,7 @@ define i8 @f() norecurse { } @H = internal global i32 42 -@Halias = internal alias i32, i32* @H +@Halias = alias i32, i32* @H ; @H can't be localized because @Halias uses it, and @Halias can't be converted to an instruction. define i8 @g() norecurse {