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

--- Comment #16 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Created attachment 36012
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36012&action=edit
addsicc pattern

(In reply to Oleg Endo from comment #9)
> The following function compiled with -O2
> 
> unsigned int check (unsigned int x)
> {
>   return x == 0 ? 1 : x;
> }
> 
> results in:
>         tst     r4,r4
>         bt/s    .L7
>         mov     #1,r0
>         mov     r4,r0
> .L7:
>         rts
>         nop
> 
> 
> Writing it as:
> unsigned int check (unsigned int x)
> {
>   return x + (x == 0);
> }
> 
> results in:
>         tst     r4,r4
>         mov     #0,r0
>         rts
>         addc    r4,r0
> 
> It seems that ifcvt is trying to utilize the 'add<mode>cc' standard name
> pattern.  If the 2nd operand of the conditional addition is a constant 1 or
> -1 the addcc insn can be implemented via addc or subc without a branch.

The attached patch adds support for the addsicc pattern and a few other
improvements. However, the first case above doesn't see any improvement.  It
seems that it's a missed ifcvt optimization.

Reply via email to