<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;}
@font-face
        {font-family:"Book Antiqua";
        panose-1:2 4 6 2 5 3 5 3 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Book Antiqua",serif;
        color:windowtext;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
.MsoChpDefault
        {mso-style-type:export-only;
        mso-fareast-language:EN-US;}
@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-IE link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>A little while ago I asked a question on CFE-Dev about a change in the behaviour of programs using the ISO C math functions, although that question should have been put to LLVM-Dev.  But I got excellent clarification of the problem anyway.  However, since then I have been trying to adapt our out-of-tree implementation to get the previous behaviour.  The problem is that something like:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>#include <math.h><o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>extern double foo(double);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>int useMathName() {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>  if ((exp(1.0) < 2.71) || (exp(1.0) > 2.72))<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>    return -1;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>  return 0;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>}<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>int useOtherName() {<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>  if ((foo(1.0) < 2.71) || (foo(1.0) > 2.72))<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>    return -1;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>  return 0;<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span style='font-size:12.0pt;font-family:"Courier New"'>}<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>With v3.8.0 the compiler elided both the calls to ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>exp</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ and the tests, so the function ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>useMathName</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ reduced to simply:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>return 0;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>But this was not correct as it ignored the possibility that the math functions could have the side-effect of changing ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New";color:black'>errno</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’, and this was fixed in v3.9.0, and the calls are no longer elided, though using the “as-if” rule, the tests are still eliminated and ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>useMathName</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ becomes:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>(void)exp(1.0);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>(void)exp(1.0);<o:p></o:p></span></p><p class=MsoNormal style='margin-left:36.0pt'><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>return 0;<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>So I changed our implementation so that ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>-fno-math-errno</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ is the default for the tool-chain, and the ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New";color:black'>-fmath-errno</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ option is not passed on to the CC1 phase.  I expected that this would allow the compiler to elide the calls, but it is not doing so.  I don’t want to use ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>-ffast-math</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ as this has lots of FP issues, and I don’t want to make it the default.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>Any idea why the math functions are not elided?  I am using ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>-O3</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ and implying ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>-fno-math-errno</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’.  I have verified that our Toolchain implements ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>IsMathErrnoDefault</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ and returns ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>false</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’, and that the option ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>-fmath-errno</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’ is not being passed to the CC1 stage.  Since our math function implementation does not in fact change ‘</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Courier New"'>errno</span><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>’, it is very desirable that this elision occurs in an FP safe way.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>Thanks,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'>            MartinO<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-GB style='font-size:12.0pt;font-family:"Book Antiqua",serif'><o:p> </o:p></span></p></div></body></html>