llvm / llvm/llvm-project

[NVPTX] Backend crashes with fatal error on aliased kernel function definitions

Open
#213,504 0 comments 0 reactions 0 assignees View on GitHub
backend:NVPTX confirmed crash-on-valid
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Hi, this was found while playing around with NVPTX targets in the zig compiler.

when the language exports a kernel function like this code

```zig
export fn foo(a: [*]u32) callconv(.nvptx_kernel) void {
a[0] = 0;
}
```

The zig compiler creates aliases for all exported objects, so the generated IR looks like this:

```llvm

@foo = alias void (ptr), ptr @example.foo

; Function Attrs: mustprogress nofree norecurse noredzone nosync nounwind willreturn memory(argmem: write)
define private ptx_kernel void @example.foo(ptr nonnull writeonly captures(none) initializes((0, 4)) %0) unnamed_addr #0 {
store i32 0, ptr %0, align 4
ret void
}

```

But when lowering to PTX, llvm currently reports a fatal error: `LLVM ERROR: NVPTX aliasee must be a non-kernel function definition`, since nvptx backend lacks support for symbol aliasing if it's a kernel entrypoint, this crashes the frontend entirely.

Instead of a fatal error, it would be awesome if the backend could handle unsupported aliases by emulating them during lowering, this would help prevent the need for hardcoded, target-specific workarounds in frontends.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the NVPTX backend failure with the aliased kernel IR shown in the issue, then trace the backend path that reports “NVPTX aliasee must be a non-kernel function definition.” Determine how unsupported aliases should be handled during lowering and add regression coverage showing that this input no longer causes a fatal error.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.