https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103647
Bug ID: 103647 Summary: constant array comparison not always folded Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: denis.campredon at gmail dot com Target Milestone: --- On trunk and gcc 11, with -O2 the following functions are not optimized to xor eax, eax ------------ bool f() { char a[] = {'a', 'c'}; char b[] = {'a', 'b'}; return __builtin_memcmp(a, b, 2); } bool g() { char a[] = {'a', 'b'}; char b[] = {'a', 'b', 'c'}; return __builtin_memcmp(a, b, 2); } ------------ .LC1: .string "ab" .LC0: .string "ac" f(): movzx eax, WORD PTR .LC1[rip] cmp WORD PTR .LC0[rip], ax setne al ret g(): cmp WORD PTR .LC1[rip], 25185 setne al ret