Skip to content

[NFC]Update a ThinLTO test case #117584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 3, 2024
Merged

Conversation

mingmingl-llvm
Copy link
Contributor

@mingmingl-llvm mingmingl-llvm commented Nov 25, 2024

Run function-import pass in a similar way that it runs in a ThinLTO distributed backend compile and checks that function alias is imported as a definition. More accurately, the function alias is a clone of the aliasee function.

@llvmbot llvmbot added the LTO Link time optimization (regular/full LTO or ThinLTO) label Nov 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2024

@llvm/pr-subscribers-lto

Author: Mingming Liu (mingmingl-llvm)

Changes

The ThinLTO indexing step can import a function alias without importing its aliasee, making aliasee:null in the summary. The backend compile will crash in function-import pass when trying to get aliasee of the alias. The crash stack up to FunctionImportPass::run is pasted below.

This patch updates the existing tests to reflect this.

0.      Program arguments: /home/tmp/llvm-type-profiling/llvm-project/build/bin/opt -passes=function-import -summary-file=/home/tmp/llvm-type-profiling/llvm-project/build/test/ThinLTO/X86/Output/distributed_indexes.ll.tmp1.bc.thinlto.bc /home/tmp/llvm-type-profiling/llvm-project/build/test/ThinLTO/X86/Output/distributed_indexes.ll.tmp1.bc -o /dev/null
1.      Running pass "function-import" on module "/home/tmp/llvm-type-profiling/llvm-project/build/test/ThinLTO/X86/Output/distributed_indexes.ll.tmp1.bc"
 #<!-- -->0 0x0000563eaf4dbf74 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #<!-- -->1 0x0000563eaf4dc3b2 PrintStackTraceSignalHandler(void*) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #<!-- -->2 0x0000563eaf4d9b38 llvm::sys::RunSignalHandlers() /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #<!-- -->3 0x0000563eaf4db950 SignalHandler(int) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #<!-- -->4 0x00007f8cdef74590 (/lib/x86_64-linux-gnu/libc.so.6+0x3f590)
 #<!-- -->5 0x00007f8cdefc33ac __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #<!-- -->6 0x00007f8cdef744f2 raise ./signal/../sysdeps/posix/raise.c:27:6
 #<!-- -->7 0x00007f8cdef5d4ed abort ./stdlib/abort.c:81:7
 #<!-- -->8 0x00007f8cdef5d415 _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #<!-- -->9 0x00007f8cdef6d012 (/lib/x86_64-linux-gnu/libc.so.6+0x38012)
