https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95836
Bug ID: 95836
Summary: Failure to remove strchr converted to bool with string
literal when bit magic would be much more efficient
(and sometimes smaller)
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: ---
bool f(char c)
{
return strchr("1234567890", c);
}
This (and a lot of other similar strchr calls with string literals) can be
optimized to using a few bitwise operations (here, to something like `return
((unsigned)c < 64) & ((((uint64_t)1 << c) & 287948901175001089) != 0);`). This
transformation is done by LLVM, but not by GCC.