-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Improvements for null check folding. #1735
Merged
Merged
Changes from all commits
Commits
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 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp | ||
index a71c325ff48..c0569355c89 100644 | ||
--- a/src/coreclr/src/jit/importer.cpp | ||
+++ b/src/coreclr/src/jit/importer.cpp | ||
@@ -15184,41 +15184,41 @@ void Compiler::impImportBlockCode(BasicBlock* block) | ||
info.compCompHnd->compareTypesForEquality(resolvedToken.hClass, clsHnd); | ||
|
||
if (compare == TypeCompareState::Must) | ||
{ | ||
JITDUMP("\nOptimizing %s (%s) -- type test will succeed\n", | ||
opcode == CEE_UNBOX ? "UNBOX" : "UNBOX.ANY", eeGetClassName(clsHnd)); | ||
|
||
// For UNBOX, null check (if necessary), and then leave the box payload byref on the stack. | ||
if (opcode == CEE_UNBOX) | ||
{ | ||
GenTree* cloneOperand; | ||
op1 = impCloneExpr(op1, &cloneOperand, NO_CLASS_HANDLE, (unsigned)CHECK_SPILL_ALL, | ||
nullptr DEBUGARG("optimized unbox clone")); | ||
|
||
GenTree* boxPayloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL); | ||
GenTree* boxPayloadAddress = | ||
gtNewOperNode(GT_ADD, TYP_BYREF, cloneOperand, boxPayloadOffset); | ||
GenTree* nullcheck = gtNewOperNode(GT_NULLCHECK, TYP_I_IMPL, op1); | ||
block->bbFlags |= BBF_HAS_NULLCHECK; | ||
optMethodFlags |= OMF_HAS_NULLCHECK; | ||
- GenTree* result = gtNewOperNode(GT_COMMA, TYP_BYREF, nullcheck, boxPayloadAddress); | ||
+ GenTree* result = gtNewOperNode(GT_COMMA, TYP_BYREF, nullcheck, boxPayloadAddress); | ||
impPushOnStack(result, tiRetVal); | ||
break; | ||
} | ||
|
||
// For UNBOX.ANY load the struct from the box payload byref (the load will nullcheck) | ||
assert(opcode == CEE_UNBOX_ANY); | ||
GenTree* boxPayloadOffset = gtNewIconNode(TARGET_POINTER_SIZE, TYP_I_IMPL); | ||
GenTree* boxPayloadAddress = gtNewOperNode(GT_ADD, TYP_BYREF, op1, boxPayloadOffset); | ||
impPushOnStack(boxPayloadAddress, tiRetVal); | ||
oper = GT_OBJ; | ||
goto OBJ; | ||
} | ||
else | ||
{ | ||
JITDUMP("\nUnable to optimize %s -- can't resolve type comparison\n", | ||
opcode == CEE_UNBOX ? "UNBOX" : "UNBOX.ANY"); | ||
} | ||
} | ||
else | ||
{ |
This file contains 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 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 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 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.
Curious how you found these missing propagation bits... did you experiment with temporarily making
optEarlyPropFor...
always return true? (if not, may be worth a try).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.
No, I just saw some null checks not getting removed in some diffs and tracked that down to the missing flags. Good idea to try with
optDoEarlyPropFor...
returning always true. Will try tomorrow.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.
I added missing
OMF_HAS_NULLCHECK
andBBF_HAS_NULLCHECK
in a couple of places but they didn't result in any new diffs. ChangingoptDoEarlyPropFor...
to always return true does result in diffs but they don't seem to be related to nullchecks. I will follow up outside of this PR.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.
Apparently it was me who was forgetting to add these....