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

Move GetMethodTable and IsReference to JIT #88860

Closed

Conversation

MichalPetryka
Copy link
Contributor

Moves the simple and most important RuntimeHelpers intrinsics to the JIT.

Extracted from #88543.

@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 Jul 13, 2023
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 13, 2023
@ghost
Copy link

ghost commented Jul 13, 2023

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

Issue Details

Moves the simple and most important RuntimeHelpers intrinsics to the JIT.

Extracted from #88543.

Author: MichalPetryka
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@MichalPetryka
Copy link
Contributor Author

@MihuBot

@@ -4699,6 +4699,17 @@ GenTree* Compiler::optAssertionProp_Update(GenTree* newTree, GenTree* tree, Stat
if (parent != nullptr)
{
parent->ReplaceOperand(useEdge, newTree);
if ((parent->gtOper == GT_IND) && newTree->IsIconHandle())
Copy link
Member

Choose a reason for hiding this comment

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

What has changed that requires modifying assertion prop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

VN can fold the method table indir to a constant handle which this place then replaces indirs on such method table with. This causes an assert in fgdiagnostic to fire complaining about the indir missing the invariant and nonfaulting flags.

Copy link
Member

Choose a reason for hiding this comment

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

But why couldn't this also happen without your changes? Is VN able to recognize something in your expansions but not the inlined IL intrinsics?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, so basically we had IND(IND(knownObj)) and the inner IND(knonwObj) was folded by assertprop (with help of VN) to a CLASS_HANDLE so now we have IND(CLASS_HANDLE) but without proper flags (it's not really a correctness issue, more like annoying requirement from the fgdiagnostic)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is VN able to recognize something in your expansions but not the inlined IL intrinsics?

I'd assume it's not able to recognize the field address + subtract magic there.

But why couldn't this also happen without your changes?

I think this should reproduce with any indir over the method table returned from gtNewMethodTableLookup, seems like nothing does that today though.

@jkotas
Copy link
Member

jkotas commented Jul 14, 2023

crossgen crashing during the build with:

  /__w/1/s/src/coreclr/jit/fgdiagnostic.cpp:3290
  Assertion failed '!"Missing flags on tree"' in 'Interop+Sys:.cctor()' during 'Insert GC Polls' (IL size 27; hash 0xb6a186f0; FullOpts)

Comment on lines 4701 to +4702
parent->ReplaceOperand(useEdge, newTree);
parent->gtFlags |= gtGetFlagsForOperand(parent->gtOper, newTree);
Copy link
Contributor

Choose a reason for hiding this comment

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

This flag updating call should be moved to this place in morph:

if (op1->IsIconHandle(GTF_ICON_OBJ_HDL))
{
tree->gtFlags |= (GTF_IND_INVARIANT | GTF_IND_NONFAULTING | GTF_IND_NONNULL);
}

Comment on lines +4903 to +4914
GenTreeFlags flags = GTF_EMPTY;
if ((oper == GT_IND) && op->IsIconHandle())
{
flags |= GTF_IND_NONFAULTING;

GenTreeFlags handleKind = op->GetIconHandleFlag();
if ((handleKind != GTF_ICON_STATIC_HDL) && (handleKind != GTF_ICON_BBC_PTR) &&
(handleKind != GTF_ICON_GLOBAL_PTR))
{
flags |= GTF_IND_INVARIANT;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This invariantness setting is fragile; it does not check what type is being loaded.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I had the same concern - like why do we expect invariantess if we acess a byte location with long type

@@ -8214,6 +8240,7 @@ GenTreeBlk* Compiler::gtNewBlkIndir(ClassLayout* layout, GenTree* addr, GenTreeF
//
GenTreeIndir* Compiler::gtNewIndir(var_types typ, GenTree* addr, GenTreeFlags indirFlags)
{
indirFlags |= gtGetFlagsForOperand(GT_IND, addr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed here? The caller is expected to pass the right indirFlags.

Copy link
Member

@EgorBo EgorBo Jul 14, 2023

Choose a reason for hiding this comment

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

I bet it's not needed it's just how @MichalPetryka was trying to find the case where it's not set (turned out be assertprop)

@JulieLeeMSFT
Copy link
Member

Hi @MichalPetryka, this is a kindly reminder. The .NET 8 RC1 snap is one week away.

@EgorBo EgorBo added the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 4, 2023
@JulieLeeMSFT JulieLeeMSFT added this to the 9.0.0 milestone Sep 5, 2023
@JulieLeeMSFT
Copy link
Member

@MichalPetryka, I am moving this to .NET 9 because it is too late for .NET 8.

@BruceForstall
Copy link
Member

@MichalPetryka Can you mark this "Draft" until it is ready for review again?

@MichalPetryka MichalPetryka marked this pull request as draft September 15, 2023 16:06
@ghost ghost added the no-recent-activity label Sep 29, 2023
@ghost
Copy link

ghost commented Sep 29, 2023

This pull request has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

@ghost
Copy link

ghost commented Oct 14, 2023

This pull request will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the pull request, but please note that it will be locked if it remains inactive for another 30 days.

@ghost ghost closed this Oct 14, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Nov 13, 2023
This pull request was closed.
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 needs-author-action An issue or pull request that requires more info or actions from the author. no-recent-activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants