Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,7 @@ void Compiler::fgAdjustForAddressExposedOrWrittenThis()
// Optionally enable adjustment during stress.
if (compStressCompile(STRESS_GENERIC_VARN, 15))
{
JITDUMP("JitStress: creating modifiable `this`\n");
thisVarDsc->lvHasILStoreOp = true;
}

Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15665,7 +15665,13 @@ void Compiler::impImportBlockCode(BasicBlock* block)
constraintCall ? &constrainedResolvedToken : nullptr,
returnFalseIfInvalid);

if (passedConstraintCheck)
// 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))
Comment on lines +15668 to +15674
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.

{
// Now check with the runtime
CORINFO_METHOD_HANDLE declaredCalleeHnd = callInfo.hMethod;
Expand Down