[PATCH] D98794: [AArch64] Correctly align HFA arguments when passed on the stack

Momchil Velikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 17 10:25:07 PDT 2021


chill created this revision.
Herald added subscribers: dexonsmith, jdoerfert, danielkiss, hiraditya, kristof.beyls.
chill requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When we pass a Homogeneous Floating-Point Aggregate (HFA) argument
with increased alignment requirements, for example

  struct S {
    __attribute__ ((__aligned__(16))) double v[4];
  };


Clang uses `[4 x double]` for the parameter, which is passed on the
stack at alignment 8, whereas it should be at alignment 16, following
Rule C.4 in  AAPCS (https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#642parameter-passing-rules)

Currently we don't have a way to express in LLVM IR the alignment
requirements of the function arguments. The `align` attribute is
applicable to pointers only, and only for some special ways of passing
arguments (e..g `byval`). When implementing AAPCS32/AAPCS64, clang
resorts to dubious hacks of coercing to types, which naturally have
the needed alignment. We don't have enough types to cover all the
cases, though.

This patch introduces a new use of the `stackalign` attribute to
control stack slot alignment, when and if an argument is passed in
memory.

The attribute `align` is left as an optimizer hint - it still applies
to pointer types only and pertains to the content of the pointer,
whereas the alignment of the pointer itself is determined by the
`stackalign` attribute.

For `byval` arguments, the `stackalign` attribute assumes the role,
previously perfomed by `align`, falling back to `align` if
stackalign` is absent.

In a followup patch, clang will start generating `stacklign` for
`byval` arguments.

Patch by Momchil Velikov and Lucas Prates.


https://reviews.llvm.org/D98794

Files:
  clang/include/clang/CodeGen/CGFunctionInfo.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aarch64-args-hfa.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/Argument.h
  llvm/include/llvm/IR/Attributes.h
  llvm/include/llvm/IR/Function.h
  llvm/include/llvm/IR/InstrTypes.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
  llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Target/AArch64/AArch64CallingConvention.cpp
  llvm/test/Bitcode/compatibility.ll
  llvm/test/CodeGen/AArch64/arm64-abi-hfa-args.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98794.331306.patch
Type: text/x-patch
Size: 20894 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210317/9f65a55e/attachment.bin>


More information about the llvm-commits mailing list