llvm / llvm-project

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

[WebAssembly] Simple GC Statepoint support example crashes `llc` on `--march=wasm32` #80638

Open ThePuzzlemaker opened 7 months ago

ThePuzzlemaker commented 7 months ago

I tried this code:

; ModuleID = 'tmp-opt.bc'
source_filename = "tmp.ll"

define void @foo() {
  ret void
}

define ptr addrspace(1) @test1(ptr addrspace(1) %obj) gc "statepoint-example" {
  %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(ptr ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) %obj) ]
  %obj.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%obj, %obj)
  ret ptr addrspace(1) %obj.relocated
}

declare void @do_safepoint()

define void @gc.safepoint_poll() {
  call void @do_safepoint()
  ret void
}

declare void @__tmp_use(...)

declare token @llvm.experimental.gc.statepoint.p0(i64 immarg, i32 immarg, ptr, i32 immarg, i32 immarg, ...)

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32 immarg, i32 immarg) #0

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }

I ran llc tmp-opt.ll --march wasm32.

What I expected to happen: llc compiles, generates a .s file

What happened: llc crashes and hangs, with stacktrace:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: llc-17 tmp-opt.bc --march wasm32
1.  Running pass 'Function Pass Manager' on module 'tmp-opt.bc'.
2.  Running pass 'WebAssembly Assembly Printer' on function '@test1'
 #0 0x00007c1d90ebf933 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM-17.so+0xabf933)
 #1 0x00007c1d90ebcbcf llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-17.so+0xabcbcf)
 #2 0x00007c1d90ebcd1d (/usr/lib/libLLVM-17.so+0xabcd1d)
 #3 0x00007c1d8fe5a770 (/usr/lib/libc.so.6+0x3c770)
 #4 0x00007c1d8ff8e1ae (/usr/lib/libc.so.6+0x1701ae)
 #5 0x00007c1d94b43e49 (/usr/lib/libLLVM-17.so+0x4743e49)
 #6 0x00007c1d94b4477b (/usr/lib/libLLVM-17.so+0x474477b)
 #7 0x00007c1d94b44f4e (/usr/lib/libLLVM-17.so+0x4744f4e)
 #8 0x00007c1d94ad2582 (/usr/lib/libLLVM-17.so+0x46d2582)
 #9 0x00007c1d91a9f2d0 llvm::AsmPrinter::emitFunctionBody() (/usr/lib/libLLVM-17.so+0x169f2d0)
#10 0x00007c1d94ad21c3 (/usr/lib/libLLVM-17.so+0x46d21c3)
#11 0x00007c1d913c30a5 (/usr/lib/libLLVM-17.so+0xfc30a5)
#12 0x00007c1d9105d0d9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/libLLVM-17.so+0xc5d0d9)
#13 0x00007c1d9105d424 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/libLLVM-17.so+0xc5d424)
#14 0x00007c1d9105ddac llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/libLLVM-17.so+0xc5ddac)
#15 0x000058e4d46ad8b8 (/usr/lib/llvm17/bin/llc+0x188b8)
#16 0x000058e4d46a38d6 main (/usr/lib/llvm17/bin/llc+0xe8d6)
#17 0x00007c1d8fe43cd0 (/usr/lib/libc.so.6+0x25cd0)
#18 0x00007c1d8fe43d8a __libc_start_main (/usr/lib/libc.so.6+0x25d8a)
#19 0x000058e4d46a3ed5 _start (/usr/lib/llvm17/bin/llc+0xeed5)

After investigation in GDB (blasphemy, I know :P):

