public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hans-Peter Nilsson <hans-peter.nilsson@axis.com>
To: rdsandiford@googlemail.com
Cc: iant@google.com, zadeck@naturalbridge.com,
	gcc-patches@gcc.gnu.org,   mikestump@comcast.net,
	Kenneth.Zadeck@naturalbridge.com, avr@gjlay.de,
	  ramana.radhakrishnan@linaro.org
Subject: Fix gcc.dg/lower-subreg-1.c failure (was: [C Patch]: pr52543)
Date: Wed, 09 May 2012 06:02:00 -0000	[thread overview]
Message-ID: <201205090602.q4962Pli001609@ignucius.se.axis.com> (raw)
In-Reply-To: <g4lilcez75.fsf@richards-thinkpad.stglab.manchester.uk.ibm.com>	(message from Richard Sandiford on Tue, 1 May 2012 16:46:38 +0200)

> From: Richard Sandiford <rdsandiford@googlemail.com>
> Date: Tue, 1 May 2012 16:46:38 +0200

> To repeat: as things stand, very few targets define proper rtx costs
> for SET.

IMHO it's wrong to start blaming targets when rtx_cost doesn't
take the mode in account in the first place, for the default
cost.  (Well, except for the modes-tieable subreg special-case.)
The targets where an operation in N * word_mode costs no more
than one in word_mode, if there even is one, is a minority,
let's adjust the defaults to that.

>  This patch is therefore expected to prevent lower-subreg
> from running in cases where it's actually benefical.  If you see that
> happening, please check whether the rtx_costs are defined properly.

Well, for CRIS (one of the targets of the PR53176 fallout) they
are sane, basically.  Where cris_rtx_costs returns true, it
returns mostly(*) ballparkly-correct costs *where it's passed an
rtx for which there's a corresponding insn*, otherwise falling
back to the defaults.  It shouldn't have to check for validity
of the rtx asked about; core GCC already knows which insns there
are and can gate that in rtx_cost or its callers.

(*) I see a bug in that cris_rtx_costs doesn't check the mode
for extendsidi2, to return COSTS_N_INSNS (3) instead of 0
(because a sign-extending move to SImode doesn't cost more than
a move; a sign- or zero-extension is also free in an operand for
addition and multiplication).  But this isn't on the path that
lower-subreg.c takes, so only an incidental observation...

> Of course, if the costs are defined properly and lower-subreg still
> makes the wrong choice, we need to look at why.

By the way, regarding validity of rtx_cost calls:

> +++ gcc/lower-subreg.c  2012-05-01 09:46:48.473830772 +0100

> +/* Return the cost of a CODE shift in mode MODE by OP1 bits, using the
> +   rtxes in RTXES.  SPEED_P selects between the speed and size cost.  */
> +
> +static int
> +shift_cost (bool speed_p, struct cost_rtxes *rtxes, enum rtx_code code,
> +           enum machine_mode mode, int op1)
> +{
> +  PUT_MODE (rtxes->target, mode);
> +  PUT_CODE (rtxes->shift, code);
> +  PUT_MODE (rtxes->shift, mode);
> +  PUT_MODE (rtxes->source, mode);
> +  XEXP (rtxes->shift, 1) = GEN_INT (op1);
> +  SET_SRC (rtxes->set) = rtxes->shift;
> +  return insn_rtx_cost (rtxes->set, speed_p);
> +}
> +
> +/* For each X in the range [0, BITS_PER_WORD), set SPLITTING[X]
> +   to true if it is profitable to split a double-word CODE shift
> +   of X + BITS_PER_WORD bits.  SPEED_P says whether we are testing
> +   for speed or size profitability.
> +
> +   Use the rtxes in RTXES to calculate costs.  WORD_MOVE_ZERO_COST is
> +   the cost of moving zero into a word-mode register.  WORD_MOVE_COST
> +   is the cost of moving between word registers.  */
> +
> +static void
> +compute_splitting_shift (bool speed_p, struct cost_rtxes *rtxes,
> +                        bool *splitting, enum rtx_code code,
> +                        int word_move_zero_cost, int word_move_cost)
> +{

I think there should be a gating check whether the target
implements that kind of shift in that mode at all, before
checking the cost.  Not sure whether it's generally best to put
that test here, or to make the rtx_cost function return the cost
of a libcall for that mode when that happens.  Similar for the
other insns.

Isn't the below better than doing virtually the same in each
target's rtx_costs?  Not tested yet besides "make cc1" and
checking that lower-subreg.c yields sane costs and that
gcc.dg/lower-subreg-1.c passes for cris-elf.  Note that
untieable SUBREGs still get a higher cost than tieable ones.

I'll test this for cris-elf, please tell me if/what other tests
and targets are required (simulator or compilefarm targets only,
please).

	* rtlanal.c (rtx_cost): Adjust default cost for X with a
	UNITS_PER_WORD factor for all X according to the size of
	its mode, not just for SUBREGs with untieable modes.

Index: gcc/rtlanal.c
===================================================================
--- gcc/rtlanal.c	(revision 187308)
+++ gcc/rtlanal.c	(working copy)
@@ -3755,10 +3755,17 @@ rtx_cost (rtx x, enum rtx_code outer_cod
   enum rtx_code code;
   const char *fmt;
   int total;
+  int factor;
 
   if (x == 0)
     return 0;
 
+  /* A size N times larger than UNITS_PER_WORD likely needs N times as
+     many insns, taking N times as long.  */
+  factor = GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD;
+  if (factor == 0)
+    factor = 1;
+
   /* Compute the default costs of certain things.
      Note that targetm.rtx_costs can override the defaults.  */
 
@@ -3766,20 +3773,27 @@ rtx_cost (rtx x, enum rtx_code outer_cod
   switch (code)
     {
     case MULT:
-      total = COSTS_N_INSNS (5);
+      total = factor * COSTS_N_INSNS (5);
       break;
     case DIV:
     case UDIV:
     case MOD:
     case UMOD:
-      total = COSTS_N_INSNS (7);
+      total = factor * COSTS_N_INSNS (7);
       break;
     case USE:
       /* Used in combine.c as a marker.  */
       total = 0;
       break;
+    case SET:
+      /* A SET doesn't have a mode, so let's look at the SET_DEST to get
+	 the mode for the factor.  */
+      factor = GET_MODE_SIZE (GET_MODE (SET_DEST (x))) / UNITS_PER_WORD;
+      if (factor == 0)
+	factor = 1;
+      /* Pass through.  */
     default:
-      total = COSTS_N_INSNS (1);
+      total = factor * COSTS_N_INSNS (1);
     }
 
   switch (code)
@@ -3792,8 +3806,7 @@ rtx_cost (rtx x, enum rtx_code outer_cod
       /* If we can't tie these modes, make this expensive.  The larger
 	 the mode, the more expensive it is.  */
       if (! MODES_TIEABLE_P (GET_MODE (x), GET_MODE (SUBREG_REG (x))))
-	return COSTS_N_INSNS (2
-			      + GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD);
+	return COSTS_N_INSNS (2 + factor);
       break;
 
     default:

brgds, H-P

  parent reply	other threads:[~2012-05-09  6:02 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4F67D595.9030700@naturalbridge.com>
     [not found] ` <mcrd387n9bf.fsf@dhcp-172-18-216-180.mtv.corp.google.com>
     [not found]   ` <4F6881EA.9080306@naturalbridge.com>
     [not found]     ` <mcrvclzl7b7.fsf@dhcp-172-18-216-180.mtv.corp.google.com>
     [not found]       ` <4F6889CC.8080302@naturalbridge.com>
     [not found]         ` <mcrr4wnl6lb.fsf@dhcp-172-18-216-180.mtv.corp.google.com>
2012-03-29 21:10           ` [C Patch]: pr52543 Kenneth Zadeck
2012-03-30  8:34             ` Ramana Radhakrishnan
2012-03-30 10:09             ` Richard Sandiford
2012-03-30 15:25               ` Kenneth Zadeck
2012-03-30 15:41                 ` Richard Sandiford
2012-03-31 16:21                   ` Kenneth Zadeck
2012-04-03 13:53                     ` Richard Sandiford
2012-04-03 15:33                       ` Kenneth Zadeck
2012-04-03 19:20                         ` Richard Sandiford
2012-04-03 20:36                           ` Ian Lance Taylor
2012-05-01 14:47                             ` Richard Sandiford
2012-05-01 17:51                               ` H.J. Lu
2012-05-03 19:52                               ` Georg-Johann Lay
2012-05-03 22:14                                 ` Mike Stump
2012-05-04 23:02                                   ` Georg-Johann Lay
2012-05-06 18:55                                     ` [committed] Fix lower-subreg cost calculation Richard Sandiford
2012-05-08 15:26                                       ` Richard Earnshaw
2012-05-08 21:42                                         ` Richard Sandiford
2012-05-09  9:48                                           ` Richard Earnshaw
2012-05-07 19:01                                     ` [C Patch]: pr52543 Mike Stump
2012-05-09  6:02                               ` Hans-Peter Nilsson [this message]
2012-05-09  9:15                                 ` Fix gcc.dg/lower-subreg-1.c failure Richard Sandiford
2012-05-09 16:37                                   ` Hans-Peter Nilsson
2012-07-07 23:03                                   ` Fix gcc.dg/lower-subreg-1.c failure, revisited Hans-Peter Nilsson
2012-07-08 12:14                                     ` Richard Sandiford
2012-07-12 21:14                                     ` Hans-Peter Nilsson
2012-05-16  6:25                                 ` ping: Fix gcc.dg/lower-subreg-1.c failure (was: [C Patch]: pr52543) Hans-Peter Nilsson
2012-05-23  4:42                                   ` ping*2: " Hans-Peter Nilsson
2012-05-30  2:49                                     ` ping*3: " Hans-Peter Nilsson
2012-06-07  5:39                                       ` ping*4: " Hans-Peter Nilsson
2012-04-03 16:22                       ` [C Patch]: pr52543 Ian Lance Taylor
2012-05-10  6:45               ` Paolo Bonzini
2012-05-10  6:54                 ` Paolo Bonzini
     [not found]             ` <CACUk7=XVO=yHrPBFtAVfPxMtViYthtGGfuQSVGHNqHE7ibER0g@mail.gmail.com>
2012-03-30 19:29               ` Kenneth Zadeck
2012-03-30 22:38                 ` Ramana Radhakrishnan

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=201205090602.q4962Pli001609@ignucius.se.axis.com \
    --to=hans-peter.nilsson@axis.com \
    --cc=Kenneth.Zadeck@naturalbridge.com \
    --cc=avr@gjlay.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=iant@google.com \
    --cc=mikestump@comcast.net \
    --cc=ramana.radhakrishnan@linaro.org \
    --cc=rdsandiford@googlemail.com \
    --cc=zadeck@naturalbridge.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).