<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 16px; font-family: Calibri, sans-serif;">
<div>
<div>Hi Philip,</div>
<div><br>
</div>
<div>Attached you will find the LLVM IR that causes LLVM 3.7.0 to emit assembly generating a whole bunch of blocked store-forwarding pipeline stalls. </div>
<div><br>
</div>
<div>Compile using:</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span><span style="font-family: Consolas; font-size: 14px;">$ llvm/3.7.0/Release/bin/opt -S -O3 store-forward-failure.ll -o - | llvm/3.7.0/Release/bin/llc -filetype=asm -O3 -o -</span></div>
<div><span style="font-family: Consolas; font-size: 14px;"><br>
</span></div>
<div><span style="font-family: Consolas; font-size: 14px;"><br>
</span></div>
<div>You will find assembly sequences such as:</div>
<div>
<div><br>
</div>
<div>        movss   dword ptr [rcx - 12], xmm4 # 32-bit store</div>
<div>        movss   dword ptr [rcx - 16], xmm3 # 32-bit store</div>
<div>    <span class="Apple-tab-span" style="white-space:pre"></span>mov<span class="Apple-tab-span" style="white-space:pre">
</span>rdx, qword ptr [rcx - 16]      # 64-bit load</div>
<div><br>
</div>
<div>Notice how the stores and loads are back-to-back and of different bit-width.  On my processor (Intel Sandy Bridge), this sequence seems to fail store-forwarding and to cause a huge CPU pipeline stall. Or at least, this is what the following CPU performance
 counter leads me to believe:</div>
<div><br>
</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>LD_BLOCKS.STORE_FORWARD: Loads blocked by overlapping with store buffer that cannot be forwarded.</div>
<div><br>
</div>
<div>My test case is generating 1,500,000,000  of these "blocked store-forwarding » when using LLVM 3.7 versus 74,000 for LLVM 3.6! The number of instructions executed per CPU cycles goes down to 0.7 IPC instead of 2.2 IPC.</div>
</div>
<div><br>
</div>
<div>Further analysis suggests that it might be due to the GVN pass (which runs just before the MemCpy pass) which actually combines 2 32-bit loads into a single 64-bit load.  See the attached files.</div>
<div><br>
</div>
<div>I have also noted that the alloca are actually getting properly annotated with an alignment of 8 bytes by the « Combine redundant instructions » pass. So, I guess that annotating alloca when emitting LLVM IR within our JIT compiler is unnecessary. Is that
 a fair assessment ?</div>
<div><br>
</div>
<div>Is store-forwarding always blocking on these kind of memory accesses even if they are properly aligned ?</div>
<div><br>
</div>
<div>(Side note: Moving the alloca into the entry BB, causes all of these redundant alloca, store and load instructions to be optimized out and the entire store-forwarding issue goes away for this particular test case. But, isn’t this an issue that could be
 triggered in other valid cases ?) </div>
<div><br>
</div>
<div>Cheers, </div>
<div>Benoit</div>
<div><br>
</div>
<div>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 9pt; font-family: Arial, sans-serif; color: rgb(99, 99, 99);">Benoit Belley</span></b><span style="font-size: 9pt; "><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Sr Principal Developer</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">M&E-Product Development Group</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 7pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">MAIN</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> +1
 514 393 1616</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 7pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">DIRECT</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> +1
 438 448 6304</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 7pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">FAX</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> +1
 514 393 0110</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><a href="http://twitter.com/autodesk" style="color: purple; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Twitter</span></a><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><a href="https://www.facebook.com/Autodesk" style="color: purple; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Facebook</span></a><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Autodesk, Inc.</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">10 Duke Street</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Montreal, Quebec, Canada H3C 2L7</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><a href="http://www.autodesk.com/" style="color: purple; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">www.autodesk.com</span></a><span style="color: rgb(146, 147, 150); "><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; "><img border="0" width="283" height="41" id="Picture_x0020_1" src="cid:66293B5D-D36D-49F1-B95D-4322DE588F3C" alt="Description: Email_Signature_Logobar" type="image/png"><o:p></o:p></p>
