<div dir="ltr"><div><div>Thanks for the explanation, Tim!<br><br></div>gcc 4.8.1 *does* generate an fma for your code example for an x86 target that supports fma. I'd bet that the HW vendors' compilers do the same, but I don't have any of those installed at the moment to test that theory. So this is a bug in those compilers? Do you know how they justify it?<br>
<br></div><div>I see section 6.5 "Expressions" in the C standard, and I can see that 6.5.8 would seem to agree with you assuming that a "floating expression" is a subset of "expression"...is there any other part of the standard that you know of that I can reference?<br>
</div><div><br></div>This is made a little weirder by the fact that gcc and clang have a 'fast' setting for fp-contract, but the C standard that I'm looking at states that it is just an "on-off-switch".<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Dec 18, 2013 at 11:17 AM, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> <a href="http://llvm.org/bugs/show_bug.cgi?id=17188" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=17188</a><br>
> <a href="http://llvm.org/bugs/show_bug.cgi?id=17211" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=17211</a><br>
<br>
Ah, thanks. That makes a lot more sense now.<br>
<div class="im"><br>
> Correct - clang is different than gcc, icc, msvc, xlc, etc. on this. Still<br>
> haven't seen any explanation for how this is better though...<br>
<br>
</div>That would be because it follows what C tells us a compiler has to do<br>
by default but provides overrides in either direction if you know what<br>
you're doing.<br>
<br>
The key point is that LLVM (currently) has no notion of statement<br>
boundaries, so it would fuse the operations in this function:<br>
<div class="im"><br>
float foo(float accum, float lhs, float rhs) {<br>
</div> float product = lhs * rhs;<br>
return accum + product;<br>
}<br>
<br>
This isn't allowed even under FP_CONTRACT=on (the multiply and add do<br>
not occur within a single expression), so LLVM can't in good<br>
conscience enable these optimisations by default.<br>
<br>
Cheers.<br>
<span class="HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br></div>