https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102793
Bug ID: 102793 Summary: AArch64: sequential comparisons with equal conditional blocks don't use ccmp Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: christophm30 at gmail dot com Target Milestone: --- The following code: int ccmp(uint64_t* s1, uint64_t* s2, int(*foo)(void)) { uint64_t d1, d2, bar; d1 = *s1++; d2 = *s2++; bar = (d1 ^ d2) & 0xabcd; if (bar == 0 || d1 != d2) return foo(); return 0; } int noccmp(uint64_t* s1, uint64_t* s2, int(*foo)(void)) { uint64_t d1, d2, bar; d1 = *s1++; d2 = *s2++; bar = (d1 ^ d2) & 0xabcd; if (bar == 0) return foo(); if (d1 != d2) return foo(); return 0; } ...produces (GCC master or earlier, ARM64, with -O3): ccmp: ldr x3, [x0] mov x4, 43981 ldr x0, [x1] eor x1, x3, x0 tst x1, x4 ccmp x3, x0, 0, ne bne .L5 mov w0, 0 ret .L5: mov x16, x2 br x16 noccmp: ldr x3, [x0] mov x4, 43981 ldr x0, [x1] eor x1, x3, x0 tst x1, x4 beq .L8 cmp x3, x0 beq .L9 .L8: mov x16, x2 br x16 .L9: mov w0, 0 ret Since both conditional blocks do exactly the same (they call foo()), both functions could use the ccmp instruction. I just observed this and have not analysed this any further.