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

--- Comment #20 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #19)
> (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)

I see

        movl    a(%rip), %edx
        leal    2(%rdx), %eax
        cmpl    $-1, %edx
        movl    $0, %edx
        cmove   %edx, %eax
        movl    %eax, a(%rip)

with -O2 or

        movl    a(%rip), %edx
        xorl    %eax, %eax
        cmpl    $-1, %edx
        je      .L2
        leal    2(%rdx), %eax
.L2:
        movl    %eax, a(%rip)

with -Os.  The GIMPLE code makes it difficult to do better I guess, it
doesn't help that we don't have any CC there.

Reply via email to