-
Notifications
You must be signed in to change notification settings - Fork 15k
Closed as duplicate of#155762
Copy link
Labels
backend:X86crashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]duplicateResolved as duplicateResolved as duplicate
Description
Summary
When building LLVM 21.1.x with Clang 21.x and -march=sapphirerapids, the X86 backend deterministically crashes during SelectionDAG combine (combineSetCC) with an APInt assertion:
APInt::setBits/getLowBitsSet: hiBit <= BitWidth (hiBit out of range)
This happens even without LTO. Changing only -march to x86-64-v3 makes the crash disappear.
Environment
- OS: Linux x86_64 (triple: x86_64-pc-linux-gnu)
- Clang/LLD versions involved:
- Works: host toolchain Clang 20.1.8 building LLVM 21.1.1
- Fails: host toolchain Clang 21.1.0 or 21.1.1 building LLVM 21.1.1
- libc++: used for building (CLANG_DEFAULT_CXX_STDLIB=libc++; -stdlib=libc++)
- Assertions: ON (LLVM_ENABLE_ASSERTIONS=ON)
- LTO: not required to reproduce (OFF also crashes). FULL/Thin also reproduce when -march=sapphirerapids is used.
- CPU features: -march=sapphirerapids (enables AVX-512 family)
Affected versions
- Reproducible with Clang/LLVM 21.1.0 and 21.1.1 as host compilers.
- Not reproducible with Clang/LLVM 20.1.8 as host compiler (same source).
What I did (repro matrix)
- Build LLVM 21.1.0 using Clang 20.1.8 → OK.
- Build LLVM 21.1.1 using Clang 21.1.0 → Crash.
- Build LLVM 21.1.1 using Clang 20.1.8 → OK.
- Self-host: Build LLVM 21.1.1 using Clang 21.1.1 → same crash as in step 2.
- Important: If I only change -march=sapphirerapids to -march=x86-64-v3 (keeping LTO as before), both the “20 builds 21” and “21 builds 21” builds succeed.
Minimal reproduction
- The crash happens while compiling this TU from LLVM itself:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp - Clang emits a preprocessed repro and a run script automatically. I will attach:
- /tmp/InstructionCombining-XXXX.cpp
- /tmp/InstructionCombining-XXXX.sh
- Running the script as-is (with -march=sapphirerapids) crashes; editing only -march to x86-64-v3 makes it pass.
Representative crash output:
[1612/11988] CCACHE_DIR=/dev/shm/CCACHE_dykecpWdGHYNcwwN CCACHE_MAXSIZE=50G CCACHE_CPP2=yes CCACHE_NOHASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros /home/capri/.local/ccache/bin/ccache /home/capri/.local/llvm/selected/bin/clang++ -DEXPERIMENTAL_KEY_INSTRUCTIONS -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/dev/shm/llvm-bdir/build/lib/Transforms/InstCombine -I/dev/shm/llvm-bdir/source/llvm/lib/Transforms/InstCombine -I/dev/shm/llvm-bdir/build/include -I/dev/shm/llvm-bdir/source/llvm/include -march=sapphirerapids -O3 -pipe -fstack-protector-all -fcf-protection=full -fstack-clash-protection -fstrict-flex-arrays=3 --gcc-toolchain=/home/capri/.local/gcc/selected -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o -c /dev/shm/llvm-bdir/source/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
FAILED: lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o
CCACHE_DIR=/dev/shm/CCACHE_dykecpWdGHYNcwwN CCACHE_MAXSIZE=50G CCACHE_CPP2=yes CCACHE_NOHASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros /home/capri/.local/ccache/bin/ccache /home/capri/.local/llvm/selected/bin/clang++ -DEXPERIMENTAL_KEY_INSTRUCTIONS -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/dev/shm/llvm-bdir/build/lib/Transforms/InstCombine -I/dev/shm/llvm-bdir/source/llvm/lib/Transforms/InstCombine -I/dev/shm/llvm-bdir/build/include -I/dev/shm/llvm-bdir/source/llvm/include -march=sapphirerapids -O3 -pipe -fstack-protector-all -fcf-protection=full -fstack-clash-protection -fstrict-flex-arrays=3 --gcc-toolchain=/home/capri/.local/gcc/selected -stdlib=libc++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -std=c++17 -fPIC -fno-exceptions -funwind-tables -UNDEBUG -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o.d -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o -c /dev/shm/llvm-bdir/source/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
clang++: ../source/llvm/include/llvm/ADT/APInt.h:1368: void llvm::APInt::setBits(unsigned int, unsigned int): Assertion `hiBit <= BitWidth && "hiBit out of range"' failed.
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: /home/capri/.local/llvm/selected/bin/clang++ -march=sapphirerapids -O3 -pipe -fstack-protector-all -fcf-protection=full -fstack-clash-protection -fstrict-flex-arrays=3 --gcc-toolchain=/home/capri/.local/gcc/selected -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -O3 -std=c++17 -fPIC -fno-exceptions -funwind-tables -fdiagnostics-color -DEXPERIMENTAL_KEY_INSTRUCTIONS -DLLVM_EXPORTS -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Transforms/InstCombine -I../source/llvm/lib/Transforms/InstCombine -Iinclude -I../source/llvm/include -stdlib=libc++ -DNDEBUG -UNDEBUG -c -MD -MT lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o -MF lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o.d -fcolor-diagnostics -o lib/Transforms/InstCombine/CMakeFiles/LLVMInstCombine.dir/InstructionCombining.cpp.o ../source/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module '../source/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp'.
4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@_ZL16tryFactorizationRN4llvm14BinaryOperatorERKNS_13SimplifyQueryERNS_9IRBuilderINS_12TargetFolderENS_25IRBuilderCallbackInserterEEENS_11Instruction9BinaryOpsEPNS_5ValueESD_SD_SD_'
#0 0x00007f9aba8908ea llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/capri/.local/llvm/selected/lib/libLLVMSupport.so.21.1+0x2908ea)
#1 0x00007f9aba88f307 llvm::sys::RunSignalHandlers() (/home/capri/.local/llvm/selected/lib/libLLVMSupport.so.21.1+0x28f307)
#2 0x00007f9aba7780b1 CrashRecoverySignalHandler(int) ld-temp.o:0:0
#3 0x00007f9aba467b40 __restore_rt (/lib64/libc.so.6+0x40b40)
#4 0x00007f9aba4bd9dc __pthread_kill_implementation (/lib64/libc.so.6+0x969dc)
#5 0x00007f9aba467a96 gsignal (/lib64/libc.so.6+0x40a96)
#6 0x00007f9aba44f8fa abort (/lib64/libc.so.6+0x288fa)
#7 0x00007f9aba44f81e _nl_load_domain.cold (/lib64/libc.so.6+0x2881e)
#8 0x00007f9aba45fff6 (/lib64/libc.so.6+0x38ff6)
#9 0x00007f9ac2fdbdfc llvm::APInt::getLowBitsSet(unsigned int, unsigned int) ld-temp.o:0:0
#10 0x00007f9ac31438bb combineSetCC(llvm::SDNode*, llvm::SelectionDAG&, llvm::TargetLowering::DAGCombinerInfo&, llvm::X86Subtarget const&) ld-temp.o:0:0
#11 0x00007f9ac310ac22 llvm::X86TargetLowering::PerformDAGCombine(llvm::SDNode*, llvm::TargetLowering::DAGCombinerInfo&) const (/home/capri/.local/llvm/selected/lib/libLLVMX86CodeGen.so.21.1+0x50ac22)
#12 0x00007f9ab9b34e13 (anonymous namespace)::DAGCombiner::combine(llvm::SDNode*) ld-temp.o:0:0
#13 0x00007f9ab9b346d5 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::BatchAAResults*, llvm::CodeGenOptLevel) (/home/capri/.local/llvm/selected/lib/libLLVMSelectionDAG.so.21.1+0x1346d5)
#14 0x00007f9ab9e58f60 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/capri/.local/llvm/selected/lib/libLLVMSelectionDAG.so.21.1+0x458f60)
#15 0x00007f9ab9e55f9d llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/capri/.local/llvm/selected/lib/libLLVMSelectionDAG.so.21.1+0x455f9d)
#16 0x00007f9ab9e51d20 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/capri/.local/llvm/selected/lib/libLLVMSelectionDAG.so.21.1+0x451d20)
#17 0x00007f9ab9e4fe04 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/capri/.local/llvm/selected/lib/libLLVMSelectionDAG.so.21.1+0x44fe04)
#18 0x00007f9abea51144 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/capri/.local/llvm/selected/lib/libLLVMCodeGen.so.21.1+0x651144)
#19 0x00007f9abaed4fa9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/capri/.local/llvm/selected/lib/libLLVMCore.so.21.1+0x4d4fa9)
#20 0x00007f9abaee0fb4 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/capri/.local/llvm/selected/lib/libLLVMCore.so.21.1+0x4e0fb4)
#21 0x00007f9abaed993b llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/capri/.local/llvm/selected/lib/libLLVMCore.so.21.1+0x4d993b)
#22 0x00007f9ac0efd9ea clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/capri/.local/llvm/selected/lib/libclangCodeGen.so.21.1+0x2fd9ea)
#23 0x00007f9ac131655e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/capri/.local/llvm/selected/lib/libclangCodeGen.so.21.1+0x71655e)
#24 0x00007f9ab6ee58e9 clang::ParseAST(clang::Sema&, bool, bool) (/home/capri/.local/llvm/selected/lib/libclangParse.so.21.1+0x768e9)
#25 0x00007f9abd3d50b8 clang::FrontendAction::Execute() (/home/capri/.local/llvm/selected/lib/libclangFrontend.so.21.1+0x1d50b8)
#26 0x00007f9abd3336dd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/capri/.local/llvm/selected/lib/libclangFrontend.so.21.1+0x1336dd)
#27 0x00007f9ac32f7a6f clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/capri/.local/llvm/selected/lib/libclangFrontendTool.so.21.1+0x7a6f)
#28 0x0000555c3a0989db cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/capri/.local/llvm/selected/bin/clang+++0x169db)
#29 0x0000555c3a09448f ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) ld-temp.o:0:0
#30 0x00007f9abcf3a1bf void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const::$_0>(long) ld-temp.o:0:0
#31 0x00007f9aba77839c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/capri/.local/llvm/selected/lib/libLLVMSupport.so.21.1+0x17839c)
#32 0x00007f9abcf3a0a8 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const (/home/capri/.local/llvm/selected/lib/libclangDriver.so.21.1+0x13a0a8)
#33 0x00007f9abcef3bd1 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/capri/.local/llvm/selected/lib/libclangDriver.so.21.1+0xf3bd1)
#34 0x00007f9abcef3f8e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&, bool) const (/home/capri/.local/llvm/selected/lib/libclangDriver.so.21.1+0xf3f8e)
#35 0x00007f9abcf33f7e clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&) (/home/capri/.local/llvm/selected/lib/libclangDriver.so.21.1+0x133f7e)
#36 0x0000555c3a09389c clang_main(int, char**, llvm::ToolContext const&) (/home/capri/.local/llvm/selected/bin/clang+++0x1189c)
#37 0x0000555c3a0a322a main (/home/capri/.local/llvm/selected/bin/clang+++0x2122a)
#38 0x00007f9aba45130e __libc_start_call_main (/lib64/libc.so.6+0x2a30e)
#39 0x00007f9aba4513c9 __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a3c9)
#40 0x0000555c3a091925 _start (/home/capri/.local/llvm/selected/bin/clang+++0xf925)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 21.1.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /home/capri/.local/llvm/21/bin
Build config: +assertions
Configuration file: /home/capri/.config/clang/21/x86_64-pc-linux-gnu-clang++.cfg
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/InstructionCombining-d6d78d.cpp
clang++: note: diagnostic msg: /tmp/InstructionCombining-d6d78d.sh
clang++: note: diagnostic msg:
********************
Configuration knobs (for context)
- configure options (excerpt): LLVM_ENABLE_ASSERTIONS=ON, BUILD_SHARED_LIBS=ON, LLVM_ENABLE_LLD=ON, CLANG_DEFAULT_CXX_STDLIB=libc++, LLVM_UNREACHABLE_OPTIMIZE=ON, LLVM_ENABLE_LTO=OFF/FULL (either way reproduces with -march=sapphirerapids).
- common compile flags used when it crashes:
-march=sapphirerapids -O3 -pipe -fstack-protector-all -fcf-protection=full -fstack-clash-protection -fstrict-flex-arrays=3 --gcc-toolchain= -stdlib=libc++ - With the exact same setup but -march=x86-64-v3, the build succeeds.
Expected behavior
Compilation should succeed (no backend assertion) when building LLVM itself.
Actual behavior
Deterministic crash in X86 SelectionDAG combineSetCC due to APInt bitmask assertion when using -march=sapphirerapids.
Workarounds
- Build the toolchain itself with a baseline CPU (e.g. -march=x86-64-v3), or explicitly disable AVX-512 family features (e.g. -mno-avx512f -mno-avx512vl -mno-avx512bw -mno-avx512dq -mno-avx512cd -mno-avx512vbmi -mno-avx512vbmi2 -mno-avx512vnni ...).
- Disabling assertions “avoids” the abort but is not recommended.
Notes
- This looks distinct from regression in clang 20.1.8 / coroutines / distributed LTO: crash in optimizer #155558 (that one is about distributed ThinLTO post-link O0/coroutines passes). Here, LTO is not required and the crash happens while compiling a single TU from LLVM itself.
- The problem appears tied to the sapphirerapids/AVX-512 path in X86 DAG combine (combineSetCC computing an out-of-range APInt mask).
Attachments
- Please see the attached preprocessed source and run script produced by clang:
- /tmp/InstructionCombining-d6d78d.cpp
- /tmp/InstructionCombining-d6d78d.sh
Metadata
Metadata
Assignees
Labels
backend:X86crashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]duplicateResolved as duplicateResolved as duplicate