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

Do some minor enhancements of the code generation in the JIT #7956

Merged
merged 12 commits into from
Dec 20, 2023

Conversation

bjorng
Copy link
Contributor

@bjorng bjorng commented Dec 14, 2023

Take better advantage of type information and known constant operands to enhance code generation. Also take advantage of the bit manipulation instructions for AArch64 to enhance code generation for the binary syntax.

@bjorng bjorng added team:VM Assigned to OTP team VM enhancement testing currently being tested, tag is used by OTP internal CI labels Dec 14, 2023
@bjorng bjorng self-assigned this Dec 14, 2023
@bjorng bjorng requested a review from jhogberg December 14, 2023 09:32
Copy link
Contributor

github-actions bot commented Dec 14, 2023

CT Test Results

       3 files     140 suites   46m 38s ⏱️
1 575 tests 1 526 ✔️ 49 💤 0
2 087 runs  2 019 ✔️ 68 💤 0

Results for commit 1e3099e.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

Leverage the bitfield manipulation instructions to optimize matching.
Consider this example:

    bm(<<X:16, Y:16, Z:16>>) ->
        {X, Y, Z}.

In OTP 26, the code for extracting the `X`, `Y`, and `Z` variables looks
like this:

    # extract integer 16
        ror x7, x7, 48
        mov x27, 15
        bfi x27, x7, 4, 16

    # extract integer 16
        ror x7, x7, 48
        mov x28, 15
        bfi x28, x7, 4, 16

    # extract integer 16
        ror x7, x7, 48
        mov x15, 15
        bfi x15, x7, 4, 16

With this commit, the code is simplified to:

    # extract integer 16
        mov x4, 15
        orr x27, x4, x7, 44

    # extract integer 16
        ubfx x9, x7, 32, 16
        orr x28, x4, x9, 4

    # extract integer 16
        ubfx x9, x7, 16, 16
        orr x15, x4, x9, 4
Consider this example:

    bb(<<X:8, Y:8, Z:8>>) ->
        <<X:16, Y:16, Z:16>>.

In OTP 26, the code for constructing the binary from the values of
`X`, `Y`, and `Z` looks like this:

    # accumulate value for integer segment
        bfxil x7, x27, 4, 16

    # accumulate value for integer segment
        lsl x7, x7, 16
        bfxil x7, x28, 4, 16

    # accumulate value for integer segment
        lsl x7, x7, 16
        bfxil x7, x15, 4, 16

    # construct integer segment from accumulator
        rev64 x7, x7
        lsr x7, x7, 16

With this commit, the code is simplifed to:

    # accumulate value for integer segment at offset 48
        bfi x7, x27, 44, 20

    # accumulate value for integer segment at offset 32
        bfi x7, x28, 28, 20

    # accumulate value for integer segment at offset 16
        bfi x7, x15, 12, 20

    # construct integer segment from accumulator
        rev64 x7, x7
Simplify the code when right-hand side operand is constant. Also
eliminate some register shuffling by using the LEA instruction.
Take better advantage of operand types.

* If one operand is known to never be an immediate term, don't emit
any test for immediate operands. (Just go ahead and call the helper
fragment.)

* Don't do any immediate test for known immediates.
* Inline equality test with lists of a single immediate element (such
as `[42]` or `[a]`). Call a specialized helper fragment for equality
test with lists of two or more immediates.

* Call a a specialized helper fragment for matching tuples containing
only immediates. Use the same helper fragment for matching bignums
and floats.

* Inline comparisons with empty binaries and empty maps.
@bjorng bjorng merged commit 4025970 into erlang:master Dec 20, 2023
17 checks passed
@bjorng bjorng deleted the bjorn/jit/optimizations branch December 20, 2023 11:21
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 testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants