[Bug tree-optimization/97690] (cond ? 2 : 0) is not optimized to int(cond) << 1

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 3 10:30:14 GMT 2020


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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It seems to be target-independent. For aarch64, -O3 and -Os both give:

f(bool):
        tst     w0, 255
        cset    w0, ne
        lsl     w0, w0, 1
        ret
g(bool):
        ubfiz   w0, w0, 1, 8
        ret


And avr -Os is horrible:

__zero_reg__ = 1
f(bool):
        cpse r24,__zero_reg__
        rjmp .L3
        ldi r25,0
        ldi r24,0
        ret
.L3:
        ldi r24,lo8(2)
        ldi r25,0
        ret
g(bool):
        ldi r25,0
        lsl r24
        rol r25
ret


More information about the Gcc-bugs mailing list