[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
Thu Apr 22 13:24:12 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG16ff1a7023db: [GlobalOpt] Don't replace alias with aliasee if aliasee is interposable (authored by aeubanks).

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.339769.patch
Type: text/x-patch
Size: 1772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210422/e40aff63/attachment.bin>


More information about the llvm-commits mailing list