Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Fix consume-order checking in codegen. #8601

Merged
merged 2 commits into from
Dec 14, 2016
Merged

Conversation

pgavlin
Copy link

@pgavlin pgavlin commented Dec 12, 2016

The switch to LIR invalidated the correspondence between a node's
sequence number and the order in which it must be consumed with respect
to other nodes. This in turn made the consume-order checks during code
generation incorrect.

This change introduces a new field, gtUseNum, that is used during code
generation to check the order in which nodes are consumed. Re-enabling
these checks revealed a bug in code generation for locked instructions
on x86, which were consuming their operands out-of-order; this change
also contains a fix for that bug.

Fixes #7963.

@pgavlin
Copy link
Author

pgavlin commented Dec 12, 2016

@CarolEidt @dotnet/jit-contrib PTAL

{
assert(operand->gtUseNum == -1);
operand->gtUseNum = useNum;
useNum++;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this works, we may want to set these use numbers during LSRA's traversal of a node's operands to help ensure that the correspondence between a node's use number and the relative order in which it is visited by LSRA is correct. Thoughts?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a reasonable approach. If one were to get fancy, one could maintain the LsraLocation at which it is consumed, along with its operand index - but that would be more info than is needed here (though possibly handy for debugging purposes!)

Copy link

@CarolEidt CarolEidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pgavlin pgavlin force-pushed the gh7963 branch 2 times, most recently from b3329a4 to d589d61 Compare December 13, 2016 18:18
}

assert((node->OperGet() == GT_CATCH_ARG) || ((node->gtDebugFlags & GTF_DEBUG_NODE_CG_CONSUMED) == 0));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-enabling the checks revealed that we (always?) consume CATCH_ARG nodes twice on xarch: once in the codegen for the CATCH_ARG node itself and then once for the node that consumes the CATCH_ARG (if any). @BruceForstall @CarolEidt any idea why the processing for the CATCH_ARG node contains a call to genConsumeReg?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know - I'm not very familiar with the code for GT_CATCH_ARG but in general we shouldn't be consuming the current node in genCodeForTreeNode

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know...


In reply to: 92242247 [](ancestors = 92242247)

The switch to LIR invalidated the correspondence between a node's
sequence number and the order in which it must be consumed with respect
to other nodes. This in turn made the consume-order checks during code
generation incorrect.

This change introduces a new field, `gtUseNum`, that is used during code
generation to check the order in which nodes are consumed. Re-enabling
these checks revealed a bug in code generation for locked instructions
on x86, which were consuming their operands out-of-order; this change
also contains a fix for that bug.

Fixes #7963.
@pgavlin pgavlin merged commit b038f90 into dotnet:master Dec 14, 2016
@pgavlin pgavlin deleted the gh7963 branch December 14, 2016 19:21
@karelz karelz modified the milestone: 2.0.0 Aug 28, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Fix consume-order checking in codegen.

Commit migrated from dotnet/coreclr@b038f90
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure that codegen consumes registers in the proper order
5 participants