From fd6fc71b444b43a3efc4bbc89db561609729bcca 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212079 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/GlobalOpt.cpp | 7 ++++++- test/Transforms/GlobalOpt/alias-resolve.ll | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index dc9b2a8105e..63a6058b969 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/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/test/Transforms/GlobalOpt/alias-resolve.ll b/test/Transforms/GlobalOpt/alias-resolve.ll index 2d5a956d14b..9d70c708aad 100644 --- a/test/Transforms/GlobalOpt/alias-resolve.ll +++ b/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.11.0