Skip to content

Small runtime-indexed local arrays spill to PTX local memory #397

Closed

Description

@niklebedenko

Problem

Small fixed arrays indexed by a runtime value are lowered through an alloca and dynamic GEP. After inlining and normal optimization, those accesses can remain as per-thread PTX local memory even when the array is tiny and the surrounding loop has a compile-time bound.

This affects both by-value reads and reads/writes through compiler-owned local arrays. It is especially visible for nested aggregate arrays, where otherwise ordinary Rust range loops produce .local, ld.local, and st.local instructions.

Expected behavior

For small fixed arrays, cuda-oxide should use bounded constant-index extract/GEP plus select chains so LLVM can keep values in SSA. Large arrays and borrowed/external arrays should retain ordinary memory lowering to bound code growth and preserve memory-access semantics. A bounded post-inline full-unroll pass is also needed so Rust range-loop helpers expose those constant accesses before final SROA.

Reproducer

The existing array_for_loop GPU example can be extended with runtime reads/writes of a three-element aggregate array and assertions that the generated kernel contains no PTX local-memory operations.

Activity

  1. added
    optional-opts
    codegen
    on Aug 6, 2026
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

    codegenoptional-opts

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions