3 * optimizes away redundant insns such as:
14 * Author: Chris Lu <czl@andrew.cmu.edu>
19 val peephole : x86.insn list -> x86.insn list
22 structure Peephole :> PEEPHOLE =
26 (* val peephole : x86.insn list -> x86.insn list *)
28 fun peephole ((insn1 as X.MOVL(a1,b1))::(insn2 as X.MOVL(a2,b2))::l) =
29 if(x86.opereq(a1, b1) orelse (x86.opereq(a1, a2) andalso x86.opereq(b1, b2))) then
31 else if(x86.opereq(a2, b2) orelse (x86.opereq(a1, b2) andalso x86.opereq(b1, a2))) then
34 insn1::(peephole (insn2::l))
35 | peephole ((insn as X.MOVL(a,b))::l) = if x86.opereq(a, b) then peephole l else insn::(peephole l)
36 | peephole ((insn1 as X.NEG(a))::(insn2 as X.NEG(b))::l) = if x86.opereq(a, b) then peephole l else insn1::(peephole (insn2::l))
37 | peephole (a::l) = a::(peephole l)