<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/125429>125429</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[maybe missed optimizaton] Suboptimal assembly with constexpr non-static VS static variable
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
chrooti
</td>
</tr>
</table>
<pre>
Looking at the following example on Godbolt: https://www.godbolt.org/z/cMoojqsd3
the assembly generated is optimal: to call writev one lea and three movs are emitted. If the static specifier is removed from the definition of `vecs` the assembly degenerates into a bunch of `movaps` that copy the `.data` section entries into the stack before passing a pointer to it.
Given that string literal are supposed to live in static storage and the the Iovecs are just pointers to them whether they are `static` or not probably should not make any difference to the generated asm output.
Notably in the IR output `@__const.main.vecs` switches from `internal` linkage in the optimal "static" case to `private unnamed_addr` in the "non-static" one, which seems both correct _and_ the eventual source of the possibly missed optimization.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxkVEGP2zYT_TX0ZbCCRMne3YMO-32BgwBtDw3QqzEiRxZ3KY5KjqQ4v76gLCcNejAMcPjevPdmREzJXQNRq47_U8dPB5xl4NiaITKLO3Rsb-1vzB8uXAEFZCDo2Xte8wF9w3HyBBzgM9uOvaj6DQaRKan6Temz0ud1XYvrvVhwvCp9_q702fzO_P53srUq31T5lmkxJRo7f4MrBYooZMEl4EnciD7zCoNB72GNTmgBDgSeEDBYkCESwchLAowENDoRsgV86TfFSVCcgTSRcb2jmIkjjbyQhT7yuF2y1LvgxHEA7kGdyoVMUqcSfhFn6SEvgQvCgNDNwQw7ZuQFpx2FAoan24ZXp7KwKJgriczWhYJE96DZZZoP6KjnSDDlyeTQYWIXhGL276SAe2Kf3ULh3iRJzBe9E4rotwDSPE2cyGaMdwuBCz9CEI54pT022n5fOHvdkO9zkkfHBHdhI6wDyZAlDHTbrqlTeefLhjhCYIEpcoc5ozTw7O12NuJHbnUD6_qeIgVDO-m_xoxpBJ5lmqVQ5dsfLBuLC3dtf-613FM15eViOCQpRnSheIworU7MQOk-TXUqN_0BfS56Fz6y451w3yhQWu8WtAaDaROmTuUU3YJCMIeAI9kLWhszzQ5XWgcOTz-hHEjp_8M6ODNAIhoTdCwDGI6RjMAFg71sUFooyIweEs_RUF6ZfDxxSi47Hl3KM9sEuu-Yl6Q42La2r_UrHqitnuuXoz7q5_owtE3doamq5uW5aUp6bfq-76yt7AtWdVeb7uBaXepjqUtdvTZVVRcvdW1Md8SqJovP1KimpBGdL7xfxvxtHlxKM7WVPjb69eCxI5-2d0HrQCtsVaV1fiZim0FP3XxNqim9S5J-0ogTvz0oI946-o8tDur4Cb7O3WMSPz6u1W25hST0bcpL9cgZ_vr62N8Fo8PO02GOvv31qbk6GeauMDwqfc5q9r-nKfI7GVH6vHlISp93k0ur_wkAAP__Fw29Kw">