Skip to content

LLVM crash when using @llvm.prefetch IR on x86 #62839

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

Closed
Voultapher opened this issue May 21, 2023 · 7 comments · Fixed by llvm/llvm-project-release-prs#452
Closed

LLVM crash when using @llvm.prefetch IR on x86 #62839

Voultapher opened this issue May 21, 2023 · 7 comments · Fixed by llvm/llvm-project-release-prs#452
Assignees
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid] release:backport release:merged

Comments

@Voultapher
Copy link
Contributor

Voultapher commented May 21, 2023

Using this IR:

define void @prefetch(ptr %a) {
start:
  tail call void @llvm.prefetch.p0(ptr %a, i32 0, i32 0, i32 0)
  ret void
}

declare void @llvm.prefetch.p0(ptr, i32, i32, i32)

Happens on:

  • LLVM version: 16.0.4
  • Clang nightly

I get this crash backtrace:

warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
fatal error: error in backend: Cannot select: 0x557bbbeecb50: ch = Prefetch<(load (s8) from %ir.a)> 0x557bbbe8c890, 0x557bbbeeca70, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>
  0x557bbbeeca70: i64,ch = CopyFromReg 0x557bbbe8c890, Register:i64 %0
    0x557bbbeeca00: i64 = Register %0
  0x557bbbeecae0: i32 = Constant<0>
  0x557bbbeecae0: i32 = Constant<0>
  0x557bbbeecae0: i32 = Constant<0>
In function: prefetch
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -g -o /app/output.s -masm=intel -S -x ir -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>
1.	Code generation
2.	Running pass 'Function Pass Manager' on module '<source>'.
3.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@prefetch'
 #0 0x0000557bb2645bcf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x360dbcf)
 #1 0x0000557bb2643bfc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x360bbfc)
 #2 0x0000557bb2594d77 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x355cd77)
 #3 0x0000557bb263b7f2 llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x36037f2)
 #4 0x0000557bafeda3b6 (/opt/compiler-explorer/clang-trunk/bin/clang+++0xea23b6)
 #5 0x0000557bb259dd6a llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3565d6a)
 #6 0x0000557bb3665a60 llvm::SelectionDAGISel::CannotYetSelect(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x462da60)
 #7 0x0000557bb366b2d5 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x46332d5)
 #8 0x0000557bb12e781a (anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) X86ISelDAGToDAG.cpp:0:0
 #9 0x0000557bb3663007 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x462b007)
#10 0x0000557bb366f909 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4637909)
#11 0x0000557bb367269b llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x463a69b)
#12 0x0000557bb3674c96 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.0) SelectionDAGISel.cpp:0:0
#13 0x0000557bb12f1275 (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) X86ISelDAGToDAG.cpp:0:0
#14 0x0000557bb1abc680 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#15 0x0000557bb1fda42a llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2fa242a)
#16 0x0000557bb1fda5b9 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2fa25b9)
#17 0x0000557bb1fdb1a0 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x2fa31a0)
#18 0x0000557bb28b75d0 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x387f5d0)
#19 0x0000557bb37b3efe clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x477befe)
#20 0x0000557bb309e001 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4066001)
#21 0x0000557bb3022343 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3fea343)
#22 0x0000557bb317d2d3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x41452d3)
#23 0x0000557bafedb93c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xea393c)
#24 0x0000557bafed703f ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x0000557bb2e7f15d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#26 0x0000557bb2594c67 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x355cc67)
#27 0x0000557bb2e7f39c clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#28 0x0000557bb2e46dde clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e0edde)
#29 0x0000557bb2e477ad clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e0f7ad)
#30 0x0000557bb2e51e7c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3e19e7c)
#31 0x0000557bafed953f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xea153f)
#32 0x0000557bafdd72e5 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd9f2e5)
#33 0x00007f48337c3083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#34 0x0000557bafed331e _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xe9b31e)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
ASM generation compiler returned: 70
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
fatal error: error in backend: Cannot select: 0x562b297f27f0: ch = Prefetch<(load (s8) from %ir.a)> 0x562b2975e970, 0x562b297f2710, Constant:i32<0>, Constant:i32<0>, Constant:i32<0>
  0x562b297f2710: i64,ch = CopyFromReg 0x562b2975e970, Register:i64 %0
    0x562b297f26a0: i64 = Register %0
  0x562b297f2780: i32 = Constant<0>
  0x562b297f2780: i32 = Constant<0>
  0x562b297f2780: i32 = Constant<0>
In function: prefetch
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Execution build compiler returned: 70

This breaks prefetch intrinsics in other languages, e.g. rust-lang/rust#111823

@Voultapher Voultapher changed the title LLVM crash when @llvm.prefetch IR on x86 LLVM crash when @llvm.prefetch IR on x86 May 21, 2023
@topperc topperc self-assigned this May 21, 2023
@topperc
Copy link
Collaborator

topperc commented May 21, 2023

Candidate patch https://reviews.llvm.org/D151050

@Voultapher Voultapher changed the title LLVM crash when @llvm.prefetch IR on x86 LLVM crash when using @llvm.prefetch IR on x86 May 21, 2023
@Voultapher
Copy link
Contributor Author

Wow that was faster than expected.

@EugeneZelenko EugeneZelenko added backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels May 21, 2023
@llvmbot
Copy link
Member

llvmbot commented May 21, 2023

@llvm/issue-subscribers-backend-x86

@topperc
Copy link
Collaborator

topperc commented May 22, 2023

Fixed by 022aefa

@nikic
Copy link
Contributor

nikic commented May 22, 2023

/cherry-pick 022aefa

@llvmbot
Copy link
Member

llvmbot commented May 22, 2023

/branch llvm/llvm-project-release-prs/issue62839

@llvmbot
Copy link
Member

llvmbot commented May 22, 2023

/pull-request llvm/llvm-project-release-prs#452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 crash Prefer [crash-on-valid] or [crash-on-invalid] release:backport release:merged
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants