Skip to content

Commit f3f1dc2

Browse files
committed
Constant propagation: optimize "known integer or Vundef" results
Results that analyze to `IU n` are turned into `load-integer-immediate(n)` operations. This is semantically safe, and enables compile-time evaluation of some pointer comparisons (e.g. `&x == &x` where `x` is a global variable or a stack-allocated variable).
1 parent 57a630c commit f3f1dc2

10 files changed

+15
-5
lines changed

aarch64/ConstpropOp.vp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Require SelectOp.
2323

2424
Definition const_for_result (a: aval) : option operation :=
2525
match a with
26-
| I n => Some(Ointconst n)
26+
| I n | IU n => Some(Ointconst n)
2727
| L n => Some(Olongconst n)
2828
| F n => if Compopts.generate_float_constants tt then Some(Ofloatconst n) else None
2929
| FS n => if Compopts.generate_float_constants tt then Some(Osingleconst n) else None

aarch64/ConstpropOpproof.v

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ Proof.
9292
unfold const_for_result; intros; destruct a; inv H; SimplVM.
9393
- (* integer *)
9494
exists (Vint n); auto.
95+
- (* integer or undef *)
96+
exists (Vint n); split; auto. inv H0; auto.
9597
- (* long *)
9698
exists (Vlong n); auto.
9799
- (* float *)

arm/ConstpropOp.vp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Require Import ValueDomain ValueAOp.
2626

2727
Definition const_for_result (a: aval) : option operation :=
2828
match a with
29-
| I n => Some(Ointconst n)
29+
| I n | IU n => Some(Ointconst n)
3030
| F n => if Compopts.generate_float_constants tt then Some(Ofloatconst n) else None
3131
| FS n => if Compopts.generate_float_constants tt then Some(Osingleconst n) else None
3232
| Ptr(Gl id ofs) => Some (Oaddrsymbol id ofs)

arm/ConstpropOpproof.v

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Proof.
107107
destruct a; inv H; SimplVM.
108108
- (* integer *)
109109
exists (Vint n); auto.
110+
- (* integer or undef *)
111+
exists (Vint n); split; auto. inv H0; auto.
110112
- (* float *)
111113
destruct (generate_float_constants tt); inv H2. exists (Vfloat f); auto.
112114
- (* single *)

powerpc/ConstpropOp.vp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Require Import ValueDomain ValueAOp.
2222

2323
Definition const_for_result (a: aval) : option operation :=
2424
match a with
25-
| I n => Some(Ointconst n)
25+
| I n | IU n => Some(Ointconst n)
2626
| L n => if Archi.ppc64 then Some (Olongconst n) else None
2727
| F n => if Compopts.generate_float_constants tt then Some(Ofloatconst n) else None
2828
| FS n => if Compopts.generate_float_constants tt then Some(Osingleconst n) else None

powerpc/ConstpropOpproof.v

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ Proof.
101101
destruct a; inv H; SimplVM.
102102
- (* integer *)
103103
exists (Vint n); auto.
104+
- (* integer or undef *)
105+
exists (Vint n); split; auto. inv H0; auto.
104106
- (* long *)
105107
destruct (Archi.ppc64); inv H2. exists (Vlong n); auto.
106108
- (* float *)

riscV/ConstpropOp.vp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Require Import ValueDomain.
2323

2424
Definition const_for_result (a: aval) : option operation :=
2525
match a with
26-
| I n => Some(Ointconst n)
26+
| I n | IU n => Some(Ointconst n)
2727
| L n => if Archi.ptr64 then Some(Olongconst n) else None
2828
| F n => if Compopts.generate_float_constants tt then Some(Ofloatconst n) else None
2929
| FS n => if Compopts.generate_float_constants tt then Some(Osingleconst n) else None

riscV/ConstpropOpproof.v

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Proof.
9191
destruct a; inv H; SimplVM.
9292
- (* integer *)
9393
exists (Vint n); auto.
94+
- (* integer or undef *)
95+
exists (Vint n); split; auto. inv H0; auto.
9496
- (* long *)
9597
destruct ptr64; inv H2. exists (Vlong n); auto.
9698
- (* float *)

x86/ConstpropOp.vp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Definition Olea_ptr (a: addressing) := if Archi.ptr64 then Oleal a else Olea a.
2525

2626
Definition const_for_result (a: aval) : option operation :=
2727
match a with
28-
| I n => Some(Ointconst n)
28+
| I n | IU n => Some(Ointconst n)
2929
| L n => if Archi.ptr64 then Some(Olongconst n) else None
3030
| F n => if Compopts.generate_float_constants tt then Some(Ofloatconst n) else None
3131
| FS n => if Compopts.generate_float_constants tt then Some(Osingleconst n) else None

x86/ConstpropOpproof.v

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ Proof.
9898
destruct a; inv H; SimplVM.
9999
- (* integer *)
100100
exists (Vint n); auto.
101+
- (* integer or undef *)
102+
exists (Vint n); split; auto. inv H0; auto.
101103
- (* long *)
102104
destruct ptr64; inv H2. exists (Vlong n); auto.
103105
- (* float *)

0 commit comments

Comments
 (0)