summaryrefslogtreecommitdiff
path: root/lib/compiler/src/beam_ssa_funs.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compiler/src/beam_ssa_funs.erl')
-rw-r--r--lib/compiler/src/beam_ssa_funs.erl18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/compiler/src/beam_ssa_funs.erl b/lib/compiler/src/beam_ssa_funs.erl
index 41a123515f..2d9bfc4db9 100644
--- a/lib/compiler/src/beam_ssa_funs.erl
+++ b/lib/compiler/src/beam_ssa_funs.erl
@@ -143,7 +143,19 @@ lfo_optimize_is([], _LFuns, _Trampolines) ->
[].
lfo_short_circuit(Call, Trampolines) ->
- case maps:find(Call, Trampolines) of
- {ok, Other} -> lfo_short_circuit(Other, Trampolines);
- error -> Call
+ lfo_short_circuit(Call, Trampolines, cerl_sets:new()).
+
+lfo_short_circuit(Call, Trampolines, Seen0) ->
+ %% Beware of infinite loops! Get out if this call has been seen before.
+ case cerl_sets:is_element(Call, Seen0) of
+ true ->
+ Call;
+ false ->
+ case Trampolines of
+ #{Call := Other} ->
+ Seen = cerl_sets:add_element(Call, Seen0),
+ lfo_short_circuit(Other, Trampolines, Seen);
+ #{} ->
+ Call
+ end
end.