Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Convert DIV/MOD to UDIV/UMOD using assertions - #94347

Merged
EgorBo merged 9 commits into
dotnet:mainfrom
EgorBo:use-assertions-div
Nov 6, 2023
Merged

EgorBo merged 9 commits into
dotnet:mainfrom
EgorBo:use-assertions-div

Conversation

@EgorBo

@EgorBo EgorBo commented Nov 3, 2023 •

Copy link
Copy Markdown
Member

Closes #94218

static int Test(int i)
{
    if (i < 4) return 0;
    return i / 4;
}
; Method Benchmarks:Test(int):int (FullOpts)
       cmp      ecx, 4
       jge      SHORT G_M33641_IG05
       xor      eax, eax
       ret      
G_M33641_IG05:
       mov      eax, ecx
-      sar      eax, 31
-      and      eax, 3
-      add      eax, ecx
-      sar      eax, 2
+      shr      eax, 2
       ret      
-; Total bytes of code: 22
+; Total bytes of code: 14

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

ghost commented Nov 3, 2023

Copy link
Copy Markdown

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

Issue Details

Closes #94218

Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
EgorBo marked this pull request as ready for review November 4, 2023 13:50
@EgorBo

EgorBo commented Nov 4, 2023 •

Copy link
Copy Markdown
Member Author

@AndyAyersMS @dotnet/jit-contrib PTAL, diffs are not too big, I think I saw in some places in BCL we explicitly add (uint) cast for better CQ so this PR should allow to use that hack less often. Currently, it doesn't support long because we don't create assertions for those (I'll look separately if I can cheaply enable them) as these assertions mainly focus on bound checks.

Also, I remove GTF_DIV_BY_CNS_OPT as it doesn't seem to have any value to occupy a flag.

@EgorBo
EgorBo requested a review from AndyAyersMS November 4, 2023 14:42
Comment thread src/coreclr/jit/assertionprop.cpp Resolved
Comment thread src/coreclr/jit/assertionprop.cpp Resolved
Comment thread src/coreclr/jit/assertionprop.cpp Resolved
Comment thread src/coreclr/jit/assertionprop.cpp Resolved
@EgorBo
EgorBo merged commit 6066de1 into dotnet:main Nov 6, 2023
@EgorBo

EgorBo commented Nov 6, 2023

Copy link
Copy Markdown
Member Author

Failure is #86019

@EgorBo
EgorBo deleted the use-assertions-div branch November 6, 2023 13:19
@ghost ghost locked as resolved and limited conversation to collaborators Dec 6, 2023
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.

Signed division performed even when values are provably non-negative

4 participants