<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>I really like Chandler's approach! By passing the state and
status in and out as arguments and returns, rather than as side
channels and side effects, the compiler will be able to do its
normal goodness without breaking correctness :D<br>
</p>
<p>I am a bit cautious when Chandler says that InstCombine should
lower the intrinsics if it is default (i.e. round-nearest) and the
flags are not used. It seems legitimate for that exact intrinsic
to be used by developers who especially want round-nearest in code
where they know the dynamic rounding mode may not be default..?<br>
</p>
<p>Here's something to ponder: does exception trapping mean that the
new intrinsic functions have side-effects? Not all targets
support exception trapping. I believe ARM64 is an example
mainstream target that doesn't support exception traps. If a
target doesn't support trapping, or if the intrinsic doesn't ask
for it, then perhaps this allows the intrinsics to be const?<br>
</p>
<p>The standard C math functions (pow, rint, sqrt etc) are already
intrinsics. Will these also be parameterised?</p>
<p>(I have been using Debian code search
<a class="moz-txt-link-freetext" href="https://github.com/williame/debian-code-search-cli">https://github.com/williame/debian-code-search-cli</a> to find
examples of fenv usage 'in the wild', and its very very sparse.
However, there are a handful of examples where someone doing
interval arithmetic or something, and in the cases hopefully we
can parameterise the C math function intrinsics so backends can
use explicit rounding ops if they have them.)</p>
<p>/Will<br>
</p>
<div class="moz-cite-prefix">On 18/08/16 20:14, Kaylor, Andrew
wrote:<br>
</div>
<blockquote
cite="mid:0983E6C011D2DC4188F8761B533492DE57566483@ORSMSX115.amr.corp.intel.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",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;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@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]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">We’re
in the process of trying to figure out a good way to
harmonize FP exception handling and rounding with the
related issues in vector masking. Obviously we don’t want
to have completely different solutions for these closely
related problems. We’re looking at ways to do something
along the lines of Chandler’s proposal that will also handle
the problem of false exceptions in masked vector lanes, but
we want to make sure that whatever we do won’t limit the
possibilities of optimizing FP code while correctly handling
fenv access because we also care a lot about that.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">BTW,
I’m not using the royal we here. I mean to indicate that
I’m working with other people here at Intel to put together
something that isn’t half baked when we propose it. We were
hoping to have a BOF session at the upcoming LLVM Dev
Meeting to talk about this, but of course I’m happy to
discuss it before then too.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">-Andy<o:p></o:p></span></p>
<p class="MsoNormal"><a moz-do-not-send="true"
name="_MailEndCompose"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></a></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><a moz-do-not-send="true"
name="_____replyseparator"></a><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">
<a class="moz-txt-link-abbreviated" href="mailto:mehdi.amini@apple.com">mehdi.amini@apple.com</a> [<a class="moz-txt-link-freetext" href="mailto:mehdi.amini@apple.com">mailto:mehdi.amini@apple.com</a>]
<br>
<b>Sent:</b> Thursday, August 18, 2016 10:31 AM<br>
<b>To:</b> Kaylor, Andrew
<a class="moz-txt-link-rfc2396E" href="mailto:andrew.kaylor@intel.com"><andrew.kaylor@intel.com></a><br>
<b>Cc:</b> Reid Kleckner <a class="moz-txt-link-rfc2396E" href="mailto:rnk@google.com"><rnk@google.com></a>; Will
<a class="moz-txt-link-rfc2396E" href="mailto:will@millcomputing.com"><will@millcomputing.com></a>; Chandler Carruth
(<a class="moz-txt-link-abbreviated" href="mailto:chandlerc@gmail.com">chandlerc@gmail.com</a>) <a class="moz-txt-link-rfc2396E" href="mailto:chandlerc@gmail.com"><chandlerc@gmail.com></a><br>
<b>Subject:</b> Re: [llvm-dev] fenv.h vs the optimizer<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Great, feel free to CC me and Steve Canon
on the patches!<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">— <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Mehdi<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Aug 18, 2016, at 10:22 AM,
Kaylor, Andrew <<a moz-do-not-send="true"
href="mailto:andrew.kaylor@intel.com">andrew.kaylor@intel.com</a>>
wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">> That’s where we are right
now, “someone” needs to step up and drives this,
interested? :)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Yes!</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<div>
<p class="MsoNormal"><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span
class="apple-converted-space"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span></span><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif"><a
moz-do-not-send="true"
href="mailto:mehdi.amini@apple.com">mehdi.amini@apple.com</a>
[<a moz-do-not-send="true"
href="mailto:mehdi.amini@apple.com">mailto:mehdi.amini@apple.com</a>]<span
class="apple-converted-space"> </span><br>
<b>Sent:</b><span
class="apple-converted-space"> </span>Thursday,
August 18, 2016 10:17 AM<br>
<b>To:</b><span class="apple-converted-space"> </span>Kaylor,
Andrew <<a moz-do-not-send="true"
href="mailto:andrew.kaylor@intel.com">andrew.kaylor@intel.com</a>><br>
<b>Cc:</b><span class="apple-converted-space"> </span>Reid
Kleckner <<a moz-do-not-send="true"
href="mailto:rnk@google.com">rnk@google.com</a>>;
Will <<a moz-do-not-send="true"
href="mailto:will@millcomputing.com">will@millcomputing.com</a>>;
Chandler Carruth (<a moz-do-not-send="true"
href="mailto:chandlerc@gmail.com">chandlerc@gmail.com</a>)
<<a moz-do-not-send="true"
href="mailto:chandlerc@gmail.com">chandlerc@gmail.com</a>><br>
<b>Subject:</b><span
class="apple-converted-space"> </span>Re:
[llvm-dev] fenv.h vs the optimizer</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<blockquote
style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal">On Aug 18, 2016, at 10:01
AM, Kaylor, Andrew <<a
moz-do-not-send="true"
href="mailto:andrew.kaylor@intel.com"><span
style="color:purple">andrew.kaylor@intel.com</span></a>>
wrote:<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">We
are definitely interested in correctly
handling the FP side effects. </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">I’ve
been reading up on the past community
discussions of this in hopes of bringing
this back into focus. The last discussion
I found on the topic was this thread
started by Medhi in February:</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><a
moz-do-not-send="true"
href="http://lists.llvm.org/pipermail/llvm-dev/2016-February/094869.html"><span
style="color:purple">http://lists.llvm.org/pipermail/llvm-dev/2016-February/094869.html</span></a></span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Chandler
made a proposal in that thread that seemed
to be widely agreed upon, but then as far
as I can tell nothing was done to
implement it.</span><o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">That’s where we are right
now, “someone” needs to step up and drives this,
interested? :)<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">— <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Mehdi<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<br>
<o:p></o:p></p>
</div>
<blockquote
style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">-Andy</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"><b><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span
class="apple-converted-space"><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span></span><span
style="font-size:11.0pt;font-family:"Calibri",sans-serif">llvm-dev
[<a moz-do-not-send="true"
href="mailto:llvm-dev-bounces@lists.llvm.org"><span
style="color:purple">mailto:llvm-dev-bounces@lists.llvm.org</span></a>]<span
class="apple-converted-space"> </span><b>On
Behalf Of<span
class="apple-converted-space"> </span></b>Reid
Kleckner via llvm-dev<br>
<b>Sent:</b><span
class="apple-converted-space"> </span>Thursday,
August 18, 2016 8:42 AM<br>
<b>To:</b><span
class="apple-converted-space"> </span>Will
<<a moz-do-not-send="true"
href="mailto:will@millcomputing.com"><span
style="color:purple">will@millcomputing.com</span></a>>;
Tim Amini Golling <<a
moz-do-not-send="true"
href="mailto:mehdi.amini@apple.com"><span
style="color:purple">mehdi.amini@apple.com</span></a>><br>
<b>Cc:</b><span
class="apple-converted-space"> </span>llvm-dev
<<a moz-do-not-send="true"
href="mailto:llvm-dev@lists.llvm.org"><span
style="color:purple">llvm-dev@lists.llvm.org</span></a>><br>
<b>Subject:</b><span
class="apple-converted-space"> </span>Re:
[llvm-dev] fenv.h vs the optimizer</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">LLVM has never really
supported fenv.h:<o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><a
moz-do-not-send="true"
href="https://llvm.org/bugs/show_bug.cgi?id=8100"><span
style="color:purple">https://llvm.org/bugs/show_bug.cgi?id=8100</span></a><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">Even if we added
support for the rounding modes, we don't
support non-call exceptions either:<o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><a
moz-do-not-send="true"
href="https://llvm.org/bugs/show_bug.cgi?id=1269"><span
style="color:purple">https://llvm.org/bugs/show_bug.cgi?id=1269</span></a><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">I think there is
interest in addressing the rounding mode
stuff, but less interest in modelling FP
side effects. Medhi had some ideas
around this.<o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal">On Thu, Aug 18, 2016
at 1:12 AM, Will via llvm-dev <<a
moz-do-not-send="true"
href="mailto:llvm-dev@lists.llvm.org"
target="_blank"><span
style="color:purple">llvm-dev@lists.llvm.org</span></a>>
wrote:<o:p></o:p></p>
</div>
</div>
<blockquote
style="border:none;border-left:solid #CCCCCC
1.0pt;padding:0in 0in 0in
6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal">Howdy all,<br>
<br>
I've been playing around with programs
that use the C11 fenv.h.<br>
<br>
It seems that, currently, the LLVM
compiler does not regard to the
exception-flag side-effects of
floating point operations?<br>
<br>
When run on my macbook, the example
code on<span
class="apple-converted-space"> </span><a
moz-do-not-send="true"
href="http://en.cppreference.com/w/c/numeric/fenv/FE_exceptions"
target="_blank"><span
style="color:purple">http://en.cppreference.com/w/c/numeric/fenv/FE_exceptions</span></a><span
class="apple-converted-space"> </span>does
not print all the expected exceptions.<br>
<br>
Other examples:<br>
<br>
void foo() {<br>
fesetround(FE_DOWNWARD);<br>
printf("foo downward: %f\n",
rint(0.5));<br>
fesetround(FE_UPWARD);<br>
printf("foo upward: %f\n",
rint(0.5));<br>
}<br>
<br>
If compiled with optimization, only
one call to rint() is made and the
result is reused.<br>
<br>
void bar(double a, double b) {<br>
feclearexcept(FE_INEXACT);<br>
a / b;<br>
printf("bar %f / %f is %sexact\n",
a, b, fetestexcept(FE_INEXACT)? "in":
"");<br>
}<br>
<br>
The compiler omits the divide as the
result is unused. And so on.<br>
<br>
Presumably this has never worked? And
perhaps LLVM is no worse than other
compilers in this regard?<br>
<br>
Is there any appetite to fix it? What
kind of changes would need to be made?<br>
<br>
Thx,<br>
<br>
Will<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a moz-do-not-send="true"
href="mailto:llvm-dev@lists.llvm.org"
target="_blank"><span
style="color:purple">llvm-dev@lists.llvm.org</span></a><br>
<a moz-do-not-send="true"
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
target="_blank"><span
style="color:purple">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</span></a><o:p></o:p></p>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</blockquote>
<br>
</body>
</html>