llvm / llvm/llvm-project

[LSROA] Array support

Open
#192,620 0 comments 0 reactions 1 assignee View on GitHub

@bogner is already working on this.

Since Aug 26, 2026.

enhancement llvm:transforms
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

We should update the LSROA pass to analyze loaded indices of arrays and only extract those.

The current LSROA implementation only splits load/stores on structs, not arrays. This means if a global array is copied in a temporary and a single element is loaded, the full array may be copied (for example if it's in a different address space, like it is in SPIR-V).

Acceptance Criteria

Given some IR with a structured.alloc of an array, where it loads and stores to individual elements via structured.gep:

define i32 @test_simple_array() {
entry:
  %tmp = call elementtype([10 x i32]) ptr @llvm.structured.alloca.p0()
  %ptr = call ptr (ptr, ...) @llvm.structured.gep.p0(ptr elementtype([10 x i32]) %tmp, i32 0)
  store i32 0, ptr %ptr
  %res = load i32, ptr %ptr
  ret i32 %res
}

We should be able to elminate the structured.gep and operate on the individual elements directly:

define i32 @test_simple_array() {
entry:
  %tmp_i32 = call elementtype(i32) ptr @llvm.structured.alloca.p0()
  store i32 0, ptr %tmp_i32
  %res = load i32, ptr %tmp_i32
  ret i32 %res
}

We will need to update the existing LSROA/array.ll test case to show that this works.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.