Section Correctness.
(** A peephole optimizer is correct if it replaces an instruction with a semantically equivalent sequence of instructions. *)
Definition ph_correct (ph : peephole_optimization) :=
forall (i:instr),
@eq_asm_denotations_EQ Exit unit _ (fun _ => denote_instr i) (fun _ => denote_list (ph i)).
(* concrete optimizations --------------------------------------------------- *)
Definition simple (i:instr) : list instr :=
match i with
| Imov dest (Oreg src) =>
if Nat.eqb dest src then [] else [i]
| _ => [i]
end.

(* SAZ: Belongs in the utilities? (but depends on EQ_registers) EQ_Registers is now just an alias for eq_map, so this can be moved to MapDefaultFacts. *)
Lemma EQ_registers_add:
forall (r : reg) (d:value) (regs1 regs2 : registers),
EQ_registers d regs1 regs2 ->
EQ_registers d (alist_add r (lookup_default r d regs1) regs1) regs2.