[PATCH] D43690: [ThinLTO] Keep available_externally symbols live

Vlad Tsyrklevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 12:38:00 PST 2018


vlad.tsyrklevich created this revision.
Herald added subscribers: llvm-commits, eraman, inglorion, mehdi_amini.

This change fixes PR36483. The bug was originally introduced by a change
that marked non-prevailing symbols dead. This broke LowerTypeTests
handling of available_externally functions, which are non-prevailing.
LowerTypeTests uses liveness information to avoid emitting thunks for
unused functions.

Marking available_externally functions dead is incorrect, the functions
are used though the function definitions are not. This change keeps them
live, and lets the EliminateAvailableExternally/GlobalDCE passes remove
them later instead.

I've also enabled EliminateAvailableExternally for all optimization
levels, I believe it being disabled for https://reviews.llvm.org/owners/package/1/ was an oversight.


Repository:
  rL LLVM

https://reviews.llvm.org/D43690

Files:
  lib/Transforms/IPO/FunctionImport.cpp
  lib/Transforms/IPO/PassManagerBuilder.cpp
  test/ThinLTO/X86/deadstrip.ll


Index: test/ThinLTO/X86/deadstrip.ll
===================================================================
--- test/ThinLTO/X86/deadstrip.ll
+++ test/ThinLTO/X86/deadstrip.ll
@@ -14,6 +14,7 @@
 ; RUN:   -r %t1.bc,_dead_func,pl \
 ; RUN:   -r %t1.bc,_baz,l \
 ; RUN:   -r %t1.bc,_boo,l \
+; RUN:   -r %t1.bc,_live_available_externally_func,l \
 ; RUN:   -r %t2.bc,_baz,pl \
 ; RUN:   -r %t2.bc,_boo,pl \
 ; RUN:   -r %t2.bc,_dead_func,l \
@@ -27,6 +28,8 @@
 ; COMBINED-DAG: <COMBINED {{.*}} op2=119
 ; Live, dso_local, Internal
 ; COMBINED-DAG: <COMBINED {{.*}} op2=103
+; Live, Local, AvailableExternally
+; COMBINED-DAG: <COMBINED {{.*}} op2=97
 ; Live, Local, External
 ; COMBINED-DAG: <COMBINED {{.*}} op2=96
 ; COMBINED-DAG: <COMBINED {{.*}} op2=96
@@ -79,6 +82,7 @@
 ; RUN:   -r %t1.bc,_dead_func,pl \
 ; RUN:   -r %t1.bc,_baz,l \
 ; RUN:   -r %t1.bc,_boo,l \
+; RUN:   -r %t1.bc,_live_available_externally_func,l \
 ; RUN:   -r %t3.bc,_baz,pl \
 ; RUN:   -r %t3.bc,_boo,pl \
 ; RUN:   -r %t3.bc,_dead_func,l \
@@ -124,8 +128,13 @@
     ret void
 }
 
+define available_externally void @live_available_externally_func() {
+    ret void
+}
+
 define void @main() {
     call void @bar()
     call void @bar_internal()
+    call void @live_available_externally_func()
     ret void
 }
Index: lib/Transforms/IPO/PassManagerBuilder.cpp
===================================================================
--- lib/Transforms/IPO/PassManagerBuilder.cpp
+++ lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -520,7 +520,7 @@
   if (RunPartialInlining)
     MPM.add(createPartialInliningPass());
 
-  if (OptLevel > 1 && !PrepareForLTO && !PrepareForThinLTO)
+  if (!PrepareForLTO && !PrepareForThinLTO)
     // Remove avail extern fns and globals definitions if we aren't
     // compiling an object file for later LTO. For LTO we want to preserve
     // these so they are eligible for inlining at link-time. Note if they
Index: lib/Transforms/IPO/FunctionImport.cpp
===================================================================
--- lib/Transforms/IPO/FunctionImport.cpp
+++ lib/Transforms/IPO/FunctionImport.cpp
@@ -611,9 +611,14 @@
       if (S->isLive())
         return;
 
-    // We do not keep live symbols that are known to be non-prevailing.
+    // We only keep live symbols that are known to be non-prevailing if they
+    // are available_externally. Those symbols are discarded later in the
+    // EliminateAvailableExternally pass and setting them to not-live breaks
+    // downstreams users of liveness information (PR36483).
     if (isPrevailing(VI.getGUID()) == PrevailingType::No)
-      return;
+      for (auto &S : VI.getSummaryList())
+        if (S->linkage() != GlobalValue::AvailableExternallyLinkage)
+          return;
 
     for (auto &S : VI.getSummaryList())
       S->setLive(true);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43690.135683.patch
Type: text/x-patch
Size: 2812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180223/16705b1b/attachment.bin>


More information about the llvm-commits mailing list