+} /* insert_Confirm_in_block */
+
+/**
+ * Checks if a node is a non-null Confirm.
+ */
+static int is_non_null_Confirm(const ir_node *ptr) {
+ for (;;) {
+ if (! is_Confirm(ptr))
+ break;
+ if (get_Confirm_cmp(ptr) == pn_Cmp_Lg) {
+ ir_node *bound = get_Confirm_bound(ptr);
+
+ if (is_Const(bound) && is_Const_null(bound))
+ return 1;
+ }
+ ptr = get_Confirm_value(ptr);
+ }
+ /*
+ * While a SymConst is not a Confirm, it is non-null
+ * anyway. This helps to reduce the number of
+ * constructed Confirms.
+ */
+ if (is_SymConst_addr_ent(ptr))
+ return 1;
+ return 0;
+} /* is_non_null_Confirm */
+
+/**
+ * The given pointer will be dereferenced, add non-null Confirms.
+ *
+ * @param ptr a node representing an address
+ * @param block the block of the dereferencing instruction
+ * @param env environment
+ */
+static void insert_non_null(ir_node *ptr, ir_node *block, env_t *env) {
+ const ir_edge_t *edge, *next;
+ ir_node *c = NULL;
+
+ foreach_out_edge_safe(ptr, edge, next) {
+ ir_node *succ = get_edge_src_irn(edge);
+ int pos;
+ ir_node *blk;
+
+
+ if (is_Confirm(succ)) {
+ /* beware of loops */
+ continue;
+ }
+
+ if ((is_Load(succ) || is_Store(succ)) &&
+ get_nodes_block(succ) == block) {
+ /* Ignore Loads and Store in the same block for now,
+ because we are not sure if they are dominated.
+ This is not a bad restriction: if exception flow is
+ present, they are in other blocks either. */
+ 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 ptr in a block
+ * dominated by the Load/Store block.
+ * We can replace the input with a Confirm(ptr, !=, NULL).
+ */
+ if (c == NULL) {
+ ir_mode *mode = get_irn_mode(ptr);
+ c = new_Const(mode, get_mode_null(mode));
+
+ c = new_r_Confirm(current_ir_graph, block, ptr, c, pn_Cmp_Lg);
+ }
+
+ set_irn_n(succ, pos, c);
+ DB((dbg, LEVEL_2, "Replacing input %d of node %+F with %+F\n", pos, succ, c));
+
+ env->num_non_null += 1;
+ env->num_confirms += 1;
+ }
+ }
+} /* insert_non_null */
+
+/**
+ * Pre-walker: Called for every node to insert Confirm nodes
+ */
+static void insert_Confirm(ir_node *node, void *env) {
+ ir_node *ptr;
+
+ switch (get_irn_opcode(node)) {
+ case iro_Block:
+ insert_Confirm_in_block(node, env);
+ break;
+ case iro_Load:
+ ptr = get_Load_ptr(node);
+ if (! is_non_null_Confirm(ptr))
+ insert_non_null(ptr, get_nodes_block(node), env);
+ break;
+ case iro_Store:
+ ptr = get_Store_ptr(node);
+ if (! is_non_null_Confirm(ptr))
+ insert_non_null(ptr, get_nodes_block(node), env);
+ break;
+ default:
+ break;
+ }