[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 Mar 30 17:26:50 PDT 2021


aeubanks created this revision.
Herald added a subscriber: hiraditya.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Since aliases point to the definition within the current module, we
don't actually care about the linkage of the alias itself, but rather
the linkage of the aliasee. If the aliasee is interposable, replacing
the alias with the aliasee may cause us to choose the non-local function
at link time rather than the function in the current module.

PR27866 provides some background.


Repository:
  rG LLVM Github Monorepo

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
@@ -33,7 +33,10 @@
 ; CHECK: call void @bar2()
 
          call void @weak1()
-; CHECK: call void @weak1()
+; CHECK: call void @bar2()
+
+         call void @bar6()
+; CHECK: call void @bar6()
          ret void
 }
 
@@ -44,3 +47,9 @@
   ret void
 }
 ;CHECK: define void @foo3
+
+define weak void @bar5() {
+  ret void
+}
+
+ at bar6 = alias void(), void ()* @bar5
Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2932,16 +2932,15 @@
       continue;
     }
 
-    // If the alias can change at link time, nothing can be done - bail out.
-    if (J->isInterposable())
-      continue;
-
     Constant *Aliasee = J->getAliasee();
-    GlobalValue *Target = dyn_cast<GlobalValue>(Aliasee->stripPointerCasts());
+    GlobalValue *Target =
+        dyn_cast<GlobalValue>(Aliasee->stripPointerCastsAndAliases());
     // 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.334309.patch
Type: text/x-patch
Size: 1657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210331/49ae3d40/attachment.bin>


More information about the llvm-commits mailing list