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
This commit is contained in:
David Majnemer 2014-07-01 00:30:56 +00:00
parent 5bfe75cf61
commit 0e2cc2a519
2 changed files with 10 additions and 1 deletions

View File

@ -2865,7 +2865,12 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) {
continue;
Constant *Aliasee = J->getAliasee();
GlobalValue *Target = cast<GlobalValue>(Aliasee->stripPointerCasts());
GlobalValue *Target = dyn_cast<GlobalValue>(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.

View File

@ -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
}