Skip to content

Commit 7b66ef1

Browse files
committedMar 8, 2018
[ThinLTO] Keep available_externally symbols live
Summary: 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 O1 was an oversight. Reviewers: pcc, tejohnson Reviewed By: tejohnson Subscribers: grimar, mehdi_amini, inglorion, eraman, llvm-commits Differential Revision: https://reviews.llvm.org/D43690 llvm-svn: 327041
1 parent d5e5992 commit 7b66ef1

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed
 

‎llvm/lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,25 @@ void llvm::computeDeadSymbols(
544544
if (S->isLive())
545545
return;
546546

547-
// We do not keep live symbols that are known to be non-prevailing.
548-
if (isPrevailing(VI.getGUID()) == PrevailingType::No)
549-
return;
547+
// We only keep live symbols that are known to be non-prevailing if any are
548+
// available_externally. Those symbols are discarded later in the
549+
// EliminateAvailableExternally pass and setting them to not-live breaks
550+
// downstreams users of liveness information (PR36483).
551+
if (isPrevailing(VI.getGUID()) == PrevailingType::No) {
552+
bool AvailableExternally = false;
553+
for (auto &S : VI.getSummaryList())
554+
if (S->linkage() == GlobalValue::AvailableExternallyLinkage)
555+
AvailableExternally = true;
556+
557+
if (!AvailableExternally)
558+
return;
559+
560+
#ifndef NDEBUG
561+
for (auto &S : VI.getSummaryList())
562+
assert(!GlobalValue::isInterposableLinkage(S->linkage()) &&
563+
"Symbol with interposable and available_externally linkages");
564+
#endif
565+
}
550566

551567
for (auto &S : VI.getSummaryList())
552568
S->setLive(true);

‎llvm/test/ThinLTO/X86/deadstrip.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
; RUN: -r %t1.bc,_dead_func,pl \
1515
; RUN: -r %t1.bc,_baz,l \
1616
; RUN: -r %t1.bc,_boo,l \
17+
; RUN: -r %t1.bc,_live_available_externally_func,l \
1718
; RUN: -r %t2.bc,_baz,pl \
1819
; RUN: -r %t2.bc,_boo,pl \
1920
; RUN: -r %t2.bc,_dead_func,l \
@@ -27,6 +28,8 @@
2728
; COMBINED-DAG: <COMBINED {{.*}} op2=119
2829
; Live, dso_local, Internal
2930
; COMBINED-DAG: <COMBINED {{.*}} op2=103
31+
; Live, Local, AvailableExternally
32+
; COMBINED-DAG: <COMBINED {{.*}} op2=97
3033
; Live, Local, External
3134
; COMBINED-DAG: <COMBINED {{.*}} op2=96
3235
; COMBINED-DAG: <COMBINED {{.*}} op2=96
@@ -79,6 +82,7 @@
7982
; RUN: -r %t1.bc,_dead_func,pl \
8083
; RUN: -r %t1.bc,_baz,l \
8184
; RUN: -r %t1.bc,_boo,l \
85+
; RUN: -r %t1.bc,_live_available_externally_func,l \
8286
; RUN: -r %t3.bc,_baz,pl \
8387
; RUN: -r %t3.bc,_boo,pl \
8488
; RUN: -r %t3.bc,_dead_func,l \
@@ -124,8 +128,13 @@ define void @dead_func() {
124128
ret void
125129
}
126130

131+
define available_externally void @live_available_externally_func() {
132+
ret void
133+
}
134+
127135
define void @main() {
128136
call void @bar()
129137
call void @bar_internal()
138+
call void @live_available_externally_func()
130139
ret void
131140
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2+
target triple = "x86_64-unknown-linux-gnu"
3+
4+
define weak i32 @foo() {
5+
ret i32 0
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: opt -module-summary %s -o %t1.bc
2+
; RUN: opt -module-summary -o %t2.bc %S/Inputs/not-prevailing.ll
3+
; RUN: not --crash llvm-lto2 run -o %t3.bc %t1.bc %t2.bc -r %t1.bc,bar,px \
4+
; RUN: -r %t1.bc,foo,x -r %t2.bc,foo,x -save-temps 2>&1 | FileCheck %s
5+
6+
; CHECK: Assertion {{.*}} "Symbol with interposable and available_externally linkages"' failed
7+
8+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
9+
target triple = "x86_64-unknown-linux-gnu"
10+
11+
define available_externally i32 @foo() {
12+
ret i32 1
13+
}
14+
15+
define i32 @bar() {
16+
%1 = call i32 @foo()
17+
ret i32 %1
18+
}

0 commit comments

Comments
 (0)
Please sign in to comment.