[llvm-commits] [llvm] r158014 - in /llvm/trunk: docs/LangRef.html include/llvm/Intrinsics.td include/llvm/Target/TargetLowering.h lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Hal Finkel hfinkel at anl.gov
Fri Jun 15 13:41:35 PDT 2012



----- Original Message -----
> From: "Chris Lattner" <clattner at apple.com>
> To: "Hal Finkel" <hfinkel at anl.gov>
> Cc: "Lang Hames" <lhames at gmail.com>, "llvm-commits LLVM" <llvm-commits at cs.uiuc.edu>, "Steve Cannon" <cannon at apple.com>
> Sent: Friday, June 15, 2012 1:04:44 PM
> Subject: Re: [llvm-commits] [llvm] r158014 - in /llvm/trunk: docs/LangRef.html include/llvm/Intrinsics.td
> include/llvm/Target/TargetLowering.h lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
> On Jun 9, 2012, at 9:51 PM, Hal Finkel wrote:
> > On Tue, 05 Jun 2012 19:07:46 -0000 Lang Hames <lhames at gmail.com>
> > wrote:
> >> Author: lhames
> >> Date: Tue Jun 5 14:07:46 2012
> >> New Revision: 158014
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=158014&view=rev
> >> Log:
> >> Add a new intrinsic: llvm.fmuladd. This intrinsic represents a
> >> multiply-add expression (a * b + c) that can be implemented as a
> >> fused multiply-add (fma) if the target determines that this will be
> >> more efficient. This intrinsic will be used to implement
> >> FP_CONTRACT
> >> support and an aggressive FMA formation mode.
> >>
> >> If your target has a fast FMA instruction you should override the
> >> isFMAFasterThanMulAndAdd method in TargetLowering to return true.
> >
> >
> > Will this apply (or be extended) to other contractions as well (like
> > a *
> > b - c) [fmsub on PowerPC].
> 
> 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.

This makes sense.

> 
> If you are interested, here's a possible sketch of an approach that
> could handle the more general cases (including subtract, random
> negations, etc):
> 
> 1. Add two bits (like NSW/NUW on integer ops) to the floating point
> binary operations (fmul, fadd, ...): LHS_Contractable and
> RHS_Contractable.
> 
> 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.
> 
> 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.

I like the idea of marking the operands because it makes the contraction markers use-specific. This is similar to the contraction-barrier intrinsic that had been proposed recently on a related thread. I'll comment more on the PR.

> 
> I filed PR13118 to track this if you're interested.

Thanks!

 -Hal

> 
> -Chris



More information about the llvm-commits mailing list