-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Fix impGetNodeAddr flag handling for volatile, unaligned, and initclass accesses #122381
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
Open
Copilot
wants to merge
8
commits into
main
Choose a base branch
from
copilot/review-impgetnodeaddr-flags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
741dbd2
Initial plan
Copilot 98548f2
Fix impGetNodeAddr flag handling in all 5 locations
Copilot 4be7539
Address code review feedback: remove extra blank line
Copilot 270cf27
Fix recursive call and optimize flag checking
Copilot 7c2aedd
Rename allowVolatileUnaligned to allowConfiguredDerefs and check GTF_…
Copilot ca6c9f2
Fix bugs, slightly refactor
jakobbotsch 0595a5d
Apply suggestion from @jakobbotsch
jakobbotsch 3391737
Apply suggestions from code review
jakobbotsch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -805,13 +805,14 @@ GenTree* Compiler::impStoreStruct(GenTree* store, | |||||||||||||||||||||||||
| WellKnownArg wellKnownArgType = | ||||||||||||||||||||||||||
| srcCall->ShouldHaveRetBufArg() ? WellKnownArg::RetBuffer : WellKnownArg::None; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // TODO-Bug?: verify if flags matter here | ||||||||||||||||||||||||||
| // Return buffers cannot have volatile, unaligned, or initclass flags | ||||||||||||||||||||||||||
| GenTreeFlags indirFlags = GTF_EMPTY; | ||||||||||||||||||||||||||
| GenTree* destAddr = impGetNodeAddr(store, CHECK_SPILL_ALL, &indirFlags); | ||||||||||||||||||||||||||
| GenTree* destAddr = impGetNodeAddr(store, CHECK_SPILL_ALL, GTF_IND_MUST_PRESERVE_FLAGS, &indirFlags); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (!impIsLegalRetBuf(destAddr, srcCall)) | ||||||||||||||||||||||||||
| if (((indirFlags & GTF_IND_MUST_PRESERVE_FLAGS) != GTF_EMPTY) || !impIsLegalRetBuf(destAddr, srcCall)) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| unsigned tmp = lvaGrabTemp(false DEBUGARG("stack copy for value returned via return buffer")); | ||||||||||||||||||||||||||
| unsigned tmp = lvaGrabTemp(false DEBUGARG( | ||||||||||||||||||||||||||
| printfAlloc("stack copy for value returned via return buffer"))); | ||||||||||||||||||||||||||
| lvaSetStruct(tmp, srcCall->gtRetClsHnd, false); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| GenTree* spilledCall = gtNewStoreLclVarNode(tmp, srcCall); | ||||||||||||||||||||||||||
|
|
@@ -929,13 +930,14 @@ GenTree* Compiler::impStoreStruct(GenTree* store, | |||||||||||||||||||||||||
| if (call->ShouldHaveRetBufArg()) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| // insert the return value buffer into the argument list as first byref parameter after 'this' | ||||||||||||||||||||||||||
| // TODO-Bug?: verify if flags matter here | ||||||||||||||||||||||||||
| // Return buffers cannot have volatile, unaligned, or initclass flags | ||||||||||||||||||||||||||
| GenTreeFlags indirFlags = GTF_EMPTY; | ||||||||||||||||||||||||||
| GenTree* destAddr = impGetNodeAddr(store, CHECK_SPILL_ALL, &indirFlags); | ||||||||||||||||||||||||||
| GenTree* destAddr = impGetNodeAddr(store, CHECK_SPILL_ALL, GTF_IND_MUST_PRESERVE_FLAGS, &indirFlags); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (!impIsLegalRetBuf(destAddr, call)) | ||||||||||||||||||||||||||
| if (((indirFlags & GTF_IND_MUST_PRESERVE_FLAGS) != GTF_EMPTY) || !impIsLegalRetBuf(destAddr, call)) | ||||||||||||||||||||||||||
|
Comment on lines
+933
to
+937
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| unsigned tmp = lvaGrabTemp(false DEBUGARG("stack copy for value returned via return buffer")); | ||||||||||||||||||||||||||
| unsigned tmp = lvaGrabTemp(false DEBUGARG( | ||||||||||||||||||||||||||
| printfAlloc("stack copy for value returned via return buffer"))); | ||||||||||||||||||||||||||
| lvaSetStruct(tmp, call->gtRetClsHnd, false); | ||||||||||||||||||||||||||
| destAddr = gtNewLclVarAddrNode(tmp, TYP_I_IMPL); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -1096,35 +1098,38 @@ GenTree* Compiler::impStoreStructPtr(GenTree* destAddr, GenTree* value, unsigned | |||||||||||||||||||||||||
| // impGetNodeAddr: Get the address of a value. | ||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||
| // Arguments: | ||||||||||||||||||||||||||
| // val - The value in question | ||||||||||||||||||||||||||
| // curLevel - Stack level for spilling | ||||||||||||||||||||||||||
| // pDerefFlags - Flags to be used on dereference, nullptr when | ||||||||||||||||||||||||||
| // the address won't be dereferenced. Returned flags | ||||||||||||||||||||||||||
| // are included in the GTF_IND_COPYABLE_FLAGS mask. | ||||||||||||||||||||||||||
| // val - The value in question | ||||||||||||||||||||||||||
| // curLevel - Stack level for spilling | ||||||||||||||||||||||||||
| // allowedMustPreserveIndirFlags - If 'val' is an indirection and it has any must-preserve indir flags (like | ||||||||||||||||||||||||||
| // volatile), then those flags must be included in this mask to be allowed | ||||||||||||||||||||||||||
| // through without creating a temp. | ||||||||||||||||||||||||||
| // pIndirFlags - [out] Flags that indirs created based on this address can and should set. | ||||||||||||||||||||||||||
| // Returned flags are included in the GTF_IND_COPYABLE_FLAGS mask. | ||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||
| // Return Value: | ||||||||||||||||||||||||||
| // In case "val" represents a location (is an indirection/local), | ||||||||||||||||||||||||||
| // will return its address. Otherwise, address of a temporary assigned | ||||||||||||||||||||||||||
| // the value of "val" will be returned. | ||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||
| GenTree* Compiler::impGetNodeAddr(GenTree* val, unsigned curLevel, GenTreeFlags* pDerefFlags) | ||||||||||||||||||||||||||
| GenTree* Compiler::impGetNodeAddr(GenTree* val, | ||||||||||||||||||||||||||
| unsigned curLevel, | ||||||||||||||||||||||||||
| GenTreeFlags allowedMustPreserveIndirFlags, | ||||||||||||||||||||||||||
| GenTreeFlags* pIndirFlags) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| if (pDerefFlags != nullptr) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| *pDerefFlags = GTF_EMPTY; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| *pIndirFlags = GTF_EMPTY; | ||||||||||||||||||||||||||
| switch (val->OperGet()) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| case GT_BLK: | ||||||||||||||||||||||||||
| case GT_IND: | ||||||||||||||||||||||||||
| case GT_STOREIND: | ||||||||||||||||||||||||||
| case GT_STORE_BLK: | ||||||||||||||||||||||||||
| if (pDerefFlags != nullptr) | ||||||||||||||||||||||||||
| if (((val->gtFlags & GTF_IND_MUST_PRESERVE_FLAGS & ~allowedMustPreserveIndirFlags) != 0)) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| *pDerefFlags = val->gtFlags & GTF_IND_COPYABLE_FLAGS; | ||||||||||||||||||||||||||
| return val->AsIndir()->Addr(); | ||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| *pIndirFlags = val->gtFlags & GTF_IND_COPYABLE_FLAGS; | ||||||||||||||||||||||||||
| return val->AsIndir()->Addr(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| case GT_LCL_VAR: | ||||||||||||||||||||||||||
| case GT_STORE_LCL_VAR: | ||||||||||||||||||||||||||
|
|
@@ -1138,12 +1143,13 @@ GenTree* Compiler::impGetNodeAddr(GenTree* val, unsigned curLevel, GenTreeFlags* | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| case GT_COMMA: | ||||||||||||||||||||||||||
| impAppendTree(val->AsOp()->gtGetOp1(), curLevel, impCurStmtDI); | ||||||||||||||||||||||||||
| return impGetNodeAddr(val->AsOp()->gtGetOp2(), curLevel, pDerefFlags); | ||||||||||||||||||||||||||
| return impGetNodeAddr(val->AsOp()->gtGetOp2(), curLevel, allowedMustPreserveIndirFlags, pIndirFlags); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| assert(!val->OperIsStore()); | ||||||||||||||||||||||||||
| unsigned lclNum = lvaGrabTemp(true DEBUGARG("location for address-of(RValue)")); | ||||||||||||||||||||||||||
| impStoreToTemp(lclNum, val, curLevel); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -3290,12 +3296,13 @@ int Compiler::impBoxPatternMatch(CORINFO_RESOLVED_TOKEN* pResolvedToken, | |||||||||||||||||||||||||
| GenTree* objToBox = impPopStack().val; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Spill struct to get its address (to access hasValue field) | ||||||||||||||||||||||||||
| // TODO-Bug?: verify if flags matter here | ||||||||||||||||||||||||||
| // Transfer any volatile/unaligned flags to the indirection | ||||||||||||||||||||||||||
| GenTreeFlags indirFlags = GTF_EMPTY; | ||||||||||||||||||||||||||
| objToBox = impGetNodeAddr(objToBox, CHECK_SPILL_ALL, &indirFlags); | ||||||||||||||||||||||||||
| objToBox = | ||||||||||||||||||||||||||
| impGetNodeAddr(objToBox, CHECK_SPILL_ALL, GTF_IND_MUST_PRESERVE_FLAGS, &indirFlags); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| static_assert(OFFSETOF__CORINFO_NullableOfT__hasValue == 0); | ||||||||||||||||||||||||||
| impPushOnStack(gtNewIndir(TYP_UBYTE, objToBox), typeInfo(TYP_INT)); | ||||||||||||||||||||||||||
| impPushOnStack(gtNewIndir(TYP_UBYTE, objToBox, indirFlags), typeInfo(TYP_INT)); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| JITDUMP("\n Importing BOX; ISINST; BR_TRUE/FALSE as nullableVT.hasValue\n"); | ||||||||||||||||||||||||||
| return returnToken; | ||||||||||||||||||||||||||
|
|
@@ -3675,9 +3682,10 @@ void Compiler::impImportAndPushBox(CORINFO_RESOLVED_TOKEN* pResolvedToken) | |||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // TODO-Bug?: verify if flags matter here | ||||||||||||||||||||||||||
| // Boxing helpers allow the "initclass" indir flag, but not volatile/unaligned flags | ||||||||||||||||||||||||||
| GenTreeFlags indirFlags = GTF_EMPTY; | ||||||||||||||||||||||||||
| op1 = gtNewHelperCallNode(boxHelper, TYP_REF, op2, impGetNodeAddr(exprToBox, CHECK_SPILL_ALL, &indirFlags)); | ||||||||||||||||||||||||||
| op1 = gtNewHelperCallNode(boxHelper, TYP_REF, op2, | ||||||||||||||||||||||||||
| impGetNodeAddr(exprToBox, CHECK_SPILL_ALL, GTF_IND_INITCLASS, &indirFlags)); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /* Push the result back on the stack, */ | ||||||||||||||||||||||||||
|
|
@@ -8526,7 +8534,8 @@ void Compiler::impImportBlockCode(BasicBlock* block) | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| op1 = impGetNodeAddr(op1, CHECK_SPILL_ALL, nullptr); | ||||||||||||||||||||||||||
| GenTreeFlags indirFlags; | ||||||||||||||||||||||||||
| op1 = impGetNodeAddr(op1, CHECK_SPILL_ALL, GTF_EMPTY, &indirFlags); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| JITDUMP("\n ... optimized to ...\n"); | ||||||||||||||||||||||||||
|
|
@@ -9537,9 +9546,12 @@ void Compiler::impImportBlockCode(BasicBlock* block) | |||||||||||||||||||||||||
| BADCODE3("Unexpected opcode (has to be LDFLD)", ": %02X", (int)opcode); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // TODO-Bug?: verify if flags matter here | ||||||||||||||||||||||||||
| GenTreeFlags indirFlags = GTF_EMPTY; | ||||||||||||||||||||||||||
| obj = impGetNodeAddr(obj, CHECK_SPILL_ALL, &indirFlags); | ||||||||||||||||||||||||||
| // Get the address and any flags from the original access (volatile, unaligned, etc.) | ||||||||||||||||||||||||||
| GenTreeFlags objAddrFlags = GTF_EMPTY; | ||||||||||||||||||||||||||
| obj = impGetNodeAddr(obj, CHECK_SPILL_ALL, GTF_IND_MUST_PRESERVE_FLAGS, &objAddrFlags); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Combine the flags from the object address with any prefix flags | ||||||||||||||||||||||||||
| indirFlags |= objAddrFlags; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| op1 = gtNewFieldAddrNode(resolvedToken.hField, obj, fieldInfo.offset); | ||||||||||||||||||||||||||
|
|
@@ -10349,7 +10361,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Get the address of the refany | ||||||||||||||||||||||||||
| GenTreeFlags indirFlags = GTF_EMPTY; | ||||||||||||||||||||||||||
| op1 = impGetNodeAddr(op1, CHECK_SPILL_ALL, &indirFlags); | ||||||||||||||||||||||||||
| op1 = impGetNodeAddr(op1, CHECK_SPILL_ALL, GTF_IND_MUST_PRESERVE_FLAGS, &indirFlags); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Fetch the type from the correct slot | ||||||||||||||||||||||||||
| op1 = gtNewOperNode(GT_ADD, TYP_BYREF, op1, | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.