Skip to content

PTX optimization emits unreachable device helper definitions #386

Closed

Description

@niklebedenko

Problem

The PTX pipeline runs LLVM's default O2 pipeline, but non-kernel Rust device helpers retain external linkage. Even after every call has been inlined, GlobalDCE cannot remove an externally visible definition, so llc can emit unreachable .visible .func bodies into final PTX.

This increases PTX size and leaves compiler-generated helper symbols in an artifact whose externally consumed API consists of kernel entries, standalone device-function exports, and host-visible globals.

Before: optimized PTX retains fully inlined `.visible .func` helper definitions
After:  private helper definitions are removed while externally consumed symbols remain visible

Correctness boundary

The optimizer must not infer public roots from rendered LLVM text or assume that kernels are the entire module ABI. CUDA Oxide also emits standalone device functions and defined globals such as #[constant] symbols that host code resolves by name.

Until the IR distinguishes host-visible globals from compiler-private storage, retaining all defined globals is the conservative behavior that preserves existing linkage.

Reproducer

A module containing a marked kernel and an otherwise unused device helper emits both definitions without optimization. The optimized result should retain the kernel entry and remove the helper. As an adjacent ABI check, the constant_memory example must continue to locate, populate, and read its constant symbol from the host.

Acceptance criteria

  • Non-root helper definitions are absent from optimized PTX.
  • Kernel entries, standalone device-function roots, and defined globals retain external linkage.
  • The optimizer receives roots from typed exporter state, without parsing rendered LLVM.
  • Modules without roots and no-opt compilation retain their current behavior.
  • Automated tests cover optimized deletion, no-opt retention, and constant-memory host lookup.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions