https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94846
Bug ID: 94846
Summary: Failure to optimize jnc+inc into adc
Product: gcc
Version: 10.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: ---
unsigned f(unsigned *p, unsigned x)
{
unsigned u = *p;
*p += x;
if (u > *p)
++*p;
return *p;
}
This is what LLVM outputs with -O3 :
f(unsigned int*, unsigned int): # @f(unsigned int*, unsigned int)
mov eax, esi
add eax, dword ptr [rdi]
adc eax, 0
mov dword ptr [rdi], eax
ret
This is what GCC outputs :
f(unsigned int*, unsigned int):
mov eax, esi
add eax, DWORD PTR [rdi]
jnc .L6
add eax, 1
.L6:
mov DWORD PTR [rdi], eax
ret
GCC should most likely be optimizing this to the same thing as LLVM.