+2008-03-06 Richard Guenther <rguenther@suse.de>
+
+ * tree.def (BIT_FIELD_REF): Constrain result type and its precision.
+ * tree-cfg.c (verify_expr): Verify BIT_FIELD_REF constraints on
+ result type and precision.
+ * expr.c (get_inner_reference): Set unsignedp based on the result
+ type of BIT_FIELD_REF.
+ * tree.h (BIT_FIELD_REF_UNSIGNED): Remove.
+ * tree-sra.c (instantiate_element): Do not set BIT_FIELD_REF_UNSIGNED.
+ (try_instantiate_multiple_fields): Likewise. Use the correct type
+ for BIT_FIELD_REF.
+ (sra_build_assignment): Likewise.
+ (sra_build_elt_assignment): Likewise.
+ (sra_explode_bitfield_assignment): Likewise.
+ * print-tree.c (print_node): Do not check BIT_FIELD_REF_UNSIGNED.
+ * tree-vect-transform.c (vect_create_epilog_for_reduction): Do not
+ set BIT_FIELD_REF_UNSIGNED.
+ (vectorizable_load): Likewise.
+
2008-03-06 Andreas Krebbel <krebbel1@de.ibm.com>
* cse.c (cse_extended_basic_block): Invalidate artificial defs
else if (TREE_CODE (exp) == BIT_FIELD_REF)
{
size_tree = TREE_OPERAND (exp, 1);
- *punsignedp = BIT_FIELD_REF_UNSIGNED (exp);
+ *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
+ || TYPE_UNSIGNED (TREE_TYPE (exp)));
/* For vector types, with the correct size of access, use the mode of
inner type. */
case tcc_reference:
case tcc_statement:
case tcc_vl_exp:
- if (TREE_CODE (node) == BIT_FIELD_REF && BIT_FIELD_REF_UNSIGNED (node))
- fputs (" unsigned", file);
if (TREE_CODE (node) == BIND_EXPR)
{
print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
error ("invalid position or size operand to BIT_FIELD_REF");
return t;
}
+ else if (INTEGRAL_TYPE_P (TREE_TYPE (t))
+ && (TYPE_PRECISION (TREE_TYPE (t))
+ != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
+ {
+ error ("integral result type precision does not match "
+ "field size of BIT_FIELD_REF");
+ return t;
+ }
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
+ && (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (t)))
+ != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
+ {
+ error ("mode precision of non-integral result does not "
+ "match field size of BIT_FIELD_REF");
+ return t;
+ }
}
t = TREE_OPERAND (t, 0);
TYPE_SIZE (elt->type),
DECL_SIZE (var))
: bitsize_int (0));
- if (!INTEGRAL_TYPE_P (elt->type)
- || TYPE_UNSIGNED (elt->type))
- BIT_FIELD_REF_UNSIGNED (elt->replacement) = 1;
}
/* For vectors, if used on the left hand side with BIT_FIELD_REF,
/* Create the field group as a single variable. */
- type = lang_hooks.types.type_for_mode (mode, 1);
+ /* We used to create a type for the mode above, but size turns
+ to be out not of mode-size. As we need a matching type
+ to build a BIT_FIELD_REF, use a nonstandard integer type as
+ fallback. */
+ type = lang_hooks.types.type_for_size (size, 1);
+ if (!type || TYPE_PRECISION (type) != size)
+ type = build_nonstandard_integer_type (size, 1);
gcc_assert (type);
var = build3 (BIT_FIELD_REF, type, NULL_TREE,
bitsize_int (size),
bitsize_int (bit));
- BIT_FIELD_REF_UNSIGNED (var) = 1;
block = instantiate_missing_elements_1 (elt, var, type);
gcc_assert (block && block->is_scalar);
TREE_TYPE (block->element), var,
bitsize_int (size),
bitsize_int (bit & ~alchk));
- BIT_FIELD_REF_UNSIGNED (block->replacement) = 1;
}
block->in_bitfld_block = 2;
+ (TREE_INT_CST_LOW
(DECL_FIELD_BIT_OFFSET (f))))
& ~alchk));
- BIT_FIELD_REF_UNSIGNED (fld->replacement) = TYPE_UNSIGNED (field_type);
fld->in_bitfld_block = 1;
}
tree var, shift, width;
tree utype, stype, stmp, utmp, dtmp;
tree list, stmt;
- bool unsignedp = BIT_FIELD_REF_UNSIGNED (src);
+ bool unsignedp = (INTEGRAL_TYPE_P (TREE_TYPE (src))
+ ? TYPE_UNSIGNED (TREE_TYPE (src)) : true);
var = TREE_OPERAND (src, 0);
width = TREE_OPERAND (src, 1);
if (elt->in_bitfld_block == 2
&& TREE_CODE (src) == BIT_FIELD_REF)
{
+ tmp = src;
cst = TYPE_SIZE (TREE_TYPE (var));
cst2 = size_binop (MINUS_EXPR, TREE_OPERAND (src, 2),
TREE_OPERAND (dst, 2));
}
else
{
- src = fold_build3 (BIT_FIELD_REF, TREE_TYPE (var), src, cst, cst2);
- BIT_FIELD_REF_UNSIGNED (src) = 1;
+ src = fold_convert (TREE_TYPE (var), tmp);
}
return sra_build_assignment (var, src);
type = TREE_TYPE (infld);
if (TYPE_PRECISION (type) != TREE_INT_CST_LOW (flen))
type = lang_hooks.types.type_for_size (TREE_INT_CST_LOW (flen), 1);
+ else
+ type = unsigned_type_for (type);
if (TREE_CODE (infld) == BIT_FIELD_REF)
{
}
infld = fold_build3 (BIT_FIELD_REF, type, infld, flen, fpos);
- BIT_FIELD_REF_UNSIGNED (infld) = 1;
invar = size_binop (MINUS_EXPR, flp.field_pos, bpos);
if (flp.overlap_pos)
invar = size_binop (PLUS_EXPR, invar, vpos);
invar = fold_build3 (BIT_FIELD_REF, type, var, flen, invar);
- BIT_FIELD_REF_UNSIGNED (invar) = 1;
if (to_var)
st = sra_build_bf_assignment (invar, infld);
vec_size_in_bits = tree_low_cst (TYPE_SIZE (vectype), 1);
rhs = build3 (BIT_FIELD_REF, scalar_type, vec_temp, bitsize,
bitsize_zero_node);
- BIT_FIELD_REF_UNSIGNED (rhs) = TYPE_UNSIGNED (scalar_type);
epilog_stmt = build_gimple_modify_stmt (new_scalar_dest, rhs);
new_temp = make_ssa_name (new_scalar_dest, epilog_stmt);
GIMPLE_STMT_OPERAND (epilog_stmt, 0) = new_temp;
tree rhs = build3 (BIT_FIELD_REF, scalar_type, vec_temp, bitsize,
bitpos);
- BIT_FIELD_REF_UNSIGNED (rhs) = TYPE_UNSIGNED (scalar_type);
epilog_stmt = build_gimple_modify_stmt (new_scalar_dest, rhs);
new_name = make_ssa_name (new_scalar_dest, epilog_stmt);
GIMPLE_STMT_OPERAND (epilog_stmt, 0) = new_name;
bitpos = bitsize_zero_node;
rhs = build3 (BIT_FIELD_REF, scalar_type, new_temp, bitsize, bitpos);
- BIT_FIELD_REF_UNSIGNED (rhs) = TYPE_UNSIGNED (scalar_type);
epilog_stmt = build_gimple_modify_stmt (new_scalar_dest, rhs);
new_temp = make_ssa_name (new_scalar_dest, epilog_stmt);
GIMPLE_STMT_OPERAND (epilog_stmt, 0) = new_temp;
bitpos = bitsize_zero_node;
vec_inv = build3 (BIT_FIELD_REF, scalar_type, new_temp,
bitsize, bitpos);
- BIT_FIELD_REF_UNSIGNED (vec_inv) =
- TYPE_UNSIGNED (scalar_type);
vec_dest =
vect_create_destination_var (scalar_dest, NULL_TREE);
new_stmt = build_gimple_modify_stmt (vec_dest, vec_inv);
Operand 0 is the structure or union expression;
operand 1 is a tree giving the constant number of bits being referenced;
operand 2 is a tree giving the constant position of the first referenced bit.
- The field can be either a signed or unsigned field;
- BIT_FIELD_REF_UNSIGNED says which. */
+ The result type width has to match the number of bits referenced.
+ If the result type is integral, its signedness specifies how it is extended
+ to its mode width. */
DEFTREECODE (BIT_FIELD_REF, "bit_field_ref", tcc_reference, 3)
/* The ordering of the following codes is optimized for the checking
all types
DECL_UNSIGNED in
all decls
- BIT_FIELD_REF_UNSIGNED in
- BIT_FIELD_REF
asm_written_flag:
#define DECL_UNSIGNED(NODE) \
(DECL_COMMON_CHECK (NODE)->base.unsigned_flag)
-/* In a BIT_FIELD_REF, means the bitfield is to be interpreted as unsigned. */
-#define BIT_FIELD_REF_UNSIGNED(NODE) \
- (BIT_FIELD_REF_CHECK (NODE)->base.unsigned_flag)
-
/* In integral and pointer types, means an unsigned type. */
#define TYPE_UNSIGNED(NODE) (TYPE_CHECK (NODE)->base.unsigned_flag)