Skip to content

Commit

Permalink
Fix must-expand intrinsic detection (#99818)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Jun 15, 2024
1 parent b1f63db commit 0f0981f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3625,14 +3625,18 @@ class Compiler

// Return true if call is a recursive call; return false otherwise.
// Note when inlining, this looks for calls back to the root method.
bool gtIsRecursiveCall(GenTreeCall* call)
bool gtIsRecursiveCall(GenTreeCall* call, bool useInlineRoot = true)
{
return gtIsRecursiveCall(call->gtCallMethHnd);
return gtIsRecursiveCall(call->gtCallMethHnd, useInlineRoot);
}

bool gtIsRecursiveCall(CORINFO_METHOD_HANDLE callMethodHandle)
bool gtIsRecursiveCall(CORINFO_METHOD_HANDLE callMethodHandle, bool useInlineRoot = true)
{
return (callMethodHandle == impInlineRoot()->info.compMethodHnd);
if (useInlineRoot)
{
return callMethodHandle == impInlineRoot()->info.compMethodHnd;
}
return callMethodHandle == info.compMethodHnd;
}

//-------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/hwintrinsic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ GenTree* Compiler::addRangeCheckIfNeeded(
)
{
assert(!immOp->IsCnsIntOrI());
assert(varTypeIsUnsigned(immOp));
assert(varTypeIsIntegral(immOp));

return addRangeCheckForHWIntrinsic(immOp, immLowerBound, immUpperBound);
}
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
if (isIntrinsic)
{
// The recursive non-virtual calls to Jit intrinsics are must-expand by convention.
mustExpand = gtIsRecursiveCall(method) && !(methodFlags & CORINFO_FLG_VIRTUAL);
mustExpand = gtIsRecursiveCall(method, false) && !(methodFlags & CORINFO_FLG_VIRTUAL);
}
else
{
Expand Down Expand Up @@ -10135,7 +10135,7 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
assert(strcmp(className, "Vector`1") == 0);
result = NI_Vector_GetCount;
}
else if (gtIsRecursiveCall(method))
else if (gtIsRecursiveCall(method, false))
{
// For the framework itself, any recursive intrinsics will either be
// only supported on a single platform or will be guarded by a relevant
Expand Down Expand Up @@ -10370,7 +10370,7 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)

result = NI_Vector_GetCount;
}
else if (gtIsRecursiveCall(method))
else if (gtIsRecursiveCall(method, false))
{
// For the framework itself, any recursive intrinsics will either be
// only supported on a single platform or will be guarded by a relevant
Expand Down
8 changes: 0 additions & 8 deletions src/libraries/System.Private.CoreLib/src/System/Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,12 @@ public virtual Type[] GetGenericParameterConstraints()
protected virtual bool IsMarshalByRefImpl() => false;
public bool IsPrimitive
{
#if NATIVEAOT
// https://github.com/dotnet/runtime/issues/97272
[MethodImpl(MethodImplOptions.NoOptimization)]
#endif
[Intrinsic]
get => IsPrimitiveImpl();
}
protected abstract bool IsPrimitiveImpl();
public bool IsValueType
{
#if NATIVEAOT
// https://github.com/dotnet/runtime/issues/97272
[MethodImpl(MethodImplOptions.NoOptimization)]
#endif
[Intrinsic]
get => IsValueTypeImpl();
}
Expand Down

0 comments on commit 0f0981f

Please sign in to comment.