<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/67497>67497</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            odd code generated for swapping...
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Clang has always had this odd detection for swapping - if you are swapping one register's worth of data (1,2,4,8, or 16 byte elements), it will detect this kind of code pattern:

int t = a; a = b; b = t;

But as soon as there are two registers worth of data (like a struct with 32 bytes - 2 16 byte regs, or a struct with 6 bytes - 1 int and short), it gives up and buffers the whole thing on the stack first and then moves things around.  GCC and MSVC both detect this swapping style code perfectly, no matter how big the struct it.

Here's a simple Compiler Explorer that shows the problem:

https://godbolt.org/z/Td63qr1r4

It's not a huge problem but I can measure it when sorting small structs.  And heck, even crappy 32-bit MSVC does this ok. 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxslM-yrCYQxp8GN11jOeg414WLezyZ5C6ySip7kFa4g2CgPWby9CmYqTl_Khul6Kb5fl8DIkYzO8SenV7Y6bUQG2kf-p84TYKCUIX06tYPVrgZtIgg7C5uEbRQQNpE8EqBQsKRjHcw-QBxF-tq3AwHMBPc_AYi4PusdwgBZxMJA-PnCLsPpMFPoAQJYPzbkfGBMz40jA_fGB_ABzi2IG-EgBYXdBQZ71LEEOzG2oeCu6KrcSqVG71CWAURBsfq76x6ZdXjaxwBAatfQbD6BUQeyjSUeUisfvmY_7IRiAjRe5f-pDFgpqLdP2H-h8SaK4KASGEbk1LSUPMMEuEA_EkVcI4P0M_Z7TP5CEm0cAqi9oHe-WfzhhG2NcfkNk1JCWmEXXuLyZJsep6KJMYrTCbEeynS6GDxqUDOiyCC35wqAX4dhpzy-x9_DSA96U8eP7sZ6WbxYTWGCUeytyTMeViy9aD9DtLMj_0zmqHyo7u_YcB8EgREs6wWYfDLaiwG-OWf1fqAAUgLSuT7nW0NXlpcvrRVE60xzfEL45fZK-ktlT7MjF_-Zfzyp2rrv8MxNB8X_aC8t_MEAvQ2P4uD3Ah-wCgcLCjiFjAft2RZ9IEy_SKsfVDFEuC7U6BxvCYH8A0djEGs6w1qfpCG7l4qf3c7gr-WcNdQqL5WXd2JAvtj253O7blpToXuu64bO6FO_HziksvqVDdKyU5KWSveHVVhel7xuup4y3ldNaeyGqXCamq5quTYKsmaChdhbGnt25K8KEyMG_btuenOhRUSbcx3n3OHO-Qg4zw9BaFPaw5ymyNrKmsixfcqZMhin25_bv6MDoMgVJ-egLIsiy3Y_ktjDOlNlqNfGL-kgo_fYQ3-J47E-CXLiIxfssz_AgAA___tHYWu">