Skip to content

Commit de545d7

Browse files
committed
Revised instruction selection for the "select" operation
Instead of returning an optional expression, `SelectOp.select` now always returns a CminorSel expression. A separate Boolean-valued function `SelectOp.select_supported` indicates at which types "select" is supported.
1 parent cf8a423 commit de545d7

File tree

12 files changed

+75
-102
lines changed

12 files changed

+75
-102
lines changed

aarch64/SelectOp.vp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -523,16 +523,14 @@ Definition floatofsingle (e: expr) := Eop Ofloatofsingle (e ::: Enil).
523523

524524
(** ** Selection *)
525525

526+
Definition select_supported (ty: typ) :=
527+
match ty with
528+
| Tint | Tlong | Tfloat | Tsingle => true
529+
| _ => false
530+
end.
531+
526532
Definition select (ty: typ) (cond: condition) (args: exprlist) (e1 e2: expr) :=
527-
if match ty with
528-
| Tint => true
529-
| Tlong => true
530-
| Tfloat => true
531-
| Tsingle => true
532-
| _ => false
533-
end
534-
then Some (Eop (Osel cond ty) (e1 ::: e2 ::: args))
535-
else None.
533+
Eop (Osel cond ty) (e1 ::: e2 ::: args).
536534

537535
(** ** Recognition of addressing modes for load and store operations *)
538536

aarch64/SelectOpproof.v

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,18 +1000,16 @@ Qed.
10001000
(** Selection *)
10011001

10021002
Theorem eval_select:
1003-
forall le ty cond al vl a1 v1 a2 v2 a,
1004-
select ty cond al a1 a2 = Some a ->
1003+
forall le ty cond al vl a1 v1 a2 v2,
1004+
select_supported ty = true ->
10051005
eval_exprlist ge sp e m le al vl ->
10061006
eval_expr ge sp e m le a1 v1 ->
10071007
eval_expr ge sp e m le a2 v2 ->
10081008
exists v,
1009-
eval_expr ge sp e m le a v
1009+
eval_expr ge sp e m le (select ty cond al a1 a2) v
10101010
/\ Val.lessdef (Val.select (eval_condition cond vl m) v1 v2 ty) v.
10111011
Proof.
1012-
unfold select; intros.
1013-
destruct (match ty with Tint | Tlong | Tfloat | Tsingle => true | _ => false end); inv H.
1014-
econstructor; split; EvalOp; eauto.
1012+
unfold select; intros. TrivialExists.
10151013
Qed.
10161014

10171015
(** Addressing modes *)

arm/SelectOp.vp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,16 @@ Definition compf (c: comparison) (e1: expr) (e2: expr) :=
379379
Definition compfs (c: comparison) (e1: expr) (e2: expr) :=
380380
Eop (Ocmp (Ccompfs c)) (e1 ::: e2 ::: Enil).
381381

382+
(** ** Selection *)
383+
384+
Definition select_supported (ty: typ) :=
385+
match ty with
386+
| Tint | Tfloat | Tsingle => true
387+
| _ => false
388+
end.
389+
382390
Definition select (ty: typ) (cond: condition) (args: exprlist) (e1 e2: expr) :=
383-
if match ty with
384-
| Tint => true
385-
| Tfloat => true
386-
| Tsingle => true
387-
| _ => false
388-
end
389-
then Some (Eop (Osel cond ty) (e1 ::: e2 ::: args))
390-
else None.
391+
Eop (Osel cond ty) (e1 ::: e2 ::: args).
391392

392393
(** ** Integer conversions *)
393394

arm/SelectOpproof.v

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -729,18 +729,16 @@ Proof.
729729
Qed.
730730

731731
Theorem eval_select:
732-
forall le ty cond al vl a1 v1 a2 v2 a,
733-
select ty cond al a1 a2 = Some a ->
732+
forall le ty cond al vl a1 v1 a2 v2,
733+
select_supported ty = true ->
734734
eval_exprlist ge sp e m le al vl ->
735735
eval_expr ge sp e m le a1 v1 ->
736736
eval_expr ge sp e m le a2 v2 ->
737737
exists v,
738-
eval_expr ge sp e m le a v
738+
eval_expr ge sp e m le (select ty cond al a1 a2) v
739739
/\ Val.lessdef (Val.select (eval_condition cond vl m) v1 v2 ty) v.
740740
Proof.
741-
unfold select; intros.
742-
destruct (match ty with Tint | Tfloat | Tsingle => true | _ => false end); inv H.
743-
econstructor; split; eauto; EvalOp.
741+
unfold select; intros. TrivialExists.
744742
Qed.
745743

