https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101642
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I think better testcase would be int x; unsigned short foo (void) { return __builtin_bswap16 (x) ? : x; } because otherwise you're asking for it to be DCEd. The problem is that for __builtin_bswap16 like for many other builtins with 8 or 16-bit argument(s) the operand is promoted to int. So, many of the match.pd rules just don't trigger for it at all, like: (simplify (bswap (bswap @0)) @0) (simplify (bswap (bit_not (bswap @0))) (bit_not @0)) (for bitop (bit_xor bit_ior bit_and) (simplify (bswap (bitop:c (bswap @0) @1)) (bitop @0 (bswap @1)))) because there are casts it doesn't take into account for bswap16, others are just incorrect, like: (for cmp (eq ne) (simplify (cmp (bswap @0) (bswap @1)) (cmp @0 @1)) - it needs to convert @0 and @1 to the type of one of the bswaps, otherwise it could be comparing even the upper bits, and others are both incorrect and cause ICE, like (simplify (cmp (bswap @0) INTEGER_CST@1) (cmp @0 (bswap @1)))) Let me deal with just those now and the rest that just don't match can be dealt with later on.