[llvm] 16ff1a7 - [GlobalOpt] Don't replace alias with aliasee if aliasee is interposable

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 22 13:23:58 PDT 2021


Author: Arthur Eubanks
Date: 2021-04-22T13:12:34-07:00
New Revision: 16ff1a7023db2a2a8ffe0a9a1cd879c6ecf1ccca

URL: https://github.com/llvm/llvm-project/commit/16ff1a7023db2a2a8ffe0a9a1cd879c6ecf1ccca
DIFF: https://github.com/llvm/llvm-project/commit/16ff1a7023db2a2a8ffe0a9a1cd879c6ecf1ccca.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 94278a0d501d4..cc4947c825c9b 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2944,9 +2944,11 @@ OptimizeGlobalAliases(Module &M,
     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();
 

diff  --git a/llvm/test/Transforms/GlobalOpt/alias-resolve.ll b/llvm/test/Transforms/GlobalOpt/alias-resolve.ll
index 46b90ec29b9df..324119ce05999 100644
--- a/llvm/test/Transforms/GlobalOpt/alias-resolve.ll
+++ b/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 @@ entry:
 
          call void @weak1()
 ; CHECK: call void @weak1()
+
+         call void @priva()
+; CHECK: call void @priva()
+
          ret void
 }
 


        


More information about the llvm-commits mailing list