#<!-- -->10 0x0000563eaf66150b llvm::AliasSummary::getAliasee() const /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:689:13
#<!-- -->11 0x0000563eaf8bff26 llvm::AliasSummary::getAliasee() /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:695:3
#<!-- -->12 0x0000563eaf8c008d llvm::GlobalValueSummary::getBaseObject() /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:714:28
#<!-- -->13 0x0000563eb1ccbcf7 qualifyCalleeCandidates(llvm::ModuleSummaryIndex const&amp;, llvm::ArrayRef&lt;std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt;&gt;, llvm::StringRef)::'lambda'(std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt; const&amp;)::operator()(std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt; const&amp;) const /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:238:50
#<!-- -->14 0x0000563eb1cd45ff decltype(auto) llvm::callable_detail::Callable&lt;qualifyCalleeCandidates(llvm::ModuleSummaryIndex const&amp;, llvm::ArrayRef&lt;std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt;&gt;, llvm::StringRef)::'lambda'(std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt; const&amp;), false&gt;::operator()&lt;std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt; const&amp;, 0&gt;(std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt; const&amp;) const /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/ADT/STLExtras.h:250:18
#<!-- -->15 0x0000563eb1cd4636 llvm::mapped_iterator&lt;std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt; const*, qualifyCalleeCandidates(llvm::ModuleSummaryIndex const&amp;, llvm::ArrayRef&lt;std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt;&gt;, llvm::StringRef)::'lambda'(std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt; const&amp;), std::pair&lt;llvm::FunctionImporter::ImportFailureReason, llvm::GlobalValueSummary const*&gt;&gt;::operator*() const /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/ADT/STLExtras.h:363:43
#<!-- -->16 0x0000563eb1ccc0f6 selectCallee(llvm::ModuleSummaryIndex const&amp;, llvm::ArrayRef&lt;std::unique_ptr&lt;llvm::GlobalValueSummary, std::default_delete&lt;llvm::GlobalValueSummary&gt;&gt;&gt;, unsigned int, llvm::StringRef, llvm::GlobalValueSummary const*&amp;, llvm::FunctionImporter::ImportFailureReason&amp;) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:301:30
#<!-- -->17 0x0000563eb1ccd436 computeImportForFunction(llvm::FunctionSummary const&amp;, llvm::ModuleSummaryIndex const&amp;, unsigned int, llvm::DenseMap&lt;unsigned long, llvm::GlobalValueSummary*, llvm::DenseMapInfo&lt;unsigned long, void&gt;, llvm::detail::DenseMapPair&lt;unsigned long, llvm::GlobalValueSummary*&gt;&gt; const&amp;, llvm::function_ref&lt;bool (unsigned long, llvm::GlobalValueSummary const*)&gt;, llvm::SmallVectorImpl&lt;std::tuple&lt;llvm::FunctionSummary const*, unsigned int&gt;&gt;&amp;, GlobalsImporter&amp;, llvm::FunctionImporter::ImportMapTy&amp;, llvm::DenseMap&lt;llvm::StringRef, llvm::DenseSet&lt;llvm::ValueInfo, llvm::DenseMapInfo&lt;llvm::ValueInfo, void&gt;&gt;, llvm::DenseMapInfo&lt;llvm::StringRef, void&gt;, llvm::detail::DenseMapPair&lt;llvm::StringRef, llvm::DenseSet&lt;llvm::ValueInfo, llvm::DenseMapInfo&lt;llvm::ValueInfo, void&gt;&gt;&gt;&gt;*, llvm::DenseMap&lt;unsigned long, std::tuple&lt;unsigned int, llvm::GlobalValueSummary const*, std::unique_ptr&lt;llvm::FunctionImporter::ImportFailureInfo, std::default_delete&lt;llvm::FunctionImporter::ImportFailureInfo&gt;&gt;&gt;, llvm::DenseMapInfo&lt;unsigned long, void&gt;, llvm::detail::DenseMapPair&lt;unsigned long, std::tuple&lt;unsigned int, llvm::GlobalValueSummary const*, std::unique_ptr&lt;llvm::FunctionImporter::ImportFailureInfo, std::default_delete&lt;llvm::FunctionImporter::ImportFailureInfo&gt;&gt;&gt;&gt;&gt;&amp;) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:916:23
#<!-- -->18 0x0000563eb1ccdde5 ModuleImportsManager::computeImportForModule(llvm::DenseMap&lt;unsigned long, llvm::GlobalValueSummary*, llvm::DenseMapInfo&lt;unsigned long, void&gt;, llvm::detail::DenseMapPair&lt;unsigned long, llvm::GlobalValueSummary*&gt;&gt; const&amp;, llvm::StringRef, llvm::FunctionImporter::ImportMapTy&amp;) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:1037:29
#<!-- -->19 0x0000563eb1ccf9fa ComputeCrossModuleImportForModuleForTest(llvm::StringRef, llvm::function_ref&lt;bool (unsigned long, llvm::GlobalValueSummary const*)&gt;, llvm::ModuleSummaryIndex const&amp;, llvm::FunctionImporter::ImportMapTy&amp;) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:1309:26
#<!-- -->20 0x0000563eb1cd3e1b doImportingForModuleForTest(llvm::Module&amp;, llvm::function_ref&lt;bool (unsigned long, llvm::GlobalValueSummary const*)&gt;) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:2013:19
#<!-- -->21 0x0000563eb1cd4189 llvm::FunctionImportPass::run(llvm::Module&amp;, llvm::AnalysisManager&lt;llvm::Module&gt;&amp;) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:2055:7

Full diff: https://github.com/llvm/llvm-project/pull/117584.diff

2 Files Affected:

  • (modified) llvm/test/ThinLTO/X86/distributed_indexes.ll (+4)
  • (modified) llvm/test/ThinLTO/X86/import_callee_declaration.ll (+4)
