X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fopt_confirms.c;h=28e0ef7d5588b7ad8c1738481bfd5d684fefb1f2;hb=c7dc950ac0cdd7d24acffb798b5867d0db5dd7c8;hp=a0f7ceb5318a246bfa9dd6f4b6d1e93d357bf204;hpb=3977737475ce98c71e45f363a053e47d5d1bb39d;p=libfirm diff --git a/ir/opt/opt_confirms.c b/ir/opt/opt_confirms.c index a0f7ceb53..28e0ef7d5 100644 --- a/ir/opt/opt_confirms.c +++ b/ir/opt/opt_confirms.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. * @@ -107,7 +107,15 @@ int value_not_zero(ir_node *n, ir_node **confirm) { *confirm = NULL; /* there might be several Confirms one after other that form an interval */ - for (; is_Confirm(n); n = get_Confirm_value(n)) { + for (;;) { + if (is_Minus(n) || is_Abs(n)) { + /* we can safely skip Minus and Abs when checking for != 0 */ + n = get_unop_op(n); + continue; + } + if (! is_Confirm(n)) + break; + /* * Note: A Confirm is never after a Const. So, * we simply can check the bound for being a Const @@ -143,6 +151,7 @@ int value_not_zero(ir_node *n, ir_node **confirm) { default: break; } + n = get_Confirm_value(n); } tv = value_of(n); @@ -181,14 +190,17 @@ int value_not_null(ir_node *n, ir_node **confirm) { op = get_irn_op(n); } } - if (op == op_SymConst && get_SymConst_kind(n) == symconst_addr_ent) + if (is_Global(n)) { + /* global references are never NULL */ return 1; - if (op == op_Const) { - tarval *tv = get_Const_tarval(n); - - if (tv != tarval_bad && !tarval_is_null(tv)) - return 1; + } else if (n == get_irg_frame(current_ir_graph)) { + /* local references are never NULL */ + return 1; + } else if (op == op_Const) { + /* explicit non-NULL addresses */ + return !is_Const_null(n); } else { + /* check for more Confirms */ for (; is_Confirm(n); n = skip_Cast(get_Confirm_value(n))) { if (get_Confirm_cmp(n) != pn_Cmp_Lg) { ir_node *bound = get_Confirm_bound(n); @@ -211,7 +223,23 @@ value_classify_sign classify_value_sign(ir_node *n) { tarval *tv, *c; ir_mode *mode; pn_Cmp cmp, ncmp; + int negate = 1; + for (;;) { + ir_opcode code = get_irn_opcode(n); + + switch (code) { + case iro_Minus: + negate *= -1; + n = get_Minus_op(n); + continue; + case iro_Confirm: + break; + default: + return value_classified_unknown; + } + break; + } if (get_irn_op(n) != op_Confirm) return value_classified_unknown; @@ -254,7 +282,7 @@ value_classify_sign classify_value_sign(ir_node *n) { return value_classified_unknown; /* yep, negative */ - return value_classified_negative; + return value_classified_negative * negate; case pn_Cmp_Ge: /* @@ -285,7 +313,7 @@ value_classify_sign classify_value_sign(ir_node *n) { } /* yep, positive */ - return value_classified_positive; + return value_classified_positive * negate; default: return value_classified_unknown; @@ -599,8 +627,9 @@ tarval *computed_value_Cmp_Confirm(ir_node *cmp, ir_node *left, ir_node *right, pnc = get_inversed_pnc(pnc); } else if (! is_Confirm(left)) { - /* no Confirm on either one side, finish */ - return tarval_bad; + /* nothing more found */ + tv = tarval_bad; + goto check_null_case; } /* ok, here at least left is a Confirm, right might be */ @@ -733,6 +762,24 @@ tarval *computed_value_Cmp_Confirm(ir_node *cmp, ir_node *left, ir_node *right, get_interval(&l_iv, l_bound, l_pnc), get_interval_from_tv(&r_iv, tv), pnc); + } else { +check_null_case: + /* check some other cases */ + if ((pnc == pn_Cmp_Eq || pnc == pn_Cmp_Lg) && + is_Const(right) && is_Const_null(right)) { + /* for == 0 or != 0 we have some special tools */ + ir_mode *mode = get_irn_mode(left); + ir_node *dummy; + if (mode_is_reference(mode)) { + if (value_not_null(left, &dummy)) { + tv = pnc == pn_Cmp_Eq ? tarval_b_false : tarval_b_true; + } + } else { + if (value_not_zero(left, &dummy)) { + tv = pnc == pn_Cmp_Eq ? tarval_b_false : tarval_b_true; + } + } + } } if (tv != tarval_bad)