Skip to content

Commit fd6fc71

Browse files
committed
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
1 parent b6a4058 commit fd6fc71

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2865,7 +2865,12 @@ bool GlobalOpt::OptimizeGlobalAliases(Module &M) {
28652865
continue;
28662866

28672867
Constant *Aliasee = J->getAliasee();
2868-
GlobalValue *Target = cast<GlobalValue>(Aliasee->stripPointerCasts());
2868+
GlobalValue *Target = dyn_cast<GlobalValue>(Aliasee->stripPointerCasts());
2869+
// We can't trivially replace the alias with the aliasee if the aliasee is
2870+
// non-trivial in some way.
2871+
// TODO: Try to handle non-zero GEPs of local aliasees.
2872+
if (!Target)
2873+
continue;
28692874
Target->removeDeadConstantUsers();
28702875

28712876
// Make all users of the alias use the aliasee instead.

test/Transforms/GlobalOpt/alias-resolve.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
@weak1 = alias weak void ()* @bar2
1313
; CHECK: @weak1 = alias weak void ()* @bar2
1414

15+
@bar4 = private unnamed_addr constant [2 x i8*] zeroinitializer
16+
@foo4 = unnamed_addr alias linkonce_odr getelementptr inbounds ([2 x i8*]* @bar4, i32 0, i32 1)
17+
; CHECK: @foo4 = unnamed_addr alias linkonce_odr getelementptr inbounds ([2 x i8*]* @bar4, i32 0, i32 1)
18+
1519
define void @bar2() {
1620
ret void
1721
}

0 commit comments

Comments
 (0)