This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fold sqrt comparisons against constants


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]