X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firopt.c;h=2510e5f5bc58ea6ff184fb30c3212e1ce2880541;hb=68c75332d891023a982f164d8b642766824844a9;hp=26299c0c2566040f86233705a358fbae519696e9;hpb=869a57a3b9d6bb4cca925b536733bef66bfacf2d;p=libfirm diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 26299c0c2..2510e5f5b 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -145,8 +145,7 @@ static tarval *computed_value_Carry(ir_node *n) { tarval_add(ta, tb); return tarval_carry() ? get_mode_one(m) : get_mode_null(m); } else { - if ( (classify_tarval(ta) == TV_CLASSIFY_NULL) - || (classify_tarval(tb) == TV_CLASSIFY_NULL)) + if (tarval_is_null(ta) || tarval_is_null(tb)) return get_mode_null(m); } return tarval_bad; @@ -166,7 +165,7 @@ static tarval *computed_value_Borrow(ir_node *n) { if ((ta != tarval_bad) && (tb != tarval_bad)) { return tarval_cmp(ta, tb) == pn_Cmp_Lt ? get_mode_one(m) : get_mode_null(m); - } else if (classify_tarval(ta) == TV_CLASSIFY_NULL) { + } else if (tarval_is_null(ta)) { return get_mode_null(m); } return tarval_bad; @@ -310,12 +309,8 @@ static tarval *computed_value_And(ir_node *n) { if ((ta != tarval_bad) && (tb != tarval_bad)) { return tarval_and (ta, tb); } else { - tarval *v; - - if ( (classify_tarval ((v = ta)) == TV_CLASSIFY_NULL) - || (classify_tarval ((v = tb)) == TV_CLASSIFY_NULL)) { - return v; - } + if (tarval_is_null(ta)) return ta; + if (tarval_is_null(tb)) return tb; } return tarval_bad; } /* computed_value_And */ @@ -334,11 +329,8 @@ static tarval *computed_value_Or(ir_node *n) { if ((ta != tarval_bad) && (tb != tarval_bad)) { return tarval_or (ta, tb); } else { - tarval *v; - if ( (classify_tarval ((v = ta)) == TV_CLASSIFY_ALL_ONE) - || (classify_tarval ((v = tb)) == TV_CLASSIFY_ALL_ONE)) { - return v; - } + if (tarval_is_all_one(ta)) return ta; + if (tarval_is_all_one(tb)) return tb; } return tarval_bad; } /* computed_value_Or */ @@ -859,12 +851,10 @@ static ir_node *equivalent_node_neutral_zero(ir_node *n) * which happens in this rare construction: NULL + 3. * Then, a Conv would be needed which we cannot include here. */ - if (classify_tarval (tv) == TV_CLASSIFY_NULL) { - if (get_irn_mode(on) == get_irn_mode(n)) { - n = on; + if (tarval_is_null(tv) && get_irn_mode(on) == get_irn_mode(n)) { + n = on; - DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_0); - } + DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_0); } return n; @@ -935,7 +925,7 @@ static ir_node *equivalent_node_left_zero(ir_node *n) { ir_node *a = get_binop_left(n); ir_node *b = get_binop_right(n); - if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) { + if (is_Const(b) && is_Const_null(b)) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_0); @@ -969,7 +959,7 @@ static ir_node *equivalent_node_Sub(ir_node *n) { b = get_Sub_right(n); /* Beware: modes might be different */ - if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) { + if (is_Const(b) && is_Const_null(b)) { ir_node *a = get_Sub_left(n); if (mode == get_irn_mode(a)) { n = a; @@ -1020,10 +1010,10 @@ static ir_node *equivalent_node_Mul(ir_node *n) { ir_node *b = get_Mul_right(n); /* Mul is commutative and has again an other neutral element. */ - if (classify_tarval(value_of(a)) == TV_CLASSIFY_ONE) { + if (is_Const(a) && is_Const_one(a)) { n = b; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_1); - } else if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { + } else if (is_Const(b) && is_Const_one(b)) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_1); } @@ -1039,7 +1029,7 @@ static ir_node *equivalent_node_Div(ir_node *n) { ir_node *b = get_Div_right(n); /* Div is not commutative. */ - if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { /* div(x, 1) == x */ + if (is_Const(b) && is_Const_one(b)) { /* div(x, 1) == x */ /* Turn Div into a tuple (mem, bad, a) */ ir_node *mem = get_Div_mem(n); ir_node *blk = get_irn_n(n, -1); @@ -1060,7 +1050,7 @@ static ir_node *equivalent_node_Quot(ir_node *n) { ir_node *b = get_Quot_right(n); /* Div is not commutative. */ - if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { /* Quot(x, 1) == x */ + if (is_Const(b) && is_Const_one(b)) { /* Quot(x, 1) == x */ /* Turn Quot into a tuple (mem, jmp, bad, a) */ ir_node *mem = get_Quot_mem(n); ir_node *blk = get_irn_n(n, -1); @@ -1080,7 +1070,7 @@ static ir_node *equivalent_node_DivMod(ir_node *n) { ir_node *b = get_DivMod_right(n); /* Div is not commutative. */ - if (classify_tarval(value_of(b)) == TV_CLASSIFY_ONE) { /* div(x, 1) == x */ + if (is_Const(b) && is_Const_one(b)) { /* div(x, 1) == x */ /* Turn DivMod into a tuple (mem, jmp, bad, a, 0) */ ir_node *a = get_DivMod_left(n); ir_node *mem = get_Div_mem(n); @@ -1109,10 +1099,10 @@ static ir_node *equivalent_node_Or(ir_node *n) { if (a == b) { n = a; /* Or has it's own neutral element */ DBG_OPT_ALGSIM0(oldn, n, FS_OPT_OR); - } else if (classify_tarval(value_of(a)) == TV_CLASSIFY_NULL) { + } else if (is_Const(a) && is_Const_null(a)) { n = b; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_OR); - } else if (classify_tarval(value_of(b)) == TV_CLASSIFY_NULL) { + } else if (is_Const(b) && is_Const_null(b)) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_OR); } @@ -1134,12 +1124,12 @@ static ir_node *equivalent_node_And(ir_node *n) { DBG_OPT_ALGSIM0(oldn, n, FS_OPT_AND); return n; } - if (classify_tarval(value_of(a)) == TV_CLASSIFY_ALL_ONE) { + if (is_Const(a) && is_Const_all_one(a)) { n = b; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND); return n; } - if (classify_tarval(value_of(b)) == TV_CLASSIFY_ALL_ONE) { + if (is_Const(b) && is_Const_all_one(b)) { n = a; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_AND); return n; @@ -1467,7 +1457,8 @@ static ir_node *equivalent_node_Mux(ir_node *n) * However, if +0 and -0 is handled differently, we cannot use the first one. */ if (get_irn_op(cmp) == op_Cmp && get_Cmp_left(cmp) == a) { - if (classify_Const(get_Cmp_right(cmp)) == CNST_NULL) { + ir_node *cmp_r = get_Cmp_right(cmp); + if (is_Const(cmp_r) && is_Const_null(cmp_r)) { /* Mux(a CMP 0, X, a) */ if (get_irn_op(b) == op_Minus && get_Minus_op(b) == a) { /* Mux(a CMP 0, -a, a) */ @@ -1480,7 +1471,7 @@ static ir_node *equivalent_node_Mux(ir_node *n) n = a; DBG_OPT_ALGSIM0(oldn, n, FS_OPT_MUX_TRANSFORM); } - } else if (classify_Const(b) == CNST_NULL) { + } else if (is_Const(b) && is_Const_null(b)) { /* Mux(a CMP 0, 0, a) */ if (proj_nr == pn_Cmp_Lg || proj_nr == pn_Cmp_Ne) { /* Mux(a != 0, 0, a) ==> a */ @@ -2028,7 +2019,7 @@ static ir_node *transform_node_Add(ir_node *n) { if (is_Not(a)) { ir_node *op = get_Not_op(a); - if (classify_Const(b) == CNST_ONE) { + if (is_Const(b) && is_Const_one(b)) { /* ~x + 1 = -x */ ir_node *blk = get_irn_n(n, -1); n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, blk, op, mode); @@ -2172,7 +2163,7 @@ restart: } /* Beware of Sub(P, P) which cannot be optimized into a simple Minus ... */ - if (mode_is_num(mode) && mode == get_irn_mode(a) && (classify_Const(a) == CNST_NULL)) { + if (mode_is_num(mode) && mode == get_irn_mode(a) && is_Const(a) && is_Const_null(a)) { n = new_rd_Minus( get_irn_dbg_info(n), current_ir_graph, @@ -3059,15 +3050,14 @@ static ir_node *transform_node_Eor(ir_node *n) { } else if ((mode == mode_b) && (get_irn_op(a) == op_Proj) && (get_irn_mode(a) == mode_b) - && (classify_tarval (value_of(b)) == TV_CLASSIFY_ONE) + && is_Const(b) && is_Const_one(b) && (get_irn_op(get_Proj_pred(a)) == op_Cmp)) { /* 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), mode_b, get_negated_pnc(get_Proj_proj(a), mode)); DBG_OPT_ALGSIM0(oldn, n, FS_OPT_EOR_TO_NOT_BOOL); - } else if ((mode == mode_b) - && (classify_tarval (value_of(b)) == TV_CLASSIFY_ONE)) { + } else if (mode == mode_b && is_Const(b) && is_Const_one(b)) { /* The Eor is a Not. Replace it by a Not. */ /* ????!!!Extend to bitfield 1111111. */ n = new_r_Not(current_ir_graph, get_irn_n(n, -1), a, mode_b); @@ -3101,12 +3091,15 @@ static ir_node *transform_node_Not(ir_node *n) { DBG_OPT_ALGSIM0(oldn, n, FS_OPT_NOT_CMP); return n; } - if (op_a == op_Sub && classify_Const(get_Sub_right(a)) == CNST_ONE) { - /* ~(x-1) = -x */ - ir_node *op = get_Sub_left(a); - ir_node *blk = get_irn_n(n, -1); - 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); + if (op_a == op_Sub) { + ir_node *sub_r = get_Sub_right(a); + if (is_Const(sub_r) && is_Const_one(sub_r)) { + /* ~(x-1) = -x */ + ir_node *op = get_Sub_left(a); + ir_node *blk = get_irn_n(n, -1); + 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); + } } return n; } /* transform_node_Not */ @@ -3433,9 +3426,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { } /* TODO extend to arbitrary constants */ - if (is_Conv(left) && - is_Const(right) && - tarval_is_null(get_Const_tarval(right))) { + if (is_Conv(left) && is_Const(right) && is_Const_null(right)) { ir_mode* mode = get_irn_mode(left); ir_node* op = get_Conv_op(left); ir_mode* op_mode = get_irn_mode(op); @@ -3443,10 +3434,9 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (get_mode_size_bits(mode) > get_mode_size_bits(op_mode) && (mode_is_signed(mode) || !mode_is_signed(op_mode))) { ir_node *null = new_Const(op_mode, get_mode_null(op_mode)); - dbg_info *dbg = get_irn_dbg_info(n); - ir_graph *irg = current_ir_graph; - ir_node *block = get_nodes_block(n); - return new_rd_Cmp(dbg, irg, block, op, null); + set_Cmp_left( n, op); + set_Cmp_right(n, null); + return proj; } } @@ -3647,7 +3637,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { if (proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg) { /* a-b == 0 ==> a == b, a-b != 0 ==> a != b */ - if (classify_tarval(tv) == TV_CLASSIFY_NULL && is_Sub(left)) { + if (tarval_is_null(tv) && is_Sub(left)) { right =get_Sub_right(left); left = get_Sub_left(left); @@ -3897,8 +3887,8 @@ static ir_node *transform_node_Or_bf_store(ir_node *or) { tv2 = get_Const_tarval(c2); tv = tarval_or(tv1, tv2); - if (classify_tarval(tv) == TV_CLASSIFY_ALL_ONE) { - /* the AND does NOT clear a bit with isn't set be the OR */ + if (tarval_is_all_one(tv)) { + /* the AND does NOT clear a bit with isn't set by the OR */ set_Or_left(or, or_l); set_Or_right(or, c1); @@ -3926,7 +3916,7 @@ static ir_node *transform_node_Or_bf_store(ir_node *or) { tv4 = get_Const_tarval(c4); tv = tarval_or(tv4, tv2); - if (classify_tarval(tv) != TV_CLASSIFY_ALL_ONE) { + if (!tarval_is_all_one(tv)) { /* have at least one 0 at the same bit position */ return or; } @@ -4321,77 +4311,79 @@ static ir_node *transform_node_Mux(ir_node *n) { * However, if +0 and -0 is handled differently, we cannot use the first * one. */ - if (get_irn_op(cmp) == op_Cmp - && classify_Const(get_Cmp_right(cmp)) == CNST_NULL) { - ir_node *block = get_irn_n(n, -1); - - if(is_negated_value(f, t)) { - ir_node *cmp_left = get_Cmp_left(cmp); - - /* Psi(a >= 0, a, -a) = Psi(a <= 0, -a, a) ==> Abs(a) */ - if ( (cmp_left == t && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt)) - || (cmp_left == f && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt))) - { - n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block, - cmp_left, mode); - DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS); - return n; - /* Psi(a <= 0, a, -a) = Psi(a >= 0, -a, a) ==> -Abs(a) */ - } else if ((cmp_left == t && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt)) - || (cmp_left == f && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt))) - { - n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block, - cmp_left, mode); - n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, - block, n, mode); - DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS); - return n; + if (is_Cmp(cmp)) { + ir_node *cmp_r = get_Cmp_right(cmp); + if (is_Const(cmp_r) && is_Const_null(cmp_r)) { + ir_node *block = get_irn_n(n, -1); + + if(is_negated_value(f, t)) { + ir_node *cmp_left = get_Cmp_left(cmp); + + /* Psi(a >= 0, a, -a) = Psi(a <= 0, -a, a) ==> Abs(a) */ + if ( (cmp_left == t && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt)) + || (cmp_left == f && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt))) + { + n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block, + cmp_left, mode); + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS); + return n; + /* Psi(a <= 0, a, -a) = Psi(a >= 0, -a, a) ==> -Abs(a) */ + } else if ((cmp_left == t && (pn == pn_Cmp_Le || pn == pn_Cmp_Lt)) + || (cmp_left == f && (pn == pn_Cmp_Ge || pn == pn_Cmp_Gt))) + { + n = new_rd_Abs(get_irn_dbg_info(n), current_ir_graph, block, + cmp_left, mode); + n = new_rd_Minus(get_irn_dbg_info(n), current_ir_graph, + block, n, mode); + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_ABS); + return n; + } } - } - if (mode_is_int(mode) && mode_is_signed(mode) && - get_mode_arithmetic(mode) == irma_twos_complement) { - ir_node *x = get_Cmp_left(cmp); + if (mode_is_int(mode) && mode_is_signed(mode) && + get_mode_arithmetic(mode) == irma_twos_complement) { + ir_node *x = get_Cmp_left(cmp); - /* the following optimization works only with signed integer two-complement mode */ + /* the following optimization works only with signed integer two-complement mode */ - if (mode == get_irn_mode(x)) { - /* - * FIXME: this restriction is two rigid, as it would still - * work if mode(x) = Hs and mode == Is, but at least it removes - * all wrong cases. - */ - if ((pn == pn_Cmp_Lt || pn == pn_Cmp_Le) && - classify_Const(t) == CNST_ALL_ONE && - classify_Const(f) == CNST_NULL) { + if (mode == get_irn_mode(x)) { /* - * Mux(x:T Shrs(x, sizeof_bits(T) - 1) - * Conditions: - * T must be signed. + * FIXME: this restriction is two rigid, as it would still + * work if mode(x) = Hs and mode == Is, but at least it removes + * all wrong cases. */ - n = new_rd_Shrs(get_irn_dbg_info(n), - current_ir_graph, block, x, + if ((pn == pn_Cmp_Lt || pn == pn_Cmp_Le) && + is_Const(t) && is_Const_all_one(t) && + is_Const(f) && is_Const_null(f)) { + /* + * Mux(x:T Shrs(x, sizeof_bits(T) - 1) + * Conditions: + * T must be signed. + */ + n = new_rd_Shrs(get_irn_dbg_info(n), + current_ir_graph, block, x, + new_r_Const_long(current_ir_graph, block, mode_Iu, + get_mode_size_bits(mode) - 1), + mode); + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR); + return n; + } else if ((pn == pn_Cmp_Gt || pn == pn_Cmp_Ge) && + is_Const(t) && is_Const_one(t) && + is_Const(f) && is_Const_null(f)) { + /* + * Mux(x:T >/>= 0, 0, 1) -> Shr(-x, sizeof_bits(T) - 1) + * Conditions: + * T must be signed. + */ + n = new_rd_Shr(get_irn_dbg_info(n), + current_ir_graph, block, + new_r_Minus(current_ir_graph, block, x, mode), new_r_Const_long(current_ir_graph, block, mode_Iu, get_mode_size_bits(mode) - 1), mode); - DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR); - return n; - } else if ((pn == pn_Cmp_Gt || pn == pn_Cmp_Ge) && - classify_Const(t) == CNST_ONE && - classify_Const(f) == CNST_NULL) { - /* - * Mux(x:T >/>= 0, 0, 1) -> Shr(-x, sizeof_bits(T) - 1) - * Conditions: - * T must be signed. - */ - n = new_rd_Shr(get_irn_dbg_info(n), - current_ir_graph, block, - new_r_Minus(current_ir_graph, block, x, mode), - new_r_Const_long(current_ir_graph, block, mode_Iu, - get_mode_size_bits(mode) - 1), - mode); - DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR); - return n; + DBG_OPT_ALGSIM1(oldn, cmp, sel, n, FS_OPT_MUX_TO_SHR); + return n; + } } } }