<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=us-ascii">
<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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@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="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Makes sense. I personally greatly prefer having a type rather than a `<span style="font-family:"Courier New"">static constexpr int CostUnfathomable = 10000`</span>.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I think the type should have arithmetic operators defined such that an “invalid cost” on either side results in an invalid cost (similar to how NaN infects floats), and an implicit conversion that constructs a valid cost. Then I could just
do:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal">Cost c = 7;<o:p></o:p></p>
<p class="MsoNormal">// c is a valid cost of 7 here<o:p></o:p></p>
<p class="MsoNormal">c = c + someFuncThatReturnsInvalidCost();<o:p></o:p></p>
<p class="MsoNormal">Cost d = 2 + c;<o:p></o:p></p>
<p class="MsoNormal">// d and c are both invalid costs here<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This way, basically no existing code has to change. I’m actually a little disappointed that llvm::Optional doesn’t already have this behavior (with arithmetic operators guarded by enable_if).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal"> Christopher Tetreault<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> David Sherwood <David.Sherwood@arm.com> <br>
<b>Sent:</b> Friday, November 6, 2020 12:18 AM<br>
<b>To:</b> Chris Tetreault <ctetreau@quicinc.com>; LLVM Dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> [EXT] RE: [llvm-dev] [Proposal] Introducing the concept of invalid costs to the IR cost model<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-GB">Hi Chris,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Thanks for the reply. My email was really to just ask if people were ok with the idea<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">in principle and I kind of deliberately avoided getting into too many details at this<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">point. If people are happy with the idea in principle I can push a patch up soon that<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">shows what such a class could like so that people can comment on it?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">David Sherwood.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Chris Tetreault <<a href="mailto:ctetreau@quicinc.com">ctetreau@quicinc.com</a>>
<br>
<b>Sent:</b> 05 November 2020 19:23<br>
<b>To:</b> David Sherwood <<a href="mailto:David.Sherwood@arm.com">David.Sherwood@arm.com</a>>; LLVM Dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> RE: [llvm-dev] [Proposal] Introducing the concept of invalid costs to the IR cost model<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal">You’re being quite vague about what the extra state is. Is this because you haven’t yet settled on what it should be, or do you actually intend to let it be a template parameter:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">template <typename T><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">struct Cost {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> unsigned Val;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> T State;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal"> Christopher Tetreault<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@lists.llvm.org</a>>
<b>On Behalf Of </b>David Sherwood via llvm-dev<br>
<b>Sent:</b> Thursday, November 5, 2020 7:43 AM<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> [EXT] [llvm-dev] [Proposal] Introducing the concept of invalid costs to the IR cost model<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-GB">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I'd like to propose a change to our cost interfaces so that instead of returning<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">an unsigned value from functions like getInstructionCost, getUserCost, etc., we<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">instead return a wrapper class that encodes an integer cost along with extra<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">state. The extra state can be used to express:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">1. A cost as infinitely expensive in order to prevent certain optimisations<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">taking place. For example, there are already examples in LLVM where the cost is<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">set extremely high, but not so high that it would cause overflow. This might be to<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">prevent vectorisation in cases where we would have to scalarize the operation,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">which is particularly relevant for scalable vectors, where scalarisation is<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">not [yet] available. There isn't currently a standard value for something that<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">constitutes very expensive and we can replace all the magic numbers with a<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">single invalid state.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">2. A cost as unknown, where the user is simply unable to determine an accurate<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">cost for an operation.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">This new wrapper class would work almost seamlessly with existing code as it<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">would contain the full set of operators required for arithmetic and comparisons.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">This is in addition to the ability to create invalid costs and query the validity<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">of an existing cost. Once a cost becomes invalid or unknown it will remain in that<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">state regardless of any further arithmetic performed.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Kind Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">David Sherwood.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
</div>
</body>
</html>