Skip to content

Commit 96b3285

Browse files
authored
Eliminate NextCallReturnAddress call followed by CEE_POP (#118500)
This sequence should be handled as no-op
1 parent c2e7c99 commit 96b3285

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2748,14 +2748,22 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
27482748
m_compHnd->getCallInfo(&resolvedCallToken, pConstrainedToken, m_methodInfo->ftn, flags, &callInfo);
27492749
if (callInfo.methodFlags & CORINFO_FLG_INTRINSIC)
27502750
{
2751+
NamedIntrinsic ni = GetNamedIntrinsic(m_compHnd, m_methodHnd, callInfo.hMethod);
2752+
if ((ni == NI_System_StubHelpers_NextCallReturnAddress) && (m_ip[5] == CEE_POP))
2753+
{
2754+
// Call to System.StubHelpers.NextCallReturnAddress followed by CEE_POP is a special case that we handle
2755+
// as a no-op.
2756+
m_ip += 6; // Skip the call and the CEE_POP
2757+
return;
2758+
}
2759+
27512760
// If we are being asked explicitly to compile an intrinsic for interpreting, we need to forcibly enable
27522761
// intrinsics for the recursive call. Otherwise we will just recurse infinitely and overflow stack.
27532762
// This expansion can produce value that is inconsistent with the value seen by JIT/R2R code that can
27542763
// cause user code to misbehave. This is by design. One-off method Interpretation is for internal use only.
27552764
bool isMustExpand = (callInfo.hMethod == m_methodHnd);
27562765
if ((InterpConfig.InterpMode() == 3) || isMustExpand)
27572766
{
2758-
NamedIntrinsic ni = GetNamedIntrinsic(m_compHnd, m_methodHnd, callInfo.hMethod);
27592767
if (EmitNamedIntrinsicCall(ni, resolvedCallToken.hClass, callInfo.hMethod, callInfo.sig))
27602768
{
27612769
m_ip += 5;

src/coreclr/interpreter/intrinsics.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ NamedIntrinsic GetNamedIntrinsic(COMP_HANDLE compHnd, CORINFO_METHOD_HANDLE comp
3838
return NI_System_Math_ReciprocalSqrtEstimate;
3939
}
4040
}
41+
else if (!strcmp(namespaceName, "System.StubHelpers"))
42+
{
43+
if (!strcmp(className, "StubHelpers"))
44+
{
45+
if (!strcmp(methodName, "NextCallReturnAddress"))
46+
return NI_System_StubHelpers_NextCallReturnAddress;
47+
}
48+
}
4149
else if (!strcmp(namespaceName, "System.Numerics"))
4250
{
4351
if (!strcmp(className, "Vector") && !strcmp(methodName, "get_IsHardwareAccelerated"))

0 commit comments

Comments
 (0)