Add missing returns.
[libfirm] / ir / ir / iropt.c
index d7ab0b2..518b903 100644 (file)
@@ -48,7 +48,7 @@
 #include "opt_confirms.h"
 #include "opt_polymorphy.h"
 #include "irtools.h"
-#include "xmalloc.h"
+#include "array_t.h"
 
 /* Make types visible to allow most efficient access */
 #include "entity_t.h"
@@ -1252,15 +1252,16 @@ restart:
                                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 (smaller_mode(b_mode, 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 (get_mode_arithmetic(n_mode) == irma_twos_complement &&
-                           get_mode_arithmetic(a_mode) == irma_ieee754) {
+                       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 = tarval_ieee754_get_mantissa_size(a_mode);
@@ -1277,6 +1278,7 @@ restart:
                                                set_Conv_strict(b, 1);
                                        n = b; /* ConvA(ConvB(ConvA(...))) == ConvA(...) */
                                        DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV);
+                                       return n;
                                }
                        }
                }
@@ -5279,10 +5281,15 @@ static ir_node *transform_node_Rotl(ir_node *n) {
  */
 static ir_node *transform_node_Conv(ir_node *n) {
        ir_node *c, *oldn = n;
-       ir_node *a = get_Conv_op(n);
+       ir_mode *mode = get_irn_mode(n);
+       ir_node *a    = get_Conv_op(n);
 
-       if (is_const_Phi(a)) {
-               c = apply_conv_on_phi(a, get_irn_mode(n));
+       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
+                * is instantly reverted, when it tries to insert a Convb.
+                */
+               c = apply_conv_on_phi(a, mode);
                if (c) {
                        DBG_OPT_ALGSIM0(oldn, c, FS_OPT_CONST_PHI);
                        return c;
@@ -5290,10 +5297,34 @@ static ir_node *transform_node_Conv(ir_node *n) {
        }
 
        if (is_Unknown(a)) { /* Conv_A(Unknown_B) -> Unknown_A */
-               ir_mode *mode = get_irn_mode(n);
                return new_r_Unknown(current_ir_graph, mode);
        }
 
+       if (mode_is_reference(mode) &&
+               get_mode_size_bits(mode) == get_mode_size_bits(get_irn_mode(a)) &&
+               is_Add(a)) {
+               ir_node *l = get_Add_left(a);
+               ir_node *r = get_Add_right(a);
+               dbg_info *dbgi = get_irn_dbg_info(a);
+               ir_node *block = get_nodes_block(n);
+               if(is_Conv(l)) {
+                       ir_node *lop = get_Conv_op(l);
+                       if(get_irn_mode(lop) == mode) {
+                               /* ConvP(AddI(ConvI(P), x)) -> AddP(P, x) */
+                               n = new_rd_Add(dbgi, current_ir_graph, block, lop, r, mode);
+                               return n;
+                       }
+               }
+               if(is_Conv(r)) {
+                       ir_node *rop = get_Conv_op(r);
+                       if(get_irn_mode(rop) == mode) {
+                               /* ConvP(AddI(x, ConvI(P))) -> AddP(x, P) */
+                               n = new_rd_Add(dbgi, current_ir_graph, block, l, rop, mode);
+                               return n;
+                       }
+               }
+       }
+
        return n;
 }  /* transform_node_Conv */
 
@@ -5316,6 +5347,9 @@ static ir_node *transform_node_End(ir_node *n) {
                        continue;
                } else if (is_irn_pinned_in_irg(ka) && is_Block_dead(get_nodes_block(ka))) {
                        continue;
+               } else if (is_Bad(ka)) {
+                       /* no need to keep Bad */
+                       continue;
                }
                in[j++] = ka;
        }