Skip to content
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

LLVM 18 breaks inlining callees with compatible target attributes #70002

Open
yingfeng opened this issue Oct 24, 2023 · 6 comments
Open

LLVM 18 breaks inlining callees with compatible target attributes #70002

yingfeng opened this issue Oct 24, 2023 · 6 comments
Labels
question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@yingfeng
Copy link

yingfeng commented Oct 24, 2023

Consider the following code:

    constexpr int32_t MinimumValue = std::numeric_limits<OutputType>::min();
    constexpr int32_t MaximumValue = std::numeric_limits<OutputType>::max();

    auto ScaleVector = _mm512_set1_ps(Scale);
    auto MinimumValueVector = _mm512_set1_ps(float(MinimumValue - ZeroPoint));
    auto MaximumValueVector = _mm512_set1_ps(float(MaximumValue - ZeroPoint));
    auto ZeroPointVector = _mm512_set1_epi32(ZeroPoint);

When compiling with previous versions of clang (up to and including version llvmorg-18-init), it can be compiled normally. While when switching to the head of LLVM 18, following errors are got:

always_inline function  '_mm512_set1_ps' requires target feature 'evex512', but would be inlined into function 'MlasQuantizeLinearAvx512F' that is compiled without support for 'evex512'

This issue seems to relate with 65205

@yingfeng
Copy link
Author

It seems such definition should be added:

if (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "18.0")
    add_definitions(-mevex512)
endif()

Introducing such clang-18 dedicated definitions is strange

@dtcxzyw
Copy link
Member

dtcxzyw commented Oct 24, 2023

You should pass -mavx512f to clang. Godbolt: https://godbolt.org/z/hxedYr4WT

@dtcxzyw dtcxzyw added question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! and removed new issue labels Oct 25, 2023
@yingfeng
Copy link
Author

You should pass -mavx512f to clang. Godbolt: https://godbolt.org/z/hxedYr4WT

It can not work, since I use desktop to build the program without avx512 supported. The only approach right now is to add -mevex512 flag which could even not work for earlier clang 18.

