fixed bug where projections ended up in the wrong blocks
authorChristian Helmer <c.helmer@gmx.de>
Fri, 25 May 2012 14:01:49 +0000 (16:01 +0200)
committerChristian Helmer <c.helmer@gmx.de>
Fri, 26 Oct 2012 12:13:23 +0000 (14:13 +0200)
ir/opt/gvn_pre.c

index 019ddd6..79d737e 100644 (file)
@@ -563,10 +563,11 @@ static void compute_avail_top_down(ir_node *block, void *ctx)
  */
 static ir_node *phi_translate(ir_node *node, ir_node *block, int pos)
 {
-       ir_node  *nn;
-       ir_node **in;
        int       i;
        int       arity;
+       ir_node **in;
+       ir_node  *nn;
+       ir_node  *target_block;
 
        if (is_Phi(node)) {
                if (get_nodes_block(node) == block) {
@@ -594,10 +595,17 @@ static ir_node *phi_translate(ir_node *node, ir_node *block, int pos)
                        in[i] = trans;
        }
 
+       target_block = get_Block_cfgpred_block(block, pos);
+       if (is_Proj(node)) {
+               /* Projections are the sole case where we have to ensure
+                  that they are in the same block as their tuple node. */
+               target_block = get_nodes_block(in[0]);
+       }
+
        nn = new_ir_node(
                get_irn_dbg_info(node),
                get_irn_irg(node),
-               get_Block_cfgpred_block(block, pos),
+               target_block,
                get_irn_op(node),
                get_irn_mode(node),
                arity,