public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/31313] New: consecutive strcmps are not merged
@ 2007-03-22 15:12 tobi at gcc dot gnu dot org
2007-03-22 15:28 ` [Bug tree-optimization/31313] " pinskia at gcc dot gnu dot org
2007-04-29 6:47 ` pinskia at gcc dot gnu dot org
0 siblings, 2 replies; 3+ messages in thread
From: tobi at gcc dot gnu dot org @ 2007-03-22 15:12 UTC (permalink / raw)
To: gcc-bugs
I just ran into some code which did something like
int strcmp(const char *, const char *);
int f (const char *c)
{
return (strcmp (c, "aaa") == 0 || strcmp (c, "aab") == 0);
}
It would be possible to optimize this into something like (hopefully I get it
right)
int f (const char *c)
{
if (strncmp (c, "aa", 2))
return 0;
return ((c[2] == 'a' || c[2] == 'b') && !c[3]);
}
Instead, we scan through the whole string twice, as can be seen in the
assembly.
Likewise, more complicated combinations of comparisons could be reduced into an
optimal matching sequence. Putting this into component rtl-optimization,
because the strcmp calls survive all of the tree optimizers unchanged.
--
Summary: consecutive strcmps are not merged
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tobi at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31313
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-04-29 6:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-22 15:12 [Bug rtl-optimization/31313] New: consecutive strcmps are not merged tobi at gcc dot gnu dot org
2007-03-22 15:28 ` [Bug tree-optimization/31313] " pinskia at gcc dot gnu dot org
2007-04-29 6:47 ` pinskia at gcc dot gnu dot org
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).