746744
Theorem eval_cast8signed: unary_constructor_sound cast8signed (Val.sign_ext 8).

backend/Selection.v

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,9 @@ Definition sel_binop (op: Cminor.binary_operation) (arg1 arg2: expr) : expr :=
164164

165165
Definition sel_select (ty: typ) (cnd ifso ifnot: expr) : expr :=
166166
let (cond, args) := condition_of_expr cnd in
167-
match SelectOp.select ty cond args ifso ifnot with
168-
| Some a => a
169-
| None => Econdition (condexpr_of_expr cnd) ifso ifnot
170-
end.
167+
if SelectOp.select_supported ty
168+
then SelectOp.select ty cond args ifso ifnot
169+
else Econdition (condexpr_of_expr cnd) ifso ifnot.
171170

172171
(** Conversion from Cminor expression to Cminorsel expressions *)
173172

@@ -186,7 +185,7 @@ Fixpoint sel_exprlist (al: list Cminor.expr) : exprlist :=
186185
| a :: bl => Econs (sel_expr a) (sel_exprlist bl)
187186
end.
188187

189-
Definition sel_select_opt (ty: typ) (arg1 arg2 arg3: Cminor.expr) : option expr :=
188+
Definition sel_select_expr (ty: typ) (arg1 arg2 arg3: Cminor.expr) : expr :=
190189
let (cond, args) := condition_of_expr (sel_expr arg1) in
191190
SelectOp.select ty cond args (sel_expr arg2) (sel_expr arg3).
192191

@@ -375,12 +374,11 @@ Definition if_conversion_base
375374
(cond: Cminor.expr) (id: ident) (ifso ifnot: Cminor.expr)
376375
(kont: stmt) : option stmt :=
377376
let ty := env id in
378-
if is_known ki id
377+
if SelectOp.select_supported ty
378+
&& is_known ki id
379379
&& safe_expr ki ifso && safe_expr ki ifnot
380380
&& if_conversion_heuristic id cond ifso ifnot ty kont
381-
then option_map
382-
(fun sel => Sassign id sel)
383-
(sel_select_opt ty cond ifso ifnot)
381+
then Some (Sassign id (sel_select_expr ty cond ifso ifnot))
384382
else None.
385383

386384
Definition if_conversion

backend/Selectionproof.v

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,10 @@ Lemma eval_sel_select:
361361
/\ Val.lessdef (Val.select (Some b) v2 v3 ty) v.
362362
Proof.
363363
unfold sel_select; intros.
364-
specialize (eval_condition_of_expr _ _ _ _ H H2).
364+
specialize (eval_condition_of_expr _ _ _ _ H H2).
365365
destruct (condition_of_expr a1) as [cond args]; simpl fst; simpl snd. intros (vl & A & B).
366-
destruct (select ty cond args a2 a3) as [a|] eqn:SEL.
367-
- exploit eval_select; eauto. rewrite B. auto.
366+
destruct (select_supported ty) eqn:SUP.
367+
- rewrite <- B. eapply eval_select; eauto.
368368
- exists (if b then v2 else v3); split.
369369
econstructor; eauto. eapply eval_condexpr_of_expr; eauto. destruct b; auto.
370370
apply Val.lessdef_normalize.
@@ -776,27 +776,29 @@ Proof.
776776
exists (v1' :: vl'); split; auto. constructor; eauto.
777777
Qed.
778778

