Proving correctness of compiler optimizations by temporal logic

David Lacey, Neil D. Jones, Eric Van Wyk, Carl Christian Frederiksen
2002 SIGPLAN notices  
Many classical compiler optimizations can be elegantly expressed using rewrite rules of form: I =⇒ I if φ, where I, I are intermediate language instructions and φ is a property expressed in a temporal logic suitable for describing program data flow. Its reading: If the current program π contains an instruction of form I at some control point p, and if flow condition φ is satisfied at p, then replace I by I . The purpose of this paper is to show how such transformations may be proven correct.
more » ... proven correct. Our methodology is illustrated by three familiar optimizations, dead code elimination, constant folding and code motion. The meaning of correctness is that for any program π, if Rewrite(π, π , p,I =⇒ I if φ) then [[π]] =[[π ]], i.e. π and π have exactly the same semantics. and π is the result of transforming it, a induction relation is established between the computations of π and π . A consequence is that if π has a terminating computation with "final answer" v, then π also has a terminating computation with the same final answer; and vice versa.
doi:10.1145/565816.503299 fatcat:n3ihj3brwrdenl5iwfa6myhg64