https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122592
--- Comment #6 from Richard Earnshaw <rearnsha at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> The trunk produces:
> ```
> and w3, w1, 65535
> rev16 w1, w1
> cmp w0, 0
> and w1, w1, 65535
> csel w3, w3, w1, eq
> add w0, w3, w2, uxth
> ret
> ```
> Which is slightly better.
Optimal would be
rev16 w1, w1
cmp w0, 0
csel w3, w3, w1, eq
add w0, w3, w2
and w0, w0, 65535
ret
since in none of the upper bits in the registers can affect the low bits.
Furthermore, if this were then inlined then the final AND could in many cases
be similarly eliminated.