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

--- Comment #1 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Another bit test case I ran into (on GCC 8) is something like 

    unsigned int bleh = (i & 4) == 0 ? 0 : 3;

An optimized result would be something like

     tst       #4,r1
     stz       #0,r14
     stnz      #3,r14

This would take 3 cycles to execute, which is minimal.  The same can be done
with a smaller code size:

     mov.l     #0,r14
     tst       #4,r1
     stnz      #3,r14


It seems it kind of works for some cases, but not for all the cases.  For
example, inverting the condition in the above example:

    unsigned int bleh = (i & 4) != 0 ? 0 : 3;

results in:

66 4e                           mov.l   #4, r14
53 2e                           and     r2, r14
66 3e                           mov.l   #3, r14
fd 74 fe 00                     stnz    #0, r14


But then swapping the constants to 

    unsigned int bleh = (i & 4) != 0 ? 3 : 0;

again falls back to cbranch code:

66 4e                           mov.l   #4, r14
53 2e                           and     r2, r14
14                              beq.s   0f
66 3e                           mov.l   #3, r14
03                              nop
0:

Reply via email to