* tree-flow.h (types_compatible_p): Declare.
* tree-ssa.c (types_compatible_p): New function.
* ipa-type-escape.c (discover_unique_type): Use
types_compatible_p instead of lang_hooks.types_compatible_p.
* tree-ssa-copyrename.c (copy_rename_partition_coalesce): Likewise.
* tree-vn.c (expressions_equal_p): Likewise.
* tree.c (fields_compatible_p): Likewise.
* tree-ssa-dom.c (avail_expr_eq): Likewise.
(cprop_operand): Use useless_type_conversion_p instead of
lang_hooks.types_compatible_p.
* tree-inline.c (setup_one_parameter): Likewise.
(declare_return_variable): Likewise.
* tree-nrv.c (tree_nrv): Likewise.
* tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Likewise.
(maybe_fold_offset_to_component_ref): Likewise.
(maybe_fold_offset_to_reference): Likewise.
* tree-ssa-copy.c (may_propagate_copy): Likewise.
(merge_alias_info): Likewise.
* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Likewise.
* tree-ssa-phiopt.c (conditional_replacement): Likewise.
* tree-ssa-reassoc.c (optimize_ops_list): Likewise.
* tree-tailcall.c (find_tail_calls): Likewise.
* tree-vect-generic.c (expand_vector_operations_1): Likewise.
* gimplify.c (canonicalize_addr_expr): Likewise.
(fold_indirect_ref_rhs): Likewise.
(gimplify_addr_expr): Likewise. Swap parameters to cpt_same_type.
(cpt_same_type): Likewise.
(check_pointer_types_r): Swap parameters to cpt_same_type
where appropriate.
* fold-const.c (fold_convert): Revert fix for PR15988.
* tree-inline.c (setup_one_parameter): Instead fix it here by
using fold_build1 instead of fold_convert and checking for
error_mark_node. Convert only if the conversion is necessary.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@126198
138bc75d-0d04-0410-961f-
82ee72b054a4
+2007-07-02 Richard Guenther <rguenther@suse.de>
+
+ * tree-flow.h (types_compatible_p): Declare.
+ * tree-ssa.c (types_compatible_p): New function.
+ * ipa-type-escape.c (discover_unique_type): Use
+ types_compatible_p instead of lang_hooks.types_compatible_p.
+ * tree-ssa-copyrename.c (copy_rename_partition_coalesce): Likewise.
+ * tree-vn.c (expressions_equal_p): Likewise.
+ * tree.c (fields_compatible_p): Likewise.
+ * tree-ssa-dom.c (avail_expr_eq): Likewise.
+ (cprop_operand): Use useless_type_conversion_p instead of
+ lang_hooks.types_compatible_p.
+ * tree-inline.c (setup_one_parameter): Likewise.
+ (declare_return_variable): Likewise.
+ * tree-nrv.c (tree_nrv): Likewise.
+ * tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Likewise.
+ (maybe_fold_offset_to_component_ref): Likewise.
+ (maybe_fold_offset_to_reference): Likewise.
+ * tree-ssa-copy.c (may_propagate_copy): Likewise.
+ (merge_alias_info): Likewise.
+ * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Likewise.
+ * tree-ssa-phiopt.c (conditional_replacement): Likewise.
+ * tree-ssa-reassoc.c (optimize_ops_list): Likewise.
+ * tree-tailcall.c (find_tail_calls): Likewise.
+ * tree-vect-generic.c (expand_vector_operations_1): Likewise.
+ * gimplify.c (canonicalize_addr_expr): Likewise.
+ (fold_indirect_ref_rhs): Likewise.
+ (gimplify_addr_expr): Likewise. Swap parameters to cpt_same_type.
+ (cpt_same_type): Likewise.
+ (check_pointer_types_r): Swap parameters to cpt_same_type
+ where appropriate.
+ * fold-const.c (fold_convert): Revert fix for PR15988.
+ * tree-inline.c (setup_one_parameter): Instead fix it here by
+ using fold_build1 instead of fold_convert and checking for
+ error_mark_node. Convert only if the conversion is necessary.
+
2007-07-02 Joseph Myers <joseph@codesourcery.com>
* configure.ac: Check for .gnu_attribute on Power.
|| TREE_CODE (orig) == ERROR_MARK)
return error_mark_node;
- if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig)
- || lang_hooks.types_compatible_p (TYPE_MAIN_VARIANT (type),
- TYPE_MAIN_VARIANT (orig)))
+ if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig))
return fold_build1 (NOP_EXPR, type, arg);
switch (TREE_CODE (type))
/* Both cast and addr_expr types should address the same object type. */
dctype = TREE_TYPE (ctype);
ddatype = TREE_TYPE (datype);
- if (!lang_hooks.types_compatible_p (ddatype, dctype))
+ if (!useless_type_conversion_p (dctype, ddatype))
return;
/* The addr_expr and the object type should match. */
obj_expr = TREE_OPERAND (addr_expr, 0);
otype = TREE_TYPE (obj_expr);
- if (!lang_hooks.types_compatible_p (otype, datype))
+ if (!useless_type_conversion_p (datype, otype))
return;
/* The lower bound and element sizes must be constant. */
tree op = TREE_OPERAND (sub, 0);
tree optype = TREE_TYPE (op);
/* *&p => p */
- if (lang_hooks.types_compatible_p (type, optype))
+ if (useless_type_conversion_p (type, optype))
return op;
/* *(foo *)&fooarray => fooarray[0] */
else if (TREE_CODE (optype) == ARRAY_TYPE
- && lang_hooks.types_compatible_p (type, TREE_TYPE (optype)))
+ && useless_type_conversion_p (type, TREE_TYPE (optype)))
{
tree type_domain = TYPE_DOMAIN (optype);
tree min_val = size_zero_node;
/* *(foo *)fooarrptr => (*fooarrptr)[0] */
if (TREE_CODE (TREE_TYPE (subtype)) == ARRAY_TYPE
- && lang_hooks.types_compatible_p (type, TREE_TYPE (TREE_TYPE (subtype))))
+ && useless_type_conversion_p (type, TREE_TYPE (TREE_TYPE (subtype))))
{
tree type_domain;
tree min_val = size_zero_node;
tree t_expr = TREE_TYPE (expr);
tree t_op00 = TREE_TYPE (op00);
- if (!lang_hooks.types_compatible_p (t_expr, t_op00))
+ if (!useless_type_conversion_p (t_expr, t_op00))
{
#ifdef ENABLE_CHECKING
tree t_op0 = TREE_TYPE (op0);
gcc_assert (POINTER_TYPE_P (t_expr)
- && cpt_same_type (TREE_CODE (t_op0) == ARRAY_TYPE
- ? TREE_TYPE (t_op0) : t_op0,
- TREE_TYPE (t_expr))
+ && (cpt_same_type (TREE_TYPE (t_expr), t_op0)
+ || (TREE_CODE (t_op0) == ARRAY_TYPE
+ && cpt_same_type (TREE_TYPE (t_expr),
+ TREE_TYPE (t_op0))))
&& POINTER_TYPE_P (t_op00)
&& cpt_same_type (t_op0, TREE_TYPE (t_op00)));
#endif
static bool
cpt_same_type (tree a, tree b)
{
- if (lang_hooks.types_compatible_p (a, b))
+ if (useless_type_conversion_p (a, b))
return true;
/* ??? The C++ FE decomposes METHOD_TYPES to FUNCTION_TYPES and doesn't
ptype = TREE_TYPE (t);
otype = TREE_TYPE (TREE_OPERAND (t, 0));
dtype = TREE_TYPE (ptype);
- if (!cpt_same_type (otype, dtype))
+ if (!cpt_same_type (dtype, otype))
{
/* &array is allowed to produce a pointer to the element, rather than
a pointer to the array type. We must allow this in order to
pointer to the element type. */
gcc_assert (TREE_CODE (otype) == ARRAY_TYPE
&& POINTER_TYPE_P (ptype)
- && cpt_same_type (TREE_TYPE (otype), dtype));
+ && cpt_same_type (dtype, TREE_TYPE (otype)));
break;
}
break;
/* Create an alias since this is just the same as
other_type. */
tree other_type = (tree) result->value;
- if (lang_hooks.types_compatible_p (type, other_type) == 1)
+ if (types_compatible_p (type, other_type))
{
free (brand);
/* Insert this new type as an alias for other_type. */
extern void flush_pending_stmts (edge);
extern bool tree_ssa_useless_type_conversion (tree);
extern bool useless_type_conversion_p (tree, tree);
+extern bool types_compatible_p (tree, tree);
extern void verify_ssa (bool);
extern void delete_tree_ssa (void);
extern void walk_use_def_chains (tree, walk_use_def_chains_fn, void *, bool);
tree init_stmt;
tree var;
tree var_sub;
- tree rhs = value ? fold_convert (TREE_TYPE (p), value) : NULL;
+ tree rhs = value;
tree def = (gimple_in_ssa_p (cfun)
? gimple_default_def (id->src_cfun, p) : NULL);
+ if (value
+ && value != error_mark_node
+ && !useless_type_conversion_p (TREE_TYPE (p), TREE_TYPE (value)))
+ rhs = fold_build1 (NOP_EXPR, TREE_TYPE (p), value);
+
/* If the parameter is never assigned to, has no SSA_NAMEs created,
we may not need to create a new variable here at all. Instead, we may
be able to just use the argument value. */
It is not big deal to prohibit constant propagation here as
we will constant propagate in DOM1 pass anyway. */
if (is_gimple_min_invariant (value)
- && lang_hooks.types_compatible_p (TREE_TYPE (value), TREE_TYPE (p))
+ && useless_type_conversion_p (TREE_TYPE (p),
+ TREE_TYPE (value))
/* We have to be very careful about ADDR_EXPR. Make sure
the base variable isn't a local variable of the inlined
function, e.g., when doing recursive inlining, direct or
bool use_it = false;
/* We can't use MODIFY_DEST if there's type promotion involved. */
- if (!lang_hooks.types_compatible_p (caller_type, callee_type))
+ if (!useless_type_conversion_p (callee_type, caller_type))
use_it = false;
/* ??? If we're assigning to a variable sized type, then we must
/* Build the use expr. If the return type of the function was
promoted, convert it back to the expected type. */
use = var;
- if (!lang_hooks.types_compatible_p (TREE_TYPE (var), caller_type))
+ if (!useless_type_conversion_p (caller_type, TREE_TYPE (var)))
use = fold_convert (caller_type, var);
STRIP_USELESS_TYPE_CONVERSION (use);
|| TREE_STATIC (found)
|| TREE_ADDRESSABLE (found)
|| DECL_ALIGN (found) > DECL_ALIGN (result)
- || !lang_hooks.types_compatible_p (TREE_TYPE (found),
- result_type))
+ || !useless_type_conversion_p (result_type,
+ TREE_TYPE (found)))
return 0;
}
else if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT)
if (TREE_CODE (array_type) != ARRAY_TYPE)
return NULL_TREE;
elt_type = TREE_TYPE (array_type);
- if (!lang_hooks.types_compatible_p (orig_type, elt_type))
+ if (!useless_type_conversion_p (orig_type, elt_type))
return NULL_TREE;
/* Use signed size type for intermediate computation on the index. */
return NULL_TREE;
/* Short-circuit silly cases. */
- if (lang_hooks.types_compatible_p (record_type, orig_type))
+ if (useless_type_conversion_p (record_type, orig_type))
return NULL_TREE;
tail_array_field = NULL_TREE;
/* Here we exactly match the offset being checked. If the types match,
then we can return that field. */
if (cmp == 0
- && lang_hooks.types_compatible_p (orig_type, field_type))
+ && useless_type_conversion_p (orig_type, field_type))
{
if (base_is_ptr)
base = build1 (INDIRECT_REF, record_type, base);
sub_offset / BITS_PER_UNIT), 1);
}
}
- if (lang_hooks.types_compatible_p (orig_type, TREE_TYPE (base))
+ if (useless_type_conversion_p (orig_type, TREE_TYPE (base))
&& integer_zerop (offset))
return base;
type = TREE_TYPE (base);
tree mt_orig = symbol_mem_tag (SSA_NAME_VAR (orig));
if (mt_dest && mt_orig && mt_dest != mt_orig)
return false;
- else if (!lang_hooks.types_compatible_p (type_d, type_o))
+ else if (!useless_type_conversion_p (type_d, type_o))
return false;
else if (get_alias_set (TREE_TYPE (type_d)) !=
get_alias_set (TREE_TYPE (type_o)))
gcc_assert (POINTER_TYPE_P (TREE_TYPE (new_name)));
#if defined ENABLE_CHECKING
- gcc_assert (lang_hooks.types_compatible_p (TREE_TYPE (orig_name),
- TREE_TYPE (new_name)));
+ gcc_assert (useless_type_conversion_p (TREE_TYPE (orig_name),
+ TREE_TYPE (new_name)));
/* If the pointed-to alias sets are different, these two pointers
would never have the same memory tag. In this case, NEW should
}
/* Don't coalesce if the two variables aren't type compatible. */
- if (!lang_hooks.types_compatible_p (TREE_TYPE (root1), TREE_TYPE (root2)))
+ if (!types_compatible_p (TREE_TYPE (root1), TREE_TYPE (root2)))
{
if (debug)
fprintf (debug, " : Incompatible types. No coalesce.\n");
propagation opportunity. */
if (TREE_CODE (val) != SSA_NAME)
{
- if (!lang_hooks.types_compatible_p (op_type, val_type))
+ if (!useless_type_conversion_p (op_type, val_type))
{
val = fold_convert (TREE_TYPE (op), val);
if (!is_gimple_min_invariant (val))
/* In case of a collision, both RHS have to be identical and have the
same VUSE operands. */
- if ((TREE_TYPE (rhs1) == TREE_TYPE (rhs2)
- || lang_hooks.types_compatible_p (TREE_TYPE (rhs1), TREE_TYPE (rhs2)))
+ if (types_compatible_p (TREE_TYPE (rhs1), TREE_TYPE (rhs2))
&& operand_equal_p (rhs1, rhs2, OEP_PURE_SAME))
{
bool ret = compare_ssa_operands_equal (stmt1, stmt2, SSA_OP_VUSE);
&& TREE_CODE (TREE_OPERAND (rhs, 1)) == SSA_NAME
/* Avoid problems with IVopts creating PLUS_EXPRs with a
different type than their operands. */
- && lang_hooks.types_compatible_p (TREE_TYPE (name), TREE_TYPE (rhs)))
+ && useless_type_conversion_p (TREE_TYPE (rhs), TREE_TYPE (name)))
{
bool res;
cond = COND_EXPR_COND (last_stmt (cond_bb));
result = PHI_RESULT (phi);
if (TREE_CODE (cond) != SSA_NAME
- && !lang_hooks.types_compatible_p (TREE_TYPE (cond), TREE_TYPE (result)))
+ && !useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (cond)))
{
tree tmp;
/* If the condition was a naked SSA_NAME and the type is not the
same as the type of the result, then convert the type of the
condition. */
- if (!lang_hooks.types_compatible_p (TREE_TYPE (cond), TREE_TYPE (result)))
+ if (!useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (cond)))
cond = fold_convert (TREE_TYPE (result), cond);
/* We need to know which is the true edge and which is the false
if (oelm1->rank == 0
&& is_gimple_min_invariant (oelm1->op)
- && lang_hooks.types_compatible_p (TREE_TYPE (oelm1->op),
- TREE_TYPE (oelast->op)))
+ && useless_type_conversion_p (TREE_TYPE (oelm1->op),
+ TREE_TYPE (oelast->op)))
{
tree folded = fold_binary (opcode, TREE_TYPE (oelm1->op),
oelm1->op, oelast->op);
return false;
}
+/* Return true if a conversion from either type of TYPE1 and TYPE2
+ to the other is not required. Otherwise return false. */
+
+bool
+types_compatible_p (tree type1, tree type2)
+{
+ return (type1 == type2
+ || (useless_type_conversion_p (type1, type2)
+ && useless_type_conversion_p (type2, type1)));
+}
+
/* Return true if EXPR is a useless type conversion, otherwise return
false. */
equivalent types. The latter requirement could be relaxed if
we emitted a suitable type conversion statement. */
if (!is_gimple_reg_type (TREE_TYPE (param))
- || !lang_hooks.types_compatible_p (TREE_TYPE (param),
- TREE_TYPE (arg)))
+ || !useless_type_conversion_p (TREE_TYPE (param),
+ TREE_TYPE (arg)))
break;
/* The parameter should be a real operand, so that phi node
gcc_assert (code != VEC_LSHIFT_EXPR && code != VEC_RSHIFT_EXPR);
rhs = expand_vector_operation (bsi, type, compute_type, rhs, code);
- if (lang_hooks.types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (rhs)))
+ if (useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs)))
*p_rhs = rhs;
else
*p_rhs = gimplify_build1 (bsi, VIEW_CONVERT_EXPR, TREE_TYPE (lhs), rhs);
}
else if (TREE_CODE (e1) == TREE_CODE (e2)
- && (te1 == te2 || lang_hooks.types_compatible_p (te1, te2))
+ && (te1 == te2
+ || types_compatible_p (te1, te2))
&& operand_equal_p (e1, e2, OEP_PURE_SAME))
return true;
DECL_FIELD_OFFSET (f2), OEP_ONLY_CONST))
return false;
- if (!lang_hooks.types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
+ if (!types_compatible_p (TREE_TYPE (f1), TREE_TYPE (f2)))
return false;
return true;