===================================================================
@@ -4178,3 +4178,25 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
{ CONSTRUCTOR_ELT (ctor, idx / k)->value; })
(BIT_FIELD_REF { CONSTRUCTOR_ELT (ctor, idx / k)->value; }
@1 { bitsize_int ((idx % k) * width); })))))))))
+
+/* Simplify a bit extraction from a bit insertion for the cases with
+ the inserted element fully covering the extraction or the insertion
+ not touching the extraction. */
+(simplify
+ (BIT_FIELD_REF (bit_insert @0 @1 @ipos) @rsize @rpos)
+ (with
+ {
+ unsigned HOST_WIDE_INT isize;
+ if (INTEGRAL_TYPE_P (TREE_TYPE (@1)))
+ isize = TYPE_PRECISION (TREE_TYPE (@1));
+ else
+ isize = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (@1)));
+ }
+ (switch
+ (if (wi::leu_p (@ipos, @rpos)
+ && wi::leu_p (wi::add (@rpos, @rsize), wi::add (@ipos, isize)))
+ (BIT_FIELD_REF @1 @rsize { wide_int_to_tree (bitsizetype,
+ wi::sub (@rpos, @ipos)); }))
+ (if (wi::geu_p (@ipos, wi::add (@rpos, @rsize))
+ || wi::geu_p (@rpos, wi::add (@ipos, isize)))
+ (BIT_FIELD_REF @0 @rsize @rpos)))))
===================================================================
@@ -4245,7 +4245,7 @@ maybe_canonicalize_mem_ref_addr (tree *t
TREE_TYPE (*t),
TREE_OPERAND (TREE_OPERAND (*t, 0), 0),
TYPE_SIZE (TREE_TYPE (*t)),
- wide_int_to_tree (sizetype, idx));
+ wide_int_to_tree (bitsizetype, idx));
res = true;
}
}
===================================================================
@@ -3053,7 +3053,9 @@ verify_expr (tree *tp, int *walk_subtree
tree t1 = TREE_OPERAND (t, 1);
tree t2 = TREE_OPERAND (t, 2);
if (!tree_fits_uhwi_p (t1)
- || !tree_fits_uhwi_p (t2))
+ || !tree_fits_uhwi_p (t2)
+ || !types_compatible_p (bitsizetype, TREE_TYPE (t1))
+ || !types_compatible_p (bitsizetype, TREE_TYPE (t2)))
{
error ("invalid position or size operand to BIT_FIELD_REF");
return t;
@@ -4247,6 +4249,7 @@ verify_gimple_assign_ternary (gassign *s
return true;
}
if (! tree_fits_uhwi_p (rhs3)
+ || ! types_compatible_p (bitsizetype, TREE_TYPE (rhs3))
|| ! tree_fits_uhwi_p (TYPE_SIZE (rhs2_type)))
{
error ("invalid position or size in BIT_INSERT_EXPR");
===================================================================
@@ -3936,7 +3936,7 @@ make_bit_field_ref (location_t loc, tree
bftype = build_nonstandard_integer_type (bitsize, 0);
result = build3_loc (loc, BIT_FIELD_REF, bftype, inner,
- size_int (bitsize), bitsize_int (bitpos));
+ bitsize_int (bitsize), bitsize_int (bitpos));
REF_REVERSE_STORAGE_ORDER (result) = reversep;
if (bftype != type)
===================================================================
@@ -3531,7 +3531,7 @@ vectorizable_simd_clone_call (gimple *st
arginfo[i].op = vec_oprnd0;
vec_oprnd0
= build3 (BIT_FIELD_REF, atype, vec_oprnd0,
- size_int (prec),
+ bitsize_int (prec),
bitsize_int ((m & (k - 1)) * prec));
new_stmt
= gimple_build_assign (make_ssa_name (atype),
@@ -3692,7 +3692,7 @@ vectorizable_simd_clone_call (gimple *st
}
else
t = build3 (BIT_FIELD_REF, vectype, new_temp,
- size_int (prec), bitsize_int (l * prec));
+ bitsize_int (prec), bitsize_int (l * prec));
new_stmt
= gimple_build_assign (make_ssa_name (vectype), t);
vect_finish_stmt_generation (stmt, new_stmt, gsi);