Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Dec 18, 2023

Closes #96046

byte Test(int a) => rva[8 - (a & 7)];

static ReadOnlySpan<byte> rva => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

Was:

; Method Program:Test(int):ubyte:this (FullOpts)
       sub      rsp, 40
       and      ecx, 7
       mov      eax, ecx
       neg      eax
       add      eax, 8
       cmp      eax, 10
       jae      SHORT G_M949_IG04
       mov      rcx, 0x1735CBE29D0
       movzx    rax, byte  ptr [rax+rcx]
       add      rsp, 40
       ret
G_M949_IG04:
       call     CORINFO_HELP_RNGCHKFAIL
       int3
; Total bytes of code 44

Now:

; Method Program:Test(int):ubyte:this (FullOpts)
       sub      rsp, 40
       and      edx, 7
       mov      eax, edx
       neg      eax
       add      eax, 8
       mov      rcx, 0x228C6572A20
       movzx    rax, byte  ptr [rax+rcx]
       add      rsp, 40
       ret      
; Total bytes of code: 33

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 18, 2023
@ghost ghost assigned EgorBo Dec 18, 2023
@ghost
Copy link

ghost commented Dec 18, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

Closes #96046

byte Test(int a) => rva[8 - (a & 7)];

static ReadOnlySpan<byte> rva => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

Was:

; Method Program:Test(int):ubyte:this (FullOpts)
       sub      rsp, 40
       and      ecx, 7
       mov      eax, ecx
       neg      eax
       add      eax, 8
       cmp      eax, 10
       jae      SHORT G_M949_IG04
       mov      rcx, 0x1735CBE29D0
       movzx    rax, byte  ptr [rax+rcx]
       add      rsp, 40
       ret
G_M949_IG04:
       call     CORINFO_HELP_RNGCHKFAIL
       int3
; Total bytes of code 44

Now:

; Method Program:Test(int):ubyte:this (FullOpts)
       sub      rsp, 40
       and      edx, 7
       mov      eax, edx
       neg      eax
       add      eax, 8
       mov      rcx, 0x228C6572A20
       movzx    rax, byte  ptr [rax+rcx]
       add      rsp, 40
       ret      
; Total bytes of code: 33
Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Dec 18, 2023

@dotnet/jit-contrib PTAL, small change, diffs aren't too big, but it closes #96046

Comment on lines 558 to 559
result.lLimit = Limit(Limit::keConstant, -range.UpperLimit().GetConstant());
result.uLimit = Limit(Limit::keConstant, -range.LowerLimit().GetConstant());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can either the existing upper or lower limit be INT_MIN, in which case -INT_MIN == INT_MIN?

Copy link
Member Author

@EgorBo EgorBo Dec 19, 2023

Choose a reason for hiding this comment

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

I wasn't able to repro such a case, but added a check just in case 👍

@EgorBo EgorBo merged commit 152463d into dotnet:main Dec 20, 2023
@EgorBo EgorBo deleted the neg-bound-checks branch December 20, 2023 12:42
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unnecessary call to CORINFO_HELP_RNGCHKFAIL with subtraction and bitwise and
2 participants