@@ -3125,15 +3125,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
3125
3125
// To be fixed in https://github.com/dotnet/runtime/pull/77465
3126
3126
const bool tier0opts = !opts.compDbgCode && !opts.jitFlags ->IsSet (JitFlags::JIT_FLAG_MIN_OPT);
3127
3127
3128
- if (tier0opts)
3129
- {
3130
- // The *Estimate APIs are allowed to differ in behavior across hardware
3131
- // so ensure we treat them as "betterToExpand" to get deterministic behavior
3132
-
3133
- betterToExpand |= (ni == NI_System_Math_ReciprocalEstimate);
3134
- betterToExpand |= (ni == NI_System_Math_ReciprocalSqrtEstimate);
3135
- }
3136
- else if (!mustExpand)
3128
+ if (!mustExpand)
3137
3129
{
3138
3130
switch (ni)
3139
3131
{
@@ -7471,6 +7463,8 @@ bool Compiler::IsTargetIntrinsic(NamedIntrinsic intrinsicName)
7471
7463
{
7472
7464
case NI_System_Math_Abs:
7473
7465
case NI_System_Math_Sqrt:
7466
+ case NI_System_Math_ReciprocalEstimate:
7467
+ case NI_System_Math_ReciprocalSqrtEstimate:
7474
7468
return true ;
7475
7469
7476
7470
default :
@@ -8847,7 +8841,7 @@ GenTree* Compiler::impEstimateIntrinsic(CORINFO_METHOD_HANDLE method,
8847
8841
simdSize = 16 ;
8848
8842
}
8849
8843
8850
- GenTree* op1 = impPopStack ().val ;
8844
+ GenTree* op1 = impImplicitR4orR8Cast ( impPopStack ().val , callType) ;
8851
8845
8852
8846
op1 = gtNewSimdCreateScalarUnsafeNode (simdType, op1, callJitType, simdSize);
8853
8847
op1 = gtNewSimdHWIntrinsicNode (simdType, op1, intrinsicId, callJitType, simdSize);
@@ -8856,10 +8850,27 @@ GenTree* Compiler::impEstimateIntrinsic(CORINFO_METHOD_HANDLE method,
8856
8850
}
8857
8851
#endif // FEATURE_HW_INTRINSICS
8858
8852
8859
- // TODO-CQ: Returning this as an intrinsic blocks inlining and is undesirable
8860
- // return impMathIntrinsic(method, sig, callType, intrinsicName, tailCall);
8853
+ switch (intrinsicName)
8854
+ {
8855
+ case NI_System_Math_ReciprocalEstimate:
8856
+ case NI_System_Math_ReciprocalSqrtEstimate:
8857
+ {
8858
+ GenTree* op1 = impImplicitR4orR8Cast (impPopStack ().val , callType);
8861
8859
8862
- return nullptr ;
8860
+ if (intrinsicName == NI_System_Math_ReciprocalSqrtEstimate)
8861
+ {
8862
+ op1 = new (this , GT_INTRINSIC) GenTreeIntrinsic (genActualType (callType), op1, NI_System_Math_Sqrt,
8863
+ nullptr );
8864
+ }
8865
+
8866
+ return gtNewOperNode (GT_DIV, genActualType (callType), gtNewDconNode (1.0 , callType), op1);
8867
+ }
8868
+
8869
+ default :
8870
+ {
8871
+ unreached ();
8872
+ }
8873
+ }
8863
8874
}
8864
8875
8865
8876
GenTree* Compiler::impMathIntrinsic (CORINFO_METHOD_HANDLE method,
@@ -8958,8 +8969,8 @@ GenTree* Compiler::impMinMaxIntrinsic(CORINFO_METHOD_HANDLE method,
8958
8969
GenTreeDblCon* cnsNode = nullptr ;
8959
8970
GenTree* otherNode = nullptr ;
8960
8971
8961
- GenTree* op2 = impStackTop ().val ;
8962
- GenTree* op1 = impStackTop (1 ).val ;
8972
+ GenTree* op2 = impImplicitR4orR8Cast ( impStackTop ().val , callType) ;
8973
+ GenTree* op1 = impImplicitR4orR8Cast ( impStackTop (1 ).val , callType) ;
8963
8974
8964
8975
if (op2->IsCnsFltOrDbl ())
8965
8976
{
@@ -9227,7 +9238,7 @@ GenTree* Compiler::impMinMaxIntrinsic(CORINFO_METHOD_HANDLE method,
9227
9238
retNode->AsHWIntrinsic ()->Op (2 ) = op1;
9228
9239
}
9229
9240
9230
- return gtNewSimdToScalarNode (callType, retNode, callJitType, 16 );
9241
+ return gtNewSimdToScalarNode (genActualType ( callType) , retNode, callJitType, 16 );
9231
9242
}
9232
9243
}
9233
9244
#endif // FEATURE_HW_INTRINSICS && TARGET_XARCH
@@ -9392,7 +9403,7 @@ GenTree* Compiler::impMinMaxIntrinsic(CORINFO_METHOD_HANDLE method,
9392
9403
callJitType, 16 );
9393
9404
}
9394
9405
9395
- return gtNewSimdToScalarNode (callType, tmp, callJitType, 16 );
9406
+ return gtNewSimdToScalarNode (genActualType ( callType) , tmp, callJitType, 16 );
9396
9407
}
9397
9408
#endif // FEATURE_HW_INTRINSICS && TARGET_XARCH
9398
9409
0 commit comments