Commit d87361aa authored by Matthias Braun's avatar Matthias Braun
Browse files

transfer keep-alive edge if necessary in transform_node_Phi

parent 15477169
......@@ -38,7 +38,8 @@ void exchange(ir_node *old, ir_node *nw)
/* When replacing a PhiM node, it must not be hold by a keep-alive edge.
* => Keep-alive edges are not normal users and should not move along when
* exchanging. */
if (is_Phi(old) && get_irn_mode(old) == mode_M && !is_Bad(nw)) {
if (is_Phi(old) && get_irn_mode(old) == mode_M && !is_Bad(nw)
&& (!is_Phi(nw) || get_nodes_block(old) != get_nodes_block(nw))) {
ir_node *end = get_irg_end(irg);
foreach_irn_in(end, i, kept) {
assert(kept != old);
......
......@@ -602,20 +602,23 @@ void remove_End_keepalive(ir_node *end, const ir_node *irn)
remove_irn_n(end, idx);
}
void remove_keep_alive(const ir_node *irn)
bool remove_keep_alive(const ir_node *irn)
{
ir_graph *irg = get_irn_irg(irn);
ir_node *end = get_irg_end(irg);
bool found = false;
for (int i = get_End_n_keepalives(end);;) {
if (i-- == 0)
return;
return found;
ir_node *old_ka = end->in[1 + END_KEEPALIVE_OFFSET + i];
/* find irn */
if (old_ka == irn)
if (old_ka == irn) {
set_irn_n(end, END_KEEPALIVE_OFFSET+i, new_r_Bad(irg, get_irn_mode(irn)));
found = true;
}
}
}
......
......@@ -540,8 +540,9 @@ void ir_register_getter_ops(void);
/** remove keep alive edge to node by rerouting the edge to a Bad node.
* (rerouting is preferable to removing when we are in a walker which also
* accesses the End node) */
void remove_keep_alive(const ir_node *kept_node);
* accesses the End node)
* @return true if an edge was removed */
bool remove_keep_alive(const ir_node *kept_node);
/**
* Create a node similar to @p old. Except for @p block and @p in all aspects
......
......@@ -5370,8 +5370,10 @@ static ir_node *transform_node_Phi(ir_node *phi)
return phi;
/* Move the Pin nodes "behind" the Phi. */
remove_keep_alive(phi); /* no self-loop => we can remove the Phi+keep */
bool kept = remove_keep_alive(phi);
ir_node *new_phi = new_r_Phi(block, n, in, mode_M);
if (kept)
keep_alive(new_phi);
return new_r_Pin(block, new_phi);
} else if (mode_is_reference(mode)) {
/* Move Confirms down through Phi nodes. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment