From 66280c79c6ec1478f498092a519543f7f6ade630 Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Fri, 2 Aug 2024 08:57:06 +0200 Subject: [PATCH] fixup: compiler alias analysis: Avoid redundant database changes Forgotten cases when a variable is first created and then immediately set to aliased. --- lib/compiler/src/beam_ssa_alias.erl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/compiler/src/beam_ssa_alias.erl b/lib/compiler/src/beam_ssa_alias.erl index 12eb2f513811..9d3433855f64 100644 --- a/lib/compiler/src/beam_ssa_alias.erl +++ b/lib/compiler/src/beam_ssa_alias.erl @@ -1123,29 +1123,25 @@ aa_bif(Dst, element, [#b_literal{val=Idx},Tuple], SS, _AAS) %% point in trying to provide aa_tuple_extraction/5 with type %% information. aa_tuple_extraction(Dst, Tuple, #b_literal{val=Idx-1}, #{}, SS); -aa_bif(Dst, element, [#b_literal{},Tuple], SS0, _AAS) -> +aa_bif(Dst, element, [#b_literal{},Tuple], SS, _AAS) -> %% This BIF will fail, but in order to avoid any later transforms %% making use of uniqueness, conservatively alias. - SS = beam_ssa_ss:add_var(Dst, unique, SS0), aa_set_aliased([Dst,Tuple], SS); -aa_bif(Dst, element, [#b_var{},Tuple], SS0, _AAS) -> - SS = beam_ssa_ss:add_var(Dst, unique, SS0), +aa_bif(Dst, element, [#b_var{},Tuple], SS, _AAS) -> aa_set_aliased([Dst,Tuple], SS); -aa_bif(Dst, hd, [Pair], SS0, _AAS) -> +aa_bif(Dst, hd, [Pair], SS, _AAS) -> %% The hd bif is always rewritten to a get_hd instruction when the %% argument is known to be a pair. Therefore this code is only %% reached when the type of Pair is unknown, thus there is no %% point in trying to provide aa_pair_extraction/5 with type %% information. - SS = beam_ssa_ss:add_var(Dst, unique, SS0), aa_pair_extraction(Dst, Pair, hd, SS); -aa_bif(Dst, tl, [Pair], SS0, _AAS) -> +aa_bif(Dst, tl, [Pair], SS, _AAS) -> %% The tl bif is always rewritten to a get_tl instruction when the %% argument is known to be a pair. Therefore this code is only %% reached when the type of Pair is unknown, thus there is no %% point in trying to provide aa_pair_extraction/5 with type %% information. - SS = beam_ssa_ss:add_var(Dst, unique, SS0), aa_pair_extraction(Dst, Pair, tl, SS); aa_bif(Dst, map_get, [_Key,Map], SS, AAS) -> aa_map_extraction(Dst, Map, SS, AAS);