Skip to content

Conversation

@AndyAyersMS
Copy link
Member

@AndyAyersMS AndyAyersMS commented Jul 30, 2022

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.

Fixes dotnet#73090.
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 30, 2022
@ghost ghost assigned AndyAyersMS Jul 30, 2022
@AndyAyersMS
Copy link
Member Author

cc @dotnet/jit-contrib

@ghost
Copy link

ghost commented Jul 30, 2022

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
Member Author

/azp run runtime-coreclr libraries-jitstress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AndyAyersMS
Copy link
Member Author

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.

@AndyAyersMS AndyAyersMS changed the title JIT: have jit stress create modifiable this earlier JIT: have jit tail call stress avoid creating loops in some cases Jul 30, 2022
@AndyAyersMS
Copy link
Member Author

/azp run runtime-coreclr jitstress

@azure-pipelines
Copy link

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
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
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
Member Author

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
Member Author

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:main Jul 31, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 30, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion failed 'compCanHavePatchpoints()' during 'Importation'

2 participants