diff --git a/llvm/test/ThinLTO/X86/distributed_indexes.ll b/llvm/test/ThinLTO/X86/distributed_indexes.ll
index 4f2662b1b34e1b..b70342fd0c96f5 100644
--- a/llvm/test/ThinLTO/X86/distributed_indexes.ll
+++ b/llvm/test/ThinLTO/X86/distributed_indexes.ll
@@ -48,6 +48,10 @@
 ; RUN: llvm-dis %t1.bc.thinlto.bc -o - | FileCheck %s --check-prefix=DIS
 ; DIS: aliasee: null
 
+; function-import pass crashed when alias is imported but aliasee doesn't.
+; TODO: Import both alias and aliasee, or neither of them.
+; RUN: not --crash opt -passes=function-import -summary-file=%t1.bc.thinlto.bc %t1.bc -o /dev/null 2>&1
+
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 
 declare void @g(...)
diff --git a/llvm/test/ThinLTO/X86/import_callee_declaration.ll b/llvm/test/ThinLTO/X86/import_callee_declaration.ll
index 246920e5db0dc8..96257214c0a1af 100644
--- a/llvm/test/ThinLTO/X86/import_callee_declaration.ll
+++ b/llvm/test/ThinLTO/X86/import_callee_declaration.ll
@@ -62,6 +62,10 @@
 ; these two GUIDs are declaration.
 ;
 ; RUN: llvm-dis main.bc.thinlto.bc -o - | FileCheck %s --check-prefix=MAIN-DIS
+
+; function-import pass crashed when alias is imported but aliasee doesn't.
+; TODO: Import both alias and aliasee, or neither of them.
+; RUN: not --crash opt -passes=function-import -summary-file=main.bc.thinlto.bc main.bc -o /dev/null 2>&1
 ;
 ; MAIN-DIS: [[LIBMOD:\^[0-9]+]] = module: (path: "lib.bc", hash: (0, 0, 0, 0, 0))
 ; MAIN-DIS: gv: (guid: 2418497564662708935, summaries: (function: (module: [[LIBMOD]], flags: ({{.*}} importType: declaration), insts: 8, {{.*}})))

@teresajohnson
Copy link
Contributor

The ThinLTO indexing step can import a function alias without importing its aliasee, making aliasee:null in the summary. The backend compile will crash in function-import pass when trying to get aliasee of the alias. The crash stack up to FunctionImportPass::run is pasted below.

I'm confused as to what is happening here. The below crash is when we are computing imports, not after importing. The function importer should import an alias as a copy of its aliasee when it actually does the IR importing, but the below crash seems earlier. Hmm, it looks like you are trying to run the function import pass, which is just for testing, using the distributed ThinLTO index files. We shouldn't use these for computing imports. What are you trying to do here?

This patch updates the existing tests to reflect this.

0.      Program arguments: /home/tmp/llvm-type-profiling/llvm-project/build/bin/opt -passes=function-import -summary-file=/home/tmp/llvm-type-profiling/llvm-project/build/test/ThinLTO/X86/Output/distributed_indexes.ll.tmp1.bc.thinlto.bc /home/tmp/llvm-type-profiling/llvm-project/build/test/ThinLTO/X86/Output/distributed_indexes.ll.tmp1.bc -o /dev/null
1.      Running pass "function-import" on module "/home/tmp/llvm-type-profiling/llvm-project/build/test/ThinLTO/X86/Output/distributed_indexes.ll.tmp1.bc"
 #0 0x0000563eaf4dbf74 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x0000563eaf4dc3b2 PrintStackTraceSignalHandler(void*) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x0000563eaf4d9b38 llvm::sys::RunSignalHandlers() /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x0000563eaf4db950 SignalHandler(int) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f8cdef74590 (/lib/x86_64-linux-gnu/libc.so.6+0x3f590)
 #5 0x00007f8cdefc33ac __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f8cdef744f2 raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007f8cdef5d4ed abort ./stdlib/abort.c:81:7
 #8 0x00007f8cdef5d415 _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007f8cdef6d012 (/lib/x86_64-linux-gnu/libc.so.6+0x38012)
#10 0x0000563eaf66150b llvm::AliasSummary::getAliasee() const /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:689:13
#11 0x0000563eaf8bff26 llvm::AliasSummary::getAliasee() /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:695:3
#12 0x0000563eaf8c008d llvm::GlobalValueSummary::getBaseObject() /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:714:28
#13 0x0000563eb1ccbcf7 qualifyCalleeCandidates(llvm::ModuleSummaryIndex const&, llvm::ArrayRef<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>>>, llvm::StringRef)::'lambda'(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&)::operator()(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&) const /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:238:50
#14 0x0000563eb1cd45ff decltype(auto) llvm::callable_detail::Callable<qualifyCalleeCandidates(llvm::ModuleSummaryIndex const&, llvm::ArrayRef<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>>>, llvm::StringRef)::'lambda'(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&), false>::operator()<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&, 0>(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&) const /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/ADT/STLExtras.h:250:18
#15 0x0000563eb1cd4636 llvm::mapped_iterator<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const*, qualifyCalleeCandidates(llvm::ModuleSummaryIndex const&, llvm::ArrayRef<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>>>, llvm::StringRef)::'lambda'(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&), std::pair<llvm::FunctionImporter::ImportFailureReason, llvm::GlobalValueSummary const*>>::operator*() const /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/ADT/STLExtras.h:363:43
#16 0x0000563eb1ccc0f6 selectCallee(llvm::ModuleSummaryIndex const&, llvm::ArrayRef<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>>>, unsigned int, llvm::StringRef, llvm::GlobalValueSummary const*&, llvm::FunctionImporter::ImportFailureReason&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:301:30
#17 0x0000563eb1ccd436 computeImportForFunction(llvm::FunctionSummary const&, llvm::ModuleSummaryIndex const&, unsigned int, llvm::DenseMap<unsigned long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long, void>, llvm::detail::DenseMapPair<unsigned long, llvm::GlobalValueSummary*>> const&, llvm::function_ref<bool (unsigned long, llvm::GlobalValueSummary const*)>, llvm::SmallVectorImpl<std::tuple<llvm::FunctionSummary const*, unsigned int>>&, GlobalsImporter&, llvm::FunctionImporter::ImportMapTy&, llvm::DenseMap<llvm::StringRef, llvm::DenseSet<llvm::ValueInfo, llvm::DenseMapInfo<llvm::ValueInfo, void>>, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, llvm::DenseSet<llvm::ValueInfo, llvm::DenseMapInfo<llvm::ValueInfo, void>>>>*, llvm::DenseMap<unsigned long, std::tuple<unsigned int, llvm::GlobalValueSummary const*, std::unique_ptr<llvm::FunctionImporter::ImportFailureInfo, std::default_delete<llvm::FunctionImporter::ImportFailureInfo>>>, llvm::DenseMapInfo<unsigned long, void>, llvm::detail::DenseMapPair<unsigned long, std::tuple<unsigned int, llvm::GlobalValueSummary const*, std::unique_ptr<llvm::FunctionImporter::ImportFailureInfo, std::default_delete<llvm::FunctionImporter::ImportFailureInfo>>>>>&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:916:23
#18 0x0000563eb1ccdde5 ModuleImportsManager::computeImportForModule(llvm::DenseMap<unsigned long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long, void>, llvm::detail::DenseMapPair<unsigned long, llvm::GlobalValueSummary*>> const&, llvm::StringRef, llvm::FunctionImporter::ImportMapTy&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:1037:29
#19 0x0000563eb1ccf9fa ComputeCrossModuleImportForModuleForTest(llvm::StringRef, llvm::function_ref<bool (unsigned long, llvm::GlobalValueSummary const*)>, llvm::ModuleSummaryIndex const&, llvm::FunctionImporter::ImportMapTy&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:1309:26
#20 0x0000563eb1cd3e1b doImportingForModuleForTest(llvm::Module&, llvm::function_ref<bool (unsigned long, llvm::GlobalValueSummary const*)>) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:2013:19
#21 0x0000563eb1cd4189 llvm::FunctionImportPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:2055:7

@teresajohnson
Copy link
Contributor

The ThinLTO indexing step can import a function alias without importing its aliasee, making aliasee:null in the summary. The backend compile will crash in function-import pass when trying to get aliasee of the alias. The crash stack up to FunctionImportPass::run is pasted below.

I'm confused as to what is happening here. The below crash is when we are computing imports, not after importing. The function importer should import an alias as a copy of its aliasee when it actually does the IR importing, but the below crash seems earlier. Hmm, it looks like you are trying to run the function import pass, which is just for testing, using the distributed ThinLTO index files. We shouldn't use these for computing imports. What are you trying to do here?

