llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.28k stars 12.1k forks source link

Crash using -O3 and arm neon #107810

Open MarkReedZ opened 2 months ago

MarkReedZ commented 2 months ago

I'd appreciate any tip on moving the code around to avoid this.

bench-82d8ec.sh.txt bench-82d8ec.cpp.txt

Code: https://github.com/MarkReedZ/SimSIMD/commit/09e89bb71e37b7e120a34f19012d3fc2b13183f4

Output

/usr/bin/clang++ -DSIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS=1 -I/home/ubuntu/SimSIMD/include -I/home/ubuntu/SimSIMD/build_release/_deps/benchmark-src/include -I/home/ubuntu/SimSIMD/build_release/_deps/benchmark-build/include -O3 -std=c++17 -march=native -pedantic -ferror-limit=1 -MD -MT CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o -MF CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o.d -o CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o -c /home/ubuntu/SimSIMD/cpp/bench.cxx
In file included from /home/ubuntu/SimSIMD/cpp/bench.cxx:26:
In file included from /home/ubuntu/SimSIMD/include/simsimd/simsimd.h:111:
In file included from /home/ubuntu/SimSIMD/include/simsimd/binary.h:21:
/home/ubuntu/SimSIMD/include/simsimd/types.h:279:2: warning: #warning is a C++23 extension [-Wpedantic]
  279 | #warning "Unknown compiler or architecture for bfloat16."
      |  ^
/home/ubuntu/SimSIMD/include/simsimd/types.h:279:2: warning: "Unknown compiler or architecture for bfloat16." [-W#warnings]
fatal error: error in backend: Cannot select: 0xc436a2f2a660: v8bf16 = fneg 0xc436a212fa20
  0xc436a212fa20: v8bf16 = bitcast 0xc436a2040130
    0xc436a2040130: v8i16,i64,ch = load<(load (s128) from %ir.8, align 2), <post-inc>> 0xc436a5911010, 0xc436a3a26190, Constant:i64<16>
      0xc436a3a26190: i64,ch = CopyFromReg 0xc436a5911010, Register:i64 %0
        0xc436a2f2ae40: i64 = Register %0
      0xc436a34f11a0: i64 = Constant<16>
In function: _ZL22simsimd_dot_bf16c_neonPKtS0_yPd
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: /usr/bin/clang++ -DSIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS=1 -I/home/ubuntu/SimSIMD/include -I/home/ubuntu/SimSIMD/build_release/_deps/benchmark-src/include -I/home/ubuntu/SimSIMD/build_release/_deps/benchmark-build/include -O3 -std=c++17 -march=native -pedantic -ferror-limit=1 -MD -MT CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o -MF CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o.d -o CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o -c /home/ubuntu/SimSIMD/cpp/bench.cxx
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module '/home/ubuntu/SimSIMD/cpp/bench.cxx'.
4.  Running pass 'AArch64 Instruction Selection' on function '@_ZL22simsimd_dot_bf16c_neonPKtS0_yPd'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM.so.18.1      0x0000e37d3259d398 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 84
1  libLLVM.so.18.1      0x0000e37d3259b5a8 llvm::sys::RunSignalHandlers() + 116
2  libLLVM.so.18.1      0x0000e37d324eb17c
3  libLLVM.so.18.1      0x0000e37d324eb128
4  libLLVM.so.18.1      0x0000e37d32597fcc llvm::sys::Process::Exit(int, bool) + 52
5  clang++              0x0000c43678342560
6  libLLVM.so.18.1      0x0000e37d324f8a20 llvm::report_fatal_error(llvm::Twine const&, bool) + 248
7  libLLVM.so.18.1      0x0000e37d32d8b8b8 llvm::SelectionDAGISel::isOrEquivalentToAdd(llvm::SDNode const*) const + 0
8  libLLVM.so.18.1      0x0000e37d32d8ae08 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) + 13284
9  libLLVM.so.18.1      0x0000e37d341d0250
10 libLLVM.so.18.1      0x0000e37d32d83c54 llvm::SelectionDAGISel::DoInstructionSelection() + 344
11 libLLVM.so.18.1      0x0000e37d32d8343c llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 900
12 libLLVM.so.18.1      0x0000e37d32d82a98 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 3980
13 libLLVM.so.18.1      0x0000e37d32d80f14 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1496
14 libLLVM.so.18.1      0x0000e37d3295aef0 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 680
15 libLLVM.so.18.1      0x0000e37d326f5af4 llvm::FPPassManager::runOnFunction(llvm::Function&) + 580
16 libLLVM.so.18.1      0x0000e37d326fb070 llvm::FPPassManager::runOnModule(llvm::Module&) + 64
17 libLLVM.so.18.1      0x0000e37d326f60d8 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 868
18 libclang-cpp.so.18.1 0x0000e37d3a80bc64 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>>, clang::BackendConsumer*) + 2688
19 libclang-cpp.so.18.1 0x0000e37d3ab25f58 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1180
20 libclang-cpp.so.18.1 0x0000e37d3978a5b0 clang::ParseAST(clang::Sema&, bool, bool) + 572
21 libclang-cpp.so.18.1 0x0000e37d3b53fa34 clang::FrontendAction::Execute() + 112
22 libclang-cpp.so.18.1 0x0000e37d3b4d0590 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 744
23 libclang-cpp.so.18.1 0x0000e37d3b5b8e4c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 616
24 clang++              0x0000c436783421c4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 3360
25 clang++              0x0000c4367833fbac
26 libclang-cpp.so.18.1 0x0000e37d3b1ca950
27 libLLVM.so.18.1      0x0000e37d324eb0f8 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 168
28 libclang-cpp.so.18.1 0x0000e37d3b1ca1bc clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 352
29 libclang-cpp.so.18.1 0x0000e37d3b198d3c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 756
30 libclang-cpp.so.18.1 0x0000e37d3b198f4c clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 136
31 libclang-cpp.so.18.1 0x0000e37d3b1b12f4 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 324
32 clang++              0x0000c4367833f344 clang_main(int, char**, llvm::ToolContext const&) + 9756
33 clang++              0x0000c4367834ae40 main + 92
34 libc.so.6            0x0000e37d3caa84c4
35 libc.so.6            0x0000e37d3caa8598 __libc_start_main + 152
36 clang++              0x0000c4367833c970 _start + 48
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang++: note: diagnostic msg: 
********************

