From 9c852215c79ed6ec42c223463d4b5a0c221b4bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 16 Jan 2019 19:06:19 +0100 Subject: beam_ssa_type: Eliminate redundant 'succeeded' instructions The beam_ssa_type pass would leave redundant 'succeeded' instructions, and depend on the live optimization pass to remove them. Update beam_ssa_type to remove redundant 'succeeded' instructions. This will not improve the generated code, but will improve compilation times since it eliminates instructions and variables. --- lib/compiler/src/beam_ssa_type.erl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'lib/compiler/src/beam_ssa_type.erl') diff --git a/lib/compiler/src/beam_ssa_type.erl b/lib/compiler/src/beam_ssa_type.erl index ab5ea4b1a4..4ea3781783 100644 --- a/lib/compiler/src/beam_ssa_type.erl +++ b/lib/compiler/src/beam_ssa_type.erl @@ -139,6 +139,19 @@ opt_is([#b_set{op=phi,dst=Dst,args=Args0}=I0|Is], Ds = Ds0#{Dst=>I}, opt_is(Is, Ts, Ds, Ls, Sub0, [I|Acc]) end; +opt_is([#b_set{op=succeeded,args=Args0,dst=Dst}=I], + Ts0, Ds0, Ls, Sub0, Acc) -> + Args = simplify_args(Args0, Sub0, Ts0), + Type = type(succeeded, Args, Ts0, Ds0), + case get_literal_from_type(Type) of + #b_literal{}=Lit -> + Sub = Sub0#{Dst=>Lit}, + opt_is([], Ts0, Ds0, Ls, Sub, Acc); + none -> + Ts = update_types(I, Ts0, Ds0), + Ds = Ds0#{Dst=>I}, + opt_is([], Ts, Ds, Ls, Sub0, [I|Acc]) + end; opt_is([#b_set{args=Args0,dst=Dst}=I0|Is], Ts0, Ds0, Ls, Sub0, Acc) -> Args = simplify_args(Args0, Sub0, Ts0), @@ -296,8 +309,6 @@ simplify(#b_set{op=put_tuple,args=Args}=I, _Ts) -> none -> I; List -> #b_literal{val=list_to_tuple(List)} end; -simplify(#b_set{op=succeeded,args=[#b_literal{}]}, _Ts) -> - #b_literal{val=true}; simplify(#b_set{op=wait_timeout,args=[#b_literal{val=infinity}]}=I, _Ts) -> I#b_set{op=wait,args=[]}; simplify(I, _Ts) -> I. @@ -627,6 +638,8 @@ type(succeeded, [#b_var{}=Src], Ts, Ds) -> #b_set{} -> t_boolean() end; +type(succeeded, [#b_literal{}], _Ts, _Ds) -> + t_atom(true); type(_, _, _, _) -> any. arith_op_type(Args, Ts) -> -- cgit v1.2.3