Skip to content

Commit

Permalink
Refactoring due to the PR comments (dotnet#65625)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFoD committed Jun 20, 2022
1 parent 1ec62d0 commit fd79612
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4528,9 +4528,6 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
{
// both are constant, we can fold this operation completely. Pop both peeked values

DEBUG_DESTROY_NODE(impPopStack().val);
DEBUG_DESTROY_NODE(impPopStack().val);

if (ni == NI_System_Math_Max)
{
cnsNode->gtDconVal =
Expand All @@ -4544,6 +4541,11 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
}

retNode = cnsNode;

impPopStack();
impPopStack();
DEBUG_DESTROY_NODE(otherNode);

break;
}

Expand All @@ -4553,57 +4555,73 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
{
// maxsd, maxss, minsd, and minss all return op2 if either is NaN
// we require NaN to be propagated so ensure the known NaN is op2
impPopStack();
impPopStack();
DEBUG_DESTROY_NODE(otherNode);

op2 = cnsNode;
op1 = otherNode;
retNode = cnsNode;
break;
}
else if (ni == NI_System_Math_Max)
{
// maxsd, maxss return op2 if both inputs are 0 of either sign
// we require +0 to be greater than -0, so we can't handle if
// the known constant is +0. This is because if the unknown value
// is -0, we'd need the cns to be op2. But if the unknown value
// is NaN, we'd need the cns to be op1 instead.
if (cnsNode->IsFloatPositiveZero())
{
// maxsd, maxss return op2 if both inputs are 0 of either sign
// we require +0 to be greater than -0, so we can't handle if
// the known constant is +0. This is because if the unknown value
// is -0, we'd need the cns to be op2. But if the unknown value
// is NaN, we'd need the cns to be op1 instead.

break;
}

// Given the checks, op1 can safely be the cns and op2 the other node
ni = (callType == TYP_DOUBLE) ? NI_SSE2_Max : NI_SSE_Max;

// one is constant and we know its something we can handle, so pop both peeked values

op1 = cnsNode;
op2 = otherNode;
}
else
{
assert(ni == NI_System_Math_Min);

// minsd, minss return op2 if both inputs are 0 of either sign
// we require -0 to be lesser than +0, so we can't handle if
// the known constant is -0. This is because if the unknown value
// is +0, we'd need the cns to be op2. But if the unknown value
// is NaN, we'd need the cns to be op1 instead.
if (cnsNode->IsFloatNegativeZero())
{
// minsd, minss return op2 if both inputs are 0 of either sign
// we require -0 to be lesser than +0, so we can't handle if
// the known constant is -0. This is because if the unknown value
// is +0, we'd need the cns to be op2. But if the unknown value
// is NaN, we'd need the cns to be op1 instead.

break;
}

// Given the checks, op1 can safely be the cns and op2 the other node
ni = (callType == TYP_DOUBLE) ? NI_SSE2_Min : NI_SSE_Min;

// one is constant and we know its something we can handle, so pop both peeked values

op1 = cnsNode;
op2 = otherNode;
}

// one is constant and we know its something we can handle, so pop both peeked values
assert(op1->IsCnsFltOrDbl() && !op2->IsCnsFltOrDbl());

impPopStack().val;
impPopStack().val;

op1 = gtNewSimdHWIntrinsicNode(TYP_SIMD16, op1, NI_Vector128_CreateScalarUnsafe, callJitType, 16);
GenTreeVecCon* vecCon = gtNewVconNode(TYP_SIMD16, callJitType);

if (callJitType == CORINFO_TYPE_FLOAT)
{
vecCon->gtSimd16Val.f32[0] = (float)op1->AsDblCon()->gtDconVal;
}
else
{
vecCon->gtSimd16Val.f64[0] = op1->AsDblCon()->gtDconVal;
}

op1 = vecCon;
op2 = gtNewSimdHWIntrinsicNode(TYP_SIMD16, op2, NI_Vector128_CreateScalarUnsafe, callJitType, 16);

retNode = gtNewSimdHWIntrinsicNode(TYP_SIMD16, op1, op2, ni, callJitType, 16);
Expand Down

0 comments on commit fd79612

Please sign in to comment.