Skip to content

Commit c16c0e3

Browse files
committed
Better fix
1 parent d58c541 commit c16c0e3

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

src/coreclr/jit/compiler.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -3571,14 +3571,18 @@ class Compiler
35713571

35723572
// Return true if call is a recursive call; return false otherwise.
35733573
// Note when inlining, this looks for calls back to the root method.
3574-
bool gtIsRecursiveCall(GenTreeCall* call)
3574+
bool gtIsRecursiveCall(GenTreeCall* call, bool inlineeOnly = false)
35753575
{
3576-
return gtIsRecursiveCall(call->gtCallMethHnd);
3576+
return gtIsRecursiveCall(call->gtCallMethHnd, inlineeOnly);
35773577
}
35783578

3579-
bool gtIsRecursiveCall(CORINFO_METHOD_HANDLE callMethodHandle)
3579+
bool gtIsRecursiveCall(CORINFO_METHOD_HANDLE callMethodHandle, bool inlineeOnly = false)
35803580
{
3581-
return (callMethodHandle == impInlineRoot()->info.compMethodHnd);
3581+
if (inlineeOnly)
3582+
{
3583+
return callMethodHandle == info.compMethodHnd;
3584+
}
3585+
return callMethodHandle == impInlineRoot()->info.compMethodHnd;
35823586
}
35833587

35843588
//-------------------------------------------------------------------------
@@ -4539,7 +4543,8 @@ class Compiler
45394543
CORINFO_CLASS_HANDLE clsHnd,
45404544
CORINFO_METHOD_HANDLE method,
45414545
CORINFO_SIG_INFO* sig,
4542-
bool mustExpand);
4546+
bool mustExpand,
4547+
bool* pLateExpansion);
45434548
GenTree* impSimdAsHWIntrinsic(NamedIntrinsic intrinsic,
45444549
CORINFO_CLASS_HANDLE clsHnd,
45454550
CORINFO_METHOD_HANDLE method,

src/coreclr/jit/hwintrinsic.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -1036,20 +1036,23 @@ struct HWIntrinsicSignatureReader final
10361036
// impHWIntrinsic: Import a hardware intrinsic as a GT_HWINTRINSIC node if possible
10371037
//
10381038
// Arguments:
1039-
// intrinsic -- id of the intrinsic function.
1040-
// clsHnd -- class handle containing the intrinsic function.
1041-
// method -- method handle of the intrinsic function.
1042-
// sig -- signature of the intrinsic call
1043-
// mustExpand -- true if the intrinsic must return a GenTree*; otherwise, false
1044-
1039+
// intrinsic - id of the intrinsic function.
1040+
// clsHnd - class handle containing the intrinsic function.
1041+
// method - method handle of the intrinsic function.
1042+
// sig - signature of the intrinsic call
1043+
// mustExpand - true if the intrinsic must return a GenTree*; otherwise, false
1044+
// pLateExpansion - [OUT] set to true if the intrinsic must be expanded during codegen phase
1045+
// (typically, via a jump table).
1046+
//
10451047
// Return Value:
10461048
// The GT_HWINTRINSIC node, or nullptr if not a supported intrinsic
10471049
//
10481050
GenTree* Compiler::impHWIntrinsic(NamedIntrinsic intrinsic,
10491051
CORINFO_CLASS_HANDLE clsHnd,
10501052
CORINFO_METHOD_HANDLE method,
10511053
CORINFO_SIG_INFO* sig,
1052-
bool mustExpand)
1054+
bool mustExpand,
1055+
bool* pLateExpansion)
10531056
{
10541057
// NextCallRetAddr requires a CALL, so return nullptr.
10551058
if (!mustExpand && info.compHasNextCallRetAddr)
@@ -1225,7 +1228,8 @@ GenTree* Compiler::impHWIntrinsic(NamedIntrinsic intrinsic,
12251228

12261229
if ((immVal2 < immLowerBound2) || (immVal2 > immUpperBound2))
12271230
{
1228-
assert(!mustExpand);
1231+
// Will be expanded as a jump table during codegen phase
1232+
*pLateExpansion = true;
12291233
return nullptr;
12301234
}
12311235
}
@@ -1306,7 +1310,8 @@ GenTree* Compiler::impHWIntrinsic(NamedIntrinsic intrinsic,
13061310

13071311
if (immOutOfRange)
13081312
{
1309-
assert(!mustExpand);
1313+
// Will be expanded as a jump table during codegen phase
1314+
*pLateExpansion = true;
13101315
// The imm-HWintrinsics that do not accept all imm8 values may throw
13111316
// ArgumentOutOfRangeException when the imm argument is not in the valid range
13121317
return nullptr;

src/coreclr/jit/importercalls.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -2871,7 +2871,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
28712871
if (isIntrinsic)
28722872
{
28732873
// The recursive non-virtual calls to Jit intrinsics are must-expand by convention.
2874-
mustExpand = gtIsRecursiveCall(method) && !(methodFlags & CORINFO_FLG_VIRTUAL);
2874+
mustExpand = gtIsRecursiveCall(method, true) && !(methodFlags & CORINFO_FLG_VIRTUAL);
28752875
}
28762876
else
28772877
{
@@ -3054,9 +3054,10 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
30543054
}
30553055
}
30563056

3057-
GenTree* hwintrinsic = impHWIntrinsic(ni, clsHnd, method, sig, mustExpand);
3057+
bool lateExpansion = false;
3058+
GenTree* hwintrinsic = impHWIntrinsic(ni, clsHnd, method, sig, mustExpand, &lateExpansion);
30583059

3059-
if (mustExpand && (hwintrinsic == nullptr))
3060+
if (mustExpand && (hwintrinsic == nullptr) && !lateExpansion)
30603061
{
30613062
return impUnsupportedNamedIntrinsic(CORINFO_HELP_THROW_NOT_IMPLEMENTED, method, sig, mustExpand);
30623063
}
@@ -9611,7 +9612,7 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
96119612
assert(strcmp(className, "Vector`1") == 0);
96129613
result = NI_Vector_GetCount;
96139614
}
9614-
else if (gtIsRecursiveCall(method))
9615+
else if (gtIsRecursiveCall(method, true))
96159616
{
96169617
// For the framework itself, any recursive intrinsics will either be
96179618
// only supported on a single platform or will be guarded by a relevant
@@ -9835,7 +9836,7 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
98359836

98369837
result = NI_Vector_GetCount;
98379838
}
9838-
else if (gtIsRecursiveCall(method))
9839+
else if (gtIsRecursiveCall(method, true))
98399840
{
98409841
// For the framework itself, any recursive intrinsics will either be
98419842
// only supported on a single platform or will be guarded by a relevant

0 commit comments

Comments
 (0)