+#ifdef REMAT
+
+#ifdef BUGGY_REMAT
+
+/**
+ * Check if a spilled node could be rematerialized.
+ *
+ * @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 *spill, ir_node *spilled, ir_node *reloader) {
+ int pos, max;
+
+ /* check for 'normal' spill and general remat condition */
+ if (!be_is_Spill(spill) || !arch_irn_is(senv->chordal_env->birg->main_env->arch_env, spilled, rematerializable))
+ return 0;
+
+ /* check availability of original arguments */
+ if (is_Block(reloader)) {
+
+ /* we want to remat at the end of a block.
+ * thus all arguments must be alive at the end of the block
+ */
+ for (pos=0, max=get_irn_arity(spilled); pos<max; ++pos) {
+ ir_node *arg = get_irn_n(spilled, pos);
+ if (!is_live_end(reloader, arg))
+ return 0;
+ }
+
+ } else {
+
+ /* we want to remat before the insn reloader
+ * thus an arguments is alive if
+ * - it interferes with the reloaders result
+ * or
+ * - or it is (last-) used by reloader itself
+ */
+ for (pos=0, max=get_irn_arity(spilled); pos<max; ++pos) {
+ ir_node *arg = get_irn_n(spilled, pos);
+ int i, m;
+
+ if (values_interfere(reloader, arg))
+ goto is_alive;
+
+ for (i=0, m=get_irn_arity(reloader); i<m; ++i) {
+ ir_node *rel_arg = get_irn_n(reloader, i);
+ if (rel_arg == arg)
+ goto is_alive;
+ }
+
+ /* arg is not alive before reloader */
+ return 0;
+
+is_alive: ;
+
+ }