<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63535>63535</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Missed compiler optimization with member wise initialization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
martijnvels
</td>
</tr>
</table>
<pre>
The compiler does not optimize (coalesce) adjacent initializations when doing member-wise initialization.
See the example in https://gcc.godbolt.org/z/qnxxz8jh3
All 3 code alternatives basically implement a copy construct of an instance. This example is trivial and the default ctor would suffice, but in practice we often have cases where the default constructor does not suffice.
The poignant part is that the compiler does optimize a full instance memcpy for the default ctor, but does not do so for a member-wise init. The only alternative left for the code is to use alternative hand-rolled initialization (ALT). Our practical use case is protocol buffer generated message code where at scale, the cost of this can add up as throughput for hot data copies is limited mostly by stores / cycle for large, mostly trivial message data. (i.e. our example has 1 store vs 4 stores).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVMuS6jYQ_Rqx6RqXkcHAwotJbrFKKovMD7Sltq0pWXLUbRjm61Myj3ndDSxonT4vGpldH4gatf1DbX-tcJYhpmbEJO41nMjzqo320rwMBCaOk_OUwEZiCFEgTuJG906g9N5E9MSGlD4A2lc0FARccOLQu3cUFwPDeaAANrrQw0hjS-np7Ji-jRWq_KXK5-vnv0QgAwG94Tj5PAqDyMSqelb6qPSxN6boo22jlyKmXunju9LH_8Lb2_v-dag-Yz17DxWYaAnQC6WA4k7E0CI7g95fwOUdY2aOYOJ0ARMDS5qNQOwAA7jAgsFQAS-D4w9WDJLcyaEHDHYhbKnD2QsYiQnOcfYWeO46lx36E9o5mwNTQiPOEJwJYicUYMATgUGmxaxEX7HubOKnEG6oX1zLcU3R9QGDwIRJFoYDygL3NchHiAjd7P1DYk7ITBfoYvoh6C7hQcJG4LiM4o9ks1cEMfjLZ9vBUycP8CWUzDHCzF_igQGDfUrRe7LfipJr9_zXi9KHAv6Z091N9AtGNjFDTilKNNFDO3cdJegpUEIhCyMxY39bfnUbBdigXzK68uIleslpGwyA1sI8AWY7U5z7YZqvKobsAsrSG0ecN3s3umVPZPEXaC_AEhMxKH0EczGelpceU78svM3dm3Snl1GLrNUVVECc06N2AzKsr6BwYtjc8BdDPtdhZZvKHqoDrqhZ1_vdXlebql4NTaXr_XZX2327tuV2vVmvD1W3oZ3e29pUul25Rpe6Kmtd62pbVnWxWdfreleXZd3u6w53alPSiM4X3p_G_AdcOeaZmrraVtuVx5Y8L8dF60BnWH5UWudbk5r85qmde1ab0jsW_kARJ56avx0z2Y_C3rp6Tf_sZLiVDX5zRlZz8s23W-FkmNvCxFHpY151-3qaUnwlI0ofF4Ks9HER8H8AAAD__0kPxpc">