+/**
+ * A very simple rematerialization checker.
+ *
+ * @param senv the spill environment
+ * @param spill the Spill node
+ * @param spilled the node that was spilled
+ * @param reloader a irn that requires a reload
+ */
+static int check_remat_conditions(spill_env_t *senv, ir_node *spilled, ir_node *reloader) {
+ const arch_env_t *aenv = senv->chordal_env->birg->main_env->arch_env;
+
+ return get_irn_arity(spilled) == 0 &&
+ arch_irn_is(aenv, spilled, rematerializable);
+}
+
+#endif /* BUGGY_REMAT */
+
+/**
+ * Re-materialize a node.
+ *
+ * @param senv the spill environment
+ * @param spilled the node that was spilled
+ * @param reloader a irn that requires a reload
+ */
+static ir_node *do_remat(spill_env_t *senv, ir_node *spilled, ir_node *reloader) {
+ ir_node *res;
+ ir_node *bl = (is_Block(reloader)) ? reloader : get_nodes_block(reloader);
+
+ /* recompute the value */
+ res = new_ir_node(get_irn_dbg_info(spilled), senv->chordal_env->irg, bl,
+ get_irn_op(spilled),
+ get_irn_mode(spilled),
+ get_irn_arity(spilled),
+ get_irn_in(spilled) + 1);
+ copy_node_attr(spilled, res);
+
+ DBG((senv->dbg, LEVEL_1, "Insert remat %+F before reloader %+F\n", res, reloader));
+
+ /* insert in schedule */
+ if (is_Block(reloader)) {
+ ir_node *insert = sched_skip(reloader, 0, sched_skip_cf_predicator, (void *) senv->chordal_env->birg->main_env->arch_env);
+ sched_add_after(insert, res);
+ } else {
+ sched_add_before(reloader, res);
+ }
+
+ return res;
+}
+
+static void place_copies_for_phi(spill_env_t *env, ir_node* node) {
+ int i, arity;
+
+ assert(is_Phi(node));
+
+ /* We have to place copy nodes in the predecessor blocks to temporarily
+ * produce new values that get separate spill slots
+ */
+ for(i = 0, arity = get_irn_arity(node); i < arity; ++i) {
+ ir_node *pred_block, *arg, *copy, *insert_point;
+
+ /* Don't do anything for looping edges (there's no need
+ * and placing copies here breaks stuff as it suddenly
+ * generates new living values through the whole loop)
+ */
+ arg = get_irn_n(node, i);
+ if(arg == node)
+ continue;
+
+ pred_block = get_Block_cfgpred_block(get_nodes_block(node), i);
+ copy = be_new_Copy(env->cls, get_irn_irg(arg), pred_block, arg);