From: Richard Sandiford <richard.sandiford@arm.com>
To: Richard Henderson <rth@redhat.com>
Cc: "gcc-patches\@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
Andreas Krebbel <krebbel@linux.vnet.ibm.com>
Subject: Re: RFA: Fix mode checks for possibly-constant predicates
Date: Wed, 03 Jun 2015 07:23:00 -0000 [thread overview]
Message-ID: <87sia971bv.fsf@e105548-lin.cambridge.arm.com> (raw)
In-Reply-To: <5568A761.20705@redhat.com> (Richard Henderson's message of "Fri, 29 May 2015 18:52:33 +0100")
Richard Henderson <rth@redhat.com> writes:
> On 05/29/2015 10:23 AM, Richard Sandiford wrote:
>> + /* Check whether the predicate accepts const scalar ints (which always
>> + have a stored mode of VOIDmode, but logically have a real mode)
>> + and whether it matches anything besides const scalar ints. */
>> + bool matches_const_scalar_int_p = false;
>> + bool matches_other_p = false;
>> + for (int i = 0; i < NUM_RTX_CODE; ++i)
>> + if (p->codes[i])
>> + switch (i)
>> + {
>> + CASE_CONST_SCALAR_INT:
>> + matches_const_scalar_int_p = true;
>> + break;
>> +
>> + default:
>> + matches_other_p = true;
>> + break;
>> + }
>> +
>> + /* There's no need for a mode check if the predicate only accepts
>> + constant integers. The code checks in the predicate are enough
>> + to establish that the mode is VOIDmode.
>> +
>> + Note that the predicate itself should check whether a scalar
>> + integer is in range of the given mode. */
>> + if (!matches_other_p && !p->codes[CONST_DOUBLE])
>> + return;
>
> I think perhaps it would be cleaner to not use CASE_CONST_SCALAR_INT,
> and then do
>
> switch (i)
> {
> case CONST_INT:
> case CONST_WIDE_INT:
> matches_const_scalar_int_p = true;
> break;
>
> case CONST_DOUBLE:
> if (!TARGET_SUPPORTS_WIDE_INT)
> matches_const_scalar_int_p = true;
> matches_other_p = true;
> break;
>
> default:
> matches_other_p = true;
> break;
> }
>
> if (!matches_other_p)
> return;
>
> Otherwise ok.
Ah, yeah, that's better. Here's what I applied after testing on
x86_64-linux-gnu.
Thanks,
Richard
gcc/
* genpreds.c (mark_mode_tests): Mark all MATCH_CODEs as
NO_MODE_TEST.
(add_mode_tests): Don't add mode tests if the predicate only
accepts scalar constant integers. Otherwise, allow the mode
of "op" to be VOIDmode if the predicate does accept such integers.
Index: gcc/genpreds.c
===================================================================
--- gcc/genpreds.c 2015-06-02 13:32:21.394938060 +0100
+++ gcc/genpreds.c 2015-06-02 13:34:50.377221396 +0100
@@ -218,11 +218,11 @@ needs_variable (rtx exp, const char *var
/* Given an RTL expression EXP, find all subexpressions which we may
assume to perform mode tests. Normal MATCH_OPERAND does;
- MATCH_CODE does if it applies to the whole expression and accepts
- CONST_INT or CONST_DOUBLE; and we have to assume that MATCH_TEST
- does not. These combine in almost-boolean fashion - the only
- exception is that (not X) must be assumed not to perform a mode
- test, whether or not X does.
+ MATCH_CODE doesn't as such (although certain codes always have
+ VOIDmode); and we have to assume that MATCH_TEST does not.
+ These combine in almost-boolean fashion - the only exception is
+ that (not X) must be assumed not to perform a mode test, whether
+ or not X does.
The mark is the RTL /v flag, which is true for subexpressions which
do *not* perform mode tests.
@@ -244,10 +244,7 @@ mark_mode_tests (rtx exp)
break;
case MATCH_CODE:
- if (XSTR (exp, 1)[0] != '\0'
- || (!strstr (XSTR (exp, 0), "const_int")
- && !strstr (XSTR (exp, 0), "const_double")))
- NO_MODE_TEST (exp) = 1;
+ NO_MODE_TEST (exp) = 1;
break;
case MATCH_TEST:
@@ -313,6 +310,40 @@ add_mode_tests (struct pred_data *p)
if (p->special)
return;
+ /* Check whether the predicate accepts const scalar ints (which always
+ have a stored mode of VOIDmode, but logically have a real mode)
+ and whether it matches anything besides const scalar ints. */
+ bool matches_const_scalar_int_p = false;
+ bool matches_other_p = false;
+ for (int i = 0; i < NUM_RTX_CODE; ++i)
+ if (p->codes[i])
+ switch (i)
+ {
+ case CONST_INT:
+ case CONST_WIDE_INT:
+ matches_const_scalar_int_p = true;
+ break;
+
+ case CONST_DOUBLE:
+ if (!TARGET_SUPPORTS_WIDE_INT)
+ matches_const_scalar_int_p = true;
+ matches_other_p = true;
+ break;
+
+ default:
+ matches_other_p = true;
+ break;
+ }
+
+ /* There's no need for a mode check if the predicate only accepts
+ constant integers. The code checks in the predicate are enough
+ to establish that the mode is VOIDmode.
+
+ Note that the predicate itself should check whether a scalar
+ integer is in range of the given mode. */
+ if (!matches_other_p)
+ return;
+
mark_mode_tests (p->exp);
/* If the whole expression already tests the mode, we're done. */
@@ -320,7 +351,11 @@ add_mode_tests (struct pred_data *p)
return;
match_test_exp = rtx_alloc (MATCH_TEST);
- XSTR (match_test_exp, 0) = "mode == VOIDmode || GET_MODE (op) == mode";
+ if (matches_const_scalar_int_p)
+ XSTR (match_test_exp, 0) = ("mode == VOIDmode || GET_MODE (op) == mode"
+ " || GET_MODE (op) == VOIDmode");
+ else
+ XSTR (match_test_exp, 0) = "mode == VOIDmode || GET_MODE (op) == mode";
and_exp = rtx_alloc (AND);
XEXP (and_exp, 1) = match_test_exp;
next prev parent reply other threads:[~2015-06-03 6:28 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-27 10:20 Mostly rewrite genrecog Richard Sandiford
2015-04-28 23:18 ` Jeff Law
2015-04-29 13:59 ` Richard Sandiford
2015-04-29 8:52 ` Eric Botcazou
2015-04-29 13:51 ` Richard Sandiford
2015-04-30 10:44 ` Eric Botcazou
2015-04-30 6:54 ` Bin.Cheng
2015-04-30 11:58 ` Richard Sandiford
2015-04-30 7:17 ` Andreas Schwab
2015-04-30 7:58 ` Richard Sandiford
2015-04-30 12:10 ` Andreas Schwab
2015-04-30 12:33 ` Richard Biener
2015-04-30 16:27 ` Richard Sandiford
2015-05-01 12:42 ` Richard Sandiford
2015-05-01 13:57 ` Jeff Law
2015-05-07 8:59 ` [nvptx] " Thomas Schwinge
2015-05-07 9:14 ` Jakub Jelinek
2015-05-21 8:09 ` Thomas Schwinge
2015-05-21 11:57 ` Bernd Schmidt
2015-05-08 9:10 ` genrecog: Address -Wsign-compare diagnostics (was: Mostly rewrite genrecog) Thomas Schwinge
2015-05-08 14:43 ` genrecog: Address -Wsign-compare diagnostics Richard Sandiford
2015-05-08 18:39 ` Jeff Law
2015-05-16 8:13 ` Mostly rewrite genrecog Andreas Krebbel
2015-05-17 22:05 ` Richard Sandiford
2015-05-22 16:14 ` Andreas Krebbel
2015-05-22 16:32 ` Richard Sandiford
2015-05-29 17:39 ` RFA: Fix mode checks for possibly-constant predicates Richard Sandiford
2015-05-29 19:27 ` Richard Henderson
2015-06-03 7:23 ` Richard Sandiford [this message]
2015-06-03 9:39 ` Richard Sandiford
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=87sia971bv.fsf@e105548-lin.cambridge.arm.com \
--to=richard.sandiford@arm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=krebbel@linux.vnet.ibm.com \
--cc=rth@redhat.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).