Why doesn't gcc resolve _mm256_loadu_pd as single vmovupd? : <p>I'm writing some <em>AVX</em> code and I need to load from potentially unaligned memory. I'm currently loading 4 <em>doubles</em>, hence I would use intrinsic instruction <a href="https://software.intel.com/en-us/node/524102" rel="noreferrer">_mm256_loadu_pd</a>; the code I've written is:</p>

<pre><code>__m256d d1 = _mm256_loadu_pd(vInOut + i*4);
</code></pre>

<p>I've then compiled with options <code>-O3 -mavx -g</code> and subsequently used <em>objdump</em> to get the assembler code plus annotated code and line (<code>objdump -S -M intel -l avx.obj</code>).<br>When I look into the underlying assembler code, I find the following:</p>

<pre><code>vmovupd xmm0,XMMWORD PTR [rsi+rax*1]
vinsertf128 ymm0,ymm0,XMMWORD PTR [rsi+rax*1+0x10],0x1
</code></pre>

<p>I was expecting to see this:</p>

<pre><code>vmovupd ymm0,XMMWORD PTR [rsi+rax*1]
</code></pre>

<p>and fully use the 256 bit register (<em>ymm0</em>), instead it looks like <em>gcc</em> has decided to fill in the 128 bit part (<em>xmm0</em>) and then load again the other half with <em>vinsertf128</em>.</p>

<p>Is someone able to explain this?<br>
Equivalent code is getting compiled with a single <em>vmovupd</em> in MSVC VS 2012.</p>

<p>I'm running <code>gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0</code> on <em>Ubuntu 18.04 x86-64</em>.</p>
