public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/95821] New: Failure to optimize strchr to use memchr for string constant
@ 2020-06-22 17:07 gabravier at gmail dot com
2020-06-22 17:20 ` [Bug tree-optimization/95821] " jakub at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gabravier at gmail dot com @ 2020-06-22 17:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95821
Bug ID: 95821
Summary: Failure to optimize strchr to use memchr for string
constant
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
auto f(char c)
{
return strchr("123", c);
}
This can be optimized to `return memchr("123", c, 4)`. This transformation is
done by LLVM, but not by GCC.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/95821] Failure to optimize strchr to use memchr for string constant
2020-06-22 17:07 [Bug tree-optimization/95821] New: Failure to optimize strchr to use memchr for string constant gabravier at gmail dot com
@ 2020-06-22 17:20 ` jakub at gcc dot gnu.org
2021-12-22 7:35 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-22 17:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95821
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
For -Os that is an undesirable change because it makes the code larger. But
otherwise yes, seems useful.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/95821] Failure to optimize strchr to use memchr for string constant
2020-06-22 17:07 [Bug tree-optimization/95821] New: Failure to optimize strchr to use memchr for string constant gabravier at gmail dot com
2020-06-22 17:20 ` [Bug tree-optimization/95821] " jakub at gcc dot gnu.org
@ 2021-12-22 7:35 ` pinskia at gcc dot gnu.org
2021-12-22 7:39 ` pinskia at gcc dot gnu.org
2022-06-17 1:48 ` hjl.tools at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-22 7:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95821
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Severity|normal |enhancement
Ever confirmed|0 |1
Last reconfirmed| |2021-12-22
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Though for small strings it might even make sense to inline it, eg.:
auto f(char c)
{
return strchr("123", c);
}
to
auto f(char c)
{
auto t = "123";
int t1;
switch (c)
{
case '1':
t1 = 1;
case '2':
t1 = 2;
case '3':
t1 = 3;
default:
t = 0;
return t;
}
return t+t1;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/95821] Failure to optimize strchr to use memchr for string constant
2020-06-22 17:07 [Bug tree-optimization/95821] New: Failure to optimize strchr to use memchr for string constant gabravier at gmail dot com
2020-06-22 17:20 ` [Bug tree-optimization/95821] " jakub at gcc dot gnu.org
2021-12-22 7:35 ` pinskia at gcc dot gnu.org
@ 2021-12-22 7:39 ` pinskia at gcc dot gnu.org
2022-06-17 1:48 ` hjl.tools at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-22 7:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95821
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> Confirmed.
> auto f(char c)
> {
> auto t = "123";
> int t1;
> switch (c)
> {
> case '1':
> t1 = 1;
> case '2':
> t1 = 2;
> case '3':
> t1 = 3;
> default:
> t = 0;
> return t;
> }
> return t+t1;
> }
I missed '\0' (and break's):
auto f(char c)
{
auto t = "123";
int t1;
switch (c)
{
case '1':
t1 = 1;
break;
case '2':
t1 = 2;
break;
case '3':
t1 = 3;
break;
case '\0':
t1 = 4;
break;
default:
t = 0;
return t;
}
return t+t1;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/95821] Failure to optimize strchr to use memchr for string constant
2020-06-22 17:07 [Bug tree-optimization/95821] New: Failure to optimize strchr to use memchr for string constant gabravier at gmail dot com
` (2 preceding siblings ...)
2021-12-22 7:39 ` pinskia at gcc dot gnu.org
@ 2022-06-17 1:48 ` hjl.tools at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2022-06-17 1:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95821
--- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 53157
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53157&action=edit
A patch
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-06-17 1:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22 17:07 [Bug tree-optimization/95821] New: Failure to optimize strchr to use memchr for string constant gabravier at gmail dot com
2020-06-22 17:20 ` [Bug tree-optimization/95821] " jakub at gcc dot gnu.org
2021-12-22 7:35 ` pinskia at gcc dot gnu.org
2021-12-22 7:39 ` pinskia at gcc dot gnu.org
2022-06-17 1:48 ` hjl.tools at gmail dot com
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).