Skip to content

JIT: have jit tail call stress avoid creating loops in some cases - #73114

Merged
AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:Fix73090
Jul 31, 2022
Merged

JIT: have jit tail call stress avoid creating loops in some cases#73114
AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:Fix73090

Conversation

@AndyAyersMS

@AndyAyersMSAndyAyersMS commented Jul 30, 2022

Copy link
Copy Markdown
Member

Don't create a loop via tail call stress if the method didn't already have a loop and could have patchpoints.

Fixes#73090.

Set `lvHasILStoreOp` on `this` right when the local is created, so that
subsequent logic in the JIT sees a consistent value.
Fixesdotnet#73090.
@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 30, 2022
@AndyAyersMS

Copy link
Copy Markdown
MemberAuthor

cc @dotnet/jit-contrib

@ghost

Copy link
Copy Markdown

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

Issue Details

Set lvHasILStoreOp on this right when the local is created, so that
subsequent logic in the JIT sees a consistent value.

Fixes #73090.

Author:AndyAyersMS
Assignees:-
Labels:

area-CodeGen-coreclr

Milestone:-

@AndyAyersMS

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-coreclr libraries-jitstress

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@AndyAyersMS

Copy link
Copy Markdown
MemberAuthor

Bug was different than I thought -- jit stress was creating modifiable this, but we didn't disqualify the method from OSR initially because the method didn't have a loop. But later tail call stress created a loop and subsequent importer calls asserted that the method could not have patchpoints.

Fix is to disallow tail call stress from creating the loop.

@AndyAyersMSAndyAyersMS changed the title JIT: have jit stress create modifiable this earlierJIT: have jit tail call stress avoid creating loops in some casesJul 30, 2022
@AndyAyersMS

Copy link
Copy Markdown
MemberAuthor

/azp run runtime-coreclr jitstress

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines +15668 to +15674
// Avoid setting compHasBackwardsJump = true via tail call stress if the method cannot have
// patchpoints.
//
const bool mayHavePatchpoints = opts.jitFlags->IsSet(JitFlags::JIT_FLAG_TIER0) &&
(JitConfig.TC_OnStackReplacement() > 0) &&
compCanHavePatchpoints();
if (passedConstraintCheck && (mayHavePatchpoints || compHasBackwardJump))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix looks fine to me but I am a bit confused we are marking a backward jump in the first place. We should not do the loop optimization in tier-0 (and, since #41059, never under tailcall stress).

I can clean this up in the future if you don't want to do this as part of this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But clearly you had to add special support for OSR due to the tailcall-to-loop optimization, so maybe I am missing something?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

No, you're on to something.

We are probably too aggressive in marking explicit tail calls as backwards branches in Tier0—and more importantly in this case, changing the value of compHasBackwardJump. We do this regardless of optimization flags. If we are never going to do the optimization, then we don't need to change compHasBackwardJump either.

Another possible fix would be that when tail call stress changes an implicit tail call to an explicit one, it should also set compTailPrefixSeen. But it's not as clean of a fix; we might already have added some patchpoints.

@AndyAyersMS

Copy link
Copy Markdown
MemberAuthor

I'll merge this to fix jitstress. Not sure if I'll have time today to do anything more.

@AndyAyersMS
AndyAyersMS merged commit 5e6df13 into dotnet:mainJul 31, 2022
@ghostghost locked as resolved and limited conversation to collaborators Aug 30, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion failed 'compCanHavePatchpoints()' during 'Importation'

2 participants

@AndyAyersMS@jakobbotsch