Issue 235439
Summary [SelectionDAG] Assertion failure in `llvm::TargetLowering::getVectorSubVecPointer`
Labels new issue
Assignees
Reporter mlugg
    I hit an assertion failure while working on the Zig compiler. Repro:
```llvm
source_filename = "repro"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux6.18.441-gnu2.41.0"

attributes #0 = { "target-cpu"="znver4" }
define void @foo(ptr %ptr, i64 %index) #0 {
 %loaded = load <1 x i1>, ptr %ptr, align 1
  %modified = insertelement <1 x i1> %loaded, i1 1, i64 %index
  store <1 x i1> %modified, ptr %ptr, align 1
  ret void
}
```
Output on a recent `main` (courtesy of @alexrp):
```console
$  ./bin/clang repro.ll
warning: overriding the module target triple with x86_64-unknown-linux-gnu [-Woverride-module]
clang-24: /home/alexrp/Sources/llvm/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:12497: llvm::SDValue llvm::TargetLowering::getVectorSubVecPointer(llvm::SelectionDAG&, llvm::SDValue, llvm::EVT, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags) const: Assertion `EltSize * 8 == EltVT.getFixedSizeInBits() && "Converting bits to bytes lost precision"' failed.
```
I do have a stack trace, but it's from 23.1.4. I've pasted that below in case it's useful, but I'll spin up a build of LLVM's `main` branch in a moment to get an up-to-date stack trace.
```
1.      Code generation
2.      Running pass 'Function Pass Manager' on module 'repro.ll'.
3.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@foo'
 #0 0x00000000042cfc3b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x42cfc3b)
 #1 0x00000000042cc834 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00000000042cc918 SignalHandlerTerminate(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x0000000008e0f2a0 __restore_rt libc_sigaction.o:0:0
 #4 0x0000000008e2b0fc __pthread_kill_implementation.constprop.0 pthread_kill.o:0:0
 #5 0x0000000008e0f1a2 gsignal (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x8e0f1a2)
 #6 0x0000000000ced821 abort (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0xced821)
 #7 0x0000000000ced7f6 _nl_load_domain.cold loadmsgcat.o:0:0
 #8 0x0000000008e09ce2 (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x8e09ce2)
 #9 0x0000000000942e8c llvm::TargetLowering::getVectorSubVecPointer(llvm::SelectionDAG&, llvm::SDValue, llvm::EVT, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags) const (.cold) TargetLowering.cpp:0:0
#10 0x00000000059cd74d llvm::TargetLowering::getVectorElementPointer(llvm::SelectionDAG&, llvm::SDValue, llvm::EVT, llvm::SDValue, llvm::SDNodeFlags) const (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x59cd74d)
#11 0x0000000005852d7e (anonymous namespace)::SelectionDAGLegalize::ExpandInsertToVectorThroughStack(llvm::SDValue) (.constprop.0.isra.0) LegalizeDAG.cpp:0:0
#12 0x0000000005860ab5 (anonymous namespace)::SelectionDAGLegalize::ExpandINSERT_VECTOR_ELT(llvm::SDValue) (.constprop.0.isra.0) LegalizeDAG.cpp:0:0
#13 0x000000000587d1fe (anonymous namespace)::SelectionDAGLegalize::ExpandNode(llvm::SDNode*) LegalizeDAG.cpp:0:0
#14 0x0000000005874d3e (anonymous namespace)::SelectionDAGLegalize::LegalizeOp(llvm::SDNode*) LegalizeDAG.cpp:0:0
#15 0x00000000058762f0 llvm::SelectionDAG::Legalize() (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x58762f0)
#16 0x0000000005985bcb llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x5985bcb)
#17 0x000000000598a6ff llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x598a6ff)
#18 0x000000000598bdd6 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x598bdd6)
#19 0x0000000005984003 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x5984003)
#20 0x00000000035675ab llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x35675ab)
#21 0x0000000003b9c629 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x3b9c629)
#22 0x0000000003b9cbe5 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x3b9cbe5)
#23 0x0000000003b9d66f (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) LegacyPassManager.cpp:0:0
#24 0x0000000003b9dd5b llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x3b9dd5b)
#25 0x00000000046dea6d (anonymous namespace)::EmitAssemblyHelper::TimeCodegenPasses(llvm::function_ref<void ()>) BackendUtil.cpp:0:0
#26 0x00000000046f149a (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#27 0x00000000046f1761 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, 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*) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x46f1761)
#28 0x0000000004d69267 clang::CodeGenAction::ExecuteAction() (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x4d69267)
#29 0x00000000050d0e6b clang::FrontendAction::Execute() (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x50d0e6b)
#30 0x000000000505d075 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x505d075)
#31 0x00000000051a52ee clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x51a52ee)
#32 0x0000000000dfccee cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0xdfccee)
#33 0x0000000000df3570 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#34 0x0000000000df8088 clang_main(int, char**, llvm::ToolContext const&) (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0xdf8088)
#35 0x0000000000cef1ca main (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0xcef1ca)
#36 0x0000000008dfb746 __libc_start_call_main libc-start.o:0:0
#37 0x0000000008dfd955 __libc_start_main_impl (/home/mlugg/.local/llvm23-release-static-g++/bin/clang-23+0x8dfd955)
#38 0x0000000000df2ad1 _start /builddir/glibc-2.41/csu/../sysdeps/x86_64/start.S:117:0
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to