https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12395

--- Comment #19 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #18)
> This is what is produced (at least for 7.3.0):
Which has been produced since GCC 6.
that is due to ifcvt.c changes.
On the trunk we can produce on the gimple now:
  a.1_1 = a;
  if (a.1_1 != -1)
    goto <bb 3>; [50.00%]
  else
    goto <bb 4>; [50.00%]

  <bb 3> [local count: 536870913]:
  _3 = a.1_1 + 2;

  <bb 4> [local count: 1073741824]:
  # _2 = PHI <0(2), _3(3)>
  a = _2;

Note most optimial code is really:
        movl    a(%rip), %eax
        addl    $1, %eax
        adcl    $0, %eax
        movl    %eax, a(%rip)
Which can be produced with LLVM with:
void foo1() {
        extern int a;
        a += 1; a+=a==0;
}

GCC is close:
        movl    a(%rip), %eax
        xorl    %edx, %edx
        addl    $1, %eax
        sete    %dl
        addl    %edx, %eax
        movl    %eax, a(%rip)

But the the sete and addl can be combined.

Reply via email to