From 76d9e65c1f4ff2b2b6b270bd1a12c9c5f79fcfa7 Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Wed, 19 Apr 2017 17:49:25 -0700 Subject: [PATCH] Made behavior to conform to ECMA for 'tail.call, pop, ret' case Commit migrated from https://github.com/dotnet/coreclr/commit/a3b208ac4e62fd5a2645d8b7942ff964852ad0d4 --- src/coreclr/src/jit/flowgraph.cpp | 8 ++++---- src/coreclr/src/jit/importer.cpp | 14 +++++++------- src/coreclr/src/jit/morph.cpp | 4 ++-- src/coreclr/tests/issues.targets | 9 ++++++--- src/coreclr/tests/testsUnsupportedOutsideWindows.txt | 2 ++ 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/coreclr/src/jit/flowgraph.cpp b/src/coreclr/src/jit/flowgraph.cpp index c385155..72d2960 100644 --- a/src/coreclr/src/jit/flowgraph.cpp +++ b/src/coreclr/src/jit/flowgraph.cpp @@ -5455,15 +5455,15 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, B if (!impIsTailCallILPattern(tailCall, opcode, codeAddr + sz, codeEndp, isRecursive, &isCallPopAndRet)) { -#ifdef _TARGET_AMD64_ +#if !defined(FEATURE_CORECLR) && defined(_TARGET_AMD64_) BADCODE3("tail call not followed by ret or pop+ret", " at offset %04X", (IL_OFFSET)(codeAddr - codeBegp)); #else BADCODE3("tail call not followed by ret", " at offset %04X", (IL_OFFSET)(codeAddr - codeBegp)); -#endif //_TARGET_AMD64_ +#endif // !FEATURE_CORECLR && _TARGET_AMD64_ } -#ifdef _TARGET_AMD64_ +#if !defined(FEATURE_CORECLR) && defined(_TARGET_AMD64_) if (isCallPopAndRet) { // By breaking here, we let pop and ret opcodes to be @@ -5472,7 +5472,7 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, B // in fgMorphCall(). break; } -#endif //_TARGET_AMD64_ +#endif // !FEATURE_CORECLR && _TARGET_AMD64_ } else { diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 2e3ca81..90d6c92 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -6321,7 +6321,7 @@ bool Compiler::impIsTailCallILPattern(bool tailPrefixed, int cntPop = 0; OPCODE nextOpcode; -#ifdef _TARGET_AMD64_ +#if !defined(FEATURE_CORECLR) && defined(_TARGET_AMD64_) do { nextOpcode = (OPCODE)getU1LittleEndian(codeAddrOfNextOpcode); @@ -6332,7 +6332,7 @@ bool Compiler::impIsTailCallILPattern(bool tailPrefixed, // one pop seen so far. #else nextOpcode = (OPCODE)getU1LittleEndian(codeAddrOfNextOpcode); -#endif +#endif // !FEATURE_CORECLR && _TARGET_AMD64_ if (isCallPopAndRet) { @@ -6340,15 +6340,15 @@ bool Compiler::impIsTailCallILPattern(bool tailPrefixed, *isCallPopAndRet = (nextOpcode == CEE_RET) && (cntPop == 1); } -#ifdef _TARGET_AMD64_ +#if !defined(FEATURE_CORECLR) && defined(_TARGET_AMD64_) // Jit64 Compat: // Tail call IL pattern could be either of the following // 1) call/callvirt/calli + ret // 2) call/callvirt/calli + pop + ret in a method returning void. return (nextOpcode == CEE_RET) && ((cntPop == 0) || ((cntPop == 1) && (info.compRetType == TYP_VOID))); -#else //!_TARGET_AMD64_ +#else return (nextOpcode == CEE_RET) && (cntPop == 0); -#endif +#endif // !FEATURE_CORECLR && _TARGET_AMD64_ } /***************************************************************************** @@ -15455,14 +15455,14 @@ bool Compiler::impReturnInstruction(BasicBlock* block, int prefixFlags, OPCODE& // We must have imported a tailcall and jumped to RET if (prefixFlags & PREFIX_TAILCALL) { -#ifndef _TARGET_AMD64_ +#if defined(FEATURE_CORECLR) || !defined(_TARGET_AMD64_) // Jit64 compat: // This cannot be asserted on Amd64 since we permit the following IL pattern: // tail.call // pop // ret assert(verCurrentState.esStackDepth == 0 && impOpcodeIsCallOpcode(opcode)); -#endif +#endif // FEATURE_CORECLR || !_TARGET_AMD64_ opcode = CEE_RET; // To prevent trying to spill if CALL_SITE_BOUNDARIES diff --git a/src/coreclr/src/jit/morph.cpp b/src/coreclr/src/jit/morph.cpp index 42557d8..2a6e7db 100644 --- a/src/coreclr/src/jit/morph.cpp +++ b/src/coreclr/src/jit/morph.cpp @@ -7863,7 +7863,7 @@ GenTreePtr Compiler::fgMorphCall(GenTreeCall* call) // the call. GenTreeStmt* nextMorphStmt = fgMorphStmt->gtNextStmt; -#ifdef _TARGET_AMD64_ +#if !defined(FEATURE_CORECLR) && defined(_TARGET_AMD64_) // Legacy Jit64 Compat: // There could be any number of GT_NOPs between tail call and GT_RETURN. // That is tail call pattern could be one of the following: @@ -7930,7 +7930,7 @@ GenTreePtr Compiler::fgMorphCall(GenTreeCall* call) fgRemoveStmt(compCurBB, morphStmtToRemove); } } -#endif // _TARGET_AMD64_ +#endif // !FEATURE_CORECLR && _TARGET_AMD64_ // Delete GT_RETURN if any if (nextMorphStmt != nullptr) diff --git a/src/coreclr/tests/issues.targets b/src/coreclr/tests/issues.targets index b7b6287..bc8ee5d 100644 --- a/src/coreclr/tests/issues.targets +++ b/src/coreclr/tests/issues.targets @@ -187,6 +187,12 @@ 6707 + + 9880 + + + 9880 + @@ -204,9 +210,6 @@ 3392, test is useful to have because it can be run manually when making changes to the GC that can have effects in OOM scenarios, but not appropriate to run on our current test infrastructure. - - tail. call pop ret is only supported on amd64 - 2420. x86 JIT doesn't support implicit tail call optimization or tail. call pop ret sequence diff --git a/src/coreclr/tests/testsUnsupportedOutsideWindows.txt b/src/coreclr/tests/testsUnsupportedOutsideWindows.txt index ef43049..9983cc0 100644 --- a/src/coreclr/tests/testsUnsupportedOutsideWindows.txt +++ b/src/coreclr/tests/testsUnsupportedOutsideWindows.txt @@ -315,6 +315,7 @@ JIT/Methodical/tailcall/_il_dbgpointer/_il_dbgpointer.sh JIT/Methodical/tailcall/_il_dbgpointer_i/_il_dbgpointer_i.sh JIT/Methodical/tailcall/_il_relpointer/_il_relpointer.sh JIT/Methodical/tailcall/_il_relpointer_i/_il_relpointer_i.sh +JIT/Methodical/tailcall_v4/smallFrame/smallFrame.sh JIT/Methodical/varargs/callconv/gc_ctor_il_d/gc_ctor_il_d.sh JIT/Methodical/varargs/callconv/gc_ctor_il_r/gc_ctor_il_r.sh JIT/Methodical/varargs/callconv/val_ctor_il_d/val_ctor_il_d.sh @@ -326,6 +327,7 @@ JIT/Methodical/varargs/seh/filter_il_d/filter_il_d.sh JIT/Methodical/varargs/seh/filter_il_r/filter_il_r.sh JIT/opt/Inline/tests/security/security.sh JIT/opt/Inline/tests/xmodb/xmodb.sh +JIT/opt/Tailcall/TailcallVerifyWithPrefix/TailcallVerifyWithPrefix.sh JIT/Regression/clr-x64-JIT/v2.1/b173569/b173569/b173569.sh JIT/Regression/clr-x64-JIT/v4.0/devdiv374539/DevDiv_374539/DevDiv_374539.sh JIT/Regression/CLR-x86-EJIT/V1-M12-Beta2/b26323/b26323/b26323.sh -- 2.7.4