- 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;
-
- /* we want the Confirm on the left side */
- t = left;
- left = right;
- right = t;
-
- pnc = get_inversed_pnc(pnc);
- }
- else if (get_irn_op(left) != op_Confirm) {
- /* no Confirm on either one side, finish */
- return tarval_bad;
- }
-
- /* ok, here at least left is a Confirm, right might be */
- l_bound = get_Confirm_bound(left);
- l_pnc = get_Confirm_cmp(left);
-
- if (get_irn_op(right) == op_Confirm) {
- /*
- * 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);
-
- /*
- * 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);
-
- /*
- * triangle inequality:
- *
- * a CMP B && B CMP b => a CMP b, !(a ~CMP b)
- *
- * We handle correctly cases with some <=/>= here
- */
- if ((l_pnc & ~pn_Cmp_Eq) == (r_inc_pnc & ~pn_Cmp_Eq)) {
- res_pnc = (l_pnc & ~pn_Cmp_Eq) | (l_pnc & r_inc_pnc & pn_Cmp_Eq);
-
- if ((pnc == res_pnc) || ((pnc & ~pn_Cmp_Eq) == res_pnc)) {
- DBG_OUT_TR(l_pnc, l_bound, r_pnc, r_bound, pnc, "true");
- DBG_EVAL_CONFIRM(cmp);
- return tarval_b_true;
- }
- else {
- pn_Cmp neg_pnc = get_negated_pnc(pnc, get_irn_mode(left));
-
- if ((neg_pnc == res_pnc) || ((neg_pnc & ~pn_Cmp_Eq) == res_pnc)) {
- DBG_OUT_TR(l_pnc, l_bound, r_pnc, r_bound, pnc, "false");
- DBG_EVAL_CONFIRM(cmp);
- return tarval_b_false;
- }
- }
- }
- }
- }
-
- /*
- * Here, we check only the right Confirm, as the left Confirms are
- * checked later anyway.
- */
-
- if (left == r_bound) {
- /*
- * l == bound(r) AND pnc(r) == pnc:
- *
- * We know that a CMP b and check for that
- */
- if ((r_pnc == pnc) || (r_pnc == (pnc & ~pn_Cmp_Eq))) {
- DBG_OUT_R(r_pnc, r_bound, left, pnc, right, "true");
- DBG_EVAL_CONFIRM(cmp);
- return tarval_b_true;
- }
- /*
- * l == bound(r) AND pnc(r) != pnc:
- *
- * We know that a CMP b and check for a ~CMP b
- */
- else {
- mode = get_irn_mode(left);
- neg_pnc = get_negated_pnc(pnc, mode);
-
- if ((r_pnc == neg_pnc) || (r_pnc == (neg_pnc & ~pn_Cmp_Eq))) {
- DBG_OUT_R(r_pnc, r_bound, left, pnc, right, "false");
- DBG_EVAL_CONFIRM(cmp);
- return tarval_b_false;
- }
- }
- }
-
- /* now, try interval magic */
- tv = compare_iv(
- get_interval(&l_iv, l_bound, l_pnc),
- get_interval(&r_iv, r_bound, r_pnc),
- pnc);
-
- if (tv != tarval_bad) {
- DBG_EVAL_CONFIRM(cmp);
- return tv;
- }
- }
-
- /* from Here, check only left Confirm */
-
- /*
- * some checks can be made WITHOUT constant bounds
- */
- if (right == l_bound) {
- /*
- * r == bound(l) AND pnc(l) == pnc:
- *
- * We know that a CMP b and check for that
- */
- if ((l_pnc == pnc) || (l_pnc == (pnc & ~pn_Cmp_Eq))) {
- DBG_OUT_L(l_pnc, l_bound, left, pnc, right, "true");
- DBG_EVAL_CONFIRM(cmp);
- return tarval_b_true;
- }
- /*
- * r == bound(l) AND pnc(l) is Not(pnc):
- *
- * We know that a CMP b and check for a ~CMP b
- */
- else {
- mode = get_irn_mode(left);
- neg_pnc = get_negated_pnc(pnc, mode);
-
- if ((l_pnc == neg_pnc) || (l_pnc == (neg_pnc & ~pn_Cmp_Eq))) {
- DBG_OUT_L(l_pnc, l_bound, left, pnc, right, "false");
- DBG_EVAL_CONFIRM(cmp);
- return tarval_b_false;
- }
- }
- }
-
- /* now, only right == Const can help */
- tv = value_of(right);
-
- if (tv != tarval_bad) {
- tv = compare_iv(
- get_interval(&l_iv, l_bound, l_pnc),
- get_interval_from_tv(&r_iv, tv),
- pnc);
- }
-
- if (tv != tarval_bad)
- DBG_EVAL_CONFIRM(cmp);
-
- return tv;
+ ir_node *l_bound;
+ pn_Cmp l_pnc, res_pnc, neg_pnc;
+ interval_t l_iv, r_iv;
+ ir_tarval *tv;
+ ir_mode *mode;
+
+ if (is_Confirm(right)) {
+ /* we want the Confirm on the left side */
+ ir_node *t = right;
+ right = left;
+ left = t;
+
+ pnc = get_inversed_pnc(pnc);
+ } else if (! is_Confirm(left)) {
+ /* nothing more found */
+ tv = tarval_bad;
+ goto check_null_case;
+ }
+
+ /* ok, here at least left is a Confirm, right might be */
+ l_bound = get_Confirm_bound(left);
+ l_pnc = get_Confirm_cmp(left);
+
+ if (is_Confirm(right)) {
+ /*
+ * 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);
+
+ /*
+ * 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);
+
+ /*
+ * triangle inequality:
+ *
+ * a CMP B && B CMP b => a CMP b, !(a ~CMP b)
+ *
+ * We handle correctly cases with some <=/>= here
+ */
+ if ((l_pnc & ~pn_Cmp_Eq) == (r_inc_pnc & ~pn_Cmp_Eq)) {
+ res_pnc = (l_pnc & ~pn_Cmp_Eq) | (l_pnc & r_inc_pnc & pn_Cmp_Eq);
+
+ if ((pnc == res_pnc) || ((pnc & ~pn_Cmp_Eq) == res_pnc)) {
+ DBG_OUT_TR(l_pnc, l_bound, r_pnc, r_bound, pnc, "true");
+ DBG_EVAL_CONFIRM(cmp);
+ return tarval_b_true;
+ } else {
+ pn_Cmp neg_pnc = get_negated_pnc(pnc, get_irn_mode(left));
+
+ if ((neg_pnc == res_pnc) || ((neg_pnc & ~pn_Cmp_Eq) == res_pnc)) {
+ DBG_OUT_TR(l_pnc, l_bound, r_pnc, r_bound, pnc, "false");
+ DBG_EVAL_CONFIRM(cmp);
+ return tarval_b_false;
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * Here, we check only the right Confirm, as the left Confirms are
+ * checked later anyway.
+ */
+ if (left == r_bound) {
+ /*
+ * l == bound(r) AND pnc(r) == pnc:
+ *
+ * We know that a CMP b and check for that
+ */
+ if ((r_pnc == pnc) || (r_pnc == (pnc & ~pn_Cmp_Eq))) {
+ DBG_OUT_R(r_pnc, r_bound, left, pnc, right, "true");
+ DBG_EVAL_CONFIRM(cmp);
+ return tarval_b_true;
+ }
+ /*
+ * l == bound(r) AND pnc(r) != pnc:
+ *
+ * We know that a CMP b and check for a ~CMP b
+ */
+ else {
+ mode = get_irn_mode(left);
+ neg_pnc = get_negated_pnc(pnc, mode);
+
+ if ((r_pnc == neg_pnc) || (r_pnc == (neg_pnc & ~pn_Cmp_Eq))) {
+ DBG_OUT_R(r_pnc, r_bound, left, pnc, right, "false");
+ DBG_EVAL_CONFIRM(cmp);
+ return tarval_b_false;
+ }
+ }
+ }
+
+ /* now, try interval magic */
+ tv = compare_iv(
+ get_interval(&l_iv, l_bound, l_pnc),
+ get_interval(&r_iv, r_bound, r_pnc),
+ pnc);
+
+ if (tv != tarval_bad) {
+ DBG_EVAL_CONFIRM(cmp);
+ return tv;
+ }
+ }
+
+ /* from Here, check only left Confirm */
+
+ /*
+ * some checks can be made WITHOUT constant bounds
+ */
+ if (right == l_bound) {
+ /*
+ * r == bound(l) AND pnc(l) == pnc:
+ *
+ * We know that a CMP b and check for that
+ */
+ if ((l_pnc == pnc) || (l_pnc == (pnc & ~pn_Cmp_Eq))) {
+ DBG_OUT_L(l_pnc, l_bound, left, pnc, right, "true");
+ DBG_EVAL_CONFIRM(cmp);
+ return tarval_b_true;
+ }
+ /*
+ * r == bound(l) AND pnc(l) is Not(pnc):
+ *
+ * We know that a CMP b and check for a ~CMP b
+ */
+ else {
+ mode = get_irn_mode(left);
+ neg_pnc = get_negated_pnc(pnc, mode);
+
+ if ((l_pnc == neg_pnc) || (l_pnc == (neg_pnc & ~pn_Cmp_Eq))) {
+ DBG_OUT_L(l_pnc, l_bound, left, pnc, right, "false");
+ DBG_EVAL_CONFIRM(cmp);
+ return tarval_b_false;
+ }
+ }
+ }
+
+ /* now, only right == Const can help */
+ tv = value_of(right);
+
+ if (tv != tarval_bad) {
+ tv = compare_iv(
+ 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);
+ const 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)
+ DBG_EVAL_CONFIRM(cmp);
+
+ return tv;