Section SOUNDNESS.
Variable A V: Type.
Variable genv: Genv.t A V.
Remark type_add:
forall v1 v2, Val.has_type (Val.add v1 v2) Tint.
Remark type_addl:
forall v1 v2, Val.has_type (Val.addl v1 v2) Tlong.
Proof with (try exact I; try reflexivity).
intros.
destruct op; simpl in H0; FuncInv; subst; simpl.
congruence.
exact I.
exact I.
exact I.
exact I.
unfold Genv.symbol_address; destruct (Genv.find_symbol genv id)...
destruct v0...
destruct v0...
destruct v0...
destruct v0...
destruct v0...
unfold Val.sub, Val.has_type; destruct Archi.ptr64, v0, v1... destruct (eq_block b b0)...
destruct v0; destruct v1...
destruct v0...
destruct v0; destruct v1...
destruct v0; destruct v1...
destruct v0; destruct v1; simpl in *; inv H0.
destruct (Int.eq i0 Int.zero || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2...
destruct v0; destruct v1; simpl in *; inv H0. destruct (Int.eq i0 Int.zero); inv H2...
destruct v0; destruct v1; simpl in *; inv H0.
destruct (Int.eq i0 Int.zero || Int.eq i (Int.repr Int.min_signed) && Int.eq i0 Int.mone); inv H2...
destruct v0; destruct v1; simpl in *; inv H0. destruct (Int.eq i0 Int.zero); inv H2...
destruct v0; destruct v1...
destruct v0...
destruct v0; destruct v1...
destruct v0...
destruct v0; destruct v1...
destruct v0...
destruct v0...
destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)...
destruct v0; simpl... destruct (Int.ltu n Int.iwordsize)...
destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)...
destruct v0; simpl... destruct (Int.ltu n Int.iwordsize)...
destruct v0; simpl in H0; try discriminate. destruct (Int.ltu n (Int.repr 31)); inv H0...
destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int.iwordsize)...
destruct v0; simpl... destruct (Int.ltu n Int.iwordsize)...
destruct v0...
destruct v0; simpl... destruct (Int.ltu n Int.iwordsize)...
destruct v1; simpl... destruct (Int.ltu (Int.sub Int.iwordsize n) Int.iwordsize)...
eapply type_of_addressing32_sound; eauto.
destruct v0; destruct v1...
destruct v0...
destruct v0...
destruct v0...
destruct v0...
destruct v0...
unfold Val.addl, Val.has_type; destruct Archi.ptr64, v0...
unfold Val.subl, Val.has_type; destruct Archi.ptr64, v0, v1... destruct (eq_block b b0)...
destruct v0; destruct v1...
destruct v0...
destruct v0; destruct v1...
destruct v0; destruct v1...
destruct v0; destruct v1; simpl in *; inv H0.
destruct (Int64.eq i0 Int64.zero || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2...
destruct v0; destruct v1; simpl in *; inv H0. destruct (Int64.eq i0 Int64.zero); inv H2...
destruct v0; destruct v1; simpl in *; inv H0.
destruct (Int64.eq i0 Int64.zero || Int64.eq i (Int64.repr Int64.min_signed) && Int64.eq i0 Int64.mone); inv H2...
destruct v0; destruct v1; simpl in *; inv H0. destruct (Int64.eq i0 Int64.zero); inv H2...
destruct v0; destruct v1...
destruct v0...
destruct v0; destruct v1...
destruct v0...
destruct v0; destruct v1...
destruct v0...
destruct v0...
destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')...
destruct v0; simpl... destruct (Int.ltu n Int64.iwordsize')...
destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')...
destruct v0; simpl... destruct (Int.ltu n Int64.iwordsize')...
destruct v0; inv H0. destruct (Int.ltu n (Int.repr 63)); inv H2...
destruct v0; destruct v1; simpl... destruct (Int.ltu i0 Int64.iwordsize')...
destruct v0; simpl... destruct (Int.ltu n Int64.iwordsize')...
destruct v0...
eapply type_of_addressing64_sound; eauto.
destruct v0...
destruct v0...
destruct v0; destruct v1...
destruct v0; destruct v1...
destruct v0; destruct v1...
destruct v0; destruct v1...
destruct v0...
destruct v0...
destruct v0; destruct v1...
destruct v0; destruct v1...
destruct v0; destruct v1...
destruct v0; destruct v1...
destruct v0...
destruct v0...
destruct v0; simpl in H0; inv H0. destruct (Float.to_int f); inv H2...
destruct v0; simpl in H0; inv H0...
destruct v0; simpl in H0; inv H0. destruct (Float32.to_int f); inv H2...
destruct v0; simpl in H0; inv H0...
destruct v0; simpl in H0; inv H0. destruct (Float.to_long f); inv H2...
destruct v0; simpl in H0; inv H0...
destruct v0; simpl in H0; inv H0. destruct (Float32.to_long f); inv H2...
destruct v0; simpl in H0; inv H0...
destruct (eval_condition cond vl m); simpl... destruct b...
unfold Val.select. destruct (eval_condition c vl m). apply Val.normalize_type. exact I.
Qed.
End SOUNDNESS.
(** * Manipulating and transforming operations *)
(** Recognition of move operations. *)
Definition is_move_operation
(A: Type) (op: operation) (args: list A) : option A :=
match op, args with
| Omove, arg :: nil => Some arg
| _, _ => None
end.
(** [negate_condition cond] returns a condition that is logically equivalent to the negation of [cond]. *)
Definition negate_condition (cond: condition): condition :=
match cond with
| Ccomp c => Ccomp(negate_comparison c)
| Ccompu c => Ccompu(negate_comparison c)
| Ccompimm c n => Ccompimm (negate_comparison c) n
| Ccompuimm c n => Ccompuimm (negate_comparison c) n
| Ccompl c => Ccompl(negate_comparison c)
| Ccomplu c => Ccomplu(negate_comparison c)
| Ccomplimm c n => Ccomplimm (negate_comparison c) n
| Ccompluimm c n => Ccompluimm (negate_comparison c) n
| Ccompf c => Cnotcompf c
| Cnotcompf c => Ccompf c
| Ccompfs c => Cnotcompfs c
| Cnotcompfs c => Ccompfs c
| Cmaskzero n => Cmasknotzero n
| Cmasknotzero n => Cmaskzero n
end.
(** Shifting stack-relative references.  This is used in [Stacking]. *)
Definition shift_stack_addressing (delta: Z) (addr: addressing) :=
match addr with
| Ainstack ofs => Ainstack (Ptrofs.add ofs (Ptrofs.repr delta))
| _ => addr
end.
Definition shift_stack_operation (delta: Z) (op: operation) :=
match op with
| Olea  addr => Olea  (shift_stack_addressing delta addr)
| Oleal addr => Oleal (shift_stack_addressing delta addr)
| _ => op
end.
(** Offset an addressing mode [addr] by a quantity [delta], so that it designates the pointer [delta] bytes past the pointer designated by [addr].  This may be undefined if an offset overflows, in which case [None] is returned.  *)
Definition offset_addressing_total (addr: addressing) (delta: Z) : addressing :=
match addr with
| Aindexed n => Aindexed (n + delta)
| Aindexed2 n => Aindexed2 (n + delta)
| Ascaled sc n => Ascaled sc (n + delta)
| Aindexed2scaled sc n => Aindexed2scaled sc (n + delta)
| Aglobal s n => Aglobal s (Ptrofs.add n (Ptrofs.repr delta))
| Abased s n => Abased s (Ptrofs.add n (Ptrofs.repr delta))
| Abasedscaled sc s n => Abasedscaled sc s (Ptrofs.add n (Ptrofs.repr delta))
| Ainstack n => Ainstack (Ptrofs.add n (Ptrofs.repr delta))
end.
Definition offset_addressing (addr: addressing) (delta: Z) : option addressing :=
let addr' := offset_addressing_total addr delta in
if addressing_valid addr' then Some addr' else None.
(** The following lemma is used only in [Allocproof] in cases where [Archi.ptr64 = false]. *)
(** Operations that are so cheap to recompute that CSE should not factor them out. *)
Definition is_trivial_op (op: operation) : bool :=
match op with
| Omove => true
| Ointconst _ => true
| Olongconst _ => true
| Olea (Aglobal _ _) => true
| Olea (Ainstack _) => true
| Oleal (Aglobal _ _) => true
| Oleal (Ainstack _) => true
| _ => false
end.
(** Operations that depend on the memory state. *)
Definition condition_depends_on_memory (c: condition) : bool :=
match c with
| Ccompu _ => negb Archi.ptr64
| Ccompuimm _ _ => negb Archi.ptr64
| Ccomplu _ => Archi.ptr64
| Ccompluimm _ _ => Archi.ptr64
| _ => false
end.
Definition op_depends_on_memory (op: operation) : bool :=
match op with
| Ocmp c => condition_depends_on_memory c
| Osel c ty => condition_depends_on_memory c
| _ => false
end.

Lemma condition_depends_on_memory_correct:
forall c args m1 m2,
condition_depends_on_memory c = false ->
eval_condition c args m1 = eval_condition c args m2.