Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 37 additions & 49 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5014,60 +5014,52 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
#endif // FEATURE_HW_INTRINSICS

#ifdef TARGET_RISCV64
GenTree* op2 = impImplicitR4orR8Cast(impPopStack().val, callType);
GenTree* op1 = impImplicitR4orR8Cast(impPopStack().val, callType);

if (isNative)
if (!isMagnitude)
{
assert(!isMagnitude && !isNumber);
isNumber = true;
}

GenTree *op1Clone = nullptr, *op2Clone = nullptr;
GenTree* op2 = impImplicitR4orR8Cast(impPopStack().val, callType);
GenTree* op1 = impImplicitR4orR8Cast(impPopStack().val, callType);

if (!isNumber)
{
op2 = impCloneExpr(op2, &op2Clone, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 for Math.Min/Max non-Number"));
}
if (isNative)
{
assert(!isMagnitude && !isNumber);
isNumber = true;
}

if (!isNumber)
{
op1 = impCloneExpr(op1, &op1Clone, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for Math.Min/Max non-Number"));
}
GenTree *op1Clone = nullptr, *op2Clone = nullptr;

static const CORINFO_CONST_LOOKUP nullEntry = {IAT_VALUE};
if (isMagnitude)
{
op1 = new (this, GT_INTRINSIC)
GenTreeIntrinsic(callType, op1, NI_System_Math_Abs, nullptr R2RARG(nullEntry));
op2 = new (this, GT_INTRINSIC)
GenTreeIntrinsic(callType, op2, NI_System_Math_Abs, nullptr R2RARG(nullEntry));
}
if (!isNumber)
{
op2 = impCloneExpr(op2, &op2Clone, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 for Math.Min/Max non-Number"));
op1 = impCloneExpr(op1, &op1Clone, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for Math.Min/Max non-Number"));
}

ni = isMax ? NI_System_Math_MaxNumber : NI_System_Math_MinNumber;
GenTree* minMax =
new (this, GT_INTRINSIC) GenTreeIntrinsic(callType, op1, op2, ni, nullptr R2RARG(nullEntry));
static const CORINFO_CONST_LOOKUP nullEntry = {IAT_VALUE};

if (!isNumber)
{
GenTreeOp* isOp1Number = gtNewOperNode(GT_EQ, TYP_INT, op1Clone, gtCloneExpr(op1Clone));
GenTreeOp* isOp2Number = gtNewOperNode(GT_EQ, TYP_INT, op2Clone, gtCloneExpr(op2Clone));
GenTreeOp* isOkForMinMax = gtNewOperNode(GT_EQ, TYP_INT, isOp1Number, isOp2Number);
ni = isMax ? NI_System_Math_MaxNumber : NI_System_Math_MinNumber;
GenTree* minMax =
new (this, GT_INTRINSIC) GenTreeIntrinsic(callType, op1, op2, ni, nullptr R2RARG(nullEntry));

GenTreeOp* nanPropagator =
gtNewOperNode(GT_ADD, callType, gtCloneExpr(op1Clone), gtCloneExpr(op2Clone));
if (!isNumber)
{
GenTreeOp* isOp1Number = gtNewOperNode(GT_EQ, TYP_INT, op1Clone, gtCloneExpr(op1Clone));
GenTreeOp* isOp2Number = gtNewOperNode(GT_EQ, TYP_INT, op2Clone, gtCloneExpr(op2Clone));
GenTreeOp* isOkForMinMax = gtNewOperNode(GT_EQ, TYP_INT, isOp1Number, isOp2Number);

GenTreeOp* nanPropagator =
gtNewOperNode(GT_ADD, callType, gtCloneExpr(op1Clone), gtCloneExpr(op2Clone));

GenTreeQmark* qmark =
gtNewQmarkNode(callType, isOkForMinMax, gtNewColonNode(callType, minMax, nanPropagator));
// QMARK has to be a root node
unsigned tmp = lvaGrabTemp(true DEBUGARG("Temp for Qmark in Math.Min/Max non-Number"));
impStoreToTemp(tmp, qmark, CHECK_SPILL_NONE);
minMax = gtNewLclvNode(tmp, callType);
}

GenTreeQmark* qmark =
gtNewQmarkNode(callType, isOkForMinMax, gtNewColonNode(callType, minMax, nanPropagator));
// QMARK has to be a root node
unsigned tmp = lvaGrabTemp(true DEBUGARG("Temp for Qmark in Math.Min/Max non-Number"));
impStoreToTemp(tmp, qmark, CHECK_SPILL_NONE);
minMax = gtNewLclvNode(tmp, callType);
retNode = minMax;
}

retNode = minMax;
#endif // TARGET_RISCV64
}

Expand Down Expand Up @@ -8322,12 +8314,8 @@ bool Compiler::IsTargetIntrinsic(NamedIntrinsic intrinsicName)
case NI_System_Math_Abs:
case NI_System_Math_Sqrt:
case NI_System_Math_Max:
case NI_System_Math_MaxMagnitude:
case NI_System_Math_MaxMagnitudeNumber:
case NI_System_Math_MaxNumber:
case NI_System_Math_Min:
case NI_System_Math_MinMagnitude:
case NI_System_Math_MinMagnitudeNumber:
case NI_System_Math_MinNumber:
case NI_System_Math_MultiplyAddEstimate:
case NI_System_Math_ReciprocalEstimate:
Expand Down
Loading