beloopana: Remove duplicate comments.
[libfirm] / ir / ir / iropt.c
index 0b3b658..981f01f 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2011 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
@@ -50,6 +36,8 @@
 #include "firm_types.h"
 #include "bitfiddle.h"
 #include "be.h"
+#include "error.h"
+#include "firmstat_t.h"
 
 #include "entity_t.h"
 
@@ -180,48 +168,6 @@ static ir_tarval *computed_value_Sub(const ir_node *n)
        return tarval_bad;
 }
 
-/**
- * Return the value of a Carry.
- * Special : a op 0, 0 op b
- */
-static ir_tarval *computed_value_Carry(const ir_node *n)
-{
-       ir_node   *a  = get_binop_left(n);
-       ir_node   *b  = get_binop_right(n);
-       ir_mode   *m  = get_irn_mode(n);
-       ir_tarval *ta = value_of(a);
-       ir_tarval *tb = value_of(b);
-
-       if ((ta != tarval_bad) && (tb != tarval_bad)) {
-               tarval_add(ta, tb);
-               return tarval_carry() ? get_mode_one(m) : get_mode_null(m);
-       } else {
-               if (tarval_is_null(ta) || tarval_is_null(tb))
-                       return get_mode_null(m);
-       }
-       return tarval_bad;
-}
-
-/**
- * Return the value of a Borrow.
- * Special : a op 0
- */
-static ir_tarval *computed_value_Borrow(const ir_node *n)
-{
-       ir_node   *a  = get_binop_left(n);
-       ir_node   *b  = get_binop_right(n);
-       ir_mode   *m  = get_irn_mode(n);
-       ir_tarval *ta = value_of(a);
-       ir_tarval *tb = value_of(b);
-
-       if ((ta != tarval_bad) && (tb != tarval_bad)) {
-               return tarval_cmp(ta, tb) == ir_relation_less ? get_mode_one(m) : get_mode_null(m);
-       } else if (tarval_is_null(ta)) {
-               return get_mode_null(m);
-       }
-       return tarval_bad;
-}
-
 /**
  * Return the value of an unary Minus.
  */
@@ -946,15 +892,13 @@ static ir_node *equivalent_node_Sub(ir_node *n)
  *   We handle it anyway here but the better way would be a
  *   flag. This would be needed for Pascal for instance.
  */
-static ir_node *equivalent_node_idempotent_unop(ir_node *n)
+static ir_node *equivalent_node_involution(ir_node *n)
 {
        ir_node *oldn = n;
        ir_node *pred = get_unop_op(n);
-
-       /* optimize symmetric unop */
        if (get_irn_op(pred) == get_irn_op(n)) {
                n = get_unop_op(pred);
-               DBG_OPT_ALGSIM2(oldn, pred, n, FS_OPT_IDEM_UNARY);
+               DBG_OPT_ALGSIM2(oldn, pred, n, FS_OPT_INVOLUTION);
        }
        return n;
 }
@@ -1101,121 +1045,18 @@ static ir_node *equivalent_node_Conv(ir_node *n)
        ir_mode *n_mode = get_irn_mode(n);
        ir_mode *a_mode = get_irn_mode(a);
 
-restart:
        if (n_mode == a_mode) { /* No Conv necessary */
-               if (get_Conv_strict(n)) {
-                       ir_node *p = a;
-
-                       /* neither Minus nor Confirm change the precision,
-                          so we can "look-through" */
-                       for (;;) {
-                               if (is_Minus(p)) {
-                                       p = get_Minus_op(p);
-                               } else if (is_Confirm(p)) {
-                                       p = get_Confirm_value(p);
-                               } else {
-                                       /* stop here */
-                                       break;
-                               }
-                       }
-                       if (is_Conv(p) && get_Conv_strict(p)) {
-                               /* we known already, that a_mode == n_mode, and neither
-                                  Minus change the mode, so the second Conv
-                                  can be kicked */
-                               assert(get_irn_mode(p) == n_mode);
-                               n = a;
-                               DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
-                               return n;
-                       }
-                       if (is_Proj(p)) {
-                               ir_node *pred = get_Proj_pred(p);
-                               if (is_Load(pred)) {
-                                       /* Loads always return with the exact precision of n_mode */
-                                       assert(get_Load_mode(pred) == n_mode);
-                                       n = a;
-                                       DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
-                                       return n;
-                               }
-                               if (is_Proj(pred) && get_Proj_proj(pred) == pn_Start_T_args) {
-                                       pred = get_Proj_pred(pred);
-                                       if (is_Start(pred)) {
-                                               /* Arguments always return with the exact precision,
-                                                  as strictConv's are place before Call -- if the
-                                                  caller was compiled with the same setting.
-                                                  Otherwise, the semantics is probably still right. */
-                                               assert(get_irn_mode(p) == n_mode);
-                                               n = a;
-                                               DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
-                                               return n;
-                                       }
-                               }
-                       }
-                       if (is_Conv(a)) {
-                               /* special case: the immediate predecessor is also a Conv */
-                               if (! get_Conv_strict(a)) {
-                                       /* first one is not strict, kick it */
-                                       a = get_Conv_op(a);
-                                       a_mode = get_irn_mode(a);
-                                       set_Conv_op(n, a);
-                                       goto restart;
-                               }
-                               /* else both are strict conv, second is superfluous */
-                               n = a;
-                               DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
-                               return n;
-                       }
-               } else {
-                       n = a;
-                       DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
-                       return n;
-               }
+               n = a;
+               DBG_OPT_ALGSIM0(oldn, n, FS_OPT_CONV);
+               return n;
        } else if (is_Conv(a)) { /* Conv(Conv(b)) */
                ir_node *b      = get_Conv_op(a);
                ir_mode *b_mode = get_irn_mode(b);
 
-               if (get_Conv_strict(n) && get_Conv_strict(a)) {
-                       /* both are strict conv */
-                       if (smaller_mode(a_mode, n_mode)) {
-                               /* both are strict, but the first is smaller, so
-                                  the second cannot remove more precision, remove the
-                                  strict bit */
-                               set_Conv_strict(n, 0);
-                       }
-               }
-               if (n_mode == b_mode) {
-                       if (! get_Conv_strict(n) && ! get_Conv_strict(a)) {
-                               if (n_mode == mode_b) {
-                                       n = b; /* Convb(Conv*(xxxb(...))) == xxxb(...) */
-                                       DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
-                                       return n;
-                               } else if (get_mode_arithmetic(n_mode) == get_mode_arithmetic(a_mode)) {
-                                       if (values_in_mode(b_mode, a_mode)) {
-                                               n = b;        /* ConvS(ConvL(xxxS(...))) == xxxS(...) */
-                                               DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
-                                               return n;
-                                       }
-                               }
-                       }
-                       if (mode_is_int(n_mode) && get_mode_arithmetic(a_mode) == irma_ieee754) {
-                               /* ConvI(ConvF(I)) -> I, iff float mantissa >= int mode */
-                               unsigned int_mantissa   = get_mode_size_bits(n_mode) - (mode_is_signed(n_mode) ? 1 : 0);
-                               unsigned float_mantissa = get_mode_mantissa_size(a_mode);
-
-                               if (float_mantissa >= int_mantissa) {
-                                       n = b;
-                                       DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
-                                       return n;
-                               }
-                       }
-                       if (is_Conv(b)) {
-                               if (smaller_mode(b_mode, a_mode)) {
-                                       if (get_Conv_strict(n))
-                                               set_Conv_strict(b, 1);
-                                       n = b; /* ConvA(ConvB(ConvA(...))) == ConvA(...) */
-                                       DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
-                                       return n;
-                               }
-                       }
+               if (n_mode == b_mode && values_in_mode(b_mode, a_mode)) {
+                       n = b;
+                       DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
+                       return n;
                }
        }
        return n;
@@ -1233,7 +1074,7 @@ static ir_node *equivalent_node_Phi(ir_node *n)
        ir_node *first_val = NULL; /* to shutup gcc */
 
        if (!get_opt_optimize() &&
-                       get_irg_phase_state(get_irn_irg(n)) != phase_building)
+           !irg_is_constrained(get_irn_irg(n), IR_GRAPH_CONSTRAINT_CONSTRUCTION))
                return n;
 
        n_preds = get_Phi_n_preds(n);
