Skip to content

Commit 0191307

Browse files
authored
[IR] Allow alignstack attribute on return values (#130439)
The PTX target allows an alignment to be specified on both return values and parameters to allow for more efficient vectorized stores. Currently we represent these parameter alignments via the "alignstack" attribute, but must fall back to metadata for the return value. This PR allows "alignstack" on return values as well.
1 parent 4336e5e commit 0191307

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

llvm/docs/LangRef.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,12 +1616,12 @@ Currently, only the following parameter attributes are defined:
16161616

16171617
``alignstack(<n>)``
16181618
This indicates the alignment that should be considered by the backend when
1619-
assigning this parameter to a stack slot during calling convention
1620-
lowering. The enforcement of the specified alignment is target-dependent,
1621-
as target-specific calling convention rules may override this value. This
1622-
attribute serves the purpose of carrying language specific alignment
1623-
information that is not mapped to base types in the backend (for example,
1624-
over-alignment specification through language attributes).
1619+
assigning this parameter or return value to a stack slot during calling
1620+
convention lowering. The enforcement of the specified alignment is
1621+
target-dependent, as target-specific calling convention rules may override
1622+
this value. This attribute serves the purpose of carrying language specific
1623+
alignment information that is not mapped to base types in the backend (for
1624+
example, over-alignment specification through language attributes).
16251625

16261626
``allocalign``
16271627
The function parameter marked with this attribute is the alignment in bytes of the

llvm/include/llvm/IR/Attributes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def SExt : EnumAttr<"signext", IntersectPreserve, [ParamAttr, RetAttr]>;
291291

292292
/// Alignment of stack for function (3 bits) stored as log2 of alignment with
293293
/// +1 bias 0 means unaligned (different from alignstack=(1)).
294-
def StackAlignment : IntAttr<"alignstack", IntersectPreserve, [FnAttr, ParamAttr]>;
294+
def StackAlignment : IntAttr<"alignstack", IntersectPreserve, [FnAttr, ParamAttr, RetAttr]>;
295295

296296
/// Function can be speculated.
297297
def Speculatable : EnumAttr<"speculatable", IntersectAnd, [FnAttr]>;

llvm/test/CodeGen/NVPTX/param-overalign.ll

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ define float @caller_md(float %a, float %b) {
4545
ret float %r
4646
}
4747

48-
define float @callee_md(%struct.float2 %a) {
48+
define float @callee_md(%struct.float2 alignstack(8) %a) {
4949
; CHECK-LABEL: .visible .func (.param .b32 func_retval0) callee_md(
5050
; CHECK-NEXT: .param .align 8 .b8 callee_md_param_0[8]
5151
; CHECK-NEXT: )
@@ -105,5 +105,10 @@ define float @callee(%struct.float2 alignstack(8) %a ) {
105105
ret float %2
106106
}
107107

108-
!nvvm.annotations = !{!0}
109-
!0 = !{ptr @callee_md, !"align", i32 u0x00010008}
108+
define alignstack(8) %struct.float2 @aligned_return(%struct.float2 %a ) {
109+
; CHECK-LABEL: .visible .func (.param .align 8 .b8 func_retval0[8]) aligned_return(
110+
; CHECK-NEXT: .param .align 4 .b8 aligned_return_param_0[8]
111+
; CHECK-NEXT: )
112+
; CHECK-NEXT: {
113+
ret %struct.float2 %a
114+
}

0 commit comments

Comments
 (0)