Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove boxing from "value is S" for nullables#95711

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
EgorBo merged 6 commits intodotnet:mainfromEgorBo:box-isinst-nullable
Dec 7, 2023

Conversation

@EgorBo
Copy link
Member

@EgorBoEgorBo commentedDec 7, 2023
edited
Loading

Closes#95685

boolTest<T>(Tvalue)=>valueisint;// T is Nullable<int>
; Assembly listing for method Prog:Test[System.Nullable`1[int]]-      sub      rsp, 40-      mov      qword ptr [rsp+0x38], rdx-      lea      rdx, [rsp+0x38]-      mov      rcx, 0xD1FFAB1E      ; System.Nullable`1[int]-      call     CORINFO_HELP_BOX_NULLABLE-      test     rax, rax-      je       SHORT G_M33107_IG04-      mov      rcx, 0xD1FFAB1E      ; System.Int32-      xor      rdx, rdx-      cmp      qword ptr [rax], rcx-      cmovne   rax, rdx-G_M33107_IG04:-      test     rax, rax-      setne    al-      movzx    rax, al-      add      rsp, 40+      mov      qword ptr [rsp+0x10], rdx+      movzx    rax, byte  ptr [rsp+0x10]       ret-; Total bytes of code 67+; Total bytes of code 11

I recommend reviewing with "hide whitespaces" mode on the review tab. I removed some codeAddr validations and replaced those withimpGetNonPrefixOpcode that does the same.

@ghostghost added the area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labelDec 7, 2023
@ghostghost assignedEgorBoDec 7, 2023
@ghost
Copy link

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

Issue Details

Closes#95685

It turns out to be a simple fix
Example:

boolTest1<T>(Tvalue)// T is int?{returnvalueisint;}voidTest2<T>(Tvalue)// T is int?{if(valueisint)Console.WriteLine();}
; Assembly listing for method Prog:Test1[System.Nullable`1[int]]-      sub      rsp, 40-      mov      qword ptr [rsp+0x38], rdx-      lea      rdx, [rsp+0x38]-      mov      rcx, 0xD1FFAB1E      ; System.Nullable`1[int]-      call     CORINFO_HELP_BOX_NULLABLE-      test     rax, rax-      je       SHORT G_M33107_IG04-      mov      rcx, 0xD1FFAB1E      ; System.Int32-      xor      rdx, rdx-      cmp      qword ptr [rax], rcx-      cmovne   rax, rdx-G_M33107_IG04:-      test     rax, rax-      setne    al-      movzx    rax, al-      add      rsp, 40+      xor      eax, eax       ret-; Total bytes of code 67+; Total bytes of code 3; Assembly listing for method Prog:Test2[System.Nullable`1[int]]-      sub      rsp, 40-      mov      qword ptr [rsp+0x38], rdx-      cmp      byte  ptr [rsp+0x38], 0-      je       SHORT G_M14037_IG04-      call     [System.Console:WriteLine()]-G_M14037_IG04:-      nop-      add      rsp, 40       ret-; Total bytes of code 28+; Total bytes of code 1
Author:EgorBo
Assignees:-
Labels:

area-CodeGen-coreclr

Milestone:-

@EgorBo
Copy link
MemberAuthor

@MihuBot

Comment on lines +2966 to +2975
case CEE_LDNULL:
{
// "ldnull + cgt_un" is used when BOX+ISINST is not fed into a branch, e.g.:
//
// if (obj is string) { <--- box + isinst + br_true
//
// bool b = obj is string; <--- box + isinst + ldnull + cgt_un
//
// bool b = obj is not string; <--- box + isinst + ldnull + cgt_un + ldc.i4.0 + ceq
//
Copy link
Member

@huoyaoyuanhuoyaoyuanDec 7, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I did similar transform in#47920 (comment) . It's interesting to see which implementation covers more cases.

I'll push it later today.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think I tried this transformation I while back and gave up due to small diffs, decided to push it because of customer reported issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

main...huoyaoyuan:runtime:isinst-null-cmp
It doesn't help, and doesn't conflict either. Let's do separately.

Copy link
MemberAuthor

@EgorBoEgorBoDec 7, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think my change is simpler? (if you ignore whitespaces).

Also, not sure ifbox + isinst + ldnull + ceq ever shows up - Roslyn seems to not emitting it so I didn't bother

E.g.sharplab

@EgorBoEgorBo marked this pull request as ready for reviewDecember 7, 2023 09:13
@EgorBo
Copy link
MemberAuthor

PTAL @dotnet/jit-contrib,@jakobbotsch A small change (if you disable whitespaces) that closes#95685

Almost no hits in BCL (except afew tests in minopts)

@EgorBoEgorBo merged commit8383c97 intodotnet:mainDec 7, 2023
@EgorBoEgorBo deleted the box-isinst-nullable branchDecember 7, 2023 13:26
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJan 7, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@jakobbotschjakobbotschjakobbotsch approved these changes

+1 more reviewer

@huoyaoyuanhuoyaoyuanhuoyaoyuan left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

@EgorBoEgorBo

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Generic type check allocates for nullable structs

3 participants

@EgorBo@huoyaoyuan@jakobbotsch

[8]ページ先頭

©2009-2025 Movatter.jp