Skip to content

fix(nvvm): hoist fixed stack allocations before text export - #1682

Open
paulzhng wants to merge 2 commits into
NVIDIA:mainfrom
paulzhng:fix/nvvm-entry-allocas
Open

paulzhng wants to merge 2 commits into
NVIDIA:mainfrom
paulzhng:fix/nvvm-entry-allocas

Conversation

@paulzhng

Copy link
Copy Markdown
Contributor

Fixes #1681 by moving eligible fixed scratch allocations into function entry during nvvm-transforms normalization.

Scratch introduced during lowering can otherwise remain in body blocks and introduce dynamic stack handling when NVVM inlines helpers. This updates the LLVM dialect IR before verification and export, preserving alignment, source/debug metadata and initialization sites. Each moved allocation gets a constant count defined in entry.

Dynamic counts remain untouched. Allocations inside cycles are only hoisted when their pointer uses prove that the address cannot escape or be observed across iterations. Ordinary PTX builds keep their existing behavior.

The first commit adds nvvm_entry_allocas following the existing example structure. It checks GPU results independently from allocation placement and PTX shape -- the numerical oracle already passes before the fix on CUDA 13.4. The second commit implements normalization and adds regression coverage.

Tested with Rust 1.99.1 and CUDA 13.4 on an RTX 5080:

  • 2,045 compiler tests passed, with 20 ignored.
  • Both NVVM dialects are covered, including escaping pointer uses, multi block cycles, count dominance and idempotence.
  • The example verifies all 1,024 results; its code shape check passes with no dynamic stack instructions.
  • The three GPU control examples and compile only check passed.
  • Compute-sanitizer memcheck reports zero errors.
  • Clippy, formatting, SPDX, dependency license and smoketest contract checks pass.

Please let me know if anything should be adjusted -- happy to fix!

Add the nvvm_entry_allocas standalone example. Check true-entry allocation
placement and the absence of dynamic-stack PTX instructions while keeping
an aggregate call with 128-bit parameter stores live through extended
split compilation. Verify GPU results independently against a host oracle.

On CUDA 13.4 the numerical oracle passes before entry normalization; the
code-shape check distinguishes the storage-placement regression.

Signed-off-by: Paul Zhang <paul@studio-vaai.com>
Normalize fixed scratch storage after NVVM compatibility rewrites, updating the LLVM-dialect IR before verification and export. Move original allocation operations with their metadata and supply dominating constant counts in entry, while retaining initialization at its original control-flow site.

Leave dynamic counts and loop slots with observable addresses in place. Cover calls, block arguments, comparisons, pointer conversions, returns, stored pointers and selects through pointer-view chains, with both NVVM dialects, multi-block cycles, idempotence and count-dominance checks.

Based on fcd6724.

Signed-off-by: Paul Zhang <paul@studio-vaai.com>
@paulzhng
paulzhng requested a review from nihalpasham as a code owner October 30, 2026 20:56
@copy-pr-bot

copy-pr-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fixed scratch allocations can introduce dynamic stack handling in NVVM

1 participant