Skip to content

llvm-export: encode enum debug tags as unsigned storage - #1222

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
ZenAlexa:contrib/1220-full-debug-llc-o0-emits-b8-4294967295-that-ptxas-rejec
Sep 3, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
ZenAlexa:contrib/1220-full-debug-llc-o0-emits-b8-4294967295-that-ptxas-rejec

Conversation

@ZenAlexa

@ZenAlexa ZenAlexa commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • encode signed direct-enum discriminator metadata as an unsigned carrier of the same storage width
  • preserve each DebugEnumVariant.discriminant raw bit pattern and ordinary signed-local metadata
  • exercise high-bit i8 tags through full-debug export and real LLVM 21, 22, and 23 llc -O0 NVPTX lowering

Motivation

DebugEnumVariant.discriminant stores the physical tag bits in a u64. LLVM's NVPTX DWARF path derives extension behavior from the artificial discriminator carrier. A signed i8 carrier sign-extends tags 255 and 251, producing .b8 4294967295 and .b8 4294967291; ptxas rejects both records. The same-width unsigned carrier selects zero extension and emits .b8 255 and .b8 251.

The conversion is scoped to the artificial enum discriminator member. Ordinary signed locals retain DW_ATE_signed.

Validation

  • cargo test -p llvm-export
  • focused full-debug enum test with LLVM 21, 22, and 23 llc -O0
  • signed-carrier control: .b8 0xffffffffffffffff
  • unsigned-carrier treatment: .b8 255
  • H100 80GB HBM3 integration: both examples built with Rust 1.100 nightly and LLVM 23.1, emitted .b8 255 and .b8 251, and assembled with CUDA 13.1.115 ptxas at exit code 0
  • cargo clippy -p llvm-export --all-targets -- -D warnings
  • repository formatting and git diff --check

Fixes #1220

Copilot AI lite review requested due to automatic review settings September 2, 2026 15:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ZenAlexa

ZenAlexa commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

H100 integration is complete. Both examples built with Rust 1.100 nightly and LLVM 23.1, emitted .b8 255 and .b8 251, and assembled with CUDA 13.1.115 ptxas at exit code 0.

@nihalpasham

nihalpasham commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Worth landing. I reproduced the chain with a hand-written module through llc-21, llc-22 and the toolchain's llc 23.1:

discriminator type   DW_AT_discr_value in PTX    ptxas
i8  (signed)         .b8 0xffffffffffffffff      Value out of range for type .b8 4294967295
u8  (unsigned)       .b8 255                     ok

The 4294967295 in #1220 is ptxas re-printing that hex literal, so both reports are one record.

  • The real bug is upstream. LLVM's text-assembly writer (MCAsmStreamer::emitIntValue) creates the 1-byte DWARF constant with no size, and NVPTX has no signed data directive, so it prints a 64-bit hex literal. DwarfUnit's form choice is fine. I will file the LLVM issue.
  • Unsigned is a legitimate encoding, not a hack. The discriminator (the hidden tag byte that says which variant is live) is compared as DW_FORM_data1, which carries no sign; the discriminator's type decides, so 255 == 255. rustc already does this for niche tags and keeps the sign on direct tags only because ELF object emission never touches the text printer. It holds for 16/32/64-bit tags too: unsigned picks a wider form, and NVPTX masks the split .b8 pairs.
  • Coverage checks out: direct tags are the only signed discriminators the importer produces, discriminant.ty has no other consumer in the exporter, and nothing else there emits a signed DWARF constant.
  • On this head, locally: cargo test -p llvm-export passes with llc 18, 21, 22 and 23 all discovered; both full debug: llc -O0 emits .b8 4294967295 that ptxas rejects (repr_u32_enum_stride, set_discriminant) #1220 examples build with CUDA_OXIDE_DEBUG=full, assemble with ptxas 13.3 (.b8 255 / .b8 251), and run on an RTX 5090. Nothing landed on main since you branched.

One change before I merge: rewrite the comment at debug.rs:828 to name what it routes around (LLVM MC prints a negative 1-byte DWARF constant as a 64-bit hex literal on NVPTX, ptxas rejects it), why unsigned is equivalent (DW_FORM_data1 has no sign, the discriminator type decides), and when to drop it (once every llc I support truncates the literal). Without that, someone will "fix" it back to match rustc.

Optional: have discover_llvm_tools skip majors below 21 so the gate only runs on toolchains cuda-oxide supports. Can you push the comment change?

@ZenAlexa

ZenAlexa commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for tracing the LLVM MC path. The comment now records the NVPTX text-emission failure, signless DW_FORM_data1 semantics, and the supported-llc removal condition. Tool discovery stays unchanged to preserve the broader regression probe; LLVM 21 remains the supported floor. cargo test -p llvm-export, crate clippy, repository formatting, and git diff --check pass.

@nihalpasham nihalpasham added bug Something isn't working debug info Debug information in generated PTX/IR (line/source maps) llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate) labels Sep 3, 2026
@nihalpasham
nihalpasham merged commit d843d5b into NVIDIA:main Sep 3, 2026
52 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 debug info Debug information in generated PTX/IR (line/source maps) llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

full debug: llc -O0 emits .b8 4294967295 that ptxas rejects (repr_u32_enum_stride, set_discriminant)

3 participants