@@ -2597,14 +2597,53 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
2597
2597
break ;
2598
2598
}
2599
2599
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
+
2600
2639
GenTree* retNode = nullptr ;
2601
2640
2602
2641
// Under debug and minopts, only expand what is required.
2603
2642
// NextCallReturnAddress intrinsic returns the return address of the next call.
2604
2643
// If that call is an intrinsic and is expanded, codegen for NextCallReturnAddress will fail.
2605
2644
// To avoid that we conservatively expand only required intrinsics in methods that call
2606
2645
// the NextCallReturnAddress intrinsic.
2607
- if (!mustExpand && (opts.OptimizationDisabled () || info.compHasNextCallRetAddr ))
2646
+ if (!mustExpand && (( opts.OptimizationDisabled () && !betterToExpand ) || info.compHasNextCallRetAddr ))
2608
2647
{
2609
2648
*pIntrinsicName = NI_Illegal;
2610
2649
return retNode;
0 commit comments