Skip to content

[1 x i128] kernel argument results in failed assertion #49221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
maleadt opened this issue Apr 7, 2021 · 4 comments
Open

[1 x i128] kernel argument results in failed assertion #49221

maleadt opened this issue Apr 7, 2021 · 4 comments
Assignees
Labels
backend:NVPTX bugzilla Issues migrated from bugzilla confirmed Verified by a second party

Comments

@maleadt
Copy link
Contributor

maleadt commented Apr 7, 2021

Bugzilla Link 49877
Version trunk
OS Linux
CC @Artem-B

Extended Description

The following snippet, reduced from a user report at JuliaGPU/CUDA.jl#793, results in a failed assertion:

source_filename = "text"
target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
target triple = "nvptx64-nvidia-cuda"

define void @kernel( [1 x i128] ) {
  ret void
}
❯ ./bin/llc /tmp/wip.ll -o -
//
// Generated by LLVM NVPTX Back-End
//

.version 6.0
.target sm_30
.address_size 64

llc: /home/tim/Julia/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:11655: void llvm::SelectionDAGISel::LowerArguments(const llvm::Function&): Assertion `InVals.size() == Ins.size() && "LowerFormalArguments didn't emit the correct number of values!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: ./bin/llc /tmp/wip.ll -o -
1.	Running pass 'Function Pass Manager' on module '/tmp/wip.ll'.
2.	Running pass 'NVPTX DAG->DAG Pattern Instruction Selection' on function '@kernel'
 #0 0x00005e6a5ab59e5c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/tim/Julia/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x00005e6a5ab5a26f PrintStackTraceSignalHandler(void*) /home/tim/Julia/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x00005e6a5ab57723 llvm::sys::RunSignalHandlers() /home/tim/Julia/src/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x00005e6a5ab59739 SignalHandler(int) /home/tim/Julia/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x000077a63a61e1d0 (/usr/lib/libc.so.6+0x3d1d0)
 #5 0x000077a63a6773f4 (/usr/lib/libc.so.6+0x963f4)
 #6 0x000077a63a61e120 raise (/usr/lib/libc.so.6+0x3d120)
 #7 0x000077a63a6054c3 abort (/usr/lib/libc.so.6+0x244c3)
 #8 0x000077a63a6053df (/usr/lib/libc.so.6+0x243df)
 #9 0x000077a63a616177 (/usr/lib/libc.so.6+0x35177)
#10 0x00005e6a5a87e81e llvm::SelectionDAGISel::LowerArguments(llvm::Function const&) /home/tim/Julia/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:11657:3
#11 0x00005e6a5a937700 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) /home/tim/Julia/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1600:19
#12 0x00005e6a5a93196f llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/tim/Julia/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:615:7
#13 0x00005e6a579c24a0 llvm::NVPTXDAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) /home/tim/Julia/src/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp:63:1
#14 0x00005e6a5a93076b llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) /home/tim/Julia/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:374:40
#15 0x00005e6a595bacc6 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/tim/Julia/src/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:94:33
#16 0x00005e6a59d84298 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/tim/Julia/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1408:20
#17 0x00005e6a59d8456a llvm::FPPassManager::runOnModule(llvm::Module&) /home/tim/Julia/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1454:13
#18 0x00005e6a59d849b6 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/tim/Julia/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1523:20
#19 0x00005e6a59d7fa09 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/tim/Julia/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:541:13
#20 0x00005e6a59d85289 llvm::legacy::PassManager::run(llvm::Module&) /home/tim/Julia/src/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1651:1
#21 0x00005e6a561f8dc1 compileModule(char**, llvm::LLVMContext&) /home/tim/Julia/src/llvm-project/llvm/tools/llc/llc.cpp:742:34
#22 0x00005e6a561f6547 main /home/tim/Julia/src/llvm-project/llvm/tools/llc/llc.cpp:409:35
#23 0x000077a63a606e08 (/usr/lib/libc.so.6+0x25e08)
#24 0x000077a63a606ecc __libc_start_main (/usr/lib/libc.so.6+0x25ecc)
#25 0x00005e6a561f4fa5 _start (./bin/llc+0x6ffcfa5)
zsh: IOT instruction  ./bin/llc /tmp/wip.ll -o -

https://godbolt.org/z/sa7ar8esP

Reproduces on trunk, and in an attempt to bisect this (as the user report indicated this was a new failure) I kept on running into the assertion going back to LLVM from 2016, so it looks like this has always been here?

@maleadt
Copy link
Contributor Author

maleadt commented Apr 7, 2021

assigned to @Artem-B

@Artem-B
Copy link
Member

Artem-B commented Apr 7, 2021

Apparently array of i128 falls through the cracks.
We do decompose stand-alone i128 into i64,i64 but that's about it:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp#L155

In the end we return just a single SDValue while the argument is expected to be a pair of i64 and that's what triggers the assertion.

So, yes, the bug has apparently been there since the i128 support has been added.

I've pinged the author of the change in https://reviews.llvm.org/D55144

@maleadt
Copy link
Contributor Author

maleadt commented Apr 8, 2021

Thanks. FWIW, I only noticed this now because we used to pass kernel arguments as byval pointers, which doesn't trigger this assertion, but had to disable that due to performance issues (which I probably should revisit given your recent work on that).

@Artem-B
Copy link
Member

Artem-B commented Sep 27, 2021

If the original issue with byval arguments was that it resulted in LLVM keeping their copies in local memory, then you may want to revisit that approach. There were some recent NVPTX back-end improvements that help eliminate the local copies in many more cases. If all access are reads and are not hidden behind conditional control flow, LLVM should access the parameter directly, not its local copy.

Passing i128 as a scalar is going to be tricky as PTX does not have 128-bit integer type. We may need to add some glue to pack it as a byval struct or split it into two 64-bit arguments. I'm unlikely to get to it any time soon.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:NVPTX bugzilla Issues migrated from bugzilla confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

4 participants