fold-const.c (fold_indirect_ref_1): Handle folding POINTER_PLUS_EXPR to ARRAY_REF.
* fold-const.c (fold_indirect_ref_1): Handle folding POINTER_PLUS_EXPR to ARRAY_REF. From-SVN: r166163
This commit is contained in:
parent
878415841a
commit
7bf8ca763d
|
@ -1,3 +1,8 @@
|
||||||
|
2010-11-01 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
|
* fold-const.c (fold_indirect_ref_1): Handle folding
|
||||||
|
POINTER_PLUS_EXPR to ARRAY_REF.
|
||||||
|
|
||||||
2010-11-01 Kaz Kojima <kkojima@gcc.gnu.org>
|
2010-11-01 Kaz Kojima <kkojima@gcc.gnu.org>
|
||||||
|
|
||||||
* config/sh/sh.c (TARGET_DELEGITIMIZE_ADDRESS): Redefine.
|
* config/sh/sh.c (TARGET_DELEGITIMIZE_ADDRESS): Redefine.
|
||||||
|
|
|
@ -15643,53 +15643,59 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ((foo*)&vectorfoo)[1] => BIT_FIELD_REF<vectorfoo,...> */
|
|
||||||
if (TREE_CODE (sub) == POINTER_PLUS_EXPR
|
if (TREE_CODE (sub) == POINTER_PLUS_EXPR
|
||||||
&& TREE_CODE (TREE_OPERAND (sub, 1)) == INTEGER_CST)
|
&& TREE_CODE (TREE_OPERAND (sub, 1)) == INTEGER_CST)
|
||||||
{
|
{
|
||||||
tree op00 = TREE_OPERAND (sub, 0);
|
tree op00 = TREE_OPERAND (sub, 0);
|
||||||
tree op01 = TREE_OPERAND (sub, 1);
|
tree op01 = TREE_OPERAND (sub, 1);
|
||||||
tree op00type;
|
|
||||||
|
|
||||||
STRIP_NOPS (op00);
|
STRIP_NOPS (op00);
|
||||||
op00type = TREE_TYPE (op00);
|
if (TREE_CODE (op00) == ADDR_EXPR)
|
||||||
if (TREE_CODE (op00) == ADDR_EXPR
|
|
||||||
&& TREE_CODE (TREE_TYPE (op00type)) == VECTOR_TYPE
|
|
||||||
&& type == TREE_TYPE (TREE_TYPE (op00type)))
|
|
||||||
{
|
{
|
||||||
HOST_WIDE_INT offset = tree_low_cst (op01, 0);
|
tree op00type;
|
||||||
tree part_width = TYPE_SIZE (type);
|
op00 = TREE_OPERAND (op00, 0);
|
||||||
unsigned HOST_WIDE_INT part_widthi = tree_low_cst (part_width, 0)/BITS_PER_UNIT;
|
op00type = TREE_TYPE (op00);
|
||||||
unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT;
|
|
||||||
tree index = bitsize_int (indexi);
|
|
||||||
|
|
||||||
if (offset/part_widthi <= TYPE_VECTOR_SUBPARTS (TREE_TYPE (op00type)))
|
/* ((foo*)&vectorfoo)[1] => BIT_FIELD_REF<vectorfoo,...> */
|
||||||
return fold_build3_loc (loc,
|
if (TREE_CODE (op00type) == VECTOR_TYPE
|
||||||
BIT_FIELD_REF, type, TREE_OPERAND (op00, 0),
|
&& type == TREE_TYPE (op00type))
|
||||||
part_width, index);
|
{
|
||||||
|
HOST_WIDE_INT offset = tree_low_cst (op01, 0);
|
||||||
|
tree part_width = TYPE_SIZE (type);
|
||||||
|
unsigned HOST_WIDE_INT part_widthi = tree_low_cst (part_width, 0)/BITS_PER_UNIT;
|
||||||
|
unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT;
|
||||||
|
tree index = bitsize_int (indexi);
|
||||||
|
|
||||||
}
|
if (offset/part_widthi <= TYPE_VECTOR_SUBPARTS (op00type))
|
||||||
}
|
return fold_build3_loc (loc,
|
||||||
|
BIT_FIELD_REF, type, op00,
|
||||||
|
part_width, index);
|
||||||
|
|
||||||
|
}
|
||||||
/* ((foo*)&complexfoo)[1] => __imag__ complexfoo */
|
/* ((foo*)&complexfoo)[1] => __imag__ complexfoo */
|
||||||
if (TREE_CODE (sub) == POINTER_PLUS_EXPR
|
else if (TREE_CODE (op00type) == COMPLEX_TYPE
|
||||||
&& TREE_CODE (TREE_OPERAND (sub, 1)) == INTEGER_CST)
|
&& type == TREE_TYPE (op00type))
|
||||||
{
|
{
|
||||||
tree op00 = TREE_OPERAND (sub, 0);
|
tree size = TYPE_SIZE_UNIT (type);
|
||||||
tree op01 = TREE_OPERAND (sub, 1);
|
if (tree_int_cst_equal (size, op01))
|
||||||
tree op00type;
|
return fold_build1_loc (loc, IMAGPART_EXPR, type, op00);
|
||||||
|
}
|
||||||
STRIP_NOPS (op00);
|
/* ((foo *)&fooarray)[1] => fooarray[1] */
|
||||||
op00type = TREE_TYPE (op00);
|
else if (TREE_CODE (op00type) == ARRAY_TYPE
|
||||||
if (TREE_CODE (op00) == ADDR_EXPR
|
&& type == TREE_TYPE (op00type))
|
||||||
&& TREE_CODE (TREE_TYPE (op00type)) == COMPLEX_TYPE
|
{
|
||||||
&& type == TREE_TYPE (TREE_TYPE (op00type)))
|
tree type_domain = TYPE_DOMAIN (op00type);
|
||||||
{
|
tree min_val = size_zero_node;
|
||||||
tree size = TYPE_SIZE_UNIT (type);
|
if (type_domain && TYPE_MIN_VALUE (type_domain))
|
||||||
if (tree_int_cst_equal (size, op01))
|
min_val = TYPE_MIN_VALUE (type_domain);
|
||||||
return fold_build1_loc (loc, IMAGPART_EXPR, type,
|
op01 = size_binop_loc (loc, EXACT_DIV_EXPR, op01,
|
||||||
TREE_OPERAND (op00, 0));
|
TYPE_SIZE_UNIT (type));
|
||||||
|
op01 = size_binop_loc (loc, PLUS_EXPR, op01, min_val);
|
||||||
|
op0 = build4 (ARRAY_REF, type, op00, op01,
|
||||||
|
NULL_TREE, NULL_TREE);
|
||||||
|
SET_EXPR_LOCATION (op0, loc);
|
||||||
|
return op0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue