Skip to content

Commit 8267861

Browse files
committed
refactor
1 parent 36da4e4 commit 8267861

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

compiler/lib/global_deadcode.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -483,16 +483,17 @@ let zero prog pure_funs sentinal live_table =
483483
(* Zero out return values in last instruction, otherwise do nothing. *)
484484
match block.branch with
485485
| Return x ->
486-
let tc =
487-
(* We don't want to break tailcalls. *)
486+
let live_tc =
487+
(* Don't break tailcalls, it's needed for generate_closure
488+
and effects passes. If the (tail)call is dead, it will
489+
be eliminated later by the deadcode pass, don't make it live again by
490+
returning its result. *)
488491
match List.last body with
489-
| Some (Let (x', (Apply _ as e))) when Code.Var.equal x' x ->
490-
if (not (is_live x')) && Pure_fun.pure_expr pure_funs e
491-
then false (* we don't want to stop deadcode *)
492-
else true
492+
| Some (Let (x', (Apply _ as e))) ->
493+
Code.Var.equal x x' && (is_live x' || not (Pure_fun.pure_expr pure_funs e))
493494
| Some _ | None -> false
494495
in
495-
if tc then Return x else Return (zero_var x)
496+
if live_tc then Return x else Return (zero_var x)
496497
| Raise (_, _)
497498
| Stop | Branch _
498499
| Cond (_, _, _)

0 commit comments

Comments
 (0)