https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31313
Kael Franco <kaelfandrew at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kaelfandrew at gmail dot com --- Comment #3 from Kael Franco <kaelfandrew at gmail dot com> --- (In reply to Tobias Schlüter from comment #0) > 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. This would require implementing Burst trie or suffix tree: https://stackoverflow.com/questions/10722410/fast-string-comparison-in-c