Skip to content

Commit e1edb16

Browse files
EgorBojakobbotsch
andauthored
Allow some intrinsics in Tier0 (#77357)
Co-authored-by: Jakob Botsch Nielsen <[email protected]>
1 parent cc14f35 commit e1edb16

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/coreclr/jit/importercalls.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2597,14 +2597,53 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
25972597
break;
25982598
}
25992599

2600+
// Allow some lighweight intrinsics in Tier0 which can improve throughput
2601+
// we introduced betterToExpand here because we're fine if intrinsic decides to not expand itself
2602+
// in this case unlike mustExpand.
2603+
bool betterToExpand = false;
2604+
2605+
// NOTE: MinOpts() is always true for Tier0 so we have to check explicit flags instead.
2606+
// To be fixed in https://github.com/dotnet/runtime/pull/77465
2607+
const bool tier0opts = !opts.compDbgCode && !opts.jitFlags->IsSet(JitFlags::JIT_FLAG_MIN_OPT);
2608+
2609+
if (!mustExpand && tier0opts)
2610+
{
2611+
switch (ni)
2612+
{
2613+
// This one is just `return true/false`
2614+
case NI_System_Runtime_CompilerServices_RuntimeHelpers_IsKnownConstant:
2615+
2616+
// We need these to be able to fold "typeof(...) == typeof(...)"
2617+
case NI_System_RuntimeTypeHandle_GetValueInternal:
2618+
case NI_System_Type_GetTypeFromHandle:
2619+
case NI_System_Type_op_Equality:
2620+
case NI_System_Type_op_Inequality:
2621+
2622+
// Simple cases
2623+
case NI_System_String_get_Chars:
2624+
case NI_System_String_get_Length:
2625+
case NI_System_Span_get_Item:
2626+
case NI_System_Span_get_Length:
2627+
case NI_System_ReadOnlySpan_get_Item:
2628+
case NI_System_ReadOnlySpan_get_Length:
2629+
betterToExpand = true;
2630+
break;
2631+
2632+
default:
2633+
// Unsafe.* are all small enough to prefer expansions.
2634+
betterToExpand = ni >= NI_SRCS_UNSAFE_START && ni <= NI_SRCS_UNSAFE_END;
2635+
break;
2636+
}
2637+
}
2638+
26002639
GenTree* retNode = nullptr;
26012640

26022641
// Under debug and minopts, only expand what is required.
26032642
// NextCallReturnAddress intrinsic returns the return address of the next call.
26042643
// If that call is an intrinsic and is expanded, codegen for NextCallReturnAddress will fail.
26052644
// To avoid that we conservatively expand only required intrinsics in methods that call
26062645
// the NextCallReturnAddress intrinsic.
2607-
if (!mustExpand && (opts.OptimizationDisabled() || info.compHasNextCallRetAddr))
2646+
if (!mustExpand && ((opts.OptimizationDisabled() && !betterToExpand) || info.compHasNextCallRetAddr))
26082647
{
26092648
*pIntrinsicName = NI_Illegal;
26102649
return retNode;

0 commit comments

Comments
 (0)