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

JIT does not use BT instruction for constant mask #111554

Open
rameel opened this issue Jan 17, 2025 · 3 comments · May be fixed by #111979
Open

JIT does not use BT instruction for constant mask #111554

rameel opened this issue Jan 17, 2025 · 3 comments · May be fixed by #111979
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 in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@rameel
Copy link

rameel commented Jan 17, 2025

public static bool CheckLetterOrDigit(int uc)
{
    return (LetterOrDigitCategories & (1 << uc)) != 0;
}
L0000: mov eax, 1
L0005: shlx eax, eax, ecx
L000a: test eax, 0x11f
L000f: setne al
L0012: movzx eax, al
L0015: ret
public static bool CheckLetterOrDigit(int mask, int uc)
{
    return (mask & (1 << uc)) != 0;
}
L0000: bt ecx, edx
L0003: setb al
L0006: movzx eax, al
L0009: ret

A more complete example sharplab where

L0032: mov eax, 1
L0037: shlx eax, eax, edx
L003c: test eax, 0x11f
L0041: je short L0056

could be optimized to

L0032: mov eax, 0x11f
L0037: bt eax, edx
L003a: jae short L0056
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jan 17, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 17, 2025
Copy link
Contributor

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

@JulieLeeMSFT JulieLeeMSFT added help wanted [up-for-grabs] Good issue for external contributors and removed untriaged New issue has not been triaged by the area owner labels Jan 21, 2025
@JulieLeeMSFT JulieLeeMSFT added this to the Future milestone Jan 21, 2025
@JulieLeeMSFT
Copy link
Member

Thanks, @rameel, for filing the issue with examples.
Community contributions are welcome on this issue.

@varelen
Copy link

varelen commented Jan 29, 2025

Hey, I would like to take a look at this.

varelen added a commit to varelen/dotnet-runtime that referenced this issue Jan 29, 2025
…a left shift in a compare

This optmizes the generated code when having a pattern  like '(SomeConstant & (1 << value)) != 0' which was previously only optimized for '(variable & (1 << value)) != 0'.

Fix dotnet#111554
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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 in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
3 participants