From: Richard Sandiford <richard.sandiford@arm.com>
To: Eric Botcazou <ebotcazou@adacore.com>
Cc: <gcc-patches@gcc.gnu.org>
Subject: Re: [1/2] PR88598: Optimise x * { 0 or 1, 0 or 1, ... }
Date: Fri, 04 Jan 2019 12:13:00 -0000 [thread overview]
Message-ID: <87o98wpqna.fsf@arm.com> (raw)
In-Reply-To: <1848503.BfMgXAnLGD@polaris> (Eric Botcazou's message of "Fri, 4 Jan 2019 13:04:27 +0100")
Eric Botcazou <ebotcazou@adacore.com> writes:
>> Index: gcc/tree.c
>> ===================================================================
>> --- gcc/tree.c 2019-01-04 11:39:24.810266962 +0000
>> +++ gcc/tree.c 2019-01-04 11:40:33.141683783 +0000
>> @@ -11229,6 +11229,60 @@ initializer_zerop (const_tree init, bool
>> }
>> }
>>
>> +/* Return true if EXPR is an initializer expression that consists only
>> + of INTEGER_CSTs for which IP0 or IP1 holds and REAL_CSTs for which
>> + RP0 or RP1 holds. The choice between IP0 and IP1, and between
>> + RP0 and RP1, can vary from one element to the next. */
>> +
>> +template<bool (*IP0) (const_tree), bool (*IP1) (const_tree),
>> + bool (*RP0) (const_tree), bool (*RP1) (const_tree)>
>> +bool
>> +initializer_each_a_or_bp (const_tree expr)
>> +{
>> +#define RECURSE(X) initializer_each_a_or_bp<IP0, IP1, RP0, RP1> (X)
>> +
>> + STRIP_ANY_LOCATION_WRAPPER (expr);
>> +
>> + switch (TREE_CODE (expr))
>> + {
>> + case INTEGER_CST:
>> + return IP0 (expr) || IP1 (expr);
>> +
>> + case REAL_CST:
>> + return RP0 (expr) || RP1 (expr);
>> +
>> + case VECTOR_CST:
>> + {
>> + unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (expr);
>> + if (VECTOR_CST_STEPPED_P (expr)
>> + && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (expr)).is_constant (&nelts))
>> + return false;
>> +
>> + for (unsigned int i = 0; i < nelts; ++i)
>> + if (!RECURSE (VECTOR_CST_ENCODED_ELT (expr, i)))
>> + return false;
>> +
>> + return true;
>> + }
>> +
>> + default:
>> + return false;
>> + }
>> +
>> +#undef RECURSE
>
> Can we avoid the gratuitous use of template here? We were told that C++ would
> be used only when it makes things more straightforward and it's the contrary
> in this case, to wit the need for the ugly RECURSE macro in the middle.
I did it that way so that it would be easy to add things like
zero_or_minus_onep without cut-&-pasting the whole structure.
The way to do that in C would be to use a macro for the full
function, but that's even uglier due to the extra backslashes.
I can change it to:
for (unsigned int i = 0; i < nelts; ++i)
{
tree elt = VECTOR_CST_ENCODED_ELT (expr, i);
if (!initializer_each_a_or_bp<IP0, IP1, RP0, RP1> (elt))
return false;
}
if we want to avoid macros.
I was actually worried that this wouldn't be C++ enough, due to not
using a function template to combine each pair of functions. :-)
Richard
next prev parent reply other threads:[~2019-01-04 12:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-04 11:43 Richard Sandiford
2019-01-04 12:04 ` Eric Botcazou
2019-01-04 12:13 ` Richard Sandiford [this message]
2019-01-04 12:19 ` Jakub Jelinek
2019-01-04 12:44 ` Richard Sandiford
2019-01-07 11:35 ` Richard Biener
2019-01-04 12:25 ` Eric Botcazou
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=87o98wpqna.fsf@arm.com \
--to=richard.sandiford@arm.com \
--cc=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.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).