GlobalOpt: Handle non-zero offsets for aliases
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 1 Jul 2014 00:30:56 +0000 (00:30 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 1 Jul 2014 00:30:56 +0000 (00:30 +0000)
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
test/Transforms/GlobalOpt/alias-resolve.ll

index dc9b2a8105ea7d81fbed15a9dc2b07e71ddb64df..63a6058b9693f996cc03cd097546677c5b262559 100644 (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.
index 2d5a956d14b1266467f49f7f005478dafe9ba4b0..9d70c708aad865bf3f710ed7d877c3f2c18348c6 100644 (file)
 @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
 }