https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115719
Bug ID: 115719 Summary: __builtin_memcmp missed if it compare length of 3 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: kese111 at gmail dot com Target Milestone: --- here is example code: bool test_even_3(const char* input) { return ( __builtin_memcmp(input, "ab", 2) == 0 || __builtin_memcmp(input, "abc", 3) == 0 ); } bool test_even_4(const char* input) { return ( __builtin_memcmp(input, "ab", 2) == 0 || __builtin_memcmp(input, "abc", 3) == 0 || __builtin_memcmp(input, "abcd", 4) == 0 ); } and its results for x86-gcc-trunk(Compiler explorer) test_even_3(char const*): cmp WORD PTR [rdi], 25185 mov eax, 1 je .L12 mov eax, 1 test eax, eax sete al .L12: ret test_even_4(char const*): cmp WORD PTR [rdi], 25185 mov eax, 1 je .L17 cmp DWORD PTR [rdi], 1684234849 sete al .L17: ret used O2 optimizing. what am I missing?