This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: merge CONVERT_EXPR and NOP_EXPR part 1/2
- From: Tomas Bily <tbily at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Cc: tomby at ucw dot cz
- Date: Wed, 12 Sep 2007 18:51:24 +0200
- Subject: PATCH: merge CONVERT_EXPR and NOP_EXPR part 1/2
Hi,
CONVERT_EXPR and NOP_EXPR have nearly same use in current gcc.
This patch merge the diferences between CONVERT_EXPR and NOP_EXPR.
Bootstraped and tested on x86_64-unknow-linux, i686-unknown-linux,
ia64-unknow-linux. Ok ?
Greetings
Tomas
Index: gcc/java/typeck.c
===================================================================
--- gcc/java/typeck.c (revision 127700)
+++ gcc/java/typeck.c (working copy)
@@ -123,7 +123,7 @@ convert (tree type, tree expr)
if (TREE_CODE (TREE_TYPE (expr)) == ERROR_MARK)
return error_mark_node;
if (code == VOID_TYPE)
- return build1 (CONVERT_EXPR, type, expr);
+ return build1 (NOP_EXPR, type, expr);
if (code == BOOLEAN_TYPE)
return fold_convert (type, expr);
if (code == INTEGER_TYPE)
Index: gcc/java/expr.c
===================================================================
--- gcc/java/expr.c (revision 127700)
+++ gcc/java/expr.c (working copy)
@@ -2763,7 +2763,7 @@ build_jni_stub (tree method)
it might be promoted. */
drt = TREE_TYPE (DECL_RESULT (method));
if (drt != TREE_TYPE (res_var))
- res_var = build1 (CONVERT_EXPR, drt, res_var);
+ res_var = build1 (NOP_EXPR, drt, res_var);
res_var = build2 (MODIFY_EXPR, drt, DECL_RESULT (method), res_var);
TREE_SIDE_EFFECTS (res_var) = 1;
}
Index: gcc/tree.c
===================================================================
--- gcc/tree.c (revision 127700)
+++ gcc/tree.c (working copy)
@@ -6157,7 +6152,9 @@ get_narrower (tree op, int *unsignedp_pt
tree win = op;
bool integral_p = INTEGRAL_TYPE_P (TREE_TYPE (op));
- while (TREE_CODE (op) == NOP_EXPR)
+ while (TREE_CODE (op) == NOP_EXPR
+ && !((TREE_CODE (TREE_TYPE (op)) == REAL_TYPE) &&
+ (TREE_TYPE (op) != TREE_TYPE (TREE_OPERAND (op, 0)))))
{
int bitschange
= (TYPE_PRECISION (TREE_TYPE (op))
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c (revision 127700)
+++ gcc/fold-const.c (working copy)
@@ -3690,10 +3689,6 @@ fold_truth_not_expr (tree arg)
return invert_truthvalue (TREE_OPERAND (arg, 0));
case NOP_EXPR:
- if (TREE_CODE (TREE_TYPE (arg)) == BOOLEAN_TYPE)
- return build1 (TRUTH_NOT_EXPR, type, arg);
-
- case CONVERT_EXPR:
case FLOAT_EXPR:
return build1 (TREE_CODE (arg), type,
invert_truthvalue (TREE_OPERAND (arg, 0)));
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c (revision 127700)
+++ gcc/cp/typeck.c (working copy)
@@ -4120,7 +4119,7 @@ build_unary_op (enum tree_code code, tre
if ((invalid_op_diag
= targetm.invalid_unary_op ((code == UNARY_PLUS_EXPR
- ? CONVERT_EXPR
+ ? NON_LVALUE_EXPR
: code),
TREE_TYPE (xarg))))
{
@@ -4345,7 +4344,7 @@ build_unary_op (enum tree_code code, tre
if (TREE_CODE (argtype) == REFERENCE_TYPE)
{
tree type = build_pointer_type (TREE_TYPE (argtype));
- arg = build1 (CONVERT_EXPR, type, arg);
+ arg = build1 (NOP_EXPR, type, arg);
return arg;
}
else if (pedantic && DECL_MAIN_P (arg))
@@ -4364,7 +4363,7 @@ build_unary_op (enum tree_code code, tre
if (TREE_CODE (TREE_TYPE (arg)) == REFERENCE_TYPE)
{
tree type = build_pointer_type (TREE_TYPE (TREE_TYPE (arg)));
- arg = build1 (CONVERT_EXPR, type, arg);
+ arg = build1 (NOP_EXPR, type, arg);
}
else
/* Don't let this be an lvalue. */
Index: gcc/cp/cvt.c
===================================================================
--- gcc/cp/cvt.c (revision 127700)
+++ gcc/cp/cvt.c (working copy)
@@ -267,7 +267,7 @@ cp_convert_to_pointer (tree type, tree e
if (INTEGRAL_CODE_P (form))
{
if (TYPE_PRECISION (intype) == POINTER_SIZE)
- return build1 (CONVERT_EXPR, type, expr);
+ return build1 (NOP_EXPR, type, expr);
expr = cp_convert (c_common_type_for_size (POINTER_SIZE, 0), expr);
/* Modes may be different but sizes should be the same. There
is supposed to be some integral type that is the same width
@@ -987,7 +987,10 @@ convert_to_void (tree expr, const char *
conversions. Do not use STRIP_NOPs because it will
not strip conversions to "void", as that is not a
mode-preserving conversion. */
- while (TREE_CODE (e) == NOP_EXPR)
+ while (TREE_CODE (e) == NOP_EXPR
+ && (!TREE_SIDE_EFFECTS (e)
+ || (TREE_CODE (TREE_OPERAND (e, 0)) == CALL_EXPR
+ && DECL_BUILT_IN (get_callee_fndecl (TREE_OPERAND (e, 0))))))
e = TREE_OPERAND (e, 0);
code = TREE_CODE (e);
@@ -1004,7 +1007,7 @@ convert_to_void (tree expr, const char *
warning (OPT_Wunused_value, "value computed is not used");
}
}
- expr = build1 (CONVERT_EXPR, void_type_node, expr);
+ expr = build1 (NOP_EXPR, void_type_node, expr);
}
if (! TREE_SIDE_EFFECTS (expr))
expr = void_zero_node;
Index: gcc/dojump.c
===================================================================
--- gcc/dojump.c (revision 127700)
+++ gcc/dojump.c (working copy)
@@ -193,12 +193,11 @@ do_jump (tree exp, rtx if_false_label, r
|| TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_REF
|| TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_RANGE_REF)
goto normal;
- case CONVERT_EXPR:
- /* If we are narrowing the operand, we have to do the compare in the
- narrower mode. */
+
if ((TYPE_PRECISION (TREE_TYPE (exp))
< TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (exp, 0)))))
goto normal;
+
case NON_LVALUE_EXPR:
case ABS_EXPR:
case NEGATE_EXPR:
Index: gcc/ada/trans.c
===================================================================
--- gcc/ada/trans.c (revision 127700)
+++ gcc/ada/trans.c (working copy)
@@ -5986,9 +5985,8 @@ addressable_p (tree gnu_expr)
case ARRAY_REF: case ARRAY_RANGE_REF:
case REALPART_EXPR: case IMAGPART_EXPR:
- case NOP_EXPR:
return addressable_p (TREE_OPERAND (gnu_expr, 0));
- case CONVERT_EXPR:
+ case NOP_EXPR:
return (AGGREGATE_TYPE_P (TREE_TYPE (gnu_expr))
&& addressable_p (TREE_OPERAND (gnu_expr, 0)));
Index: gcc/ada/utils.c
===================================================================
--- gcc/ada/utils.c (revision 127700)
+++ gcc/ada/utils.c (working copy)
@@ -3557,7 +3556,7 @@ convert (tree type, tree expr)
switch (code)
{
case VOID_TYPE:
- return fold_build1 (CONVERT_EXPR, type, expr);
+ return fold_build1 (NOP_EXPR, type, expr);
case BOOLEAN_TYPE:
return fold_convert (type, gnat_truthvalue_conversion (expr));
Index: gcc/matrix-reorg.c
===================================================================
--- gcc/matrix-reorg.c (revision 127700)
+++ gcc/matrix-reorg.c (working copy)
@@ -1762,7 +1761,7 @@ transform_access_sites (void **slot, voi
/* Emit convert statement to convert to type of use. */
conv =
- fold_build1 (CONVERT_EXPR,
+ fold_build1 (NOP_EXPR,
TREE_TYPE (GIMPLE_STMT_OPERAND
(acc_info->stmt, 0)),
TREE_OPERAND (GIMPLE_STMT_OPERAND
Index: gcc/tree-eh.c
===================================================================
--- gcc/tree-eh.c (revision 127700)
+++ gcc/tree-eh.c (working copy)
@@ -1971,7 +1971,7 @@ tree_could_trap_p (tree expr)
case UNEQ_EXPR:
return honor_snans;
- case CONVERT_EXPR:
+ case NOP_EXPR:
case FIX_TRUNC_EXPR:
/* Conversion of floating point might trap. */
return honor_nans;
Index: gcc/fortran/convert.c
===================================================================
--- gcc/fortran/convert.c (revision 127700)
+++ gcc/fortran/convert.c (working copy)
@@ -89,7 +89,7 @@ convert (tree type, tree expr)
return error_mark_node;
}
if (code == VOID_TYPE)
- return build1 (CONVERT_EXPR, type, e);
+ return build1 (NOP_EXPR, type, e);
#if 0
/* This is incorrect. A truncation can't be stripped this way.
Extensions will be stripped by the use of get_unwidened. */
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c (revision 127700)
+++ gcc/c-typeck.c (working copy)
@@ -2890,7 +2887,7 @@ build_unary_op (enum tree_code code, tre
switch (code)
{
- case CONVERT_EXPR:
+ case NON_LVALUE_EXPR:
/* This is used for unary plus, because a CONVERT_EXPR
is enough to prevent anybody from looking inside for
associativity, but won't generate any code. */
@@ -3628,7 +3623,11 @@ build_c_cast (tree type, tree expr)
tree otype, ovalue;
if (type == void_type_node)
- return build1 (CONVERT_EXPR, type, value);
+ {
+ if (integer_zerop (value))
+ return build1 (NOP_EXPR, type, integer_one_node);
+ return build1 (NOP_EXPR, type, value);
+ }
otype = TREE_TYPE (value);
Index: gcc/treelang/tree-convert.c
===================================================================
--- gcc/treelang/tree-convert.c (revision 127700)
+++ gcc/treelang/tree-convert.c (working copy)
@@ -80,7 +80,7 @@ convert (tree type, tree expr)
return error_mark_node;
}
if (code == VOID_TYPE)
- return build1 (CONVERT_EXPR, type, e);
+ return build1 (NOP_EXPR, type, e);
if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
return fold (convert_to_integer (type, e));
if (code == BOOLEAN_TYPE)
Index: gcc/tree.def
===================================================================
--- gcc/tree.def (revision 127700)
+++ gcc/tree.def (working copy)
@@ -736,7 +736,7 @@ DEFTREECODE (RANGE_EXPR, "range_expr", t
/* Represents a conversion of type of a value.
All conversions, including implicit ones, must be
represented by CONVERT_EXPR or NOP_EXPR nodes. */
-DEFTREECODE (CONVERT_EXPR, "convert_expr", tcc_unary, 1)
+/* DEFTREECODE (CONVERT_EXPR, "convert_expr", tcc_unary, 1)*/
/* Conversion of a fixed-point value to an integer, a real, or a fixed-point
value. Or conversion of a fixed-point value from an integer, a real, or
Index: gcc/tree-vect-generic.c
===================================================================
--- gcc/tree-vect-generic.c (revision 127700)
+++ gcc/tree-vect-generic.c (working copy)
@@ -430,8 +430,6 @@ expand_vector_operations_1 (block_stmt_i
|| code == VIEW_CONVERT_EXPR)
return;
- gcc_assert (code != CONVERT_EXPR);
-
/* The signedness is determined from input argument. */
if (code == VEC_UNPACK_FLOAT_HI_EXPR
|| code == VEC_UNPACK_FLOAT_LO_EXPR)
Index: gcc/c-parser.c
===================================================================
--- gcc/c-parser.c (revision 127700)
+++ gcc/c-parser.c (working copy)
@@ -4800,7 +4800,7 @@ c_parser_unary_expression (c_parser *par
"traditional C rejects the unary plus operator");
op = c_parser_cast_expression (parser, NULL);
op = default_function_array_conversion (op);
- return parser_build_unary_op (CONVERT_EXPR, op);
+ return parser_build_unary_op (NON_LVALUE_EXPR, op);
case CPP_MINUS:
c_parser_consume_token (parser);
op = c_parser_cast_expression (parser, NULL);
Index: gcc/config/ia64/ia64.c
===================================================================
--- gcc/config/ia64/ia64.c (revision 127700)
+++ gcc/config/ia64/ia64.c (working copy)
@@ -9810,7 +9810,7 @@ ia64_invalid_unary_op (int op, tree type
{
/* Reject operations on __fpreg other than unary + or &. */
if (TYPE_MODE (type) == RFmode
- && op != CONVERT_EXPR
+ && op != NON_LVALUE_EXPR
&& op != ADDR_EXPR)
return N_("invalid operation on %<__fpreg%>");
return NULL;
Index: gcc/stmt.c
===================================================================
--- gcc/stmt.c (revision 127700)
+++ gcc/stmt.c (working copy)
@@ -3267,8 +3267,8 @@ emit_case_nodes (rtx index, case_node_pt
{
/* Widen LOW and HIGH to the same width as INDEX. */
tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
- tree low = build1 (CONVERT_EXPR, type, node->low);
- tree high = build1 (CONVERT_EXPR, type, node->high);
+ tree low = build1 (NOP_EXPR, type, node->low);
+ tree high = build1 (NOP_EXPR, type, node->high);
rtx low_rtx, new_index, new_bound;
/* Instead of doing two branches, emit one unsigned branch for
Index: gcc/convert.c
===================================================================
--- gcc/convert.c (revision 127700)
+++ gcc/convert.c (working copy)
@@ -61,7 +61,7 @@ convert_to_pointer (tree type, tree expr
expr = fold_build1 (NOP_EXPR,
lang_hooks.types.type_for_size (POINTER_SIZE, 0),
expr);
- return fold_build1 (CONVERT_EXPR, type, expr);
+ return fold_build1 (NOP_EXPR, type, expr);
default:
@@ -309,11 +308,7 @@ convert_to_real (tree type, tree expr)
case REAL_TYPE:
/* Ignore the conversion if we don't need to store intermediate
results and neither type is a decimal float. */
- return build1 ((flag_float_store
- || DECIMAL_FLOAT_TYPE_P (type)
- || DECIMAL_FLOAT_TYPE_P (itype))
- ? CONVERT_EXPR : NOP_EXPR, type, expr);
-
+ return build1 (NOP_EXPR, type, expr);
case INTEGER_TYPE:
case ENUMERAL_TYPE:
case BOOLEAN_TYPE:
@@ -450,7 +445,7 @@ convert_to_integer (tree type, tree expr
/* Convert to an unsigned integer of the correct width first,
and from there widen/truncate to the required type. */
- expr = fold_build1 (CONVERT_EXPR,
+ expr = fold_build1 (NOP_EXPR,
lang_hooks.types.type_for_size (POINTER_SIZE, 0),
expr);
return fold_convert (type, expr);
@@ -486,12 +481,8 @@ convert_to_integer (tree type, tree expr
conversion necessitates an explicit sign-extension. In
the signed-to-unsigned case the high-order bits have to
be cleared. */
- if (TYPE_UNSIGNED (type) != TYPE_UNSIGNED (TREE_TYPE (expr))
- && (TYPE_PRECISION (TREE_TYPE (expr))
- != GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr)))))
- code = CONVERT_EXPR;
- else
- code = NOP_EXPR;
+
+ code = NOP_EXPR;
tem = fold_unary (code, type, expr);
if (tem)
@@ -708,7 +699,7 @@ convert_to_integer (tree type, tree expr
break;
}
- return build1 (CONVERT_EXPR, type, expr);
+ return build1 (NOP_EXPR, type, expr);
case REAL_TYPE:
return build1 (FIX_TRUNC_EXPR, type, expr);