Ah, I assume you are trying to simulate a ThinLTO distributed backend. Add "-import-all-index" to your opt invocation. This will do what a ThinLTO distributed backend will do and blindly follow the importing decisions encoded in the sharded index file, rather than trying to recompute the import decisions. See for example the invocations in llvm/test/ThinLTO/X86/distributed_import.ll.

This patch updates the existing tests to reflect this.

0.      Program arguments: /home/tmp/llvm-type-profiling/llvm-project/build/bin/opt -passes=function-import -summary-file=/home/tmp/llvm-type-profiling/llvm-project/build/test/ThinLTO/X86/Output/distributed_indexes.ll.tmp1.bc.thinlto.bc /home/tmp/llvm-type-profiling/llvm-project/build/test/ThinLTO/X86/Output/distributed_indexes.ll.tmp1.bc -o /dev/null
1.      Running pass "function-import" on module "/home/tmp/llvm-type-profiling/llvm-project/build/test/ThinLTO/X86/Output/distributed_indexes.ll.tmp1.bc"
 #0 0x0000563eaf4dbf74 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x0000563eaf4dc3b2 PrintStackTraceSignalHandler(void*) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x0000563eaf4d9b38 llvm::sys::RunSignalHandlers() /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x0000563eaf4db950 SignalHandler(int) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f8cdef74590 (/lib/x86_64-linux-gnu/libc.so.6+0x3f590)
 #5 0x00007f8cdefc33ac __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f8cdef744f2 raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007f8cdef5d4ed abort ./stdlib/abort.c:81:7
 #8 0x00007f8cdef5d415 _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007f8cdef6d012 (/lib/x86_64-linux-gnu/libc.so.6+0x38012)
#10 0x0000563eaf66150b llvm::AliasSummary::getAliasee() const /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:689:13
#11 0x0000563eaf8bff26 llvm::AliasSummary::getAliasee() /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:695:3
#12 0x0000563eaf8c008d llvm::GlobalValueSummary::getBaseObject() /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/IR/ModuleSummaryIndex.h:714:28
#13 0x0000563eb1ccbcf7 qualifyCalleeCandidates(llvm::ModuleSummaryIndex const&, llvm::ArrayRef<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>>>, llvm::StringRef)::'lambda'(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&)::operator()(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&) const /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:238:50
#14 0x0000563eb1cd45ff decltype(auto) llvm::callable_detail::Callable<qualifyCalleeCandidates(llvm::ModuleSummaryIndex const&, llvm::ArrayRef<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>>>, llvm::StringRef)::'lambda'(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&), false>::operator()<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&, 0>(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&) const /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/ADT/STLExtras.h:250:18
#15 0x0000563eb1cd4636 llvm::mapped_iterator<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const*, qualifyCalleeCandidates(llvm::ModuleSummaryIndex const&, llvm::ArrayRef<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>>>, llvm::StringRef)::'lambda'(std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>> const&), std::pair<llvm::FunctionImporter::ImportFailureReason, llvm::GlobalValueSummary const*>>::operator*() const /home/tmp/llvm-type-profiling/llvm-project/llvm/include/llvm/ADT/STLExtras.h:363:43
#16 0x0000563eb1ccc0f6 selectCallee(llvm::ModuleSummaryIndex const&, llvm::ArrayRef<std::unique_ptr<llvm::GlobalValueSummary, std::default_delete<llvm::GlobalValueSummary>>>, unsigned int, llvm::StringRef, llvm::GlobalValueSummary const*&, llvm::FunctionImporter::ImportFailureReason&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:301:30
#17 0x0000563eb1ccd436 computeImportForFunction(llvm::FunctionSummary const&, llvm::ModuleSummaryIndex const&, unsigned int, llvm::DenseMap<unsigned long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long, void>, llvm::detail::DenseMapPair<unsigned long, llvm::GlobalValueSummary*>> const&, llvm::function_ref<bool (unsigned long, llvm::GlobalValueSummary const*)>, llvm::SmallVectorImpl<std::tuple<llvm::FunctionSummary const*, unsigned int>>&, GlobalsImporter&, llvm::FunctionImporter::ImportMapTy&, llvm::DenseMap<llvm::StringRef, llvm::DenseSet<llvm::ValueInfo, llvm::DenseMapInfo<llvm::ValueInfo, void>>, llvm::DenseMapInfo<llvm::StringRef, void>, llvm::detail::DenseMapPair<llvm::StringRef, llvm::DenseSet<llvm::ValueInfo, llvm::DenseMapInfo<llvm::ValueInfo, void>>>>*, llvm::DenseMap<unsigned long, std::tuple<unsigned int, llvm::GlobalValueSummary const*, std::unique_ptr<llvm::FunctionImporter::ImportFailureInfo, std::default_delete<llvm::FunctionImporter::ImportFailureInfo>>>, llvm::DenseMapInfo<unsigned long, void>, llvm::detail::DenseMapPair<unsigned long, std::tuple<unsigned int, llvm::GlobalValueSummary const*, std::unique_ptr<llvm::FunctionImporter::ImportFailureInfo, std::default_delete<llvm::FunctionImporter::ImportFailureInfo>>>>>&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:916:23
#18 0x0000563eb1ccdde5 ModuleImportsManager::computeImportForModule(llvm::DenseMap<unsigned long, llvm::GlobalValueSummary*, llvm::DenseMapInfo<unsigned long, void>, llvm::detail::DenseMapPair<unsigned long, llvm::GlobalValueSummary*>> const&, llvm::StringRef, llvm::FunctionImporter::ImportMapTy&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:1037:29
#19 0x0000563eb1ccf9fa ComputeCrossModuleImportForModuleForTest(llvm::StringRef, llvm::function_ref<bool (unsigned long, llvm::GlobalValueSummary const*)>, llvm::ModuleSummaryIndex const&, llvm::FunctionImporter::ImportMapTy&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:1309:26
#20 0x0000563eb1cd3e1b doImportingForModuleForTest(llvm::Module&, llvm::function_ref<bool (unsigned long, llvm::GlobalValueSummary const*)>) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:2013:19
#21 0x0000563eb1cd4189 llvm::FunctionImportPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/tmp/llvm-type-profiling/llvm-project/llvm/lib/Transforms/IPO/FunctionImport.cpp:2055:7

