<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Suyog,<div><br></div><div>Thanks for the reply. Do you know if it is possible to add a new intrinsic without actually modifying core code (ISDOpcodes.h is an example of core code)? I'd like to add this intrinsic with as little code change as possible.</div><div><br></div></div></blockquote><div><br></div><div><br></div><div>There were attempts to identify this pattern (and similar other) at selectionDAG level and emit vector code customized for a backend.</div><div>See example - <a href="https://llvm.org/bugs/show_bug.cgi?id=20035">https://llvm.org/bugs/show_bug.cgi?id=20035</a> and thread <a href="http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20140616/221763.html">http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20140616/221763.html</a> </div><div><br></div><div>As reviewed, this made very specific to a given target and it was suggested to handle these patterns at IR level. </div><div>At IR level, attempt was made to catch this pattern in Loop/SLP(unrolled straight line code) vectorizer and use TTI cost info to vectorize the pattern.</div><div>This was again clumsy. <br><br>As James and Shahid pointed out, intrinsics are the best shot to vectorize this pattern to make it more generic. </div><div>This generally follows the steps listed by Shahid : </div><p style="color:rgb(80,0,80);font-size:12.8px"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">1.<span style="font-stretch:normal;font-size:7pt;font-family:'Times New Roman'">       </span></span><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Define an intrinsic, xyz(),  for the required instruction and corresponding SDNode<u></u><u></u></span></p><p style="color:rgb(80,0,80);font-size:12.8px"><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">2.<span style="font-stretch:normal;font-size:7pt;font-family:'Times New Roman'">       </span></span><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Generate the “call xyz() “ IR based the matched pattern<u></u><u></u></span></p><p style="color:rgb(80,0,80);font-size:12.8px"><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">3.<span style="font-stretch:normal;font-size:7pt;font-family:'Times New Roman'">       </span></span><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Map “call xyz()” IR to corresponding SDNode in SelectionDagBuilder.cpp<u></u><u></u></span></p><p style="color:rgb(80,0,80);font-size:12.8px"><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">4.<span style="font-stretch:normal;font-size:7pt;font-family:'Times New Roman'">       </span></span><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Provide default expansion of the xyz() intrinsic<u></u><u></u></span></p><p style="color:rgb(80,0,80);font-size:12.8px"><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">5.<span style="font-stretch:normal;font-size:7pt;font-family:'Times New Roman'">       </span></span><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Legalize type and/or operation<u></u><u></u></span></p><p style="color:rgb(80,0,80);font-size:12.8px"><u></u></p><div><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">6.<span style="font-stretch:normal;font-size:7pt;font-family:'Times New Roman'">       </span></span><u style="color:rgb(80,0,80);font-size:12.8px"></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Provide Lowering of intrinsic/SDNode to generate your target instruction</span></div><div><br></div><div>When a pattern is identified and marked with intrinsic at IR level, a corresponding SDNode will be generated when converting IR to SelectionDAG.</div><div>This SDNode can then be legalize/expanded/lowered to specific target when lowering to target machine code. For this intrinsic specific SDNode, </div><div>IMO you will have to add the entries in ISDOpcodes.h. I don't see any harm or big change in adding them. <br><br>As you know, the pattern listed in above discussions is commonly occurring pattern and hence need to be identified at IR level via intrinsics. <br></div><div>Every target has its own way to handle these patterns - as far as i know X86 will have single instruction PSAD while AArch64 will handle it in two steps.</div><div>This variance can be handled at DAGLowering and target code generation phase (and this will be highly acceptable to land in trunk code </div><div>since it solves the issue in clean and generic way). </div><div><br></div><div>Not sure if <span style="font-size:12.8px">D10867</span><span style="font-size:12.8px"> and </span><span style="font-size:12.8px">D11678</span><span style="font-size:12.8px">  were reverted later, but i think these can serve your purpose as an example to add intrinsic and generate code. </span><span style="font-size:12.8px">  </span></div><div><br></div><div>Regards,</div><div>Suyog</div><div> </div></div></div></div>