[43/828] Building CXX object src/CMakeFiles/infinity_parser.dir/parser/parsed_expr/cast_expr.cpp.o
FAILED: src/CMakeFiles/infinity_parser.dir/parser/parsed_expr/cast_expr.cpp.o
ccache /usr/lib64/ccache/clang++  -I/home/zhichyu/[github.com/infiniflow/infinity/src](http://github.com/infiniflow/infinity/src) -I/home/zhichyu/[github.com/infiniflow/infinity/third_party/spdlog/include](http://github.com/infiniflow/infinity/third_party/spdlog/include) -I/home/zhichyu/[github.com/infiniflow/infinity/third_party/ctpl](http://github.com/infiniflow/infinity/third_party/ctpl) -I/home/zhichyu/[github.com/infiniflow/infinity/third_party/nlohmann](http://github.com/infiniflow/infinity/third_party/nlohmann) -Wno-error=deprecated-declarations -g -std=gnu++23   -march=native -mavx512f -D INFINITY_DEBUG -fcolor-diagnostics -Winvalid-pch -Xclang -include-pch -Xclang /home/zhichyu/[github.com/infiniflow/infinity/build/src/CMakeFiles/infinity_parser.dir/cmake_pch.hxx.pch](http://github.com/infiniflow/infinity/build/src/CMakeFiles/infinity_parser.dir/cmake_pch.hxx.pch) -Xclang -include -Xclang /home/zhichyu/[github.com/infiniflow/infinity/build/src/CMakeFiles/infinity_parser.dir/cmake_pch.hxx](http://github.com/infiniflow/infinity/build/src/CMakeFiles/infinity_parser.dir/cmake_pch.hxx) -MD -MT src/CMakeFiles/infinity_parser.dir/parser/parsed_expr/cast_expr.cpp.o -MF src/CMakeFiles/infinity_parser.dir/parser/parsed_expr/cast_expr.cpp.o.d -o src/CMakeFiles/infinity_parser.dir/parser/parsed_expr/cast_expr.cpp.o -c /home/zhichyu/[github.com/infiniflow/infinity/src/parser/parsed_expr/cast_expr.cpp](http://github.com/infiniflow/infinity/src/parser/parsed_expr/cast_expr.cpp)
fatal error: error in backend: Cannot select: 0x562f2509cb70: v8i32,ch = load<(load (s512) from %ir.13, align 8), anyext from v16i32> 0x562f22df9a80, 0x562f264ae860, undef:i64, third_party/spdlog/include/spdlog/details/log_msg_buffer-inl.h:22:7
  0x562f264ae860: i64,ch = load<(dereferenceable load (s64) from %ir.8)> 0x562f26cd0810, FrameIndex:i64<5>, undef:i64, third_party/spdlog/include/spdlog/details/log_msg_buffer-inl.h:22:15
    0x562f264af270: i64 = FrameIndex<5>
    0x562f23b54e80: i64 = undef
  0x562f23b54e80: i64 = undef
In function: _ZN6spdlog7details14log_msg_bufferC2ERKS1_
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/local/bin/clang++ -I/home/zhichyu/[github.com/infiniflow/infinity/src](http://github.com/infiniflow/infinity/src) -I/home/zhichyu/[github.com/infiniflow/infinity/third_party/spdlog/include](http://github.com/infiniflow/infinity/third_party/spdlog/include) -I/home/zhichyu/[github.com/infiniflow/infinity/third_party/ctpl](http://github.com/infiniflow/infinity/third_party/ctpl) -I/home/zhichyu/[github.com/infiniflow/infinity/third_party/nlohmann](http://github.com/infiniflow/infinity/third_party/nlohmann) -Wno-error=deprecated-declarations -g -std=gnu++23 -march=native -mavx512f -D INFINITY_DEBUG -fcolor-diagnostics -Winvalid-pch -Xclang -include-pch -Xclang /home/zhichyu/[github.com/infiniflow/infinity/build/src/CMakeFiles/infinity_parser.dir/cmake_pch.hxx.pch](http://github.com/infiniflow/infinity/build/src/CMakeFiles/infinity_parser.dir/cmake_pch.hxx.pch) -Xclang -include -Xclang /home/zhichyu/[github.com/infiniflow/infinity/build/src/CMakeFiles/infinity_parser.dir/cmake_pch.hxx](http://github.com/infiniflow/infinity/build/src/CMakeFiles/infinity_parser.dir/cmake_pch.hxx) -MD -MT src/CMakeFiles/infinity_parser.dir/parser/parsed_expr/cast_expr.cpp.o -MF src/CMakeFiles/infinity_parser.dir/parser/parsed_expr/cast_expr.cpp.o.d -o src/CMakeFiles/infinity_parser.dir/parser/parsed_expr/cast_expr.cpp.o -c /home/zhichyu/[github.com/infiniflow/infinity/src/parser/parsed_expr/cast_expr.cpp](http://github.com/infiniflow/infinity/src/parser/parsed_expr/cast_expr.cpp)
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '/home/zhichyu/[github.com/infiniflow/infinity/src/parser/parsed_expr/cast_expr.cpp](http://github.com/infiniflow/infinity/src/parser/parsed_expr/cast_expr.cpp)'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@_ZN6spdlog7details14log_msg_bufferC2ERKS1_'
 #0 0x0000562f1aba2b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/bin/clang+++0x2c1ab18)
 #1 0x0000562f1aba08ee llvm::sys::RunSignalHandlers() (/usr/local/bin/clang+++0x2c188ee)
 #2 0x0000562f1ab1c7ae (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
 #3 0x0000562f1ab1c76b (/usr/local/bin/clang+++0x2b9476b)
 #4 0x0000562f1ab9d417 llvm::sys::Process::Exit(int, bool) (/usr/local/bin/clang+++0x2c15417)
 #5 0x0000562f18d26523 (/usr/local/bin/clang+++0xd9e523)
 #6 0x0000562f1ab225a2 llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/local/bin/clang+++0x2b9a5a2)
 #7 0x0000562f1b8f2d57 (/usr/local/bin/clang+++0x396ad57)
 #8 0x0000562f1b8f2205 (/usr/local/bin/clang+++0x396a205)
 #9 0x0000562f19ceff0d (anonymous namespace)::X86DAGToDAGISel::Select(llvm::SDNode*) X86ISelDAGToDAG.cpp:0:0
#10 0x0000562f1b8e9dfc llvm::SelectionDAGISel::DoInstructionSelection() (/usr/local/bin/clang+++0x3961dfc)
#11 0x0000562f1b8e955d llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/usr/local/bin/clang+++0x396155d)
#12 0x0000562f1b8e8a32 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/local/bin/clang+++0x3960a32)
#13 0x0000562f1b8e66d9 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/local/bin/clang+++0x395e6d9)
#14 0x0000562f19ce5e6f (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) X86ISelDAGToDAG.cpp:0:0
#15 0x0000562f1a2b1977 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/local/bin/clang+++0x2329977)
#16 0x0000562f1a6c7dc6 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/local/bin/clang+++0x273fdc6)
#17 0x0000562f1a6cef73 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/local/bin/clang+++0x2746f73)
#18 0x0000562f1a6c89d7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/local/bin/clang+++0x27409d7)
#19 0x0000562f1ad43576 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>>) (/usr/local/bin/clang+++0x2dbb576)
#20 0x0000562f1b9ed04b clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/local/bin/clang+++0x3a6504b)
#21 0x0000562f1c7ce486 clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/bin/clang+++0x4846486)
#22 0x0000562f1b422bd7 clang::FrontendAction::Execute() (/usr/local/bin/clang+++0x349abd7)
#23 0x0000562f1b399614 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/bin/clang+++0x3411614)
#24 0x0000562f1b4dc870 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/bin/clang+++0x3554870)
#25 0x0000562f18d26225 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/local/bin/clang+++0xd9e225)
#26 0x0000562f18d232a1 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x0000562f1b203039 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::$_0>(long) Job.cpp:0:0
#28 0x0000562f1ab1c74c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/local/bin/clang+++0x2b9474c)
#29 0x0000562f1b202a66 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/usr/local/bin/clang+++0x327aa66)
#30 0x0000562f1b1c52d7 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/local/bin/clang+++0x323d2d7)
#31 0x0000562f1b1c577e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/usr/local/bin/clang+++0x323d77e)
#32 0x0000562f1b1e2fcf clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/usr/local/bin/clang+++0x325afcf)
#33 0x0000562f18d22947 clang_main(int, char**, llvm::ToolContext const&) (/usr/local/bin/clang+++0xd9a947)
#34 0x0000562f18d31061 main (/usr/local/bin/clang+++0xda9061)
#35 0x00007faae6c281b0 __libc_start_call_main (/lib64/libc.so.6+0x281b0)
#36 0x00007faae6c28279 __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x28279)
#37 0x0000562f18d1fa15 _start (/usr/local/bin/clang+++0xd97a15)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git d5b0ad632657a598f99bdab64a178015c6ea4b11)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
clang++: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/cast_expr-bf8063.cpp
clang++: note: diagnostic msg: /tmp/cast_expr-bf8063.sh
clang++: note: diagnostic msg:

********************
ninja: build stopped: subcommand failed.

@jan-wassenberg
Copy link

jan-wassenberg commented Nov 8, 2023

Hi @dtcxzyw , I understand this new target was added to support AVX10.

We are not always able to follow your suggestion of a global -mavx512 flag because we also want to support dynamic dispatch. Will it be sufficient to add "evex512" to the list of targets we specify (via pragma) to individual functions? That would be conditional on the compiler supporting evex512, we can check __EVEX512__.

@dtcxzyw
Copy link
Member

dtcxzyw commented Nov 8, 2023

Hi @dtcxzyw , I understand this new target was added to support AVX10.

We are not always able to follow your suggestion of a global -mavx512 flag because we also want to support dynamic dispatch. Will it be sufficient to add "evex512" to the list of targets we specify (via pragma) to individual functions? That would be conditional on the compiler supporting evex512, we can check EVEX512.

Did you mean __attribute__((target("avx512f")))? Godbolt: https://godbolt.org/z/GM5rdjErM

@jan-wassenberg
Copy link

That is included in the list we use: ,avx512f,avx512cd,avx512vl,avx512dq,avx512bw

The error @yingfeng is running into is hwy/ops/x86_512-inl.h:2962:24: error: always_inline function '_mm512_loadu_ps' requires target feature 'evex512', but would be inlined into function 'LoadU' that is compiled without support for 'evex512' 2962 | return Vec512<float>{_mm512_loadu_ps(p)};

Possibly this is caused by their extra compiler flags -march=native -mtune=native, which does not make sense in the context of Highway's dynamic dispatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

3 participants