From 90e291e8fd42d6c9cf0695e940f34c92df1fa103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 27 Mar 2019 06:15:55 +0100 Subject: Fix unsafe optimization made by the loader Fix the unsafe load-time optimization introduced in 07bdbb3a1edc. https://bugs.erlang.org/browse/ERL-899 --- erts/emulator/beam/beam_load.c | 7 +++++++ erts/emulator/beam/ops.tab | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'erts/emulator/beam') diff --git a/erts/emulator/beam/beam_load.c b/erts/emulator/beam/beam_load.c index 21740caa2c..69e49e97f3 100644 --- a/erts/emulator/beam/beam_load.c +++ b/erts/emulator/beam/beam_load.c @@ -3145,6 +3145,13 @@ is_killed(LoaderState* stp, GenOpArg Reg, GenOpArg Live) Live.val <= Reg.val; } +static int +is_killed_by_call_fun(LoaderState* stp, GenOpArg Reg, GenOpArg Live) +{ + return Reg.type == TAG_x && Live.type == TAG_u && + Live.val+1 <= Reg.val; +} + /* * Test whether register Reg is killed by make_fun instruction that * creates the fun given by index idx. diff --git a/erts/emulator/beam/ops.tab b/erts/emulator/beam/ops.tab index 6832e65b1b..3a95b1a37e 100644 --- a/erts/emulator/beam/ops.tab +++ b/erts/emulator/beam/ops.tab @@ -338,7 +338,7 @@ swap_temp R1 R2 Tmp | line Loc | apply Live | is_killed_apply(Tmp, Live) => \ swap_temp R1 R2 Tmp | line Loc | apply_last Live D | is_killed_apply(Tmp, Live) => \ swap R1 R2 | line Loc | apply_last Live D -swap_temp R1 R2 Tmp | line Loc | call_fun Live | is_killed(Tmp, Live) => \ +swap_temp R1 R2 Tmp | line Loc | call_fun Live | is_killed_by_call_fun(Tmp, Live) => \ swap R1 R2 | line Loc | call_fun Live swap_temp R1 R2 Tmp | make_fun2 OldIndex=u | is_killed_by_make_fun(Tmp, OldIndex) => \ swap R1 R2 | make_fun2 OldIndex -- cgit v1.2.3