@@ -1338,56 +1179,6 @@ static ir_node *equivalent_node_Proj_CopyB(ir_node *proj)
        return proj;
 }
 
-/**
- * Optimize Bounds(idx, idx, upper) into idx.
- */
-static ir_node *equivalent_node_Proj_Bound(ir_node *proj)
-{
-       ir_node *oldn  = proj;
-       ir_node *bound = get_Proj_pred(proj);
-       ir_node *idx   = get_Bound_index(bound);
-       ir_node *pred  = skip_Proj(idx);
-       int ret_tuple  = 0;
-
-       if (idx == get_Bound_lower(bound))
-               ret_tuple = 1;
-       else if (is_Bound(pred)) {
-               /*
-                * idx was Bounds checked previously, it is still valid if
-                * lower <= pred_lower && pred_upper <= upper.
-                */
-               ir_node *lower = get_Bound_lower(bound);
-               ir_node *upper = get_Bound_upper(bound);
-               if (get_Bound_lower(pred) == lower &&
-                       get_Bound_upper(pred) == upper) {
-                       /*
-                        * One could expect that we simply return the previous
-                        * Bound here. However, this would be wrong, as we could
-                        * add an exception Proj to a new location then.
-                        * So, we must turn in into a tuple.
-                        */
-                       ret_tuple = 1;
-               }
-       }
-       if (ret_tuple) {
-               /* Turn Bound into a tuple (mem, jmp, bad, idx) */
-               switch (get_Proj_proj(proj)) {
-               case pn_Bound_M:
-                       DBG_OPT_EXC_REM(proj);
-                       proj = get_Bound_mem(bound);
-                       break;
-               case pn_Bound_res:
-                       proj = idx;
-                       DBG_OPT_ALGSIM0(oldn, proj, FS_OPT_NOP);
-                       break;
-               default:
-                       /* cannot optimize pn_Bound_X_regular, handled in transform ... */
-                       break;
-               }
-       }
-       return proj;
-}
-
 /**
  * Does all optimizations on nodes that must be done on its Projs
  * because of creating new nodes.
@@ -1613,44 +1404,40 @@ static ir_tarval *do_eval(eval_func eval, ir_tarval *a, ir_tarval *b, ir_mode *m
  */
 static ir_node *apply_binop_on_phi(ir_node *phi, ir_tarval *other, eval_func eval, ir_mode *mode, int left)
 {
-       ir_tarval *tv;
-       void      **res;
-       ir_node   *pred;
-       ir_graph  *irg;
-       int       i, n = get_irn_arity(phi);
-
-       NEW_ARR_A(void *, res, n);
+       int         n   = get_irn_arity(phi);
+       ir_tarval **tvs = ALLOCAN(ir_tarval*, n);
        if (left) {
-               for (i = 0; i < n; ++i) {
-                       pred = get_irn_n(phi, i);
-                       tv   = get_Const_tarval(pred);
-                       tv   = do_eval(eval, other, tv, mode);
+               for (int i = 0; i < n; ++i) {
+                       ir_node   *pred = get_irn_n(phi, i);
+                       ir_tarval *tv   = get_Const_tarval(pred);
+                       tv = do_eval(eval, other, tv, mode);
 
                        if (tv == tarval_bad) {
                                /* folding failed, bad */
                                return NULL;
                        }
-                       res[i] = tv;
+                       tvs[i] = tv;
                }
        } else {
-               for (i = 0; i < n; ++i) {
-                       pred = get_irn_n(phi, i);
-                       tv   = get_Const_tarval(pred);
-                       tv   = do_eval(eval, tv, other, mode);
+               for (int i = 0; i < n; ++i) {
+                       ir_node   *pred = get_irn_n(phi, i);
+                       ir_tarval *tv   = get_Const_tarval(pred);
+                       tv = do_eval(eval, tv, other, mode);
 
                        if (tv == tarval_bad) {
                                /* folding failed, bad */
                                return 0;
                        }
-                       res[i] = tv;
+                       tvs[i] = tv;
                }
        }
-       irg = get_irn_irg(phi);
-       for (i = 0; i < n; ++i) {
-               pred = get_irn_n(phi, i);
-               res[i] = new_r_Const(irg, (ir_tarval*)res[i]);
+       ir_graph *irg = get_irn_irg(phi);
+       ir_node **res = ALLOCAN(ir_node*, n);
+       for (int i = 0; i < n; ++i) {
+               res[i] = new_r_Const(irg, tvs[i]);
        }
-       return new_r_Phi(get_nodes_block(phi), n, (ir_node **)res, mode);
+       ir_node *block = get_nodes_block(phi);
+       return new_r_Phi(block, n, res, mode);
 }
 
 /**
@@ -1665,37 +1452,31 @@ static ir_node *apply_binop_on_phi(ir_node *phi, ir_tarval *other, eval_func eva
  */
 static ir_node *apply_binop_on_2_phis(ir_node *a, ir_node *b, eval_func eval, ir_mode *mode)
 {
-       ir_tarval *tv_l, *tv_r, *tv;
-       void     **res;
-       ir_node  *pred;
-       ir_graph *irg;
-       int      i, n;
-
        if (get_nodes_block(a) != get_nodes_block(b))
                return NULL;
 
-       n = get_irn_arity(a);
-       NEW_ARR_A(void *, res, n);
-
-       for (i = 0; i < n; ++i) {
-               pred = get_irn_n(a, i);
-               tv_l = get_Const_tarval(pred);
-               pred = get_irn_n(b, i);
-               tv_r = get_Const_tarval(pred);
-               tv   = do_eval(eval, tv_l, tv_r, mode);
+       int         n   = get_irn_arity(a);
+       ir_tarval **tvs = ALLOCAN(ir_tarval*, n);
+       for (int i = 0; i < n; ++i) {
+               ir_node   *pred_a = get_irn_n(a, i);
+               ir_tarval *tv_l   = get_Const_tarval(pred_a);
+               ir_node   *pred_b = get_irn_n(b, i);
+               ir_tarval *tv_r   = get_Const_tarval(pred_b);
+               ir_tarval *tv     = do_eval(eval, tv_l, tv_r, mode);
 
                if (tv == tarval_bad) {
                        /* folding failed, bad */
                        return NULL;
                }
-               res[i] = tv;
+               tvs[i] = tv;
        }
-       irg = get_irn_irg(a);
-       for (i = 0; i < n; ++i) {
-               pred = get_irn_n(a, i);
-               res[i] = new_r_Const(irg, (ir_tarval*)res[i]);
+       ir_graph *irg = get_irn_irg(a);
+       ir_node **res = ALLOCAN(ir_node*, n);
+       for (int i = 0; i < n; ++i) {
+               res[i] = new_r_Const(irg, tvs[i]);
        }
-       return new_r_Phi(get_nodes_block(a), n, (ir_node **)res, mode);
+       ir_node *block = get_nodes_block(a);
+       return new_r_Phi(block, n, res, mode);
 }
 
 /**
@@ -1708,32 +1489,27 @@ static ir_node *apply_binop_on_2_phis(ir_node *a, ir_node *b, eval_func eval, ir
  */
 static ir_node *apply_unop_on_phi(ir_node *phi, ir_tarval *(*eval)(ir_tarval *))
 {
-       ir_tarval *tv;
-       void     **res;
-       ir_node  *pred;
-       ir_mode  *mode;
-       ir_graph *irg;
-       int      i, n = get_irn_arity(phi);
-
-       NEW_ARR_A(void *, res, n);
-       for (i = 0; i < n; ++i) {
-               pred = get_irn_n(phi, i);
-               tv   = get_Const_tarval(pred);
-               tv   = eval(tv);
+       int         n   = get_irn_arity(phi);
+       ir_tarval **tvs = ALLOCAN(ir_tarval*, n);
+       for (int i = 0; i < n; ++i) {
+               ir_node   *pred = get_irn_n(phi, i);
+               ir_tarval *tv   = get_Const_tarval(pred);
+               tv = eval(tv);
 
                if (tv == tarval_bad) {
                        /* folding failed, bad */
                        return 0;
                }
-               res[i] = tv;
+               tvs[i] = tv;
        }
-       mode = get_irn_mode(phi);
-       irg  = get_irn_irg(phi);
-       for (i = 0; i < n; ++i) {
-               pred = get_irn_n(phi, i);
-               res[i] = new_r_Const(irg, (ir_tarval*)res[i]);
+       ir_graph *irg  = get_irn_irg(phi);
+       ir_node **res  = ALLOCAN(ir_node*, n);
+       for (int i = 0; i < n; ++i) {
+               res[i] = new_r_Const(irg, tvs[i]);
        }
-       return new_r_Phi(get_nodes_block(phi), n, (ir_node **)res, mode);
+       ir_node *block = get_nodes_block(phi);
+       ir_mode *mode  = get_irn_mode(phi);
+       return new_r_Phi(block, n, res, mode);
 }
 
 /**
@@ -1745,30 +1521,26 @@ static ir_node *apply_unop_on_phi(ir_node *phi, ir_tarval *(*eval)(ir_tarval *))
  */
 static ir_node *apply_conv_on_phi(ir_node *phi, ir_mode *mode)
 {
-       ir_tarval *tv;
-       void     **res;
-       ir_node  *pred;
-       ir_graph *irg;
-       int      i, n = get_irn_arity(phi);
-
-       NEW_ARR_A(void *, res, n);
-       for (i = 0; i < n; ++i) {
-               pred = get_irn_n(phi, i);
-               tv   = get_Const_tarval(pred);
-               tv   = tarval_convert_to(tv, mode);
+       int         n   = get_irn_arity(phi);
+       ir_tarval **tvs = ALLOCAN(ir_tarval*, n);
+       for (int i = 0; i < n; ++i) {
+               ir_node   *pred = get_irn_n(phi, i);
+               ir_tarval *tv   = get_Const_tarval(pred);
+               tv = tarval_convert_to(tv, mode);
 
                if (tv == tarval_bad) {
                        /* folding failed, bad */
                        return 0;
                }
-               res[i] = tv;
+               tvs[i] = tv;
        }
-       irg = get_irn_irg(phi);
-       for (i = 0; i < n; ++i) {
-               pred = get_irn_n(phi, i);
-               res[i] = new_r_Const(irg, (ir_tarval*)res[i]);
+       ir_graph *irg = get_irn_irg(phi);
+       ir_node **res = ALLOCAN(ir_node*, n);
+       for (int i = 0; i < n; ++i) {
+               res[i] = new_r_Const(irg, tvs[i]);
        }
-       return new_r_Phi(get_nodes_block(phi), n, (ir_node **)res, mode);
+       ir_node *block = get_nodes_block(phi);
+       return new_r_Phi(block, n, res, mode);
 }
 
 /**
@@ -2046,7 +1818,7 @@ static ir_node *transform_node_Or_bf_store(ir_node *irn_or)
                }
 
                /* ok, all conditions met */
-               block = get_irn_n(irn_or, -1);
+               block = get_nodes_block(irn_or);
                irg   = get_irn_irg(block);
 
                new_and = new_r_And(block, value, new_r_Const(irg, tarval_and(tv4, tv2)), mode);
@@ -2290,7 +2062,6 @@ static ir_node *transform_node_bitop_shift(ir_node *n)
                return n;
        }
 
-       irg       = get_irn_irg(n);
        block     = get_nodes_block(n);
        dbg_bitop = get_irn_dbg_info(n);
        dbg_shift = get_irn_dbg_info(left);
@@ -2849,26 +2620,6 @@ restart:
                }
                DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_TO_ADD);
                return n;
-#if 0
-       } else if (is_Mul(b)) { /* a - (b * C) -> a + (b * -C) */
-               ir_node *m_right = get_Mul_right(b);
-               if (is_Const(m_right)) {
-                       ir_node *cnst2 = const_negate(m_right);
-                       if (cnst2 != NULL) {
-                               dbg_info *m_dbg   = get_irn_dbg_info(b);
-                               ir_node  *m_block = get_nodes_block(b);
-                               ir_node  *m_left  = get_Mul_left(b);
-                               ir_mode  *m_mode  = get_irn_mode(b);
-                               ir_node  *mul     = new_rd_Mul(m_dbg, m_block, m_left, cnst2, m_mode);
-                               dbg_info *a_dbg   = get_irn_dbg_info(n);
-                               ir_node  *a_block = get_nodes_block(n);
-
-                               n = new_rd_Add(a_dbg, a_block, a, mul, mode);
-                               DBG_OPT_ALGSIM0(oldn, n, FS_OPT_SUB_TO_ADD);
-                               return n;
-                       }
-               }
-#endif
        }
 
        /* Beware of Sub(P, P) which cannot be optimized into a simple Minus ... */
@@ -3092,7 +2843,7 @@ static ir_node *transform_node_Mul2n(ir_node *n, ir_mode *mode)
        }
        if (tb == get_mode_one(smode)) {
                /* (L)a * (L)1 = (L)a */
-               ir_node *blk = get_irn_n(a, -1);
+               ir_node *blk = get_nodes_block(a);
                n = new_rd_Conv(get_irn_dbg_info(n), blk, a, mode);
                DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_NEUTRAL_1);
                return n;
@@ -3287,34 +3038,22 @@ static ir_node *transform_node_Div(ir_node *n)
                assert(mode_is_float(mode));
 
                /* Optimize x/c to x*(1/c) */
-               if (get_mode_arithmetic(mode) == irma_ieee754) {
-                       ir_tarval *tv = value_of(b);
+               ir_tarval *tv = value_of(b);
 
-                       if (tv != tarval_bad) {
-                               int rem = tarval_fp_ops_enabled();
+               if (tv != tarval_bad) {
+                       tv = tarval_div(get_mode_one(mode), tv);
 
-                               /*
-                                * Floating point constant folding might be disabled here to
-                                * prevent rounding.
-                                * However, as we check for exact result, doing it is safe.
-                                * Switch it on.
-                                */
-                               tarval_enable_fp_ops(1);
-                               tv = tarval_div(get_mode_one(mode), tv);
-                               tarval_enable_fp_ops(rem);
-
-                               /* Do the transformation if the result is either exact or we are
-                                  not using strict rules. */
-                               if (tv != tarval_bad &&
-                                       (tarval_ieee754_get_exact() || (get_irg_fp_model(get_irn_irg(n)) & fp_strict_algebraic) == 0)) {
-                                       ir_node  *block = get_nodes_block(n);
-                                       ir_graph *irg   = get_irn_irg(block);
-                                       ir_node  *c     = new_r_Const(irg, tv);
-                                       dbg_info *dbgi  = get_irn_dbg_info(n);
-                                       value = new_rd_Mul(dbgi, block, a, c, mode);
+                       /* Do the transformation if the result is either exact or we are
+                          not using strict rules. */
+                       if (tv != tarval_bad &&
+                               (tarval_ieee754_get_exact() || (get_irg_fp_model(get_irn_irg(n)) & fp_strict_algebraic) == 0)) {
+                               ir_node  *block = get_nodes_block(n);
+                               ir_graph *irg   = get_irn_irg(block);
+                               ir_node  *c     = new_r_Const(irg, tv);
+                               dbg_info *dbgi  = get_irn_dbg_info(n);
+                               value = new_rd_Mul(dbgi, block, a, c, mode);
 
-                                       goto make_tuple;
-                               }
+                               goto make_tuple;
                        }
                }
        }
@@ -3331,11 +3070,13 @@ make_tuple:
 
                /* skip a potential Pin */
                mem = skip_Pin(mem);
-               turn_into_tuple(n, pn_Div_max+1);
-               set_Tuple_pred(n, pn_Div_M,         mem);
-               set_Tuple_pred(n, pn_Div_X_regular, new_r_Jmp(blk));
-               set_Tuple_pred(n, pn_Div_X_except,  new_r_Bad(irg, mode_X));
-               set_Tuple_pred(n, pn_Div_res,       value);
+               ir_node *const in[] = {
+                       [pn_Div_M]         = mem,
+                       [pn_Div_res]       = value,
+                       [pn_Div_X_regular] = new_r_Jmp(blk),
+                       [pn_Div_X_except]  = new_r_Bad(irg, mode_X),
+               };
+               turn_into_tuple(n, ARRAY_SIZE(in), in);
        }
        return n;
 }
@@ -3423,11 +3164,13 @@ make_tuple:
 
                /* skip a potential Pin */
                mem = skip_Pin(mem);
-               turn_into_tuple(n, pn_Mod_max+1);
-               set_Tuple_pred(n, pn_Mod_M,         mem);
-               set_Tuple_pred(n, pn_Mod_X_regular, new_r_Jmp(blk));
-               set_Tuple_pred(n, pn_Mod_X_except,  new_r_Bad(irg, mode_X));
-               set_Tuple_pred(n, pn_Mod_res,       value);
+               ir_node *const in[] = {
+                       [pn_Mod_M]         = mem,
+                       [pn_Mod_res]       = value,
+                       [pn_Mod_X_regular] = new_r_Jmp(blk),
+                       [pn_Mod_X_except]  = new_r_Bad(irg, mode_X),
+               };
+               turn_into_tuple(n, ARRAY_SIZE(in), in);
        }
        return n;
 }
@@ -3443,7 +3186,6 @@ static ir_node *transform_node_Cond(ir_node *n)
        ir_node   *a   = get_Cond_selector(n);
        ir_graph  *irg = get_irn_irg(n);
        ir_tarval *ta;
-       ir_node   *jmp;
 
        /* we need block info which is not available in floating irgs */
        if (get_irg_pinned(irg) == op_pin_state_floats)
@@ -3456,21 +3198,18 @@ static ir_node *transform_node_Cond(ir_node *n)
                ta = compute_cmp_ext(a);
        }
 
-       if (ta != tarval_bad && get_irn_mode(a) == mode_b) {
-               /* It's a boolean Cond, branching on a boolean constant.
+       if (ta != tarval_bad) {
+               /* It's branching on a boolean constant.
                   Replace it by a tuple (Bad, Jmp) or (Jmp, Bad) */
-               ir_node *blk = get_nodes_block(n);
-               jmp = new_r_Jmp(blk);
-               turn_into_tuple(n, pn_Cond_max+1);
-               if (ta == tarval_b_true) {
-                       set_Tuple_pred(n, pn_Cond_false, new_r_Bad(irg, mode_X));
-                       set_Tuple_pred(n, pn_Cond_true, jmp);
-               } else {
-                       set_Tuple_pred(n, pn_Cond_false, jmp);
-                       set_Tuple_pred(n, pn_Cond_true, new_r_Bad(irg, mode_X));
-               }
-               /* We might generate an endless loop, so keep it alive. */
-               add_End_keepalive(get_irg_end(irg), blk);
+               ir_node *const blk  = get_nodes_block(n);
+               ir_node *const jmp  = new_r_Jmp(blk);
+               ir_node *const bad  = new_r_Bad(irg, mode_X);
+               bool     const cond = ta == tarval_b_true;
+               ir_node *const in[] = {
+                       [pn_Cond_false] = cond ? bad : jmp,
+                       [pn_Cond_true]  = cond ? jmp : bad,
+               };
+               turn_into_tuple(n, ARRAY_SIZE(in), in);
                clear_irg_properties(irg, IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE);
        }
        return n;
