aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-04-16 08:14:28 +0200
committerBjörn Gustavsson <[email protected]>2015-04-22 10:14:55 +0200
commitde9c0ab5295fb0a16b05c4df101074ce9cd6695b (patch)
treeb10c3ace7daaf59047d77fada92195c3272d6166
parent68fdf06841859afc4de3ccdc26fac7b78e8b47db (diff)
downloadotp-de9c0ab5295fb0a16b05c4df101074ce9cd6695b.tar.gz
otp-de9c0ab5295fb0a16b05c4df101074ce9cd6695b.tar.bz2
otp-de9c0ab5295fb0a16b05c4df101074ce9cd6695b.zip
beam_type: Eliminate redundant calls to checkerror_1/2
Profiling shows that the excution time for checkerror_1/2 could be be near the top even for modules without any floating point operations. It turns out that the complexity of simplify_float_1/4 is quadratic. checkerror/1 is called with the growing accumulator for each iteration. checkerror/1 will traverse the entire accumulated list *unless* some floating point operations are used. We can avoid this situation if we only call checkerror/1 when there are live floating point registers. We can also avoid calling flush/3 if there are no live floating point registers.
-rw-r--r--lib/compiler/src/beam_type.erl14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/compiler/src/beam_type.erl b/lib/compiler/src/beam_type.erl
index 26c933481a..4731b5e78e 100644
--- a/lib/compiler/src/beam_type.erl
+++ b/lib/compiler/src/beam_type.erl
@@ -149,9 +149,10 @@ simplify_basic_1([], Ts, Acc) ->
%%
simplify_float(Is0, Ts0) ->
{Is1,Ts} = simplify_float_1(Is0, Ts0, [], []),
- Is2 = flt_need_heap(Is1),
+ Is2 = opt_fmoves(Is1, []),
+ Is3 = flt_need_heap(Is2),
try
- {flt_liveness(Is2),Ts}
+ {flt_liveness(Is3),Ts}
catch
throw:not_possible -> not_possible
end.
@@ -202,14 +203,15 @@ simplify_float_1([{set,_,_,{'catch',_}}=I|Is]=Is0, _Ts, Rs0, Acc0) ->
simplify_float_1(Is, tdb_new(), Rs0, [I|Acc]);
simplify_float_1([{set,_,_,{line,_}}=I|Is], Ts, Rs, Acc) ->
simplify_float_1(Is, Ts, Rs, [I|Acc]);
+simplify_float_1([I|Is], Ts0, [], Acc) ->
+ Ts = update(I, Ts0),
+ simplify_float_1(Is, Ts, [], [I|Acc]);
simplify_float_1([I|Is]=Is0, Ts0, Rs0, Acc0) ->
Ts = update(I, Ts0),
{Rs,Acc} = flush(Rs0, Is0, Acc0),
simplify_float_1(Is, Ts, Rs, [I|checkerror(Acc)]);
-simplify_float_1([], Ts, Rs, Acc0) ->
- Acc = checkerror(Acc0),
- Is0 = reverse(flush_all(Rs, [], Acc)),
- Is = opt_fmoves(Is0, []),
+simplify_float_1([], Ts, [], Acc) ->
+ Is = reverse(Acc),
{Is,Ts}.
coerce_to_float({integer,I}=Int) ->