This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH to variable_size
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 28 Feb 2003 17:17:17 -0500
- Subject: PATCH to variable_size
This patch simplifies the trees for TYPE_SIZE of a variable-length array;
previously it involved first subtracting, then adding one because of how we
were wrapping bits in SAVE_EXPRs. This patch changes variable_size to
leave the subtraction in the TYPE_DOMAIN value outside of the SAVE_EXPR so
that it can be folded away when creating the TYPE_SIZE. This also improves
optimized code a bit for some VLA testcases.
Booted and tested i686-pc-linux-gnu, applied to trunk.
2003-02-28 Jason Merrill <jason at redhat dot com>
* stor-layout.c (variable_size): Leave a "minus 1" outside the
SAVE_EXPR.
*** stor-layout.c.~1~ Wed Feb 26 14:26:30 2003
--- stor-layout.c Wed Feb 26 16:28:35 2003
*************** tree
*** 157,162 ****
--- 157,164 ----
variable_size (size)
tree size;
{
+ tree save;
+
/* If the language-processor is to take responsibility for variable-sized
items (e.g., languages which have elaboration procedures like Ada),
just return SIZE unchanged. Likewise for self-referential sizes and
*************** variable_size (size)
*** 166,172 ****
|| contains_placeholder_p (size))
return size;
! size = save_expr (size);
/* If an array with a variable number of elements is declared, and
the elements require destruction, we will emit a cleanup for the
--- 168,179 ----
|| contains_placeholder_p (size))
return size;
! if (TREE_CODE (size) == MINUS_EXPR && integer_onep (TREE_OPERAND (size, 1)))
! /* If this is the upper bound of a C array, leave the minus 1 outside
! the SAVE_EXPR so it can be folded away. */
! TREE_OPERAND (size, 0) = save = save_expr (TREE_OPERAND (size, 0));
! else
! size = save = save_expr (size);
/* If an array with a variable number of elements is declared, and
the elements require destruction, we will emit a cleanup for the
*************** variable_size (size)
*** 176,183 ****
`unsaved', i.e., all SAVE_EXPRs are recalculated. However, we do
not wish to do that here; the array-size is the same in both
places. */
! if (TREE_CODE (size) == SAVE_EXPR)
! SAVE_EXPR_PERSISTENT_P (size) = 1;
if ((*lang_hooks.decls.global_bindings_p) ())
{
--- 183,190 ----
`unsaved', i.e., all SAVE_EXPRs are recalculated. However, we do
not wish to do that here; the array-size is the same in both
places. */
! if (TREE_CODE (save) == SAVE_EXPR)
! SAVE_EXPR_PERSISTENT_P (save) = 1;
if ((*lang_hooks.decls.global_bindings_p) ())
{
*************** variable_size (size)
*** 190,205 ****
}
if (immediate_size_expand)
! /* NULL_RTX is not defined; neither is the rtx type.
! Also, we would like to pass const0_rtx here, but don't have it. */
! expand_expr (size, expand_expr (integer_zero_node, NULL_RTX, VOIDmode, 0),
! VOIDmode, 0);
else if (cfun != 0 && cfun->x_dont_save_pending_sizes_p)
/* The front-end doesn't want us to keep a list of the expressions
that determine sizes for variable size objects. */
;
else
! put_pending_size (size);
return size;
}
--- 197,209 ----
}
if (immediate_size_expand)
! expand_expr (save, const0_rtx, VOIDmode, 0);
else if (cfun != 0 && cfun->x_dont_save_pending_sizes_p)
/* The front-end doesn't want us to keep a list of the expressions
that determine sizes for variable size objects. */
;
else
! put_pending_size (save);
return size;
}