Commit d1d5979d authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Improve equivalent_node_Sync() and transform_node_Sync() so they remove Bad...

Improve equivalent_node_Sync() and transform_node_Sync() so they remove Bad and duplicate predecessors.

[r19034]
parent d2d29722
...@@ -1297,45 +1297,36 @@ static ir_node *equivalent_node_Phi(ir_node *n) { ...@@ -1297,45 +1297,36 @@ static ir_node *equivalent_node_Phi(ir_node *n) {
* themselves. * themselves.
*/ */
static ir_node *equivalent_node_Sync(ir_node *n) { static ir_node *equivalent_node_Sync(ir_node *n) {
int i, n_preds; int arity = get_Sync_n_preds(n);
int i;
ir_node *oldn = n;
ir_node *first_val = NULL; /* to shutup gcc */
if (!get_opt_normalize()) return n;
n_preds = get_Sync_n_preds(n); for (i = 0; i < arity;) {
ir_node *pred = get_Sync_pred(n, i);
int j;
/* Find first non-self-referencing input */ /* Remove Bad predecessors */
for (i = 0; i < n_preds; ++i) { if (is_Bad(pred)) {
first_val = get_Sync_pred(n, i); del_Sync_n(n, i);
if ((first_val != n) /* not self pointer */ && --arity;
(! is_Bad(first_val)) continue;
) { /* value not dead */
break; /* then found first value. */
} }
}
if (i >= n_preds)
/* A totally Bad or self-referencing Sync (we didn't break the above loop) */
return new_Bad();
/* search the rest of inputs, determine if any of these /* Remove duplicate predecessors */
are non-self-referencing */ for (j = 0;; ++j) {
while (++i < n_preds) { if (j >= i) {
ir_node *scnd_val = get_Sync_pred(n, i); ++i;
if ((scnd_val != n) && break;
(scnd_val != first_val) && }
(! is_Bad(scnd_val)) if (get_Sync_pred(n, j) == pred) {
) del_Sync_n(n, i);
break; --arity;
break;
}
}
} }
if (i >= n_preds) { if (arity == 0) return new_Bad();
/* Fold, if no multiple distinct non-self-referencing inputs */ if (arity == 1) return get_Sync_pred(n, 0);
n = first_val;
DBG_OPT_SYNC(oldn, n);
}
return n; return n;
} /* equivalent_node_Sync */ } /* equivalent_node_Sync */
...@@ -4873,28 +4864,35 @@ static ir_node *transform_node_Psi(ir_node *n) { ...@@ -4873,28 +4864,35 @@ static ir_node *transform_node_Psi(ir_node *n) {
* of the other sync to our own inputs * of the other sync to our own inputs
*/ */
static ir_node *transform_node_Sync(ir_node *n) { static ir_node *transform_node_Sync(ir_node *n) {
int i, arity; int arity = get_Sync_n_preds(n);
int i;
for (i = 0; i < arity;) {
ir_node *pred = get_Sync_pred(n, i);
int pred_arity;
int j;
arity = get_irn_arity(n); if (!is_Sync(pred)) {
for(i = 0; i < get_irn_arity(n); /*empty*/) {
int i2, arity2;
ir_node *in = get_irn_n(n, i);
if(!is_Sync(in)) {
++i; ++i;
continue; continue;
} }
/* set sync input 0 instead of the sync */ del_Sync_n(n, i);
set_irn_n(n, i, get_irn_n(in, 0)); --arity;
/* so we check this input again for syncs */
pred_arity = get_Sync_n_preds(pred);
/* append all other inputs of the sync to our sync */ for (j = 0; j < pred_arity; ++j) {
arity2 = get_irn_arity(in); ir_node *pred_pred = get_Sync_pred(pred, j);
for(i2 = 1; i2 < arity2; ++i2) { int k;
ir_node *in_in = get_irn_n(in, i2);
add_irn_n(n, in_in); for (k = 0;; ++k) {
/* increase arity so we also check the new inputs for syncs */ if (k >= arity) {
arity++; add_irn_n(n, pred_pred);
++arity;
break;
}
if (get_Sync_pred(n, k) == pred_pred) break;
}
} }
} }
......
Supports Markdown
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