X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firopt.c;h=81f9edc4c427cb957858185005fd87e9e16a12e5;hb=a999e1baedb84dc9b83059708699dac1c7fdb9a2;hp=f0dae40a50b061b985da72ba6db1f7c3b8bb179a;hpb=37e955f158f80e93a20caa15d0df952d60a029c5;p=libfirm diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index f0dae40a5..81f9edc4c 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -1882,13 +1882,13 @@ static ir_node *transform_node_AddSub(ir_node *n) { ir_mode *mode = get_irn_mode(n); if (mode_is_reference(mode)) { - ir_node *left = get_binop_left(n); - ir_node *right = get_binop_right(n); - int ref_bits = get_mode_size_bits(mode); + ir_node *left = get_binop_left(n); + ir_node *right = get_binop_right(n); + unsigned ref_bits = get_mode_size_bits(mode); if (is_Conv(left)) { ir_mode *mode = get_irn_mode(left); - int bits = get_mode_size_bits(mode); + unsigned bits = get_mode_size_bits(mode); if (ref_bits == bits && mode_is_int(mode) && @@ -1911,7 +1911,7 @@ static ir_node *transform_node_AddSub(ir_node *n) { if (is_Conv(right)) { ir_mode *mode = get_irn_mode(right); - int bits = get_mode_size_bits(mode); + unsigned bits = get_mode_size_bits(mode); if (ref_bits == bits && mode_is_int(mode) && @@ -2027,74 +2027,6 @@ static ir_node *transform_node_Add(ir_node *n) { DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_A_MINUS_B); return n; } - if (! is_reassoc_running()) { - /* do NOT execute this code if reassociation is enabled, it does the inverse! */ - if (is_Mul(a)) { - ir_node *ma = get_Mul_left(a); - ir_node *mb = get_Mul_right(a); - - if (b == ma) { - ir_node *blk = get_irn_n(n, -1); - n = new_rd_Mul( - get_irn_dbg_info(n), current_ir_graph, blk, - ma, - new_rd_Add( - get_irn_dbg_info(n), current_ir_graph, blk, - mb, - new_r_Const_long(current_ir_graph, blk, mode, 1), - mode), - mode); - DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_MUL_A_X_A); - return n; - } else if (b == mb) { - ir_node *blk = get_irn_n(n, -1); - n = new_rd_Mul( - get_irn_dbg_info(n), current_ir_graph, blk, - mb, - new_rd_Add( - get_irn_dbg_info(n), current_ir_graph, blk, - ma, - new_r_Const_long(current_ir_graph, blk, mode, 1), - mode), - mode); - DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_MUL_A_X_A); - return n; - } - } - if (is_Mul(b)) { - ir_node *ma = get_Mul_left(b); - ir_node *mb = get_Mul_right(b); - - if (a == ma) { - ir_node *blk = get_irn_n(n, -1); - n = new_rd_Mul( - get_irn_dbg_info(n), current_ir_graph, blk, - ma, - new_rd_Add( - get_irn_dbg_info(n), current_ir_graph, blk, - mb, - new_r_Const_long(current_ir_graph, blk, mode, 1), - mode), - mode); - DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_MUL_A_X_A); - return n; - } - if (a == mb) { - ir_node *blk = get_irn_n(n, -1); - n = new_rd_Mul( - get_irn_dbg_info(n), current_ir_graph, blk, - mb, - new_rd_Add( - get_irn_dbg_info(n), current_ir_graph, blk, - ma, - new_r_Const_long(current_ir_graph, blk, mode, 1), - mode), - mode); - DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ADD_MUL_A_X_A); - return n; - } - } - } if (get_mode_arithmetic(mode) == irma_twos_complement) { /* Here we rely on constants be on the RIGHT side */ if (is_Not(a)) { @@ -2311,16 +2243,16 @@ restart: if (mode == get_irn_mode(b)) { ir_mode *ma, *mb; - - a = get_Conv_op(a); - b = get_Conv_op(b); + ir_node *op_a = get_Conv_op(a); + ir_node *op_b = get_Conv_op(b); /* check if it's allowed to skip the conv */ - ma = get_irn_mode(a); - mb = get_irn_mode(b); + ma = get_irn_mode(op_a); + mb = get_irn_mode(op_b); if (mode_is_reference(ma) && mode_is_reference(mb)) { /* SubInt(ConvInt(aP), ConvInt(bP)) -> SubInt(aP,bP) */ + a = op_a; b = op_b; set_Sub_left(n, a); set_Sub_right(n, b); @@ -2429,12 +2361,14 @@ static ir_node *transform_node_Mul2n(ir_node *n, ir_mode *mode) { ir_mode *smode = get_irn_mode(a); if (ta == get_mode_one(smode)) { + /* (L)1 * (L)b = (L)b */ ir_node *blk = get_irn_n(n, -1); 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); 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); @@ -2442,12 +2376,14 @@ static ir_node *transform_node_Mul2n(ir_node *n, ir_mode *mode) { return n; } if (tb == get_mode_one(smode)) { + /* (L)a * (L)1 = (L)a */ ir_node *blk = get_irn_n(a, -1); n = new_rd_Conv(get_irn_dbg_info(n), current_ir_graph, blk, a, mode); DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_1); return n; } else if (tb == get_mode_minus_one(smode)) { + /* (L)a * (L)-1 = (L)-a */ ir_node *blk = get_irn_n(n, -1); 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); @@ -2533,7 +2469,8 @@ static ir_node *transform_node_Mul(ir_node *n) { if (is_Const(a)) { tarval *tv = get_Const_tarval(a); if (tarval_ieee754_get_exponent(tv) == 1 && tarval_ieee754_zero_mantissa(tv)) { - n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), b, b, mode); + /* 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); return n; } @@ -2541,7 +2478,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)) { - n = new_rd_Add(get_irn_dbg_info(n), current_ir_graph, get_irn_n(n, -1), a, a, mode); + /* 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); return n; } @@ -2751,7 +2689,7 @@ static ir_node *transform_node_DivMod(ir_node *n) { else if (is_Const(a) && is_const_Phi(b)) { /* check for Div(Const, Phi) */ va = apply_binop_on_phi(b, get_Const_tarval(a), tarval_div, mode, 1); - va = apply_binop_on_phi(b, get_Const_tarval(a), tarval_mod, mode, 1); + vb = apply_binop_on_phi(b, get_Const_tarval(a), tarval_mod, mode, 1); if (va && vb) { DBG_OPT_ALGSIM0(n, va, FS_OPT_CONST_PHI); DBG_OPT_ALGSIM0(n, vb, FS_OPT_CONST_PHI); @@ -2883,6 +2821,7 @@ static ir_node *transform_node_Quot(ir_node *n) { /** * Optimize Abs(x) into x if x is Confirmed >= 0 * Optimize Abs(x) into -x if x is Confirmed <= 0 + * Optimize Abs(-x) int Abs(x) */ static ir_node *transform_node_Abs(ir_node *n) { ir_node *c, *oldn = n; @@ -2903,7 +2842,7 @@ static ir_node *transform_node_Abs(ir_node *n) { * not run it in the equivalent_node() context. */ n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, - get_irn_n(n, -1), a, mode); + get_nodes_block(n), a, mode); DBG_OPT_CONFIRM(oldn, n); return n; @@ -2914,8 +2853,17 @@ static ir_node *transform_node_Abs(ir_node *n) { DBG_OPT_CONFIRM(oldn, n); return n; default: + break; + } + if (is_Minus(a)) { + /* Abs(-x) = Abs(x) */ + mode = get_irn_mode(n); + n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, + get_nodes_block(n), get_Minus_op(a), mode); + DBG_OPT_ALGSIM0(oldn, n, FS_OPT_ABS_MINUS_X); return n; } + return n; } /* transform_node_Abs */ /** @@ -3005,7 +2953,8 @@ static ir_node *transform_bitwise_distributive(ir_node *n, ir_node *b_left = get_binop_left(b); ir_node *b_right = get_binop_right(b); ir_node *c = NULL; - ir_node *op1, *op2; + ir_node *op1 = NULL; + ir_node *op2 = NULL; if (is_op_commutative(op)) { if (a_left == b_left) { @@ -3346,7 +3295,7 @@ static ir_node *transform_node_Minus(ir_node *n) { if (is_Const(c)) { tarval *tv = get_Const_tarval(c); - if (tarval_is_long(tv) && get_tarval_long(tv) == get_mode_size_bits(mode) - 1) { + if (tarval_is_long(tv) && get_tarval_long(tv) == (int) get_mode_size_bits(mode) - 1) { /* -(a >>u (size-1)) = a >>s (size-1) */ ir_node *v = get_Shr_left(a); @@ -3362,7 +3311,7 @@ static ir_node *transform_node_Minus(ir_node *n) { if (is_Const(c)) { tarval *tv = get_Const_tarval(c); - if (tarval_is_long(tv) && get_tarval_long(tv) == get_mode_size_bits(mode) - 1) { + if (tarval_is_long(tv) && get_tarval_long(tv) == (int) get_mode_size_bits(mode) - 1) { /* -(a >>s (size-1)) = a >>u (size-1) */ ir_node *v = get_Shrs_left(a); @@ -3415,8 +3364,8 @@ static ir_node *transform_node_Cast(ir_node *n) { 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_SymConst_symbol(pred), - get_SymConst_kind(pred), tp); + n = new_rd_SymConst_type(NULL, current_ir_graph, get_irn_n(pred, -1), get_irn_mode(pred), + get_SymConst_symbol(pred), get_SymConst_kind(pred), tp); DBG_OPT_CSTEVAL(oldn, n); } @@ -3697,7 +3646,8 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { ir_mode *mode_left = get_irn_mode(op_left); ir_mode *mode_right = get_irn_mode(op_right); - if (smaller_mode(mode_left, mode) && smaller_mode(mode_right, mode)) { + if (smaller_mode(mode_left, mode) && smaller_mode(mode_right, mode) + && mode_left != mode_b && mode_right != mode_b) { ir_graph *irg = current_ir_graph; ir_node *block = get_nodes_block(n); @@ -3865,9 +3815,6 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { } } - if (!get_opt_reassociation()) - return proj; - /* * First step: normalize the compare op * by placing the constant on the right side @@ -4491,7 +4438,7 @@ static ir_node *transform_node_Or_Rot(ir_node *or) { return or; if (get_tarval_long(tv1) + get_tarval_long(tv2) - != get_mode_size_bits(mode)) + != (int) get_mode_size_bits(mode)) return or; /* yet, condition met */ @@ -4516,7 +4463,7 @@ static ir_node *transform_node_Or_Rot(ir_node *or) { if (! tarval_is_long(tv1)) return or; - if (get_tarval_long(tv1) != get_mode_size_bits(mode)) + if (get_tarval_long(tv1) != (int) get_mode_size_bits(mode)) return or; /* yet, condition met */ @@ -4539,7 +4486,7 @@ static ir_node *transform_node_Or_Rot(ir_node *or) { if (! tarval_is_long(tv1)) return or; - if (get_tarval_long(tv1) != get_mode_size_bits(mode)) + if (get_tarval_long(tv1) != (int) get_mode_size_bits(mode)) return or; /* yet, condition met */ @@ -4735,6 +4682,12 @@ static ir_node *transform_node_Conv(ir_node *n) { return c; } } + + 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); + } + return n; } /* transform_node_Conv */ @@ -5291,19 +5244,17 @@ void del_identities(pset *value_table) { * @param n The node to normalize */ static void normalize_node(ir_node *n) { - if (get_opt_reassociation()) { - if (is_op_commutative(get_irn_op(n))) { - ir_node *l = get_binop_left(n); - ir_node *r = get_binop_right(n); - - /* For commutative operators perform a OP b == b OP a but keep - * constants on the RIGHT side. This helps greatly in some - * optimizations. Moreover we use the idx number to make the form - * deterministic. */ - if (!operands_are_normalized(l, r)) { - set_binop_left(n, r); - set_binop_right(n, l); - } + if (is_op_commutative(get_irn_op(n))) { + ir_node *l = get_binop_left(n); + ir_node *r = get_binop_right(n); + + /* For commutative operators perform a OP b == b OP a but keep + * constants on the RIGHT side. This helps greatly in some + * optimizations. Moreover we use the idx number to make the form + * deterministic. */ + if (!operands_are_normalized(l, r)) { + set_binop_left(n, r); + set_binop_right(n, l); } } } /* normalize_node */