From: Richard Biener <richard.guenther@gmail.com>
To: Marc Glisse <marc.glisse@inria.fr>
Cc: Wilco Dijkstra <Wilco.Dijkstra@arm.com>, nd <nd@arm.com>,
GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Simplify floating point comparisons
Date: Wed, 02 May 2018 10:41:00 -0000 [thread overview]
Message-ID: <CAFiYyc3LA+WTXGvgBEw2fwq8Wc00aKLpAhhkgryQ5usHbKiYSg@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1804302040170.2839@stedding.saclay.inria.fr>
On Mon, Apr 30, 2018 at 8:49 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> 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 = 婊BL_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?
We have none specific so this makes it flag_unsafe_math_optimizations.
Richard.
> --
> Marc Glisse
next prev parent reply other threads:[~2018-05-02 10:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-17 16:30 Wilco Dijkstra
2017-10-18 10:36 ` Prathamesh Kulkarni
2017-10-18 11:07 ` Richard Biener
2017-10-18 19:11 ` Joseph Myers
2017-11-15 15:43 ` Wilco Dijkstra
2017-11-21 16:45 ` Jeff Law
2018-01-04 14:09 ` Wilco Dijkstra
2018-01-04 21:27 ` Marc Glisse
2018-01-05 9:32 ` Richard Biener
2018-01-09 15:34 ` Wilco Dijkstra
2018-01-12 13:25 ` Wilco Dijkstra
2018-04-30 17:41 ` Jeff Law
2018-04-30 19:04 ` Marc Glisse
2018-05-02 10:41 ` Richard Biener [this message]
2018-11-09 17:05 ` Wilco Dijkstra
2018-11-12 14:05 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFiYyc3LA+WTXGvgBEw2fwq8Wc00aKLpAhhkgryQ5usHbKiYSg@mail.gmail.com \
--to=richard.guenther@gmail.com \
--cc=Wilco.Dijkstra@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=marc.glisse@inria.fr \
--cc=nd@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).