-
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
Eliminate duplicate zero initializations more aggressively. #31960
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23579,10 +23579,15 @@ Statement* Compiler::fgInlinePrependStatements(InlineInfo* inlineInfo) | |
|
||
CORINFO_METHOD_INFO* InlineeMethodInfo = InlineeCompiler->info.compMethodInfo; | ||
|
||
unsigned lclCnt = InlineeMethodInfo->locals.numArgs; | ||
unsigned lclCnt = InlineeMethodInfo->locals.numArgs; | ||
bool bbInALoop = (block->bbFlags & BBF_BACKWARD_JUMP) != 0; | ||
bool bbIsReturn = block->bbJumpKind == BBJ_RETURN; | ||
|
||
// Does callee contain any zero-init local? | ||
if ((lclCnt != 0) && (InlineeMethodInfo->options & CORINFO_OPT_INIT_LOCALS) != 0) | ||
// If the callee contains zero-init locals, we need to explicitly initialize them if we are | ||
// in a loop or if the caller doesn't have compInitMem set. Otherwise we can rely on the | ||
// normal logic in the caller to insert zero-init in the prolog if necessary. | ||
if ((lclCnt != 0) && ((InlineeMethodInfo->options & CORINFO_OPT_INIT_LOCALS) != 0) && | ||
((bbInALoop && !bbIsReturn) || !info.compInitMem)) | ||
{ | ||
|
||
#ifdef DEBUG | ||
|
@@ -23596,9 +23601,20 @@ Statement* Compiler::fgInlinePrependStatements(InlineInfo* inlineInfo) | |
{ | ||
unsigned tmpNum = inlineInfo->lclTmpNum[lclNum]; | ||
|
||
// Is the local used at all? | ||
// If the local is used check whether we need to insert explicit zero initialization. | ||
if (tmpNum != BAD_VAR_NUM) | ||
{ | ||
if (!fgVarNeedsExplicitZeroInit(lvaGetDesc(tmpNum), bbInALoop, bbIsReturn)) | ||
{ | ||
#ifdef DEBUG | ||
if (verbose) | ||
{ | ||
printf("\nSkipping zero initialization of V%02u\n", tmpNum); | ||
} | ||
#endif // DEBUG | ||
continue; | ||
} | ||
|
||
var_types lclTyp = (var_types)lvaTable[tmpNum].lvType; | ||
noway_assert(lclTyp == lclVarInfo[lclNum + inlineInfo->argCnt].lclTypeInfo); | ||
|
||
|
@@ -23613,18 +23629,14 @@ Statement* Compiler::fgInlinePrependStatements(InlineInfo* inlineInfo) | |
{ | ||
CORINFO_CLASS_HANDLE structType = | ||
lclVarInfo[lclNum + inlineInfo->argCnt].lclVerTypeInfo.GetClassHandle(); | ||
|
||
if (fgStructTempNeedsExplicitZeroInit(lvaTable + tmpNum, block)) | ||
{ | ||
tree = gtNewBlkOpNode(gtNewLclvNode(tmpNum, lclTyp), // Dest | ||
gtNewIconNode(0), // Value | ||
false, // isVolatile | ||
false); // not copyBlock | ||
|
||
newStmt = gtNewStmt(tree, callILOffset); | ||
fgInsertStmtAfter(block, afterStmt, newStmt); | ||
afterStmt = newStmt; | ||
} | ||
tree = gtNewBlkOpNode(gtNewLclvNode(tmpNum, lclTyp), // Dest | ||
gtNewIconNode(0), // Value | ||
false, // isVolatile | ||
false); // not copyBlock | ||
|
||
newStmt = gtNewStmt(tree, callILOffset); | ||
fgInsertStmtAfter(block, afterStmt, newStmt); | ||
afterStmt = newStmt; | ||
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. Can you add jitdump here for the case where the local is used by we decide we don't need to zero init? 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. Sure, done. |
||
} | ||
|
||
#ifdef DEBUG | ||
|
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
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.
I don't want to hold up getting this merged - looks great BTW - but why didn't you just delete this?
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 want to go back and see if any of this needs to be resurrected. It looks like part of the unreachable code was supposed to be responsible for correctness. I'll clean this up in a subsequent 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.
Perhaps open an issue for follow up on this, so we don't forget?
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 a comment to the issue that tracks improving the heuristic: #8890 (comment)