File 2075-Remove-redundant-optimization-of-exported-variables-.patch of Package erlang
From e762670296fa520bfd8ccf0f20981ab78d878893 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Wed, 16 Oct 2019 14:09:52 +0200
Subject: [PATCH] Remove redundant optimization of exported variables in a
'case'
b1615cb1159c introduced an optimization of a 'case' that exported
variables but whose return value was ignored.
This optimization is no longer necessary since it is done just as
well by `beam_ssa_opt`.
---
lib/compiler/src/sys_core_fold.erl | 51 +++++---------------------------------
1 file changed, 6 insertions(+), 45 deletions(-)
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl
index 63c67639d4..0d4522fd13 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -2624,32 +2624,22 @@ opt_simple_let_2(Let0, Vs0, Arg0, Body, PrevBody, Sub) ->
{[],#c_values{es=[]},_} ->
%% No variables left.
Body;
- {[#c_var{name=V}=Var|Vars]=Vars0,Arg1,Body} ->
+ {[#c_var{name=V}=Var]=Vars0,Arg1,Body} ->
case core_lib:is_var_used(V, Body) of
- false when Vars =:= [] ->
+ false ->
%% If the variable is not used in the body, we can
%% rewrite the let to a sequence:
%% let <Var> = Arg in BodyWithoutVar ==>
%% seq Arg BodyWithoutVar
Arg = maybe_suppress_warnings(Arg1, Var, PrevBody),
#c_seq{arg=Arg,body=Body};
- false ->
- %% There are multiple values returned by the argument
- %% and the first value is not used (this is a 'case'
- %% with exported variables, but the return value is
- %% ignored). We can remove the first variable and the
- %% the first value returned from the 'let' argument.
- Arg2 = remove_first_value(Arg1),
- Let1 = Let0#c_let{vars=Vars,arg=Arg2,body=Body},
- post_opt_let(Let1, Sub);
true ->
Let1 = Let0#c_let{vars=Vars0,arg=Arg1,body=Body},
post_opt_let(Let1, Sub)
end;
- {[],Arg,Body} ->
- %% The argument for a sequence must be a single value (not
- %% #c_values{}). Therefore, we must keep the let.
- post_opt_let(#c_let{vars=[],arg=Arg,body=Body}, Sub)
+ {_,_,_} ->
+ Let1 = Let0#c_let{vars=Vs0,arg=Arg0,body=Body},
+ post_opt_let(Let1, Sub)
end.
%% post_opt_let(Let, Sub)
@@ -2662,39 +2652,6 @@ post_opt_let(Let0, Sub) ->
Let1 = opt_bool_case_in_let(Let0, Sub),
opt_build_stacktrace(Let1).
-
-%% remove_first_value(Core0) -> Core.
-%% Core0 is an expression that returns at least two values.
-%% Remove the first value returned from Core0.
-
-remove_first_value(#c_values{es=[V|Vs]}) ->
- Values = core_lib:make_values(Vs),
- case is_safe_simple(V) of
- false ->
- #c_seq{arg=V,body=Values};
- true ->
- Values
- end;
-remove_first_value(#c_case{clauses=Cs0}=Core) ->
- Cs = remove_first_value_cs(Cs0),
- Core#c_case{clauses=Cs};
-remove_first_value(#c_receive{clauses=Cs0,action=Act0}=Core) ->
- Cs = remove_first_value_cs(Cs0),
- Act = remove_first_value(Act0),
- Core#c_receive{clauses=Cs,action=Act};
-remove_first_value(#c_let{body=B}=Core) ->
- Core#c_let{body=remove_first_value(B)};
-remove_first_value(#c_seq{body=B}=Core) ->
- Core#c_seq{body=remove_first_value(B)};
-remove_first_value(#c_primop{}=Core) ->
- Core;
-remove_first_value(#c_call{}=Core) ->
- Core.
-
-remove_first_value_cs(Cs) ->
- [C#c_clause{body=remove_first_value(B)} ||
- #c_clause{body=B}=C <- Cs].
-
%% maybe_suppress_warnings(Arg, #c_var{}, PreviousBody) -> Arg'
%% Try to suppress false warnings when a variable is not used.
%% For instance, we don't expect a warning for useless building in:
--
2.16.4