<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJzFVk1z2zYQ_TXUBWMNRYqyfNAhtpOml_aSmR41ILkiEYMAgw9L8q_vW1CSLdfNTKaHemgTIIB9b99-wLVtj5uvKisexO-iJq3omTDqJV47G00rpBHKNNZ45QOZ5oiZCD0J6T0NtT5imxPSdXEgE8SIz8p0wu6EsebGB2la6VoRjiN5RtHqiUS2yrfboahWCiPAhj0RrDppvJZBWSOiUcHDRBCNHUalqRV7FXqhWqCoRmpANr0K1IToQFXLzousWMPezcBLWfk4n88xzYq7uXhg_i25xHxntbZ7ZunlMGpiWn7UKsC1YEXY239SycpPWf6Y5Z_Y4vRM06KEOjq2cKp8OKxXMOGUmQP_82lH-rvdyoCFOgbabplnsQ4QjUIaF_L5UOAFrqcnHYItofz2hZzFtpNi4nBZz27vp4HAjyMoYcR24F3bQD68bL3CGEcP7GI6V95DpS94Tvu9WAi124kDgITUWjCYP5t__NBnhPT_0WJnbdrykft0CMTu_5pt8ROJy_u3pBmDqyCIyyZ4-XjW21NgGxfFr7XG6qRuzVmNHEt470P3yuMa_1_CMP39q0flTDXCGV1bFIm30TXkp4rhivizSHUWQ_pk8ZbmiJynRu1U80Epcb5wqXRkyMmA6msswirHkaRLHnChT33gXPqAODCMnfoDSr95Yjv7XjU9p5fnquqwgiyhiekumoaLDOoAGoX7BCiuwRQzweEC1VZ4kNatiB54kKvjXuQQPLxkOxf38IgxHaExjM7WmgZGDL2Ey6zQB92CEUdHHtxTB4hgKb1420F66fekdeoiHwrSWppUoAPE5M-h5zAwZ5D1F67-TJY740WetA-Y7JOPOqAVIpTkU8cdRvQfeDKFkc-A7bOy0QtEcIyJNZxtI8c6Gqy2qgmSj9SEDq7QmJPzgzpQO3-bNX_YQJM64OtZKm618lW7iWTq2ixUEkgeT417UazVSZMplpzah9USAYTKBkfS_fHqu-ZwCjI2dj2Ht7cIZhL8Weo4XQwsRaORIOLJ2L2fiPHHi8ZOdX04CVwfL1fNVRLicnqTIBjg8tGEVIXsVzlgx5R3V6p8Y0hPNKQMr2nic3OpE0RHcgp2DWpG7-XRJxLkf8LhCuArAZndEp1ta4uAA0dpHbk0UkR42UcSfQhjunRSAzntnlvXYfaCX6p-fMNH_9s7B6R58tONjJCwuZ5v3711KMXFtGnWbsr2rryTMxnRDNwGxeX9d3Kz6PTmHTBSL9ZzJCMmWj-fXzdIlO9QEtPEFxH8UpWrxd2s38hmtaTbvF7m5UpWd8vVbb6slk3ZrsuqoSqfaYl_NPwmq-6z6nH23yHVpsgLPDkm1aJazdt2QbIq6ny9Lppy1WbLnAap9JztsIgzt0km64hWt8w1IuVfFzmvOkN0ZhhU0LT55ZtlqqnXpE8d83x5cNGf8sWjlTgHz_RxljzbJLf-BpeRIig>53619</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            __attribute__((target("avx2"))) is not enough to pass __m256i as arguments correctly
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          shossjer
      </td>
    </tr>
</table>

<pre>
    Hi, I believe I have found an inconsistency in the assembly for argument passing of non-standard types, like `__m256i` between translation units not compiled with identical architecture flags (`-march=...`). Consider the following sample, split into two translation units:
```
#include <x86intrin.h>

__attribute__((target("avx2")))
int is_zero(__m256i x)
{
    return _mm256_testz_si256(x, x); // returns 1 iff x is all zeros
}
```
and
```
#include <x86intrin.h>

__attribute__((target("avx2")))
int foo()
{
    extern __attribute__((target("avx2"))) int is_zero(__m256i x);

    const __m256i x = _mm256_setzero_si256(); // sets all bits to zero
    return is_zero(x);
}
```

When compiling both sources with `-O2` but without any specific architecture flags, the generated code appears to pass the argument `x` on the stack, which is strange since both functions are marked to target avx2 and should use a register instead. But the real problem is that when architecture flags are present, such as `-march=haswell`, the generated code does the expected thing and uses registers instead of the stack and as a result becomes incompatible with the previous output, produces unpredictable behavior when mixed.

Note that this is not a problem if the types are, say `__m128i`, since all x64 machines have registers large enough to hold such values, and clang knows this and does the right thing by passing the argument in a register regardless of architecture options.

This seems to be clang-specific because gcc always passes the argument in a register.

Here is a godbolt to illustrate the issue https://godbolt.org/z/e5qTodbsG.

Thanks for all the hard work!

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFVk1z2zYQ_TXUBWONRFqydNAhtpOml_aSmR41ILEiEYMAgw9L8q_vW1CSLcfNTE710CZAALtv3-4-uHbquPmqi_JB_ClqMpqeCaNO4rVzySohrdC2cTboEMk2R8xE7EjIEKivzRHbvJC-TT3ZKAZ81rYVbiesszchSqukVyIeBwrsxegnEsVytt325WKpMYLbuCeCVS9tMDJqZ0WyOgaYiKJx_aANKbHXsRNawYtupIHLptORmpg8oBrZBlGUK9i76XmpqB6n0ymmRbmeigfGr8hn5DtnjNszyiD7wRDDCoPREaFFJ-Le_QylqD4Vs8di9oktjs84LSuwY5JCUNXDYbWECa_tFP4_n3bkv9utjFioU6TtlnGWqwjSKOZxKZ8PJV7AenryIdgSOmxfyDtsOzEmDpf14u5-HAj8eAITVmx73rWNFOLLNmiMcfTAIeZz1T1Y-oLntD-IudC7nTjAkZDGCHYWzuYfP4wZKf1_uNg5l7d8FD4dInH4v2db_ILi6v4taPbBXRDFZROifDzzHSiyjQvj11xjdWS35qpGjWV_71P3iuPa_3-kYfz7T4fOGXuEK7p2aJLgkm8ojB3DHfF3mfssxfzJ4S3tETVPjd7p5oNW4nrhVmnJkpcR3dc4pFUOA0mfI-BGH3Xg3PpwcWA3btQHtH7zxHb2nW46Lq_AXdViBVVCI9Jdsg03GdiBazTuE1xxD-acCU4XoCoRANookQL8ga6WtcgjeXhJNRX3iIh9eoIwDN7Vhnr2GDuJkJmhD9SCPQ6eArBnBUhAKYN4qyCdDHsyJqvIh4QoRyMLdACZ_Dl2nAbGDLDhgjWcwbIyXujJ--CTYwrJREghUkkhK24_QH8QyZhGPgO0z9qlIJ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