This is an archive of the discontinued LLVM Phabricator instance.

[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...
AbandonedPublic

Authored by LiuChen3 on Apr 19 2020, 10:48 PM.

Details

Reviewers
None
Summary

...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.

Diff Detail

Event Timeline

LiuChen3 created this revision.Apr 19 2020, 10:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2020, 10:48 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
LiuChen3 abandoned this revision.Apr 19 2020, 10:50 PM