@@ -4112,7 +3851,7 @@ static ir_node *transform_node_Proj_Mod(ir_node *proj)
                switch (proj_nr) {
 
                case pn_Mod_X_regular:
-                       return new_r_Jmp(get_irn_n(mod, -1));
+                       return new_r_Jmp(get_nodes_block(mod));
 
                case pn_Mod_X_except: {
                        ir_graph *irg = get_irn_irg(proj);
@@ -4213,53 +3952,56 @@ static ir_node *transform_node_Cmp(ir_node *n)
        }
 
        /* Remove unnecessary conversions */
-       if (is_Conv(left) && is_Conv(right)) {
-               ir_node *op_left    = get_Conv_op(left);
-               ir_node *op_right   = get_Conv_op(right);
-               ir_mode *mode_left  = get_irn_mode(op_left);
-               ir_mode *mode_right = get_irn_mode(op_right);
-
-               if (smaller_mode(mode_left, mode) && smaller_mode(mode_right, mode)
-                               && mode_left != mode_b && mode_right != mode_b) {
-                       ir_node *block = get_nodes_block(n);
-
-                       if (mode_left == mode_right) {
-                               left    = op_left;
-                               right   = op_right;
-                               changed = true;
-                               DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_CONV_CONV);
-                       } else if (smaller_mode(mode_left, mode_right)) {
-                               left    = new_r_Conv(block, op_left, mode_right);
-                               right   = op_right;
-                               changed = true;
-                               DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_CONV);
-                       } else if (smaller_mode(mode_right, mode_left)) {
-                               left    = op_left;
-                               right   = new_r_Conv(block, op_right, mode_left);
-                               changed = true;
-                               DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_CONV);
+       if (!mode_is_float(mode)
+           || be_get_backend_param()->mode_float_arithmetic == NULL) {
+               if (is_Conv(left) && is_Conv(right)) {
+                       ir_node *op_left    = get_Conv_op(left);
+                       ir_node *op_right   = get_Conv_op(right);
+                       ir_mode *mode_left  = get_irn_mode(op_left);
+                       ir_mode *mode_right = get_irn_mode(op_right);
+
+                       if (smaller_mode(mode_left, mode) && smaller_mode(mode_right, mode)
+                                       && mode_left != mode_b && mode_right != mode_b) {
+                               ir_node *block = get_nodes_block(n);
+
+                               if (mode_left == mode_right) {
+                                       left    = op_left;
+                                       right   = op_right;
+                                       changed = true;
+                                       DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_CONV_CONV);
+                               } else if (smaller_mode(mode_left, mode_right)) {
+                                       left    = new_r_Conv(block, op_left, mode_right);
+                                       right   = op_right;
+                                       changed = true;
+                                       DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_CONV);
+                               } else if (smaller_mode(mode_right, mode_left)) {
+                                       left    = op_left;
+                                       right   = new_r_Conv(block, op_right, mode_left);
+                                       changed = true;
+                                       DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_CONV);
+                               }
+                               mode = get_irn_mode(left);
                        }
