jumpthreading: when copying kept nodes keep the copies
authorMatthias Braun <matze@braunis.de>
Mon, 12 Nov 2012 16:16:54 +0000 (17:16 +0100)
committerMatthias Braun <matze@braunis.de>
Mon, 12 Nov 2012 16:17:38 +0000 (17:17 +0100)
ir/opt/jumpthreading.c

index 6c4ed4a..754c3f3 100644 (file)
@@ -282,8 +282,8 @@ static void copy_and_fix(const jumpthreading_env_t *env, ir_node *block,
                ir_mode *mode;
 
                if (is_End(node)) {
-                       /* edge is a Keep edge. If the end block is unreachable via normal control flow,
-                        * we must maintain end's reachability with Keeps.
+                       /* edge is a Keep edge. If the end block is unreachable via normal
+                        * control flow, we must maintain end's reachability with Keeps.
                         */
                        keep_alive(copy_block);
                        continue;
@@ -354,6 +354,17 @@ static void copy_and_fix(const jumpthreading_env_t *env, ir_node *block,
                copy_node = (ir_node*)get_irn_link(node);
                construct_ssa(block, node, copy_block, copy_node);
        }
+
+       /* make sure new nodes are kept alive if old nodes were */
+       ir_graph *irg = get_irn_irg(block);
+       ir_node  *end = get_irg_end(irg);
+       for (int i = 0, arity = get_End_n_keepalives(end); i < arity; ++i) {
+               ir_node *keep = get_End_keepalive(end, i);
+               if (get_irn_visited(keep) < env->visited_nr || is_Block(keep))
+                       continue;
+               ir_node *copy = get_irn_link(keep);
+               add_End_keepalive(end, copy);
+       }
 }
 
 /**