[llvm] r266854 - FunctionImport: make sure we always select the right callee in presence of alias
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 19 21:17:44 PDT 2016
Author: mehdi_amini
Date: Tue Apr 19 23:17:36 2016
New Revision: 266854
URL: http://llvm.org/viewvc/llvm-project?rev=266854&view=rev
Log:
FunctionImport: make sure we always select the right callee in presence of alias
From: Mehdi Amini <mehdi.amini at apple.com>
Added:
llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition1.ll
llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition2.ll
llvm/trunk/test/ThinLTO/X86/select_right_alias_definition.ll
Modified:
llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=266854&r1=266853&r2=266854&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Tue Apr 19 23:17:36 2016
@@ -86,12 +86,21 @@ selectCallee(const GlobalValueInfoList &
assert(GlobInfo->summary() &&
"We should not have a Global Info without summary");
auto *GVSummary = GlobInfo->summary();
- if (auto *AS = dyn_cast<AliasSummary>(GVSummary))
+ if (GlobalValue::isWeakAnyLinkage(GVSummary->linkage()))
+ // There is no point in importing weak symbols, we can't inline them
+ return false;
+ if (auto *AS = dyn_cast<AliasSummary>(GVSummary)) {
GVSummary = &AS->getAliasee();
- auto *Summary = cast<FunctionSummary>(GVSummary);
+ // Alias can't point to "available_externally". However when we import
+ // linkOnceODR the linkage does not change. So we import the alias
+ // and aliasee only in this case.
+ // FIXME: we should import alias as available_externally *function*,
+ // the destination module does need to know it is an alias.
+ if (!GlobalValue::isLinkOnceODRLinkage(GVSummary->linkage()))
+ return false;
+ }
- if (GlobalValue::isWeakAnyLinkage(Summary->linkage()))
- return false;
+ auto *Summary = cast<FunctionSummary>(GVSummary);
if (Summary->instCount() > Threshold)
return false;
@@ -166,16 +175,9 @@ static void computeImportForFunction(
if (isa<AliasSummary>(CalleeSummary)) {
ResolvedCalleeSummary = cast<FunctionSummary>(
&cast<AliasSummary>(CalleeSummary)->getAliasee());
- if (!GlobalValue::isLinkOnceODRLinkage(
- ResolvedCalleeSummary->linkage())) {
- // Alias can't point to "available_externally". However when we import
- // linkOnceODR the linkage does not change. So we import the alias
- // and aliasee only in this case.
- // FIXME: we should import alias as available_externally *function*, the
- // destination module does need to know it is an alias.
- DEBUG(dbgs() << "ignored! Aliasee is not linkonce_odr.\n");
- continue;
- }
+ assert(
+ GlobalValue::isLinkOnceODRLinkage(ResolvedCalleeSummary->linkage()) &&
+ "Unexpected alias to a non-linkonceODR in import list");
} else
ResolvedCalleeSummary = cast<FunctionSummary>(CalleeSummary);
Added: llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition1.ll?rev=266854&view=auto
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition1.ll (added)
+++ llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition1.ll Tue Apr 19 23:17:36 2016
@@ -0,0 +1,6 @@
+
+ at foo = weak alias i32 (...), bitcast (i32 ()* @foo1 to i32 (...)*)
+
+define i32 @foo1() {
+ ret i32 42
+}
\ No newline at end of file
Added: llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition2.ll?rev=266854&view=auto
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition2.ll (added)
+++ llvm/trunk/test/ThinLTO/X86/Inputs/select_right_alias_definition2.ll Tue Apr 19 23:17:36 2016
@@ -0,0 +1,7 @@
+
+ at foo = alias i32 (...), bitcast (i32 ()* @foo2 to i32 (...)*)
+
+define linkonce_odr i32 @foo2() {
+ %ret = add i32 42, 42
+ ret i32 %ret
+}
\ No newline at end of file
Added: llvm/trunk/test/ThinLTO/X86/select_right_alias_definition.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/select_right_alias_definition.ll?rev=266854&view=auto
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/select_right_alias_definition.ll (added)
+++ llvm/trunk/test/ThinLTO/X86/select_right_alias_definition.ll Tue Apr 19 23:17:36 2016
@@ -0,0 +1,27 @@
+; RUN: opt -module-summary %s -o %t_main.bc
+; RUN: opt -module-summary %p/Inputs/select_right_alias_definition1.ll -o %t1.bc
+; RUN: opt -module-summary %p/Inputs/select_right_alias_definition2.ll -o %t2.bc
+
+; Make sure that we always select the right definition for alia foo, whatever
+; order the files are linked in.
+
+; Try with one order
+; RUN: llvm-lto -thinlto-action=thinlink -o %t.index1.bc %t_main.bc %t1.bc %t2.bc
+; RUN: llvm-lto -thinlto-action=import -thinlto-index %t.index1.bc %t_main.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORT
+
+; Try with the other order (reversing %t1.bc and %t2.bc)
+; RUN: llvm-lto -thinlto-action=thinlink -o %t.index2.bc %t_main.bc %t2.bc %t1.bc
+; RUN: llvm-lto -thinlto-action=import -thinlto-index %t.index2.bc %t_main.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=IMPORT
+
+; IMPORT: @foo = alias i32 (...), bitcast (i32 ()* @foo2 to i32 (...)*)
+; IMPORT: define linkonce_odr i32 @foo2() {
+; IMPORT-NEXT: %ret = add i32 42, 42
+; IMPORT-NEXT: ret i32 %ret
+; IMPORT-NEXT: }
+
+declare i32 @foo()
+
+define i32 @main() {
+ %ret = call i32 @foo()
+ ret i32 %ret
+}
\ No newline at end of file
More information about the llvm-commits
mailing list