<div>Hey Michael,</div><div><br></div><div>Thanks for the legwork!</div><div><br></div>It appears that the stats you listed are for movaps [SSE], not vmovaps [AVX]. I would *assume* that vmovaps(m128) is closer to vmovaps(m256), since they are both AVX instructions. Although, yes, I agree that this is not clear from Agner's report. Please correct me if I am misunderstanding.<br>
<div><div><br></div><div>As I am sure you are aware, we cannot use SSE (movaps) instructions in an AVX context, or else we'll pay the context switch penalty. It might be too big an assumption to assume that movaps and vmovaps have the same timings. Same for movsd.</div>
<div><br></div><div>Also, I'm sure you are aware that the Sandybridge optimization guide suggests that unaligned stores be split into a 128b store and 128b extract. This does argue against my above assumption.</div><div>
<br></div><div>For full disclosure, I have not timed the individual instructions; just kernels. So, my performance gains may be coming from another source related to this change. Most likely, my gains are from better use of cache, since we would not be moving unneeded bytes around. In the context of shared cache, this savings may be enough to keep the other cores more busy. Not to mention the stack space saved. But, I cannot say for sure right now.</div>
<div><br></div><div><br><div class="gmail_quote">On Fri, Jul 27, 2012 at 3:45 AM, Michael Gottesman <span dir="ltr"><<a href="mailto:mgottesman@apple.com" target="_blank">mgottesman@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div>Just looked up the numbers from Agner Fog for Sandy Bridge for vmovaps/etc for loading/storing from memory.</div><div><br></div><div>vmovaps - load takes 1 load mu op, 3 latency, with a reciprocal throughput of 0.5.</div>
<div>vmovaps - store takes 1 store mu op, 1 load mu op for address calculation, 3 latency, with a reciprocal throughput of 1.</div><div><br></div><div>He does not list vmovsd, but movsd has the same stats as vmovaps, so I feel it is a safe assumption to make that vmovsd has the same stats as well.</div>
<span class="HOEnZb"><font color="#888888"><div><br></div><div>Michael</div><br></font></span><div><div><div class="h5"><div>On Jul 26, 2012, at 11:46 AM, Cameron McInally wrote:</div><br></div></div><blockquote type="cite">
<div><div class="h5">Ah, bad example. This is a general problem for all (maybe most) SSE and AVX SS/SD patterns though, which is why I mentioned Sandybridge. You can swap out VFMADDSD in my example for VADDSD or whatever you like.<div>
<br></div>
<div>I have a lion's share of such a change implemented already and performance is greatly affected. If the community is interested in this change, I would be happy to prepare a patch.</div><div><br></div><div>-Cameron<br>

<br><div class="gmail_quote">On Thu, Jul 26, 2012 at 2:27 PM, Jan Sjodin <span dir="ltr"><<a href="mailto:jan_sjodin@yahoo.com" target="_blank">jan_sjodin@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

You can't execute FMA4 instructions on Intel processors, so it doesn't really matter what the impact of the move instructions would be, since it would end up with an illegal instruction regardless. :) It does perhaps bring up an issue of tuning for different architectures, but that is something nobody is really looking into at the moment afaik.<br>


<br>
<br>
- Jan<br>
<br>
>________________________________<br>
> From: Cameron McInally <<a href="mailto:cameron.mcinally@nyu.edu" target="_blank">cameron.mcinally@nyu.edu</a>><br>
>To: Jan Sjodin <<a href="mailto:jan_sjodin@yahoo.com" target="_blank">jan_sjodin@yahoo.com</a>><br>
>Cc: "<a href="mailto:dag@cray.com" target="_blank">dag@cray.com</a>" <<a href="mailto:dag@cray.com" target="_blank">dag@cray.com</a>>; "<a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a>" <<a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a>><br>


>Sent: Thursday, July 26, 2012 10:49 AM<br>
<div>>Subject: Re: [LLVMdev] X86 FMA4<br>
><br>
><br>
</div><div><div>>Hey Jan and Dave,<br>
><br>
><br>
>It's not obvious, but there is a significant scalar performance issue following the GCC intrinsics.<br>
><br>
><br>
>Let's look at the VFMADDSD pattern. We're operating on scalars with undefineds as the remaining vector elements of the operands. This sounds okay, but when one looks closer...<br>
><br>
>       vmovsd  fp4_+1088(%rip), %xmm3  # fpppp.f:647<br>
>       vmovaps %xmm3, 18560(%rsp)      # fpppp.f:647 <= 16-byte spill<br>
>       vfmaddsd        %xmm5, fp4_+3288(%rip), %xmm3, %xmm3 # fpppp.f:647<br>
><br>
><br>
>The spill here is 16-bytes. But, we're only using the low 8-bytes of xmm3. Changing the intrinsics and patterns to accept scalar operands, we end up with...<br>
><br>
>       vmovsd  fp4_+1056(%rip), %xmm0  # fpppp.f:666<br>
>       vmovsd  %xmm0, 10088(%rsp)      # fpppp.f:666 <= 8-byte spill<br>
>       vfmaddsd        %xmm3, fp4_+3288(%rip), %xmm0, %xmm3 # fpppp.f:666<br>
><br>
><br>
>I do not know the actual number of cycles offhand, but I believe on Interlagos and Sandybridge, a vmovaps takes roughly 3x as many micro-ops as a vmovsd if it involves memory.<br>
><br>
><br>
>-Cameron<br>
><br>
><br>
>On Thu, Jul 26, 2012 at 9:41 AM, Jan Sjodin <<a href="mailto:jan_sjodin@yahoo.com" target="_blank">jan_sjodin@yahoo.com</a>> wrote:<br>
><br>
>Because the intrinsics uses vector types (same as gcc).<br>
>><br>
>><br>
>>- Jan<br>
>><br>
>><br>
>><br>
>>----- Original Message -----<br>
>>> From: "<a href="mailto:dag@cray.com" target="_blank">dag@cray.com</a>" <<a href="mailto:dag@cray.com" target="_blank">dag@cray.com</a>><br>
>>> To: <a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a><br>
>>> Cc:<br>
>>> Sent: Wednesday, July 25, 2012 3:26 PM<br>
>>> Subject: [LLVMdev] X86 FMA4<br>
>>><br>
>>> We're migrating to LLVM 3.1 and trying to use the upstream FMA patterns.<br>
>>><br>
>>> Why is VFMADDSD4 defined with vector types?  Is this simply because the<br>
>>> gcc intrinsic uses vector types?  It's quite unnatural if you have a<br>
>>> compiler that generates FMAs as opposed to requiring user intrinsics.<br>
>><br>
><br>
><br>
</div></div></blockquote></div><br></div></div></div><div class="im">
_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></div></blockquote></div><br></div></blockquote></div><br></div></div>