+ /* ignore control flow */
+ mode = get_irn_mode(node);
+ if (mode == mode_X || is_Cond(node))
+ continue;
+#ifdef AVOID_PHIB
+ /* we may not copy mode_b nodes, because this could produce Phi with
+ * mode_bs which can't be handled in all backends. Instead we duplicate
+ * the node and move it to its users */
+ if (mode == mode_b) {
+ const ir_edge_t *edge, *next;
+ ir_node *pred;
+ int pn;
+
+ assert(is_Proj(node));
+
+ pred = get_Proj_pred(node);
+ pn = get_Proj_proj(node);
+
+ foreach_out_edge_safe(node, edge, next) {
+ ir_node *cmp_copy;
+ ir_node *user = get_edge_src_irn(edge);
+ int pos = get_edge_src_pos(edge);
+ ir_node *user_block = get_nodes_block(user);
+
+ if(user_block == block)
+ continue;
+
+ cmp_copy = exact_copy(pred);
+ set_nodes_block(cmp_copy, user_block);
+ copy = new_r_Proj(current_ir_graph, user_block, cmp_copy, mode_b, pn);
+ set_irn_n(user, pos, copy);
+ }
+ continue;
+ }
+#endif
+
+ copy = copy_and_fix_node(env, block, copy_block, j, node);
+
+ /* we might hit values in blocks that have already been processed by a
+ * recursive find_phi_with_const() call */
+ assert(get_irn_visited(copy) <= env->visited_nr);
+ if(get_irn_visited(copy) >= env->visited_nr) {
+ ir_node *prev_copy = get_irn_link(copy);
+ if(prev_copy != NULL)
+ set_irn_link(node, prev_copy);
+ }
+ }
+
+ /* fix data-flow (and reconstruct SSA if needed) */
+ foreach_out_edge(block, edge) {
+ ir_node *node = get_edge_src_irn(edge);
+ ir_node *copy_node;
+ ir_mode *mode;
+
+ if (is_Block(node)) {
+ /* Block->Block edge, should be the MacroBlock edge */
+ assert(get_Block_MacroBlock(node) == block && "Block->Block edge found");
+ continue;
+ }
+
+ mode = get_irn_mode(node);
+ if (mode == mode_X || is_Cond(node))
+ continue;
+#ifdef AVOID_PHIB
+ if (mode == mode_b)
+ continue;
+#endif
+
+ DB((dbg, LEVEL_2, ">> Fixing users of %+F\n", node));
+
+ copy_node = get_irn_link(node);
+ construct_ssa(block, node, copy_block, copy_node);
+ }
+}
+
+/**
+ * returns whether the cmp evaluates to true or false, or can't be evaluated!
+ * 1: true, 0: false, -1: can't evaluate
+ *
+ * @param pnc the compare mode of the Compare
+ * @param tv_left the left tarval
+ * @param tv_right the right tarval
+ */
+static int eval_cmp_tv(pn_Cmp pnc, tarval *tv_left, tarval *tv_right) {
+ pn_Cmp cmp_result = tarval_cmp(tv_left, tv_right);
+
+ /* does the compare evaluate to true? */
+ if (cmp_result == pn_Cmp_False)
+ return -1;
+ if ((cmp_result & pnc) != cmp_result)
+ return 0;
+
+ return 1;
+}
+
+/**
+ * returns whether the cmp evaluates to true or false, or can't be evaluated!
+ * 1: true, 0: false, -1: can't evaluate
+ *
+ * @param env the environment
+ * @param cand the candidate node, either a Const or a Confirm
+ */
+static int eval_cmp(condeval_env_t *env, ir_node *cand) {
+ if (is_Const(cand)) {
+ tarval *tv_cand = get_Const_tarval(cand);
+ tarval *tv_cmp = get_Const_tarval(env->cnst);
+
+ return eval_cmp_tv(env->pnc, tv_cand, tv_cmp);
+ } else { /* a Confirm */
+ tarval *res = computed_value_Cmp_Confirm(env->cmp, cand, env->cnst, env->pnc);
+
+ if (res == tarval_bad)
+ return -1;
+ return res == tarval_b_true;
+ }
+}
+
+/**
+ * Check for Const or Confirm with Const.
+ */
+static int is_Const_or_Confirm(const ir_node *node) {
+ if (is_Confirm(node))
+ node = get_Confirm_bound(node);
+ return is_Const(node);
+}
+
+/**
+ * get the tarval of a Const or Confirm with
+ */
+static tarval *get_Const_or_Confirm_tarval(const ir_node *node) {
+ if (is_Confirm(node)) {
+ if (get_Confirm_bound(node))
+ node = get_Confirm_bound(node);
+ }
+ return get_Const_tarval(node);
+}
+
+static ir_node *find_const_or_confirm(condeval_env_t *env, ir_node *jump, ir_node *value)
+{
+ ir_node *block = get_nodes_block(jump);
+
+ if (irn_visited_else_mark(value))
+ return NULL;
+
+ if (is_Const_or_Confirm(value)) {
+ if (eval_cmp(env, value) <= 0) {
+ return NULL;
+ }
+
+ DB((
+ dbg, LEVEL_1,
+ "> Found condition evaluation candidate %+F->%+F\n",
+ env->true_block, block
+ ));
+
+ /* adjust true_block to point directly towards our jump */
+ add_pred(env->true_block, jump);
+
+ split_critical_edge(env->true_block, 0);