+2019-12-03 Richard Sandiford <richard.sandiford@arm.com>
+
+ * gimplify.c (gimplify_compound_lval): Don't gimplify and install
+ an array element size if array_element_size is already an invariant.
+ Similarly don't gimplify and install a field offset if
+ component_ref_field_offset is already an invariant.
+
2019-12-03 Richard Sandiford <richard.sandiford@arm.com>
* cfgexpand.c (discover_nonconstant_array_refs_r): If an access
if (TREE_OPERAND (t, 3) == NULL_TREE)
{
- tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)));
- tree elmt_size = unshare_expr (array_ref_element_size (t));
- tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type));
-
- /* Divide the element size by the alignment of the element
- type (above). */
- elmt_size
- = size_binop_loc (loc, EXACT_DIV_EXPR, elmt_size, factor);
-
+ tree elmt_size = array_ref_element_size (t);
if (!is_gimple_min_invariant (elmt_size))
{
+ elmt_size = unshare_expr (elmt_size);
+ tree elmt_type = TREE_TYPE (TREE_TYPE (TREE_OPERAND (t, 0)));
+ tree factor = size_int (TYPE_ALIGN_UNIT (elmt_type));
+
+ /* Divide the element size by the alignment of the element
+ type (above). */
+ elmt_size = size_binop_loc (loc, EXACT_DIV_EXPR,
+ elmt_size, factor);
+
TREE_OPERAND (t, 3) = elmt_size;
tret = gimplify_expr (&TREE_OPERAND (t, 3), pre_p,
post_p, is_gimple_reg,
/* Set the field offset into T and gimplify it. */
if (TREE_OPERAND (t, 2) == NULL_TREE)
{
- tree offset = unshare_expr (component_ref_field_offset (t));
- tree field = TREE_OPERAND (t, 1);
- tree factor
- = size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT);
-
- /* Divide the offset by its alignment. */
- offset = size_binop_loc (loc, EXACT_DIV_EXPR, offset, factor);
-
+ tree offset = component_ref_field_offset (t);
if (!is_gimple_min_invariant (offset))
{
+ offset = unshare_expr (offset);
+ tree field = TREE_OPERAND (t, 1);
+ tree factor
+ = size_int (DECL_OFFSET_ALIGN (field) / BITS_PER_UNIT);
+
+ /* Divide the offset by its alignment. */
+ offset = size_binop_loc (loc, EXACT_DIV_EXPR,
+ offset, factor);
+
TREE_OPERAND (t, 2) = offset;
tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p,
post_p, is_gimple_reg,