<div style="font-family: Calibri; font-size: medium; ">
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="font-size: 11.5pt; "> </span></p>
</div>
</div>
</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@lists.llvm.org</a>> on behalf of Benoit Belley via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
<span style="font-weight:bold">Reply-To: </span>Benoit Belley <<a href="mailto:benoit.belley@autodesk.com">benoit.belley@autodesk.com</a>><br>
<span style="font-weight:bold">Date: </span>mardi 8 septembre 2015 13:11<br>
<span style="font-weight:bold">To: </span>Philip Reames <<a href="mailto:listmail@philipreames.com">listmail@philipreames.com</a>>, "<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
<span style="font-weight:bold">Subject: </span>Re: [llvm-dev] LLVM struct, alloca, SROA and the entry basic block<br>
</div>
<div><br>
</div>
<blockquote id="MAC_OUTLOOK_ATTRIBUTION_BLOCKQUOTE" style="BORDER-LEFT: #b5c4df 5 solid; PADDING:0 0 0 5; MARGIN:0 0 0 5;">
<div>
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 16px; font-family: Calibri, sans-serif;">
<div>
<div><span style="font-family: Calibri; font-size: 11pt; font-weight: bold;">From:
</span><span style="font-family: Calibri; font-size: 11pt;">Philip Reames <</span><a href="mailto:listmail@philipreames.com" style="font-family: Calibri; font-size: 11pt;">listmail@philipreames.com</a><span style="font-family: Calibri; font-size: 11pt;">></span></div>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">Date: </span>mardi 8 septembre 2015 12:50<br>
<span style="font-weight:bold">To: </span>Benoit Belley <<a href="mailto:benoit.belley@autodesk.com">benoit.belley@autodesk.com</a>>, "<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
<span style="font-weight:bold">Subject: </span>Re: [llvm-dev] LLVM struct, alloca, SROA and the entry basic block<br>
</div>
<div><br>
</div>
<blockquote id="MAC_OUTLOOK_ATTRIBUTION_BLOCKQUOTE" style="BORDER-LEFT: #b5c4df 5 solid; PADDING:0 0 0 5; MARGIN:0 0 0 5;">
<div>
<div text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 09/08/2015 07:21 AM, Benoit Belley via llvm-dev wrote:<br>
</div>
<blockquote cite="mid:D2146725.50382%25benoit.belley@autodesk.com" type="cite">
<div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif;
        font-size: 16px;">
Hi everyone,</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif;
        font-size: 16px;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif;
        font-size: 16px;">
We have noticed that the SROA pass will only eliminate ‘alloca’ instructions if those are located in the entry basic block of a function.</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif;
        font-size: 16px;">
<br>
</div>
<div><i><font face="Calibri,sans-serif"><b>As a general recommendation, should the LLVM IR emitted by our compiler always place ‘alloca’ instructions in the entry basic block ? (I couldn’t find any recommendations concerning this matter.)</b></font></i></div>
</blockquote>
<font face="Calibri,sans-serif">Yes.  </font><br>
</div>
</div>
</blockquote>
</span>
<div><br>
</div>
<div><br>
</div>
<div>Thanks Phil. Should this be mentioned somewhere in the documentation ? As a footnote in the LLVM Language Reference manual maybe ?</div>
<div><br>
</div>
<div>As a note, I have also find out that alloca instructions should be placed before any call instructions as these can get inlined and then, the original alloca can no longer by placed in the entry basic block!</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<blockquote id="MAC_OUTLOOK_ATTRIBUTION_BLOCKQUOTE" style="BORDER-LEFT: #b5c4df 5 solid; PADDING:0 0 0 5; MARGIN:0 0 0 5;">
<div>
<div text="#000000" bgcolor="#FFFFFF"><font face="Calibri,sans-serif"><i><b><br>
</b></i></font>
<blockquote cite="mid:D2146725.50382%25benoit.belley@autodesk.com" type="cite">
<div><i><font face="Calibri,sans-serif"><br>
</font></i></div>
<div><font face="Calibri,sans-serif">In addition, we have noticed that the MemCpy pass will attempt to copy LLVM struct using moves that are as large as possible. </font>For example, a struct of 3 floats is copied using a 64-bit and a 32-bit move. It is therefore
 important that such a struct be aligned on 8-byte boundary, not just 4 bytes! Else, one runs the risk of triggering store-forwarding failure pipelining stalls (which we did encountered really badly with one of our internal performance benchmark).</div>