-                       mode = get_irn_mode(left);
-               }
-       }
-       if (is_Conv(left) && is_Const(right)) {
-               ir_node   *op_left   = get_Conv_op(left);
-               ir_mode   *mode_left = get_irn_mode(op_left);
-               if (smaller_mode(mode_left, mode) && mode_left != mode_b) {
-                       ir_tarval *tv        = get_Const_tarval(right);
-                       tarval_int_overflow_mode_t last_mode
-                               = tarval_get_integer_overflow_mode();
-                       ir_tarval *new_tv;
-                       tarval_set_integer_overflow_mode(TV_OVERFLOW_BAD);
-                       new_tv = tarval_convert_to(tv, mode_left);
-                       tarval_set_integer_overflow_mode(last_mode);
-                       if (new_tv != tarval_bad) {
-                               ir_graph *irg = get_irn_irg(n);
-                               left    = op_left;
-                               right   = new_r_Const(irg, new_tv);
-                               mode    = get_irn_mode(left);
-                               changed = true;
-                               DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_CONV);
+               }
+               if (is_Conv(left) && is_Const(right)) {
+                       ir_node   *op_left   = get_Conv_op(left);
+                       ir_mode   *mode_left = get_irn_mode(op_left);
+                       if (smaller_mode(mode_left, mode) && mode_left != mode_b) {
+                               ir_tarval *tv        = get_Const_tarval(right);
+                               tarval_int_overflow_mode_t last_mode
+                                       = tarval_get_integer_overflow_mode();
+                               ir_tarval *new_tv;
+                               tarval_set_integer_overflow_mode(TV_OVERFLOW_BAD);
+                               new_tv = tarval_convert_to(tv, mode_left);
+                               tarval_set_integer_overflow_mode(last_mode);
+                               if (new_tv != tarval_bad) {
+                                       ir_graph *irg = get_irn_irg(n);
+                                       left    = op_left;
+                                       right   = new_r_Const(irg, new_tv);
+                                       mode    = get_irn_mode(left);
+                                       changed = true;
+                                       DBG_OPT_ALGSIM0(n, n, FS_OPT_CMP_CONV);
+                               }
                        }
                }
        }
