https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95853
Bug ID: 95853
Summary: Failure to optimize add overflow pattern to
__builtin_add_overflow
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
struct result_struct
{
bool p;
uint64_t r;
};
result_struct size_add_overflow(uint64_t x, uint64_t y)
{
unsigned __int128 z = (unsigned __int128)x + (unsigned __int128)y;
return {z > SIZE_MAX, (size_t)z};
}
This can be optimized to
result_struct size_add_overflow(uint64_t x, uint64_t y)
{
uint64_t result;
return {__builtin_add_overflow(x, y, &result), result};
}
This transformation is done by LLVM, but not by GCC.