https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97979
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- /* Fold (X {&,^,|} C2) << C1 into (X << C1) {&,^,|} (C2 << C1) (X {&,^,|} C2) >> C1 into (X >> C1) & (C2 >> C1). */ (for shift (lshift rshift) (for bit_op (bit_and bit_xor bit_ior) (simplify (shift (convert?:s (bit_op:s @0 INTEGER_CST@2)) INTEGER_CST@1) (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (with { tree mask = int_const_binop (shift, fold_convert (type, @2), @1); } (bit_op (shift (convert @0) @1) { mask; })))))) and mask ends up NULL. tree mask = int_const_binop (shift, fold_convert (type, captures[3]), captures[4]); (gdb) p debug_tree (captures[3]) <integer_cst 0x7ffff6953138 type <integer_type 0x7ffff68255e8 int> constant 65535> (gdb) p debug_tree (captures[4]) <integer_cst 0x7ffff682a3a8 type <integer_type 0x7ffff6825690 unsigned int> constant 4294967294> (gdb) p debug_tree (type) <integer_type 0x7ffff68255e8 int public SI so we push in mismatched signs and folding interprets the unsigned shift amout as signed?