updated
[libfirm] / ir / opt / opt_confirms.c
index 95df834..ef18b69 100644 (file)
@@ -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.
  *
@@ -105,7 +105,9 @@ int value_not_zero(ir_node *n, ir_node **confirm) {
        pn_Cmp pnc;
 
        *confirm = NULL;
-       while (get_irn_op(n) == op_Confirm) {
+
+       /* there might be several Confirms one after other that form an interval */
+       for (; is_Confirm(n); n = get_Confirm_value(n)) {
                /*
                 * Note: A Confirm is never after a Const. So,
                 * we simply can check the bound for being a Const
@@ -141,9 +143,6 @@ int value_not_zero(ir_node *n, ir_node **confirm) {
                default:
                        break;
                }
-
-               /* there might be several Confirms one after other that form an interval */
-               n = get_Confirm_value(n);
        }
        tv = value_of(n);
 
@@ -172,6 +171,7 @@ int value_not_null(ir_node *n, ir_node **confirm) {
 
        *confirm = NULL;
        n  = skip_Cast(n);
+
        op = get_irn_op(n);
        assert(mode_is_reference(get_irn_mode(n)));
        if (get_opt_sel_based_null_check_elim()) {
@@ -184,15 +184,17 @@ int value_not_null(ir_node *n, ir_node **confirm) {
        if (op == op_SymConst && get_SymConst_kind(n) == symconst_addr_ent)
                return 1;
        if (op == op_Const) {
-               tarval *tv = get_Const_tarval(n);
-
-               if (tv != tarval_bad && classify_tarval(tv) != TV_CLASSIFY_NULL)
+               if (!is_Const_null(n))
                        return 1;
-       } else if (op == op_Confirm) {
-               if (get_Confirm_cmp(n) == pn_Cmp_Lg &&
-                       classify_Const(get_Confirm_bound(n)) == CNST_NULL) {
-                               *confirm = n;
-                               return 1;
+       } else {
+               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);
+                               if (is_Const(bound) && is_Const_null(bound)) {
+                                       *confirm = n;
+                                       return 1;
+                               }
+                       }
                }
        }
        return 0;
@@ -571,7 +573,6 @@ static int is_transitive(pn_Cmp pnc) {
        return (pn_Cmp_False < pnc && pnc < pn_Cmp_Lg);
 }  /* is_transitive */
 
-
 /**
  * Return the value of a Cmp if one or both predecessors
  * are Confirm nodes.
@@ -582,22 +583,20 @@ static int is_transitive(pn_Cmp pnc) {
  * @param pnc    the compare relation
  */
 tarval *computed_value_Cmp_Confirm(ir_node *cmp, ir_node *left, ir_node *right, pn_Cmp pnc) {
-       ir_node    *l_bound;
-       pn_Cmp     l_pnc, res_pnc, neg_pnc;
-       interval_t l_iv, r_iv;
-       tarval     *tv;
-       ir_mode    *mode;
-
-       if (get_irn_op(right) == op_Confirm) {
-               ir_node *t;
+       ir_node         *l_bound;
+       pn_Cmp          l_pnc, res_pnc, neg_pnc;
+       interval_t      l_iv, r_iv;
+       tarval          *tv;
+       ir_mode         *mode;
 
+       if (is_Confirm(right)) {
                /* we want the Confirm on the left side */
-               t     = left;
-               left  = right;
-               right = t;
+               ir_node *t = right;
+               right = left;
+               left  = t;
 
                pnc = get_inversed_pnc(pnc);
-       } else if (get_irn_op(left) != op_Confirm) {
+       } else if (! is_Confirm(left)) {
                /* no Confirm on either one side, finish */
                return tarval_bad;
        }
@@ -606,16 +605,16 @@ tarval *computed_value_Cmp_Confirm(ir_node *cmp, ir_node *left, ir_node *right,
        l_bound = get_Confirm_bound(left);
        l_pnc   = get_Confirm_cmp(left);
 
-       if (get_irn_op(right) == op_Confirm) {
+       if (is_Confirm(right)) {
                /*
-               * both sides are Confirm's. Check some rare cases first.
-               */
+                * both sides are Confirm's. Check some rare cases first.
+                */
                ir_node *r_bound = get_Confirm_bound(right);
-               pn_Cmp  r_pnc = get_Confirm_cmp(right);
+               pn_Cmp  r_pnc    = get_Confirm_cmp(right);
 
                /*
-               * some check can be made WITHOUT constant bounds
-               */
+                * some check can be made WITHOUT constant bounds
+                */
                if (r_bound == l_bound) {
                        if (is_transitive(l_pnc)) {
                                pn_Cmp r_inc_pnc = get_inversed_pnc(r_pnc);