@@ -4905,7 +4647,7 @@ is_bittest: {
                                if (tarval_is_single_bit(tv)) {
                                        /* special case: (x % 2^n) CMP 0 ==> x & (2^n-1) CMP 0 */
                                        ir_node *v    = get_binop_left(op);
-                                       ir_node *blk  = get_irn_n(op, -1);
+                                       ir_node *blk  = get_nodes_block(op);
                                        ir_graph *irg = get_irn_irg(op);
                                        ir_mode *mode = get_irn_mode(v);
 
@@ -4958,63 +4700,6 @@ static ir_node *transform_node_Proj_CopyB(ir_node *proj)
        return proj;
 }
 
-/**
- * Optimize Bounds(idx, idx, upper) into idx.
- */
-static ir_node *transform_node_Proj_Bound(ir_node *proj)
-{
-       ir_node *oldn  = proj;
-       ir_node *bound = get_Proj_pred(proj);
-       ir_node *idx   = get_Bound_index(bound);
-       ir_node *pred  = skip_Proj(idx);
-       int ret_tuple  = 0;
-
-       if (idx == get_Bound_lower(bound))
-               ret_tuple = 1;
-       else if (is_Bound(pred)) {
-               /*
-               * idx was Bounds checked previously, it is still valid if
-               * lower <= pred_lower && pred_upper <= upper.
-               */
-               ir_node *lower = get_Bound_lower(bound);
-               ir_node *upper = get_Bound_upper(bound);
-               if (get_Bound_lower(pred) == lower &&
-                       get_Bound_upper(pred) == upper) {
-                       /*
-                        * One could expect that we simply return the previous
-                        * Bound here. However, this would be wrong, as we could
-                        * add an exception Proj to a new location then.
-                        * So, we must turn in into a tuple.
-                        */
-                       ret_tuple = 1;
-               }
-       }
-       if (ret_tuple) {
-               /* Turn Bound into a tuple (mem, jmp, bad, idx) */
-               switch (get_Proj_proj(proj)) {
-               case pn_Bound_M:
-                       DBG_OPT_EXC_REM(proj);
-                       proj = get_Bound_mem(bound);
-                       break;
-               case pn_Bound_X_except:
-                       DBG_OPT_EXC_REM(proj);
-                       proj = new_r_Bad(get_irn_irg(proj), mode_X);
-                       break;
-               case pn_Bound_res:
-                       proj = idx;
-                       DBG_OPT_ALGSIM0(oldn, proj, FS_OPT_NOP);
-                       break;
-               case pn_Bound_X_regular:
-                       DBG_OPT_EXC_REM(proj);
-                       proj = new_r_Jmp(get_nodes_block(bound));
-                       break;
-               default:
-                       break;
-               }
-       }
-       return proj;
-}
-
 /**
  * Does all optimizations on nodes that must be done on its Projs
  * because of creating new nodes.
@@ -5119,7 +4804,6 @@ static ir_node *transform_node_Phi(ir_node *phi)
                                return phi;
 
                        /* Move the Pin nodes "behind" the Phi. */
-                       block   = get_irn_n(phi, -1);
                        new_phi = new_r_Phi(block, n, in, mode_M);
                        return new_r_Pin(block, new_phi);
                }
@@ -5131,7 +4815,7 @@ static ir_node *transform_node_Phi(ir_node *phi)
                /* Beware of Phi0 */
                if (n > 0) {
                        ir_node    *pred = get_irn_n(phi, 0);
-                       ir_node    *bound, *new_phi, *block, **in;
+                       ir_node    *bound, *new_phi, **in;
                        ir_relation relation;
                        bool        has_confirm = false;
 
@@ -5163,7 +4847,6 @@ static ir_node *transform_node_Phi(ir_node *phi)
                                return phi;
 
                        /* move the Confirm nodes "behind" the Phi */
-                       block = get_irn_n(phi, -1);
                        new_phi = new_r_Phi(block, n, in, get_irn_mode(phi));
                        return new_r_Confirm(block, new_phi, bound, relation);
                }
@@ -5565,6 +5248,69 @@ static ir_node *transform_node_Rotl(ir_node *n)
        return n;
 }
 
