From: Alan Modra <amodra@gmail.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: gcc-patches@sourceware.org, Alan Modra <amodra@gmail.com>
Subject: [RS6000] rs6000_rtx_costs reduce cost for SETs
Date: Tue, 15 Sep 2020 10:49:45 +0930 [thread overview]
Message-ID: <20200915011946.3395-8-amodra@gmail.com> (raw)
In-Reply-To: <20200915011946.3395-1-amodra@gmail.com>
Also use rs6000_cost only for speed.
* config/rs6000/rs6000.c (rs6000_rtx_costs): Reduce cost for SETs
when insn operation cost handled on recursive call. Only use
rs6000_cost for speed. Tidy break/return. Tidy AND costing.
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index fb5fe7969a3..86c90c4d756 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -21277,15 +21277,19 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
case PLUS:
case MINUS:
- if (FLOAT_MODE_P (mode))
+ if (speed && FLOAT_MODE_P (mode))
*total = rs6000_cost->fp;
else
*total = COSTS_N_INSNS (1);
return false;
case MULT:
- if (CONST_INT_P (XEXP (x, 1))
- && satisfies_constraint_I (XEXP (x, 1)))
+ if (!speed)
+ /* A little more than one insn so that nothing is tempted to
+ turn a shift left into a multiply. */
+ *total = COSTS_N_INSNS (1) + 1;
+ else if (CONST_INT_P (XEXP (x, 1))
+ && satisfies_constraint_I (XEXP (x, 1)))
{
if (INTVAL (XEXP (x, 1)) >= -256
&& INTVAL (XEXP (x, 1)) <= 255)
@@ -21304,18 +21308,22 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
return false;
case FMA:
- if (mode == SFmode)
+ if (!speed)
+ *total = COSTS_N_INSNS (1) + 1;
+ else if (mode == SFmode)
*total = rs6000_cost->fp;
else
*total = rs6000_cost->dmul;
- break;
+ return false;
case DIV:
case MOD:
if (FLOAT_MODE_P (mode))
{
- *total = mode == DFmode ? rs6000_cost->ddiv
- : rs6000_cost->sdiv;
+ if (!speed)
+ *total = COSTS_N_INSNS (1) + 2;
+ else
+ *total = mode == DFmode ? rs6000_cost->ddiv : rs6000_cost->sdiv;
return false;
}
/* FALLTHRU */
@@ -21334,7 +21342,9 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
}
else
{
- if (GET_MODE (XEXP (x, 1)) == DImode)
+ if (!speed)
+ *total = COSTS_N_INSNS (1) + 2;
+ else if (GET_MODE (XEXP (x, 1)) == DImode)
*total = rs6000_cost->divdi;
else
*total = rs6000_cost->divsi;
@@ -21368,6 +21378,7 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
return false;
case AND:
+ *total = COSTS_N_INSNS (1);
right = XEXP (x, 1);
if (CONST_INT_P (right))
{
@@ -21380,15 +21391,15 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
|| left_code == LSHIFTRT)
&& rs6000_is_valid_shift_mask (right, left, mode))
{
- *total = rtx_cost (XEXP (left, 0), mode, left_code, 0, speed);
- if (!CONST_INT_P (XEXP (left, 1)))
- *total += rtx_cost (XEXP (left, 1), SImode, left_code, 1, speed);
- *total += COSTS_N_INSNS (1);
+ rtx reg_op = XEXP (left, 0);
+ if (!REG_P (reg_op))
+ *total += rtx_cost (reg_op, mode, left_code, 0, speed);
+ reg_op = XEXP (left, 1);
+ if (!REG_P (reg_op) && !CONST_INT_P (reg_op))
+ *total += rtx_cost (reg_op, mode, left_code, 1, speed);
return true;
}
}
-
- *total = COSTS_N_INSNS (1);
return false;
case IOR:
@@ -21519,7 +21530,9 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
if (outer_code == TRUNCATE
&& GET_CODE (XEXP (x, 0)) == MULT)
{
- if (mode == DImode)
+ if (!speed)
+ *total = COSTS_N_INSNS (1) + 1;
+ else if (mode == DImode)
*total = rs6000_cost->muldi;
else
*total = rs6000_cost->mulsi;
@@ -21554,11 +21567,16 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
case FIX:
case UNSIGNED_FIX:
case FLOAT_TRUNCATE:
- *total = rs6000_cost->fp;
+ if (!speed)
+ *total = COSTS_N_INSNS (1);
+ else
+ *total = rs6000_cost->fp;
return false;
case FLOAT_EXTEND:
- if (mode == DFmode)
+ if (!speed)
+ *total = COSTS_N_INSNS (1);
+ else if (mode == DFmode)
*total = rs6000_cost->sfdf_convert;
else
*total = rs6000_cost->fp;
@@ -21576,7 +21594,7 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
*total = rs6000_cost->fp;
return false;
}
- break;
+ return false;
case NE:
case EQ:
@@ -21614,13 +21632,32 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int outer_code,
*total = 0;
return true;
}
- break;
+ return false;
+
+ case SET:
+ /* The default cost of a SET is the number of general purpose
+ regs being set multiplied by COSTS_N_INSNS (1). That only
+ works where the incremental cost of the operation and
+ operands is zero, when the operation performed can be done in
+ one instruction. For other cases where we add COSTS_N_INSNS
+ for some operation (see point 5 above), COSTS_N_INSNS (1)
+ should be subtracted from the total cost. */
+ {
+ 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;
+ return false;
}
-
- return false;
}
/* Debug form of r6000_rtx_costs that is selected if -mdebug=cost. */
next prev parent reply other threads:[~2020-09-15 1:20 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 ` Alan Modra [this message]
2020-09-17 17:51 ` [RS6000] rs6000_rtx_costs reduce cost for SETs Segher Boessenkool
2020-09-18 3:38 ` Alan Modra
2020-09-18 18:13 ` Segher Boessenkool
2020-09-21 7:07 ` Alan Modra
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=20200915011946.3395-8-amodra@gmail.com \
--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).