[llvm] [IR] Add logical SROA pass (PR #192058)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 01:55:43 PDT 2026


================
@@ -0,0 +1,33 @@
+; RUN: opt < %s -passes='lsroa' -S -debug | FileCheck %s --check-prefixes=CHECK
+
+declare void @llvm.lifetime.start.p0(ptr nocapture)
+declare void @llvm.lifetime.end.p0(ptr nocapture)
+declare ptr @llvm.structured.alloca.p0()
+declare ptr @llvm.structured.gep.p0(ptr, ...)
+
+%S = type { i32, { i32, i32 } }
+
+define i32 @test_nested_struct() {
+; CHECK-LABEL: @test_nested_struct(
+; CHECK-NEXT:  entry:
+entry:
+  %tmp = call elementtype(%S) ptr @llvm.structured.alloca.p0()
+  %0 = call ptr (ptr, ...) @llvm.structured.gep.p0(ptr elementtype(%S) %tmp, i32 0)
+  %1 = call ptr (ptr, ...) @llvm.structured.gep.p0(ptr elementtype(%S) %tmp, i32 1, i32 0)
+
+; CHECK: %[[#a:]] = call elementtype(i32) ptr @llvm.structured.alloca.p0()
+; CHECK: %[[#b:]] = call elementtype({ i32, i32 }) ptr @llvm.structured.alloca.p0()
----------------
Keenuts wrote:

This will be splited up by running the initial loop again:
naive solution will be so call the runLSROA function again each time we get a `changed` result set to `true`. When we stop receiving `changed`, this means we have no more nested composite.
This is obviously the most straightforward naive solution, another would be to add them to the worklist again etc. In all cases, this is out of scope for this PR (hence this test)

https://github.com/llvm/llvm-project/pull/192058


More information about the llvm-commits mailing list