Skip to content

Commit 55b4ec9

Browse files
committed
[ThinLTO] Don't internalize during promotion
Differential revision: https://reviews.llvm.org/D69107 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375493 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 5cd00d1 commit 55b4ec9

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

lib/Transforms/IPO/FunctionImport.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ void llvm::thinLTOResolvePrevailingInModule(
952952
if (NewLinkage == GV.getLinkage())
953953
return;
954954
if (GlobalValue::isLocalLinkage(GV.getLinkage()) ||
955+
GlobalValue::isLocalLinkage(NewLinkage) ||
955956
// In case it was dead and already converted to declaration.
956957
GV.isDeclaration())
957958
return;

test/ThinLTO/X86/not-internalized.ll

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
; ModuleID = 'test.c'
2+
source_filename = "test.c"
3+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4+
target triple = "x86_64-unknown-linux-gnu"
5+
6+
; RUN: opt -module-summary %s -o %t.bc
7+
; RUN: llvm-lto2 run -save-temps %t.bc -o %t.out \
8+
; RUN: -r=%t.bc,foo,plx \
9+
; RUN: -r=%t.bc,bar,lx
10+
11+
; Check that we don't internalize `bar` during promotion,
12+
; because foo and bar are members of the same comdat
13+
; RUN: llvm-dis %t.out.1.1.promote.bc -o - | FileCheck %s
14+
15+
; Thin LTO internalization shouldn't internalize `bar` as well
16+
; RUN: llvm-dis %t.out.1.2.internalize.bc -o - | FileCheck %s
17+
18+
; CHECK: define linkonce_odr dso_local i32 @bar() comdat($foo)
19+
20+
$foo = comdat any
21+
22+
; Function Attrs: noinline nounwind optnone uwtable
23+
define linkonce_odr dso_local i32 @bar() comdat($foo) {
24+
entry:
25+
ret i32 33
26+
}
27+
28+
; Function Attrs: noinline nounwind optnone uwtable
29+
define linkonce_odr dso_local i32 @foo() comdat {
30+
entry:
31+
%call = call i32 @bar()
32+
%add = add nsw i32 42, %call
33+
ret i32 %add
34+
}

test/ThinLTO/X86/weak_externals.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
; RUN: -r=%t.bc,_ZZN9SingletonI1SE11getInstanceEvE8instance,lx \
88
; RUN: -r=%t.bc,_ZZN9SingletonI1SE11getInstanceEvE13instance_weak,lx
99
; RUN: llvm-dis %t.out.1.1.promote.bc -o - | FileCheck %s
10+
; RUN: llvm-dis %t.out.1.2.internalize.bc -o - | FileCheck %s --check-prefix=INTERNALIZE
1011

1112
; CHECK: @_ZZN9SingletonI1SE11getInstanceEvE8instance = available_externally dso_local global %struct.S zeroinitializer
1213
; CHECK: @_ZZN9SingletonI1SE11getInstanceEvE13instance_weak = available_externally dso_local global %struct.S* null, align 8
13-
; CHECK: define internal dereferenceable(16) %struct.S* @_ZN9SingletonI1SE11getInstanceEv() comdat
14+
; CHECK: define linkonce_odr dso_local dereferenceable(16) %struct.S* @_ZN9SingletonI1SE11getInstanceEv() comdat
15+
; INTERNALIZE: define internal dereferenceable(16) %struct.S* @_ZN9SingletonI1SE11getInstanceEv()
1416

1517
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
1618
target triple = "x86_64-unknown-linux-gnu"

0 commit comments

Comments
 (0)