-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LTO] Make local linkage GlobalValue in non-prevailing COMDAT availab…
…le_externally See the updated linkonce_resolution_comdat.ll. For a local linkage GV in a non-prevailing COMDAT, it remains defined while its leader has been made available_externally. This violates the COMDAT rule that its members must be retained or discarded as a unit. To fix this, update the regular LTO change D34803 to track local linkage GlobalValues, and port the code to ThinLTO (GlobalAliases are not handled.) Fix #58215: as a size optimization, we place private `__profd_` in a COMDAT with a `__profc_` key. When FuncImport.cpp makes `__profc_` available_externally due to a non-prevailing COMDAT, `__profd_` incorrectly remains private. This change makes the `__profd_` available_externally. ``` cat > c.h <<'eof' extern void bar(); inline __attribute__((noinline)) void foo() {} eof cat > m1.cc <<'eof' #include "c.h" int main() { bar(); foo(); } eof cat > m2.cc <<'eof' #include "c.h" __attribute__((noinline)) void bar() { foo(); } eof clang -O2 -fprofile-generate=./t m1.cc m2.cc -flto -fuse-ld=lld -o t_gen rm -fr t && ./t_gen && llvm-profdata show -function=foo t/default_*.profraw # one _Z3foov clang -O2 -fprofile-generate=./t m1.cc m2.cc -flto=thin -fuse-ld=lld -o t_gen rm -fr t && ./t_gen && llvm-profdata show -function=foo t/default_*.profraw # one _Z3foov ``` Reviewed By: tejohnson Differential Revision: https://reviews.llvm.org/D135427
- Loading branch information
Showing
5 changed files
with
74 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 14 additions & 3 deletions
17
llvm/test/ThinLTO/X86/Inputs/linkonce_resolution_comdat.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
$c2 = comdat any | ||
$f = comdat any | ||
$g = comdat any | ||
|
||
define linkonce_odr i32 @f(i8*) unnamed_addr comdat($c2) { | ||
@g_private = private global i32 41, comdat($g) | ||
|
||
define linkonce_odr i32 @f(i8*) unnamed_addr comdat($f) { | ||
ret i32 41 | ||
} | ||
|
||
define linkonce_odr i32 @g() unnamed_addr comdat($g) { | ||
ret i32 41 | ||
} | ||
|
||
define i32 @g() { | ||
define internal void @g_internal() unnamed_addr comdat($g) { | ||
ret void | ||
} | ||
|
||
define i32 @h() { | ||
%i = call i32 @f(i8* null) | ||
ret i32 %i | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,54 @@ | ||
; This test ensures that we drop the preempted copy of @f from %t2.bc from its | ||
; comdat after making it available_externally. If not we would get a | ||
; verification error. | ||
; This test ensures that we drop the preempted copy of @f/@g from %t2.bc from their | ||
; comdats after making it available_externally. If not we would get a | ||
; verification error. g_internal/g_private are changed to available_externally | ||
; as well since it is in the same comdat of g. | ||
; RUN: opt -module-summary %s -o %t1.bc | ||
; RUN: opt -module-summary %p/Inputs/linkonce_resolution_comdat.ll -o %t2.bc | ||
; RUN: llvm-lto -thinlto-action=run -disable-thinlto-funcattrs=0 %t1.bc %t2.bc -exported-symbol=f -exported-symbol=g -thinlto-save-temps=%t3. | ||
; RUN: llvm-lto -thinlto-action=run -disable-thinlto-funcattrs=0 %t1.bc %t2.bc -exported-symbol=f -exported-symbol=g -exported-symbol=h -thinlto-save-temps=%t3. | ||
|
||
; RUN: llvm-dis %t3.0.3.imported.bc -o - | FileCheck %s --check-prefix=IMPORT1 | ||
; RUN: llvm-dis %t3.1.3.imported.bc -o - | FileCheck %s --check-prefix=IMPORT2 | ||
; Copy from first module is prevailing and converted to weak_odr, copy | ||
; from second module is preempted and converted to available_externally and | ||
; removed from comdat. | ||
; IMPORT1: define weak_odr i32 @f(i8* %0) unnamed_addr [[ATTR:#[0-9]+]] comdat($c1) { | ||
; IMPORT1: @g_private = private global i32 43, comdat($g) | ||
; IMPORT1: define weak_odr i32 @f(i8* %0) unnamed_addr [[ATTR:#[0-9]+]] comdat { | ||
; IMPORT1: define weak_odr i32 @g() unnamed_addr [[ATTR]] comdat { | ||
; IMPORT1: define internal void @g_internal() unnamed_addr comdat($g) { | ||
|
||
; IMPORT2: @g_private = available_externally dso_local global i32 41{{$}} | ||
; IMPORT2: define available_externally i32 @f(i8* %0) unnamed_addr [[ATTR:#[0-9]+]] { | ||
; IMPORT2: define available_externally i32 @g() unnamed_addr [[ATTR]] { | ||
; IMPORT2: define available_externally dso_local void @g_internal() unnamed_addr { | ||
|
||
; CHECK-DAG: attributes [[ATTR]] = { norecurse nounwind } | ||
|
||
; RUN: llvm-nm -o - < %t1.bc.thinlto.o | FileCheck %s --check-prefix=NM1 | ||
; RUN: llvm-nm %t1.bc.thinlto.o | FileCheck %s --check-prefix=NM1 | ||
; NM1: W f | ||
; NM1: W g | ||
|
||
; RUN: llvm-nm -o - < %t2.bc.thinlto.o | FileCheck %s --check-prefix=NM2 | ||
; RUN: llvm-nm %t2.bc.thinlto.o | FileCheck %s --check-prefix=NM2 | ||
; f() would have been turned into available_externally since it is preempted, | ||
; and inlined into g() | ||
; and inlined into h() | ||
; NM2-NOT: f | ||
; NM2-NOT: g | ||
|
||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
$c1 = comdat any | ||
$f = comdat any | ||
$g = comdat any | ||
|
||
@g_private = private global i32 43, comdat($g) | ||
|
||
define linkonce_odr i32 @f(i8*) unnamed_addr comdat($c1) { | ||
define linkonce_odr i32 @f(i8*) unnamed_addr comdat { | ||
ret i32 43 | ||
} | ||
|
||
define linkonce_odr i32 @g() unnamed_addr comdat { | ||
ret i32 43 | ||
} | ||
|
||
define internal void @g_internal() unnamed_addr comdat($g) { | ||
ret void | ||
} |