[LSROA] Nested struct support
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The LSROA pass should recursively handle nested aggregates.
The current LSROA implementation only optimizes the first level of aggregates, which means it isn't effective for more complicated structures. We should handle nested aggregates either by updating to a recursive algorithm or iterating the current pass to a fixed point.
### Acceptance Criteria
Given some IR with a `structured.alloc` of a nested struct, where it loads and stores to nested values via `structured.gep`:
```llvm
%S = type { i32, { i32, i32 } }
define i32 @test_nested_struct() {
entry:
%tmp = call elementtype(%S) ptr @llvm.structured.alloca.p0()
%sgep = call ptr (ptr, ...) @llvm.structured.gep.p0(ptr elementtype(%S) %tmp, i32 1, i32 0)
store i32 0, ptr %sgep
%v = load i32, ptr %sgep
ret i32 %v
}
```
We should be able to elminate the `structured.gep` and operate on the nested values directly:
```llvm
%S = type { i32, { i32, i32 } }
define i32 @test_nested_struct() {
entry:
%tmp_i32 = call elementtype(i32) ptr @llvm.structured.alloca.p0()
store i32 0, ptr %tmp_i32
%v = load i32, ptr %tmp_i32
ret i32 %v
}
```
We will need to update the existing [LSROA/nesting.ll] test case to show that this works.
[LSROA/nesting.ll]: https://github.com/llvm/llvm-project/blob/03b5c52/llvm/test/Transforms/LSROA/nesting.ll
Contributor guide
Assessment
This issue has not been assessed yet.