aboutsummaryrefslogtreecommitdiffstats
path: root/lib
AgeCommit message (Collapse)Author
2018-01-24Apply common subexpression elimination in blocksBjörn Gustavsson
Eliminate repeated evaluation of guard BIFs and building of cons cells in blocks. This optimization is applicable in more places than might be expected, because code generation for binaries and record can generate common sub expressions not visible in the original source code. For example, consider this function: make_binary(Term) -> Bin = term_to_binary(Term), Size = byte_size(Bin), <<Size:32,Bin/binary>>. The compiler inserts a call to byte_size/2 to calculate the size of the binary being built: {function, make_binary, 1, 2}. {label,1}. {line,...}. {func_info,{atom,t},{atom,make_binary},1}. {label,2}. {allocate,0,1}. {line,...}. {call_ext,1,{extfunc,erlang,term_to_binary,1}}. {line,...}. {gc_bif,byte_size,{f,0},1,[{x,0}],{x,1}}. %Present in original code. {line,...}. {gc_bif,byte_size,{f,0},2,[{x,0}],{x,2}}. %Inserted by compiler. {bs_add,{f,0},[{x,2},{integer,4},1],{x,2}}. {bs_init2,{f,0},{x,2},0,2,{field_flags,[]},{x,2}}. {bs_put_integer,{f,0},{integer,32},1,{field_flags,[unsigned,big]},{x,1}}. {bs_put_binary,{f,0},{atom,all},8,{field_flags,[unsigned,big]},{x,0}}. {move,{x,2},{x,0}}. {deallocate,0}. return. Common sub expression elimination (CSE) eliminates the second call to byte_size/2: {function, make_binary, 1, 2}. {label,1}. {line,...}. {func_info,{atom,t},{atom,make_binary},1}. {label,2}. {allocate,0,1}. {line,...}. {call_ext,1,{extfunc,erlang,term_to_binary,1}}. {line,...}. {gc_bif,byte_size,{f,0},1,[{x,0}],{x,1}}. {move,{x,1},{x,2}}. {bs_add,{f,0},[{x,2},{integer,4},1],{x,2}}. {bs_init2,{f,0},{x,2},0,2,{field_flags,[]},{x,2}}. {bs_put_integer,{f,0},{integer,32},1,{field_flags,[unsigned,big]},{x,1}}. {bs_put_binary,{f,0},{atom,all},8,{field_flags,[unsigned,big]},{x,0}}. {move,{x,2},{x,0}}. {deallocate,0}. return. Note: A possible future optimization would be to include binary construction instructions in blocks. If that is done, the {move,{x,1},{x,2}} instruction could also be eliminated.
2018-01-24Correct bug in beam_block:opt/2Björn Gustavsson
The folling sequence in a block: {move,{x,1},{x,2}}. {move,{x,2},{x,2}}. would be incorrectly rewritten to: {move,{x,2},{x,2}}. (Which in turn would be optimized away a little bit later.)
2018-01-24Correct unsafe optimizations in beam_blockBjörn Gustavsson
When attempting to eliminate the move/2 instruction in the following code: {bif,self,{f,0},[],{x,0}}. {move,{x,0},{x,1}}. . . . {put_tuple,2,{x,1}}. {put,{atom,ok}}. {put,{x,0}}. beam_block would produce the following unsafe code: {bif,self,{f,0},[],{x,1}}. . . . {put_tuple,2,{x,1}}. {put,{atom,ok}}. {put,{x,1}}. It is unsafe because the tuple is self-referential. The following code: {put_list,{y,6},nil,{x,4}}. {move,{x,4},{x,5}}. {put_list,{y,1},{x,5},{x,5}}. . . . {put_tuple,2,{x,6}}. {put,{x,4}}. {put,{x,5}}. would be incorrectly transformed to: {put_list,{y,6},nil,{x,5}}. {put_list,{y,1},{x,5},{x,5}}. . . . {put_tuple,2,{x,6}}. {put,{x,5}}. {put,{x,5}}. (Both elements in the built tuple get the same value.)
2018-01-23beam_validator: Validate building of tuplesBjörn Gustavsson
Make sure that there is the correct number of put/1 instructions following put_tuple/2. Also make it illegal to reference the register for the tuple being built in a put/1 instruction. That is, beam_validator will now issue a diagnostice for the the following code: {put_tuple,1,{x,0}}. {put,{x,0}}.
2018-01-19Merge branch 'maint'Hans Bolinder
* maint: dialyzer: Fix bsl/2 bug
2018-01-19Merge branch 'hasse/dialyzer/fix_bsl' into maintHans Bolinder
* hasse/dialyzer/fix_bsl: dialyzer: Fix bsl/2 bug
2018-01-19Merge pull request #1687 from bjorng/bjorn/compiler/generalize-bsm/OTP-14774Björn Gustavsson
sys_core_bsm: Rearrange arguments to enable delayed sub binary creation
2018-01-17Merge pull request #1675 from sander/patch-1Ingela Andin
Fix typo in PKCS-7.asn1 OTP-14878
2018-01-17Merge branch 'maint'Hans Bolinder
* maint: stdlib: Garbage the shell's evaluator process more often
2018-01-17Merge branch 'hasse/stdlib/fix_shell_evaluator' into maintHans Bolinder
* hasse/stdlib/fix_shell_evaluator: stdlib: Garbage the shell's evaluator process more often
2018-01-17Merge branch 'maint'Björn Gustavsson
* maint: asn1_SUITE: Fix failure in xref_export_all/1
2018-01-17asn1_SUITE: Fix failure in xref_export_all/1Björn Gustavsson
The variable 'S' was used twice. If the test case failed because there were unused functions in asn1_SUITE, there would be an ugly badmatch exception instead of the intended nice error message.
2018-01-16stdlib: Garbage the shell's evaluator process more oftenHans Bolinder
A minor fix. If the Erlang shell saves no results (history(0) or results(0)), the evaluator process now garbage collects itself. This means that any huge binaries created by the evaluation are reclaimed faster than before.
2018-01-16sys_core_bsm: Rearrange arguments to enable delayed sub binary creationBjörn Gustavsson
Argument order can prevent the delayed sub binary creation. Here is an example directly from the Efficiency Guide: non_opt_eq([H|T1], <<H,T2/binary>>) -> non_opt_eq(T1, T2); non_opt_eq([_|_], <<_,_/binary>>) -> false; non_opt_eq([], <<>>) -> true. When compiling with the bin_opt_info option, there will be a suggestion to change the argument order. It turns out sys_core_bsm can itself change the order, not the order of the arguments of themselves, but the order in which the arguments are matched. Here is how it can be rewritten in pseudo Core Erlang code: non_opt_eq(Arg1, Arg2) -> case < Arg2,Arg1 > of < <<H1,T2/binary>>, [H2|T1] > when H1 =:= H2 -> non_opt_eq(T1, T2); < <<_,T2/binary>ffff>, [_|T1] > -> false; < <<>>, [] >> -> true end. When rewritten like this, the bs_start_match2 instruction will be the first instruction in the function and it will be possible to store the match context in the same register as the binary ({x,1} in this case) and to delay the creation of sub binaries. The switching of matching order also enables many other simplifications in sys_core_bsm, since there is no longer any need to pass the position of the pattern as an argument. We will update the Efficiency Guide in a separate branch before the release of OTP 21.
2018-01-16Merge branch 'ingela/ssl/remove-rsa-keyexchange-from-default/OTP-14769'Ingela Anderton Andin
* ingela/ssl/remove-rsa-keyexchange-from-default/OTP-14769: ssl: RSA key exchange is considered broken do not support by default
2018-01-16ssl: RSA key exchange is considered broken do not support by defaultIngela Anderton Andin
2018-01-16Merge branch 'hasse/stdlib/limit_gen_bench'Hans Bolinder
* hasse/stdlib/limit_gen_bench: stdlib: Spend less time in gen_server benchmarks
2018-01-16Merge branch 'maint'Hans Bolinder
* maint: stdlib: Handle Unicode when formatting stacktraces
2018-01-16Merge branch 'hasse/stdlib/unicode_stacktrace/OTP-14847/ERL-553' into maintHans Bolinder
* hasse/stdlib/unicode_stacktrace/OTP-14847/ERL-553: stdlib: Handle Unicode when formatting stacktraces
2018-01-15Merge branch 'maint'Sverker Eriksson
2018-01-15Merge branch 'sverker/cuddle-big-bin-tests' into maintSverker Eriksson
2018-01-15Merge branch 'sverker/ic-test-cuddle' into maintSverker Eriksson
2018-01-15Merge branch 'bjorn/compiler/cuddle-with-tests'Björn Gustavsson
* bjorn/compiler/cuddle-with-tests: beam_match_SUITE: Eliminate warnings for unused variables bs_match_SUITE: Add tests case written when walking into a dead end
2018-01-15Merge branch 'maint'Hans Bolinder
* maint: stdlib: Correct a filelib test case stdlib: Let filelib:find_source() search subdirs
2018-01-15Merge branch 'hasse/stdlib/find_src/OTP-14832/ERL-527' into maintHans Bolinder
* hasse/stdlib/find_src/OTP-14832/ERL-527: stdlib: Correct a filelib test case stdlib: Let filelib:find_source() search subdirs
2018-01-15stdlib: Spend less time in gen_server benchmarksHans Bolinder
Limit the time used for the benchmarks introduced in b8f16f0.
2018-01-15Merge branch 'maint'Ingela Anderton Andin
* maint: ssl: Call clean version function
2018-01-15Merge branch 'ingela/ssl/test-cuddle' into maintIngela Anderton Andin
* ingela/ssl/test-cuddle: ssl: Call clean version function
2018-01-15ssl: Call clean version functionIngela Anderton Andin
Make sure tests are run with intended version settings.
2018-01-15stdlib: Handle Unicode when formatting stacktracesHans Bolinder
See also ERL-553 and ERL-544 (commit c3ddb0f).
2018-01-15Merge branch 'maint'John Högberg
2018-01-15Merge branch ↵John Högberg
'john/runtime_tools/reduce-sysinfo-to_file-memory-use/OTP-14816' into maint
2018-01-12Merge branch 'maint'Hans Nilsson
* maint: crypto: Disable RSA sslv23 padding for LibreSSL >= 2.6.1
2018-01-12Merge branch 'maint'Siri Hansen
Conflicts: lib/observer/src/crashdump_viewer.erl
2018-01-12crypto: Disable RSA sslv23 padding for LibreSSL >= 2.6.1Hans Nilsson
Not supported in newer LibreSSL.
2018-01-12dialyzer: Fix bsl/2 bugHans Bolinder
Also modified erl_bif_types:infinity_bsl() when called with zero as first argument. As of writing this, erlang:'bsl'/2 is modified on the master branch to never fail if called with a huge second argument.
2018-01-12beam_match_SUITE: Eliminate warnings for unused variablesBjörn Gustavsson
2018-01-12bs_match_SUITE: Add tests case written when walking into a dead endBjörn Gustavsson
Add some tests cases written when attempting some new optimizations that turned out to be unsafe.
2018-01-12Merge branch 'siri/cdv/many-links/OTP-14725' into maintSiri Hansen
* siri/cdv/many-links/OTP-14725: [observer] Improve performance for many links or monitors
2018-01-12Merge pull request #1645 from Zorbash/document-inet-iRaimo Niskanen
OTP:13713: Add documentation and typespecs for inet:i/0
2018-01-12Merge pull request #1680 from bjorng/bjorn/compiler/beam_blockBjörn Gustavsson
Run beam_block a second time
2018-01-12Merge pull request #1679 from bjorng/bjorn/compiler/sys_core_foldBjörn Gustavsson
Clean up and improve sys_core_fold optimizations
2018-01-12Merge pull request #1663 from bjorng/bjorn/compiler/refactor-annotationsBjörn Gustavsson
Refactor '%live' and '%def' annotations
2018-01-12Merge branch 'maint'Ingela Anderton Andin
2018-01-11ssl: Correct function for listing RC4 suitesIngela Anderton Andin
2018-01-11Run beam_block again after other optimizations have been runBjörn Gustavsson
Running beam_block again after the other optimizations have run will give it more opportunities for optimizations. In particular, more allocate_zero/2 instructions can be turned into allocate/2 instructions, and more get_tuple_element/3 instructions can store the retrieved value into the correct register at once. Out of a sample of about 700 modules in OTP, 64 modules were improved by this commit.
2018-01-11beam_bsm: Insert introduced 'move' instructions into blockBjörn Gustavsson
If possible, when adding move/2 instructions, try to insert them into a block. That could potentially allow them to be optimized.
2018-01-11Prepare beam_utils to run again after beam_splitBjörn Gustavsson
beam_utils:live_opt/1 is currently only run early (from beam_block). Prepare it to be run after beam_split when instructions with failure labels have been taken out of blocks. While we are it, also improve check_liveness/3. That will improve the optimizations in beam_record (replacing tuple matching instructions with an is_tagged_tuple instruction).
2018-01-11beam_utils: Correct handling of liveness for select_valBjörn Gustavsson
Since the select_val instruction never transfer directly to the next instruction, the incoming live registers should be ignored. This bug have not caused any problems yet, but it will in the future if we are to run the liveness optimizations again after the optimizations in beam_dead and beam_jump.
2018-01-11beam_block: Reorder element/2 calls in guardsBjörn Gustavsson
In a guard, reorder two consecutive calls to the element/2 BIF that access the same tuple and have the same failure label so that highest index is fetched first. That will allow the second element/2 to be replace with the slightly cheaper get_tuple_element/3 instruction.