From: Michael Beck Date: Thu, 3 Apr 2008 13:12:57 +0000 (+0000) Subject: improved Cmp(x, 0) optimizations X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=8829c3217ea4a00be8af74a260f8ca79367361f2;p=libfirm improved Cmp(x, 0) optimizations [r19089] --- diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index f6367d04a..ac9fe39cf 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -3647,11 +3647,9 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { break; } - /* remove Casts */ - if (is_Cast(left)) - left = get_Cast_op(left); - if (is_Cast(right)) - right = get_Cast_op(right); + /* remove Casts of both sides */ + left = skip_Cast(left); + right = skip_Cast(right); /* Remove unnecessary conversions */ /* TODO handle constants */ @@ -3686,7 +3684,7 @@ static ir_node *transform_node_Proj_Cmp(ir_node *proj) { } } - /* remove operation of both sides if possible */ + /* remove operation on both sides if possible */ if (proj_nr == pn_Cmp_Eq || proj_nr == pn_Cmp_Lg) { /* * The following operations are NOT safe for floating point operations, for instance diff --git a/ir/opt/opt_confirms.c b/ir/opt/opt_confirms.c index 0e6ca9a58..28e0ef7d5 100644 --- a/ir/opt/opt_confirms.c +++ b/ir/opt/opt_confirms.c @@ -190,12 +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) { - if (!is_Const_null(n)) - 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); @@ -622,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 */ @@ -756,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)