return n;
}
+static ir_node *equivalent_node_Cast(ir_node *n) {
+ ir_node *pred = get_Cast_op(n);
+ if (get_irn_type(pred) == get_Cast_type(n))
+ n = pred;
+ return n;
+}
+
static ir_node *equivalent_node_Phi(ir_node *n)
{
/* Several optimizations:
CASE(DivMod);
CASE(And);
CASE(Conv);
+ CASE(Cast);
CASE(Phi);
CASE(Proj);
CASE(Id);
return n;
}
+static ir_node *transform_node_Cast(ir_node *n) {
+ ir_node *pred = get_Cast_op(n);
+ type *tp = get_irn_type(pred);
+ if (get_irn_op(pred) == op_Const && get_Const_type(pred) != tp) {
+ n = new_rd_Const_type(NULL, current_ir_graph, get_nodes_block(pred), get_irn_mode(pred),
+ get_Const_tarval(pred), tp);
+ } else if ((get_irn_op(pred) == op_SymConst) && (get_SymConst_value_type(pred) != tp)) {
+ n = new_rd_SymConst_type(NULL, current_ir_graph, get_nodes_block(pred), get_SymConst_symbol(pred),
+ get_SymConst_kind(pred), tp);
+ }
+ return n;
+}
+
/**
* Transform a Div/Mod/DivMod with a non-zero constant. Must be
- * done here instead of equivalent node because in creates new
+ * done here instead of equivalent node because it creates new
* nodes.
* Removes the exceptions and routes the memory to the initial mem.
*
CASE(Cond);
CASE(Eor);
CASE(Not);
+ CASE(Cast);
CASE(Proj);
CASE(Or);
case iro_Shr:
static int node_cmp_attr_SymConst(ir_node *a, ir_node *b)
{
return (get_irn_symconst_attr(a).num != get_irn_symconst_attr(b).num)
- || (get_irn_symconst_attr(a).sym.type_p != get_irn_symconst_attr(b).sym.type_p);
+ || (get_irn_symconst_attr(a).sym.type_p != get_irn_symconst_attr(b).sym.type_p)
+ || (get_irn_symconst_attr(a).tp != get_irn_symconst_attr(b).tp);
}
/** Compares the attributes of two Call nodes. */
ir_node *oldn = n;
opcode iro = get_irn_opcode(n);
- /* Always optimize Phi nodes: part of the construction. */
+ type *old_tp = get_irn_type(n);
+ {
+ int i, arity = get_irn_arity(n);
+ for (i = 0; i < arity && !old_tp; ++i)
+ old_tp = get_irn_type(get_irn_n(n, i));
+ }
+
+ /* Allways optimize Phi nodes: part of the construction. */
if ((!get_opt_optimize()) && (iro != iro_Phi)) return n;
/* constant expression evaluation / constant folding */
/* evaluation was successful -- replace the node. */
obstack_free (current_ir_graph->obst, n);
n = new_Const (get_tarval_mode (tv), tv);
-
- DBG_OPT_ALGSIM0(oldn, n);
+ if (old_tp && get_type_mode(old_tp) == get_tarval_mode (tv))
+ set_Const_type(n, old_tp);
+ DBG_OPT_ALGSIM0(oldn, n);
return n;
}
}
ir_node *oldn = n;
opcode iro = get_irn_opcode(n);
+ type *old_tp = get_irn_type(n);
+ {
+ int i, arity = get_irn_arity(n);
+ for (i = 0; i < arity && !old_tp; ++i)
+ old_tp = get_irn_type(get_irn_n(n, i));
+ }
+
if (!get_opt_optimize() && (get_irn_op(n) != op_Phi)) return n;
/* if not optimize return n */
return n;
}
-
/* constant expression evaluation / constant folding */
if (get_opt_constant_folding()) {
/* constants can not be evaluated */
if ((get_irn_mode(n) != mode_T) && (tv != tarval_bad)) {
/* evaluation was successful -- replace the node. */
n = new_Const (get_tarval_mode (tv), tv);
-
- DBG_OPT_ALGSIM0(oldn, n);
+ if (old_tp && get_type_mode(old_tp) == get_tarval_mode (tv))
+ set_Const_type(n, old_tp);
+ DBG_OPT_ALGSIM0(oldn, n);
return n;
}
}