</blockquote>
This sounds like a bug to me.  We shouldn't be using the large load/stores without knowing they're aligned or that unaligned access is fast on a particular target.  Where this is best fixed (memcpy, store lowering?) I don't know. 
</div>
</div>
</blockquote>
</span>
<div><br>
</div>
<div>I’ll send out a test case. Maybe, that will help.</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<blockquote id="MAC_OUTLOOK_ATTRIBUTION_BLOCKQUOTE" style="BORDER-LEFT: #b5c4df 5 solid; PADDING:0 0 0 5; MARGIN:0 0 0 5;">
<div>
<div text="#000000" bgcolor="#FFFFFF"><br>
<blockquote cite="mid:D2146725.50382%25benoit.belley@autodesk.com" type="cite">
<div><br>
</div>
<div><b><i>Is there any guidelines for specifying the alignment of LLVM structs allocated by alloca instructions ? Is rounding down to the structure size to the next power of 2 a good strategy ? Will the MemCpy pass issue moves of up to 64-bytes on AVX-512
 capable processors ?</i></b></div>
<div><b><i><br>
</i></b></div>
<div>Cheers,</div>
<div>Benoit<i style="font-weight: bold;"> </i></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif;
        font-size: 16px;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri, sans-serif;
        font-size: 16px;">
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<b><span style="font-size: 9pt; font-family: Arial, sans-serif; color: rgb(99, 99, 99);">Benoit Belley</span></b><span style="font-size: 9pt; "><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Sr Principal Developer</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">M&E-Product Development Group</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<span style="font-size: 7.5pt; font-family: Arial, sans-serif;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<b><span style="font-size: 7pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">MAIN</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> +1 514 393 1616</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<b><span style="font-size: 7pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">DIRECT</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> +1 438 448 6304</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<b><span style="font-size: 7pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">FAX</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> +1 514 393 0110</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<span style="font-size: 7.5pt; font-family: Arial, sans-serif;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<a moz-do-not-send="true" href="http://twitter.com/autodesk" style="color: purple; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Twitter</span></a><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<a moz-do-not-send="true" href="https://www.facebook.com/Autodesk" style="color:
            purple; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Facebook</span></a><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<span style="font-size: 7.5pt; font-family: Arial, sans-serif;"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<b><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Autodesk, Inc.</span></b><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">10 Duke Street</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">Montreal, Quebec, Canada H3C 2L7</span><span style="font-size: 7.5pt; font-family: Arial, sans-serif;"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<a moz-do-not-send="true" href="http://www.autodesk.com/" style="color: purple; "><span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);">www.autodesk.com</span></a><span style="color: rgb(146, 147, 150); "><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<span style="font-size: 7.5pt; font-family: Arial, sans-serif; color: rgb(146, 147, 150);"> </span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt; font-size:
          11pt; ">
<img id="Picture_x0020_1" src="cid:part4.04080103.05030000@philipreames.com" alt="Description: Email_Signature_Logobar" type="image/png" height="41" width="283" border="0"><o:p></o:p></p>
<div style="font-family: Calibri; font-size: medium; ">
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt;
            font-size: 11pt; font-family: Calibri, sans-serif; ">
<span style="font-size: 11.5pt; "> </span></p>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset> <br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></pre>
</blockquote>
<br>
</div>
</div>
</blockquote>
</span></div>
</div>
</blockquote>
</span>
</body>
</html>