diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2012-07-01 07:51:12 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2012-07-01 07:51:12 +0000 |
commit | 4abaa3fa312fcbe7ee9665853f52a5d37e703864 (patch) | |
tree | 8fb982f2dd6fca8990708aa30a04e537c38ab395 | |
parent | 9b8f0f6c4683dd00ee0e3422b84c9cc34510011e (diff) | |
download | compcert-4abaa3fa312fcbe7ee9665853f52a5d37e703864.tar.gz compcert-4abaa3fa312fcbe7ee9665853f52a5d37e703864.zip |
Recombine x = cmp(...); if (x == 1) ...
and x = cmp(...); if (x != 1) ...
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1946 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
-rw-r--r-- | arm/CombineOp.v | 22 | ||||
-rw-r--r-- | arm/CombineOpproof.v | 29 | ||||
-rw-r--r-- | ia32/CombineOp.v | 28 | ||||
-rw-r--r-- | ia32/CombineOpproof.v | 29 | ||||
-rw-r--r-- | powerpc/CombineOp.v | 28 | ||||
-rw-r--r-- | powerpc/CombineOpproof.v | 33 |
6 files changed, 157 insertions, 12 deletions
diff --git a/arm/CombineOp.v b/arm/CombineOp.v index 80486537..d153b731 100644 --- a/arm/CombineOp.v +++ b/arm/CombineOp.v @@ -41,16 +41,30 @@ Function combine_compimm_eq_0 (x: valnum) : option(condition * list valnum) := | _ => None end. +Function combine_compimm_ne_1 (x: valnum) : option(condition * list valnum) := + match get x with + | Some(Op (Ocmp c) ys) => Some (negate_condition c, ys) + | _ => None + end. + Function combine_cond (cond: condition) (args: list valnum) : option(condition * list valnum) := match cond, args with | Ccompimm Cne n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_ne_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_ne_0 x + else if Int.eq_dec n Int.one then combine_compimm_ne_1 x + else None | Ccompimm Ceq n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_eq_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_eq_0 x + else if Int.eq_dec n Int.one then combine_compimm_eq_1 x + else None | Ccompuimm Cne n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_ne_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_ne_0 x + else if Int.eq_dec n Int.one then combine_compimm_ne_1 x + else None | Ccompuimm Ceq n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_eq_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_eq_0 x + else if Int.eq_dec n Int.one then combine_compimm_eq_1 x + else None | _, _ => None end. diff --git a/arm/CombineOpproof.v b/arm/CombineOpproof.v index 9d297ace..0d2e6dd1 100644 --- a/arm/CombineOpproof.v +++ b/arm/CombineOpproof.v @@ -58,6 +58,31 @@ Proof. destruct (eval_condition c (map valu args) m); simpl; auto. destruct b; auto. Qed. +Lemma combine_compimm_eq_1_sound: + forall x cond args, + combine_compimm_eq_1 get x = Some(cond, args) -> + eval_condition cond (map valu args) m = Val.cmp_bool Ceq (valu x) (Vint Int.one) /\ + eval_condition cond (map valu args) m = Val.cmpu_bool (Mem.valid_pointer m) Ceq (valu x) (Vint Int.one). +Proof. + intros until args. functional induction (combine_compimm_eq_1 get x); intros EQ; inv EQ. + (* of cmp *) + exploit get_sound; eauto. unfold equation_holds. simpl. intro EQ; inv EQ. + destruct (eval_condition cond (map valu args) m); simpl; auto. destruct b; auto. +Qed. + +Lemma combine_compimm_ne_1_sound: + forall x cond args, + combine_compimm_ne_1 get x = Some(cond, args) -> + eval_condition cond (map valu args) m = Val.cmp_bool Cne (valu x) (Vint Int.one) /\ + eval_condition cond (map valu args) m = Val.cmpu_bool (Mem.valid_pointer m) Cne (valu x) (Vint Int.one). +Proof. + intros until args. functional induction (combine_compimm_eq_1 get x); intros EQ; inv EQ. + (* of cmp *) + exploit get_sound; eauto. unfold equation_holds. simpl. intro EQ; inv EQ. + rewrite eval_negate_condition. + destruct (eval_condition cond (map valu args) m); simpl; auto. destruct b; auto. +Qed. + Theorem combine_cond_sound: forall cond args cond' args', combine_cond get cond args = Some(cond', args') -> @@ -68,10 +93,14 @@ Proof. simpl; eapply combine_compimm_ne_0_sound; eauto. (* compimm eq zero *) simpl; eapply combine_compimm_eq_0_sound; eauto. + (* compimm eq one *) + simpl; eapply combine_compimm_eq_1_sound; eauto. (* compuimm ne zero *) simpl; eapply combine_compimm_ne_0_sound; eauto. (* compuimm eq zero *) simpl; eapply combine_compimm_eq_0_sound; eauto. + (* compuimm eq one *) + simpl; eapply combine_compimm_eq_1_sound; eauto. Qed. Theorem combine_addr_sound: diff --git a/ia32/CombineOp.v b/ia32/CombineOp.v index 1391f556..07d5a79a 100644 --- a/ia32/CombineOp.v +++ b/ia32/CombineOp.v @@ -43,16 +43,36 @@ Function combine_compimm_eq_0 (x: valnum) : option(condition * list valnum) := | _ => None end. +Function combine_compimm_eq_1 (x: valnum) : option(condition * list valnum) := + match get x with + | Some(Op (Ocmp c) ys) => Some (c, ys) + | _ => None + end. + +Function combine_compimm_ne_1 (x: valnum) : option(condition * list valnum) := + match get x with + | Some(Op (Ocmp c) ys) => Some (negate_condition c, ys) + | _ => None + end. + Function combine_cond (cond: condition) (args: list valnum) : option(condition * list valnum) := match cond, args with | Ccompimm Cne n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_ne_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_ne_0 x + else if Int.eq_dec n Int.one then combine_compimm_ne_1 x + else None | Ccompimm Ceq n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_eq_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_eq_0 x + else if Int.eq_dec n Int.one then combine_compimm_eq_1 x + else None | Ccompuimm Cne n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_ne_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_ne_0 x + else if Int.eq_dec n Int.one then combine_compimm_ne_1 x + else None | Ccompuimm Ceq n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_eq_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_eq_0 x + else if Int.eq_dec n Int.one then combine_compimm_eq_1 x + else None | _, _ => None end. diff --git a/ia32/CombineOpproof.v b/ia32/CombineOpproof.v index 2f1fe7bc..4e07bf5a 100644 --- a/ia32/CombineOpproof.v +++ b/ia32/CombineOpproof.v @@ -66,6 +66,31 @@ Proof. intros EQ; inv EQ. destruct (valu v); simpl; auto. Qed. +Lemma combine_compimm_eq_1_sound: + forall x cond args, + combine_compimm_eq_1 get x = Some(cond, args) -> + eval_condition cond (map valu args) m = Val.cmp_bool Ceq (valu x) (Vint Int.one) /\ + eval_condition cond (map valu args) m = Val.cmpu_bool (Mem.valid_pointer m) Ceq (valu x) (Vint Int.one). +Proof. + intros until args. functional induction (combine_compimm_eq_1 get x); intros EQ; inv EQ. + (* of cmp *) + exploit get_sound; eauto. unfold equation_holds. simpl. intro EQ; inv EQ. + destruct (eval_condition cond (map valu args) m); simpl; auto. destruct b; auto. +Qed. + +Lemma combine_compimm_ne_1_sound: + forall x cond args, + combine_compimm_ne_1 get x = Some(cond, args) -> + eval_condition cond (map valu args) m = Val.cmp_bool Cne (valu x) (Vint Int.one) /\ + eval_condition cond (map valu args) m = Val.cmpu_bool (Mem.valid_pointer m) Cne (valu x) (Vint Int.one). +Proof. + intros until args. functional induction (combine_compimm_eq_1 get x); intros EQ; inv EQ. + (* of cmp *) + exploit get_sound; eauto. unfold equation_holds. simpl. intro EQ; inv EQ. + rewrite eval_negate_condition. + destruct (eval_condition cond (map valu args) m); simpl; auto. destruct b; auto. +Qed. + Theorem combine_cond_sound: forall cond args cond' args', combine_cond get cond args = Some(cond', args') -> @@ -76,10 +101,14 @@ Proof. simpl; eapply combine_compimm_ne_0_sound; eauto. (* compimm eq zero *) simpl; eapply combine_compimm_eq_0_sound; eauto. + (* compimm eq one *) + simpl; eapply combine_compimm_eq_1_sound; eauto. (* compuimm ne zero *) simpl; eapply combine_compimm_ne_0_sound; eauto. (* compuimm eq zero *) simpl; eapply combine_compimm_eq_0_sound; eauto. + (* compuimm eq one *) + simpl; eapply combine_compimm_eq_1_sound; eauto. Qed. Theorem combine_addr_sound: diff --git a/powerpc/CombineOp.v b/powerpc/CombineOp.v index 243da4ef..73b7c55b 100644 --- a/powerpc/CombineOp.v +++ b/powerpc/CombineOp.v @@ -43,16 +43,36 @@ Function combine_compimm_eq_0 (x: valnum) : option(condition * list valnum) := | _ => None end. +Function combine_compimm_eq_1 (x: valnum) : option(condition * list valnum) := + match get x with + | Some(Op (Ocmp c) ys) => Some (c, ys) + | _ => None + end. + +Function combine_compimm_ne_1 (x: valnum) : option(condition * list valnum) := + match get x with + | Some(Op (Ocmp c) ys) => Some (negate_condition c, ys) + | _ => None + end. + Function combine_cond (cond: condition) (args: list valnum) : option(condition * list valnum) := match cond, args with | Ccompimm Cne n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_ne_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_ne_0 x + else if Int.eq_dec n Int.one then combine_compimm_ne_1 x + else None | Ccompimm Ceq n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_eq_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_eq_0 x + else if Int.eq_dec n Int.one then combine_compimm_eq_1 x + else None | Ccompuimm Cne n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_ne_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_ne_0 x + else if Int.eq_dec n Int.one then combine_compimm_ne_1 x + else None | Ccompuimm Ceq n, x::nil => - if Int.eq_dec n Int.zero then combine_compimm_eq_0 x else None + if Int.eq_dec n Int.zero then combine_compimm_eq_0 x + else if Int.eq_dec n Int.one then combine_compimm_eq_1 x + else None | _, _ => None end. diff --git a/powerpc/CombineOpproof.v b/powerpc/CombineOpproof.v index f493c169..c96ecc1d 100644 --- a/powerpc/CombineOpproof.v +++ b/powerpc/CombineOpproof.v @@ -66,6 +66,31 @@ Proof. intros EQ; inv EQ. destruct (valu v); simpl; auto. Qed. +Lemma combine_compimm_eq_1_sound: + forall x cond args, + combine_compimm_eq_1 get x = Some(cond, args) -> + eval_condition cond (map valu args) m = Val.cmp_bool Ceq (valu x) (Vint Int.one) /\ + eval_condition cond (map valu args) m = Val.cmpu_bool (Mem.valid_pointer m) Ceq (valu x) (Vint Int.one). +Proof. + intros until args. functional induction (combine_compimm_eq_1 get x); intros EQ; inv EQ. + (* of cmp *) + exploit get_sound; eauto. unfold equation_holds. simpl. intro EQ; inv EQ. + destruct (eval_condition cond (map valu args) m); simpl; auto. destruct b; auto. +Qed. + +Lemma combine_compimm_ne_1_sound: + forall x cond args, + combine_compimm_ne_1 get x = Some(cond, args) -> + eval_condition cond (map valu args) m = Val.cmp_bool Cne (valu x) (Vint Int.one) /\ + eval_condition cond (map valu args) m = Val.cmpu_bool (Mem.valid_pointer m) Cne (valu x) (Vint Int.one). +Proof. + intros until args. functional induction (combine_compimm_ne_1 get x); intros EQ; inv EQ. + (* of cmp *) + exploit get_sound; eauto. unfold equation_holds. simpl. intro EQ; inv EQ. + rewrite eval_negate_condition. + destruct (eval_condition c (map valu args) m); simpl; auto. destruct b; auto. +Qed. + Theorem combine_cond_sound: forall cond args cond' args', combine_cond get cond args = Some(cond', args') -> @@ -74,12 +99,20 @@ Proof. intros. functional inversion H; subst. (* compimm ne zero *) simpl; eapply combine_compimm_ne_0_sound; eauto. + (* compimm ne one *) + simpl; eapply combine_compimm_ne_1_sound; eauto. (* compimm eq zero *) simpl; eapply combine_compimm_eq_0_sound; eauto. + (* compimm eq one *) + simpl; eapply combine_compimm_eq_1_sound; eauto. (* compuimm ne zero *) simpl; eapply combine_compimm_ne_0_sound; eauto. + (* compuimm ne one *) + simpl; eapply combine_compimm_ne_1_sound; eauto. (* compuimm eq zero *) simpl; eapply combine_compimm_eq_0_sound; eauto. + (* compuimm eq one *) + simpl; eapply combine_compimm_eq_1_sound; eauto. Qed. Theorem combine_addr_sound: |