Skip to content

Commit 1669b9d

Browse files
committed
Deadcode elimination of cyclic values
1 parent 6f5be51 commit 1669b9d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

compiler/lib/deadcode.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ and mark_reachable st pc =
9797
let block = Addr.Map.find pc st.blocks in
9898
List.iter block.body ~f:(fun i ->
9999
match i with
100+
| Let (_, Prim (Extern "caml_update_dummy", [ Pv x; Pv y ])) ->
101+
if st.live.(Var.idx x) = 0
102+
then
103+
(* We will keep this instruction only if x is live *)
104+
add_def st.defs x (Field_update y)
105+
else (
106+
mark_var st x;
107+
mark_var st y)
100108
| Let (_, e) -> if not (pure_expr st.pure_funs e) then mark_expr st e
101109
| Event _ | Assign _ -> ()
102110
| Set_field (x, _, _, y) -> (
@@ -131,6 +139,7 @@ and mark_reachable st pc =
131139

132140
let live_instr st i =
133141
match i with
142+
| Let (_, Prim (Extern "caml_update_dummy", [ Pv x; Pv _ ])) -> st.live.(Var.idx x) > 0
134143
| Let (x, e) -> st.live.(Var.idx x) > 0 || not (pure_expr st.pure_funs e)
135144
| Assign (x, _) | Set_field (x, _, _, _) -> st.live.(Var.idx x) > 0
136145
| Event _ | Offset_ref _ | Array_set _ -> true

compiler/tests-compiler/update_dummy.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ let%expect_test "deadcode elimination of cyclic values" =
1414
[%expect
1515
{|
1616
function f(param){
17-
var x = [];
18-
caml_update_dummy(x, [0, 1, x]);
1917
var y = [];
20-
caml_update_dummy(y, [0, 1, y]);
18+
runtime.caml_update_dummy(y, [0, 1, y]);
2119
return y;
2220
}
2321
//end |}]

0 commit comments

Comments
 (0)