<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Malgun Gothic";
        panose-1:2 11 5 3 2 0 0 2 0 4;}
@font-face
        {font-family:"\@Malgun Gothic";}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi Raghesh,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have also ported code for partially invariant condition from LoopUnswitch to SimpleLoopUnswitch.
<a href="https://reviews.llvm.org/D99354">https://reviews.llvm.org/D99354</a> The SimpleLoopUnswitch clones unswitchable path of loop rather than cloning whole loop but the main logic is similar. It could be better to port your code to SimpleLoopUnswitch because
 the new pass manager is default.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards<o:p></o:p></p>
<p class="MsoNormal">JinGu Kang<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>raghesh via llvm-dev<br>
<b>Sent:</b> Thursday, April 8, 2021 8:17 AM<br>
<b>To:</b> Arthur Eubanks <aeubanks@google.com><br>
<b>Cc:</b> LLVM Developers Mailing List <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] Difficulty in Porting cloneLoop in LoopUnswitch<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"> Hi Arthur,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">There are significant amounts of code that we added internally to LoopUnswitch. I presume we will be able to move that to SimpleUnswitch, but in the interest of time we thought of porting LoopUnswitch first.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Regards,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Raghesh<o:p></o:p></p>
</div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">------------------------------<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Raghesh Aloor<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">AMD India Pvt. Ltd.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Bengaluru.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">------------------------------<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Thu, Apr 8, 2021 at 12:10 PM Arthur Eubanks <<a href="mailto:aeubanks@google.com">aeubanks@google.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">The new PM's equivalent of LoopUnswitch is the (not super well named) SimpleLoopUnswitch. Is there something specific that SimpleLoopUnswitch doesn't handle?<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Wed, Apr 7, 2021 at 11:36 PM raghesh via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<p class="MsoNormal">Hi All,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Though the LoopUnswitch pass was not ported to the new pass manager by community,  we internally at AMD are in need to do that. While doing this we are facing issues to have a counterpart for the cloneLoop function, the body of which is
 given below.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><i>Loop *llvm::cloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM,<br>
                      LoopInfo *LI, LPPassManager *LPM) {<br>
  Loop &New = *LI->AllocateLoop();<br>
  if (PL)<br>
    PL->addChildLoop(&New);<br>
  else<br>
    LI->addTopLevelLoop(&New);<br>
<br>
 <b> if (LPM)<br>
    LPM->addLoop(New);</b><br>
<br>
  // Add all of the blocks in L to the new loop.<br>
  for (Loop::block_iterator I = L->block_begin(), E = L->block_end();<br>
       I != E; ++I)<br>
    if (LI->getLoopFor(*I) == L)<br>
      New.addBasicBlockToLoop(cast<BasicBlock>(VM[*I]), *LI);<br>
<br>
  // Add all of the subloops to the new loop.<br>
  for (Loop *I : *L)<br>
    cloneLoop(I, &New, VM, LI, LPM);<br>
<br>
  return &New;<br>
}</i><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">In the new pass manager flow, we are trying to use LPMUpdater's addSiblingLoops in place of addLoop, which will be invoked only for the top level loop (loop to be unswitched). According to the comments given in AddSiblingLoops the loops
 nested inside will be traversed by the pass manager anyway. In that assumption we are not adding the subloops. With this we are facing assertion failures further. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">We also tried capturing all the newly created loops and adding it towards the end of the LoopUnswitch pass, as done in the SimpleLoopUnswitch pass. That also did not help. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Another approach we tried is not to add the cloned loops at all to the pass manager.. This worked  but not sure about its implications. We might miss further optimization opportunities on these loops.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">It would be a great help if someone could point out the right way to go about it.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Regards,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Raghesh<o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">------------------------------<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Raghesh Aloor<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">AMD India Pvt. Ltd.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Bengaluru.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">------------------------------<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</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><o:p></o:p></p>
</blockquote>
</div>
</blockquote>
</div>
</div>
</body>
</html>