public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: James Greenhalgh <james.greenhalgh@arm.com>
To: Ramana Radhakrishnan <ramana.radhakrishnan@foss.arm.com>
Cc: Bernd Schmidt <bernds_cb1@t-online.de>, Jeff Law <law@redhat.com>,
	       "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	       "ebotcazou@libertysurf.fr" <ebotcazou@libertysurf.fr>,
	       "steven@gcc.gnu.org" <steven@gcc.gnu.org>
Subject: Re: [Patch] Teach RTL ifcvt to handle multiple simple set instructions
Date: Fri, 11 Sep 2015 10:55:00 -0000	[thread overview]
Message-ID: <20150911095608.GA2448@arm.com> (raw)
In-Reply-To: <20150911090412.GB31587@e105545-lin>

On Fri, Sep 11, 2015 at 10:04:12AM +0100, Ramana Radhakrishnan wrote:
> On Fri, Sep 11, 2015 at 10:53:13AM +0200, Bernd Schmidt wrote:
> > On 09/10/2015 11:11 PM, Jeff Law wrote:
> > >I think that's probably what James is most interested in getting some
> > >ideas around -- the cost model.
> > >
> > >I think the fundamental problem is BRANCH_COST isn't actually relative
> > >to anything other than the default value of "1".  It doesn't directly
> > >correspond to COSTS_N_INSNS or anything else.  So while using
> > >COSTS_N_INSNS (BRANCH_COST)) would seem to make sense, it actually
> > >doesn't.  It's not even clear how a value of 10 relates to a value of 1
> > >other than it's more expensive.
> > >
> > >ifcvt (and others) comparing to magic #s is more than a bit lame.  But
> > >with BRANCH_COST having no meaning relative to anything else I can see
> > >why Richard did things that way.
> > >
> > >In an ideal world we'd find some mapping from BRANCH_COST that relates
> > >to CONST_N_INSNS.  I suspect a simple mapping doesn't necessarily exist
> > >and we'll likely regress targets with any simplistic mapping.  But maybe
> > >now is the time to address that fundamental problem and deal with the
> > >fallout.
> > 
> > I think the right approach if we want to fix this is a new
> > branch_cost_ninsns target hook (maybe with arguments
> > taken_percentage, predictability), and gradually move everything to
> > use that instead of BRANCH_COST.
> 
> Perhaps providing backends with the entire if-then-else block along
> with the above mentioned information being if converted may be another
> approach, it allows the backends to analyse what cases are good to
> if-convert as per the ISA or micro-architecture and what aren't.

I'm not sure how much of this is likely to be target-dependent and how
much can just be abstracted to common ifcvt code resuing rtx_costs.

I've been sketching out a rough idea of a more applicable cost model for
RTL ifcvt, taking in to consideration what David mentioned regarding the
talks at cauldron. The question we want to ask is:

Which is preferable between:

  Before:
   (COSTS_N_INSNS cost of the compare+branch insns at the tail of the if BB.
     ??? (possibly) some factor related to BRANCH_COST)
   + weighted cost of then BB.
   + (if needed) weighted cost of else BB.

  After:
   seq_cost the candidate new sequence.
  
The weighted cost of the two BBs should mix in some idea as to the relative
probability that we execute them.

The tough part is figuring out how to (reasonably) factor in branch cost.
The reason that is tough is that BRANCH_COST is used inconsistently. Normally
it is not measured relative to anything, but is compared against magic numbers
for optimizations (each of which are really their own question to be posed
as above).

I don't have a good answer to that, nor a good answer as to what BRANCH_COST
should represent in future. The use in the compiler is sort-of consistent
with a measurement against instruction counts (i.e. a branch cost of 3 means
a branch is equivalent to 3 cheap instructions), but is sometimes just used
as a measure of expensive (a branch cost of >= 2 means that abs should be
expanded using a sequence of bit operations).

I'll look in to how the code in ifcvt starts to look with a modified cost
model and get back to you...

