summaryrefslogtreecommitdiff
path: root/lib/compiler/test/beam_type_SUITE.erl
Commit message (Collapse)AuthorAgeFilesLines
* Eliminate a crash in the type optimizer passBjörn Gustavsson2019-07-301-2/+23
| | | | https://bugs.erlang.org/browse/ERL-1013
* beam_ssa_type: Fix incorrect bitstring unit determinationJohn Högberg2019-06-101-2/+12
| | | | | | The compiler would treat the "Unit" of bs_init instructions as the unit of the result instead of the required unit of the input, causing is_binary checks to be wrongly optimized away.
* Merge branch 'john/compiler/list_append_type/OTP-15841' into maint-22Erlang/OTP2019-05-291-2/+9
|\ | | | | | | | | * john/compiler/list_append_type/OTP-15841: compiler: Fix broken type for erlang:'++'/2
| * compiler: Fix broken type for erlang:'++'/2John Högberg2019-05-271-2/+9
| |
* | Fix non-terminating compilationBjörn Gustavsson2019-05-201-0/+14
|/ | | | | | | | | | | | | | The compiler would not terminate while compiling the following code: foo(<<N:32>>, Tuple, NewValue) -> _ = element(N, Tuple), setelement(N, Tuple, NewValue). The type analysis pass would attempt to construct a huge list when attempting analyse the type of `Tuple` after the call to `setelement/3`. https://bugs.erlang.org/browse/ERL-948
* Cover return type determination of lists functionsBjörn Gustavsson2019-03-251-2/+16
|
* Fix crash in beam_ssa_typeBjörn Gustavsson2019-01-281-0/+16
| | | | | | | | | | To improve compilation times, beam_ssa_type keeps track of variables that are only used once and don't keep types for those variables. As currently implemented, it turns to be unsafe. Change it to only keep track of variables that are only used in the terminator of the block they are defined in. https://bugs.erlang.org/browse/ERL-840
* Merge branch 'maint'Björn Gustavsson2019-01-161-0/+4
|\ | | | | | | | | | | | | | | * maint: beam_type: Eliminate compiler crash when arithmetic expression fails Conflicts: lib/compiler/src/beam_type.erl
| * beam_type: Eliminate compiler crash when arithmetic expression failsBjörn Gustavsson2019-01-141-0/+4
| | | | | | | | | | | | | | | | | | | | | | The compiler would crash when compiling code such as: (A / B) band 16#ff The type for the expression would be 'none', but beam_type:verified_type/1 did not handle 'none'. https://bugs.erlang.org/browse/ERL-829
* | Eliminate warnings for unused variablesBjörn Gustavsson2018-11-291-2/+2
| |
* | Cover more code in beam_ssa_typeBjörn Gustavsson2018-09-171-5/+87
| |
* | Introduce a new SSA-based intermediate formatBjörn Gustavsson2018-08-241-2/+52
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | v3_codegen is replaced by three new passes: * beam_kernel_to_ssa which translates the Kernel Erlang format to a new SSA-based intermediate format. * beam_ssa_pre_codegen which prepares the SSA-based format for code generation, including register allocation. Registers are allocated using the linear scan algorithm. * beam_ssa_codegen which generates BEAM assembly code from the SSA-based format. It easier and more effective to optimize the SSA-based format before X and Y registers have been assigned. The current optimization passes constantly have to make sure no "holes" in the X register assignments are created (that is, that no X register becomes undefined that an allocation instruction depends on). This commit also introduces the following optimizations: * Replacing of tuple matching of records with the is_tagged_tuple instruction. (Replacing beam_record.) * Sinking of get_tuple_element instructions to just before the first use of the extracted values. As well as potentially avoiding extracting tuple elements when they are not actually used on all executions paths, this optimization could also reduce the number values that will need to be stored in Y registers. (Similar to beam_reorder, but more effective.) * Live optimizations, removing the definition of a variable that is not subsequently used (provided that the operation has no side effects), as well strength reduction of binary matching by replacing the extraction of value from a binary with a skip instruction. (Used to be done by beam_block, beam_utils, and v3_codegen.) * Removal of redundant bs_restore2 instructions. (Formerly done by beam_bs.) * Type-based optimizations across branches. More effective than the old beam_type pass that only did type-based optimizations in basic blocks. * Optimization of floating point instructions. (Formerly done by beam_type.) * Optimization of receive statements to introduce recv_mark and recv_set instructions. More effective with far fewer restrictions on what instructions are allowed between creating the reference and entering the receive statement. * Common subexpression elimination. (Formerly done by beam_block.)
* Call test_lib:recompile/1 from init_per_suite/1Björn Gustavsson2018-07-061-1/+1
| | | | | | | Call test_lib:recompile/1 from init_per_suite/1 instead of from all/0. That makes it easy to find the log from the compilation in the log file for the init_per_suite/1 test case.
* beam_type: Fix unsafe optimizationBjörn Gustavsson2018-06-271-2/+30
| | | | | | | | | | | | beam_type assumed that the operand for the bs_context_to_binary instruction must be a binary. That is not correct; bs_context_to_binary accepts anything. Based on the incorrect assumption, beam_type would remove other test instructions. The bug was introduced in eee8655788d2, which was supposed to be just a refactoring commit. https://bugs.erlang.org/browse/ERL-655
* Update copyright yearHenrik Nord2018-06-181-1/+1
|
* beam_type: Refactor simplifications of instructionsBjörn Gustavsson2018-03-021-1/+24
|
* Merge branch 'maint'Björn Gustavsson2018-01-311-0/+33
|\ | | | | | | | | | | | | | | * maint: Fix incorrect type interference of integer ranges Conflicts: lib/compiler/src/beam_type.erl
| * Fix incorrect type interference of integer rangesBjörn Gustavsson2018-01-291-0/+33
| |
* | beam_type: Optimize away unnecessary test_unit instructionsBjörn Gustavsson2018-01-251-2/+40
|/ | | | | | | Optimize away unnecessary test_unit instructions that verify that binaries are byte-aligned. In a tight loop, eliminating an instruction can have a small but measurable improvement of the execution time.
* Remove unsafe is_record/test_arity optimizationsJohn Högberg2018-01-041-2/+29
| | | | | | | | | | | The type optimizations for is_record and test_arity checked whether the arity was equal to the size stored in the type information, which is incorrect since said size is the *minimum* size of the tuple (as determined by previous instructions) and not its exact size. A future patch to the 'master' branch will restore these optimizations in a safe manner.
* beam_type_SUITE: Add a test case for an already fixed bugBjörn Gustavsson2017-06-121-2/+23
| | | | https://bugs.erlang.org/browse/ERL-433
* Update copyright yearRaimo Niskanen2017-05-041-1/+1
|
* Make beam_validator track type formation for binary operationsMichal Muskala2017-04-221-2/+9
| | | | | Fixes https://bugs.erlang.org/browse/ERL-406 - a bug introduced in 0377592dc2238f561291be854d2ce859dd9a5fb1
* beam_type: Avoid an internal consistency check failureBjörn Gustavsson2017-03-131-2/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Code such as the following: -record(x, {a}). f(R, N0) -> N = N0 / 100, if element(1, R#x.a) =:= 0 -> N end. would fail to compile with the following message: m: function f/2+19: Internal consistency check failed - please report this bug. Instruction: {fmove,{fr,0},{x,1}} Error: {uninitialized_reg,{fr,0}}: This bug was introduced in 348b5e6bee2f. Basically, the beam_type pass placed the fmove instruction in the wrong place. Instructions that store to floating point registers and instructions that read from floating point registers are supposed to be in the same basic block. Fix the problem by flushing all floating points instruction before a call the pseudo-BIF is_record/3, thus making sure that the fmove instruction is placed in the correct block. Here is an annotated listing of the relevant part of the .S file (before the fix): {test_heap,{alloc,[{words,0},{floats,1}]},2}. {fconv,{x,1},{fr,0}}. {fmove,{float,100.0},{fr,1}}. fclearerror. {bif,fdiv,{f,0},[{fr,0},{fr,1}],{fr,0}}. {fcheckerror,{f,0}}. %% The instruction {fmove,{fr,0},{x,1}} should have %% been here. %% Block of instructions expanded from a call to %% the pseudo-BIF is_record/3. (Expanded in a later %% compiler pass.) {test,is_tuple,{f,3},[{x,0}]}. {test,test_arity,{f,3},[{x,0},2]}. {get_tuple_element,{x,0},0,{x,2}}. {test,is_eq_exact,{f,3},[{x,2},{atom,x}]}. {move,{atom,true},{x,2}}. {jump,{f,4}}. {label,3}. {move,{atom,false},{x,2}}. {label,4}. %% End of expansion. %% The fmove instruction that beam_validator complains %% about. {fmove,{fr,0},{x,1}}. Reported-by: Richard Carlsson
* Update copyright-yearErlang/OTP2016-12-071-1/+1
|
* beam_type: Eliminate crashBjörn Gustavsson2016-05-231-2/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The following code: simple() -> case try 0 after [] end of 0 -> college; 1 -> 0 end. would crash the compiler like this: crash reason: {case_clause, {'EXIT', {function_clause, [{beam_type,simplify_select_val_int, [{select,select_val, {x,0}, {f,7}, [{integer,1},{f,9},{integer,0},{f,8}]}, 0], [{file,"beam_type.erl"},{line,169}]}, {beam_type,simplify_basic_1,3, [{file,"beam_type.erl"},{line,155}]}, {beam_type,opt,3,[{file,"beam_type.erl"},{line,57}]}, {beam_type,function,1,[{file,"beam_type.erl"},{line,36}]}, {beam_type,'-module/2-lc$^0/1-0-',1, [{file,"beam_type.erl"},{line,30}]}, {beam_type,module,2,[{file,"beam_type.erl"},{line,30}]}, {compile,'-select_passes/2-anonymous-2-',2, [{file,"compile.erl"},{line,521}]}, {compile,'-internal_comp/4-anonymous-1-',2, [{file,"compile.erl"},{line,306}]}]}}} The root cause is that the type representation is not well-defined. Integers could be represented in three different ways: integer {integer,{1,10}} {integer,0} However, only the first two forms were handled. To avoid similar problems in the future: * Make the type representation stricter. Make sure that integers are only represented as 'integer' or {integer,{Min,Max}}. * Call verify_type/1 whenever a new type is added (not only when merging types) to ensure that only the supported types are added to the type database). (ERL-150)
* beam_type: Correct handling of setelement/3Björn Gustavsson2016-05-201-2/+9
| | | | | | | | | | | | | | | | | | We must be careful how we treat the type info for the result of: setelement(Index, Tuple, NewValue) If Tuple had type information, the result of setelement/3 (in x(0)) would be assigned the same type information. But that is not safe for: setelement(1, Tuple, NewValue) since the type for the first element will be changed. Therefore, we must take care to remove the type information for the first element of the tuple if might have been modified by setelement/3.
* beam_type: Improve optimizations by keeping track of booleansBjörn Gustavsson2015-09-281-2/+13
| | | | | | | | | There is an optimization in beam_block to simplify a select_val on a known boolean value. We can implement this optimization in a cleaner way in beam_type and it will also be applicable in more situations. (When I added the optimization to beam_type without removing the optimization from beam_block, the optimization was applied 66 times.)
* beam_type: Improve optimization by keeping track of integersBjörn Gustavsson2015-09-281-0/+87
The ASN.1 compiler often generates code similar to: f(<<0:1,...>>) -> ...; f(<<1:1,...>>) -> .... Internally that will be rewritten to (conceptually): f(<<B:1,Tail/binary>>) -> case B of 0 -> case Tail of ... end; 1 -> case Tail of ... end; _ -> error(case_clause) end. Since B comes from a bit field of one bit, we know that the only possible values are 0 and 1. Therefore the error clause can be eliminated like this: f(<<B:1,Tail/binary>>) -> case B of 0 -> case Tail of ... end; _ -> case Tail of ... end end. Similarly, we can also a deduce the range for an integer from a 'band' operation with a literal integer. While we are at it, also add a test case to improve the coverage.