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

Inefficient codegen for certain op and comparison #11414

Closed
tannergooding opened this issue Nov 5, 2018 · 2 comments
Closed

Inefficient codegen for certain op and comparison #11414

tannergooding opened this issue Nov 5, 2018 · 2 comments
Labels
arch-x64 arch-x86 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI optimization
Milestone

Comments

@tannergooding
Copy link
Member

tannergooding commented Nov 5, 2018

As per dotnet/coreclr#20788 (comment), we are currently generating some inefficient code for certain op and comparison scenarios.

For example, on if ((xbits ^ ybits) < 0), we are currently generating:

xor      edx, eax
test     edx, edx
jge      SHORT G_M7953_IG04

When we could get rid of the test and just generate:

xor edx, eax
jns SHORT G_M7953_IG04

category:cq
theme:codegen
skill-level:intermediate
cost:small

@msftgits msftgits transferred this issue from dotnet/coreclr Jan 31, 2020
@msftgits msftgits added this to the Future milestone Jan 31, 2020
@BruceForstall BruceForstall added the JitUntriaged CLR JIT issues needing additional triage label Oct 28, 2020
@BruceForstall BruceForstall removed the JitUntriaged CLR JIT issues needing additional triage label Nov 25, 2020
@anthonycanino
Copy link
Contributor

Hi @tannergooding , I've been looking into this issue over the past few days and it looks like a lot of work has been done for this optimization since this issue was posted.

It looks like dotnet/coreclr#14027 started some logic for reusing flags during the lowering stage, at which point some of the cases had to be restricted due to the OF #9059. There was some discussion about making this work for ADD/SUB + LT/GE but it looks like it was abandoned due to low optimization opportunity #6794 (comment).

More recently, a PR #38586 added flag tracking during the codegen/emit stage, and addressed some remaining optimization cases, e.g., (x ^ y) < 0.

I think with PR 38586, we can handle cases like if (x - y) < 0, or more importantly, for (int x = v; x >= 0; x -= 2) as we can now look at whether the previous instruction set the SF, and if we are in a GT_GE/GT_LT with a SLT,/SGE and instead emit a JS/JNS instead.

Any tips on whether this optimization is worth pursing, as it is 1 or 2 of the remaining cases left (from my understanding).

@anthonycanino
Copy link
Contributor

@tannergooding can we close this issue now per the PR merge?

@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-x64 arch-x86 area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI optimization
Projects
None yet
Development

No branches or pull requests

4 participants