Commit fcac9229 by Roger Sayle Committed by Roger Sayle

trans-array.c (gfc_trans_create_temp_array): When the size is known at…

trans-array.c (gfc_trans_create_temp_array): When the size is known at compile-time, avoid an unnecessary conditional assignment.


	* trans-array.c (gfc_trans_create_temp_array): When the size is known
	at compile-time, avoid an unnecessary conditional assignment.
	(gfc_array_init_size): Likewise.

From-SVN: r120141
parent 458e3389
2006-12-21 Roger Sayle <roger@eyesopen.com>
* trans-array.c (gfc_trans_create_temp_array): When the size is known
at compile-time, avoid an unnecessary conditional assignment.
(gfc_array_init_size): Likewise.
2006-12-22 Kazu Hirata <kazu@codesourcery.com>
* interface.c: Fix a comment typo.
......
......@@ -701,24 +701,33 @@ gfc_trans_create_temp_array (stmtblock_t * pre, stmtblock_t * post,
{
if (function)
{
var = gfc_create_var (TREE_TYPE (size), "size");
gfc_start_block (&thenblock);
gfc_add_modify_expr (&thenblock, var, gfc_index_zero_node);
thencase = gfc_finish_block (&thenblock);
gfc_start_block (&elseblock);
gfc_add_modify_expr (&elseblock, var, size);
elsecase = gfc_finish_block (&elseblock);
/* If we know at compile-time whether any dimension size is
negative, we can avoid a conditional and pass the true size
to gfc_trans_allocate_array_storage, which can then decide
whether to allocate this on the heap or on the stack. */
if (integer_zerop (or_expr))
;
else if (integer_onep (or_expr))
size = gfc_index_zero_node;
else
{
var = gfc_create_var (TREE_TYPE (size), "size");
gfc_start_block (&thenblock);
gfc_add_modify_expr (&thenblock, var, gfc_index_zero_node);
thencase = gfc_finish_block (&thenblock);
gfc_start_block (&elseblock);
gfc_add_modify_expr (&elseblock, var, size);
elsecase = gfc_finish_block (&elseblock);
tmp = gfc_evaluate_now (or_expr, pre);
tmp = build3_v (COND_EXPR, tmp, thencase, elsecase);
gfc_add_expr_to_block (pre, tmp);
nelem = var;
size = var;
tmp = gfc_evaluate_now (or_expr, pre);
tmp = build3_v (COND_EXPR, tmp, thencase, elsecase);
gfc_add_expr_to_block (pre, tmp);
size = var;
}
}
else
nelem = size;
nelem = size;
size = fold_build2 (MULT_EXPR, gfc_array_index_type, size,
TYPE_SIZE_UNIT (gfc_get_element_type (type)));
}
......@@ -3275,6 +3284,11 @@ gfc_array_init_size (tree descriptor, int rank, tree * poffset,
*poffset = offset;
}
if (integer_zerop (or_expr))
return size;
if (integer_onep (or_expr))
return gfc_index_zero_node;
var = gfc_create_var (TREE_TYPE (size), "size");
gfc_start_block (&thenblock);
gfc_add_modify_expr (&thenblock, var, gfc_index_zero_node);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment