[llvm] [SROA] Preserve inherited alignment when rewriting allocas (PR #222967)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 14 19:49:54 PDT 2026
================
@@ -4,8 +4,8 @@
; RUN: opt < %s -mtriple nvptx64 -mcpu=sm_60 -mattr=ptx77 -passes=nvptx-lower-args -S | FileCheck %s --check-prefixes=COMMON,LOWER-ARGS,SM_60
; RUN: opt < %s -mtriple nvptx64 -mcpu=sm_70 -mattr=ptx77 -passes=nvptx-lower-args -S | FileCheck %s --check-prefixes=COMMON,LOWER-ARGS,SM_70
; RUN: opt < %s -mtriple nvptx64 -mcpu=sm_70 -mattr=ptx77 -passes=nvptx-copy-byval-args -S | FileCheck %s --check-prefixes=COMMON,COPY
-; RUN: llc < %s -mcpu=sm_60 -mattr=ptx77 | FileCheck %s --check-prefixes=PTX,PTX_60
-; RUN: llc < %s -mcpu=sm_70 -mattr=ptx77 | FileCheck %s --check-prefixes=PTX,PTX_70
+; RUN: opt < %s -mtriple=nvptx64 -mcpu=sm_60 -mattr=ptx77 -passes='nvptx-lower-args,sroa<preserve-cfg;aggregate-to-vector>,infer-alignment' | llc -mcpu=sm_60 -mattr=ptx77 | FileCheck %s --check-prefixes=PTX,PTX_60
----------------
zhouguangyuan0718 wrote:
SROA used to raise the byval local copy’s alignment from 4 to 8. With this patch it stays at 4. NVPTX’s default llc pipeline has no InferAlignment pass to recover that, so I added it explicitly to preserve the existing PTX checks.
With the original RUN lines, the relevant IR in `memcpy_to_param` is (names shortened):
```llvm
%slot = alloca <2 x i32>, align 4, addrspace(5)
store <2 x i32> %copy, ptr addrspace(5) %slot, align 4
store volatile <2 x i32> %value, ptr addrspace(5) %slot, align 4
```
The main PTX check changes would be:
```diff
-; PTX-NEXT: .local .align 8 .b8 __local_depot9[8];
+; PTX-NEXT: .local .align 4 .b8 __local_depot9[8];
-; PTX-NEXT: st.local.v2.b32 [%SPL], {%r2, %r1};
+; PTX-NEXT: st.local.b32 [%SPL+4], %r2;
+; PTX-NEXT: st.local.b32 [%SPL], %r1;
-; PTX-NEXT: st.local.v2.b32 [%SPL], {%r22, %r12};
+; PTX-NEXT: st.local.b32 [%SPL+4], %r22;
+; PTX-NEXT: st.local.b32 [%SPL], %r12;
```
The load order and register assignments also change. If needed, I can also update NVPTX’s default llc pipeline to run InferAlignment after SROA.
https://github.com/llvm/llvm-project/pull/222967
More information about the llvm-commits
mailing list