From 0e2cc2a519a35796b48dd564db80d578df56e9f8 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 1 Jul 2014 00:30:56 +0000 Subject: [PATCH] GlobalOpt: Handle non-zero offsets for aliases An alias with an aliasee of a non-zero GEP is not trivially replacable with it's aliasee. llvm-svn: 212079 --- llvm/lib/Transforms/IPO/GlobalOpt.cpp | 7 ++++++- llvm/test/Transforms/GlobalOpt/alias-resolve.ll | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index dc9b2a8..63a6058 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -2865,7 +2865,12 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) { continue; Constant *Aliasee = J->getAliasee(); - GlobalValue *Target = cast(Aliasee->stripPointerCasts()); + GlobalValue *Target = dyn_cast(Aliasee->stripPointerCasts()); + // We can't trivially replace the alias with the aliasee if the aliasee is + // non-trivial in some way. + // TODO: Try to handle non-zero GEPs of local aliasees. + if (!Target) + continue; Target->removeDeadConstantUsers(); // Make all users of the alias use the aliasee instead. diff --git a/llvm/test/Transforms/GlobalOpt/alias-resolve.ll b/llvm/test/Transforms/GlobalOpt/alias-resolve.ll index 2d5a956..9d70c70 100644 --- a/llvm/test/Transforms/GlobalOpt/alias-resolve.ll +++ b/llvm/test/Transforms/GlobalOpt/alias-resolve.ll @@ -12,6 +12,10 @@ @weak1 = alias weak void ()* @bar2 ; CHECK: @weak1 = alias weak void ()* @bar2 +@bar4 = private unnamed_addr constant [2 x i8*] zeroinitializer +@foo4 = unnamed_addr alias linkonce_odr getelementptr inbounds ([2 x i8*]* @bar4, i32 0, i32 1) +; CHECK: @foo4 = unnamed_addr alias linkonce_odr getelementptr inbounds ([2 x i8*]* @bar4, i32 0, i32 1) + define void @bar2() { ret void } -- 2.7.4