https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106323
Bug ID: 106323 Summary: [Suboptimal] memcmp(s1, s2, n) == 0 expansion on AArch64 compare to llvm Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: zhongyunde at huawei dot com Target Milestone: --- test case, see detail https://gcc.godbolt.org/z/PM3jxEM9M ``` #include <string.h> int src(char* s1, char* s2) { return memcmp(s1, s2, 3) == 0; } ``` * llvm doesn't emit branch with instruction cset ``` src: // @src ldrh w8, [x0] ldrh w9, [x1] ldrb w10, [x0, #2] ldrb w11, [x1, #2] eor w8, w8, w9 eor w9, w10, w11 orr w8, w8, w9 cmp w8, #0 cset w0, eq ret ``` * gcc ``` src: ldrh w3, [x0] ldrh w2, [x1] cmp w3, w2 beq .L5 .L2: mov w0, 1 eor w0, w0, 1 ret .L5: ldrb w2, [x0, 2] ldrb w0, [x1, 2] cmp w2, w0 bne .L2 mov w0, 0 eor w0, w0, 1 ret ```