X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firopt.c;h=25d0cd8a185a0cb3fbabe4f603de93c82b90d3fc;hb=69d11aa49aa17358468bbb2f5506ef5f009514e9;hp=22f08e4ec4f62faf2f993179c57fbe2f09cf26aa;hpb=69962029fe33ca4d798eb967fbfa913b1a6346b9;p=libfirm diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 22f08e4ec..25d0cd8a1 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -23,9 +23,7 @@ * @author Christian Schaefer, Goetz Lindenmaier, Michael Beck * @version $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif +#include "config.h" #include @@ -44,11 +42,11 @@ #include "irhooks.h" #include "irarch.h" #include "hashptr.h" -#include "archop.h" #include "opt_confirms.h" #include "opt_polymorphy.h" #include "irtools.h" -#include "xmalloc.h" +#include "irhooks.h" +#include "array_t.h" /* Make types visible to allow most efficient access */ #include "entity_t.h" @@ -137,9 +135,12 @@ static tarval *computed_value_Sub(const ir_node *n) { tarval *ta; tarval *tb; - /* a - a */ - if (a == b && !is_Bad(a)) - return get_mode_null(mode); + /* NaN - NaN != 0 */ + if (! mode_is_float(mode)) { + /* a - a = 0 */ + if (a == b) + return get_mode_null(mode); + } ta = value_of(a); tb = value_of(b); @@ -226,11 +227,14 @@ static tarval *computed_value_Mul(const ir_node *n) { if (ta != tarval_bad && tb != tarval_bad) { return tarval_mul(ta, tb); } else { - /* a*0 = 0 or 0*b = 0 */ - if (ta == get_mode_null(mode)) - return ta; - if (tb == get_mode_null(mode)) - return tb; + /* a * 0 != 0 if a == NaN or a == Inf */ + if (!mode_is_float(mode)) { + /* a*0 = 0 or 0*b = 0 */ + if (ta == get_mode_null(mode)) + return ta; + if (tb == get_mode_null(mode)) + return tb; + } } return tarval_bad; } /* computed_value_Mul */ @@ -753,8 +757,8 @@ static ir_node *equivalent_node_Block(ir_node *n) ir_node *oldn = n; int n_preds; - /* don't optimize dead blocks */ - if (is_Block_dead(n)) + /* don't optimize dead or labeled blocks */ + if (is_Block_dead(n) || has_Block_label(n)) return n; n_preds = get_Block_n_cfgpreds(n); @@ -1164,13 +1168,28 @@ static ir_node *equivalent_node_And(ir_node *n) { DBG_OPT_ALGSIM0(oldn, n, FS_OPT_AND); return n; } - /* constants are cormalized to right, check this site first */ + /* constants are normalized to right, check this site first */ tv = value_of(b); if (tarval_is_all_one(tv)) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND); return n; } + if (tv != get_tarval_bad()) { + ir_mode *mode = get_irn_mode(n); + if (!mode_is_signed(mode) && is_Conv(a)) { + ir_node *convop = get_Conv_op(a); + ir_mode *convopmode = get_irn_mode(convop); + if (!mode_is_signed(convopmode)) { + if (tarval_is_all_one(tarval_convert_to(tv, convopmode))) { + /* Conv(X) & all_one(mode(X)) = Conv(X) */ + n = a; + DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND); + return n; + } + } + } + } tv = value_of(a); if (tarval_is_all_one(tv)) { n = b; @@ -1209,8 +1228,56 @@ static ir_node *equivalent_node_Conv(ir_node *n) { restart: if (n_mode == a_mode) { /* No Conv necessary */ if (get_Conv_strict(n)) { - /* special case: the predecessor might be a also a Conv */ + ir_node *p = a; + + /* neither Minus nor Abs nor Confirm change the precision, + so we can "look-through" */ + for (;;) { + if (is_Minus(p)) { + p = get_Minus_op(p); + } else if (is_Abs(p)) { + p = get_Abs_op(p); + } else if (is_Confirm(p)) { + p = get_Confirm_value(p); + } else { + /* stop here */ + break; + } + } + if (is_Conv(p) && get_Conv_strict(p)) { + /* we known already, that a_mode == n_mode, and neither + Abs nor Minus change the mode, so the second Conv + can be kicked */ + assert(get_irn_mode(p) == n_mode); + n = a; + DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV); + return n; + } + if (is_Proj(p)) { + ir_node *pred = get_Proj_pred(p); + if (is_Load(pred)) { + /* Loads always return with the exact precision of n_mode */ + assert(get_Load_mode(pred) == n_mode); + n = a; + DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV); + return n; + } + if (is_Proj(pred) && get_Proj_proj(pred) == pn_Start_T_args) { + pred = get_Proj_pred(pred); + if (is_Start(pred)) { + /* Arguments always return with the exact precision, + as strictConv's are place before Call -- if the + caller was compiled with the same setting. + Otherwise, the semantics is probably still right. */ + assert(get_irn_mode(p) == n_mode); + n = a; + DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV); + return n; + } + } + } if (is_Conv(a)) { + /* special case: the immediate predecessor is also a Conv */ if (! get_Conv_strict(a)) { /* first one is not strict, kick it */ a = get_Conv_op(a); @@ -1219,22 +1286,15 @@ restart: goto restart; } /* else both are strict conv, second is superfluous */ - } else if (is_Proj(a)) { - ir_node *pred = get_Proj_pred(a); - if (is_Load(pred)) { - /* loads always return with the exact precision of n_mode */ - assert(get_Load_mode(pred) == n_mode); - return a; - } - /* leave strict floating point Conv's */ - return n; - } else { - /* leave strict floating point Conv's */ + n = a; + DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV); return n; } + } else { + n = a; + DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV); + return n; } - n = a; - DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV); } else if (is_Conv(a)) { /* Conv(Conv(b)) */ ir_node *b = get_Conv_op(a); ir_mode *b_mode = get_irn_mode(b); @@ -1253,25 +1313,21 @@ restart: if (n_mode == mode_b) { n = b; /* Convb(Conv*(xxxb(...))) == xxxb(...) */ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV); + return n; } else if (get_mode_arithmetic(n_mode) == get_mode_arithmetic(a_mode)) { - if (smaller_mode(b_mode, a_mode)) { + if (values_in_mode(b_mode, a_mode)) { n = b; /* ConvS(ConvL(xxxS(...))) == xxxS(...) */ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV); + return n; } } } - if (mode_is_int(n_mode) && mode_is_float(a_mode)) { + if (mode_is_int(n_mode) && get_mode_arithmetic(a_mode) == irma_ieee754) { /* ConvI(ConvF(I)) -> I, iff float mantissa >= int mode */ - size_t int_mantissa = get_mode_size_bits(n_mode) - (mode_is_signed(n_mode) ? 1 : 0); - size_t float_mantissa; - /* FIXME There is no way to get the mantissa size of a mode */ - switch (get_mode_size_bits(a_mode)) { - case 32: float_mantissa = 23 + 1; break; // + 1 for implicit 1 - case 64: float_mantissa = 52 + 1; break; - case 80: float_mantissa = 64 + 1; break; - default: float_mantissa = 0; break; - } - if (float_mantissa != 0 && float_mantissa >= int_mantissa) { + unsigned int_mantissa = get_mode_size_bits(n_mode) - (mode_is_signed(n_mode) ? 1 : 0); + unsigned float_mantissa = tarval_ieee754_get_mantissa_size(a_mode); + + if (float_mantissa >= int_mantissa) { n = b; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV); return n; @@ -1283,6 +1339,7 @@ restart: set_Conv_strict(b, 1); n = b; /* ConvA(ConvB(ConvA(...))) == ConvA(...) */ DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV); + return n; } } } @@ -1869,10 +1926,11 @@ static int is_const_Phi(ir_node *n) { if (! is_Phi(n) || get_irn_arity(n) == 0) return 0; - for (i = get_irn_arity(n) - 1; i >= 0; --i) + for (i = get_irn_arity(n) - 1; i >= 0; --i) { if (! is_Const(get_irn_n(n, i))) return 0; - return 1; + } + return 1; } /* is_const_Phi */ typedef tarval *(*tarval_sub_type)(tarval *a, tarval *b, ir_mode *mode); @@ -1940,8 +1998,7 @@ static ir_node *apply_binop_on_phi(ir_node *phi, tarval *other, tarval *(*eval)( irg = current_ir_graph; for (i = 0; i < n; ++i) { pred = get_irn_n(phi, i); - res[i] = new_r_Const_type(irg, get_irg_start_block(irg), - mode, res[i], get_Const_type(pred)); + res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred)); } return new_r_Phi(irg, get_nodes_block(phi), n, (ir_node **)res, mode); } /* apply_binop_on_phi */ @@ -1985,7 +2042,7 @@ static ir_node *apply_binop_on_2_phis(ir_node *a, ir_node *b, tarval *(*eval)(), irg = current_ir_graph; for (i = 0; i < n; ++i) { pred = get_irn_n(a, i); - res[i] = new_r_Const_type(irg, get_irg_start_block(irg), mode, res[i], get_Const_type(pred)); + res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred)); } return new_r_Phi(irg, get_nodes_block(a), n, (ir_node **)res, mode); } /* apply_binop_on_2_phis */ @@ -2022,8 +2079,7 @@ static ir_node *apply_unop_on_phi(ir_node *phi, tarval *(*eval)(tarval *)) { irg = current_ir_graph; for (i = 0; i < n; ++i) { pred = get_irn_n(phi, i); - res[i] = new_r_Const_type(irg, get_irg_start_block(irg), - mode, res[i], get_Const_type(pred)); + res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred)); } return new_r_Phi(irg, get_nodes_block(phi), n, (ir_node **)res, mode); } /* apply_unop_on_phi */ @@ -2057,8 +2113,7 @@ static ir_node *apply_conv_on_phi(ir_node *phi, ir_mode *mode) { irg = current_ir_graph; for (i = 0; i < n; ++i) { pred = get_irn_n(phi, i); - res[i] = new_r_Const_type(irg, get_irg_start_block(irg), - mode, res[i], get_Const_type(pred)); + res[i] = new_r_Const_type(irg, res[i], get_Const_type(pred)); } return new_r_Phi(irg, get_nodes_block(phi), n, (ir_node **)res, mode); } /* apply_conv_on_phi */ @@ -2215,7 +2270,7 @@ static ir_node *transform_node_Add(ir_node *n) { current_ir_graph, block, a, - new_r_Const_long(current_ir_graph, block, mode, 2), + new_Const_long(mode, 2), mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_A_A); return n; @@ -2224,7 +2279,7 @@ static ir_node *transform_node_Add(ir_node *n) { n = new_rd_Sub( get_irn_dbg_info(n), current_ir_graph, - get_irn_n(n, -1), + get_nodes_block(n), b, get_Minus_op(a), mode); @@ -2235,7 +2290,7 @@ static ir_node *transform_node_Add(ir_node *n) { n = new_rd_Sub( get_irn_dbg_info(n), current_ir_graph, - get_irn_n(n, -1), + get_nodes_block(n), a, get_Minus_op(b), mode); @@ -2249,15 +2304,14 @@ static ir_node *transform_node_Add(ir_node *n) { if (is_Const(b) && is_Const_one(b)) { /* ~x + 1 = -x */ - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_PLUS_1); return n; } if (op == b) { /* ~x + x = -1 */ - ir_node *blk = get_irn_n(n, -1); - n = new_r_Const(current_ir_graph, blk, mode, get_mode_minus_one(mode)); + n = new_Const(get_mode_minus_one(mode)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_X_NOT_X); return n; } @@ -2267,8 +2321,7 @@ static ir_node *transform_node_Add(ir_node *n) { if (op == a) { /* x + ~x = -1 */ - ir_node *blk = get_irn_n(n, -1); - n = new_r_Const(current_ir_graph, blk, mode, get_mode_minus_one(mode)); + n = new_Const(get_mode_minus_one(mode)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_X_NOT_X); return n; } @@ -2285,10 +2338,8 @@ static ir_node *const_negate(ir_node *cnst) { tarval *tv = tarval_neg(get_Const_tarval(cnst)); dbg_info *dbgi = get_irn_dbg_info(cnst); ir_graph *irg = get_irn_irg(cnst); - ir_node *block = get_nodes_block(cnst); - ir_mode *mode = get_irn_mode(cnst); if (tv == tarval_bad) return NULL; - return new_rd_Const(dbgi, irg, block, mode, tv); + return new_rd_Const(dbgi, irg, tv); } /** @@ -2319,7 +2370,20 @@ static ir_node *transform_node_Sub(ir_node *n) { if (is_Const(b) && is_Const_null(b) && mode_is_reference(lmode)) { /* a Sub(a, NULL) is a hidden Conv */ dbg_info *dbg = get_irn_dbg_info(n); - return new_rd_Conv(dbg, current_ir_graph, get_nodes_block(n), a, mode); + n = new_rd_Conv(dbg, current_ir_graph, get_nodes_block(n), a, mode); + DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_TO_CONV); + return n; + } + + if (mode == lmode && + get_mode_arithmetic(mode) == irma_twos_complement && + is_Const(a) && + get_Const_tarval(a) == get_mode_minus_one(mode)) { + /* -1 - x -> ~x */ + dbg_info *dbg = get_irn_dbg_info(n); + n = new_rd_Not(dbg, current_ir_graph, get_nodes_block(n), b, mode); + DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_TO_NOT); + return n; } } @@ -2330,7 +2394,7 @@ restart: if (mode_is_float(mode) && (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic)) return n; - if (is_Const(b) && get_irn_mode(b) != mode_P) { + if (is_Const(b) && !mode_is_reference(get_irn_mode(b))) { /* a - C -> a + (-C) */ ir_node *cnst = const_negate(b); if (cnst != NULL) { @@ -2363,18 +2427,30 @@ restart: n = new_rd_Add(dbg, irg, block, a, right, mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MINUS); return n; - } else if (is_Sub(b)) { /* a - (b - c) -> a + (c - b) */ + } else if (is_Sub(b)) { + /* a - (b - c) -> a + (c - b) + * -> (a - b) + c iff (b - c) is a pointer */ ir_graph *irg = current_ir_graph; dbg_info *s_dbg = get_irn_dbg_info(b); ir_node *s_block = get_nodes_block(b); - ir_node *s_left = get_Sub_right(b); - ir_node *s_right = get_Sub_left(b); + ir_node *s_left = get_Sub_left(b); + ir_node *s_right = get_Sub_right(b); ir_mode *s_mode = get_irn_mode(b); - ir_node *sub = new_rd_Sub(s_dbg, irg, s_block, s_left, s_right, s_mode); - dbg_info *a_dbg = get_irn_dbg_info(n); - ir_node *a_block = get_nodes_block(n); + if (mode_is_reference(s_mode)) { + ir_node *sub = new_rd_Sub(s_dbg, irg, s_block, a, s_left, mode); + dbg_info *a_dbg = get_irn_dbg_info(n); + ir_node *a_block = get_nodes_block(n); + + if (s_mode != mode) + s_right = new_r_Conv(irg, a_block, s_right, mode); + n = new_rd_Add(a_dbg, irg, a_block, sub, s_right, mode); + } else { + ir_node *sub = new_rd_Sub(s_dbg, irg, s_block, s_right, s_left, s_mode); + dbg_info *a_dbg = get_irn_dbg_info(n); + ir_node *a_block = get_nodes_block(n); - n = new_rd_Add(a_dbg, irg, a_block, a, sub, mode); + n = new_rd_Add(a_dbg, irg, a_block, a, sub, mode); + } DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_TO_ADD); return n; } else if (is_Mul(b)) { /* a - (b * C) -> a + (b * -C) */ @@ -2403,7 +2479,7 @@ restart: n = new_rd_Minus( get_irn_dbg_info(n), current_ir_graph, - get_irn_n(n, -1), + get_nodes_block(n), b, mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_0_A); @@ -2418,7 +2494,7 @@ restart: if (left == b) { if (mode != get_irn_mode(right)) { /* This Sub is an effective Cast */ - right = new_r_Conv(get_irn_irg(n), get_irn_n(n, -1), right, mode); + right = new_r_Conv(get_irn_irg(n), get_nodes_block(n), right, mode); } n = right; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_ADD_SUB); @@ -2426,7 +2502,7 @@ restart: } else if (right == b) { if (mode != get_irn_mode(left)) { /* This Sub is an effective Cast */ - left = new_r_Conv(get_irn_irg(n), get_irn_n(n, -1), left, mode); + left = new_r_Conv(get_irn_irg(n), get_nodes_block(n), left, mode); } n = left; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_ADD_SUB); @@ -2443,20 +2519,20 @@ restart: if (left == a) { ir_mode *r_mode = get_irn_mode(right); - n = new_r_Minus(get_irn_irg(n), get_irn_n(n, -1), right, r_mode); + n = new_r_Minus(get_irn_irg(n), get_nodes_block(n), right, r_mode); if (mode != r_mode) { /* This Sub is an effective Cast */ - n = new_r_Conv(get_irn_irg(n), get_irn_n(n, -1), n, mode); + n = new_r_Conv(get_irn_irg(n), get_nodes_block(n), n, mode); } DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_ADD_SUB); return n; } else if (right == a) { ir_mode *l_mode = get_irn_mode(left); - n = new_r_Minus(get_irn_irg(n), get_irn_n(n, -1), left, l_mode); + n = new_r_Minus(get_irn_irg(n), get_nodes_block(n), left, l_mode); if (mode != l_mode) { /* This Sub is an effective Cast */ - n = new_r_Conv(get_irn_irg(n), get_irn_n(n, -1), n, mode); + n = new_r_Conv(get_irn_irg(n), get_nodes_block(n), n, mode); } DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_ADD_SUB); return n; @@ -2491,7 +2567,7 @@ restart: ir_node *mb = get_Mul_right(a); if (ma == b) { - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); n = new_rd_Mul( get_irn_dbg_info(n), current_ir_graph, blk, @@ -2500,13 +2576,13 @@ restart: get_irn_dbg_info(n), current_ir_graph, blk, mb, - new_r_Const_long(current_ir_graph, blk, mode, 1), + new_Const_long(mode, 1), mode), mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MUL_A_X_A); return n; } else if (mb == b) { - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); n = new_rd_Mul( get_irn_dbg_info(n), current_ir_graph, blk, @@ -2515,7 +2591,7 @@ restart: get_irn_dbg_info(n), current_ir_graph, blk, ma, - new_r_Const_long(current_ir_graph, blk, mode, 1), + new_Const_long(mode, 1), mode), mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_MUL_A_X_A); @@ -2525,7 +2601,7 @@ restart: if (is_Sub(a)) { /* (x - y) - b -> x - (y + b) */ ir_node *x = get_Sub_left(a); ir_node *y = get_Sub_right(a); - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); ir_mode *m_b = get_irn_mode(b); ir_mode *m_y = get_irn_mode(y); ir_mode *add_mode; @@ -2562,8 +2638,8 @@ restart: tv = tarval_add(tv, get_mode_one(mode)); if (tv != tarval_bad) { - ir_node *blk = get_irn_n(n, -1); - ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv); + ir_node *blk = get_nodes_block(n); + ir_node *c = new_Const(tv); n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, blk, get_Not_op(b), c, mode); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_C_NOT_X); return n; @@ -2587,14 +2663,14 @@ static ir_node *transform_node_Mul2n(ir_node *n, ir_mode *mode) { if (ta == get_mode_one(smode)) { /* (L)1 * (L)b = (L)b */ - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); n = new_rd_Conv(get_irn_dbg_info(n), current_ir_graph, blk, b, mode); DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_1); return n; } else if (ta == get_mode_minus_one(smode)) { /* (L)-1 * (L)b = (L)b */ - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, b, smode); n = new_rd_Conv(get_irn_dbg_info(n), current_ir_graph, blk, n, mode); DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_MINUS_1); @@ -2609,7 +2685,7 @@ static ir_node *transform_node_Mul2n(ir_node *n, ir_mode *mode) { } else if (tb == get_mode_minus_one(smode)) { /* (L)a * (L)-1 = (L)-a */ - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, a, smode); n = new_rd_Conv(get_irn_dbg_info(n), current_ir_graph, blk, n, mode); DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_MINUS_1); @@ -2645,7 +2721,7 @@ static ir_node *transform_node_Mul(ir_node *n) { else if (value_of(b) == get_mode_minus_one(mode)) r = a; if (r) { - n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), r, mode); + n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), r, mode); DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_MUL_MINUS_1); return n; } @@ -2693,7 +2769,8 @@ static ir_node *transform_node_Mul(ir_node *n) { if (get_mode_arithmetic(mode) == irma_ieee754) { if (is_Const(a)) { tarval *tv = get_Const_tarval(a); - if (tarval_ieee754_get_exponent(tv) == 1 && tarval_ieee754_zero_mantissa(tv)) { + if (tarval_ieee754_get_exponent(tv) == 1 && tarval_ieee754_zero_mantissa(tv) + && !tarval_is_negative(tv)) { /* 2.0 * b = b + b */ n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), b, b, mode); DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_ADD_A_A); @@ -2702,7 +2779,8 @@ static ir_node *transform_node_Mul(ir_node *n) { } else if (is_Const(b)) { tarval *tv = get_Const_tarval(b); - if (tarval_ieee754_get_exponent(tv) == 1 && tarval_ieee754_zero_mantissa(tv)) { + if (tarval_ieee754_get_exponent(tv) == 1 && tarval_ieee754_zero_mantissa(tv) + && !tarval_is_negative(tv)) { /* a * 2.0 = a + a */ n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), a, a, mode); DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_ADD_A_A); @@ -2751,7 +2829,7 @@ static ir_node *transform_node_Div(ir_node *n) { value = n; tv = value_of(n); if (tv != tarval_bad) { - value = new_Const(get_tarval_mode(tv), tv); + value = new_Const(tv); DBG_OPT_CSTEVAL(n, value); goto make_tuple; @@ -2762,7 +2840,7 @@ static ir_node *transform_node_Div(ir_node *n) { if (a == b && value_not_zero(a, &dummy)) { /* BEWARE: we can optimize a/a to 1 only if this cannot cause a exception */ - value = new_Const(mode, get_mode_one(mode)); + value = new_Const(get_mode_one(mode)); DBG_OPT_CSTEVAL(n, value); goto make_tuple; } else { @@ -2771,7 +2849,7 @@ static ir_node *transform_node_Div(ir_node *n) { if (tv == get_mode_minus_one(mode)) { /* a / -1 */ - value = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), a, mode); + value = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), a, mode); DBG_OPT_CSTEVAL(n, value); goto make_tuple; } @@ -2787,11 +2865,10 @@ static ir_node *transform_node_Div(ir_node *n) { make_tuple: /* Turn Div into a tuple (mem, jmp, bad, value) */ mem = get_Div_mem(n); - blk = get_irn_n(n, -1); + blk = get_nodes_block(n); /* skip a potential Pin */ - if (is_Pin(mem)) - mem = get_Pin_op(mem); + mem = skip_Pin(mem); turn_into_tuple(n, pn_Div_max); set_Tuple_pred(n, pn_Div_M, mem); set_Tuple_pred(n, pn_Div_X_regular, new_r_Jmp(current_ir_graph, blk)); @@ -2839,7 +2916,7 @@ static ir_node *transform_node_Mod(ir_node *n) { value = n; tv = value_of(n); if (tv != tarval_bad) { - value = new_Const(get_tarval_mode(tv), tv); + value = new_Const(tv); DBG_OPT_CSTEVAL(n, value); goto make_tuple; @@ -2850,7 +2927,7 @@ static ir_node *transform_node_Mod(ir_node *n) { if (a == b && value_not_zero(a, &dummy)) { /* BEWARE: we can optimize a%a to 0 only if this cannot cause a exception */ - value = new_Const(mode, get_mode_null(mode)); + value = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, value); goto make_tuple; } else { @@ -2859,7 +2936,7 @@ static ir_node *transform_node_Mod(ir_node *n) { if (tv == get_mode_minus_one(mode)) { /* a % -1 = 0 */ - value = new_Const(mode, get_mode_null(mode)); + value = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, value); goto make_tuple; } @@ -2875,11 +2952,10 @@ static ir_node *transform_node_Mod(ir_node *n) { make_tuple: /* Turn Mod into a tuple (mem, jmp, bad, value) */ mem = get_Mod_mem(n); - blk = get_irn_n(n, -1); + blk = get_nodes_block(n); /* skip a potential Pin */ - if (is_Pin(mem)) - mem = get_Pin_op(mem); + mem = skip_Pin(mem); turn_into_tuple(n, pn_Mod_max); set_Tuple_pred(n, pn_Mod_M, mem); set_Tuple_pred(n, pn_Mod_X_regular, new_r_Jmp(current_ir_graph, blk)); @@ -2937,7 +3013,7 @@ static ir_node *transform_node_DivMod(ir_node *n) { if (tb != tarval_bad) { if (tb == get_mode_one(get_tarval_mode(tb))) { va = a; - vb = new_Const(mode, get_mode_null(mode)); + vb = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, vb); goto make_tuple; } else if (ta != tarval_bad) { @@ -2947,14 +3023,14 @@ static ir_node *transform_node_DivMod(ir_node *n) { Jmp for X result!? */ resb = tarval_mod(ta, tb); if (resb == tarval_bad) return n; /* Causes exception! */ - va = new_Const(mode, resa); - vb = new_Const(mode, resb); + va = new_Const(resa); + vb = new_Const(resb); DBG_OPT_CSTEVAL(n, va); DBG_OPT_CSTEVAL(n, vb); goto make_tuple; } else if (mode_is_signed(mode) && tb == get_mode_minus_one(mode)) { - va = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), a, mode); - vb = new_Const(mode, get_mode_null(mode)); + va = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), a, mode); + vb = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, va); DBG_OPT_CSTEVAL(n, vb); goto make_tuple; @@ -2967,8 +3043,8 @@ static ir_node *transform_node_DivMod(ir_node *n) { } else if (a == b) { if (value_not_zero(a, &dummy)) { /* a/a && a != 0 */ - va = new_Const(mode, get_mode_one(mode)); - vb = new_Const(mode, get_mode_null(mode)); + va = new_Const(get_mode_one(mode)); + vb = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(n, va); DBG_OPT_CSTEVAL(n, vb); goto make_tuple; @@ -2988,10 +3064,9 @@ static ir_node *transform_node_DivMod(ir_node *n) { make_tuple: mem = get_DivMod_mem(n); /* skip a potential Pin */ - if (is_Pin(mem)) - mem = get_Pin_op(mem); + mem = skip_Pin(mem); - blk = get_irn_n(n, -1); + blk = get_nodes_block(n); turn_into_tuple(n, pn_DivMod_max); set_Tuple_pred(n, pn_DivMod_M, mem); set_Tuple_pred(n, pn_DivMod_X_regular, new_r_Jmp(current_ir_graph, blk)); @@ -3012,10 +3087,10 @@ static ir_node *transform_node_Quot(ir_node *n) { if (get_mode_arithmetic(mode) == irma_ieee754) { ir_node *b = get_Quot_right(n); + tarval *tv = value_of(b); - if (is_Const(b)) { - tarval *tv = get_Const_tarval(b); - int rem; + if (tv != tarval_bad) { + int rem = tarval_fp_ops_enabled(); /* * Floating point constant folding might be disabled here to @@ -3023,23 +3098,22 @@ static ir_node *transform_node_Quot(ir_node *n) { * However, as we check for exact result, doing it is safe. * Switch it on. */ - rem = tarval_enable_fp_ops(1); + tarval_enable_fp_ops(1); tv = tarval_quo(get_mode_one(mode), tv); - (void)tarval_enable_fp_ops(rem); + tarval_enable_fp_ops(rem); /* Do the transformation if the result is either exact or we are not using strict rules. */ if (tv != tarval_bad && (tarval_ieee754_get_exact() || (get_irg_fp_model(current_ir_graph) & fp_strict_algebraic) == 0)) { - ir_node *blk = get_irn_n(n, -1); - ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv); + ir_node *blk = get_nodes_block(n); + ir_node *c = new_Const(tv); ir_node *a = get_Quot_left(n); ir_node *m = new_rd_Mul(get_irn_dbg_info(n), current_ir_graph, blk, a, c, mode); ir_node *mem = get_Quot_mem(n); /* skip a potential Pin */ - if (is_Pin(mem)) - mem = get_Pin_op(mem); + mem = skip_Pin(mem); turn_into_tuple(n, pn_Quot_max); set_Tuple_pred(n, pn_Quot_M, mem); set_Tuple_pred(n, pn_Quot_X_regular, new_r_Jmp(current_ir_graph, blk)); @@ -3193,7 +3267,7 @@ static ir_node *transform_bitwise_distributive(ir_node *n, ir_mode *a_mode = get_irn_mode(a_op); ir_mode *b_mode = get_irn_mode(b_op); if(a_mode == b_mode && (mode_is_int(a_mode) || a_mode == mode_b)) { - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); n = exact_copy(n); set_binop_left(n, a_op); @@ -3245,7 +3319,7 @@ static ir_node *transform_bitwise_distributive(ir_node *n, if (c != NULL) { /* (a sop c) & (b sop c) => (a & b) sop c */ - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); ir_node *new_n = exact_copy(n); set_binop_left(new_n, op1); @@ -3438,21 +3512,21 @@ static ir_node *transform_node_Eor(ir_node *n) { if (a == b) { /* a ^ a = 0 */ - n = new_rd_Const(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), - mode, get_mode_null(mode)); + n = new_rd_Const(get_irn_dbg_info(n), current_ir_graph, + get_mode_null(mode)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_A_A); } else if (mode == mode_b && is_Proj(a) && is_Const(b) && is_Const_one(b) && is_Cmp(get_Proj_pred(a))) { /* The Eor negates a Cmp. The Cmp has the negated result anyways! */ - n = new_r_Proj(current_ir_graph, get_irn_n(n, -1), get_Proj_pred(a), + n = new_r_Proj(current_ir_graph, get_nodes_block(n), get_Proj_pred(a), mode_b, get_negated_pnc(get_Proj_proj(a), mode)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT_BOOL); } else if (is_Const(b)) { if (is_Not(a)) { /* ~x ^ const -> x ^ ~const */ - ir_node *cnst = new_Const(mode, tarval_not(get_Const_tarval(b))); + ir_node *cnst = new_Const(tarval_not(get_Const_tarval(b))); ir_node *not_op = get_Not_op(a); dbg_info *dbg = get_irn_dbg_info(n); ir_graph *irg = current_ir_graph; @@ -3486,7 +3560,7 @@ static ir_node *transform_node_Not(ir_node *n) { is_Proj(a) && is_Cmp(get_Proj_pred(a))) { /* We negate a Cmp. The Cmp has the negated result anyways! */ - n = new_r_Proj(current_ir_graph, get_irn_n(n, -1), get_Proj_pred(a), + n = new_r_Proj(current_ir_graph, get_nodes_block(n), get_Proj_pred(a), mode_b, get_negated_pnc(get_Proj_proj(a), mode_b)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_CMP); return n; @@ -3494,7 +3568,7 @@ static ir_node *transform_node_Not(ir_node *n) { if (is_Eor(a)) { ir_node *eor_b = get_Eor_right(a); if (is_Const(eor_b)) { /* ~(x ^ const) -> x ^ ~const */ - ir_node *cnst = new_Const(mode, tarval_not(get_Const_tarval(eor_b))); + ir_node *cnst = new_Const(tarval_not(get_Const_tarval(eor_b))); ir_node *eor_a = get_Eor_left(a); dbg_info *dbg = get_irn_dbg_info(n); ir_graph *irg = current_ir_graph; @@ -3510,14 +3584,14 @@ static ir_node *transform_node_Not(ir_node *n) { ir_graph *irg = current_ir_graph; ir_node *block = get_nodes_block(n); ir_node *add_l = get_Minus_op(a); - ir_node *add_r = new_rd_Const(dbg, irg, block, mode, get_mode_minus_one(mode)); + ir_node *add_r = new_rd_Const(dbg, irg, get_mode_minus_one(mode)); n = new_rd_Add(dbg, irg, block, add_l, add_r, mode); } else if (is_Add(a)) { ir_node *add_r = get_Add_right(a); if (is_Const(add_r) && is_Const_all_one(add_r)) { /* ~(x + -1) = -x */ ir_node *op = get_Add_left(a); - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, get_irn_mode(n)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_MINUS_1); } @@ -3549,8 +3623,8 @@ static ir_node *transform_node_Minus(ir_node *n) { /* -(~x) = x + 1 */ ir_node *op = get_Not_op(a); tarval *tv = get_mode_one(mode); - ir_node *blk = get_irn_n(n, -1); - ir_node *c = new_r_Const(current_ir_graph, blk, mode, tv); + ir_node *blk = get_nodes_block(n); + ir_node *c = new_Const(tv); n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, blk, op, c, mode); DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_MINUS_NOT); return n; @@ -3565,7 +3639,7 @@ static ir_node *transform_node_Minus(ir_node *n) { /* -(a >>u (size-1)) = a >>s (size-1) */ ir_node *v = get_Shr_left(a); - n = new_rd_Shrs(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), v, c, mode); + n = new_rd_Shrs(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), v, c, mode); DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_PREDICATE); return n; } @@ -3581,7 +3655,7 @@ static ir_node *transform_node_Minus(ir_node *n) { /* -(a >>s (size-1)) = a >>u (size-1) */ ir_node *v = get_Shrs_left(a); - n = new_rd_Shr(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), v, c, mode); + n = new_rd_Shr(get_irn_dbg_info(n), current_ir_graph, get_nodes_block(n), v, c, mode); DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_PREDICATE); return n; } @@ -3592,7 +3666,7 @@ static ir_node *transform_node_Minus(ir_node *n) { /* - (a-b) = b - a */ ir_node *la = get_Sub_left(a); ir_node *ra = get_Sub_right(a); - ir_node *blk = get_irn_n(n, -1); + ir_node *blk = get_nodes_block(n); n = new_rd_Sub(get_irn_dbg_info(n), current_ir_graph, blk, ra, la, mode); DBG_OPT_ALGSIM2(oldn, a, n, FS_OPT_MINUS_SUB); @@ -3602,10 +3676,11 @@ static ir_node *transform_node_Minus(ir_node *n) { if (is_Mul(a)) { /* -(a * const) -> a * -const */ ir_node *mul_l = get_Mul_left(a); ir_node *mul_r = get_Mul_right(a); - if (is_Const(mul_r)) { - tarval *tv = tarval_neg(get_Const_tarval(mul_r)); - if(tv != tarval_bad) { - ir_node *cnst = new_Const(mode, tv); + tarval *tv = value_of(mul_r); + if (tv != tarval_bad) { + tv = tarval_neg(tv); + if (tv != tarval_bad) { + ir_node *cnst = new_Const(tv); dbg_info *dbg = get_irn_dbg_info(a); ir_graph *irg = current_ir_graph; ir_node *block = get_nodes_block(a); @@ -3628,8 +3703,7 @@ static ir_node *transform_node_Cast(ir_node *n) { ir_type *tp = get_irn_type(n); if (is_Const(pred) && get_Const_type(pred) != tp) { - n = new_rd_Const_type(NULL, current_ir_graph, get_irn_n(pred, -1), get_irn_mode(pred), - get_Const_tarval(pred), tp); + n = new_rd_Const_type(NULL, current_ir_graph, get_Const_tarval(pred), tp); DBG_OPT_CSTEVAL(oldn, n); } else if (is_SymConst(pred) && get_SymConst_value_type(pred) != tp) { n = new_rd_SymConst_type(NULL, current_ir_graph, get_irn_n(pred, -1), get_irn_mode(pred), @@ -3716,8 +3790,7 @@ static ir_node *transform_node_Proj_Div(ir_node *proj) { if (confirm == NULL) { /* we are sure we have a Const != 0 */ new_mem = get_Div_mem(div); - if (is_Pin(new_mem)) - new_mem = get_Pin_op(new_mem); + new_mem = skip_Pin(new_mem); set_Div_mem(div, new_mem); set_irn_pinned(div, op_pin_state_floats); } @@ -3767,8 +3840,7 @@ static ir_node *transform_node_Proj_Mod(ir_node *proj) { if (confirm == NULL) { /* we are sure we have a Const != 0 */ new_mem = get_Mod_mem(mod); - if (is_Pin(new_mem)) - new_mem = get_Pin_op(new_mem); + new_mem = skip_Pin(new_mem); set_Mod_mem(mod, new_mem); set_irn_pinned(mod, op_pin_state_floats); } @@ -3798,7 +3870,7 @@ static ir_node *transform_node_Proj_Mod(ir_node *proj) { if (get_Mod_left(mod) == b) { /* a % a = 0 if a != 0 */ ir_mode *mode = get_irn_mode(proj); - ir_node *res = new_Const(mode, get_mode_null(mode)); + ir_node *res = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(mod, res); return res; @@ -3826,8 +3898,7 @@ static ir_node *transform_node_Proj_DivMod(ir_node *proj) { if (confirm == NULL) { /* we are sure we have a Const != 0 */ new_mem = get_DivMod_mem(divmod); - if (is_Pin(new_mem)) - new_mem = get_Pin_op(new_mem); + new_mem = skip_Pin(new_mem); set_DivMod_mem(divmod, new_mem); set_irn_pinned(divmod, op_pin_state_floats); } @@ -3858,7 +3929,7 @@ static ir_node *transform_node_Proj_DivMod(ir_node *proj) { if (get_DivMod_left(divmod) == b) { /* a % a = 0 if a != 0 */ ir_mode *mode = get_irn_mode(proj); - ir_node *res = new_Const(mode, get_mode_null(mode)); + ir_node *res = new_Const(get_mode_null(mode)); DBG_OPT_CSTEVAL(divmod, res); return res; @@ -3883,7 +3954,7 @@ static ir_node *transform_node_Proj_Cond(ir_node *proj) { /* we have a constant switch */ long num = get_Proj_proj(proj); - if (num != get_Cond_defaultProj(n)) { /* we cannot optimize default Proj's yet */ + if (num != get_Cond_default_proj(n)) { /* we cannot optimize default Proj's yet */ if (get_tarval_long(tb) == num) { /* Do NOT create a jump here, or we will have 2 control flow ops * in a block. This case is optimized away in optimize_cf(). */ @@ -3904,7 +3975,7 @@ static ir_node *transform_node_Proj_Cond(ir_node *proj) { */ static ir_node *create_zero_const(ir_mode *mode) { tarval *tv = get_mode_null(mode); - ir_node *cnst = new_Const(mode, tv); + ir_node *cnst = new_Const(tv); return cnst; } @@ -3951,12 +4022,12 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { /* we can evaluate some cases directly */ switch (proj_nr) { case pn_Cmp_False: - return new_Const(mode_b, get_tarval_b_false()); + return new_Const(get_tarval_b_false()); case pn_Cmp_True: - return new_Const(mode_b, get_tarval_b_true()); + return new_Const(get_tarval_b_true()); case pn_Cmp_Leg: if (!mode_is_float(get_irn_mode(left))) - return new_Const(mode_b, get_tarval_b_true()); + return new_Const(get_tarval_b_true()); break; default: break; @@ -4120,6 +4191,31 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_OP_OP); } } + if (is_And(left) && is_Const(right)) { + ir_node *ll = get_binop_left(left); + ir_node *lr = get_binop_right(left); + if (is_Shr(ll) && is_Const(lr)) { + /* Cmp((x >>u c1) & c2, c3) = Cmp(x & (c2 << c1), c3 << c1) */ + ir_node *block = get_nodes_block(n); + ir_mode *mode = get_irn_mode(left); + + ir_node *llr = get_Shr_right(ll); + if (is_Const(llr)) { + ir_graph *irg = current_ir_graph; + dbg_info *dbg = get_irn_dbg_info(left); + + tarval *c1 = get_Const_tarval(llr); + tarval *c2 = get_Const_tarval(lr); + tarval *c3 = get_Const_tarval(right); + tarval *mask = tarval_shl(c2, c1); + tarval *value = tarval_shl(c3, c1); + + left = new_rd_And(dbg, irg, block, get_Shr_left(ll), new_Const(mask), mode); + right = new_Const(value); + changed |= 1; + } + } + } } /* mode_is_int(...) */ } /* proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg */ @@ -4165,9 +4261,9 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { * later and may help to normalize more compares. * Of course this is only possible for integer values. */ - if (is_Const(right)) { + tv = value_of(right); + if (tv != tarval_bad) { mode = get_irn_mode(right); - tv = get_Const_tarval(right); /* TODO extend to arbitrary constants */ if (is_Conv(left) && tarval_is_null(tv)) { @@ -4326,7 +4422,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { else if (proj_nr == pn_Cmp_Le || proj_nr == pn_Cmp_Lt) { if (tv != tarval_bad) { /* c >= 0 : Abs(a) <= c ==> (unsigned)(a + c) <= 2*c */ - if (get_irn_op(left) == op_Abs) { // TODO something is missing here + if (is_Abs(left)) { // TODO something is missing here } } } @@ -4347,7 +4443,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (mask != tv) { /* TODO: move to constant evaluation */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } @@ -4384,7 +4480,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (! tarval_is_null(get_Const_tarval(c1))) { /* TODO: move to constant evaluation */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } @@ -4409,13 +4505,13 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (tarval_and(tv, cmask) != tv) { /* condition not met */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } sl = get_Shl_left(left); blk = get_nodes_block(n); - left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(mode, amask), mode); + left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(amask), mode); tv = tarval_shr(tv, tv1); changed |= 2; DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_SHF_TO_AND); @@ -4440,13 +4536,13 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (tarval_and(tv, cmask) != tv) { /* condition not met */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } sl = get_Shr_left(left); blk = get_nodes_block(n); - left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(mode, amask), mode); + left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(amask), mode); tv = tarval_shl(tv, tv1); changed |= 2; DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_SHF_TO_AND); @@ -4474,13 +4570,13 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (!tarval_is_all_one(cond) && !tarval_is_null(cond)) { /* condition not met */ tv = proj_nr == pn_Cmp_Eq ? get_tarval_b_false() : get_tarval_b_true(); - c1 = new_Const(mode_b, tv); + c1 = new_Const(tv); DBG_OPT_CSTEVAL(proj, c1); return c1; } sl = get_Shrs_left(left); blk = get_nodes_block(n); - left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(mode, amask), mode); + left = new_rd_And(get_irn_dbg_info(left), current_ir_graph, blk, sl, new_Const(amask), mode); tv = tarval_shl(tv, tv1); changed |= 2; DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_SHF_TO_AND); @@ -4492,7 +4588,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { } if (changed & 2) /* need a new Const */ - right = new_Const(mode, tv); + right = new_Const(tv); if ((proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg) && is_Const(right) && is_Const_null(right) && is_Proj(left)) { ir_node *op = get_Proj_pred(left); @@ -4511,7 +4607,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { ir_mode *mode = get_irn_mode(v); tv = tarval_sub(tv, get_mode_one(mode), NULL); - left = new_rd_And(get_irn_dbg_info(op), current_ir_graph, blk, v, new_Const(mode, tv), mode); + left = new_rd_And(get_irn_dbg_info(op), current_ir_graph, blk, v, new_Const(tv), mode); changed |= 1; DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_MOD_TO_AND); } @@ -4520,7 +4616,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { } if (changed) { - ir_node *block = get_irn_n(n, -1); /* Beware of get_nodes_Block() */ + ir_node *block = get_nodes_block(n); /* create a new compare */ n = new_rd_Cmp(get_irn_dbg_info(n), current_ir_graph, block, left, right); @@ -4776,9 +4872,9 @@ static ir_node *transform_node_Or_bf_store(ir_node *or) { block = get_irn_n(or, -1); new_and = new_r_And(current_ir_graph, block, - value, new_r_Const(current_ir_graph, block, mode, tarval_and(tv4, tv2)), mode); + value, new_Const(tarval_and(tv4, tv2)), mode); - new_const = new_r_Const(current_ir_graph, block, mode, tarval_or(tv3, tv1)); + new_const = new_Const(tarval_or(tv3, tv1)); set_Or_left(or, new_and); set_Or_right(or, new_const); @@ -4963,23 +5059,25 @@ static ir_node *transform_node_shift(ir_node *n) { /* beware: a simple replacement works only, if res < modulo shift */ if (!is_Rotl(n)) { int modulo_shf = get_mode_modulo_shift(mode); - assert(modulo_shf >= (int) get_mode_size_bits(mode)); if (modulo_shf > 0) { tarval *modulo = new_tarval_from_long(modulo_shf, get_tarval_mode(res)); + assert(modulo_shf >= (int) get_mode_size_bits(mode)); + /* shifting too much */ if (!(tarval_cmp(res, modulo) & pn_Cmp_Lt)) { if (is_Shrs(n)) { ir_graph *irg = get_irn_irg(n); ir_node *block = get_nodes_block(n); dbg_info *dbgi = get_irn_dbg_info(n); - ir_node *cnst = new_Const(mode_Iu, new_tarval_from_long(get_mode_size_bits(mode)-1, mode_Iu)); + ir_mode *smode = get_irn_mode(right); + ir_node *cnst = new_Const_long(smode, get_mode_size_bits(mode) - 1); return new_rd_Shrs(dbgi, irg, block, get_binop_left(left), cnst, mode); } - return new_Const(mode, get_mode_null(mode)); + return new_Const(get_mode_null(mode)); } } } else { @@ -4990,7 +5088,7 @@ static ir_node *transform_node_shift(ir_node *n) { block = get_nodes_block(n); in[0] = get_binop_left(left); - in[1] = new_r_Const(current_ir_graph, block, get_tarval_mode(res), res); + in[1] = new_Const(res); irn = new_ir_node(NULL, current_ir_graph, block, get_irn_op(n), mode, 2, in); @@ -5069,7 +5167,7 @@ static ir_node *transform_node_bitop_shift(ir_node *n) { } assert(get_tarval_mode(tv_shift) == mode); - new_const = new_Const(mode, tv_shift); + new_const = new_Const(tv_shift); if (op_left == op_And) { new_bitop = new_rd_And(dbgi, irg, block, new_shift, new_const, mode); @@ -5152,7 +5250,10 @@ static ir_node *transform_node_shl_shr(ir_node *n) { return n; } - assert(get_tarval_mode(tv_shl) == get_tarval_mode(tv_shr)); + if (get_tarval_mode(tv_shl) != get_tarval_mode(tv_shr)) { + tv_shl = tarval_convert_to(tv_shl, get_tarval_mode(tv_shr)); + } + assert(tv_mask != tarval_bad); assert(get_tarval_mode(tv_mask) == mode); @@ -5163,7 +5264,7 @@ static ir_node *transform_node_shl_shr(ir_node *n) { pnc = tarval_cmp(tv_shl, tv_shr); if (pnc == pn_Cmp_Lt || pnc == pn_Cmp_Eq) { tv_shift = tarval_sub(tv_shr, tv_shl, NULL); - new_const = new_Const(get_tarval_mode(tv_shift), tv_shift); + new_const = new_Const(tv_shift); if (need_shrs) { new_shift = new_rd_Shrs(dbgi, irg, block, x, new_const, mode); } else { @@ -5172,11 +5273,11 @@ static ir_node *transform_node_shl_shr(ir_node *n) { } else { assert(pnc == pn_Cmp_Gt); tv_shift = tarval_sub(tv_shl, tv_shr, NULL); - new_const = new_Const(get_tarval_mode(tv_shift), tv_shift); + new_const = new_Const(tv_shift); new_shift = new_rd_Shl(dbgi, irg, block, x, new_const, mode); } - new_const = new_Const(mode, tv_mask); + new_const = new_Const(tv_mask); new_and = new_rd_And(dbgi, irg, block, new_shift, new_const, mode); return new_and; @@ -5263,10 +5364,15 @@ static ir_node *transform_node_Rotl(ir_node *n) { */ static ir_node *transform_node_Conv(ir_node *n) { ir_node *c, *oldn = n; - ir_node *a = get_Conv_op(n); + ir_mode *mode = get_irn_mode(n); + ir_node *a = get_Conv_op(n); - if (is_const_Phi(a)) { - c = apply_conv_on_phi(a, get_irn_mode(n)); + if (mode != mode_b && is_const_Phi(a)) { + /* Do NOT optimize mode_b Conv's, this leads to remaining + * Phib nodes later, because the conv_b_lower operation + * is instantly reverted, when it tries to insert a Convb. + */ + c = apply_conv_on_phi(a, mode); if (c) { DBG_OPT_ALGSIM0(oldn, c, FS_OPT_CONST_PHI); return c; @@ -5274,10 +5380,34 @@ static ir_node *transform_node_Conv(ir_node *n) { } if (is_Unknown(a)) { /* Conv_A(Unknown_B) -> Unknown_A */ - ir_mode *mode = get_irn_mode(n); return new_r_Unknown(current_ir_graph, mode); } + if (mode_is_reference(mode) && + get_mode_size_bits(mode) == get_mode_size_bits(get_irn_mode(a)) && + is_Add(a)) { + ir_node *l = get_Add_left(a); + ir_node *r = get_Add_right(a); + dbg_info *dbgi = get_irn_dbg_info(a); + ir_node *block = get_nodes_block(n); + if(is_Conv(l)) { + ir_node *lop = get_Conv_op(l); + if(get_irn_mode(lop) == mode) { + /* ConvP(AddI(ConvI(P), x)) -> AddP(P, x) */ + n = new_rd_Add(dbgi, current_ir_graph, block, lop, r, mode); + return n; + } + } + if(is_Conv(r)) { + ir_node *rop = get_Conv_op(r); + if(get_irn_mode(rop) == mode) { + /* ConvP(AddI(x, ConvI(P))) -> AddP(x, P) */ + n = new_rd_Add(dbgi, current_ir_graph, block, l, rop, mode); + return n; + } + } + } + return n; } /* transform_node_Conv */ @@ -5300,10 +5430,11 @@ static ir_node *transform_node_End(ir_node *n) { continue; } else if (is_irn_pinned_in_irg(ka) && is_Block_dead(get_nodes_block(ka))) { continue; + } else if (is_Bad(ka)) { + /* no need to keep Bad */ + continue; } - /* FIXME: beabi need to keep a Proj(M) */ - if (is_Phi(ka) || is_irn_keep(ka) || is_Proj(ka)) - in[j++] = ka; + in[j++] = ka; } if (j != n_keepalives) set_End_keepalives(n, j, in); @@ -5417,10 +5548,10 @@ static ir_node *transform_node_Mux(ir_node *n) { dbg_info *dbg = get_irn_dbg_info(n); ir_node *block = get_nodes_block(n); ir_graph *irg = current_ir_graph; - ir_node *t = new_Const(mode, tarval_sub(a, min, NULL)); - ir_node *f = new_Const(mode, tarval_sub(b, min, NULL)); + ir_node *t = new_Const(tarval_sub(a, min, NULL)); + ir_node *f = new_Const(tarval_sub(b, min, NULL)); n = new_rd_Mux(dbg, irg, block, sel, f, t, mode); - n = new_rd_Add(dbg, irg, block, n, new_Const(mode, min), mode); + n = new_rd_Add(dbg, irg, block, n, new_Const(min), mode); return n; } } @@ -5480,10 +5611,12 @@ static ir_node *transform_node_Mux(ir_node *n) { if (pn == pn_Cmp_Lg) { /* Mux((a & 2^C) != 0, 2^C, 0) */ n = cmp_l; + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_BITOP); } else { /* Mux((a & 2^C) == 0, 2^C, 0) */ n = new_rd_Eor(get_irn_dbg_info(n), current_ir_graph, block, cmp_l, t, mode); + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_BITOP); } return n; } @@ -5495,10 +5628,12 @@ static ir_node *transform_node_Mux(ir_node *n) { if (pn == pn_Cmp_Lg) { /* (a & (1 << n)) != 0, (1 << n), 0) */ n = cmp_l; + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_BITOP); } else { /* (a & (1 << n)) == 0, (1 << n), 0) */ n = new_rd_Eor(get_irn_dbg_info(n), current_ir_graph, block, cmp_l, t, mode); + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_BITOP); } return n; } @@ -5512,10 +5647,12 @@ static ir_node *transform_node_Mux(ir_node *n) { if (pn == pn_Cmp_Lg) { /* ((1 << n) & a) != 0, (1 << n), 0) */ n = cmp_l; + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_BITOP); } else { /* ((1 << n) & a) == 0, (1 << n), 0) */ n = new_rd_Eor(get_irn_dbg_info(n), current_ir_graph, block, cmp_l, t, mode); + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_BITOP); } return n; } @@ -5526,7 +5663,8 @@ static ir_node *transform_node_Mux(ir_node *n) { } } } - return arch_transform_node_Mux(n); + + return n; } /* transform_node_Mux */ /** @@ -5570,7 +5708,80 @@ static ir_node *transform_node_Sync(ir_node *n) { add_identities(current_ir_graph->value_table, n); return n; -} +} /* transform_node_Sync */ + +/** + * optimize a trampoline Call into a direct Call + */ +static ir_node *transform_node_Call(ir_node *call) { + ir_node *callee = get_Call_ptr(call); + ir_node *adr, *mem, *res, *bl, **in; + ir_type *ctp, *mtp, *tp; + ident *id; + dbg_info *db; + int i, n_res, n_param; + ir_variadicity var; + + if (! is_Proj(callee)) + return call; + callee = get_Proj_pred(callee); + if (! is_Builtin(callee)) + return call; + if (get_Builtin_kind(callee) != ir_bk_inner_trampoline) + return call; + + mem = get_Call_mem(call); + + if (skip_Proj(mem) == callee) { + /* memory is routed to the trampoline, skip */ + mem = get_Builtin_mem(callee); + } + + /* build a new call type */ + mtp = get_Call_type(call); + id = get_type_ident(mtp); + id = id_mangle(new_id_from_chars("T_", 2), id); + db = get_type_dbg_info(mtp); + + n_res = get_method_n_ress(mtp); + n_param = get_method_n_params(mtp); + ctp = new_d_type_method(id, n_param + 1, n_res, db); + + for (i = 0; i < n_res; ++i) + set_method_res_type(ctp, i, get_method_res_type(mtp, i)); + + NEW_ARR_A(ir_node *, in, n_param + 1); + + /* FIXME: we don't need a new pointer type in every step */ + tp = get_irg_frame_type(current_ir_graph); + id = id_mangle(get_type_ident(tp), new_id_from_chars("_ptr", 4)); + tp = new_type_pointer(id, tp, mode_P_data); + set_method_param_type(ctp, 0, tp); + + in[0] = get_Builtin_param(callee, 2); + for (i = 0; i < n_param; ++i) { + set_method_param_type(ctp, i + 1, get_method_param_type(mtp, i)); + in[i + 1] = get_Call_param(call, i); + } + var = get_method_variadicity(mtp); + set_method_variadicity(ctp, var); + if (var == variadicity_variadic) { + set_method_first_variadic_param_index(ctp, get_method_first_variadic_param_index(mtp) + 1); + } + /* When we resolve a trampoline, the function must be called by a this-call */ + set_method_calling_convention(ctp, get_method_calling_convention(mtp) | cc_this_call); + set_method_additional_properties(ctp, get_method_additional_properties(mtp)); + + adr = get_Builtin_param(callee, 1); + + db = get_irn_dbg_info(call); + bl = get_nodes_block(call); + + res = new_rd_Call(db, current_ir_graph, bl, mem, adr, n_param + 1, in, ctp); + if (get_irn_pinned(call) == op_pin_state_floats) + set_irn_pinned(res, op_pin_state_floats); + return res; +} /* transform_node_Call */ /** * Tries several [inplace] [optimizing] transformations and returns an @@ -5652,6 +5863,7 @@ static ir_op_ops *firm_set_default_transform_node(ir_opcode code, ir_op_ops *ops CASE(End); CASE(Mux); CASE(Sync); + CASE(Call); default: /* leave NULL */; } @@ -5717,12 +5929,17 @@ static int node_cmp_attr_Call(ir_node *a, ir_node *b) { static int node_cmp_attr_Sel(ir_node *a, ir_node *b) { const ir_entity *a_ent = get_Sel_entity(a); const ir_entity *b_ent = get_Sel_entity(b); +#if 0 return (a_ent->kind != b_ent->kind) || (a_ent->name != b_ent->name) || (a_ent->owner != b_ent->owner) || (a_ent->ld_name != b_ent->ld_name) || (a_ent->type != b_ent->type); +#endif + /* Matze: inlining of functions can produce 2 entities with same type, + * name, etc. */ + return a_ent != b_ent; } /* node_cmp_attr_Sel */ /** Compares the attributes of two Phi nodes. */ @@ -5785,7 +6002,7 @@ static int node_cmp_attr_Div(ir_node *a, ir_node *b) { const divmod_attr *ma = get_irn_divmod_attr(a); const divmod_attr *mb = get_irn_divmod_attr(b); return ma->exc.pin_state != mb->exc.pin_state || - ma->res_mode != mb->res_mode || + ma->resmode != mb->resmode || ma->no_remainder != mb->no_remainder; } /* node_cmp_attr_Div */ @@ -5794,7 +6011,7 @@ static int node_cmp_attr_DivMod(ir_node *a, ir_node *b) { const divmod_attr *ma = get_irn_divmod_attr(a); const divmod_attr *mb = get_irn_divmod_attr(b); return ma->exc.pin_state != mb->exc.pin_state || - ma->res_mode != mb->res_mode; + ma->resmode != mb->resmode; } /* node_cmp_attr_DivMod */ /** Compares the attributes of two Mod nodes. */ @@ -5802,7 +6019,7 @@ static int node_cmp_attr_Mod(ir_node *a, ir_node *b) { const divmod_attr *ma = get_irn_divmod_attr(a); const divmod_attr *mb = get_irn_divmod_attr(b); return ma->exc.pin_state != mb->exc.pin_state || - ma->res_mode != mb->res_mode; + ma->resmode != mb->resmode; } /* node_cmp_attr_Mod */ /** Compares the attributes of two Quot nodes. */ @@ -5810,14 +6027,24 @@ static int node_cmp_attr_Quot(ir_node *a, ir_node *b) { const divmod_attr *ma = get_irn_divmod_attr(a); const divmod_attr *mb = get_irn_divmod_attr(b); return ma->exc.pin_state != mb->exc.pin_state || - ma->res_mode != mb->res_mode; + ma->resmode != mb->resmode; } /* node_cmp_attr_Quot */ /** Compares the attributes of two Confirm nodes. */ static int node_cmp_attr_Confirm(ir_node *a, ir_node *b) { + /* no need to compare the bound, as this is a input */ return (get_Confirm_cmp(a) != get_Confirm_cmp(b)); } /* node_cmp_attr_Confirm */ +/** Compares the attributes of two Builtin nodes. */ +static int node_cmp_attr_Builtin(ir_node *a, ir_node *b) { + const builtin_attr *ma = get_irn_builtin_attr(a); + const builtin_attr *mb = get_irn_builtin_attr(b); + + /* no need to compare the type, equal kind means equal type */ + return ma->kind != mb->kind; +} /* node_cmp_attr_Builtin */ + /** Compares the attributes of two ASM nodes. */ static int node_cmp_attr_ASM(ir_node *a, ir_node *b) { int i, n; @@ -5864,6 +6091,14 @@ static int node_cmp_attr_ASM(ir_node *a, ir_node *b) { return 0; } /* node_cmp_attr_ASM */ +/** Compares the inexistent attributes of two Dummy nodes. */ +static int node_cmp_attr_Dummy(ir_node *a, ir_node *b) +{ + (void) a; + (void) b; + return 1; +} + /** * Set the default node attribute compare operation for an ir_op_ops. * @@ -5901,6 +6136,8 @@ static ir_op_ops *firm_set_default_node_cmp_attr(ir_opcode code, ir_op_ops *ops) CASE(Mod); CASE(Quot); CASE(Bound); + CASE(Builtin); + CASE(Dummy); /* FIXME CopyB */ default: /* leave NULL */; @@ -5972,13 +6209,9 @@ void del_identities(pset *value_table) { del_pset(value_table); } /* del_identities */ -/** - * Normalize a node by putting constants (and operands with larger - * node index) on the right (operator side). - * - * @param n The node to normalize - */ -static void normalize_node(ir_node *n) { +/* Normalize a node by putting constants (and operands with larger + * node index) on the right (operator side). */ +void ir_normalize_node(ir_node *n) { if (is_op_commutative(get_irn_op(n))) { ir_node *l = get_binop_left(n); ir_node *r = get_binop_right(n); @@ -5990,9 +6223,10 @@ static void normalize_node(ir_node *n) { if (!operands_are_normalized(l, r)) { set_binop_left(n, r); set_binop_right(n, l); + hook_normalize(n); } } -} /* normalize_node */ +} /* ir_normalize_node */ /** * Update the nodes after a match in the value table. If both nodes have @@ -6058,13 +6292,12 @@ ir_node *identify_remember(pset *value_table, ir_node *n) { if (!value_table) return n; - normalize_node(n); + ir_normalize_node(n); /* lookup or insert in hash table with given hash key. */ o = pset_insert(value_table, n, ir_node_hash(n)); if (o != n) { update_known_irn(o, n); - DBG_OPT_CSE(n, o); } return o; @@ -6078,7 +6311,7 @@ ir_node *identify_remember(pset *value_table, ir_node *n) { * @param value_table The value table * @param n The node to lookup */ -static INLINE ir_node *identify_cons(pset *value_table, ir_node *n) { +static inline ir_node *identify_cons(pset *value_table, ir_node *n) { ir_node *old = n; n = identify_remember(value_table, n); @@ -6217,7 +6450,10 @@ ir_node *optimize_node(ir_node *n) { /* neither constants nor Tuple values can be evaluated */ if (iro != iro_Const && (get_irn_mode(n) != mode_T)) { unsigned fp_model = get_irg_fp_model(current_ir_graph); - int old_fp_mode = tarval_enable_fp_ops((fp_model & fp_strict_algebraic) == 0); + int old_fp_mode = tarval_fp_ops_enabled(); + + tarval_enable_fp_ops(! (fp_model & fp_no_float_fold)); + /* try to evaluate */ tv = computed_value(n); if (tv != tarval_bad) { @@ -6250,7 +6486,7 @@ ir_node *optimize_node(ir_node *n) { /* evaluation was successful -- replace the node. */ irg_kill_node(current_ir_graph, n); - nw = new_Const(get_tarval_mode(tv), tv); + nw = new_Const(tv); if (old_tp && get_type_mode(old_tp) == get_tarval_mode(tv)) set_Const_type(nw, old_tp); @@ -6302,7 +6538,10 @@ ir_node *optimize_node(ir_node *n) { /* Now we have a legal, useful node. Enter it in hash table for CSE */ if (get_opt_cse() && (get_irn_opcode(n) != iro_Block)) { - n = identify_remember(current_ir_graph->value_table, n); + ir_node *o = n; + n = identify_remember(current_ir_graph->value_table, o); + if (o != n) + DBG_OPT_CSE(o, n); } return n; @@ -6326,7 +6565,9 @@ ir_node *optimize_in_place_2(ir_node *n) { /* neither constants nor Tuple values can be evaluated */ if (iro != iro_Const && get_irn_mode(n) != mode_T) { unsigned fp_model = get_irg_fp_model(current_ir_graph); - int old_fp_mode = tarval_enable_fp_ops((fp_model & fp_strict_algebraic) == 0); + int old_fp_mode = tarval_fp_ops_enabled(); + + tarval_enable_fp_ops((fp_model & fp_strict_algebraic) == 0); /* try to evaluate */ tv = computed_value(n); if (tv != tarval_bad) { @@ -6340,7 +6581,7 @@ ir_node *optimize_in_place_2(ir_node *n) { for (i = 0; i < arity && !old_tp; ++i) old_tp = get_irn_type(get_irn_n(n, i)); - n = new_Const(get_tarval_mode(tv), tv); + n = new_Const(tv); if (old_tp && get_type_mode(old_tp) == get_tarval_mode(tv)) set_Const_type(n, old_tp); @@ -6367,7 +6608,10 @@ ir_node *optimize_in_place_2(ir_node *n) { now all nodes are op_pin_state_pinned to blocks, i.e., the cse only finds common subexpressions within a block. */ if (get_opt_cse()) { - n = identify_remember(current_ir_graph->value_table, n); + ir_node *o = n; + n = identify_remember(current_ir_graph->value_table, o); + if (o != n) + DBG_OPT_CSE(o, n); } /* Some more constant expression evaluation. */ @@ -6387,8 +6631,12 @@ ir_node *optimize_in_place_2(ir_node *n) { /* Now we have a legal, useful node. Enter it in hash table for cse. Blocks should be unique anyways. (Except the successor of start: is cse with the start block!) */ - if (get_opt_cse() && (get_irn_opcode(n) != iro_Block)) - n = identify_remember(current_ir_graph->value_table, n); + if (get_opt_cse() && (get_irn_opcode(n) != iro_Block)) { + ir_node *o = n; + n = identify_remember(current_ir_graph->value_table, o); + if (o != n) + DBG_OPT_CSE(o, n); + } return n; } /* optimize_in_place_2 */