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

Optimize Enum.GetUnderlyingType with a known type to a constant #70483

Closed
MichalPetryka opened this issue Jun 9, 2022 · 5 comments
Closed

Optimize Enum.GetUnderlyingType with a known type to a constant #70483

MichalPetryka opened this issue Jun 9, 2022 · 5 comments
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged tenet-performance Performance related issue
Milestone

Comments

@MichalPetryka
Copy link
Contributor

MichalPetryka commented Jun 9, 2022

Description

Enum.GetUnderlyingType currently always does a runtime lookup even when the type is always known, for example due to being a generic parameter. This makes fast generic specialization on enums impossible, unless you specialize on their size, which in turn makes you loose information about the sign.
Having this optimized would make #70167 much more useful since currently you have no fast way to check if the conversion is safe.

Configuration

Core CLR 6.0.322.12309 on amd64 on SharpLab

Regression?

I don't think so, but haven't checked other runtimes.

Data

SharpLab

category:cq
theme:basic-cq
skill-level:intermediate
cost:medium
impact:small

@MichalPetryka MichalPetryka added the tenet-performance Performance related issue label Jun 9, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 9, 2022
@EgorBo EgorBo added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed untriaged New issue has not been triaged by the area owner labels Jun 9, 2022
@EgorBo EgorBo added this to the Future milestone Jun 9, 2022
@ghost
Copy link

ghost commented Jun 9, 2022

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

Issue Details

Description

Enum.GetUnderlyingType currently always does a runtime lookup even when the type is always known, for example due to being a generic parameter. This makes fast generic specialization on enums impossible, unless you specialize on their size, which in turn makes you loose information about the sign.
Having this optimized would make #70167 much more useful since currently you have no fast way to check if the conversion is safe.

Configuration

Core CLR 6.0.322.12309 on amd64 on SharpLab

Regression?

I don't think so, but haven't checked other runtimes.

Data

SharpLab

Author: MichalPetryka
Assignees: -
Labels:

tenet-performance, area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member

EgorBo commented Jun 9, 2022

I wasn't able to find any cases dotnet/runtime code base could benefit from such an intrinsic, do you have any real-world examples?

@MichalPetryka
Copy link
Contributor Author

The ValueToString method in PR #71590 would be an example place to use it, on SharpLab with .Net 6 it results in terrible codegen.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 5, 2022
@MichalPetryka
Copy link
Contributor Author

Fixed by #71685.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 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 in-pr There is an active PR which will close this issue when it is merged tenet-performance Performance related issue
Projects
None yet
Development

No branches or pull requests

2 participants