<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 14 (filtered medium)">
<style><!--
/* Font Definitions */
@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:0cm;
margin-bottom:.0001pt;
line-height:115%;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
line-height:115%;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Courier New";}
span.keyword
{mso-style-name:keyword;}
span.keywordtype
{mso-style-name:keywordtype;}
span.keywordflow
{mso-style-name:keywordflow;}
span.stringliteral
{mso-style-name:stringliteral;}
span.comment
{mso-style-name:comment;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
.MsoPapDefault
{mso-style-type:export-only;
line-height:115%;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:1558397628;
mso-list-type:hybrid;
mso-list-template-ids:2056974978 67698705 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-text:"%1\)";
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></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="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">It looks like SimplifyLibCalls has a tendency to emit calls to libm functions without checking with TLI whether these calls are available.<o:p></o:p></p>
<p class="MsoNormal">For example, PowOpt has this code:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">struct PowOpt : public UnsafeFPLibCallOptimization {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> PowOpt(bool UnsafeFPShrink) : UnsafeFPLibCallOptimization(UnsafeFPShrink) {}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Value *Ret = NULL;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> if (UnsafeFPShrink && Callee->getName() == "pow" &&<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> TLI->has(LibFunc::powf)) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> UnaryDoubleFPOpt UnsafeUnaryDoubleFP(true);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Ret = UnsafeUnaryDoubleFP.callOptimizer(Callee, CI, B);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">[...]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> if (Op2C->isExactlyValue(0.5)) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> // Expand pow(x, 0.5) to (x == -infinity ? +infinity : fabs(sqrt(x))).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> // This is faster than calling pow, and still handles negative zero<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> // and negative infinity correctly.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> // TODO: In fast-math mode, this could be just sqrt(x).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> // TODO: In finite-only mode, this could be just fabs(sqrt(x)).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Value *Inf = ConstantFP::getInfinity(CI->getType());<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Value *NegInf = ConstantFP::getInfinity(CI->getType(), true);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Value *Sqrt = EmitUnaryFloatFnCall(Op1, "sqrt", B,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Callee->getAttributes());<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Value *FAbs = EmitUnaryFloatFnCall(Sqrt, "fabs", B,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Callee->getAttributes());<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Value *FCmp = B.CreateFCmpOEQ(Op1, NegInf);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Value *Sel = B.CreateSelect(FCmp, Inf, FAbs);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> return Sel;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">[...]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal">So, before the callOptimizer call, it actually does check TLI to see that powf is available. However, the code below (that expands pow(x, 0.5) ) emits sqrt and fabs without making any checks.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This may be problematic in two cases:<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">1)<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]><span dir="LTR"></span>If LibFunc::pow is available, but LibFunc::sqrt and LibFunc::fabs are not. This is not very likely, but I guess it is technically possible.<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">2)<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]><span dir="LTR"></span>The simplification functions are also called for intrinsics (pow and exp2). In this case, it’s possible that libm is not available at all.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Is this a bug, or am I missing something here? Those unchecked EmitnaryFloatFnCalls are all over the pass.<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"> Michael<o:p></o:p></p>
</div>
<p>---------------------------------------------------------------------<br>
Intel Israel (74) Limited</p>
<p>This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</p></body>
</html>