[PATCH] D78473: [i386] Fix bug that get __m128/__m256/__m512 with wrong alignment for variadic functions.Currently clang aligns to 16 bytes when passing __m128/__m256/__m512 vector type.However, when calculating va_arg, it will be always treated as 4 byte...

LiuChen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 19 22:57:09 PDT 2020


LiuChen3 created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
LiuChen3 abandoned this revision.

...alignment, including
struct, union and vector types. For struct/union, there is no probem because it will align
to 4 bytes when passing them. For __m128/__m256/__m512 vector type, it will get wrong result.

This patch will get va_arg according the rules below:

1. When the target doesn't support avx and avx512: get __m128/__m256/__m512 from 16 bytes aligned stack.
2. When the target supports avx: get __m256/__m512 from 32 bytes aligned stack.
3. When the target supports avx512: get __m512 from 64 bytes aligned stack.

Notice: The current behavior of clang is inconsistent with i386 abi. The i386-abi says as below:

1. If parameters of type __m256 are required to be passed on the stack, the stack pointer must be aligned on a 0 mod 32 byte boundary at the time of the call.
2. If parameters of type __m512 are required to be passed on the stack, the stack pointer must be aligned on a 0 mod 64 byte boundary at the time of the call.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78473

Files:
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/x86_32-align-linux-avx2.c
  clang/test/CodeGen/x86_32-align-linux-avx512f.c
  clang/test/CodeGen/x86_32-align-linux.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78473.258658.patch
Type: text/x-patch
Size: 11584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200420/5977492b/attachment-0001.bin>


More information about the cfe-commits mailing list