From: James Greenhalgh <james.greenhalgh@arm.com>
To: Kyrill Tkachov <kyrylo.tkachov@arm.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Marcus Shawcroft <marcus.shawcroft@arm.com>,
Richard Earnshaw <Richard.Earnshaw@arm.com>
Subject: Re: [PATCH][AArch64] Properly cost zero_extend+ashift forms of ubfi[xz]
Date: Wed, 16 Dec 2015 14:59:00 -0000 [thread overview]
Message-ID: <20151216145928.GD10510@arm.com> (raw)
In-Reply-To: <56615D45.80408@arm.com>
On Fri, Dec 04, 2015 at 09:30:45AM +0000, Kyrill Tkachov wrote:
> Hi all,
>
> We don't handle properly the patterns for the [us]bfiz and [us]bfx instructions when they
> have an extend+ashift form. For example, the *<ANY_EXTEND:optab><GPI:mode>_ashl<SHORT:mode> pattern.
> This leads to rtx costs recuring into the extend and assigning a cost to these patterns that is too
> large.
>
> This patch fixes that oversight.
> I stumbled across this when working on a different combine patch and ended up matching the above
> pattern, only to have it rejected for -mcpu=cortex-a53 due to the erroneous cost.
>
> Bootstrapped and tested on aarch64.
>
> Ok for trunk?
>
> Thanks,
> Kyrill
>
> 2015-12-04 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
>
> * config/aarch64/aarch64.c (aarch64_extend_bitfield_pattern_p):
> New function.
> (aarch64_rtx_costs, ZERO_EXTEND, SIGN_EXTEND cases): Use the above
> to handle extend+shift rtxes.
> diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
> index c97ecdc0859e0a24792a57aeb18b2e4ea35918f4..d180f6f2d37a280ad77f34caad8496ddaa6e01b2 100644
> --- a/gcc/config/aarch64/aarch64.c
> +++ b/gcc/config/aarch64/aarch64.c
> @@ -5833,6 +5833,50 @@ aarch64_if_then_else_costs (rtx op0, rtx op1, rtx op2, int *cost, bool speed)
> return false;
> }
>
> +/* Check whether X is a bitfield operation of the form shift + extend that
> + maps down to a UBFIZ/SBFIZ/UBFX/SBFX instruction. If so, return the
> + operand to which the bitfield operation is applied to. Otherwise return
No need for that second "to" at the end of the sentence.
> + NULL_RTX. */
> +
> +static rtx
> +aarch64_extend_bitfield_pattern_p (rtx x)
> +{
> + rtx_code outer_code = GET_CODE (x);
> + machine_mode outer_mode = GET_MODE (x);
> +
> + if (outer_code != ZERO_EXTEND && outer_code != SIGN_EXTEND
> + && outer_mode != SImode && outer_mode != DImode)
> + return NULL_RTX;
> +
> + rtx inner = XEXP (x, 0);
> + rtx_code inner_code = GET_CODE (inner);
> + machine_mode inner_mode = GET_MODE (inner);
> + rtx op = NULL_RTX;
> +
> + switch (inner_code)
> + {
> + case ASHIFT:
> + if (CONST_INT_P (XEXP (inner, 1))
> + && (inner_mode == QImode || inner_mode == HImode))
> + op = XEXP (inner, 0);
> + break;
> + case LSHIFTRT:
> + if (outer_code == ZERO_EXTEND && CONST_INT_P (XEXP (inner, 1))
> + && (inner_mode == QImode || inner_mode == HImode))
> + op = XEXP (inner, 0);
> + break;
> + case ASHIFTRT:
> + if (outer_code == SIGN_EXTEND && CONST_INT_P (XEXP (inner, 1))
> + && (inner_mode == QImode || inner_mode == HImode))
> + op = XEXP (inner, 0);
> + break;
> + default:
> + break;
> + }
> +
> + return op;
> +}
> +
> /* Calculate the cost of calculating X, storing it in *COST. Result
> is true if the total cost of the operation has now been calculated. */
> static bool
> @@ -6521,6 +6565,14 @@ cost_plus:
> return true;
> }
>
> + op0 = aarch64_extend_bitfield_pattern_p (x);
> + if (op0)
> + {
> + *cost += rtx_cost (op0, mode, ZERO_EXTEND, 0, speed);
> + if (speed)
> + *cost += extra_cost->alu.bfx;
> + return true;
> + }
Newline here.
> if (speed)
> {
> if (VECTOR_MODE_P (mode))
> @@ -6552,6 +6604,14 @@ cost_plus:
> return true;
> }
>
> + op0 = aarch64_extend_bitfield_pattern_p (x);
> + if (op0)
> + {
> + *cost += rtx_cost (op0, mode, SIGN_EXTEND, 0, speed);
> + if (speed)
> + *cost += extra_cost->alu.bfx;
> + return true;
> + }
And here.
> if (speed)
> {
> if (VECTOR_MODE_P (mode))
OK with those changes.
Thanks,
James
prev parent reply other threads:[~2015-12-16 14:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-04 9:30 Kyrill Tkachov
2015-12-11 9:53 ` Kyrill Tkachov
2015-12-16 14:59 ` James Greenhalgh [this message]
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=20151216145928.GD10510@arm.com \
--to=james.greenhalgh@arm.com \
--cc=Richard.Earnshaw@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=kyrylo.tkachov@arm.com \
--cc=marcus.shawcroft@arm.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).