…dexes.ll. Revert changes to import_callee_declaration.ll
@mingmingl-llvm mingmingl-llvm changed the title [NFC]Update test case [NFC]Update a ThinLTO test case Dec 2, 2024
@mingmingl-llvm
Copy link
Contributor Author

Ah, I assume you are trying to simulate a ThinLTO distributed backend.

Yes, this is exactly what opt -passes=function-import tries to simulate.

Add "-import-all-index" to your opt invocation. This will do what a ThinLTO distributed backend will do and blindly follow the importing decisions encoded in the sharded index file, rather than trying to recompute the import decisions. See for example the invocations in llvm/test/ThinLTO/X86/distributed_import.ll.

Thanks! I added -import-all-index and updated distributed_indexes.ll. I reverted the change to import_callee_declaration.ll in this PR as there isn't much to test in the IR (except that the opt command shouldn't crash, but distributed_index.ll does this already).

@teresajohnson
Copy link
Contributor

Ah, I assume you are trying to simulate a ThinLTO distributed backend.

Yes, this is exactly what opt -passes=function-import tries to simulate.

Sort of, it only simulates a distributed ThinLTO backend with "-import-all-index". Without that it is expecting a combined index, and makes importing decisions on the original index.

Add "-import-all-index" to your opt invocation. This will do what a ThinLTO distributed backend will do and blindly follow the importing decisions encoded in the sharded index file, rather than trying to recompute the import decisions. See for example the invocations in llvm/test/ThinLTO/X86/distributed_import.ll.

Thanks! I added -import-all-index and updated distributed_indexes.ll. I reverted the change to import_callee_declaration.ll in this PR as there isn't much to test in the IR (except that the opt command shouldn't crash, but distributed_index.ll does this already).

@@ -48,6 +48,13 @@
; RUN: llvm-dis %t1.bc.thinlto.bc -o - | FileCheck %s --check-prefix=DIS
; DIS: aliasee: null

; function-import pass crashed when alias is imported but aliasee doesn't.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the comment and TODO can now be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the catch! Removed the outdated comments.

@mingmingl-llvm mingmingl-llvm merged commit b2dd4fa into main Dec 3, 2024
5 of 8 checks passed
@mingmingl-llvm mingmingl-llvm deleted the users/minglotus-6/spr/alias branch December 3, 2024 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants