| Issue |
182409
|
| Summary |
[clang] Crash at -O2/3/s with -march=native on x86_64-linux_gnu: Assertion `OpTy == RHS->getType() && "Expected LHS and RHS of same type"' failed.
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
zxt5
|
Compiler Explorer: https://godbolt.org/z/oc4Gvrrco
This code crashes at -O2/3/s with -march=native on x86_64-linux_gnu:
```
int a, b, c, d, e, f;
int g(int h, int i, int j, int k, int l, int m) {
int n = h ? 1 : 0;
n |= i ? 1 << 1 : 0;
n |= j ? 1 << 2 : 0;
n |= k ? 1 << 3 : 0;
n |= l ? 1 << 4 : 0;
n |= m ? 1 << 5 : 0;
n |= f ? 1 << 6 : 0;
n |= e ? 1 << 7 : 0;
n |= a ? 8 : 0;
n |= b ? 9 : 0;
n |= c ? 10 : 0;
n |= d ? 11 : 0;
return n;
}
void main() {}
```
Crash:
```
clang-23: /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:25355: static llvm::Value *(anonymous namespace)::HorizontalReduction::createOp(llvm::IRBuilderBase &, llvm::RecurKind, llvm::Value *, llvm::Value *, const llvm::Twine &, bool): Assertion `OpTy == RHS->getType() && "Expected LHS and RHS of same type"' failed.
```
Backtrace:
```
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: /data/x27zhou/compiler-nightly/install/llvm/bin/clang-23 -cc1 -triple x86_64-unknown-linux-gnu -Os -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu icelake-server -target-feature +prfchw -target-feature -cldemote -target-feature +avx -target-feature +aes -target-feature +sahf -target-feature +pclmul -target-feature -xop -target-feature +crc32 -target-feature -amx-fp8 -target-feature +xsaves -target-feature -avx512fp16 -target-feature -usermsr -target-feature -sm4 -target-feature -egpr -target-feature +sse4.1 -target-feature -avx10.1 -target-feature +avx512ifma -target-feature +xsave -target-feature +sse4.2 -target-feature -tsxldtrk -target-feature -sm3 -target-feature -ptwrite -target-feature -widekl -target-feature -movrs -target-feature +invpcid -target-feature +64bit -target-feature +xsavec -target-feature +avx512vpopcntdq -target-feature +cmov -target-feature -avx512vp2intersect -target-feature +avx512cd -target-feature +movbe -target-feature -avxvnniint8 -target-feature -ccmp -target-feature -amx-int8 -target-feature -kl -target-feature -sha512 -target-feature -avxvnni -target-feature -rtm -target-feature +adx -target-feature +avx2 -target-feature -hreset -target-feature -movdiri -target-feature -serialize -target-feature +vpclmulqdq -target-feature +avx512vl -target-feature -uintr -target-feature -cf -target-feature +clflushopt -target-feature -raoint -target-feature -cmpccxadd -target-feature +bmi -target-feature -amx-tile -target-feature +sse -target-feature +gfni -target-feature -avxvnniint16 -target-feature -amx-fp16 -target-feature -zu -target-feature -ndd -target-feature +xsaveopt -target-feature +rdrnd -target-feature +avx512f -target-feature -amx-bf16 -target-feature -avx512bf16 -target-feature +avx512vnni -target-feature -push2pop2 -target-feature +cx8 -target-feature +avx512bw -target-feature +sse3 -target-feature +pku -target-feature -nf -target-feature -amx-tf32 -target-feature -amx-avx512 -target-feature +fsgsbase -target-feature -clzero -target-feature -mwaitx -target-feature -lwp -target-feature +lzcnt -target-feature +sha -target-feature -movdir64b -target-feature -ppx -target-feature +wbnoinvd -target-feature -enqcmd -target-feature -avxneconvert -target-feature -tbm -target-feature +pconfig -target-feature -amx-complex -target-feature +ssse3 -target-feature +cx16 -target-feature -avx10.2 -target-feature +bmi2 -target-feature +fma -target-feature +popcnt -target-feature -avxifma -target-feature +f16c -target-feature +avx512bitalg -target-feature -rdpru -target-feature +clwb -target-feature +mmx -target-feature +sse2 -target-feature +rdseed -target-feature +avx512vbmi2 -target-feature -prefetchi -target-feature -amx-movrs -target-feature +rdpid -target-feature -fma4 -target-feature +avx512vbmi -target-feature -shstk -target-feature +vaes -target-feature -waitpkg -target-feature +sgx -target-feature +fxsr -target-feature +avx512dq -target-feature -sse4a -debugger-tuning=gdb -fdebug-compilation-dir=/home/x27zhou/fuzz-pgo/PGOFuzz/pgofuzz-output-2026-02-18-19-15-42/crash-clang-trunk-24898 -fcoverage-compilation-dir=/home/x27zhou/fuzz-pgo/PGOFuzz/pgofuzz-output-2026-02-18-19-15-42/crash-clang-trunk-24898 -resource-dir /data/x27zhou/compiler-nightly/install/llvm/lib/clang/23 -internal-isystem /data/x27zhou/compiler-nightly/install/llvm/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fmessage-length=272 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -fdwarf2-cfi-asm -o /tmp/small-92e608.o -x c small.c
1. <eof> parser at end of file
2. Optimizer
3. Running pass "function<eager-inv>(drop-unnecessary-assumes,float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,drop-unnecessary-assumes,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-arithmetic;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;switch-to-arithmetic;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)" on module "small.c"
4. Running pass "slp-vectorizer" on function "g"
#0 0x00005612b458f10b backtrace (/data/x27zhou/compiler-nightly/install/llvm/bin/clang-23+0x4f6810b)
#1 0x00005612bd3ccbb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:884:8
#2 0x00005612bd3c48d0 llvm::sys::RunSignalHandlers() /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Support/Signals.cpp:0:5
#3 0x00005612bd3cfe77 SignalHandler(int, siginfo_t*, void*) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:448:38
#4 0x00005612bd3cfacd int const* std::__find_if<int const*, __gnu_cxx::__ops::_Iter_equals_val<int const>>(int const*, int const*, __gnu_cxx::__ops::_Iter_equals_val<int const>, std::random_access_iterator_tag) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algobase.h:2067:8
#5 0x00005612bd3cfacd int const* std::__find_if<int const*, __gnu_cxx::__ops::_Iter_equals_val<int const>>(int const*, int const*, __gnu_cxx::__ops::_Iter_equals_val<int const>) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algobase.h:2112:14
#6 0x00005612bd3cfacd int const* std::find<int const*, int>(int const*, int const*, int const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/stl_algo.h:3851:14
#7 0x00005612bd3cfacd bool llvm::is_contained<int const (&) [10], int>(int const (&) [10], int const&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/STLExtras.h:1953:12
#8 0x00005612bd3cfacd SignalHandlerTerminate(int, siginfo_t*, void*) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:464:7
#9 0x00007fdda5738520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#10 0x00007fdda578c9fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#11 0x00007fdda578c9fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#12 0x00007fdda578c9fc pthread_kill ./nptl/pthread_kill.c:89:10
#13 0x00007fdda5738476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#14 0x00007fdda571e7f3 abort ./stdlib/abort.c:81:7
#15 0x00007fdda571e71b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#16 0x00007fdda572fe96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#17 0x00005612c2175139 decltype(auto) llvm::dyn_cast<llvm::SelectInst, llvm::Value>(llvm::Value*) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/Support/Casting.h:656:3
#18 0x00005612c2175139 (anonymous namespace)::HorizontalReduction::createOp(llvm::IRBuilderBase&, llvm::RecurKind, llvm::Value*, llvm::Value*, llvm::Twine const&, llvm::SmallVector<llvm::SmallVector<llvm::Value*, 16u>, 2u> const&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:25424:23
#19 0x00005612c214ff7e (anonymous namespace)::HorizontalReduction::emitReduction(llvm::IRBuilderBase&, llvm::TargetTransformInfo const&, llvm::Type*, bool)::'lambda0'(llvm::Value*, unsigned int, bool)::operator()(llvm::Value*, unsigned int, bool) const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:26932:14
#20 0x00005612c214ff7e (anonymous namespace)::HorizontalReduction::emitReduction(llvm::IRBuilderBase&, llvm::TargetTransformInfo const&, llvm::Type*, bool) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:26939:7
#21 0x00005612c214ff7e (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*, llvm::DominatorTree&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:26376:27
#22 0x00005612c206d853 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&)::$_257::operator()(llvm::Instruction*) const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:27388:19
#23 0x00005612c206d853 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:27413:30
#24 0x00005612c2073c32 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:0:14
#25 0x00005612c2051d42 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:0:27
#26 0x00005612c20461bf llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:0:16
#27 0x00005612c204416d llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:24403:18
#28 0x00005612c0372b62 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:5
#29 0x00005612bc0b2d98 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:80:8
#30 0x00005612b53c93e2 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:5
#31 0x00005612bc0bf282 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/lib/IR/PassManager.cpp:132:23
#32 0x00005612b53cc922 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:5
#33 0x00005612bc0af888 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:80:8
#34 0x00005612bda4d8c3 llvm::SmallPtrSetImplBase::isSmall() const /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:248:33
#35 0x00005612bda4d8c3 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:89:10
#36 0x00005612bda4d8c3 llvm::PreservedAnalyses::~PreservedAnalyses() /data/x27zhou/compiler-nightly/src/llvm-project/llvm/include/llvm/IR/Analysis.h:112:7
#37 0x00005612bda4d8c3 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1208:5
#38 0x00005612bda30284 (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:0:0
#39 0x00005612bda30284 (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /data/x27zhou/compiler-nightly/src/llvm-project/clang/lib/CodeGen/Backe<truncated>Please see the issue for the entire body.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs