commit 44346e249c62f7360b086a5b678262b8b7a9483c
parent 379fb0df97a05af0de480c1a1edffd9762bfa9f4
Author: Quentin Carbonneaux <quentin.carbonneaux@yale.edu>
Date: Sun, 5 Apr 2015 16:44:06 -0400
fix code emitting for x = y op x
Diffstat:
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/lo2.ml b/lo2.ml
@@ -521,8 +521,14 @@ let codegen (p: mprog): string =
for i = 0 to Array.length is - 1 do
match is.(i) with
| { ri_res = l; ri_ins = `Bop (l1, op, l2) } ->
- if l1 <> l then
- move l l1;
+ let l2 =
+ if l1 = l then l2 else
+ if l2 = l then begin
+ move (LReg (-1)) l;
+ move l l1;
+ LReg (-1)
+ end else
+ (move l l1; l2) in
begin match op with
| Add ->
begin match l2 with
@@ -662,7 +668,7 @@ let oneshot () =
let _ =
if Array.length Sys.argv > 1 && Sys.argv.(1) = "test" then
let oc = open_out "t.o" in
- nregs := 3;
+ nregs := 2;
let s = pspill |> regalloc |> movgen |> codegen in
Elf.barebones_elf oc "f" s;
close_out oc;