To repro on an AWS c7g

    sudo apt-get update && sudo apt-get install cmake build-essential libjemalloc-dev g++-13 gcc-13 clang libopenblas-dev -y
    git clone https://github.com/MarkReedZ/SimSIMD.git
    cd SimSIMD/
    git fetch && git checkout dot_bf16c_neon

    cmake -D CMAKE_BUILD_TYPE=Release -D SIMSIMD_BUILD_TESTS=1 -D SIMSIMD_BUILD_BENCHMARKS=1 -D SIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS=1  -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -D CMAKE_C_COMPILER="/usr/bin/clang" -D CMAKE_CXX_COMPILER="/usr/bin/clang++" -B build_release
    cmake --build build_release
llvmbot commented 2 months ago

@llvm/issue-subscribers-backend-aarch64

Author: Mark Reed (MarkReedZ)

I'd appreciate any tip on moving the code around to avoid this. [bench-82d8ec.sh.txt](https://github.com/user-attachments/files/16925916/bench-82d8ec.sh.txt) [bench-82d8ec.cpp.txt](https://github.com/user-attachments/files/16925917/bench-82d8ec.cpp.txt) Code: https://github.com/MarkReedZ/SimSIMD/commit/09e89bb71e37b7e120a34f19012d3fc2b13183f4 Output ``` /usr/bin/clang++ -DSIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS=1 -I/home/ubuntu/SimSIMD/include -I/home/ubuntu/SimSIMD/build_release/_deps/benchmark-src/include -I/home/ubuntu/SimSIMD/build_release/_deps/benchmark-build/include -O3 -std=c++17 -march=native -pedantic -ferror-limit=1 -MD -MT CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o -MF CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o.d -o CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o -c /home/ubuntu/SimSIMD/cpp/bench.cxx In file included from /home/ubuntu/SimSIMD/cpp/bench.cxx:26: In file included from /home/ubuntu/SimSIMD/include/simsimd/simsimd.h:111: In file included from /home/ubuntu/SimSIMD/include/simsimd/binary.h:21: /home/ubuntu/SimSIMD/include/simsimd/types.h:279:2: warning: #warning is a C++23 extension [-Wpedantic] 279 | #warning "Unknown compiler or architecture for bfloat16." | ^ /home/ubuntu/SimSIMD/include/simsimd/types.h:279:2: warning: "Unknown compiler or architecture for bfloat16." [-W#warnings] fatal error: error in backend: Cannot select: 0xc436a2f2a660: v8bf16 = fneg 0xc436a212fa20 0xc436a212fa20: v8bf16 = bitcast 0xc436a2040130 0xc436a2040130: v8i16,i64,ch = load<(load (s128) from %ir.8, align 2), <post-inc>> 0xc436a5911010, 0xc436a3a26190, Constant:i64<16> 0xc436a3a26190: i64,ch = CopyFromReg 0xc436a5911010, Register:i64 %0 0xc436a2f2ae40: i64 = Register %0 0xc436a34f11a0: i64 = Constant<16> In function: _ZL22simsimd_dot_bf16c_neonPKtS0_yPd 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: /usr/bin/clang++ -DSIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS=1 -I/home/ubuntu/SimSIMD/include -I/home/ubuntu/SimSIMD/build_release/_deps/benchmark-src/include -I/home/ubuntu/SimSIMD/build_release/_deps/benchmark-build/include -O3 -std=c++17 -march=native -pedantic -ferror-limit=1 -MD -MT CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o -MF CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o.d -o CMakeFiles/simsimd_bench.dir/cpp/bench.cxx.o -c /home/ubuntu/SimSIMD/cpp/bench.cxx 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module '/home/ubuntu/SimSIMD/cpp/bench.cxx'. 4. Running pass 'AArch64 Instruction Selection' on function '@_ZL22simsimd_dot_bf16c_neonPKtS0_yPd' Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 libLLVM.so.18.1 0x0000e37d3259d398 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 84 1 libLLVM.so.18.1 0x0000e37d3259b5a8 llvm::sys::RunSignalHandlers() + 116 2 libLLVM.so.18.1 0x0000e37d324eb17c 3 libLLVM.so.18.1 0x0000e37d324eb128 4 libLLVM.so.18.1 0x0000e37d32597fcc llvm::sys::Process::Exit(int, bool) + 52 5 clang++ 0x0000c43678342560 6 libLLVM.so.18.1 0x0000e37d324f8a20 llvm::report_fatal_error(llvm::Twine const&, bool) + 248 7 libLLVM.so.18.1 0x0000e37d32d8b8b8 llvm::SelectionDAGISel::isOrEquivalentToAdd(llvm::SDNode const*) const + 0 8 libLLVM.so.18.1 0x0000e37d32d8ae08 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) + 13284 9 libLLVM.so.18.1 0x0000e37d341d0250 10 libLLVM.so.18.1 0x0000e37d32d83c54 llvm::SelectionDAGISel::DoInstructionSelection() + 344 11 libLLVM.so.18.1 0x0000e37d32d8343c llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 900 12 libLLVM.so.18.1 0x0000e37d32d82a98 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 3980 13 libLLVM.so.18.1 0x0000e37d32d80f14 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1496 14 libLLVM.so.18.1 0x0000e37d3295aef0 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 680 15 libLLVM.so.18.1 0x0000e37d326f5af4 llvm::FPPassManager::runOnFunction(llvm::Function&) + 580 16 libLLVM.so.18.1 0x0000e37d326fb070 llvm::FPPassManager::runOnModule(llvm::Module&) + 64 17 libLLVM.so.18.1 0x0000e37d326f60d8 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 868 18 libclang-cpp.so.18.1 0x0000e37d3a80bc64 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>>, clang::BackendConsumer*) + 2688 19 libclang-cpp.so.18.1 0x0000e37d3ab25f58 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1180 20 libclang-cpp.so.18.1 0x0000e37d3978a5b0 clang::ParseAST(clang::Sema&, bool, bool) + 572 21 libclang-cpp.so.18.1 0x0000e37d3b53fa34 clang::FrontendAction::Execute() + 112 22 libclang-cpp.so.18.1 0x0000e37d3b4d0590 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 744 23 libclang-cpp.so.18.1 0x0000e37d3b5b8e4c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 616 24 clang++ 0x0000c436783421c4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 3360 25 clang++ 0x0000c4367833fbac 26 libclang-cpp.so.18.1 0x0000e37d3b1ca950 27 libLLVM.so.18.1 0x0000e37d324eb0f8 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 168 28 libclang-cpp.so.18.1 0x0000e37d3b1ca1bc clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 352 29 libclang-cpp.so.18.1 0x0000e37d3b198d3c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 756 30 libclang-cpp.so.18.1 0x0000e37d3b198f4c clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 136 31 libclang-cpp.so.18.1 0x0000e37d3b1b12f4 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 324 32 clang++ 0x0000c4367833f344 clang_main(int, char**, llvm::ToolContext const&) + 9756 33 clang++ 0x0000c4367834ae40 main + 92 34 libc.so.6 0x0000e37d3caa84c4 35 libc.so.6 0x0000e37d3caa8598 __libc_start_main + 152 36 clang++ 0x0000c4367833c970 _start + 48 clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation) Ubuntu clang version 18.1.3 (1ubuntu1) Target: aarch64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/bin clang++: note: diagnostic msg: ******************** ``` To repro on an AWS c7g ``` sudo apt-get update && sudo apt-get install cmake build-essential libjemalloc-dev g++-13 gcc-13 clang libopenblas-dev -y git clone https://github.com/MarkReedZ/SimSIMD.git cd SimSIMD/ git fetch && git checkout dot_bf16c_neon cmake -D CMAKE_BUILD_TYPE=Release -D SIMSIMD_BUILD_TESTS=1 -D SIMSIMD_BUILD_BENCHMARKS=1 -D SIMSIMD_BUILD_BENCHMARKS_WITH_CBLAS=1 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -D CMAKE_C_COMPILER="/usr/bin/clang" -D CMAKE_CXX_COMPILER="/usr/bin/clang++" -B build_release cmake --build build_release ```
MarkReedZ commented 2 weeks ago

This is fixed in 19.1: https://godbolt.org/z/xE4coY9Px

If you change the compiler version you'll see it is okay in 16 and broken in between