https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111209
Bug ID: 111209 Summary: GCC fails to understand adc pattern Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: unlvsur at live dot com Target Milestone: --- Created attachment 55805 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55805&action=edit bug example template<typename T> inline constexpr T addc(T a,T b,bool carryin,bool& carryout) noexcept { T s; auto c1 = __builtin_add_overflow(a, b, __builtin_addressof(s)); auto c2 = __builtin_add_overflow(s, carryin, __builtin_addressof(s)); carryout = c1 | c2; return s; } void test_addc(unsigned long long* a,unsigned long long* b,unsigned long long* r) { bool carry{}; r[0]=addc(a[0],b[0],carry,carry); r[1]=addc(a[1],b[1],carry,carry); } I copied the example from gcc documentation https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html But gcc seems to fail to understand the pattern correctly even with what the document describes. gcc: https://godbolt.org/z/Whaaahn41 clang: https://godbolt.org/z/Ma6rvaYd6 Looks like a bug here.