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