https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104611
Bug ID: 104611 Summary: memcmp/strcmp/strncmp can be optimized when the result is tested for [in]equality with 0 on aarch64 Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: bool f(char *a) { char t[] = "0123456789012345678901234567890"; return __builtin_memcmp(a, &t[0], sizeof(t)) == 0; } Right now GCC uses branches to optimize this but this could be done via a few loads followed by xor (eor) of the two sides and then oring the results of xor and then umavx and then comparing that to 0. This can be done for the middle-end code too if there is a max reduction opcode.