<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jun 15, 2012, at 1:51 PM, Chandler Carruth wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: arial, helvetica, sans-serif"><font size="2"><div class="gmail_quote">On Fri, Jun 15, 2012 at 10:04 AM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com" target="_blank">clattner@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; "><div class="im">On Jun 9, 2012, at 9:51 PM, Hal Finkel wrote:<br>
> On Tue, 05 Jun 2012 19:07:46 -0000 Lang Hames <<a href="mailto:lhames@gmail.com">lhames@gmail.com</a>> wrote:<br>
>> Author: lhames<br>
>> Date: Tue Jun 5 14:07:46 2012<br>
>> New Revision: 158014<br>
>><br>
>> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=158014&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=158014&view=rev</a><br>
>> Log:<br>
>> Add a new intrinsic: llvm.fmuladd. This intrinsic represents a<br>
>> multiply-add expression (a * b + c) that can be implemented as a<br>
>> fused multiply-add (fma) if the target determines that this will be<br>
>> more efficient. This intrinsic will be used to implement FP_CONTRACT<br>
>> support and an aggressive FMA formation mode.<br>
>><br>
>> If your target has a fast FMA instruction you should override the<br>
>> isFMAFasterThanMulAndAdd method in TargetLowering to return true.<br>
><br>
><br>
> Will this apply (or be extended) to other contractions as well (like a *<br>
> b - c) [fmsub on PowerPC].<br>
<br>
</div>It doesn't, and can't reasonably be extended to support it. However, it is progress that does help a number of other targets and can be upgraded to be more general if someone is motivated to do it.<br>
<br>
If you are interested, here's a possible sketch of an approach that could handle the more general cases (including subtract, random negations, etc):<br>
<br>
1. Add two bits (like NSW/NUW on integer ops) to the floating point binary operations (fmul, fadd, ...): LHS_Contractable and RHS_Contractable.<br>
<br>
2. Semantics are that the code generator is allowed to contract any tree of operations linked through "contractable" operands. In the FMA case, the multiply can be merged into the add if the add's operand is marked contractable. In the PPC case, fmsub can be contracted if the multiply operand of the subtract is marked.<br>
<br>
3. Clang would generate the operand bits according to the language mode in effect. I believe that this model is sufficiently general to handle the C99 and C++ cases.<br>
<br>
I filed PR13118 to track this if you're interested.</blockquote><div><br></div><div>Yes, please.</div><div><br></div><div>Also Chris, you should read the lengthy review thread for this patch. Steve, myself, and John McCall discussed lots of different options here, and John had an alternative to yours that also preserved the generality... I'm not sure which approach is best, so I'd love your thoughts on the two. </div>
</div></font></div>
</blockquote></div><br><div>They are semantically equivalent (and mine is inspired by his). The major difference is that mine won't block a bunch of optimizations by introducing a "copy" that has to be looked through, and mine follows the pattern established by the NUW/NSW bits on integer operations. At this point, it makes sense to move further discussion to PR13118.</div><div><br></div><div>-Chris</div></body></html>