diff --git a/gcc/match.pd b/gcc/match.pd index 1d407414bee278c64c00d425d9f025c1c58d853d..b225d36dc758f1581502c8d03761544bfd499c01 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7245,6 +7245,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && ANY_INTEGRAL_TYPE_P (type) && ANY_INTEGRAL_TYPE_P (TREE_TYPE(@0))) (IFN_REDUC_PLUS_WIDEN @0))) +/* Canonicalize BIT_FIELD_REFS and shifts to BIT_FIELD_REFS. */ +(for shift (rshift) + op (plus) + (simplify + (shift (BIT_FIELD_REF @0 @1 @2) integer_pow2p@3) + (if (INTEGRAL_TYPE_P (type)) + (with { /* Can't use wide-int here as the precision differs between + @1 and @3. */ + unsigned HOST_WIDE_INT size = tree_to_uhwi (@1); + unsigned HOST_WIDE_INT shiftc = tree_to_uhwi (@3); + unsigned HOST_WIDE_INT newsize = size - shiftc; + tree nsize = wide_int_to_tree (bitsizetype, newsize); + tree ntype + = build_nonstandard_integer_type (newsize, 1); } + (if (ntype) + (convert:type (BIT_FIELD_REF:ntype @0 { nsize; } (op @2 @3)))))))) + (simplify (BIT_FIELD_REF (BIT_FIELD_REF @0 @1 @2) @3 @4) (BIT_FIELD_REF @0 @3 { const_binop (PLUS_EXPR, bitsizetype, @2, @4); }))