<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 15, 2021 at 4:43 AM Liu, Chen3 <<a href="mailto:chen3.liu@intel.com">chen3.liu@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div lang="EN-US" style="overflow-wrap: break-word;">
<div class="gmail-m_4215559252352283621WordSection1">
<p class="MsoNormal">Hi, James Y Knight.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I'm not sure if you misunderstood this patch. This patch won’t change any alignment information in IR and MI, which means ‘load…align 32’ will always keep the alignment information but select ‘vmovups’ instead of ‘vmovaps’ during ISEL.
It can be simply considered that the only thing this patch does is to replace the aligned-move mnemonic with the unaligned-move mnemonic (in fact, we shouldn’t call it replace but emit unaligned). I think there is no impact on optimization or code layout.
<u></u><u></u></p>
<p class="MsoNormal"><u></u></p></div></div></blockquote><div><br></div><div>Yes -- I understood that, and that is exactly why this patch is not OK. Giving LLVM incorrect information about the alignment of objects causes problems other than just the emission of movaps instructions -- that alignment information is correct gets relied upon throughout the optimization pipeline.</div><div><br></div><div>So, a command-line option to "fix" only that one instruction is not something which we can reasonably provide, because it will not reliably fix users' problems. A program which is being "mis"-compiled due to the use of misaligned objects might still be miscompiled by LLVM when using your proposed patch. ("mis" in quotes, since the compiler is correctly compiling the code according to the standard, even if not according to the user's expectations).</div><div><br></div><div>The second paragraph of my original email describes an alternative patch that you could write, which <i>would</i> reliably fix such miscompilation -- effectively creating a variant of C where creating and accessing misaligned objects has fully defined behavior. (And, just to reiterate, my initial feeling is that creating such an option is not a worthwhile endeavor, but I could be persuaded otherwise.)</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-US" style="overflow-wrap: break-word;"><div class="gmail-m_4215559252352283621WordSection1"><p class="MsoNormal"><u></u></p>
<p class="MsoNormal">After discussion, we think this option more like changing the behavior when process with unaligned memory: raising exception or accepting performance degradation. Maybe the option is more like “no-exception-on-unalginedmem”. We do have
some users want this feature. They can accept “run slow” but do not want exception.<u></u><u></u></p>
<br>
<p class="MsoNormal">Thanks.<u></u><u></u></p>
<p class="MsoNormal">Chen Liu.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal"><b>From:</b> Philip Reames <<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>> <br>
<b>Sent:</b> Thursday, April 15, 2021 6:44 AM<br>
<b>To:</b> James Y Knight <<a href="mailto:jyknight@google.com" target="_blank">jyknight@google.com</a>>; Liu, Chen3 <<a href="mailto:chen3.liu@intel.com" target="_blank">chen3.liu@intel.com</a>><br>
<b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>; Luo, Yuanke <<a href="mailto:yuanke.luo@intel.com" target="_blank">yuanke.luo@intel.com</a>>; Maslov, Sergey V <<a href="mailto:sergey.v.maslov@intel.com" target="_blank">sergey.v.maslov@intel.com</a>><br>
<b>Subject:</b> Re: [llvm-dev] [RFC] [X86] Emit unaligned vector moves on avx machine with option control.<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p>+1 to what James said. My reaction to the original proposal is a strong -1, and James did a good job of explaining why.<u></u><u></u></p>
<p>Philip<u></u><u></u></p>
<div>
<p class="MsoNormal">On 4/14/21 11:57 AM, James Y Knight via llvm-dev wrote:<u></u><u></u></p>
</div>
<blockquote style="margin-top:5pt;margin-bottom:5pt">
<div>
<p class="MsoNormal">This is not a principled change -- it avoids a problem arising from <i>one</i> use of alignment information, but there are other uses of alignment in LLVM, and those will still cause problems, potentially less clearly. So, I think that
this will not be a useful option to provide to users, in this form. <u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">What I suspect you <i>actually</i> want here is an option to tell Clang not to infer load/store alignments based on object types or alignment attributes -- instead treating everything as being potentially aligned to 1 unless the allocation
is seen (e.g. global/local variables). Clang would still need to use the usual alignment computation for variable definitions and structure layout, but not memory operations. If clang emits "load ... align 1" instructions in LLVM IR, the right thing would
then happen in the X86 backend automatically.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">My initial inclination is that this feature is also not particularly worthwhile to implement, but I'm open to being convinced that this is indeed valuable enough to be worthwhile. It should actually work reliably, and is somewhat in line
with other such "not-quite-C" flags we provide (e.g. -fno-delete-null-pointer-checks). Of course, even with such an implementation, you can still have a problem with user code depending on alignof() returning a reliable answer (e.g., llvm::PointerUnion). Not
much can be done about that.<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Wed, Apr 14, 2021 at 2:07 PM Liu, Chen3 via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Hi all.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">We want to make a patch to always emit unaligned vector move instructions on AVX machine with option control. We do this for the following reason:<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<ol start="1" type="1">
<li class="MsoNormal" style="text-align:justify">
With AVX the performance for aligned vector move and unaligned vector move on X86 are the same if the address is aligned. In this case we prefer to use unaligned move because it can avoid some run time exceptions;<u></u><u></u></li><li class="MsoNormal" style="text-align:justify">
This fixes an inconsistency in optimization: suppose a load operation was merged into another instruction (e.g., load and add becomes `add [memop]'). If a misaligned pointer is passed to the two-instruction sequence, it will<u></u><u></u></li></ol>
<p style="text-align:justify">raise an exception. If the same pointer is passed to the memop instruction, it will work. Thus, the behavior of misalignment depends upon what optimization levels and passes are applied, and small source
changes could cause<u></u><u></u></p>
<p style="text-align:justify">issues to appear and disappear. It's better for the user to consistently use unaligned load/store to improve the debug experience;<u></u><u></u></p>
<ol style="margin-top:0in" start="3" type="1">
<li class="MsoNormal" style="text-align:justify;line-height:20.4pt;background:white">
<span style="color:black">Makes good use of HW that is capable of handling misaligned data gracefully. It is not necessarily a bug in users code but a third-part library. For example it would allow using a library built in old ages where stack alignment was
4-byte only.</span><u></u><u></u></li><li class="MsoNormal" style="text-align:justify">
Compatible with ICC so that users can easily use llvm;<u></u><u></u></li></ol>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Roman Lebedev is worried that this patch will hide UB. In our opinions, UB doesn't have to mean raise an exception. The example code(<a href="https://godbolt.org/z/43bYPraoa" target="_blank">https://godbolt.org/z/43bYPraoa</a>)
does have UB behavior but it is still valid (and reasonable) to interpret that UB as `go slower',<u></u><u></u></p>
<p class="MsoNormal">instead of `raise exception'. Besides, as default we still emit aligned instructions as before, but we provide an option for users with this need.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">We have two patches discussing this issue, one of which has been abandoned:<u></u><u></u></p>
<p class="MsoNormal"><a href="https://reviews.llvm.org/D88396" target="_blank">https://reviews.llvm.org/D88396</a> (abandoned)<u></u><u></u></p>
<p class="MsoNormal"><a href="https://reviews.llvm.org/D99565" target="_blank">https://reviews.llvm.org/D99565</a> (in review)<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thanks.<u></u><u></u></p>
<p class="MsoNormal">Chen Liu.<u></u><u></u></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br>
<u></u><u></u></p>
<pre>_______________________________________________<u></u><u></u></pre>
<pre>LLVM Developers mailing list<u></u><u></u></pre>
<pre><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><u></u><u></u></pre>
<pre><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></pre>
</blockquote>
</div>
</div>
</blockquote></div></div>