-
Notifications
You must be signed in to change notification settings - Fork 5.2k
JIT: ARR_LENGTH(new T[CNS]) --> CNS #85496
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
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue Details3 lines-of-code change to enable int Test()
{
var a = new int[100];
return a.Length;
}Current codegen: ; Method Proga:Test():int:this
sub rsp, 40
mov rcx, 0xD1FFAB1E ; int[]
mov edx, 100
call CORINFO_HELP_NEWARR_1_VC
mov eax, dword ptr [rax+08H]
add rsp, 40
ret
; Total bytes of code: 32New codegen: ; Method Proga:Test():int:this
mov eax, 100
ret
; Total bytes of code: 6I recommend enabling "ignore whitespaces" since most of the changes are just extra { } block
|
|
@dotnet/jit-contrib PTAL, simple change (if you ignore whitespace changes). diffs |
src/coreclr/jit/valuenum.cpp
Outdated
| } | ||
| } | ||
| // Case 3: ARR_LENGTH(new T[CNS]) | ||
| else if ((funcApp.m_func == VNF_JitNewArr) && IsVNConstant(funcApp.m_args[1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also VNF_JitReadyToRunNewArr.
There is ValueNumStore::GetNewArrSize, it would be ideal to extract a part from it that deals with an already-queried VNFuncApp (e. g. as bool TryGetNewArrSize(VNFuncApp* pFunc, int* pSize)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, my first impl used GetNewArrSize but for TP reasons I inlined it here, forgot about R2R
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the impl, GetVNFunc is still here, if TP report is fine with that then I don't think I need to complicate it more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

Quick 5 lines-of-code change to enable
ARR_LENGTH(JitNewArr)constant folding in VN:Current codegen:
New codegen:
I recommend enabling "hide whitespaces" for code review since most of the changes are just extra { } block