James

  reply	other threads:[~2015-09-11  9:56 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-08 15:01 James Greenhalgh
2015-09-10 18:24 ` Bernd Schmidt
2015-09-10 21:34   ` Jeff Law
2015-09-11  8:51     ` Kyrill Tkachov
2015-09-11 21:49       ` Jeff Law
2015-09-11  9:04     ` Bernd Schmidt
2015-09-11  9:08       ` Ramana Radhakrishnan
2015-09-11 10:55         ` James Greenhalgh [this message]
2015-09-25 15:06           ` [Patch ifcvt costs 0/3] Introduce a new target hook for ifcvt costs James Greenhalgh
2015-09-25 15:06             ` [Patch ifcvt 1/3] Factor out cost calculations from noce cases James Greenhalgh
2015-09-25 15:08             ` [Patch ifcvt 2/3] Move noce_if_info in to ifcvt.h James Greenhalgh
2015-09-25 15:14             ` [Patch Prototype AArch64 ifcvt 4/3] Wire up the new if-convert costs hook for AArch64 James Greenhalgh
2015-09-29 10:43               ` Richard Biener
2015-09-25 15:28             ` [Patch ifcvt 3/3] Create a new target hook for deciding profitability of noce if-conversion James Greenhalgh
2015-09-29 10:36             ` [Patch ifcvt costs 0/3] Introduce a new target hook for ifcvt costs Richard Biener
2015-09-29 15:28               ` James Greenhalgh
2015-09-29 19:52                 ` Mike Stump
2015-09-30  8:42                   ` Richard Biener
2015-09-30  8:48                 ` Richard Biener
2015-09-30 19:01                   ` Mike Stump
2015-10-01  9:37                 ` Bernd Schmidt
2015-10-09 11:28                   ` Bernd Schmidt
2015-10-09 15:28                     ` Jeff Law
2016-06-02 16:54                     ` [RFC: Patch 0/6] Rewrite the noce-ifcvt cost models James Greenhalgh
2016-06-02 16:54                       ` [RFC: Patch 4/6] Modify cost model for noce_cmove_arith James Greenhalgh
2016-06-02 16:54                       ` [RFC: Patch 1/6] New target hook: rtx_branch_cost James Greenhalgh
2016-06-03 10:39                         ` Richard Biener
2016-06-21 15:51                           ` [RFC: Patch 1/6 v2] New target hook: max_noce_ifcvt_seq_cost James Greenhalgh
2016-06-21 15:51                             ` [RFC: Patch 5/6 v2] Improve the cost model for multiple-sets James Greenhalgh
2016-07-13 21:23                               ` Jeff Law
2016-06-21 15:51                             ` [RFC: Patch 3/6 v2] Remove if_info->branch_cost James Greenhalgh
2016-07-13 21:19                               ` Jeff Law
2016-06-21 15:51                             ` [RFC: Patch 2/6 v2] Factor out the comparisons against magic numbers in ifcvt James Greenhalgh
2016-07-13 21:18                               ` Jeff Law
2016-06-21 15:53                             ` [RFC: Patch 4/6 v2] Modify cost model for noce_cmove_arith James Greenhalgh
2016-07-13 21:22                               ` Jeff Law
2016-06-21 15:53                             ` [RFC: Patch 6/6 v2] Remove second cost model from noce_try_store_flag_mask James Greenhalgh
2016-07-13 21:24                               ` Jeff Law
2016-06-21 21:31                             ` [RFC: Patch 1/6 v2] New target hook: max_noce_ifcvt_seq_cost Bernhard Reutner-Fischer
2016-06-30 12:01                             ` Bernd Schmidt
2016-07-13 21:16                             ` Jeff Law
2016-07-20  9:52                               ` [Re: RFC: Patch 1/2 v3] " James Greenhalgh
2016-07-20  9:52                                 ` [Patch RFC: 3/2 v3] Don't expand a conditional move between identical sources James Greenhalgh
2016-07-20  9:53                                 ` [Patch RFC 4/2 v3] Refactor noce_try_cmove_arith James Greenhalgh
2016-07-20  9:53                                 ` [RFC: Patch 2/2 v3] Introduce a new cost model for ifcvt James Greenhalgh
2016-07-20 11:41                                 ` [Re: RFC: Patch 1/2 v3] New target hook: max_noce_ifcvt_seq_cost Bernd Schmidt
2016-07-20 16:40                                   ` James Greenhalgh
2016-07-21 11:32                                     ` Bernd Schmidt
2016-06-02 16:55                       ` [RFC: Patch 2/6] Factor out the comparisons against magic numbers in ifcvt James Greenhalgh
2016-06-02 16:55                       ` [RFC: Patch 5/6] Improve the cost model for multiple-sets James Greenhalgh
2016-06-02 16:56                       ` [RFC: Patch 6/6] Remove second cost model from noce_try_store_flag_mask James Greenhalgh
2016-06-02 16:56                       ` [RFC: Patch 3/6] Remove if_info->branch_cost James Greenhalgh
2016-06-03  9:32                       ` [RFC: Patch 0/6] Rewrite the noce-ifcvt cost models Bernd Schmidt
2016-06-09 16:58                       ` Jeff Law
2016-06-10 10:45                         ` James Greenhalgh
2015-09-12 14:04     ` [Patch] Teach RTL ifcvt to handle multiple simple set instructions Eric Botcazou
2015-10-30 18:09   ` [Patch ifcvt] " James Greenhalgh
2015-11-04 11:04     ` Bernd Schmidt
2015-11-04 15:37       ` James Greenhalgh
2015-11-06  9:13         ` Christophe Lyon

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=20150911095608.GA2448@arm.com \
    --to=james.greenhalgh@arm.com \
    --cc=bernds_cb1@t-online.de \
    --cc=ebotcazou@libertysurf.fr \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=ramana.radhakrishnan@foss.arm.com \
    --cc=steven@gcc.gnu.org \
    /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).