https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117864
Bug ID: 117864 Summary: uadd_with_carry could be improved for aarch64 Product: gcc Version: 15.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: --- Target: aarch64 Take: ``` bool uadd_with_carry(unsigned a, unsigned b, bool c, unsigned* out) { unsigned sum1; bool c1 = __builtin_uadd_overflow(a, b, &sum1); unsigned sum2; bool c2 = __builtin_uadd_overflow(sum1, (unsigned)c, &sum2); *out = sum2; return c1 | c2; } ``` Right now GCC produces: ``` uadd_with_carry: adds w0, w0, w1 and w2, w2, 255 cset w1, cs adds w2, w0, w2 cset w0, cs str w2, [x3] orr w0, w1, w0 ret ``` This could be improved to: ``` uadd_with_carry: and w8, w2, #0x1 cmp w8, #1 adcs w8, w0, w1 cset w0, hs str w8, [x3] ret ``` That is implement aarch64 backend could implement the uaddc5/usubc5 optabs for SImode/DImode.