public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Bin.Cheng" <amker.cheng@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "bin.cheng" <bin.cheng@linux.alibaba.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH PR90078]Capping comp_cost computation in ivopts
Date: Wed, 17 Apr 2019 11:14:00 -0000	[thread overview]
Message-ID: <CAHFci29mpaQawLdZQ5sQp_oxvfkNHNN4BBtSuJdFL5T5SBHsfg@mail.gmail.com> (raw)
In-Reply-To: <20190417071001.GR21066@tucnak>

On Wed, Apr 17, 2019 at 3:10 PM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Wed, Apr 17, 2019 at 02:13:12PM +0800, bin.cheng wrote:
> > Hi,
> > As discussed in PR90078, this patch checks possible infinite_cost overflow in ivopts.
> > Also as discussed, overflow happens mostly because of cost scaling wrto bb_freq/loop_freq.
> > For the moment, we only implement capping in comp_cost operators, while in next
> > stage1, we may instead implement capping in get_scaled_computation_cost_at with
> > more supporting benchmark data.
> >
> > BTW, I think switching costs around comparison between infinite_cost is unnecessary
> > since there will be no overflow in integer after capping with infinite_cost.
> >
> > Bootstrap and test on x86_64, is it OK?
> >
> > Thanks,
> > bin
> >
> > 2019-04-17  Bin Cheng  <bin.cheng@linux.alibaba.com>
> >
> >         PR tree-optimization/92078
> >         * tree-ssa-loop-ivopts.c (comp_cost::operator +,-,+=,-+,/=,*=): Add
> >         checks for infinite_cost overflow.
> >
> > 2018-04-17  Bin Cheng  <bin.cheng@linux.alibaba.com>
> >
> >         PR tree-optimization/92078
> >         * gcc/testsuite/g++.dg/tree-ssa/pr90078.C: New test.
>
> --- a/gcc/tree-ssa-loop-ivopts.c
> +++ b/gcc/tree-ssa-loop-ivopts.c
> @@ -243,6 +243,9 @@ operator+ (comp_cost cost1, comp_cost cost2)
>    if (cost1.infinite_cost_p () || cost2.infinite_cost_p ())
>      return infinite_cost;
>
> +  if (cost1.cost + cost2.cost >= infinite_cost.cost)
> +    return infinite_cost;
>
> As
> #define INFTY 10000000
> what is the reason to keep the previous condition as well?
> I mean, if cost1.cost == INFTY or cost2.cost == INFTY,
> cost1.cost + cost2.cost >= INFTY too.
> Unless costs can go negative.
It's a bit complicated, but in general, costs can go negative.

>
> @@ -256,6 +259,8 @@ operator- (comp_cost cost1, comp_cost cost2)
>      return infinite_cost;
>
>    gcc_assert (!cost2.infinite_cost_p ());
> +  if (cost1.cost - cost2.cost >= infinite_cost.cost)
> +    return infinite_cost;
>
> Unless costs can be negative, when you first bail out
> for cost1.cost == INFTY, then cost1.cost - cost2.cost won't
> be INFTY (but could get negative).  So shouldn't there be a guard against
> that instead?  Or, if costs can be negative, shouldn't there be also
> guards that it doesn't grow too negative (say smaller than -INFTY)?
Negative cost is kind of a result of booking cost cancellation at
different place.  For example, it mostly comes from in modeling auto
increment/decrement addressing mode.  To be specific, when IV's
increment instruction can be merged into addressing mode, we cancel
cost of IV increment operation in cand-use cost.  Very likely 4 will
be subtracted.  In general, we wouldn't expect negative cost can go
too big, so there is no -INFTY logic in ivopts at all.  So this is the
least invasive fix for the moment, I would consider capping
bb_freq/loop_freq in the future which should rule out the overflow
possibility in the first place.

Thanks,
bin
>
>         Jakub

  reply	other threads:[~2019-04-17 11:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-17  7:00 bin.cheng
2019-04-17  7:19 ` Jakub Jelinek
2019-04-17 11:14   ` Bin.Cheng [this message]
2019-04-17 11:35     ` Jakub Jelinek
2019-05-05  6:02       ` bin.cheng
2019-05-06 10:11         ` Richard Biener
2019-05-06 10:24           ` Bin.Cheng
2019-05-06 10:27             ` 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=CAHFci29mpaQawLdZQ5sQp_oxvfkNHNN4BBtSuJdFL5T5SBHsfg@mail.gmail.com \
    --to=amker.cheng@gmail.com \
    --cc=bin.cheng@linux.alibaba.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@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).