Skip to content

fix(mir-importer): keep loop-hint marker branches off the attribute line - #1677

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:fix/unroll-marker-debug-location
Nov 3, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:fix/unroll-marker-debug-location

Conversation

@vyncint

@vyncint vyncint commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What This PR Does

Uses llvm_export::artificial_debug_location() for the synthetic MirGotoOp emitted when mir-importer replaces __unroll_config and __nounroll_config loop-hint markers, keeping #[unroll] and #[nounroll] attribute lines out of --device-debug line tables while preserving the attribute span on MirUnrollHintOp / MirNoUnrollHintOp for not-unrolled diagnostics.


Why the Attribute Line Appeared in --device-debug

#[kernel] and #[device] inject a __unroll_config / __nounroll_config marker call at the top of every annotated loop. mir-importer replaces that call with a hint op plus a MirGotoOp. Previously, the MirGotoOp inherited the marker call's source location (the attribute line), so under --device-debug (-O0), the unoptimized bra.uni emitted .loc pointing at the attribute line (38 of 38 loops in unroll_smoke).

BEFORE (cargo oxide build unroll_smoke --device-debug):
  $L__BB0_16:
      .loc 1 80 9      // main.rs:80:9 (the #[unroll] attribute line)
      bra.uni $L__BB0_17;

AFTER (with artificial_debug_location() on the marker goto):
  $L__BB0_16:
      .loc 1 0 0       // artificial location (matches #1125 kernel metadata markers)
      bra.uni $L__BB0_17;
--device-debug Attribute lines with a .loc: before -> after
unroll_smoke 38 of 38 -> 0
nounroll 8 of 8 -> 0

Verification

  • Regression (examples/debug): Adds loop_hint_test covering #[unroll], #[unroll(4)], #[unroll(never)], and #[nounroll]; verify-code-shape.sh rejects any LLVM IR !dbg or PTX .loc on those attribute lines while verifying each loop body keeps its own line (debug kernel-entry and loop-hint lineinfo shape: PASS).
  • GPU Execution (RTX 5090, sm_120a): debug runs clean under compute-sanitizer --tool memcheck (0 errors).
  • Tests & CI Gates: cargo test -p mir-importer --all-targets (1,234/1,234 PASS), just fmt-check, cargo clippy, and repository guards all pass.

Closes #1676

Under full device debug, the branch that replaces each `#[unroll]`,
`#[unroll(N)]`, `#[unroll(never)]` and `#[nounroll]` marker call kept the
call's location, which is the attribute. The attribute line therefore
landed in the loop's line table: all 38 such attributes in unroll_smoke
and all 8 in nounroll had a `.loc` on a branch inside their loop.
Line-tables builds were unaffected, since that branch does not survive
optimization.

Give the branch the artificial location, as NVIDIA#1125 does for the edges
that replace the kernel metadata markers. The hint op keeps the
attribute's location, which the not-unrolled warnings cite.

The debug example gains `loop_hint_test`, one loop per marker spelling,
and its verify-code-shape.sh now rejects any LLVM IR or PTX location on
those attribute lines while requiring each loop body to keep its own.
The script's LLVM IR and PTX helpers take the kernel name, so the
kernel-entry and loop-hint contracts share them.

Closes NVIDIA#1676.

Signed-off-by: Vyncint Ng <[email protected]>
@vyncint
vyncint requested a review from nihalpasham as a code owner October 30, 2026 10:32
@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.

@nihalpasham nihalpasham added cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book bug Something isn't working debug info Debug information in generated PTX/IR (line/source maps) codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Nov 3, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks, this is the right fix and matches how #1125 handles kernel metadata marker branches:

  • Keeps the attribute location on MirUnrollHintOp / MirNoUnrollHintOp so unroll diagnostics still point at the attribute.
  • Uses llvm_export::artificial_debug_location() on the generated MirGotoOp so --device-debug line tables stay off the attribute line.

At a7f85d42, mir-importer unit tests, repository guards, debug with --device-debug (verify-code-shape.sh), and RTX 5090 compute-sanitizer all pass. Merging once CI is green.

nihalpasham
nihalpasham previously approved these changes Nov 3, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

/ok to test 64c437c

@nihalpasham
nihalpasham merged commit 28b323c into NVIDIA:main Nov 3, 2026
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX) cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book debug info Debug information in generated PTX/IR (line/source maps)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full device debug puts #[unroll] and #[nounroll] attribute lines in the line table

2 participants