[llvm] r343970 - [ThinLTO] Keep non-prevailing (linkonce|weak)_odr symbols live
Xin Tong via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 8 08:12:48 PDT 2018
Author: trentxintong
Date: Mon Oct 8 08:12:48 2018
New Revision: 343970
URL: http://llvm.org/viewvc/llvm-project?rev=343970&view=rev
Log:
[ThinLTO] Keep non-prevailing (linkonce|weak)_odr symbols live
Summary:
If we have a symbol with (linkonce|weak)_odr linkage, we do not want
to dead strip it even it is not prevailing.
IR level (linkonce|weak)_odr symbol can become non-prevailing when we mix
ELF objects and IR objects where the (linkonce|weak)_odr symbol in the ELF
object is prevailing and the ones in the IR objects are not. Stripping
them will prevent us from doing optimizations with them.
By not dead stripping them, We will convert these symbols to
available_externally linkage as a result of non-prevailing and eventually
dropping them after inlining.
I modified cache-prevailing.ll to use linkonce linkage as it is
testing whether cache prevailing bit is effective or not, not
we should treat linkonce_odr alive or not
Reviewers: tejohnson, pcc
Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, llvm-commits
Differential Revision: https://reviews.llvm.org/D52893
Modified:
llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
llvm/trunk/test/LTO/Resolution/X86/cache-prevailing.ll
llvm/trunk/test/ThinLTO/X86/deadstrip.ll
llvm/trunk/test/Transforms/FunctionImport/not-prevailing.ll
Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=343970&r1=343969&r2=343970&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Mon Oct 8 08:12:48 2018
@@ -741,24 +741,28 @@ void llvm::computeDeadSymbols(
return;
// We only keep live symbols that are known to be non-prevailing if any 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).
+ // available_externally, linkonceodr, weakodr. Those symbols are discarded
+ // later in the EliminateAvailableExternally pass and setting them to
+ // not-live could break downstreams users of liveness information (PR36483)
+ // or limit optimization opportunities.
if (isPrevailing(VI.getGUID()) == PrevailingType::No) {
- bool AvailableExternally = false;
+ bool KeepAliveLinkage = false;
bool Interposable = false;
for (auto &S : VI.getSummaryList()) {
- if (S->linkage() == GlobalValue::AvailableExternallyLinkage)
- AvailableExternally = true;
+ if (S->linkage() == GlobalValue::AvailableExternallyLinkage ||
+ S->linkage() == GlobalValue::WeakODRLinkage ||
+ S->linkage() == GlobalValue::LinkOnceODRLinkage)
+ KeepAliveLinkage = true;
else if (GlobalValue::isInterposableLinkage(S->linkage()))
Interposable = true;
}
- if (!AvailableExternally)
+ if (!KeepAliveLinkage)
return;
if (Interposable)
- report_fatal_error("Interposable and available_externally symbol");
+ report_fatal_error(
+ "Interposable and available_externally/linkonce_odr/weak_odr symbol");
}
for (auto &S : VI.getSummaryList())
Modified: llvm/trunk/test/LTO/Resolution/X86/cache-prevailing.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/cache-prevailing.ll?rev=343970&r1=343969&r2=343970&view=diff
==============================================================================
--- llvm/trunk/test/LTO/Resolution/X86/cache-prevailing.ll (original)
+++ llvm/trunk/test/LTO/Resolution/X86/cache-prevailing.ll Mon Oct 8 08:12:48 2018
@@ -10,7 +10,7 @@
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.11.0"
- at foo = linkonce_odr constant i32 1, comdat
+ at foo = linkonce constant i32 1, comdat
$foo = comdat any
define i32* @bar() {
Modified: llvm/trunk/test/ThinLTO/X86/deadstrip.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/deadstrip.ll?rev=343970&r1=343969&r2=343970&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/deadstrip.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/deadstrip.ll Mon Oct 8 08:12:48 2018
@@ -18,6 +18,8 @@
; RUN: -r %t1.bc,_baz,l \
; RUN: -r %t1.bc,_boo,l \
; RUN: -r %t1.bc,_live_available_externally_func,l \
+; RUN: -r %t1.bc,_live_linkonce_odr_func,l \
+; RUN: -r %t1.bc,_live_weak_odr_func,l \
; RUN: -r %t2.bc,_baz,pl \
; RUN: -r %t2.bc,_boo,pl \
; RUN: -r %t2.bc,_dead_func,l \
@@ -33,12 +35,16 @@
; COMBINED-DAG: <COMBINED {{.*}} op2=119
; Live, dso_local, Internal
; COMBINED-DAG: <COMBINED {{.*}} op2=103
+; Live, Local, LinkOnceODR
+; COMBINED-DAG: <COMBINED {{.*}} op2=99
; Live, Local, AvailableExternally
; COMBINED-DAG: <COMBINED {{.*}} op2=97
; Live, Local, External
; COMBINED-DAG: <COMBINED {{.*}} op2=96
; COMBINED-DAG: <COMBINED {{.*}} op2=96
; COMBINED-DAG: <COMBINED {{.*}} op2=96
+; Live, Local, WeakODR
+; COMBINED-DAG: <COMBINED {{.*}} op2=69
; Local, (Dead)
; COMBINED-DAG: <COMBINED {{.*}} op2=64
; COMBINED-DAG: <COMBINED {{.*}} op2=64
@@ -95,6 +101,8 @@
; RUN: -r %t1.bc,_baz,l \
; RUN: -r %t1.bc,_boo,l \
; RUN: -r %t1.bc,_live_available_externally_func,l \
+; RUN: -r %t1.bc,_live_linkonce_odr_func,l \
+; RUN: -r %t1.bc,_live_weak_odr_func,l \
; RUN: -r %t3.bc,_baz,pl \
; RUN: -r %t3.bc,_boo,pl \
; RUN: -r %t3.bc,_dead_func,l \
@@ -140,6 +148,15 @@ define void @dead_func() {
ret void
}
+
+define linkonce_odr void @live_linkonce_odr_func() {
+ ret void
+}
+
+define weak_odr void @live_weak_odr_func() {
+ ret void
+}
+
define available_externally void @live_available_externally_func() {
ret void
}
@@ -147,6 +164,8 @@ define available_externally void @live_a
define void @main() {
call void @bar()
call void @bar_internal()
+ call void @live_linkonce_odr_func()
+ call void @live_weak_odr_func()
call void @live_available_externally_func()
ret void
}
Modified: llvm/trunk/test/Transforms/FunctionImport/not-prevailing.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionImport/not-prevailing.ll?rev=343970&r1=343969&r2=343970&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/FunctionImport/not-prevailing.ll (original)
+++ llvm/trunk/test/Transforms/FunctionImport/not-prevailing.ll Mon Oct 8 08:12:48 2018
@@ -3,7 +3,7 @@
; RUN: not llvm-lto2 run -o %t3.bc %t1.bc %t2.bc -r %t1.bc,bar,px \
; RUN: -r %t1.bc,foo,x -r %t2.bc,foo,x -save-temps 2>&1 | FileCheck %s
-; CHECK: Interposable and available_externally symbol
+; CHECK: Interposable and available_externally/linkonce_odr/weak_odr symbol
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
More information about the llvm-commits
mailing list