https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106804
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reference case:
<bb 2> [local count: 1073741824]:
_1 = *a_7(D);
_2 = *b_8(D);
if (_1 > _2)
goto <bb 3>; [50.00%]
else
goto <bb 4>; [50.00%]
<bb 3> [local count: 536870913]:
_3 = _1 + 1;
*a_7(D) = _3;
goto <bb 5>; [100.00%]
<bb 4> [local count: 536870913]:
_4 = _2 + 1;
*b_8(D) = _4;
<bb 5> [local count: 1073741824]:
Pointer case:
<bb 2> [local count: 1073741824]:
_1 = *a_7(D);
_2 = *b_8(D);
if (_1 > _2)
goto <bb 3>; [50.00%]
else
goto <bb 4>; [50.00%]
<bb 3> [local count: 536870912]:
<bb 4> [local count: 1073741824]:
# iftmp.0_5 = PHI <a_7(D)(3), b_8(D)(2)>
# prephitmp_10 = PHI <_1(3), _2(2)>
_4 = prephitmp_10 + 1;
*iftmp.0_5 = _4;
Pointercase 2 which does the reference case really:
void increment_largest2(int* a, int* b) {
(*a > *b ? ++*a : ++*b);
}
x86_64 clang trunk does this though:
increment_largest(int&, int&): # @increment_largest(int&, int&)
movl (%rdi), %eax
movl (%rsi), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
cmovgq %rdi, %rsi
incl %ecx
movl %ecx, (%rsi)
retq
But 2 cmov's might be worse than a conditional branch on x86_64.