<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:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;
        font-weight:normal;
        font-style:normal;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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-GB" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I'd like to propose a change to our cost interfaces so that instead of returning<o:p></o:p></p>
<p class="MsoNormal">an unsigned value from functions like getInstructionCost, getUserCost, etc., we<o:p></o:p></p>
<p class="MsoNormal">instead return a wrapper class that encodes an integer cost along with extra<o:p></o:p></p>
<p class="MsoNormal">state. The extra state can be used to express:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">1. A cost as infinitely expensive in order to prevent certain optimisations<o:p></o:p></p>
<p class="MsoNormal">taking place. For example, there are already examples in LLVM where the cost is<o:p></o:p></p>
<p class="MsoNormal">set extremely high, but not so high that it would cause overflow. This might be to<o:p></o:p></p>
<p class="MsoNormal">prevent vectorisation in cases where we would have to scalarize the operation,<o:p></o:p></p>
<p class="MsoNormal">which is particularly relevant for scalable vectors, where scalarisation is<o:p></o:p></p>
<p class="MsoNormal">not [yet] available. There isn't currently a standard value for something that<o:p></o:p></p>
<p class="MsoNormal">constitutes very expensive and we can replace all the magic numbers with a<o:p></o:p></p>
<p class="MsoNormal">single invalid state.<o:p></o:p></p>
<p class="MsoNormal">2. A cost as unknown, where the user is simply unable to determine an accurate<o:p></o:p></p>
<p class="MsoNormal">cost for an operation.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This new wrapper class would work almost seamlessly with existing code as it<o:p></o:p></p>
<p class="MsoNormal">would contain the full set of operators required for arithmetic and comparisons.<o:p></o:p></p>
<p class="MsoNormal">This is in addition to the ability to create invalid costs and query the validity<o:p></o:p></p>
<p class="MsoNormal">of an existing cost. Once a cost becomes invalid or unknown it will remain in that<o:p></o:p></p>
<p class="MsoNormal">state regardless of any further arithmetic performed.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Kind Regards,<o:p></o:p></p>
<p class="MsoNormal">David Sherwood.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>