https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123270
Bug ID: 123270
Summary: strchr should optimize to equal check on boolean
expression
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: rockeet at gmail dot com
Target Milestone: ---
#include <string.h>
bool is_abchijopqxyz123(char ch) {
return strchr("abchijopqxyz123", ch) != NULL;
}
bool fast_is_abcdhijopqxyz123(char ch) {
return 'a' == ch ||
'b' == ch ||
'c' == ch ||
'h' == ch ||
'i' == ch ||
'j' == ch ||
'o' == ch ||
'p' == ch ||
'q' == ch ||
'x' == ch ||
'y' == ch ||
'z' == ch ||
'1' == ch ||
'2' == ch ||
'3' == ch;
}
It should be better strchr in is_abchijopqxyz123 can be opitimizied to
fast_is_abcdhijopqxyz123, but it is not, see https://godbolt.org/z/qjr9rj1f4