From: Andrew Pinski <pinskia@gmail.com>
To: Andrew MacLeod <amacleod@redhat.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>,
Richard Biener <richard.guenther@gmail.com>,
Jeff Law <jeffreyalaw@gmail.com>,
Aldy Hernandez <aldyh@redhat.com>
Subject: Re: how does vrp2 rearrange this?
Date: Thu, 21 Oct 2021 12:59:59 -0700 [thread overview]
Message-ID: <CA+=Sn1nWEytYBcBsyyzvdnWVNJVtr1Ub-Qrr666z7-MLrEL6Pg@mail.gmail.com> (raw)
In-Reply-To: <1ef00577-fd32-e3b8-a00d-c2f8c3427eb6@redhat.com>
On Thu, Oct 21, 2021 at 8:04 AM Andrew MacLeod <amacleod@redhat.com> wrote:
>
> On 10/19/21 7:13 PM, Andrew Pinski wrote:
> > On Tue, Oct 19, 2021 at 3:32 PM Andrew MacLeod <amacleod@redhat.com> wrote:
> >> On 10/19/21 5:13 PM, Andrew Pinski wrote:
> >>> On Tue, Oct 19, 2021 at 1:29 PM Andrew MacLeod via Gcc-patches
> >>> <gcc-patches@gcc.gnu.org> wrote:
> >>>> using testcase ifcvt-4.c:
> >>>>
> >>>>
> >>>> typedef int word __attribute__((mode(word)));
> >>>>
> >>>> word
> >>>> foo (word x, word y, word a)
> >>>> {
> >>>> word i = x;
> >>>> word j = y;
> >>>> /* Try to make taking the branch likely. */
> >>>> __builtin_expect (x > y, 1);
> >>>> if (x > y)
> >>>> {
> >>>> i = a;
> >>>> j = i;
> >>>> }
> >>>> return i * j;
> >>>>
> >
> > The testcase is broken anyways.
> > The builtin_expect should be inside the if to have any effect. Look
> > at the estimated values:
> > if (x_3(D) > y_4(D))
> > goto <bb 4>; [50.00%] <<-- has been reversed.
> > else
> > goto <bb 3>; [50.00%]
> > ;; succ: 4 [50.0% (guessed)] count:536870912 (estimated
> > locally) (TRUE_VALUE,EXECUTABLE)
> > ;; 3 [50.0% (guessed)] count:536870912 (estimated
> > locally) (FALSE_VALUE,EXECUTABLE)
> >
> > See how it is 50/50?
> > The testcase is not even testing what it says it is testing. Just
> > happened to work previously does not mean anything. Move the
> > builtin_expect inside the if and try again. I am shocked it took this
> > long to find the testcase issue really.
> >
> > Thanks,
> > Andrew Pinski
> >
> Moving the expect around doesn't change anything, in fact, it makes it
> worse since fre and evrp immediately eliminate it as true if it is in
> the THEN block.
I think you misunderstood the change I was saying to do.
Try this:
typedef int word __attribute__((mode(word)));
word
foo (word x, word y, word a)
{
word i = x;
word j = y;
/* Try to make taking the branch likely. */
if (__builtin_expect (x > y, 1))
{
i = a;
j = i;
}
return i * j;
}
/* { dg-final { scan-rtl-dump "2 true changes made" "ce1" } } */
This should fix the "estimated values" to be more correct.
Thanks,
Andrew Pinski
>
> It looks like it is eliminated by the CDDCE pass:
>
> cddce1 sees:
>
> _1 = x_5(D) > y_7(D);
> # RANGE [0, 1] NONZERO 1
> _2 = (long int) _1;
> __builtin_expect (_2, 1);
> if (x_5(D) > y_7(D))
> goto <bb 3>; [INV]
> else
> goto <bb 4>; [INV]
>
> and proceeds:
>
> Marking useful stmt: if (x_5(D) > y_7(D))
> processing: if (x_5(D) > y_7(D))
> processing: i_3 = PHI <x_5(D)(2), a_9(D)(3)>
>
> Eliminating unnecessary statements:
> Deleting : __builtin_expect (_2, 1);
> Deleting : _2 = (long int) _1;
> Deleting : _1 = x_5(D) > y_7(D);
>
> IF we are suppose to reverse the If, it is not obvious to me who is
> suppose to.. You seem to be right that its a crap shot that VRP2 does
> it because there isnt enough info to dictate it.. unless somewhere it
> detects that a THEN targets an empty block which fallthrus to the ELSE
> block should be swapped. Or maybe you are right and that it flukeily
> happens due to the ASSERTS being added and removed.
>
> IF i turn of DCE, then this all works like it si ssupopse to.. so maybe
> DCE isnt supopse to remove this?
>
> Andrew
>
next prev parent reply other threads:[~2021-10-21 20:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-19 20:28 Andrew MacLeod
2021-10-19 21:13 ` Andrew Pinski
2021-10-19 22:32 ` Andrew MacLeod
2021-10-19 23:13 ` Andrew Pinski
2021-10-21 15:03 ` Andrew MacLeod
2021-10-21 19:59 ` Andrew Pinski [this message]
2021-10-25 15:43 ` 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='CA+=Sn1nWEytYBcBsyyzvdnWVNJVtr1Ub-Qrr666z7-MLrEL6Pg@mail.gmail.com' \
--to=pinskia@gmail.com \
--cc=aldyh@redhat.com \
--cc=amacleod@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jeffreyalaw@gmail.com \
--cc=richard.guenther@gmail.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).