Skip to content

Commit e17f25c

Browse files
authored
Jitstress fixes for tailcall tests (dotnet#1771)
Make STRESS_GENERIC_VARN more compatible with methods that make explicit tail calls. Don't add gc checks for explicit tail calls, and remove the code in morph that blocks tail calls if gc checks are active. Update the tailcall test to to disable STRESS_UNSAFE_BUFFER_CHECKS. This can be reverted when dotnet#341 is merged. Fixes dotnet#1752.
1 parent 5182dad commit e17f25c

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

src/coreclr/src/jit/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4021,7 +4021,7 @@ class Compiler
40214021
}
40224022
void impLoadArg(unsigned ilArgNum, IL_OFFSET offset);
40234023
void impLoadLoc(unsigned ilLclNum, IL_OFFSET offset);
4024-
bool impReturnInstruction(BasicBlock* block, int prefixFlags, OPCODE& opcode);
4024+
bool impReturnInstruction(int prefixFlags, OPCODE& opcode);
40254025

40264026
#ifdef _TARGET_ARM_
40274027
void impMarkLclDstNotPromotable(unsigned tmpNum, GenTree* op, CORINFO_CLASS_HANDLE hClass);

src/coreclr/src/jit/importer.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11508,7 +11508,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
1150811508
case CEE_RET:
1150911509
prefixFlags &= ~PREFIX_TAILCALL; // ret without call before it
1151011510
RET:
11511-
if (!impReturnInstruction(block, prefixFlags, opcode))
11511+
if (!impReturnInstruction(prefixFlags, opcode))
1151211512
{
1151311513
return; // abort
1151411514
}
@@ -16254,7 +16254,7 @@ GenTree* Compiler::impAssignSmallStructTypeToVar(GenTree* op, CORINFO_CLASS_HAND
1625416254
// registers return values to suitable temps.
1625516255
//
1625616256
// Arguments:
16257-
// op -- call returning a struct in a registers
16257+
// op -- call returning a struct in registers
1625816258
// hClass -- class handle for struct
1625916259
//
1626016260
// Returns:
@@ -16278,11 +16278,20 @@ GenTree* Compiler::impAssignMultiRegTypeToVar(GenTree* op, CORINFO_CLASS_HANDLE
1627816278
}
1627916279
#endif // FEATURE_MULTIREG_RET
1628016280

16281-
// do import for a return
16282-
// returns false if inlining was aborted
16283-
// opcode can be ret or call in the case of a tail.call
16284-
bool Compiler::impReturnInstruction(BasicBlock* block, int prefixFlags, OPCODE& opcode)
16281+
//------------------------------------------------------------------------
16282+
// impReturnInstruction: import a return or an explicit tail call
16283+
//
16284+
// Arguments:
16285+
// prefixFlags -- active IL prefixes
16286+
// opcode -- [in, out] IL opcode
16287+
//
16288+
// Returns:
16289+
// True if import was successful (may fail for some inlinees)
16290+
//
16291+
bool Compiler::impReturnInstruction(int prefixFlags, OPCODE& opcode)
1628516292
{
16293+
const bool isTailCall = (prefixFlags & PREFIX_TAILCALL) != 0;
16294+
1628616295
if (tiVerificationNeeded)
1628716296
{
1628816297
verVerifyThisPtrInitialised();
@@ -16334,7 +16343,7 @@ bool Compiler::impReturnInstruction(BasicBlock* block, int prefixFlags, OPCODE&
1633416343
(varTypeIsStruct(op2) && varTypeIsStruct(info.compRetType)));
1633516344

1633616345
#ifdef DEBUG
16337-
if (opts.compGcChecks && info.compRetType == TYP_REF)
16346+
if (!isTailCall && opts.compGcChecks && (info.compRetType == TYP_REF))
1633816347
{
1633916348
// DDB 3483 : JIT Stress: early termination of GC ref's life time in exception code path
1634016349
// VSW 440513: Incorrect gcinfo on the return value under COMPlus_JitGCChecks=1 for methods with
@@ -16741,7 +16750,7 @@ bool Compiler::impReturnInstruction(BasicBlock* block, int prefixFlags, OPCODE&
1674116750
}
1674216751

1674316752
// We must have imported a tailcall and jumped to RET
16744-
if (prefixFlags & PREFIX_TAILCALL)
16753+
if (isTailCall)
1674516754
{
1674616755
#if defined(FEATURE_CORECLR) || !defined(_TARGET_AMD64_)
1674716756
// Jit64 compat:

src/coreclr/src/jit/morph.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6975,15 +6975,6 @@ GenTree* Compiler::fgMorphPotentialTailCall(GenTreeCall* call)
69756975
}
69766976
#endif
69776977

6978-
#ifdef DEBUG
6979-
// DDB 99324: Just disable tailcall under compGcChecks stress mode.
6980-
if (opts.compGcChecks)
6981-
{
6982-
failTailCall("GcChecks");
6983-
return nullptr;
6984-
}
6985-
#endif
6986-
69876978
// We have to ensure to pass the incoming retValBuf as the
69886979
// outgoing one. Using a temp will not do as this function will
69896980
// not regain control to do the copy. This can happen when inlining

src/coreclr/tests/src/JIT/Directed/tailcall/tailcall.ilproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,14 @@
99
<ItemGroup>
1010
<Compile Include="$(MSBuildProjectName).il" />
1111
</ItemGroup>
12+
<PropertyGroup>
13+
<CLRTestBatchPreCommands><![CDATA[
14+
$(CLRTestBatchPreCommands)
15+
set COMPlus_JitStressModeNamesNot=STRESS_UNSAFE_BUFFER_CHECKS
16+
]]></CLRTestBatchPreCommands>
17+
<BashCLRTestPreCommands><![CDATA[
18+
$(BashCLRTestPreCommands)
19+
export COMPlus_JitStressModeNamesNot=STRESS_UNSAFE_BUFFER_CHECKS
20+
]]></BashCLRTestPreCommands>
21+
</PropertyGroup>
1222
</Project>

0 commit comments

Comments
 (0)