Skip to content

Commit 16ff1a7

Browse files
committed
[GlobalOpt] Don't replace alias with aliasee if aliasee is interposable
Both the alias and aliasee linkage are important. PR27866 provides some background. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D99629
1 parent c0bf592 commit 16ff1a7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,9 +2944,11 @@ OptimizeGlobalAliases(Module &M,
29442944
Constant *Aliasee = J->getAliasee();
29452945
GlobalValue *Target = dyn_cast<GlobalValue>(Aliasee->stripPointerCasts());
29462946
// We can't trivially replace the alias with the aliasee if the aliasee is
2947-
// non-trivial in some way.
2947+
// non-trivial in some way. We also can't replace the alias with the aliasee
2948+
// if the aliasee is interposable because aliases point to the local
2949+
// definition.
29482950
// TODO: Try to handle non-zero GEPs of local aliasees.
2949-
if (!Target)
2951+
if (!Target || Target->isInterposable())
29502952
continue;
29512953
Target->removeDeadConstantUsers();
29522954

llvm/test/Transforms/GlobalOpt/alias-resolve.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,19 @@
1616
@foo4 = weak_odr unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @bar4, i32 0, i32 1)
1717
; CHECK: @foo4 = weak_odr unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @bar4, i32 0, i32 1)
1818

19+
@priva = private alias void (), void ()* @bar5
20+
; CHECK: @priva = private alias void (), void ()* @bar5
21+
1922
define void @bar2() {
2023
ret void
2124
}
2225
; CHECK: define void @bar2()
2326

27+
define weak void @bar5() {
28+
ret void
29+
}
30+
; CHECK: define weak void @bar5()
31+
2432
define void @baz() {
2533
entry:
2634
call void @foo1()
@@ -34,6 +42,10 @@ entry:
3442

3543
call void @weak1()
3644
; CHECK: call void @weak1()
45+
46+
call void @priva()
47+
; CHECK: call void @priva()
48+
3749
ret void
3850
}
3951

0 commit comments

Comments
 (0)