* [PATCH] Minor improvement to genpreds.cc
@ 2022-05-22 9:02 Roger Sayle
2022-05-23 8:21 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2022-05-22 9:02 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1067 bytes --]
This simple patch implements Richard Biener's suggestion in comment #6
of PR tree-optimization/52171 (from February 2013) that the insn-preds
code generated by genpreds can avoid using strncmp when matching constant
strings of length one.
The effect of this patch is best explained by the diff of insn-preds.cc:
< if (!strncmp (str + 1, "g", 1))
---
> if (str[1] == 'g')
3104c3104
< if (!strncmp (str + 1, "m", 1))
---
> if (str[1] == 'm')
3106c3106
< if (!strncmp (str + 1, "c", 1))
---
> if (str[1] == 'c')
...
The equivalent optimization is performed by GCC (but perhaps not by the
host compiler), but generating simpler/smaller code may encourage further
optimizations (such as use of a switch statement).
This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check with no new failures. Ok for mainline?
2022-05-22 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
* genpreds.cc (write_lookup_constraint_1): Avoid generating a call
to strncmp for strings of length one.
Roger
--
[-- Attachment #2: patchgp.txt --]
[-- Type: text/plain, Size: 778 bytes --]
diff --git a/gcc/genpreds.cc b/gcc/genpreds.cc
index f71da09..4571ac7 100644
--- a/gcc/genpreds.cc
+++ b/gcc/genpreds.cc
@@ -1089,10 +1089,15 @@ write_lookup_constraint_1 (void)
{
do
{
- printf (" if (!strncmp (str + 1, \"%s\", %lu))\n"
- " return CONSTRAINT_%s;\n",
- c->name + 1, (unsigned long int) c->namelen - 1,
- c->c_name);
+ if (c->namelen > 2)
+ printf (" if (!strncmp (str + 1, \"%s\", %lu))\n"
+ " return CONSTRAINT_%s;\n",
+ c->name + 1, (unsigned long int) c->namelen - 1,
+ c->c_name);
+ else
+ printf (" if (str[1] == '%c')\n"
+ " return CONSTRAINT_%s;\n",
+ c->name[1], c->c_name);
c = c->next_this_letter;
}
while (c);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Minor improvement to genpreds.cc
2022-05-22 9:02 [PATCH] Minor improvement to genpreds.cc Roger Sayle
@ 2022-05-23 8:21 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-05-23 8:21 UTC (permalink / raw)
To: Roger Sayle; +Cc: GCC Patches
On Sun, May 22, 2022 at 11:03 AM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
>
> This simple patch implements Richard Biener's suggestion in comment #6
> of PR tree-optimization/52171 (from February 2013) that the insn-preds
> code generated by genpreds can avoid using strncmp when matching constant
> strings of length one.
>
> The effect of this patch is best explained by the diff of insn-preds.cc:
> < if (!strncmp (str + 1, "g", 1))
> ---
> > if (str[1] == 'g')
> 3104c3104
> < if (!strncmp (str + 1, "m", 1))
> ---
> > if (str[1] == 'm')
> 3106c3106
> < if (!strncmp (str + 1, "c", 1))
> ---
> > if (str[1] == 'c')
> ...
>
> The equivalent optimization is performed by GCC (but perhaps not by the
> host compiler), but generating simpler/smaller code may encourage further
> optimizations (such as use of a switch statement).
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check with no new failures. Ok for mainline?
OK.
Richard.
>
> 2022-05-22 Roger Sayle <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
> * genpreds.cc (write_lookup_constraint_1): Avoid generating a call
> to strncmp for strings of length one.
>
> Roger
> --
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-05-23 8:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-22 9:02 [PATCH] Minor improvement to genpreds.cc Roger Sayle
2022-05-23 8:21 ` Richard Biener
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).