From f16b0456251eaecd0a94cbc4e46b59f05b4d5c14 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Sat, 30 Jul 2022 11:03:59 -0700 Subject: [PATCH 1/3] JIT: have jit stress create modifiable this earlier Set `lvHasILStoreOp` on `this` right when the local is created, so that subsequent logic in the JIT sees a consistent value. Fixes #73090. --- src/coreclr/jit/fgbasic.cpp | 8 +------- src/coreclr/jit/lclvars.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index 57001a3a5fb471..c284f37fa56e3a 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -2215,13 +2215,7 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed void Compiler::fgAdjustForAddressExposedOrWrittenThis() { - LclVarDsc* thisVarDsc = lvaGetDesc(info.compThisArg); - - // Optionally enable adjustment during stress. - if (compStressCompile(STRESS_GENERIC_VARN, 15)) - { - thisVarDsc->lvHasILStoreOp = true; - } + LclVarDsc* const thisVarDsc = lvaGetDesc(info.compThisArg); // If this is exposed or written to, create a temp for the modifiable this if (thisVarDsc->IsAddressExposed() || thisVarDsc->lvHasILStoreOp) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index a1ac514c95de0e..dafcf55689e8f6 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -529,6 +529,14 @@ void Compiler::lvaInitThisPtr(InitVarDscInfo* varDscInfo) varDscInfo->varNum++; varDscInfo->varDsc++; } + + // Under stress, optionally force the jit to act as if `this` is modifable. + // + if (compStressCompile(STRESS_GENERIC_VARN, 15)) + { + JITDUMP("JITSTRESS: creating modifiable `this`\n"); + varDsc->lvHasILStoreOp = true; + } } /*****************************************************************************/ From 972a2ff2e27c6a6bb8b7364ef482fca2f2f8e3d6 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Sat, 30 Jul 2022 15:02:09 -0700 Subject: [PATCH 2/3] Revert "JIT: have jit stress create modifiable this earlier" This reverts commit f16b0456251eaecd0a94cbc4e46b59f05b4d5c14. --- src/coreclr/jit/fgbasic.cpp | 8 +++++++- src/coreclr/jit/lclvars.cpp | 8 -------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index c284f37fa56e3a..57001a3a5fb471 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -2215,7 +2215,13 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed void Compiler::fgAdjustForAddressExposedOrWrittenThis() { - LclVarDsc* const thisVarDsc = lvaGetDesc(info.compThisArg); + LclVarDsc* thisVarDsc = lvaGetDesc(info.compThisArg); + + // Optionally enable adjustment during stress. + if (compStressCompile(STRESS_GENERIC_VARN, 15)) + { + thisVarDsc->lvHasILStoreOp = true; + } // If this is exposed or written to, create a temp for the modifiable this if (thisVarDsc->IsAddressExposed() || thisVarDsc->lvHasILStoreOp) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index dafcf55689e8f6..a1ac514c95de0e 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -529,14 +529,6 @@ void Compiler::lvaInitThisPtr(InitVarDscInfo* varDscInfo) varDscInfo->varNum++; varDscInfo->varDsc++; } - - // Under stress, optionally force the jit to act as if `this` is modifable. - // - if (compStressCompile(STRESS_GENERIC_VARN, 15)) - { - JITDUMP("JITSTRESS: creating modifiable `this`\n"); - varDsc->lvHasILStoreOp = true; - } } /*****************************************************************************/ From 5402e965997ce7e3862921f55885674697d4eea5 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Sat, 30 Jul 2022 15:48:49 -0700 Subject: [PATCH 3/3] actual fix --- src/coreclr/jit/fgbasic.cpp | 1 + src/coreclr/jit/importer.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index 57001a3a5fb471..950663dda4f993 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -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; } diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index dff1e50a2f4231..21ca59fea1161f 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -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)) { // Now check with the runtime CORINFO_METHOD_HANDLE declaredCalleeHnd = callInfo.hMethod;