<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Hi Bjorn,</span></div>
<div style=""><br>
</div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">That sounds like another viable option but perhaps one involving slightly more work. Intuitively though it seems that solving the problem at
 the source (i.e. not adding the constant in the first place) would be the cleanest solution besides of course the issues with that already mentioned. </span></div>
<div style=""><br>
</div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">I would imagine that most machine instructions realizing hw loops are more interested in the number of jumps to make as compared to the the
 number of iterations a loop will roll. But in this case clearly my imagination does not line up with reality as other targets seem to want the number of iterations.</span></div>
<div style=""><br>
</div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">I haven't thought about the case of the addition being hoisted out of the loop pre-header but I guess that could happen. There is nothing AFAIK
 that requires us to keep the llvm.set.loop.iterations intact but it just seemed like the easiest thing to do to avoid introducing more intermediate pseudos.</span></div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</span></div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Need to experiment some more.</span></div>
<div style=""><br>
</div>
<div style=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">-Markus</span></div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Björn Pettersson A <bjorn.a.pettersson@ericsson.com><br>
<b>Sent:</b> Friday, July 12, 2019 12:23 AM<br>
<b>To:</b> Markus Lavin <markus.lavin@ericsson.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] llvm.set.loop.iterations</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi Markus.<br>
<br>
Can't you just custom lower the intrinsic at ISel, to some target specific pseudo/instruction. And then you introduce an ISD::SUB at some early point during ISel (hopefully making it possible for DAGCombine to fold away the ISD::ADD/ISD::SUB pair). Or are you
 afraid that the addition has been hoisted to a different basic block compared to the intrinsic (since DAGCombiner is local to a BB that would reduce the possibilities for folding away the ISD::SUB)?<br>
<br>
Or what says that you need to wait until hwloop finalization (assuming that there is no target-generic MIR counterpart for llvm.set.loop.iterations, or is it)?<br>
<br>
/Björn<br>
<br>
________________________________________<br>
From: llvm-dev <llvm-dev-bounces@lists.llvm.org> on behalf of Markus Lavin via llvm-dev <llvm-dev@lists.llvm.org><br>
Sent: Thursday, July 11, 2019 15:40<br>
To: llvm-dev@lists.llvm.org<br>
Subject: [llvm-dev] llvm.set.loop.iterations<br>
<br>
After playing a bit with the newly introduced hardware loop framework I realize that the llvm.set.loop.iterations intrinsic takes as argument the number of iterations the loop will execute. In fact it goes all the way to, on IR, insert an addition of constant
 1 to the number of taken backedges returned by SCEV.<br>
<br>
If the machine instruction realizing the loop is interested in the number of branches-to-make / backedges-taken then this is slightly awkward as we need to subtract the constant 1. Of course if the iteration count was constant this is trivial but if it is passed
 in register then it is not so nice to have to insert these subtract instructions from a MIR pass (where the hwloop finalization is being done).<br>
<br>
I wonder what would be the best way to deal with this.<br>
<br>
One way would be to add a TTI hook gating the original addition but then the intrinsic will have two meanings depending on what this hook returns which is not good.<br>
<br>
Another way would be to introduce a second intrinsic, say llvm.set.loop.backedges that corresponds to that value, but then we have yet another intrinsic.<br>
<br>
A third option could be to have the original intrinsic take both values as arguments.<br>
<br>
Any thoughts on this?<br>
<br>
regards<br>
Markus<br>
<br>
<br>
</div>
</span></font></div>
</body>
</html>