This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fold sqrt comparisons against constants
- From: Zack Weinberg <zack at codesourcery dot com>
- To: Roger Sayle <roger at www dot eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sun, 16 Mar 2003 15:52:47 -0800
- Subject: Re: [PATCH] Fold sqrt comparisons against constants
- References: <Pine.LNX.4.44.0303161429020.26546-100000@www.eyesopen.com>
Roger Sayle <roger at www dot eyesopen dot com> writes:
> This patch performs constant folding of comparisons of the result
> of sqrt, sqrtf, and sqrtl against floating point constants. This
> optimization can often be applied in scientific software, where
> the distance between two points is compared against a threshold.
> I know of one structural biology application where the single test
> "sqrt(x) < 9.0" is the critical path. The patch below transforms
> this into the equivalent "(x>=0.0) && (x<81.0)" with -ffast-math.
This looks good to me, but you should get a second opinion from
someone who's more up on floating point issues.
As a followup, could you consider working out which of these
optimizations are only safe under -ffast-math and which can be
applied generally? It looks to me like your example above is
always safe, or at least could be made safe by adding NaN checks.
zw