- ir_node *left = get_Cmp_left(cmp);
- ir_node *right = get_Cmp_right(cmp);
- ir_op *op;
- const ir_edge_t *edge, *next;
-
- /* Beware of Bads */
- if (is_Bad(left) ||is_Bad(right))
- return;
-
- op = get_irn_op(left);
-
- /* Do not create Confirm nodes for Cmp(Const, Const) constructs.
- These are removed anyway */
- if (op == op_Const && is_Const(right))
- return;
-
- /* try to place the constant on the right side for a Confirm */
- if (op == op_Const || op == op_SymConst) {
- ir_node *t = left;
-
- left = right;
- right = t;
-
- pnc = get_inversed_pnc(pnc);
- }
-
- /*
- * First case: both values are identical.
- * replace the left one by the right (potentially const) one.
- */
- if (pnc == pn_Cmp_Eq) {
- for (edge = get_irn_out_edge_first(left); edge; edge = next) {
- ir_node *succ = get_edge_src_irn(edge);
- int pos = get_edge_src_pos(edge);
- ir_node *blk = get_effective_use_block(succ, pos);
-
- next = get_irn_out_edge_next(left, edge);
- if (block_dominates(block, blk)) {
- /*
- * Ok, we found a usage of left in a block
- * dominated by the branch block.
- * We can replace the input with right.
- */
- set_irn_n(succ, pos, right);
- DBG_OPT_CONFIRM(left, right);
-
-// ir_printf("2 Replacing input %d of node %n with %n\n", pos, succ, right);
-
- env->num_eq += 1;
- }
- }
- }
- else { /* not pn_Cmp_Eq cases */
- ir_node *c = NULL;
-
- for (edge = get_irn_out_edge_first(left); edge; edge = next) {
- ir_node *succ = get_edge_src_irn(edge);
- int pos = get_edge_src_pos(edge);
- ir_node *blk = get_effective_use_block(succ, pos);
-
- next = get_irn_out_edge_next(left, edge);
- if (block_dominates(block, blk)) {
- /*
- * Ok, we found a usage of left in a block
- * dominated by the branch block.
- * We can replace the input with a Confirm(left, pnc, right).
- */
- if (! c)
- c = new_r_Confirm(current_ir_graph, block, left, right, pnc);
-
- pos = get_edge_src_pos(edge);
- set_irn_n(succ, pos, c);
-// ir_printf("3 Replacing input %d of node %n with %n\n", pos, succ, c);
-
- env->num_confirms += 1;
- }
- }
- }
+ ir_node *left = get_Cmp_left(cmp);
+ ir_node *right = get_Cmp_right(cmp);
+ ir_node *cond_block;
+ ir_op *op;
+ const ir_edge_t *edge, *next;
+
+ /* Beware of Bads */
+ if (is_Bad(left) || is_Bad(right))
+ return;
+
+ op = get_irn_op(left);
+
+ /* Do not create Confirm nodes for Cmp(Const, Const) constructs.
+ These are removed anyway */
+ if (op == op_Const && is_Const(right))
+ return;
+
+ /* try to place the constant on the right side for a Confirm */
+ if (op == op_Const || op == op_SymConst) {
+ ir_node *t = left;
+
+ left = right;
+ right = t;
+
+ pnc = get_inversed_pnc(pnc);
+ }
+
+ /*
+ * First case: both values are identical.
+ * replace the left one by the right (potentially const) one.
+ */
+ if (pnc == pn_Cmp_Eq) {
+ cond_block = get_Block_cfgpred_block(block, 0);
+ for (edge = get_irn_out_edge_first(left); edge; edge = next) {
+ ir_node *user = get_edge_src_irn(edge);
+ int pos = get_edge_src_pos(edge);
+ ir_node *blk = get_effective_use_block(user, pos);
+
+ next = get_irn_out_edge_next(left, edge);
+ if (block_dominates(block, blk)) {
+ /*
+ * Ok, we found a usage of left in a block
+ * dominated by the branch block.
+ * We can replace the input with right.
+ */
+ set_irn_n(user, pos, right);
+ DBG_OPT_CONFIRM(left, right);
+
+ DB((dbg, LEVEL_2, "Replacing input %d of node %+F with %+F\n", pos, user, right));
+
+ env->num_eq += 1;
+ } else if (block_dominates(blk, cond_block)
+ && is_Const(right)
+ && get_irn_pinned(user) == op_pin_state_floats) {
+ /*
+ * left == Const and we found a movable user of left in a
+ * dominator of the Cond block
+ */
+ const ir_edge_t *edge, *next;
+ for (edge = get_irn_out_edge_first(user); edge; edge = next) {
+ ir_node *usr_of_usr = get_edge_src_irn(edge);
+ int npos = get_edge_src_pos(edge);
+ ir_node *blk = get_effective_use_block(usr_of_usr, npos);
+
+ next = get_irn_out_edge_next(user, edge);
+ if (block_dominates(block, blk)) {
+ /*
+ * The user of the user is dominated by our true/false
+ * block. So, create a copy of user WITH the constant
+ * replacing it's pos'th input.
+ *
+ * This is always good for unop's and might be good
+ * for binops.
+ *
+ * If user has other user in the false/true block, code
+ * placement will move it down.
+ * If there are users in cond block or upper, we create
+ * "redundant ops", because one will have a const op,
+ * the other no const ...
+ */
+ ir_node *new_op = exact_copy(user);
+ set_nodes_block(new_op, block);
+ set_irn_n(new_op, pos, right);
+ set_irn_n(usr_of_usr, npos, new_op);
+ env->num_eq += 1;
+ }
+ }
+ }
+ }
+ } else { /* not pn_Cmp_Eq cases */
+ ir_node *c = NULL;
+
+ foreach_out_edge_safe(left, edge, next) {
+ ir_node *succ = get_edge_src_irn(edge);
+ int pos = get_edge_src_pos(edge);
+ ir_node *blk = get_effective_use_block(succ, pos);
+
+ if (block_dominates(block, blk)) {
+ /*
+ * Ok, we found a usage of left in a block
+ * dominated by the branch block.
+ * We can replace the input with a Confirm(left, pnc, right).
+ */
+ if (! c)
+ c = new_r_Confirm(block, left, right, pnc);
+
+ pos = get_edge_src_pos(edge);
+ set_irn_n(succ, pos, c);
+ DB((dbg, LEVEL_2, "Replacing input %d of node %+F with %+F\n", pos, succ, c));
+
+ env->num_confirms += 1;
+ }
+ }
+
+ if (! is_Const(right)) {
+ /* also construct inverse Confirms */
+ ir_node *rc = NULL;
+
+ pnc = get_inversed_pnc(pnc);
+ foreach_out_edge_safe(right, edge, next) {
+ ir_node *succ = get_edge_src_irn(edge);
+ int pos;
+ ir_node *blk;
+
+ if (succ == c)
+ continue;
+
+ pos = get_edge_src_pos(edge);
+ blk = get_effective_use_block(succ, pos);
+
+ if (block_dominates(block, blk)) {
+ /*
+ * Ok, we found a usage of right in a block
+ * dominated by the branch block.
+ * We can replace the input with a Confirm(right, pnc^-1, left).
+ */
+ if (! rc)
+ rc = new_r_Confirm(block, right, left, pnc);
+
+ pos = get_edge_src_pos(edge);
+ set_irn_n(succ, pos, rc);
+ DB((dbg, LEVEL_2, "Replacing input %d of node %+F with %+F\n", pos, succ, rc));
+
+ env->num_confirms += 1;
+ }
+ }
+ }
+ }