public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: gcc-patches@sourceware.org
Subject: Re: [RS6000] rs6000_rtx_costs reduce cost for SETs
Date: Mon, 21 Sep 2020 16:37:57 +0930	[thread overview]
Message-ID: <20200921070756.GX5452@bubble.grove.modra.org> (raw)
In-Reply-To: <20200918181318.GR28786@gate.crashing.org>

On Fri, Sep 18, 2020 at 01:13:18PM -0500, Segher Boessenkool wrote:
> Thanks (to both of you).  Interesting!  Which of these unrelated changes
> does this come from?

Most of the changes I saw in code generation (not in spec, I didn't
look there, but in gcc) came down to this change to the cost for SETs,
and "rs6000_rtx_costs multi-insn constants".  I expect they were the
changes that made most difference to spec results, with this patch
likely resulting in more if-conversion.

So here is the patch again, this time without any distracting other
changes.  With a further revised comment.

	* config/rs6000/rs6000.c (rs6000_rtx_costs): Reduce cost of SET
	operands.

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 8969baa4dcf..2d770afd8fe 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -21599,6 +21599,35 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
 	}
       break;
 
+    case SET:
+      /* On entry the value in *TOTAL is the number of general purpose
+	 regs being set, multiplied by COSTS_N_INSNS (1).  Handle
+	 costing of set operands specially since in most cases we have
+	 an instruction rather than just a piece of RTL and should
+	 return a cost comparable to insn_cost.  That's a little
+	 complicated because in some cases the cost of SET operands is
+	 non-zero, see point 5 above and cost of PLUS for example, and
+	 in others it is zero, for example for (set (reg) (reg)).
+	 But (set (reg) (reg)) has the same insn_cost as
+	 (set (reg) (plus (reg) (reg))).  Hack around this by
+	 subtracting COSTS_N_INSNS (1) from the operand cost in cases
+	 were we add at least COSTS_N_INSNS (1) for some operation.
+	 However, don't do so for constants.  Constants might cost
+	 more than zero when they require more than one instruction,
+	 and we do want the cost of extra instructions.  */
+      {
+	rtx_code src_code = GET_CODE (SET_SRC (x));
+	if (src_code == CONST_INT
+	    || src_code == CONST_DOUBLE
+	    || src_code == CONST_WIDE_INT)
+	  return false;
+	int set_cost = (rtx_cost (SET_SRC (x), mode, SET, 1, speed)
+			+ rtx_cost (SET_DEST (x), mode, SET, 0, speed));
+	if (set_cost >= COSTS_N_INSNS (1))
+	  *total += set_cost - COSTS_N_INSNS (1);
+	return true;
+      }
+
     default:
       break;
     }

-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2020-09-21  7:08 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-15  1:19 [RS6000] rtx_costs Alan Modra
2020-09-15  1:19 ` [RS6000] Count rldimi constant insns Alan Modra
2020-09-15 22:29   ` Segher Boessenkool
2020-09-15  1:19 ` [RS6000] rs6000_rtx_costs for PLUS/MINUS constant Alan Modra
2020-09-15 22:31   ` Segher Boessenkool
2020-09-15  1:19 ` [RS6000] rs6000_rtx_costs for AND Alan Modra
2020-09-15 18:15   ` will schmidt
2020-09-16  7:24     ` Alan Modra
2020-09-15  1:19 ` [RS6000] rs6000_rtx_costs comment Alan Modra
2020-09-16 23:21   ` Segher Boessenkool
2020-09-15  1:19 ` [RS6000] rs6000_rtx_costs multi-insn constants Alan Modra
2020-09-16 23:28   ` Segher Boessenkool
2020-09-15  1:19 ` [RS6000] rs6000_rtx_costs cost IOR Alan Modra
2020-09-17  0:02   ` Segher Boessenkool
2020-09-17  3:42     ` Alan Modra
2020-09-21 15:49       ` Segher Boessenkool
2020-09-21 23:54         ` Alan Modra
2020-09-15  1:19 ` [RS6000] rs6000_rtx_costs reduce cost for SETs Alan Modra
2020-09-17 17:51   ` Segher Boessenkool
2020-09-18  3:38     ` Alan Modra
2020-09-18 18:13       ` Segher Boessenkool
2020-09-21  7:07         ` Alan Modra [this message]
2020-09-15  1:19 ` [RS6000] rotate and mask constants Alan Modra
2020-09-15  7:16   ` Alan Modra
2020-09-21 15:56     ` Segher Boessenkool
2020-09-15 18:15 ` [RS6000] rtx_costs will schmidt

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=20200921070756.GX5452@bubble.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=gcc-patches@sourceware.org \
    --cc=segher@kernel.crashing.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).