[#0] 0x7fffef58e1a4 → __memcpy_avx512_unaligned_erms()
[#1] 0x7ffff4143e49 → jmp 0x7ffff4143eb3
[#2] 0x7ffff414477b → jmp 0x7ffff414459d
[#3] 0x7ffff4144f4e → mov rdi, QWORD PTR [rsp+0x70]
[#4] 0x7ffff40d2582 → mov rsi, QWORD PTR [rbx+0x110]
[#5] 0x7ffff109f2d0 → llvm::AsmPrinter::emitFunctionBody()()
[#6] 0x7ffff40d21c3 → xor eax, eax
[#7] 0x7ffff09c30a5 → cmp BYTE PTR [rsp+0x38], 0x0
[#8] 0x7ffff065d0d9 → llvm::FPPassManager::runOnFunction(llvm::Function&)()
[#9] 0x7ffff065d424 → llvm::FPPassManager::runOnModule(llvm::Module&)()
Version

``` $ llc --version --verbose LLVM (http://llvm.org/): LLVM version 17.0.6 Optimized build. Default target: x86_64-pc-linux-gnu Host CPU: znver4 Registered Targets: aarch64 - AArch64 (little endian) aarch64_32 - AArch64 (little endian ILP32) aarch64_be - AArch64 (big endian) amdgcn - AMD GCN GPUs arm - ARM arm64 - ARM64 (little endian) arm64_32 - ARM64 (little endian ILP32) armeb - ARM (big endian) avr - Atmel AVR Microcontroller bpf - BPF (host endian) bpfeb - BPF (big endian) bpfel - BPF (little endian) hexagon - Hexagon lanai - Lanai loongarch32 - 32-bit LoongArch loongarch64 - 64-bit LoongArch mips - MIPS (32-bit big endian) mips64 - MIPS (64-bit big endian) mips64el - MIPS (64-bit little endian) mipsel - MIPS (32-bit little endian) msp430 - MSP430 [experimental] nvptx - NVIDIA PTX 32-bit nvptx64 - NVIDIA PTX 64-bit ppc32 - PowerPC 32 ppc32le - PowerPC 32 LE ppc64 - PowerPC 64 ppc64le - PowerPC 64 LE r600 - AMD GPUs HD2XXX-HD6XXX riscv32 - 32-bit RISC-V riscv64 - 64-bit RISC-V sparc - Sparc sparcel - Sparc LE sparcv9 - Sparc V9 systemz - SystemZ thumb - Thumb thumbeb - Thumb (big endian) ve - VE wasm32 - WebAssembly 32-bit wasm64 - WebAssembly 64-bit x86 - 32-bit X86: Pentium-Pro and above x86-64 - 64-bit X86: EM64T and AMD64 xcore - XCore ```

I can provide any more information if needed.

ThePuzzlemaker commented 7 months ago

Tested with master branch as of f035c018a6a581c38680651d4856631d9c6ccb0a, it fails with the following assertion:

llc: /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp:352: std::pair<llvm::SDValue, llvm::SDNode*> lowerCallFromStatepointLoweringInfo(llvm::SelectionDAGBuilder::StatepointLoweringInfo&, llvm::SelectionDAGBuilder&): Assertion `CallEnd->getOpcode() == ISD::CALLSEQ_END && "expected!"' failed.
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=0x6, no_tid=no_tid@entry=0x0) at pthread_kill.c:44
#1  0x00007ffff78ab393 in __pthread_kill_internal (signo=0x6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007ffff785a6c8 in __GI_raise (sig=sig@entry=0x6) at ../sysdeps/posix/raise.c:26
#3  0x00007ffff78424b8 in __GI_abort () at abort.c:79
#4  0x00007ffff78423dc in __assert_fail_base (fmt=0x7ffff79bcb68 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x555559d07988 "CallEnd->getOpcode() == ISD::CALLSEQ_END && \"expected!\"", 
    file=file@entry=0x555559d07260 "/home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp", line=line@entry=0x160, 
    function=function@entry=0x555559d078e8 "std::pair<llvm::SDValue, llvm::SDNode*> lowerCallFromStatepointLoweringInfo(llvm::SelectionDAGBuilder::StatepointLoweringInfo&, llvm::SelectionDAGBuilder&)") at assert.c:94
#5  0x00007ffff7852d46 in __assert_fail (assertion=0x555559d07988 "CallEnd->getOpcode() == ISD::CALLSEQ_END && \"expected!\"", 
    file=0x555559d07260 "/home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp", line=0x160, 
    function=0x555559d078e8 "std::pair<llvm::SDValue, llvm::SDNode*> lowerCallFromStatepointLoweringInfo(llvm::SelectionDAGBuilder::StatepointLoweringInfo&, llvm::SelectionDAGBuilder&)")
    at assert.c:103
#6  0x000055555ff94047 in lowerCallFromStatepointLoweringInfo (SI=..., Builder=...) at /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp:352
#7  0x000055555ff96446 in llvm::SelectionDAGBuilder::LowerAsSTATEPOINT (this=0x555561d676c0, SI=...) at /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp:745
#8  0x000055555ff9826e in llvm::SelectionDAGBuilder::LowerStatepoint (this=0x555561d676c0, I=..., EHPadBB=0x0) at /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp:1098
#9  0x000055555fdf0800 in llvm::SelectionDAGBuilder::visitIntrinsicCall (this=0x555561d676c0, I=..., Intrinsic=0x88)
    at /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:7246
#10 0x000055555fdfbe0d in llvm::SelectionDAGBuilder::visitCall (this=0x555561d676c0, I=...) at /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:8779
#11 0x000055555fdc64dd in llvm::SelectionDAGBuilder::visit (this=0x555561d676c0, Opcode=0x38, I=...) at /home/wren/llvm-project/llvm/include/llvm/IR/Instruction.def:209
#12 0x000055555fdc5d02 in llvm::SelectionDAGBuilder::visit (this=0x555561d676c0, I=...) at /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:1316
#13 0x000055555fec179e in llvm::SelectionDAGISel::SelectBasicBlock (this=0x555561d756b0, Begin=..., End=..., HadTailCall=@0x7fffffffd170: 0x0)
    at /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:726
#14 0x000055555fec795b in llvm::SelectionDAGISel::SelectAllBasicBlocks (this=0x555561d756b0, Fn=...) at /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1751
#15 0x000055555fec0246 in llvm::SelectionDAGISel::runOnMachineFunction (this=0x555561d756b0, mf=...) at /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:516
#16 0x000055555d8d1406 in (anonymous namespace)::WebAssemblyDAGToDAGISel::runOnMachineFunction (this=0x555561d756b0, MF=...)
    at /home/wren/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp:60
#17 0x000055555ebd1495 in llvm::MachineFunctionPass::runOnFunction (this=0x555561d756b0, F=...) at /home/wren/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:93
#18 0x000055555f32a78c in llvm::FPPassManager::runOnFunction (this=0x555561d750b0, F=...) at /home/wren/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1445
#19 0x000055555f32aa5e in llvm::FPPassManager::runOnModule (this=0x555561d750b0, M=...) at /home/wren/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1491
#20 0x000055555f32aeb3 in (anonymous namespace)::MPPassManager::runOnModule (this=0x555561d5f920, M=...) at /home/wren/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1560
#21 0x000055555f325aa9 in llvm::legacy::PassManagerImpl::run (this=0x555561d64e00, M=...) at /home/wren/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:542
#22 0x000055555f32b785 in llvm::legacy::PassManager::run (this=0x7fffffffde20, M=...) at /home/wren/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1687
#23 0x000055555be17b5b in compileModule (argv=0x7fffffffe5f8, Context=...) at /home/wren/llvm-project/llvm/tools/llc/llc.cpp:743
#24 0x000055555be152c9 in main (argc=0x4, argv=0x7fffffffe5f8) at /home/wren/llvm-project/llvm/tools/llc/llc.cpp:412
ThePuzzlemaker commented 7 months ago

The SelectionDAG opcode here appears to be WebAssemblyISD::CALL, instead of the expected ISD::CALLSEQ_END. I don't know enough about SelectionDAG to fix this issue, but this may help others debug so I thought I'd mention it.

ThePuzzlemaker commented 7 months ago
Output with --debug ``` Args: bin/llc /home/wren/llvm-tmp/tmp-opt.bc --march wasm32 --debug initializeSubtargetDependencies Features: CPU:generic TuneCPU:generic ********** Add Missing Prototypes ********** ********** Fix Function Bitcasts ********** ********** Optimize returned Attributes ********** ********** Function: foo MergeICmpsLegacyPass: foo Looking for trivial roots Found a new trivial root: %0 Last visited node: %0 Looking for non-trivial roots Total: 1, Num: 2 Discovered CFG nodes: 0: nullptr 1: nullptr 2: %0 Found roots: %0 ---- Branch Probability Info : foo ---- Computing probabilities for block-frequency: foo ==================== reverse-post-order-traversal - 0: loop-detection compute-mass-in-function - node: => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - : float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: foo - : float = 1.0, int = 18014398509481984 ********** Begin Constant Hoisting ********** ********** Function: foo ********** End Constant Hoisting ********** ********** Begin TLS Variable Hoist ********** ********** Function: foo ********** End TLS Variable Hoist ********** ---- Branch Probability Info : foo ---- Looking for trivial roots Found a new trivial root: %0 Last visited node: %0 Looking for non-trivial roots Total: 1, Num: 2 Discovered CFG nodes: 0: nullptr 1: nullptr 2: %0 Found roots: %0 Computing probabilities for block-frequency: foo ==================== reverse-post-order-traversal - 0: loop-detection compute-mass-in-function - node: => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - : float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: foo - : float = 1.0, int = 18014398509481984 ********** Optimize returned Attributes ********** ********** Function: test1 MergeICmpsLegacyPass: test1 Looking for trivial roots Found a new trivial root: %0 Last visited node: %0 Looking for non-trivial roots Total: 1, Num: 2 Discovered CFG nodes: 0: nullptr 1: nullptr 2: %0 Found roots: %0 ---- Branch Probability Info : test1 ---- Computing probabilities for block-frequency: test1 ====================== reverse-post-order-traversal - 0: loop-detection compute-mass-in-function - node: => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - : float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: test1 - : float = 1.0, int = 18014398509481984 ********** Begin Constant Hoisting ********** ********** Function: test1 ********** End Constant Hoisting ********** ********** Begin TLS Variable Hoist ********** ********** Function: test1 ********** End TLS Variable Hoist ********** ---- Branch Probability Info : test1 ---- Looking for trivial roots Found a new trivial root: %0 Last visited node: %0 Looking for non-trivial roots Total: 1, Num: 2 Discovered CFG nodes: 0: nullptr 1: nullptr 2: %0 Found roots: %0 Computing probabilities for block-frequency: test1 ====================== reverse-post-order-traversal - 0: loop-detection compute-mass-in-function - node: => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - : float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: test1 - : float = 1.0, int = 18014398509481984 ********** Optimize returned Attributes ********** ********** Function: gc.safepoint_poll MergeICmpsLegacyPass: gc.safepoint_poll Looking for trivial roots Found a new trivial root: %0 Last visited node: %0 Looking for non-trivial roots Total: 1, Num: 2 Discovered CFG nodes: 0: nullptr 1: nullptr 2: %0 Found roots: %0 ---- Branch Probability Info : gc.safepoint_poll ---- Computing probabilities for block-frequency: gc.safepoint_poll ================================== reverse-post-order-traversal - 0: loop-detection compute-mass-in-function - node: => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - : float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: gc.safepoint_poll - : float = 1.0, int = 18014398509481984 ********** Begin Constant Hoisting ********** ********** Function: gc.safepoint_poll ********** End Constant Hoisting ********** ********** Begin TLS Variable Hoist ********** ********** Function: gc.safepoint_poll ********** End TLS Variable Hoist ********** ---- Branch Probability Info : gc.safepoint_poll ---- Looking for trivial roots Found a new trivial root: %0 Last visited node: %0 Looking for non-trivial roots Total: 1, Num: 2 Discovered CFG nodes: 0: nullptr 1: nullptr 2: %0 Found roots: %0 Computing probabilities for block-frequency: gc.safepoint_poll ================================== reverse-post-order-traversal - 0: loop-detection compute-mass-in-function - node: => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - : float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: gc.safepoint_poll - : float = 1.0, int = 18014398509481984 initializeSubtargetDependencies Features:+mutable-globals,+sign-ext, CPU:generic TuneCPU:generic ********** Lower RefTypes IntPtr Convs ********** ********** Function: foo [SafeStack] Function: foo [SafeStack] safestack is not requested for this function Looking for trivial roots Found a new trivial root: %0 Last visited node: %0 Looking for non-trivial roots Total: 1, Num: 2 Discovered CFG nodes: 0: nullptr 1: nullptr 2: %0 Found roots: %0 ---- Branch Probability Info : foo ---- Computing probabilities for ********** ISelDAGToDAG ********** ********** Function: foo FastISel is disabled === foo Creating new node: t1: ch = WebAssemblyISD::RETURN t0 Initial selection DAG: %bb.0 'foo:' SelectionDAG has 2 nodes: t0: ch,glue = EntryToken t1: ch = WebAssemblyISD::RETURN t0 Combining: t1: ch = WebAssemblyISD::RETURN t0 Combining: t0: ch,glue = EntryToken Optimized lowered selection DAG: %bb.0 'foo:' SelectionDAG has 2 nodes: t0: ch,glue = EntryToken t1: ch = WebAssemblyISD::RETURN t0 Legalizing node: t0: ch,glue = EntryToken Analyzing result type: ch Legal result type Analyzing result type: glue Legal result type Legally typed node: t0: ch,glue = EntryToken Legalizing node: t1: ch = WebAssemblyISD::RETURN t0 Analyzing result type: ch Legal result type Analyzing operand: t0: ch,glue = EntryToken Legal operand Legally typed node: t1: ch = WebAssemblyISD::RETURN t0 Legalizing node: t65535: ch = handlenode t1 Analyzing result type: ch Legal result type Analyzing operand: t1: ch = WebAssemblyISD::RETURN t0 Legal operand Legally typed node: t65535: ch = handlenode t1 Type-legalized selection DAG: %bb.0 'foo:' SelectionDAG has 2 nodes: t0: ch,glue = EntryToken t1: ch = WebAssemblyISD::RETURN t0 Legalizing: t1: ch = WebAssemblyISD::RETURN t0 Legal node: nothing to do Legalizing: t0: ch,glue = EntryToken Legal node: nothing to do Legalized selection DAG: %bb.0 'foo:' SelectionDAG has 2 nodes: t0: ch,glue = EntryToken t1: ch = WebAssemblyISD::RETURN t0 Legalizing: t1: ch = WebAssemblyISD::RETURN t0 Legal node: nothing to do Combining: t1: ch = WebAssemblyISD::RETURN t0 Legalizing: t0: ch,glue = EntryToken Legal node: nothing to do Combining: t0: ch,glue = EntryToken Optimized legalized selection DAG: %bb.0 'foo:' SelectionDAG has 2 nodes: t0: ch,glue = EntryToken t1: ch = WebAssemblyISD::RETURN t0 ===== Instruction selection begins: %bb.0 '' ISEL: Starting selection on root node: t1: ch = WebAssemblyISD::RETURN t0 ISEL: Starting pattern match Morphed node: t1: ch = RETURN t0 ISEL: Match complete! ISEL: Starting selection on root node: t0: ch,glue = EntryToken ===== Instruction selection ends: Selected selection DAG: %bb.0 'foo:' SelectionDAG has 2 nodes: t0: ch,glue = EntryToken t1: ch = RETURN t0 ********** List Scheduling %bb.0 '' ********** SU(0): t1: ch = RETURN t0 # preds left : 0 # succs left : 0 # rdefs left : 0 Latency : 1 Depth : 0 Height : 0 Examining Available: Height 0: SU(0): t1: ch = RETURN t0 *** Scheduling [0]: SU(0): t1: ch = RETURN t0 *** Final schedule *** SU(0): t1: ch = RETURN t0 Total amount of phi nodes to update: 0 *** MachineFunction at end of ISel *** # Machine code for function foo: IsSSA, TracksLiveness Function Live Ins: $arguments bb.0 (%ir-block.0): liveins: $arguments RETURN implicit-def dead $arguments # End machine code for function foo. ********** Argument Move ********** ********** Function: foo ********** Set p2align Operands ********** ********** Function: foo ********** Fixing br_table Default Targets ********** ********** Function: foo # Machine code for function foo: IsSSA, TracksLiveness Function Live Ins: $arguments 0B bb.0 (%ir-block.0): liveins: $arguments 16B RETURN implicit-def dead $arguments # End machine code for function foo. ********** Stack Coloring ********** ********** Function: foo block-frequency: foo ==================== reverse-post-order-traversal - 0: BB0[] loop-detection compute-mass-in-function - node: BB0[] => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - BB0[]: float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: foo - BB0[]: float = 1.0, int = 18014398509481984 ******** Pre-regalloc Machine LICM: foo ******** block-frequency: foo ==================== reverse-post-order-traversal - 0: BB0[] loop-detection compute-mass-in-function - node: BB0[] => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - BB0[]: float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: foo - BB0[]: float = 1.0, int = 18014398509481984 Entering: Exiting: Looking for trivial roots Found a new trivial root: %bb.0 Last visited node: %bb.0 Looking for non-trivial roots Total: 1, Num: 2 Discovered CFG nodes: 0: nullptr 1: nullptr 2: %bb.0 Found roots: %bb.0 Computing cycles for function: foo Entry block: bb.0 (%ir-block.0) DFS visiting block: bb.0 (%ir-block.0) first encountered at depth 1 preorder number: 1 DFS visiting block: bb.0 (%ir-block.0) ended at 1 Preorder: bb.0 (%ir-block.0): 0 ******** Machine Sinking ******** ********** PEEPHOLE OPTIMIZER ********** ********** Function: foo Skipping Detect dead lanes pass ********** PROCESS IMPLICIT DEFS ********** ********** Function: foo ********** REWRITING TWO-ADDR INSTRS ********** ********** Function: foo # Machine code for function foo: NoPHIs, TracksLiveness, TiedOpsRewritten Function Live Ins: $arguments 0B bb.0 (%ir-block.0): liveins: $arguments 16B RETURN implicit-def dead $arguments # End machine code for function foo. Computing live-in reg-units in ABI blocks. 0B %bb.0 ARGUMENTS#0 Created 1 new intervals. ********** INTERVALS ********** ARGUMENTS [0B,0d:0)[16r,16d:1) 0@0B-phi 1@16r RegMasks: ********** MACHINEINSTRS ********** # Machine code for function foo: NoPHIs, TracksLiveness, TiedOpsRewritten Function Live Ins: $arguments 0B bb.0 (%ir-block.0): liveins: $arguments 16B RETURN implicit-def dead $arguments # End machine code for function foo. ********** REGISTER COALESCER ********** ********** Function: foo ********** JOINING INTERVALS *********** : Trying to inflate 0 regs. ********** INTERVALS ********** ARGUMENTS [0B,0d:0)[16r,16d:1) 0@0B-phi 1@16r RegMasks: ********** MACHINEINSTRS ********** # Machine code for function foo: NoPHIs, TracksLiveness, TiedOpsRewritten Function Live Ins: $arguments 0B bb.0 (%ir-block.0): liveins: $arguments 16B RETURN implicit-def dead $arguments # End machine code for function foo. block-frequency: foo ==================== reverse-post-order-traversal - 0: BB0[] loop-detection compute-mass-in-function - node: BB0[] => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - BB0[]: float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: foo - BB0[]: float = 1.0, int = 18014398509481984 Machine Function ********** EXPANDING POST-RA PSEUDO INSTRS ********** ********** Function: foo ********** Nullify DBG_VALUE_LISTs ********** ********** Function: foo ********** Fixing Irreducible Control Flow ********** ********** Function: foo ********** Replace Physical Registers ********** ********** Function: foo # Machine code for function foo: NoPHIs, TracksLiveness, TiedOpsRewritten Function Live Ins: $arguments 0B bb.0 (%ir-block.0): liveins: $arguments 16B RETURN implicit-def dead $arguments # End machine code for function foo. Computing live-in reg-units in ABI blocks. 0B %bb.0 ARGUMENTS#0 Created 1 new intervals. ********** INTERVALS ********** ARGUMENTS [0B,0d:0)[16r,16d:1) 0@0B-phi 1@16r RegMasks: ********** MACHINEINSTRS ********** # Machine code for function foo: NoPHIs, TracksLiveness, TiedOpsRewritten Function Live Ins: $arguments 0B bb.0 (%ir-block.0): liveins: $arguments 16B RETURN implicit-def dead $arguments # End machine code for function foo. ********** Optimize LiveIntervals ********** ********** Function: foo block-frequency: foo ==================== reverse-post-order-traversal - 0: BB0[] loop-detection compute-mass-in-function - node: BB0[] => mass: ffffffffffffffff float-to-int: min = 1.0, max = 1.0, factor = 18014398509481984.0 - BB0[]: float = 1.0, scaled = 18014398509481984.0, int = 18014398509481984 block-frequency-info: foo - BB0[]: float = 1.0, int = 18014398509481984 ********** Memory Intrinsic Results ********** ********** Function: foo Basic Block: ********** Register Stackifying ********** ********** Function: foo ********** Register Coloring ********** ********** Function: foo Interesting register intervals: Coloring register intervals: ********** Exception Info Calculation ********** ********** Function: foo ********** CFG Sorting ********** ********** Function: foo ********** CFG Stackifying ********** ********** Function: foo ********** Make Locals Explicit ********** ********** Function: foo ********** Lowering br_unless ********** ********** Function: foo ********** Peephole ********** ********** Function: foo ********** Register Numbering ********** ********** Function: foo ********** Debug Fixup ********** ********** Function: foo ********** Lower RefTypes IntPtr Convs ********** ********** Function: test1 [SafeStack] Function: test1 [SafeStack] safestack is not requested for this function Looking for trivial roots Found a new trivial root: %0 Last visited node: %0 Looking for non-trivial roots Total: 1, Num: 2 Discovered CFG nodes: 0: nullptr 1: nullptr 2: %0 Found roots: %0 ---- Branch Probability Info : test1 ---- Computing probabilities for ********** ISelDAGToDAG ********** ********** Function: test1 FastISel is disabled === test1 Creating constant: t1: i32 = TargetConstant<0> Creating new node: t2: i32 = WebAssemblyISD::ARGUMENT TargetConstant:i32<0> Lowering statepoint %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(ptr ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) %obj) ] Deciding how to lower GC Pointers: 0 pointers will go in vregs Creating constant: t4: i64 = TargetConstant<2> Creating constant: t5: i64 = TargetConstant<0> Lowering deopt state Creating constant: t6: i64 = TargetConstant<1> Creating new node: t9: i32 = undef Creating new node: t10: ch = store<(store (s32) into %stack.0)> t0, t2, TargetFrameIndex:i32<0>, undef:i32 Creating new node: t12: i32 = WebAssemblyISD::Wrapper TargetGlobalAddress:i32 0 Creating new node: t13: i32,ch = WebAssemblyISD::CALL t10, t12 llc: /home/wren/llvm-project/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp:352: std::pair lowerCallFromStatepointLoweringInfo(llvm::SelectionDAGBuilder::StatepointLoweringInfo&, llvm::SelectionDAGBuilder&): Assertion `CallEnd->getOpcode() == ISD::CALLSEQ_END && "expected!"' failed. ```
llvmbot commented 7 months ago

@llvm/issue-subscribers-backend-webassembly

Author: James [Undefined] (ThePuzzlemaker)

I tried this code: ```llvm ; ModuleID = 'tmp-opt.bc' source_filename = "tmp.ll" define void @foo() { ret void } define ptr addrspace(1) @test1(ptr addrspace(1) %obj) gc "statepoint-example" { %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(ptr ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) %obj) ] %obj.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%obj, %obj) ret ptr addrspace(1) %obj.relocated } declare void @do_safepoint() define void @gc.safepoint_poll() { call void @do_safepoint() ret void } declare void @__tmp_use(...) declare token @llvm.experimental.gc.statepoint.p0(i64 immarg, i32 immarg, ptr, i32 immarg, i32 immarg, ...) ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none) declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32 immarg, i32 immarg) #0 attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) } ``` I ran `llc tmp-opt.ll --march wasm32`. What I expected to happen: `llc` compiles, generates a `.s` file What happened: `llc` crashes and hangs, with stacktrace: ``` PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: llc-17 tmp-opt.bc --march wasm32 1. Running pass 'Function Pass Manager' on module 'tmp-opt.bc'. 2. Running pass 'WebAssembly Assembly Printer' on function '@test1' #0 0x00007c1d90ebf933 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM-17.so+0xabf933) #1 0x00007c1d90ebcbcf llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-17.so+0xabcbcf) #2 0x00007c1d90ebcd1d (/usr/lib/libLLVM-17.so+0xabcd1d) #3 0x00007c1d8fe5a770 (/usr/lib/libc.so.6+0x3c770) #4 0x00007c1d8ff8e1ae (/usr/lib/libc.so.6+0x1701ae) #5 0x00007c1d94b43e49 (/usr/lib/libLLVM-17.so+0x4743e49) #6 0x00007c1d94b4477b (/usr/lib/libLLVM-17.so+0x474477b) #7 0x00007c1d94b44f4e (/usr/lib/libLLVM-17.so+0x4744f4e) #8 0x00007c1d94ad2582 (/usr/lib/libLLVM-17.so+0x46d2582) #9 0x00007c1d91a9f2d0 llvm::AsmPrinter::emitFunctionBody() (/usr/lib/libLLVM-17.so+0x169f2d0) #10 0x00007c1d94ad21c3 (/usr/lib/libLLVM-17.so+0x46d21c3) #11 0x00007c1d913c30a5 (/usr/lib/libLLVM-17.so+0xfc30a5) #12 0x00007c1d9105d0d9 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/libLLVM-17.so+0xc5d0d9) #13 0x00007c1d9105d424 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/libLLVM-17.so+0xc5d424) #14 0x00007c1d9105ddac llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/libLLVM-17.so+0xc5ddac) #15 0x000058e4d46ad8b8 (/usr/lib/llvm17/bin/llc+0x188b8) #16 0x000058e4d46a38d6 main (/usr/lib/llvm17/bin/llc+0xe8d6) #17 0x00007c1d8fe43cd0 (/usr/lib/libc.so.6+0x25cd0) #18 0x00007c1d8fe43d8a __libc_start_main (/usr/lib/libc.so.6+0x25d8a) #19 0x000058e4d46a3ed5 _start (/usr/lib/llvm17/bin/llc+0xeed5) ``` After investigation in GDB (blasphemy, I know :P): ``` [#0] 0x7fffef58e1a4 → __memcpy_avx512_unaligned_erms() [#1] 0x7ffff4143e49 → jmp 0x7ffff4143eb3 [#2] 0x7ffff414477b → jmp 0x7ffff414459d [#3] 0x7ffff4144f4e → mov rdi, QWORD PTR [rsp+0x70] [#4] 0x7ffff40d2582 → mov rsi, QWORD PTR [rbx+0x110] [#5] 0x7ffff109f2d0 → llvm::AsmPrinter::emitFunctionBody()() [#6] 0x7ffff40d21c3 → xor eax, eax [#7] 0x7ffff09c30a5 → cmp BYTE PTR [rsp+0x38], 0x0 [#8] 0x7ffff065d0d9 → llvm::FPPassManager::runOnFunction(llvm::Function&)() [#9] 0x7ffff065d424 → llvm::FPPassManager::runOnModule(llvm::Module&)() ``` <details><summary><strong>Version</strong></summary> <p> ``` $ llc --version --verbose LLVM (http://llvm.org/): LLVM version 17.0.6 Optimized build. Default target: x86_64-pc-linux-gnu Host CPU: znver4 Registered Targets: aarch64 - AArch64 (little endian) aarch64_32 - AArch64 (little endian ILP32) aarch64_be - AArch64 (big endian) amdgcn - AMD GCN GPUs arm - ARM arm64 - ARM64 (little endian) arm64_32 - ARM64 (little endian ILP32) armeb - ARM (big endian) avr - Atmel AVR Microcontroller bpf - BPF (host endian) bpfeb - BPF (big endian) bpfel - BPF (little endian) hexagon - Hexagon lanai - Lanai loongarch32 - 32-bit LoongArch loongarch64 - 64-bit LoongArch mips - MIPS (32-bit big endian) mips64 - MIPS (64-bit big endian) mips64el - MIPS (64-bit little endian) mipsel - MIPS (32-bit little endian) msp430 - MSP430 [experimental] nvptx - NVIDIA PTX 32-bit nvptx64 - NVIDIA PTX 64-bit ppc32 - PowerPC 32 ppc32le - PowerPC 32 LE ppc64 - PowerPC 64 ppc64le - PowerPC 64 LE r600 - AMD GPUs HD2XXX-HD6XXX riscv32 - 32-bit RISC-V riscv64 - 64-bit RISC-V sparc - Sparc sparcel - Sparc LE sparcv9 - Sparc V9 systemz - SystemZ thumb - Thumb thumbeb - Thumb (big endian) ve - VE wasm32 - WebAssembly 32-bit wasm64 - WebAssembly 64-bit x86 - 32-bit X86: Pentium-Pro and above x86-64 - 64-bit X86: EM64T and AMD64 xcore - XCore ``` </p> </details> I can provide any more information if needed.