<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: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;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@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"><span style="font-family:"Courier New"">Hi all,<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"">This is about <a href="https://reviews.llvm.org/D26708">
https://reviews.llvm.org/D26708</a><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"">Currently when the command-line switch '-ffast-math' is specified, the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">IR-level fast-math-flag 'fast' gets attached to appropriate FP math<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">instructions.  That flag acts as an "umbrella" to implicitly turn on all the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">other fast-math-flags ('nnan', 'ninf', 'nsz' and 'arcp'):<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""><a href="http://llvm.org/docs/LangRef.html#fast-math-flags">http://llvm.org/docs/LangRef.html#fast-math-flags</a><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"">This approach has the shortcoming that when there is a desire to disable one<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">of these fast-math-flags, if the 'fast' flag remains, it implicitly<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">re-enables the one being disabled.  For example, compiling this test-case:<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"">    extern void use(float x, float y);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">    void test(float a, float b, float c) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">      float q1 = a / c;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">      float q2 = b / c;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">      use(q1, q2);<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"">at '-O2 -ffast-math' does a reciprocal-transformation, so only one division<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">is done (as desired with fast-math).  Compiling it with:<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"">  -O2 -ffast-math -fno-reciprocal-math<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"">should disable the reciprocal transformations (the flag 'arcp'), but leave<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">all the other fast-math transformations enabled.  The current implementation<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">doesn't do that, since the 'fast' IR-level flag still gets set.<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"">Motivation of this discussion:
<a href="https://llvm.org/bugs/show_bug.cgi?id=27372#c2">https://llvm.org/bugs/show_bug.cgi?id=27372#c2</a><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"">As an aside, when '-ffast-math' is specified on the command-line, the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">following six switches are all passed to cc1:<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"">    -menable-no-infs<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">    -menable-no-nans<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">    -fno-signed-zeros<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">    -freciprocal-math<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">    -fno-trapping-math<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">    -ffp-contract=fast<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"">and '-ffast-math' itself is also passed cc1 (the act of passing '-ffast-math'<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">to cc1 results in the macro '__FAST_MATH__' being defined).  When (for<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">example) '-fno-reciprocal-math' is passed in addition to '-ffast-math', then<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">'-freciprocal-math' is no longer passed to cc1 (and the other five listed<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">above still are passed, along with '-ffast-math' still being passed).  It<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">seems like the intention was that these individual switches were to enable<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">the individual floating-point transformations (and so the lack of any of<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">those switches would suppress the relevant transformations), but the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">'-ffast-math' "umbrella" is over-riding the attempted suppression.<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"">The change proposed at https://reviews.llvm.org/D26708 deals with this issue<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">just for the reciprocal-transformation case, but it changes the semantics of<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">the 'fast' IR-level flag so that it no longer implies all the others.  With<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">that proposed approach, rather than an "umbrella" flag such as 'fast' being<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">checked in the back-end (along with an individual flag like 'arcp'), just<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">checking the individual flag ('arcp') would be done.  Any fast-math-related<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">transformation that doesn't have an individual flag (e.g., re-association<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">currently doesn't), should eventually have an individual flag defined for<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">it, and then that individual flag should be checked.<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"">What do people think?<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"">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">-Warren<o:p></o:p></span></p>
</div>
</body>
</html>