[prev in list] [next in list] [prev in thread] [next in thread]
List: gcc-patches
Subject: Re: [PATCH] Simplify floating point comparisons
From: Marc Glisse <marc.glisse () inria ! fr>
Date: 2018-04-30 18:49:59
Message-ID: alpine.DEB.2.21.1804302040170.2839 () stedding ! saclay ! inria ! fr
[Download RAW message or body]
On Fri, 12 Jan 2018, Wilco Dijkstra wrote:
> Hi,
>
> Here is the updated version:
>
> This patch implements some of the optimizations discussed in
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71026.
>
> Simplify (C / x >= 0.0) into x >= 0.0 with -fno-signed-zeros
> and -ffinite-math-only. If C is negative the comparison is reversed.
> Only handle >= and <= for now since C / x can underflow if C is small.
>
>
> Simplify (x * C1) > C2 into x > (C2 / C1) with -funsafe-math-optimizations.
> If C1 is negative the comparison is reversed.
>
> OK for commit?
>
> ChangeLog
> 2018-01-10 Wilco Dijkstra <wdijkstr@arm.com>
> Jackson Woodruff <jackson.woodruff@arm.com>
>
> gcc/
> PR 71026/tree-optimization
> * match.pd: Simplify floating point comparisons.
>
> gcc/testsuite/
> PR 71026/tree-optimization
> * gcc.dg/div-cmp-1.c: New test.
> * gcc.dg/div-cmp-2.c: New test.
> --
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 435125a317275527661fba011a9d26e507d293a6..8a6fee906de6a750201362119862f8326868f26b 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -376,6 +376,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (rdiv @0 (negate @1))
> (rdiv (negate @0) @1))
>
> +/* Simplify (C / x op 0.0) to x op 0.0 for C != 0, C != Inf/Nan.
> + Only handle >= and <= since C / x may underflow to zero. */
> +(for op (le ge)
> + res_op (lt ge)
> + neg_op (ge lt)
> + (simplify
> + (op (rdiv REAL_CST@0 @1) real_zerop@2)
> + (if (!HONOR_SIGNED_ZEROS (@1) && !HONOR_INFINITIES (@1))
> + (switch
> + (if (real_less (&dconst0, TREE_REAL_CST_PTR (@0)))
> + (res_op @1 @2))
> + /* For C < 0, use the inverted operator. */
> + (if (real_less (TREE_REAL_CST_PTR (@0), &dconst0))
> + (neg_op @1 @2))))))
Let's try with C = DBL_MIN and x = ąDBL_MAX. I don't believe it involves
signed zeros or infinities, just an underflow. First, the result depends
on the rounding mode. And in the default round-to-nearest, both divisions
give 0, and thus compare the same with 0, but we replace that with a sign
test on x, where they clearly give opposite answers.
What would be the proper flag to test to check if we care about underflow?
--
Marc Glisse
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic