https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115813
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed| |2024-07-07 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed. This match.pd pattern could be extended to use uniform_integer_cst_p instead of INTEGER_CST which should fix it I think: ``` /* 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); } (if (mask) (bit_op (shift (convert @0) @1) { mask; }))))))) ``` Well @2 does not need to be uniform but it does make it easier though. Note int_const_binop maybe should be changed to just const_binop once moving over to use uniform_integer_cst_p .