<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div>Hi,<br>
</div>
<div><br>
</div>
<div>I found LSR does not accurately model an IV increment cost on my target<br>
</div>
<div>with post-inc load/store instructions for particular types.  The related code<br>
</div>
<div>is in lib/Transforms/Scalar/LoopStrengthReduce.cpp:<br>
</div>
<div><br>
</div>
<div>void Cost::RateRegister()<br>
</div>
<div>...<br>
</div>
<div>unsigned LoopCost = 1;<br>
</div>
<div>if (TTI.shouldFavorPostInc()) {<br>
</div>
<div>  const SCEV *LoopStep = AR->getStepRecurrence(SE);<br>
</div>
<div>  if (isa<SCEVConstant>(LoopStep)) {<br>
</div>
<div>    // Check if a post-indexed load/store can be used.<br>
</div>
<div>    if (TTI.isIndexedLoadLegal(TTI.MIM_PostInc, AR->getType()) ||<br>
</div>
<div>      TTI.isIndexedStoreLegal(TTI.MIM_PostInc, AR->getType())) {<br>
</div>
<div>      const SCEV *LoopStart = AR->getStart();<br>
</div>
<div>      if (!isa<SCEVConstant>(LoopStart) &&<br>
</div>
<div>        SE.isLoopInvariant(LoopStart, L))<br>
</div>
<div>          LoopCost = 0;<br>
</div>
<div>    }<br>
</div>
<div>}<br>
</div>
<div><br>
</div>
<div>Here we consult TTI with TTI.isIndexLoadLegal() to see if post-inc load/store<br>
</div>
<div>is supported on the target, in which case the IV increment could be folded<br>
</div>
<div>into the load/store to save one instruction.<br>
</div>
<div><br>
</div>
<div>However this code does not make sense to me.<br>
</div>
<div>1) We don’t know if the use of this IV is a load/store.<br>
</div>
<div>2) Should we pass the type of the load/store instead of the type of IV<br>
</div>
<div>to isIndexedLoadLocal()?<br>
</div>
<div>3) I don’t understand why LoopStart needs to be a loop invariant but not a<br>
</div>
<div>Constant for the post-inc fold to be valid.  I think the constant loop start case<br>
</div>
<div>is also benefit from the post-inc load/store.<br>
</div>
<div><br>
</div>
<div>Thanks,<br>
</div>
<div>Lei</div>
<span></span>
</body>
</html>