From: Richard Biener <richard.guenther@gmail.com>
To: Jeff Law <law@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH][RFA][PR tree-optimization/79095] Improve overflow test optimization and avoid invalid warnings
Date: Mon, 30 Jan 2017 09:55:00 -0000 [thread overview]
Message-ID: <CAFiYyc32HFVgJY-bsScuiwqvNXqa=fL7wADPjO1dHT6SuyA6MQ@mail.gmail.com> (raw)
In-Reply-To: <5805fa33-4768-f5db-9d41-2a1d9b8bd0bf@redhat.com>
On Fri, Jan 27, 2017 at 11:21 PM, Jeff Law <law@redhat.com> wrote:
> On 01/27/2017 02:35 PM, Richard Biener wrote:
>>
>> On January 27, 2017 7:30:07 PM GMT+01:00, Jeff Law <law@redhat.com> wrote:
>>>
>>> On 01/27/2017 05:08 AM, Richard Biener wrote:
>>>>
>>>> On Fri, Jan 27, 2017 at 10:02 AM, Marc Glisse <marc.glisse@inria.fr>
>>>
>>> wrote:
>>>>>
>>>>> On Thu, 26 Jan 2017, Jeff Law wrote:
>>>>>
>>>>>>> I assume this causes a regression for code like
>>>>>>>
>>>>>>> unsigned f(unsigned a){
>>>>>>> unsigned b=a+1;
>>>>>>> if(b<a)return 42;
>>>>>>> return b;
>>>>>>> }
>>>>>>
>>>>>>
>>>>>> Yes. The transformation ruins the conversion into ADD_OVERFLOW for
>>>
>>> the +-
>>>>>>
>>>>>> 1 case. However, ISTM that we could potentially recover the
>>>
>>> ADD_OVERFLOW in
>>>>>>
>>>>>> phi-opt. It's a very simple pattern that would be presented to
>>>
>>> phi-opt, so
>>>>>>
>>>>>> it might not be terrible to recover -- which has the advantage that
>>>
>>> if a
>>>>>>
>>>>>> user wrote an optimized overflow test we'd be able to recover
>>>
>>> ADD_OVERFLOW
>>>>>>
>>>>>> for it.
>>>>>
>>>>>
>>>>>
>>>>> phi-opt is a bit surprising at first glance because there can be
>>>
>>> overflow
>>>>>
>>>>> checking without condition/PHI, but if it is convenient to catch
>>>
>>> many
>>>>>
>>>>> cases...
>>>>
>>>>
>>>> Yeah, and it's still on my TODO to add some helpers exercising
>>>> match.pd COND_EXPR
>>>> patterns from PHI nodes and their controlling condition.
>>>
>>> It turns out to be better to fix the existing machinery to detect
>>> ADD_OVERFLOW in the transformed case than to add new detection to
>>> phi-opt.
>>>
>>> The problem with improving the detection of ADD_OVERFLOW is that the
>>> transformed test may allow the ADD/SUB to be sunk. So by the time we
>>> run the pass to detect ADD_OVERFLOW, the test and arithmetic may be in
>>> different blocks -- ugh.
>>>
>>> The more I keep thinking about this the more I wonder if transforming
>>> the conditional is just more of a headache than its worth -- the main
>>> need here is to drive propagation of known constants into the THEN/ELSE
>>>
>>> clauses. Transforming the conditional makes that easy for VRP & DOM to
>>>
>>> discover those constant and the transform is easy to write in match.pd.
>>>
>>> But we could just go back to discovering the case in VRP or DOM via
>>> open-coding detection, then propagating the known constants without
>>> transforming the conditional.
>>
>>
>> Indeed we can do that. And in fact with named patterns in match.pd you
>> could even avoid the open-coding.
>
> negate_expr_p being the example? That does look mighty interesting... After
> recognition we'd still have to extract the operands, but it does look like
> it might handle the detection part.
Yes, the (match ..) stuff is actually exported in gimple-match.c (just
no declarations
are emitted to headers yet). logical_inverted_value might be a better example
given it has an "output":
(match (logical_inverted_value @0)
(truth_not @0))
bool
gimple_logical_inverted_value (tree t, tree *res_ops, tree
(*valueize)(tree) ATTRIBUTE_UNUSED)
{
you get @0 in res_ops[0] if that returns true. I've at some point
written some of tree-vect-patterns.c
as match.pd (match...) but never really completed it. In the end it
would be nice to write the patterns
in-inline at use points, say,
/* (match (foo @0) (....)) */
if (gimple_foo (...))
{
}
and have some gen-program extract those patterns from source files
(plus inserting the necessary
prototypes locally?).
Richard.
> jeff
next prev parent reply other threads:[~2017-01-30 9:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-26 1:03 Jeff Law
2017-01-26 7:38 ` Marc Glisse
2017-01-26 15:57 ` Jeff Law
2017-01-27 9:13 ` Marc Glisse
2017-01-27 12:10 ` Richard Biener
2017-01-27 19:20 ` Jeff Law
2017-01-27 22:02 ` Richard Biener
2017-01-27 22:10 ` Jeff Law
2017-01-27 22:29 ` Jeff Law
2017-01-30 9:55 ` Richard Biener [this message]
2017-01-30 18:08 ` Jeff Law
2017-01-30 19:53 ` Richard Biener
2017-01-27 22:36 ` Andrew Pinski
2017-01-26 18:32 ` Jeff Law
2017-01-26 10:00 ` Richard Biener
2017-01-26 16:09 ` Jeff Law
2017-01-27 9:03 ` Marc Glisse
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='CAFiYyc32HFVgJY-bsScuiwqvNXqa=fL7wADPjO1dHT6SuyA6MQ@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=law@redhat.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).