<div dir="ltr">We're canonicalizing to shufflevector with:<br><div><a target="_blank" rel="noreferrer" href="https://reviews.llvm.org/rL281787">https://reviews.llvm.org/<wbr>rL281787</a><br><br></div><div>Please let me know if you see any performance regressions from this change.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 29, 2016 at 4:57 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:10pt;color:#000000"><br><br><hr><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From: </b>"Sanjay Patel via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>To: </b>"Martin ORiordan" <<a href="mailto:Martin.ORiordan@movidius.com" target="_blank">Martin.ORiordan@movidius.com</a>><br><b>Cc: </b>"LLVM Developers" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>Sent: </b>Monday, August 29, 2016 5:45:51 PM<span class=""><br><b>Subject: </b>Re: [llvm-dev] IR canonicalization: vector select or shufflevector?<br><br></span><span class=""><div dir="ltr"><div><div><div>x86 has also put a lot of effort into shuffle lowering...so much so that it is its own life-form and brings most online codeviewer apps to their knees when you try to open X86ISelLowering.cpp. :)<br><br></div>Given that:<br>1. There are at least 2 targets that lean towards shuffle (Martin's comment + x86 uses lowerVSELECTtoVectorShuffle() for all cases like the example posted here)<br></div></div></div></span></blockquote>This is irrelevant, as such. We can always transform these into shuffle SDAG nodes regardless of how they look in the IR.<br><br>That having been said, I'm fine with choosing shuffles as the canonical form, over selects with constant vector conditions - If we don't, we'd need some utility to abstract away the difference regardless.<br><br> -Hal<div><div class="h5"><br><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div dir="ltr"><div><div>2. Size-changing shuffles are easier to reason about with other shuffles (Michael's comment)<br></div>3. Insert/extract are easier to reason about with shuffles (Eli's comment in D22114)<br><br></div>...we should probably go with shuffle as the canonical encoding. Like Philip, I think the select is easier to read in IR (and mentally translate to an x86 'blend'), but there's no other advantage for select?<br><br>I'll give this thread some more time before posting a patch...in case we've missed something.<br><div><br><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 29, 2016 at 1:34 PM, Martin J. O'Riordan via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="EN-IE"><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:rgb(148,54,52)">I must admit, I prefer the shuffle canonicalization, but mainly because we have put a lot of effort into finding optimal instruction sequences for obscure shuffle patterns.  But we could refactor easily enough to use either.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:rgb(148,54,52)"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:rgb(148,54,52)">I don’t know which makes the most logical sense in this case though.  Certainly choosing the select pattern better matches OpenCL’s native select interface.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:rgb(148,54,52)"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:rgb(148,54,52)">            MartinO<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:rgb(148,54,52)"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:11pt;font-family:"Calibri",sans-serif" lang="EN-US">From:</span></b><span style="font-size:11pt;font-family:"Calibri",sans-serif" lang="EN-US"> llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@<wbr>lists.llvm.org</a>] <b>On Behalf Of </b>Michael Kuperstein via llvm-dev<br><b>Sent:</b> 29 August 2016 19:28<br><b>To:</b> Philip Reames <<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>><br><b>Cc:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>Subject:</b> Re: [llvm-dev] IR canonicalization: vector select or shufflevector?<u></u><u></u></span></p><div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">I have a slight preference towards shufflevector, because it makes sequences of shuffles, where only some of the shuffles can be converted into selects (because the input and output vector sizes of the others don't match) simpler to reason about.<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">I'm not sure this is a particularly good reason, though.<u></u><u></u></p></div></div></div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">On Mon, Aug 29, 2016 at 8:19 AM, Philip Reames 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><blockquote style="border-width:medium medium medium 1pt;border-style:none none none solid;border-color:-moz-use-text-color -moz-use-text-color -moz-use-text-color rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div><p>I don't have a strong preference, though it is clear we should pick one.  I'd mildly prefer the select form for readability.  From an optimization standpoint, I see reasonable arguments for either.  <u></u><u></u></p><p>Philip<u></u><u></u></p><div><div><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">On 08/28/2016 12:37 PM, Sanjay Patel via llvm-dev wrote:<u></u><u></u></p></div></div></div><blockquote style="margin-top:5pt;margin-bottom:5pt"><div><div><div><div><p class="MsoNormal" style="margin-bottom:12pt">A vector select with a constant vector condition operand:<br><br>define <4 x i32> @foo(<4 x i32> %a, <4 x i32> %b) {<br>  %sel = select <4 x i1> <i1 true, i1 false, i1 false, i1 true>, <4 x i32> %a, <4 x i32> %b<br>  ret <4 x i32> %sel<br>}<br><br><br>...is equivalent to a shufflevector:<br><br>define <4 x i32> @goo(<4 x i32> %a, <4 x i32> %b) {<br>  %shuf = shufflevector <4 x i32> %a, <4 x i32> %b, <4 x i32> <i32 0, i32 5, i32 6, i32 3><br>  ret <4 x i32> %shuf<br>}<br><br><br>For the goal of canonicalization in IR, which of these should we prefer? Some backend / lowering differences for AArch64 and PPC are noted in:<br><a href="https://llvm.org/bugs/show_bug.cgi?id=28530" target="_blank">https://llvm.org/bugs/show_<wbr>bug.cgi?id=28530</a><br><a href="https://llvm.org/bugs/show_bug.cgi?id=28531" target="_blank">https://llvm.org/bugs/show_<wbr>bug.cgi?id=28531</a><u></u><u></u></p></div><p class="MsoNormal">x86 converts either form optimally in all cases I've looked at.<u></u><u></u></p><div><p class="MsoNormal" style="margin-bottom:12pt"><br>This question first came up in D22114 ( <a href="https://reviews.llvm.org/D22114" target="_blank">https://reviews.llvm.org/<wbr>D22114</a> ) and is extended in D23886 ( <a href="https://reviews.llvm.org/D23886" target="_blank">https://reviews.llvm.org/<wbr>D23886</a> ) with a constant value example.<u></u><u></u></p></div></div><p class="MsoNormal" style="margin-bottom:12pt"><u></u> <u></u></p></div></div><pre>______________________________<wbr>_________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><u></u><u></u></pre></blockquote><p class="MsoNormal"><u></u> <u></u></p></div><p class="MsoNormal" style="margin-bottom:12pt"><br>______________________________<wbr>_________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><u></u><u></u></p></blockquote></div><p class="MsoNormal"><u></u> <u></u></p></div></div></div></div></div><br>______________________________<wbr>_________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></blockquote><br><br><br></div></div><span class="HOEnZb"><font color="#888888">-- <br><div><span name="x"></span>Hal Finkel<br>Assistant Computational Scientist<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></font></span></div></div></blockquote></div><br></div>