779-
Lemma sel_select_opt_correct:
780-
forall ty cond a1 a2 a sp e m vcond v1 v2 b e' m' le,
781-
sel_select_opt ty cond a1 a2 = Some a ->
779+
Lemma sel_select_expr_correct:
780+
forall ty cond a1 a2 sp e m vcond v1 v2 b e' m' le,
781+
SelectOp.select_supported ty = true ->
782782
Cminor.eval_expr ge sp e m cond vcond ->
783783
Cminor.eval_expr ge sp e m a1 v1 ->
784784
Cminor.eval_expr ge sp e m a2 v2 ->
785785
Val.bool_of_val vcond b ->
786786
env_lessdef e e' -> Mem.extends m m' ->
787-
exists v', eval_expr tge sp e' m' le a v' /\ Val.lessdef (Val.select (Some b) v1 v2 ty) v'.
787+
exists v', eval_expr tge sp e' m' le (sel_select_expr ty cond a1 a2) v'
788+
/\ Val.lessdef (Val.select (Some b) v1 v2 ty) v'.
788789
Proof.
789-
unfold sel_select_opt; intros.
790+
unfold sel_select_expr; intros.
790791
destruct (condition_of_expr (sel_expr cond)) as [cnd args] eqn:C.
791792
exploit sel_expr_correct. eexact H0. eauto. eauto. intros (vcond' & EVC & LDC).
792793
exploit sel_expr_correct. eexact H1. eauto. eauto. intros (v1' & EV1 & LD1).
793794
exploit sel_expr_correct. eexact H2. eauto. eauto. intros (v2' & EV2 & LD2).
794795
assert (Val.bool_of_val vcond' b) by (inv H3; inv LDC; constructor).
795796
exploit eval_condition_of_expr. eexact EVC. eauto. rewrite C. intros (vargs' & EVARGS & EVCOND).
796-
exploit eval_select; eauto. intros (v' & X & Y).
797+
exploit (eval_select tge sp e' m' le ty cnd args vargs' (sel_expr a1) v1' (sel_expr a2) v2'); eauto.
798+
simpl in EVCOND; rewrite EVCOND. intros (v' & X & Y).
797799
exists v'; split; eauto.
798800
eapply Val.lessdef_trans; [|eexact Y].
799-
apply Val.select_lessdef; auto.
801+
apply Val.normalize_lessdef. destruct b; auto.
800802
Qed.
801803

802804
Lemma sel_builtin_arg_correct:
@@ -984,17 +986,15 @@ Lemma if_conversion_base_correct:
984986
E0 (State tf Sskip tk sp (PTree.set id v' e') m').
985987
Proof.
986988
unfold if_conversion_base; intros. rewrite H2 in H. clear H2.
987-
destruct andb eqn:C; try discriminate.
988-
destruct (sel_select_opt ty cond ifso ifnot) as [a'|] eqn:SSO; simpl in H; inv H.
989-
InvBooleans.
989+
destruct andb eqn:C; inv H. InvBooleans.
990990
destruct (eval_safe_expr ge f sp e m ifso) as (v1 & EV1); auto.
991991
destruct (eval_safe_expr ge f sp e m ifnot) as (v2 & EV2); auto.
992992
assert (TY1: Val.has_type v1 ty) by (eapply wt_eval_expr; eauto).
993993
assert (TY2: Val.has_type v2 ty) by (eapply wt_eval_expr; eauto).
994-
exploit sel_select_opt_correct; eauto. intros (v' & EV' & LD).
994+
exploit (sel_select_expr_correct ty cond ifso ifnot); eauto. intros (v' & EV & LD).
995995
simpl in LD. rewrite Val.normalize_idem in LD by (destruct b; auto).
996996
exists v1, v2, v'; intuition auto.
997-
constructor. eexact EV'.
997+
constructor. exact EV.
998998
Qed.
999999

10001000
Lemma if_conversion_correct:
@@ -1176,8 +1176,7 @@ Lemma if_conversion_base_nolabel: forall (hf: helper_functions) ki env a id a1 a
11761176
nolabel' s.
11771177
Proof.
11781178
unfold if_conversion_base; intros.
1179-
destruct andb; try discriminate.
1180-
destruct (sel_select_opt (env id) a a1 a2); inv H.
1179+
destruct andb; inv H.
11811180
red; auto.
11821181
Qed.
11831182

powerpc/SelectOp.vp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,15 @@ Definition floatofsingle (e: expr) := Eop Ofloatofsingle (e ::: Enil).
518518

519519
(** ** Selection *)
520520

521+
Definition select_supported (ty: typ) :=
522+
match ty with
523+
| Tint | Tfloat | Tsingle => true
524+
| Tlong => Archi.ppc64
525+
| _ => false
526+
end.
527+
521528
Definition select (ty: typ) (cond: condition) (args: exprlist) (e1 e2: expr) :=
522-
if match ty with
523-
| Tint => true
524-
| Tfloat => true
525-
| Tsingle => true
526-
| Tlong => Archi.ppc64
527-
| _ => false
528-
end
529-
then Some (Eop (Osel cond ty) (e1 ::: e2 ::: args))
530-
else None.
529+
Eop (Osel cond ty) (e1 ::: e2 ::: args).
531530

532531
(** ** Recognition of addressing modes for load and store operations *)
533532

powerpc/SelectOpproof.v

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,19 +1000,16 @@ Proof.
10001000
Qed.
10011001

10021002
Theorem eval_select:
1003-
forall le ty cond al vl a1 v1 a2 v2 a,
1004-
select ty cond al a1 a2 = Some a ->
1003+
forall le ty cond al vl a1 v1 a2 v2,
1004+
select_supported ty = true ->
10051005
eval_exprlist ge sp e m le al vl ->
10061006
eval_expr ge sp e m le a1 v1 ->
10071007
eval_expr ge sp e m le a2 v2 ->
10081008
exists v,
1009-
eval_expr ge sp e m le a v
1009+
eval_expr ge sp e m le (select ty cond al a1 a2) v
10101010
/\ Val.lessdef (Val.select (eval_condition cond vl m) v1 v2 ty) v.
10111011
Proof.
1012-
unfold select; intros.
1013-
destruct (match ty with Tint => true | Tfloat => true | Tsingle => true | Tlong => Archi.ppc64 | _ => false end); inv H.
1014-
exists (Val.select (eval_condition cond vl m) v1 v2 ty); split; auto.
1015-
EvalOp.
1012+
unfold select; intros. TrivialExists.
10161013
Qed.
10171014

10181015
Theorem eval_addressing:

riscV/SelectOp.vp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,9 @@ Definition select_swap (cond: condition) : bool :=
444444
end.
445445

446446
Definition select (ty: typ) (cond: condition) (args: exprlist) (e1 e2: expr) :=
447-
if select_supported ty then
448-
if select_swap cond
449-
then Some (Eop (Osel (negate_condition cond) ty) (e2 ::: e1 ::: args))
450-
else Some (Eop (Osel cond ty) (e1 ::: e2 ::: args))
451-
else
452-
None.
447+
if select_swap cond
448+
then Eop (Osel (negate_condition cond) ty) (e2 ::: e1 ::: args)
449+
else Eop (Osel cond ty) (e1 ::: e2 ::: args).
453450

454451
(** ** Recognition of addressing modes for load and store operations *)
455452

riscV/SelectOpproof.v

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -866,17 +866,16 @@ Proof.
866866
Qed.
867867

868868
Theorem eval_select:
869-
forall le ty cond al vl a1 v1 a2 v2 a,
870-
select ty cond al a1 a2 = Some a ->
869+
forall le ty cond al vl a1 v1 a2 v2,
870+
select_supported ty = true ->
871871
eval_exprlist ge sp e m le al vl ->
872872
eval_expr ge sp e m le a1 v1 ->
873873
eval_expr ge sp e m le a2 v2 ->
874874
exists v,
875-
eval_expr ge sp e m le a v
875+
eval_expr ge sp e m le (select ty cond al a1 a2) v
876876
/\ Val.lessdef (Val.select (eval_condition cond vl m) v1 v2 ty) v.
877877
Proof.
878878
unfold select; intros.
879-
destruct (select_supported ty); try discriminate.
880879
destruct (select_swap cond); inv H.
881880
- TrivialExists. simpl. rewrite eval_negate_condition. destruct (eval_condition cond vl m) as [[]|]; simpl; auto.
882881
- TrivialExists.

0 commit comments

Comments
 (0)