void mir_rewrite_index_src(compiler_context *ctx, unsigned old, unsigned new);
 void mir_rewrite_index_dst(compiler_context *ctx, unsigned old, unsigned new);
 void mir_rewrite_index_src_single(midgard_instruction *ins, unsigned old, unsigned new);
+bool mir_single_use(compiler_context *ctx, unsigned value);
 
 /* MIR printing */
 
 
         mir_rewrite_index_src(ctx, old, new);
         mir_rewrite_index_dst(ctx, old, new);
 }
+
+/* Checks if a value is used only once (or totally dead), which is an important
+ * heuristic to figure out if certain optimizations are Worth It (TM) */
+
+bool
+mir_single_use(compiler_context *ctx, unsigned value)
+{
+        unsigned used_count = 0;
+
+        mir_foreach_instr_global(ctx, ins) {
+                if (mir_has_arg(ins, value))
+                        ++used_count;
+
+                /* Short circuit for speed */
+                if (used_count > 1)
+                        return false;
+        }
+
+        return used_count <= 1;
+
+}