[Bug target/51244] SH Target: Inefficient conditional branch

olegendo at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Mar 6 23:43:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51244

--- Comment #22 from Oleg Endo <olegendo at gcc dot gnu.org> 2012-03-06 23:42:15 UTC ---
This is a reduced test case:

int test (volatile int* a, int b, int c)
{
  a[1] = b != 0;

  if (b == 0)
    a[10] = c;

  return b == 0;
}

with '-O2 -m4-single -mb' it gets compiled to:

        tst     r5,r5       ! b == 0 -> T
        mov     #-1,r1
        negc    r1,r1       ! b != 0 -> T, r1
        mov.l   r1,@(4,r4)
        bf      .L2         ! branch if (b == 0)
        mov.l   r6,@(40,r4)
.L2:
        tst     r5,r5
        rts    
        movt    r0

This is because in the 'movnegt' expander it is not mentioned that the T bit is
modified and the first CSE pass optimizes away the 'b == 0' test before the
branch.  I'm trying to come up with some alternative approaches...



More information about the Gcc-bugs mailing list