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

Fix incorrect fusion of div and rem #7567

Merged
merged 1 commit into from Aug 18, 2023

Conversation

bjorng
Copy link
Contributor

@bjorng bjorng commented Aug 17, 2023

The JIT would generate code that calculated the remainder incorrectly for the following example:

bug(Bin) ->
    N = byte_size(Bin),
    {N rem 128, N div 128}.

Essentially, the JIT would rewrite the code like this:

bug(Bin) ->
    N = byte_size(Bin),
    Q = N bsr 7,
    {Q band 16#7f, Q}.

That is, the remainder would be calculated as (N div 128) rem 128.

Fixes #7566

The JIT would generate code that calculated the remainder incorrectly
for the following example:

    bug(Bin) ->
        N = byte_size(Bin),
        {N rem 128, N div 128}.

Essentially, the JIT would rewrite the code like this:

    bug(Bin) ->
        N = byte_size(Bin),
        Q = N bsr 7,
        {Q band 16#7f, Q}.

That is, the remainder would be calculated as `(N div 128) rem 128`.

Fixes erlang#7566
@bjorng bjorng added team:VM Assigned to OTP team VM fix testing currently being tested, tag is used by OTP internal CI labels Aug 17, 2023
@bjorng bjorng self-assigned this Aug 17, 2023
@bjorng bjorng changed the base branch from master to maint August 17, 2023 05:12
@github-actions
Copy link
Contributor

github-actions bot commented Aug 17, 2023

CT Test Results

       3 files     133 suites   53m 11s ⏱️
1 557 tests 1 503 ✔️ 54 💤 0
1 978 runs  1 905 ✔️ 73 💤 0

Results for commit 478cefa.

♻️ This comment has been updated with latest results.

@bjorng bjorng merged commit ccf8e8e into erlang:maint Aug 18, 2023
17 checks passed
@bjorng bjorng deleted the bjorn/jit/fix-rem-div/GH-7566/OTP-7566 branch August 18, 2023 10:54
fhunleth added a commit to nerves-project/nerves_system_br that referenced this pull request Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix 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.

Wrong binary data generated on Mac OS with OTP 26
1 participant