From: Richard Biener <richard.guenther@gmail.com>
To: "Martin Liška" <mliska@suse.cz>
Cc: Andrew MacLeod <amacleod@redhat.com>,
GCC Patches <gcc-patches@gcc.gnu.org>,
Aldy Hernandez <aldyh@redhat.com>
Subject: Re: [PATCH] Loop unswitching: support gswitch statements.
Date: Thu, 2 Dec 2021 14:46:39 +0100 [thread overview]
Message-ID: <CAFiYyc2BRbchwoHAL7E_Go0=u3s+1V1mKev=VqhoY_dismxfbw@mail.gmail.com> (raw)
In-Reply-To: <cbeef151-55d1-e738-adf0-4dfd3f9ea3f1@suse.cz>
On Thu, Dec 2, 2021 at 2:10 PM Martin Liška <mliska@suse.cz> wrote:
>
> On 12/2/21 13:01, Richard Biener wrote:
> > On Thu, Dec 2, 2021 at 12:45 PM Martin Liška <mliska@suse.cz> wrote:
> >>
> >> On 12/1/21 19:21, Andrew MacLeod wrote:
> >>> On 12/1/21 09:48, Martin Liška wrote:
> >>>> On 12/1/21 15:34, Richard Biener wrote:
> >>>>> On Wed, Dec 1, 2021 at 3:25 PM Martin Liška <mliska@suse.cz> wrote:
> >>>>>>
> >>>>>> On 12/1/21 15:19, Richard Biener wrote:
> >>>>>>> which is compute the range of 'lhs' on edge_true into predicate->true_range,
> >>>>>>> assign that same range to ->false_range and then invert it to get the
> >>>>>>> range on the false_edge. What I am saying is that for better precision
> >>>>>>> you should do
> >>>>>>>
> >>>>>>> ranger->range_on_edge (predicate->false_range, edge_false, lhs);
> >>>>>>>
> >>>>>>> rather than prematurely optimize this to the inversion of the true range
> >>>>>>> since yes, ranger is CFG sensitive and only the_last_ predicate on a
> >>>>>>> long CFG path is actually inverted.
> >>>>>>>
> >>>>>>> What am I missing?
> >>>>>>
> >>>>>> I might be misunderstood, but I think it's the problem defined here:
> >>>>>> https://gcc.gnu.org/pipermail/gcc-patches/2021-November/584605.html
> >>>>>>
> >>>>>> where I used the ranger->range_on_edge on the false_edge.
> >>>>>
> >>>>> Ah, OK. But then even the true_edge range is possibly wrong, no?
> >>>>
> >>>> You are of course correct, I've just proved that in debugger ://
> >>>>
> >>>>> Consider
> >>>>>
> >>>>> for (;;)
> >>>>> {
> >>>>> if (a < 100)
> >>>>> if (a > 50) // unswitch on this
> >>>>> /* .. */
> >>>>> if (a < 120)
> >>>>> /* ... */
> >>>>> }
> >>>>>
> >>>>> then you record [51, 99] for true_range of the a > 50 predicate and thus
> >>>>> simplification will simplify the if (a < 120) check, no?
> >>>>
> >>>> Yep.
> >>>>
> >>>>>
> >>>>> You can only record the range from the (CFG independent) a > 50 check,
> >>>>> thus [51, +INF] but of course at simplification time you can also use
> >>>>> the CFG context at each simplification location.
> >>>>
> >>>> @Andrew: How can I easily get irange based just on a stmt? Something like fold_range
> >>>> with int_range_max as the 3rd argument?
> >>>>
> >>> Sorry, I miss these things if I'm not directly CC'd a lot :-)
> >>>
> >>> So you just want to know the basic range the stmt generates without context? Sure, what you say would be fine, but your want to initialize it to the type range:
> >>
> >> Yes, I want to know range of LHS in a gcond statement and the same for cases in a gswitch statement.
> >>
> >>>
> >>> int_range_max range (TREE_TYPE (name));
> >>>
> >>> you can also simply trigger it using the current SSA_NAME_RANGE_INFO global values query instead of the default current contextual one... which , if there isnt a global range, will automatically use the range of the type of the argument.. so maybe just try
> >>>
> >>> fold_range (r, stmt, get_global_range_query ())
> >>
> >> Doing
> >>
> >> predicate->true_range = int_range_max (TREE_TYPE (lhs));
> >> fold_range (predicate->true_range, stmt, get_global_range_query ());
> >> predicate->true_range.debug();
> >>
> >> gives me _Bool VARYING.
> >
> > Likely because that gives a range for the bool result rather than
> > a range for the LHS of a LHS op RHS on the true or false edge.
>
> Yes :) I guess Andrew can help us.
some grepping and poking found be gimple_range_calc_op1 which should
eventually do the trick (for constant gimple_cond_rhs at least).
> > I would guess no stmt level API gives that. In previous VRP
> > incarnation assert expr discovery would yield the asserts
> > that hold for the LHS on the respective edge and from the asserts
> > ranges could be determined.
>
> About the gswitch statements, I need similarly irange for a switch statement
> on an edge e.
Well, you simply want a range (and condition to generate the if from)
from a CASE_LABEL_EXPR. Given that's either a single integer constant
or a RANGE_EXPR it should be easy to use some of the irange CTORs here.
Richard.
> Thanks for help,
> Martin
>
> >
> > Richard.
> >
> >>
> >> Martin
> >>
> >>>
> >>> Andrew
> >>>
> >>>
> >>>
> >>>
> >>
>
next prev parent reply other threads:[~2021-12-02 13:46 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-15 8:46 Martin Liška
2021-09-19 16:50 ` Jeff Law
2021-09-28 11:50 ` Richard Biener
2021-09-28 20:39 ` Andrew MacLeod
2021-09-29 8:43 ` Richard Biener
2021-09-29 15:20 ` Andrew MacLeod
2021-09-29 15:28 ` Jeff Law
2021-09-29 15:59 ` Andrew MacLeod
2021-09-30 7:33 ` Richard Biener
2021-11-08 15:05 ` Martin Liška
2021-11-08 18:34 ` Andrew MacLeod
2021-11-08 19:45 ` Andrew MacLeod
2021-11-09 13:37 ` Richard Biener
2021-11-09 16:41 ` Andrew MacLeod
2021-11-10 7:52 ` Aldy Hernandez
2021-11-10 8:50 ` Richard Biener
2021-11-09 16:44 ` Martin Liška
2021-11-10 8:59 ` Richard Biener
2021-11-10 13:29 ` Martin Liška
2021-11-11 7:15 ` Richard Biener
2021-11-16 13:53 ` Martin Liška
2021-11-19 9:49 ` Richard Biener
2021-11-16 14:40 ` Martin Liška
2021-11-19 10:00 ` Richard Biener
2021-11-22 15:06 ` Martin Liška
2021-11-23 13:58 ` Richard Biener
2021-11-23 15:20 ` Martin Liška
2021-11-23 16:36 ` Martin Liška
2021-11-24 8:00 ` Richard Biener
2021-11-24 10:48 ` Martin Liška
2021-11-24 12:48 ` Richard Biener
2021-11-24 14:14 ` Martin Liška
2021-11-24 14:32 ` Martin Liška
2021-11-26 8:12 ` Richard Biener
2021-11-29 12:45 ` Martin Liška
2021-11-30 11:17 ` Richard Biener
2021-12-01 14:10 ` Martin Liška
2021-12-01 14:19 ` Richard Biener
2021-12-01 14:25 ` Martin Liška
2021-12-01 14:34 ` Richard Biener
2021-12-01 14:48 ` Martin Liška
2021-12-01 18:21 ` Andrew MacLeod
2021-12-02 11:45 ` Martin Liška
2021-12-02 12:01 ` Richard Biener
2021-12-02 13:10 ` Martin Liška
2021-12-02 13:46 ` Richard Biener [this message]
2021-12-08 21:06 ` Andrew MacLeod
2021-12-02 14:27 ` Andrew MacLeod
2021-12-02 16:02 ` Martin Liška
2021-12-03 14:09 ` Andrew MacLeod
2021-12-09 12:59 ` Martin Liška
2021-12-09 14:44 ` Andrew MacLeod
2021-12-09 13:02 ` Martin Liška
2022-01-05 12:34 ` Richard Biener
2022-01-06 15:11 ` Andrew MacLeod
2022-01-06 16:02 ` Martin Liška
2022-01-06 16:20 ` Andrew MacLeod
2022-01-06 16:35 ` Martin Liška
2022-01-06 16:42 ` Andrew MacLeod
2022-01-06 16:32 ` Andrew MacLeod
2022-01-06 16:30 ` Martin Liška
2022-01-13 16:01 ` Martin Liška
2022-01-14 7:23 ` Richard Biener
2021-11-25 10:38 ` Aldy Hernandez
2021-11-26 7:45 ` Richard Biener
2021-11-24 7:46 ` Richard Biener
2021-10-05 17:08 ` Andrew MacLeod
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='CAFiYyc2BRbchwoHAL7E_Go0=u3s+1V1mKev=VqhoY_dismxfbw@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=mliska@suse.cz \
/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).