[llvm-commits] [llvm] r162956 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp test/CodeGen/X86/fp-fast.ll

Stephen Canon scanon at apple.com
Fri Aug 31 07:29:02 PDT 2012


On Aug 30, 2012, at 7:55 PM, Hal Finkel <hfinkel at anl.gov> wrote:

> On Thu, 30 Aug 2012 23:35:16 -0000
> Owen Anderson <resistor at mac.com> wrote:
> 
>> Author: resistor
>> Date: Thu Aug 30 18:35:16 2012
>> New Revision: 162956
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=162956&view=rev
>> Log:
>> Teach the DAG combiner to turn chains of FADDs (x+x+x+x+...) into
>> FMULs by constants.  This is only enabled in unsafe FP math mode,
>> since it does not preserve rounding effects for all such constants.
> 
> Are there some constants for which this always is safe (powers of two?)?

I discussed this with Owen yesterday, and advised him that this was only fair game in unsafe-math (except for n=2 or 3).  I thought about it more last night, and came up with the following:

	- I believe that I have a proof that the rounding matches up to n=5 (assuming round-to-nearest; it's clear that you can't go past n=3 in directed rounding modes).  I need to reconsider this proof carefully in the more *ahem* sober light of day, which I won't have a chance to do until tomorrow at the earliest, but exhaustive testing for single-precision seems to bear it out.
	- Unfortunately, clang doesn't model FENV_ACCESS, so we don't get to assume round-to-nearest outside of fast-math.  If the source language doesn't have a notion of rounding mode control, then this doesn't apply.
	- Fortunately, clang is moving towards modeling FP_CONTRACT.  Replacing x+x+x+...+x with n*x is fair game if fp-contract is "on" or "fast".

- Steve



More information about the llvm-commits mailing list