llvm / llvm-project

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

writing zeroinitialiser to large array causes llc assertion #53164

Open cesaref opened 2 years ago

cesaref commented 2 years ago

If we alloca a large array and zero initialise it, we trigger an llc assertion. This fails on arm64 and x64, not sure about other targets. In addition, if we repeat with smaller arrays (say, 10,000 elements) the code generator produces a large number of stores which is slow to optimise.

jenkins@server MacOS % cat a.ll
; ModuleID = 'test'
source_filename = "test"
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "arm64-apple-darwin20.3.0"

; Function Attrs: argmemonly nounwind
define void @tests__bigStack1() #0 {
  %1 = alloca [800000 x i32], align 4
  store [800000 x i32] zeroinitializer, [800000 x i32]* %1, align 4
  ret void
}

attributes #0 = { argmemonly nounwind }
jenkins@server MacOS % llc a.ll                                                         
Assertion failed: (NumValues == VTs.NumVTs && "NumValues wasn't wide enough for its operands!"), function SDNode, file /Users/jenkins/source/styx/3rdParty/llvm/src/llvm/include/llvm/CodeGen/SelectionDAGNodes.h, line 1062.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /Users/jenkins/source/styx/3rdParty/llvm/build/osx/arm64/bin/llc a.ll
1.  Running pass 'Function Pass Manager' on module 'a.ll'.
2.  Running pass 'AArch64 Instruction Selection' on function '@tests__bigStack1'
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  llc                      0x0000000103e81814 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  llc                      0x0000000103e80678 llvm::sys::RunSignalHandlers() + 128
2  llc                      0x0000000103e81e8c SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001a3569c44 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001a3521c24 pthread_kill + 292
5  libsystem_c.dylib        0x00000001a3469864 abort + 104
6  libsystem_c.dylib        0x00000001a3468b68 err + 0
7  llc                      0x00000001048cd080 llvm::SDNode::SDNode(unsigned int, unsigned int, llvm::DebugLoc, llvm::SDVTList) (.cold.2) + 0
8  llc                      0x0000000103d47444 llvm::SDNode::SDNode(unsigned int, unsigned int, llvm::DebugLoc, llvm::SDVTList) + 188
9  llc                      0x0000000103d1f3b8 llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc const&, llvm::SDVTList, llvm::ArrayRef<llvm::SDValue>, llvm::SDNodeFlags) + 1696
10 llc                      0x0000000103d19d30 llvm::SelectionDAG::getMergeValues(llvm::ArrayRef<llvm::SDValue>, llvm::SDLoc const&) + 336
11 llc                      0x0000000103cbe298 llvm::SelectionDAGBuilder::getValueImpl(llvm::Value const*) + 3196
12 llc                      0x0000000103cbd51c llvm::SelectionDAGBuilder::getValue(llvm::Value const*) + 248
13 llc                      0x0000000103cb3720 llvm::SelectionDAGBuilder::visitStore(llvm::StoreInst const&) + 352
14 llc                      0x0000000103cacbb4 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) + 132
15 llc                      0x0000000103d3a260 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) + 84
16 llc                      0x0000000103d39d98 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 6740
17 llc                      0x0000000103d371d0 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 2104
18 llc                      0x0000000103467b24 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 360
19 llc                      0x000000010381af50 llvm::FPPassManager::runOnFunction(llvm::Function&) + 744
20 llc                      0x0000000103820960 llvm::FPPassManager::runOnModule(llvm::Module&) + 68
21 llc                      0x000000010381b53c llvm::legacy::PassManagerImpl::run(llvm::Module&) + 976
22 llc                      0x000000010295775c main + 7220
23 libdyld.dylib            0x00000001a353df34 start + 4
zsh: abort      ~/source/styx/3rdParty/llvm/build/osx/arm64/bin/llc a.ll
jenkins@server MacOS % 
msebor commented 2 years ago

