Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jit: Optimize instructions based on operand types #5316

Merged

Conversation

jhogberg
Copy link
Contributor

This PR lets the JIT optimize instructions by their operand types. The current implementation settles for removing redundant tag tests and the like, but we plan to add more aggressive optimizations in the near future, such as reducing arithmetic to single machine instructions when we've determined they can't overflow.

@jhogberg jhogberg added team:VM Assigned to OTP team VM enhancement labels Oct 25, 2021
@jhogberg jhogberg added this to the OTP-25.0 milestone Oct 25, 2021
@jhogberg jhogberg self-assigned this Oct 25, 2021
Copy link
Contributor

@garazdawi garazdawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

erts/emulator/beam/beam_types.h Outdated Show resolved Hide resolved
erts/emulator/beam/jit/arm/instr_common.cpp Outdated Show resolved Hide resolved
erts/emulator/beam/jit/arm/instr_common.cpp Outdated Show resolved Hide resolved
lib/stdlib/src/gb_sets.erl Show resolved Hide resolved
@jhogberg jhogberg force-pushed the john/jit/pass-type-information-to-jit/OTP-17684 branch 4 times, most recently from 92de295 to f55528d Compare October 26, 2021 06:08
@jhogberg jhogberg added the testing currently being tested, tag is used by OTP internal CI label Oct 26, 2021
@jhogberg jhogberg force-pushed the john/jit/pass-type-information-to-jit/OTP-17684 branch 6 times, most recently from a95138a to 7f5a51c Compare October 29, 2021 02:39
@jhogberg jhogberg force-pushed the john/jit/pass-type-information-to-jit/OTP-17684 branch from 7f5a51c to a030d5d Compare October 29, 2021 02:45
@bjorng bjorng self-assigned this Nov 4, 2021
@bjorng bjorng removed the testing currently being tested, tag is used by OTP internal CI label Nov 4, 2021
jhogberg and others added 4 commits November 10, 2021 14:09
Co-authored-by: Björn Gustavsson <bjorn@erlang.org>
Co-authored-by: Björn Gustavsson <bjorn@erlang.org>
Hoisting the fun check outside these loops lets us skip error
checks on the fun calls themselves, which is very nice for
functions like foldl/3.
@bjorng bjorng force-pushed the john/jit/pass-type-information-to-jit/OTP-17684 branch from 13c2ad4 to 3346acf Compare November 10, 2021 13:10
@bjorng bjorng merged commit 3617610 into erlang:master Nov 10, 2021
@itssundeep
Copy link
Contributor

This diff breaks the following example.

-module(testcode).
-compile(warn_missing_spec).

%% API
-export([
  usec_to_time/1
]).

%% Converts Usec to erlang 3-tuple time
-spec usec_to_time(integer()) -> erlang:timestamp().
usec_to_time(Usec) ->
  Us = Usec rem 1000000,
  Sec = (Usec div 1000000) rem 1000000,
  MegaSec = (Usec div 1000000) div 1000000,
  {MegaSec, Sec, Us}.
16> testcode:usec_to_time(1530342000*1000).
{1,0,0}

Can someone please look into this. I think it is failing for larger integers.

@bjorng
Copy link
Contributor

bjorng commented Nov 17, 2021

@itssundeep Thanks, I have created an issue to make sure that we don't forget to fix the bug.

bjorng added a commit to bjorng/otp that referenced this pull request Nov 17, 2021
The type-based optimizations introduced in 3617610 (erlang#5316) could
cause `divint` and `rem` instructions to be fused when it was not
safe.

Closes erlang#5401.
bjorng added a commit to bjorng/otp that referenced this pull request Nov 18, 2021
The type-based optimizations introduced in 3617610 (erlang#5316) could
cause `int` and `rem` instructions to be fused when it was not
safe.

Closes erlang#5401.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants