-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Reg struct copy. #32362
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
Reg struct copy. #32362
Conversation
c3556e3
to
3bc8f8e
Compare
PTAL @CarolEidt @dotnet/jit-contrib |
|
||
addr->gtFlags |= GTF_VAR_DEF; | ||
assert(!addr->IsPartialLclFld(comp)); | ||
addr->gtFlags |= GTF_DONT_CSE; |
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.
That is loweing, so nobody will read these flags, but I set them to have closer diffs.
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.
LGTM
The old code was expecting `ASG` in a form that doesn't exist anymore.
Keep `ASG(LCL_VAR struct, LCL_VAR or INIT_VALUE)` representation in morph and rationalize and change it to STORE_LCL_VAR later.
and fix format error after merge.
f3d8096
to
7788ee8
Compare
// Ensure that lclVar nodes are typed correctly. | ||
assert(!varDsc->lvNormalizeOnStore() || (targetType == genActualType(varDsc->TypeGet()))); | ||
#ifdef DEBUG | ||
var_types op1Type = op1->TypeGet(); |
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.
Merged my changes with the new assert from #32750.
{ | ||
if (clsHnd == NO_CLASS_HANDLE) | ||
// It is possible to use `initobj` to init a primitive type on the stack, |
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.
@kunalspathak thanks for your feedback, I added an example where var
is not a struct, but ASG
is.
This PR changes the way we handle struct copies.
cc8c366: First, it deletes rationalize transformation that was converting
ASG(LCL_VAR struct, smth)
intoSTORE_BLK
orSTORE_OBJ
.3bc8f8e: Then it skips
fgMorphOneAsgBlockOp
transformation forASG(LCL_VAR struct, smth)
, wherestruct
can be replaced with a primitive type.The overall diffs are positive, but small because of most of these structs are still marked as
doNotEnreg
inimpNormStructVal
, it will be fixed next.Positive diffs come from:
movups
(forSTORE_LCL_VAR
instead ofmovdqu
that is currently used forSTORE_BLK
), there was a PR https://github.com/dotnet/runtime/pull/1367/files that would usemovups
for all, but for now, it is useful for me to have different codegen for them, allows me to find diffs easily.ASG(struct, 0)
and similar constructions now, so we can coalesce chains of struct assignments now for zero-init, I will add non-zero cases later. It gives us diffs like-29 (-53.70% of base) : System.Private.CoreLib.dasm - SyncSuccessSentinelStateMachineBox[VoidTaskResult][System.Threading.Tasks.VoidTaskResult]:.ctor():this
, that will be an issue in the next PR, see the discussion here First Class Structs: stop lying about underlying type. #1231 (comment);The negative diffs come from:
STORE_BLK
contained logic is less efficient, it often doesn't markData
as contained when it is generating only one instruction;fgMorphOneAsgBlockOp
could retype structs with one gcField into primitive type copy without barriers and reporting, now we are generating costlySTORE_OBJ
, a primitive fix for it fails on a few library tests, I am checking them now.diffs for the Reg struct copies commit, x64, crossgen framework
Based on #1231 (comment).
Side note:
varTypeIsSmall
and similar functions invartype.h
should assert onTYP_STRUCT
because they don't have enough information to get a correct result, the callers should be responsible for handling that. It is a preexisting issue, but that change bumps its priority, I am working on a fix in another branch.