This is an archive of the discontinued LLVM Phabricator instance.

[i386] Fix bug that get __m128/__m256/__m512 with wrong alignment for variadic functions.
Needs ReviewPublic

Authored by LiuChen3 on Apr 20 2020, 7:54 PM.

Details

Summary

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

Diff Detail

Event Timeline

LiuChen3 created this revision.Apr 20 2020, 7:54 PM
LiuChen3 added a comment.EditedApr 20 2020, 8:02 PM

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

  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.

I think it's better to modify calling convention of the clang.

CCing cfe-commits

I uploaded a new patch D78564 as another solution, but it modified the current clang calling convention.

RKSimon resigned from this revision.Jun 18 2020, 2:11 AM