+/**
+ * returns mode size for may_leave_out_middle_mode
+ */
+static unsigned get_significand_size(ir_mode *mode)
+{
+       const ir_mode_arithmetic arithmetic = get_mode_arithmetic(mode);
+       switch (arithmetic) {
+       case irma_ieee754:
+       case irma_x86_extended_float:
+               return get_mode_mantissa_size(mode) + 1;
+       case irma_twos_complement:
+               return get_mode_size_bits(mode);
+       case irma_none:
+               panic("Conv node with irma_none mode?");
+       }
+       panic("unexpected mode_arithmetic in get_significand_size");
+}
+
+/**
+ * Returns true if a conversion from mode @p m0 to @p m1 has the same effect
+ * as converting from @p m0 to @p m1 and then to @p m2.
+ * Classifying the 3 modes as the big(b), middle(m) and small(s) mode this
+ * gives the following truth table:
+ * s -> b -> m  : true
+ * s -> m -> b  : !signed(s) || signed(m)
+ * m -> b -> s  : true
+ * m -> s -> b  : false
+ * b -> s -> m  : false
+ * b -> m -> s  : true
+ *
+ * s -> b -> b  : true
+ * s -> s -> b  : false
+ *
+ * additional float constraints:
+ * F -> F -> F: fine
+ * F -> I -> I: signedness of Is must match
+ * I -> F -> I: signedness of Is must match
+ * I -> I -> F: signedness of Is must match
+ * F -> I -> F: bad
+ * I -> F -> F: fine
+ * F -> F -> I: fine
+ * at least 1 float involved: signedness must match
+ */
+bool may_leave_out_middle_conv(ir_mode *m0, ir_mode *m1, ir_mode *m2)
+{
+       int n_floats = mode_is_float(m0) + mode_is_float(m1) + mode_is_float(m2);
+       if (n_floats == 1) {
+               /* because overflow gives strange results we don't touch this case */
+               return false;
+       } else if (n_floats == 2 && !mode_is_float(m1)) {
+               return false;
+       }
+
+       unsigned size0 = get_significand_size(m0);
+       unsigned size1 = get_significand_size(m1);
+       unsigned size2 = get_significand_size(m2);
+       if (size1 < size2 && size0 >= size1)
+               return false;
+       if (size1 >= size2)
+               return true;
+       return !mode_is_signed(m0) || mode_is_signed(m1);
+}
+
 /**
  * Transform a Conv.
  */
@@ -5574,6 +5320,17 @@ static ir_node *transform_node_Conv(ir_node *n)
        ir_mode *mode = get_irn_mode(n);
        ir_node *a    = get_Conv_op(n);
 
+       if (is_Conv(a)) {
+               ir_mode *a_mode = get_irn_mode(a);
+               ir_node *b      = get_Conv_op(a);
+               ir_mode *b_mode = get_irn_mode(b);
+               if (may_leave_out_middle_conv(b_mode, a_mode, mode)) {
+                       dbg_info *dbgi  = get_irn_dbg_info(n);
+                       ir_node  *block = get_nodes_block(n);
+                       return new_rd_Conv(dbgi, block, b, mode);
+               }
+       }
+
        if (mode != mode_b && is_const_Phi(a)) {
                /* Do NOT optimize mode_b Conv's, this leads to remaining
                 * Phib nodes later, because the conv_b_lower operation
@@ -6116,66 +5873,87 @@ static ir_node *transform_node_Sync(ir_node *n)
        return n;
 }
 
+static ir_node *create_load_replacement_tuple(ir_node *n, ir_node *mem,
+                                              ir_node *res)
+{
+       ir_node  *block = get_nodes_block(n);
+       ir_graph *irg   = get_irn_irg(n);
+       ir_node  *in[pn_Load_max+1];
+       size_t    n_in  = 2;
+       in[pn_Load_M]   = mem;
+       in[pn_Load_res] = res;
+       if (ir_throws_exception(n)) {
+               in[pn_Load_X_regular] = new_r_Jmp(block);
+               in[pn_Load_X_except]  = new_r_Bad(irg, mode_X);
+               n_in                  = 4;
+               assert(pn_Load_max == 4);
+       }
+       ir_node  *tuple = new_r_Tuple(block, n_in, in);
+       return tuple;
+}
+
 static ir_node *transform_node_Load(ir_node *n)
 {
+       /* don't touch volatile loads */
+       if (get_Load_volatility(n) == volatility_is_volatile)
+               return n;
+
+       ir_node *ptr = get_Load_ptr(n);
+       const ir_node *confirm;
+       if (value_not_zero(ptr, &confirm) && confirm == NULL) {
+               set_irn_pinned(n, op_pin_state_floats);
+       }
+
        /* if our memory predecessor is a load from the same address, then reuse the
         * previous result */
        ir_node *mem = get_Load_mem(n);
-       ir_node *mem_pred;
-
        if (!is_Proj(mem))
                return n;
-       /* don't touch volatile loads */
-       if (get_Load_volatility(n) == volatility_is_volatile)
-               return n;
-       mem_pred = get_Proj_pred(mem);
+       ir_node *mem_pred = get_Proj_pred(mem);
        if (is_Load(mem_pred)) {
                ir_node *pred_load = mem_pred;
 
                /* conservatively compare the 2 loads. TODO: This could be less strict
                 * with fixup code in some situations (like smaller/bigger modes) */
-               if (get_Load_ptr(pred_load) != get_Load_ptr(n))
+               if (get_Load_ptr(pred_load) != ptr)
                        return n;
                if (get_Load_mode(pred_load) != get_Load_mode(n))
                        return n;
                /* all combinations of aligned/unaligned pred/n should be fine so we do
                 * not compare the unaligned attribute */
-               {
-                       ir_node  *block = get_nodes_block(n);
-                       ir_node  *jmp   = new_r_Jmp(block);
-                       ir_graph *irg   = get_irn_irg(n);
-                       ir_node  *bad   = new_r_Bad(irg, mode_X);
-                       ir_mode  *mode  = get_Load_mode(n);
-                       ir_node  *res   = new_r_Proj(pred_load, mode, pn_Load_res);
-                       ir_node  *in[]  = { mem, res, jmp, bad };
-                       ir_node  *tuple = new_r_Tuple(block, ARRAY_SIZE(in), in);
-                       return tuple;
-               }
+               ir_mode  *mode  = get_Load_mode(n);
+               ir_node  *res   = new_r_Proj(pred_load, mode, pn_Load_res);
+               return create_load_replacement_tuple(n, mem, res);
        } else if (is_Store(mem_pred)) {
                ir_node *pred_store = mem_pred;
                ir_node *value      = get_Store_value(pred_store);
 
-               if (get_Store_ptr(pred_store) != get_Load_ptr(n))
+               if (get_Store_ptr(pred_store) != ptr)
                        return n;
                if (get_irn_mode(value) != get_Load_mode(n))
                        return n;
                /* all combinations of aligned/unaligned pred/n should be fine so we do
                 * not compare the unaligned attribute */
-               {
-                       ir_node  *block = get_nodes_block(n);
-                       ir_node  *jmp   = new_r_Jmp(block);
-                       ir_graph *irg   = get_irn_irg(n);
-                       ir_node  *bad   = new_r_Bad(irg, mode_X);
-                       ir_node  *res   = value;
-                       ir_node  *in[]  = { mem, res, jmp, bad };
-                       ir_node  *tuple = new_r_Tuple(block, ARRAY_SIZE(in), in);
-                       return tuple;
-               }
+               return create_load_replacement_tuple(n, mem, value);
        }
 
        return n;
 }
 
+static ir_node *transform_node_Store(ir_node *n)
+{
+       /* don't touch volatile stores */
+       if (get_Store_volatility(n) == volatility_is_volatile)
+               return n;
+
+       ir_node *ptr = get_Store_ptr(n);
+       const ir_node *confirm;
+       if (value_not_zero(ptr, &confirm) && confirm == NULL) {
+               set_irn_pinned(n, op_pin_state_floats);
+       }
+       return n;
+}
+
 /**
  * optimize a trampoline Call into a direct Call
  */
@@ -6349,8 +6127,6 @@ void ir_register_opt_node_ops(void)
 {
        register_computed_value_func(op_Add,      computed_value_Add);
        register_computed_value_func(op_And,      computed_value_And);
-       register_computed_value_func(op_Borrow,   computed_value_Borrow);
-       register_computed_value_func(op_Carry,    computed_value_Carry);
        register_computed_value_func(op_Cmp,      computed_value_Cmp);
        register_computed_value_func(op_Confirm,  computed_value_Confirm);
        register_computed_value_func(op_Const,    computed_value_Const);
@@ -6377,10 +6153,10 @@ void ir_register_opt_node_ops(void)
        register_equivalent_node_func(op_Conv,    equivalent_node_Conv);
        register_equivalent_node_func(op_Eor,     equivalent_node_Eor);
        register_equivalent_node_func(op_Id,      equivalent_node_Id);
-       register_equivalent_node_func(op_Minus,   equivalent_node_idempotent_unop);
+       register_equivalent_node_func(op_Minus,   equivalent_node_involution);
        register_equivalent_node_func(op_Mul,     equivalent_node_Mul);
        register_equivalent_node_func(op_Mux,     equivalent_node_Mux);
-       register_equivalent_node_func(op_Not,     equivalent_node_idempotent_unop);
+       register_equivalent_node_func(op_Not,     equivalent_node_involution);
        register_equivalent_node_func(op_Or,      equivalent_node_Or);
        register_equivalent_node_func(op_Phi,     equivalent_node_Phi);
        register_equivalent_node_func(op_Proj,    equivalent_node_Proj);
@@ -6389,7 +6165,6 @@ void ir_register_opt_node_ops(void)
        register_equivalent_node_func(op_Shr,     equivalent_node_left_zero);
        register_equivalent_node_func(op_Shrs,    equivalent_node_left_zero);
        register_equivalent_node_func(op_Sub,     equivalent_node_Sub);
-       register_equivalent_node_func_proj(op_Bound, equivalent_node_Proj_Bound);
        register_equivalent_node_func_proj(op_CopyB, equivalent_node_Proj_CopyB);
        register_equivalent_node_func_proj(op_Div,   equivalent_node_Proj_Div);
        register_equivalent_node_func_proj(op_Tuple, equivalent_node_Proj_Tuple);
@@ -6417,10 +6192,10 @@ void ir_register_opt_node_ops(void)
        register_transform_node_func(op_Shl,    transform_node_Shl);
        register_transform_node_func(op_Shrs,   transform_node_Shrs);
        register_transform_node_func(op_Shr,    transform_node_Shr);
+       register_transform_node_func(op_Store,  transform_node_Store);
        register_transform_node_func(op_Sub,    transform_node_Sub);
        register_transform_node_func(op_Switch, transform_node_Switch);
        register_transform_node_func(op_Sync,   transform_node_Sync);
-       register_transform_node_func_proj(op_Bound, transform_node_Proj_Bound);
        register_transform_node_func_proj(op_CopyB, transform_node_Proj_CopyB);
        register_transform_node_func_proj(op_Div,   transform_node_Proj_Div);
        register_transform_node_func_proj(op_Load,  transform_node_Proj_Load);
@@ -6456,7 +6231,7 @@ int identities_cmp(const void *elt, const void *key)
 
        if (get_irn_pinned(a) == op_pin_state_pinned) {
                /* for pinned nodes, the block inputs must be equal */
-               if (get_irn_n(a, -1) != get_irn_n(b, -1))
+               if (get_nodes_block(a) != get_nodes_block(b))
                        return 1;
        } else {
                ir_node *block_a = get_nodes_block(a);
@@ -6474,6 +6249,10 @@ int identities_cmp(const void *elt, const void *key)
                        if (!block_dominates(block_a, block_b)
                            && !block_dominates(block_b, block_a))
                            return 1;
+                       /* respect the workaround rule: do not move nodes which are only
+                        * held by keepalive edges */
+                       if (only_used_by_keepalive(a) || only_used_by_keepalive(b))
+                               return 1;
                }
        }
 
@@ -6766,8 +6545,6 @@ ir_node *optimize_in_place_2(ir_node *n)
 ir_node *optimize_in_place(ir_node *n)
 {
        ir_graph *irg = get_irn_irg(n);
-       /* Handle graph state */
-       assert(get_irg_phase_state(irg) != phase_building);
 
        if (get_opt_global_cse())
                set_irg_pinned(irg, op_pin_state_floats);