https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129211
Bug ID: 129211
Summary: Unsigned integers not reassociated
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: tkoenig at gcc dot gnu.org
Target Milestone: ---
This is split off from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128737#c4
(the test case by David Brown).
gcc does not reassociate unsigned integers where overflow is impossible
where profitable. The code
typedef unsigned int uint;
uint add_v1_uint(uint a, uint b, uint c, uint d) {
return a + b + c + d;
}
is translated on ARM with -O2 -mcpu=cortex-m7 into
add_v1_uint:
add r2, r2, r3
add r2, r2, r1
add r0, r0, r2
bx lr
On x86_64 with -O2 to
add edx, ecx
add edx, esi
lea eax, [rdx+rdi]
ret
This is carried over from the *.optimized dump, which shows
uint add_v1_uint (uint a, uint b, uint c, uint d)
{
uint _7;
unsigned int _9;
unsigned int _10;
<bb 2> [local count: 1073741824]:
_9 = c_5(D) + d_6(D);
_10 = b_4(D) + _9;
_7 = a_3(D) + _10;
return _7;
}
clang instead does
add esi, edi
lea eax, [rdx + rcx]
add eax, esi
ret
where to instructions can run in parallel.