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

Perf: JIT does not optimize pattern "~x + 1" #69003

Closed
GrabYourPitchforks opened this issue May 7, 2022 · 2 comments
Closed

Perf: JIT does not optimize pattern "~x + 1" #69003

GrabYourPitchforks opened this issue May 7, 2022 · 2 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI help wanted [up-for-grabs] Good issue for external contributors tenet-performance Performance related issue
Milestone

Comments

@GrabYourPitchforks
Copy link
Member

Based on a comment at #68964 (comment).

In main, current JIT compiles this method:

static uint Negate(uint value) => ~value + 1;

To this in release mode:

; Method ConsoleApp106.Program:Negate(int):int
G_M48540_IG01:
						;; size=0 bbWeight=1    PerfScore 0.00

G_M48540_IG02:
       mov      eax, ecx
       not      eax
       inc      eax
						;; size=6 bbWeight=1    PerfScore 0.75

G_M48540_IG03:
       ret      
						;; size=1 bbWeight=1    PerfScore 1.00
; Total bytes of code: 7

JIT should be taught to recognize the pattern ~x + 1 and turn it into a two's-complement neg instruction.

@GrabYourPitchforks GrabYourPitchforks added tenet-performance Performance related issue area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels May 7, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label May 7, 2022
@ghost
Copy link

ghost commented May 7, 2022

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

Issue Details

Based on a comment at #68964 (comment).

In main, current JIT compiles this method:

static uint Negate(uint value) => ~value + 1;

To this in release mode:

; Method ConsoleApp106.Program:Negate(int):int
G_M48540_IG01:
						;; size=0 bbWeight=1    PerfScore 0.00

G_M48540_IG02:
       mov      eax, ecx
       not      eax
       inc      eax
						;; size=6 bbWeight=1    PerfScore 0.75

G_M48540_IG03:
       ret      
						;; size=1 bbWeight=1    PerfScore 1.00
; Total bytes of code: 7

JIT should be taught to recognize the pattern ~x + 1 and turn it into a two's-complement neg instruction.

Author: GrabYourPitchforks
Assignees: -
Labels:

tenet-performance, area-CodeGen-coreclr

Milestone: -

@jakobbotsch jakobbotsch added the help wanted [up-for-grabs] Good issue for external contributors label May 9, 2022
@JulieLeeMSFT JulieLeeMSFT removed the untriaged New issue has not been triaged by the area owner label May 14, 2022
@JulieLeeMSFT JulieLeeMSFT added this to the Future milestone May 14, 2022
SkiFoD added a commit to SkiFoD/runtime that referenced this issue May 20, 2022
SkiFoD added a commit to SkiFoD/runtime that referenced this issue May 20, 2022
SkiFoD added a commit to SkiFoD/runtime that referenced this issue May 21, 2022
SkiFoD added a commit to SkiFoD/runtime that referenced this issue May 23, 2022
@EgorBo
Copy link
Member

EgorBo commented Jun 9, 2022

Closed via #69600

@EgorBo EgorBo closed this as completed Jun 9, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 10, 2022
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 help wanted [up-for-grabs] Good issue for external contributors tenet-performance Performance related issue
Projects
None yet
Development

No branches or pull requests

4 participants