Confirmed on x86_64 with this week top of trunk and the stack trace below (different from the reporter's) :

$ llc llvm-pr53164.ll
llc: /src/llvm/llvm/lib/IR/Type.cpp:313: static llvm::IntegerType* llvm::IntegerType::get(llvm::LLVMContext&, unsigned int): Assertion `NumBits <= MAX_INT_BITS && "bitwidth too large"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /build/llvm-gcc/bin/llc llvm-pr53164.ll
1.  Running pass 'Function Pass Manager' on module 'llvm-pr53164.ll'.
2.  Running pass 'CodeGen Prepare' on function '@tests__bigStack1'
 #0 0x00007ffacccb4e07 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /src/llvm/llvm/lib/Support/Unix/Signals.inc:569:22
 #1 0x00007ffacccb4eca PrintStackTraceSignalHandler(void*) /src/llvm/llvm/lib/Support/Unix/Signals.inc:636:1
 #2 0x00007ffacccb2d93 llvm::sys::RunSignalHandlers() /src/llvm/llvm/lib/Support/Signals.cpp:103:20
 #3 0x00007ffacccb4818 SignalHandler(int) /src/llvm/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007ffac568f750 __restore_rt (/lib64/libc.so.6+0x42750)
 #5 0x00007ffac56dc84c __pthread_kill_implementation (/lib64/libc.so.6+0x8f84c)
 #6 0x00007ffac568f6a6 gsignal (/lib64/libc.so.6+0x426a6)
 #7 0x00007ffac56797d3 abort (/lib64/libc.so.6+0x2c7d3)
 #8 0x00007ffac56796fb _nl_load_domain.cold (/lib64/libc.so.6+0x2c6fb)
 #9 0x00007ffac5688396 (/lib64/libc.so.6+0x3b396)
#10 0x00007ffaccfffc81 llvm::IntegerType::get(llvm::LLVMContext&, unsigned int) /src/llvm/llvm/lib/IR/Type.cpp:316:3
#11 0x00007ffaccfff954 llvm::Type::getIntNTy(llvm::LLVMContext&, unsigned int) /src/llvm/llvm/lib/IR/Type.cpp:245:1
#12 0x00007ffacd16d551 splitMergedValStore(llvm::StoreInst&, llvm::DataLayout const&, llvm::TargetLowering const&) /src/llvm/llvm/lib/CodeGen/CodeGenPrepare.cpp:7585:73
#13 0x00007ffacd16f330 (anonymous namespace)::CodeGenPrepare::optimizeInst(llvm::Instruction*, bool&) /src/llvm/llvm/lib/CodeGen/CodeGenPrepare.cpp:7958:5
#14 0x00007ffacd16fde0 (anonymous namespace)::CodeGenPrepare::optimizeBlock(llvm::BasicBlock&, bool&) /src/llvm/llvm/lib/CodeGen/CodeGenPrepare.cpp:8092:16
#15 0x00007ffacd151800 (anonymous namespace)::CodeGenPrepare::runOnFunction(llvm::Function&) /src/llvm/llvm/lib/CodeGen/CodeGenPrepare.cpp:555:18
#16 0x00007ffaccf4211b llvm::FPPassManager::runOnFunction(llvm::Function&) /src/llvm/llvm/lib/IR/LegacyPassManager.cpp:1430:20
#17 0x00007ffaccf4238b llvm::FPPassManager::runOnModule(llvm::Module&) /src/llvm/llvm/lib/IR/LegacyPassManager.cpp:1476:13
#18 0x00007ffaccf427b2 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /src/llvm/llvm/lib/IR/LegacyPassManager.cpp:1545:20
#19 0x00007ffaccf3db8e llvm::legacy::PassManagerImpl::run(llvm::Module&) /src/llvm/llvm/lib/IR/LegacyPassManager.cpp:535:13
#20 0x00007ffaccf42fd7 llvm::legacy::PassManager::run(llvm::Module&) /src/llvm/llvm/lib/IR/LegacyPassManager.cpp:1673:1
#21 0x00000000002257d8 compileModule(char**, llvm::LLVMContext&) /src/llvm/llvm/tools/llc/llc.cpp:737:66
#22 0x00000000002233c4 main /src/llvm/llvm/tools/llc/llc.cpp:418:35
#23 0x00007ffac567a560 __libc_start_call_main (/lib64/libc.so.6+0x2d560)
#24 0x00007ffac567a60c __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2d60c)
#25 0x0000000000222145 _start (/build/llvm-gcc/bin/llc+0x222145)
Aborted (core dumped)