Skip to content
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

Fix duplicated FldSeq in block morphing #62687

Merged

Conversation

SingleAccretion
Copy link
Contributor

@SingleAccretion SingleAccretion commented Dec 12, 2021

Reusing the address for the first field is problematic as the first field is likely to be at a zero offset, thus a zero-offset field sequence will be attached to it, and subsequent copies of the same tree will pick it up, which is incorrect and can result in silent bad codegen.

Fix by reusing the address for the last field instead.

 [000015] -A-X-+------              *  COMMA     void
-[000008] -A-X--------              +--*  ASG       long
-[000006] *--X---N----              |  +--*  IND       long
-[000000] -----+------              |  |  \--*  LCL_VAR   byref  V00 arg0          Zero Fseq[FirstLngValue]
-[000007] ------------              |  \--*  LCL_VAR   long   V03 tmp1
+[000009] -A-X--------              +--*  ASG       long
+[000007] *--X---N----              |  +--*  IND       long
+[000006] -----+------              |  |  \--*  LCL_VAR   byref  V00 arg0          Zero Fseq[FirstLngValue]
+[000008] ------------              |  \--*  LCL_VAR   long   V03 tmp1
 [000014] -A-X--------              \--*  ASG       long
 [000012] *--X---N----                 +--*  IND       long
 [000011] ------------                 |  \--*  ADD       byref
-[000009] -----+------                 |     +--*  LCL_VAR   byref  V00 arg0          Zero Fseq[FirstLngValue]
+[000000] -----+------                 |     +--*  LCL_VAR   byref  V00 arg0
 [000010] ------------                 |     \--*  CNS_INT   long   8 Fseq[SecondLngValue]
 [000013] ------------                 \--*  LCL_VAR   long   V04 tmp2

Part of #58312.

Just one method with diffs: "better" sequences unblocked quite a few CSEs.

Reusing the address for the first field is problematic as
the first field is likely to be at a zero offset, thus a
zero-offset field sequence will be attached to it, and
subsequent copies of the same tree will pick it up, which
is incorrect.

Fix by reusing the address for the last field instead.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 12, 2021
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Dec 12, 2021
@ghost
Copy link

ghost commented Dec 12, 2021

Tagging subscribers to this area: @JulieLeeMSFT
See info in area-owners.md if you want to be subscribed.

Issue Details

Reusing the address for the first field is problematic as the first field is likely to be at a zero offset, thus a zero-offset field sequence will be attached to it, and subsequent copies of the same tree will pick it up, which is incorrect.

Fix by reusing the address for the last field instead.

 [000015] -A-X-+------              *  COMMA     void
-[000008] -A-X--------              +--*  ASG       long
-[000006] *--X---N----              |  +--*  IND       long
-[000000] -----+------              |  |  \--*  LCL_VAR   byref  V00 arg0          Zero Fseq[FirstLngValue]
-[000007] ------------              |  \--*  LCL_VAR   long   V03 tmp1
+[000009] -A-X--------              +--*  ASG       long
+[000007] *--X---N----              |  +--*  IND       long
+[000006] -----+------              |  |  \--*  LCL_VAR   byref  V00 arg0          Zero Fseq[FirstLngValue]
+[000008] ------------              |  \--*  LCL_VAR   long   V03 tmp1
 [000014] -A-X--------              \--*  ASG       long
 [000012] *--X---N----                 +--*  IND       long
 [000011] ------------                 |  \--*  ADD       byref
-[000009] -----+------                 |     +--*  LCL_VAR   byref  V00 arg0          Zero Fseq[FirstLngValue]
+[000000] -----+------                 |     +--*  LCL_VAR   byref  V00 arg0
 [000010] ------------                 |     \--*  CNS_INT   long   8 Fseq[SecondLngValue]
 [000013] ------------                 \--*  LCL_VAR   long   V04 tmp2

Part of #58312.

No diffs are expected.

Author: SingleAccretion
Assignees: -
Labels:

area-CodeGen-coreclr, community-contribution

Milestone: -

@SingleAccretion SingleAccretion force-pushed the Fix-Duplicated-FldSeq-In-MorphBlock branch from cdf0f98 to f48008b Compare December 12, 2021 13:11
@SingleAccretion SingleAccretion marked this pull request as ready for review December 12, 2021 16:36
@SingleAccretion
Copy link
Contributor Author

SingleAccretion commented Dec 12, 2021

Will request the Linux_musl arm job be re-run: it is a Regex test timeout on ARM32 in Debug.

@dotnet/jit-contrib

@AndyAyersMS
Copy link
Member

Will request the Linux_musl arm job be re-run

Rerunning.

{
// Use the orginal m_dstAddr tree when i == 0
// Reuse the orginal m_dstAddr tree for the last field.
Copy link
Member

Choose a reason for hiding this comment

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

Should we assert that we're not reusing an address with a zero offset field seq?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, it is legal for the address to contain a zero-offset sequence before the morphing, so I suppose asserting here would require:

  1. Getting the "base" sequence (essentially perform the reverse of what fgAddFieldSeqForZeroOffset does).
  2. After morphing, loop over all the created address trees and assert that we only added one field to the "base", and all of them are distinct.

I am not sure it is worth the amount of code required. Once #58312 is finished, we will have asserts in VN that would have caught this case.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of how we handle the zero offset case today. We've had a number of bugs in this area.

Ok by me if it is too hard to check -- just wanted to see if you had any ideas.


using System.Runtime.CompilerServices;

class FldSeqsInPromotedCpBlk
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment linking this test to the PR and/or describing the problem this test is supposed to cover?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added one, hopefully it captures the problem precisely enough.

@AndyAyersMS
Copy link
Member

Native AOT build (a newly added thing, see #62833) is failing. I'm not familiar with this yet, so can't say what's up.

It is running tests during the build step which means test failures don't get summarized the same way as for the other CI legs, so I have no idea if this failure is happening elsewhere too.

cc @MichalStrehovsky @dotnet/jit-contrib

      nativeaot/SmokeTests/BasicThreading/BasicThreading/BasicThreading.sh [FAIL]

@MichalStrehovsky
Copy link
Member

Looks like the FinalizeTest also recently failed in runtimelab: dotnet/runtimelab#1702 (comment). The failure is probably unrelated.

I've submitted #62924 to increase the reliability of the test.

{
// Use the orginal m_dstAddr tree when i == 0
// Reuse the orginal m_dstAddr tree for the last field.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of how we handle the zero offset case today. We've had a number of bugs in this area.

Ok by me if it is too hard to check -- just wanted to see if you had any ideas.

@AndyAyersMS AndyAyersMS merged commit d5f5950 into dotnet:main Dec 16, 2021
@SingleAccretion SingleAccretion deleted the Fix-Duplicated-FldSeq-In-MorphBlock branch December 17, 2021 09:28
@ghost ghost locked as resolved and limited conversation to collaborators Jan 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants