This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran,patch] Get rid of some convert calls in favor of build_int_cst
- From: FX Coudert <fxcoudert at gmail dot com>
- To: gfortran <fortran at gcc dot gnu dot org>, patch <gcc-patches at gcc dot gnu dot org>
- Cc: Paul Brook <paul at codesourcery dot com>
- Date: Mon, 19 Jun 2006 20:55:04 +0200
- Subject: [gfortran,patch] Get rid of some convert calls in favor of build_int_cst
Following a remark from Paul Brook that calls such as
convert (foo_type, integer_zero_node);
would better be replaced by
build_int_cst (foo_type, 0);
the attached patch performs this substitution for the cases I could spot
in the Fortran front-end.
Regtested on i686-linux, OK for mainline (and 4.1, to ease backporting)?
FX
Index: trans-expr.c
===================================================================
--- trans-expr.c (revision 114721)
+++ trans-expr.c (working copy)
@@ -152,12 +152,12 @@
present = gfc_conv_expr_present (arg->symtree->n.sym);
tmp = build3 (COND_EXPR, TREE_TYPE (se->expr), present, se->expr,
- convert (TREE_TYPE (se->expr), integer_zero_node));
+ build_int_cst (TREE_TYPE (se->expr), 0));
tmp = gfc_evaluate_now (tmp, &se->pre);
se->expr = tmp;
if (ts.type == BT_CHARACTER)
{
- tmp = convert (gfc_charlen_type_node, integer_zero_node);
+ tmp = build_int_cst (gfc_charlen_type_node, 0);
tmp = build3 (COND_EXPR, gfc_charlen_type_node, present,
se->string_length, tmp);
tmp = gfc_evaluate_now (tmp, &se->pre);
@@ -526,7 +526,7 @@
All other unary operators have an equivalent GIMPLE unary operator. */
if (code == TRUTH_NOT_EXPR)
se->expr = build2 (EQ_EXPR, type, operand.expr,
- convert (type, integer_zero_node));
+ build_int_cst (type, 0));
else
se->expr = build1 (code, type, operand.expr);
@@ -656,27 +656,26 @@
if ((sgn == -1) && (TREE_CODE (type) == INTEGER_TYPE))
{
tmp = build2 (EQ_EXPR, boolean_type_node, lhs,
- fold_convert (TREE_TYPE (lhs), integer_minus_one_node));
+ build_int_cst (TREE_TYPE (lhs), -1));
cond = build2 (EQ_EXPR, boolean_type_node, lhs,
- convert (TREE_TYPE (lhs), integer_one_node));
+ build_int_cst (TREE_TYPE (lhs), 1));
/* If rhs is even,
result = (lhs == 1 || lhs == -1) ? 1 : 0. */
if ((n & 1) == 0)
{
tmp = build2 (TRUTH_OR_EXPR, boolean_type_node, tmp, cond);
- se->expr = build3 (COND_EXPR, type, tmp,
- convert (type, integer_one_node),
- convert (type, integer_zero_node));
+ se->expr = build3 (COND_EXPR, type, tmp, build_int_cst (type, 1),
+ build_int_cst (type, 0));
return 1;
}
/* If rhs is odd,
result = (lhs == 1) ? 1 : (lhs == -1) ? -1 : 0. */
- tmp = build3 (COND_EXPR, type, tmp,
- convert (type, integer_minus_one_node),
- convert (type, integer_zero_node));
- se->expr = build3 (COND_EXPR, type, cond,
- convert (type, integer_one_node),
+ tmp = build3 (COND_EXPR, type, tmp, build_int_cst (type, -1),
+ build_int_cst (type, 0));
+ se->expr = build3 (COND_EXPR, type, cond, build_int_cst (type, 1),
tmp);
return 1;
}
@@ -866,7 +864,7 @@
{
/* Create a temporary variable to hold the result. */
tmp = fold_build2 (MINUS_EXPR, gfc_charlen_type_node, len,
- convert (gfc_charlen_type_node, integer_one_node));
+ build_int_cst (gfc_charlen_type_node, 1));
tmp = build_range_type (gfc_array_index_type, gfc_index_zero_node, tmp);
tmp = build_array_type (gfc_character1_type_node, tmp);
var = gfc_create_var (tmp, "str");
@@ -1901,8 +1899,7 @@
gfc_init_se (&parmse, NULL);
parmse.expr = null_pointer_node;
if (arg->missing_arg_type == BT_CHARACTER)
- parmse.string_length = convert (gfc_charlen_type_node,
- integer_zero_node);
+ parmse.string_length = build_int_cst (gfc_charlen_type_node, 0);
}
}
else if (se->ss && se->ss->useflags)
Index: trans-stmt.c
===================================================================
--- trans-stmt.c (revision 114721)
+++ trans-stmt.c (working copy)
@@ -904,7 +904,7 @@
}
gfc_add_modify_expr (&block, count, tmp);
- count_one = convert (TREE_TYPE (count), integer_one_node);
+ count_one = build_int_cst (TREE_TYPE (count), 1);
/* Initialize the DO variable: dovar = from. */
gfc_add_modify_expr (&block, dovar, from);
Index: trans-io.c
===================================================================
--- trans-io.c (revision 114721)
+++ trans-io.c (working copy)
@@ -607,7 +607,7 @@
gfc_conv_expr (&se, e);
gfc_conv_string_parameter (&se);
tmp = se.expr;
- se.expr = fold_convert (pchar_type_node, integer_zero_node);
+ se.expr = build_int_cst (pchar_type_node, 0);
}
/* Character array. */
@@ -1308,7 +1308,7 @@
if (ts->type == BT_CHARACTER)
NML_ADD_ARG (ts->cl->backend_decl);
else
- NML_ADD_ARG (convert (gfc_charlen_type_node, integer_zero_node));
+ NML_ADD_ARG (build_int_cst (gfc_charlen_type_node, 0));
NML_ADD_ARG (dtype);
tmp = build_function_call_expr (iocall[IOCALL_SET_NML_VAL], args);
Index: trans-decl.c
===================================================================
--- trans-decl.c (revision 114721)
+++ trans-decl.c (working copy)
@@ -1618,7 +1618,7 @@
args = tree_cons (NULL_TREE, null_pointer_node, args);
if (formal->sym->ts.type == BT_CHARACTER)
{
- tmp = convert (gfc_charlen_type_node, integer_zero_node);
+ tmp = build_int_cst (gfc_charlen_type_node, 0);
string_args = tree_cons (NULL_TREE, tmp, string_args);
}
}
2006-06-19 Francois-Xavier Coudert <coudert@clipper.ens.fr>
* trans-expr.c (gfc_conv_missing_dummy, gfc_conv_unary_op,
gfc_conv_cst_int_power, gfc_conv_string_tmp,
gfc_conv_function_call): Replace calls to convert on constant
integer nodes by build_int_cst.
* trans-stmt.c (gfc_trans_do): Likewise.
* trans-io.c (set_internal_unit, transfer_namelist_element):
Likewise.
* trans-decl.c (build_entry_thunks): Likewise.