move load mode shrinking into ldst phase
[libfirm] / ir / opt / opt_osr.c
index 2165b59..275ee2e 100644 (file)
@@ -139,7 +139,7 @@ static LFTR_edge *LFTR_find(ir_node *src, iv_env *env)
 
        key.src  = src;
 
-       return (LFTR_edge*)set_find(env->lftr_edges, &key, sizeof(key), hash_ptr(src));
+       return set_find(LFTR_edge, env->lftr_edges, &key, sizeof(key), hash_ptr(src));
 }  /* LFTR_find */
 
 /**
@@ -164,7 +164,7 @@ static void LFTR_add(ir_node *src, ir_node *dst, unsigned code, ir_node *rc, iv_
         * There might be more than one edge here. This is rather bad
         * because we currently store only one.
         */
-       set_insert(env->lftr_edges, &key, sizeof(key), hash_ptr(src));
+       (void)set_insert(LFTR_edge, env->lftr_edges, &key, sizeof(key), hash_ptr(src));
 }  /* LFTR_add */
 
 /**
@@ -253,8 +253,7 @@ static ir_node *search(unsigned code, ir_node *op1, ir_node *op2, iv_env *env)
        key.op1 = op1;
        key.op2 = op2;
 
-       entry = (quadruple_t*)set_find(env->quad_map, &key, sizeof(key),
-                                      (code * 9) ^ hash_ptr(op1) ^hash_ptr(op2));
+       entry = set_find(quadruple_t, env->quad_map, &key, sizeof(key), (code * 9) ^ hash_ptr(op1) ^ hash_ptr(op2));
        if (entry)
                return entry->res;
        return NULL;
@@ -278,8 +277,7 @@ static void add(unsigned code, ir_node *op1, ir_node *op2, ir_node *result, iv_e
        key.op2  = op2;
        key.res  = result;
 
-       set_insert(env->quad_map, &key, sizeof(key),
-                  (code * 9) ^ hash_ptr(op1) ^hash_ptr(op2));
+       (void)set_insert(quadruple_t, env->quad_map, &key, sizeof(key), (code * 9) ^ hash_ptr(op1) ^ hash_ptr(op2));
 }  /* add */
 
 /**
@@ -615,8 +613,6 @@ static int check_users_for_reg_pressure(ir_node *iv, iv_env *env)
        scc        *pscc      = e->pscc;
 
        for (irn = pscc->head; irn != NULL; irn = e->next) {
-               const ir_edge_t *edge;
-
                foreach_out_edge(irn, edge) {
                        ir_node    *user = get_edge_src_irn(edge);
                        node_entry *ne = get_irn_ne(user, env);
@@ -760,8 +756,26 @@ static void classify_iv(scc *pscc, iv_env *env)
 
                next = e->next;
                switch (get_irn_opcode(irn)) {
-               case iro_Add:
                case iro_Sub:
+                       only_phi = 0;
+                       {
+                               ir_node    *left        = get_Sub_left(irn);
+                               node_entry *left_entry  = get_irn_ne(left, env);
+                               ir_node    *right       = get_Sub_right(irn);
+                               node_entry *right_entry = get_irn_ne(right, env);
+
+                               if (left_entry->pscc != e->pscc ||
+                                   (right_entry->pscc != e->pscc && !is_rc(right, header))) {
+                                       /*
+                                        * Not an induction variable.
+                                        * Region constant are only allowed on right hand side.
+                                        */
+                                       goto fail;
+                               }
+                       }
+                       break;
+
+               case iro_Add:
                        only_phi = 0;
                        /* fall through */
                case iro_Phi:
@@ -1274,27 +1288,6 @@ static void lftr(ir_graph *irg, iv_env *env)
        irg_walk_graph(irg, NULL, do_lftr, env);
 }  /* lftr */
 
-/**
- * Pre-walker: set all node links to NULL and fix the
- * block of Proj nodes.
- */
-static void clear_and_fix(ir_node *irn, void *env)
-{
-       (void)env;
-
-       set_irn_link(irn, NULL);
-
-       if (is_Proj(irn)) {
-               ir_node *pred       = get_Proj_pred(irn);
-               ir_node *pred_block = get_nodes_block(pred);
-
-               if (get_nodes_block(irn) != pred_block) {
-                       set_nodes_block(irn, pred_block);
-               }
-       }
-}  /* clear_and_fix */
-
-
 /* Remove any Phi cycles with only one real input. */
 void remove_phi_cycles(ir_graph *irg)
 {
@@ -1326,7 +1319,7 @@ void remove_phi_cycles(ir_graph *irg)
         * the same block as their predecessors.
         * This can improve the placement of new nodes.
         */
-       irg_walk_graph(irg, NULL, clear_and_fix, NULL);
+       irg_walk_graph(irg, NULL, firm_clear_link, NULL);
 
        /* calculate the post order number for blocks. */
        irg_out_block_walk(get_irg_start_block(irg), NULL, assign_po, &env);
@@ -1451,7 +1444,7 @@ void opt_osr(ir_graph *irg, unsigned flags)
         * the same block as its predecessors.
         * This can improve the placement of new nodes.
         */
-       irg_walk_graph(irg, NULL, clear_and_fix, NULL);
+       irg_walk_graph(irg, NULL, firm_clear_link, NULL);
 
        irg_block_edges_walk(get_irg_start_block(irg), NULL, assign_po, &env);