<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">
<blockquote class="quotableTextTraining" style="border-color: rgb(200, 200, 200); border-left: 3px solid rgb(200, 200, 200); padding-left: 1ex; margin-left: 0.8ex; color: rgb(102, 102, 102);">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<p style="font-size:11pt;font-family:Calibri,sans-serif;margin:0">If people are happy with the idea in principle I can push a patch up soon that</p>
<p style="font-size:11pt;font-family:Calibri,sans-serif;margin:0">shows what such a class could like so that people can comment on it?</p>
</div>
</blockquote>
<p style="font-size:11pt;font-family:Calibri,sans-serif;margin:0">Yeah, or if you got something already but needs a some more work, just upload it and tag it as a work-in-progress patch so people can have a sneak peek what's coming.</p>
<p style="font-size:11pt;font-family:Calibri,sans-serif;margin:0"><br>
</p>
<p style="font-size:11pt;font-family:Calibri,sans-serif;margin:0">Cheers,</p>
<p style="font-size:11pt;font-family:Calibri,sans-serif;margin:0">Sjoerd.<br>
</p>
<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> llvm-dev <llvm-dev-bounces@lists.llvm.org> on behalf of David Sherwood via llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Sent:</b> 06 November 2020 08:17<br>
<b>To:</b> Chris Tetreault <ctetreau@quicinc.com>; LLVM Dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] [Proposal] Introducing the concept of invalid costs to the IR cost model</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:DengXian}
@font-face
        {font-family:Calibri}
@font-face
        {}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
a:link, span.x_MsoHyperlink
        {color:#0563C1;
        text-decoration:underline}
span.x_EmailStyle20
        {font-family:"Calibri",sans-serif;
        color:windowtext}
.x_MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:72.0pt 72.0pt 72.0pt 72.0pt}
div.x_WordSection1
        {}
-->
</style>
<div lang="EN-GB" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="x_WordSection1">
<p class="x_MsoNormal">Hi Chris,</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Thanks for the reply. My email was really to just ask if people were ok with the idea</p>
<p class="x_MsoNormal">in principle and I kind of deliberately avoided getting into too many details at this</p>
<p class="x_MsoNormal">point. If people are happy with the idea in principle I can push a patch up soon that</p>
<p class="x_MsoNormal">shows what such a class could like so that people can comment on it?</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Regards,</p>
<p class="x_MsoNormal">David Sherwood.</p>
<p class="x_MsoNormal"> </p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0cm 0cm 0cm">
<p class="x_MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Chris Tetreault <ctetreau@quicinc.com>
<br>
<b>Sent:</b> 05 November 2020 19:23<br>
<b>To:</b> David Sherwood <David.Sherwood@arm.com>; LLVM Dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> RE: [llvm-dev] [Proposal] Introducing the concept of invalid costs to the IR cost model</span></p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal"><span lang="EN-US">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:</span></p>
<p class="x_MsoNormal"><span lang="EN-US"> </span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-family:"Courier New"">template <typename T></span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-family:"Courier New"">struct Cost {</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-family:"Courier New"">  unsigned Val;</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-family:"Courier New"">  T State;</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="font-family:"Courier New"">}</span></p>
<p class="x_MsoNormal"><span lang="EN-US"> </span></p>
<p class="x_MsoNormal"><span lang="EN-US">Thanks,</span></p>
<p class="x_MsoNormal"><span lang="EN-US">   Christopher Tetreault</span></p>
<p class="x_MsoNormal"><span lang="EN-US"> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0cm 0cm 0cm">
<p class="x_MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> 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</span></p>
</div>
</div>
<p class="x_MsoNormal"><span lang="EN-US"> </span></p>
<p class="x_MsoNormal">Hi,</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">I'd like to propose a change to our cost interfaces so that instead of returning</p>
<p class="x_MsoNormal">an unsigned value from functions like getInstructionCost, getUserCost, etc., we</p>
<p class="x_MsoNormal">instead return a wrapper class that encodes an integer cost along with extra</p>
<p class="x_MsoNormal">state. The extra state can be used to express:</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">1. A cost as infinitely expensive in order to prevent certain optimisations</p>
<p class="x_MsoNormal">taking place. For example, there are already examples in LLVM where the cost is</p>
<p class="x_MsoNormal">set extremely high, but not so high that it would cause overflow. This might be to</p>
<p class="x_MsoNormal">prevent vectorisation in cases where we would have to scalarize the operation,</p>
<p class="x_MsoNormal">which is particularly relevant for scalable vectors, where scalarisation is</p>
<p class="x_MsoNormal">not [yet] available. There isn't currently a standard value for something that</p>
<p class="x_MsoNormal">constitutes very expensive and we can replace all the magic numbers with a</p>
<p class="x_MsoNormal">single invalid state.</p>
<p class="x_MsoNormal">2. A cost as unknown, where the user is simply unable to determine an accurate</p>
<p class="x_MsoNormal">cost for an operation.</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">This new wrapper class would work almost seamlessly with existing code as it</p>
<p class="x_MsoNormal">would contain the full set of operators required for arithmetic and comparisons.</p>
<p class="x_MsoNormal">This is in addition to the ability to create invalid costs and query the validity</p>
<p class="x_MsoNormal">of an existing cost. Once a cost becomes invalid or unknown it will remain in that</p>
<p class="x_MsoNormal">state regardless of any further arithmetic performed.</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Kind Regards,</p>
<p class="x_MsoNormal">David Sherwood.</p>
<p class="x_MsoNormal"> </p>
</div>
</div>
</body>
</html>