[PATCH] D99629: [GlobalOpt] Don't replace alias with aliasee if aliasee is interposable

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 20 13:33:38 PDT 2021


aeubanks updated this revision to Diff 338980.
aeubanks added a comment.

keep check of alias itself


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99629/new/

https://reviews.llvm.org/D99629

Files:
  llvm/lib/Transforms/IPO/GlobalOpt.cpp
  llvm/test/Transforms/GlobalOpt/alias-resolve.ll


Index: llvm/test/Transforms/GlobalOpt/alias-resolve.ll
===================================================================
--- llvm/test/Transforms/GlobalOpt/alias-resolve.ll
+++ llvm/test/Transforms/GlobalOpt/alias-resolve.ll
@@ -16,11 +16,19 @@
 @foo4 = weak_odr unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @bar4, i32 0, i32 1)
 ; CHECK: @foo4 = weak_odr unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @bar4, i32 0, i32 1)
 
+ at priva  = private alias void (), void ()* @bar5
+; CHECK: @priva = private alias void (), void ()* @bar5
+
 define void @bar2() {
   ret void
 }
 ; CHECK: define void @bar2()
 
+define weak void @bar5() {
+  ret void
+}
+; CHECK: define weak void @bar5()
+
 define void @baz() {
 entry:
          call void @foo1()
@@ -34,6 +42,10 @@
 
          call void @weak1()
 ; CHECK: call void @weak1()
+
+         call void @priva()
+; CHECK: call void @priva()
+
          ret void
 }
 
Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2944,9 +2944,11 @@
     Constant *Aliasee = J->getAliasee();
     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.
+    // non-trivial in some way. We also can't replace the alias with the aliasee
+    // if the aliasee is interposable because aliases point to the local
+    // definition.
     // TODO: Try to handle non-zero GEPs of local aliasees.
-    if (!Target)
+    if (!Target || Target->isInterposable())
       continue;
     Target->removeDeadConstantUsers();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99629.338980.patch
Type: text/x-patch
Size: 1772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210420/538508d0/attachment.bin>


More information about the llvm-commits mailing list