Skip to content

Commit

Permalink
Consistently use fgMakeMultiUse in the gtNewSimd*Node APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Jan 3, 2023
1 parent 8843b24 commit edb2ce8
Showing 1 changed file with 40 additions and 121 deletions.
161 changes: 40 additions & 121 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19080,12 +19080,8 @@ GenTree* Compiler::gtNewSimdAbsNode(
GenTree* tmp;
CORINFO_CLASS_HANDLE clsHnd = gtGetStructHandleForSimdOrHW(type, simdBaseJitType, isSimdAsHWIntrinsic);

GenTree* op1Dup1;
op1 = impCloneExpr(op1, &op1Dup1, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op1 for vector abs"));

GenTree* op1Dup2;
op1Dup1 =
impCloneExpr(op1Dup1, &op1Dup2, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op1 for vector abs"));
GenTree* op1Dup1 = fgMakeMultiUse(&op1, clsHnd);
GenTree* op1Dup2 = fgMakeMultiUse(&op1Dup1, clsHnd);

// op1 = op1 < Zero
tmp = gtNewZeroConNode(type);
Expand Down Expand Up @@ -19402,14 +19398,10 @@ GenTree* Compiler::gtNewSimdBinOpNode(genTreeOps op,
else
{
// op1Dup = op1
GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector multiply"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);

// op2Dup = op2
GenTree* op2Dup;
op2 = impCloneExpr(op2, &op2Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 for vector multiply"));
GenTree* op2Dup = fgMakeMultiUse(&op2, clsHnd);;

// op1 = Sse2.ShiftRightLogical128BitLane(op1, 4)
op1 = gtNewSimdHWIntrinsicNode(type, op1, gtNewIconNode(4, TYP_INT),
Expand Down Expand Up @@ -19962,9 +19954,7 @@ GenTree* Compiler::gtNewSimdCmpOpNode(genTreeOps op,
GenTree* tmp =
gtNewSimdCmpOpNode(op, type, op1, op2, CORINFO_TYPE_INT, simdSize, isSimdAsHWIntrinsic);

tmp = impCloneExpr(tmp, &op1, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone tmp for vector Equals"));

op1 = fgMakeMultiUse(&tmp, clsHnd);
op2 = gtNewSimdHWIntrinsicNode(type, tmp, gtNewIconNode(SHUFFLE_ZWXY), NI_SSE2_Shuffle,
CORINFO_TYPE_INT, simdSize, isSimdAsHWIntrinsic);

Expand Down Expand Up @@ -20010,9 +20000,7 @@ GenTree* Compiler::gtNewSimdCmpOpNode(genTreeOps op,
if (!varTypeIsLong(simdBaseType))
{
assert(!varTypeIsFloating(simdBaseType));
GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector GreaterThanOrEqual"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);

// EQ(Max(op1, op2), op1)
GenTree* maxNode =
Expand All @@ -20033,13 +20021,8 @@ GenTree* Compiler::gtNewSimdCmpOpNode(genTreeOps op,
//
// result = BitwiseOr(op1, op2)

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector GreaterThanOrEqual"));

GenTree* op2Dup;
op2 = impCloneExpr(op2, &op2Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 for vector GreaterThanOrEqual"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);
GenTree* op2Dup = fgMakeMultiUse(&op2, clsHnd);

op1 = gtNewSimdCmpOpNode(GT_GT, type, op1, op2, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
op2 = gtNewSimdCmpOpNode(GT_EQ, type, op1Dup, op2Dup, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -20186,21 +20169,11 @@ GenTree* Compiler::gtNewSimdCmpOpNode(genTreeOps op,
//
// result = BitwiseOr(op1, op2)

GenTree* op1Dup1;
op1 = impCloneExpr(op1, &op1Dup1, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector GreaterThan"));

GenTree* op1Dup2;
op1Dup1 = impCloneExpr(op1Dup1, &op1Dup2, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector GreaterThan"));
GenTree* op1Dup1 = fgMakeMultiUse(&op1, clsHnd);
GenTree* op1Dup2 = fgMakeMultiUse(&op1Dup1, clsHnd);

GenTree* op2Dup1;
op2 = impCloneExpr(op2, &op2Dup1, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 for vector GreaterThan"));

GenTree* op2Dup2;
op2Dup1 = impCloneExpr(op2Dup1, &op2Dup2, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 vector GreaterThan"));
GenTree* op2Dup1 = fgMakeMultiUse(&op2, clsHnd);
GenTree* op2Dup2 = fgMakeMultiUse(&op2Dup1, clsHnd);

GenTree* t =
gtNewSimdCmpOpNode(op, type, op1, op2, CORINFO_TYPE_INT, simdSize, isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -20259,9 +20232,7 @@ GenTree* Compiler::gtNewSimdCmpOpNode(genTreeOps op,
if (!varTypeIsLong(simdBaseType))
{
assert(!varTypeIsFloating(simdBaseType));
GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector LessThanOrEqual"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);

// EQ(Min(op1, op2), op1)
GenTree* minNode =
Expand All @@ -20282,13 +20253,8 @@ GenTree* Compiler::gtNewSimdCmpOpNode(genTreeOps op,
//
// result = BitwiseOr(op1, op2)

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector LessThanOrEqual"));

GenTree* op2Dup;
op2 = impCloneExpr(op2, &op2Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 for vector LessThanOrEqual"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);
GenTree* op2Dup = fgMakeMultiUse(&op2, clsHnd);

op1 = gtNewSimdCmpOpNode(GT_LT, type, op1, op2, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
op2 = gtNewSimdCmpOpNode(GT_EQ, type, op1Dup, op2Dup, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -20435,21 +20401,11 @@ GenTree* Compiler::gtNewSimdCmpOpNode(genTreeOps op,
//
// result = BitwiseOr(op1, op2)

GenTree* op1Dup1;
op1 = impCloneExpr(op1, &op1Dup1, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector LessThan"));

GenTree* op1Dup2;
op1Dup1 = impCloneExpr(op1Dup1, &op1Dup2, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector LessThan"));

GenTree* op2Dup1;
op2 = impCloneExpr(op2, &op2Dup1, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 for vector LessThan"));
GenTree* op1Dup1 = fgMakeMultiUse(&op1, clsHnd);
GenTree* op1Dup2 = fgMakeMultiUse(&op1Dup1, clsHnd);

GenTree* op2Dup2;
op2Dup1 = impCloneExpr(op2Dup1, &op2Dup2, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 vector LessThan"));
GenTree* op2Dup1 = fgMakeMultiUse(&op2, clsHnd);
GenTree* op2Dup2 = fgMakeMultiUse(&op2Dup1, clsHnd);

GenTree* t =
gtNewSimdCmpOpNode(op, type, op1, op2, CORINFO_TYPE_INT, simdSize, isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -21586,11 +21542,8 @@ GenTree* Compiler::gtNewSimdMaxNode(var_types type,
return gtNewSimdHWIntrinsicNode(type, op1, op2, intrinsic, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
}

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op1 for vector Max"));

GenTree* op2Dup;
op2 = impCloneExpr(op2, &op2Dup, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op2 for vector Max"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);
GenTree* op2Dup = fgMakeMultiUse(&op2, clsHnd);

// op1 = op1 > op2
op1 = gtNewSimdCmpOpNode(GT_GT, type, op1, op2, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -21698,13 +21651,8 @@ GenTree* Compiler::gtNewSimdMinNode(var_types type,
GenTree* constVector =
gtNewSimdCreateBroadcastNode(type, constVal, CORINFO_TYPE_INT, simdSize, isSimdAsHWIntrinsic);

GenTree* constVectorDup1;
constVector = impCloneExpr(constVector, &constVectorDup1, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone constVector for vector Min"));

GenTree* constVectorDup2;
constVectorDup1 = impCloneExpr(constVectorDup1, &constVectorDup2, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone constVector for vector Min"));
GenTree* constVectorDup1 = fgMakeMultiUse(&constVector, clsHnd);
GenTree* constVectorDup2 = fgMakeMultiUse(&constVectorDup1, clsHnd);

// op1 = op1 - constVector
// -or-
Expand Down Expand Up @@ -21785,11 +21733,8 @@ GenTree* Compiler::gtNewSimdMinNode(var_types type,
return gtNewSimdHWIntrinsicNode(type, op1, op2, intrinsic, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
}

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op1 for vector Min"));

GenTree* op2Dup;
op2 = impCloneExpr(op2, &op2Dup, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op2 for vector Min"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);
GenTree* op2Dup = fgMakeMultiUse(&op2, clsHnd);

// op1 = op1 < op2
op1 = gtNewSimdCmpOpNode(GT_LT, type, op1, op2, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -21930,13 +21875,8 @@ GenTree* Compiler::gtNewSimdNarrowNode(var_types type,
CorInfoType opBaseJitType = (simdBaseType == TYP_INT) ? CORINFO_TYPE_LONG : CORINFO_TYPE_ULONG;
CORINFO_CLASS_HANDLE clsHnd = gtGetStructHandleForSimdOrHW(type, opBaseJitType, isSimdAsHWIntrinsic);

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector narrow"));

GenTree* op2Dup;
op2 = impCloneExpr(op2, &op2Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 for vector narrow"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);
GenTree* op2Dup = fgMakeMultiUse(&op2, clsHnd);

tmp1 = gtNewSimdHWIntrinsicNode(type, op1, op2, NI_AVX2_UnpackLow, simdBaseJitType, simdSize,
isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -22078,13 +22018,8 @@ GenTree* Compiler::gtNewSimdNarrowNode(var_types type,
// var tmp4 = Sse2.UnpackHigh(tmp1, tmp2);
// return Sse2.UnpackLow(tmp3, tmp4).As<T>();

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector narrow"));

GenTree* op2Dup;
op2 = impCloneExpr(op2, &op2Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector narrow"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);
GenTree* op2Dup = fgMakeMultiUse(&op2, clsHnd);

tmp1 = gtNewSimdHWIntrinsicNode(type, op1, op2, NI_SSE2_UnpackLow, simdBaseJitType, simdSize,
isSimdAsHWIntrinsic);
Expand All @@ -22093,13 +22028,8 @@ GenTree* Compiler::gtNewSimdNarrowNode(var_types type,

clsHnd = gtGetStructHandleForSimdOrHW(type, simdBaseJitType, isSimdAsHWIntrinsic);

GenTree* tmp1Dup;
tmp1 = impCloneExpr(tmp1, &tmp1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone tmp1 for vector narrow"));

GenTree* tmp2Dup;
tmp2 = impCloneExpr(tmp2, &tmp2Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone tmp2 for vector narrow"));
GenTree* tmp1Dup = fgMakeMultiUse(&tmp1, clsHnd);
GenTree* tmp2Dup = fgMakeMultiUse(&tmp2, clsHnd);

tmp3 = gtNewSimdHWIntrinsicNode(type, tmp1, tmp2, NI_SSE2_UnpackLow, simdBaseJitType, simdSize,
isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -22128,13 +22058,8 @@ GenTree* Compiler::gtNewSimdNarrowNode(var_types type,
CorInfoType opBaseJitType = (simdBaseType == TYP_INT) ? CORINFO_TYPE_LONG : CORINFO_TYPE_ULONG;
CORINFO_CLASS_HANDLE clsHnd = gtGetStructHandleForSimdOrHW(type, opBaseJitType, isSimdAsHWIntrinsic);

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector narrow"));

GenTree* op2Dup;
op2 = impCloneExpr(op2, &op2Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op2 for vector narrow"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);
GenTree* op2Dup = fgMakeMultiUse(&op2, clsHnd);

tmp1 = gtNewSimdHWIntrinsicNode(type, op1, op2, NI_SSE2_UnpackLow, simdBaseJitType, simdSize,
isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -22632,15 +22557,15 @@ GenTree* Compiler::gtNewSimdSumNode(

for (int i = 0; i < haddCount; i++)
{
op1 = impCloneExpr(op1, &tmp, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op1 for vector sum"));
tmp = fgMakeMultiUse(&op1, clsHnd);
op1 = gtNewSimdHWIntrinsicNode(simdType, op1, tmp, intrinsic, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
}

if (simdSize == 32)
{
intrinsic = (simdBaseType == TYP_FLOAT) ? NI_SSE_Add : NI_SSE2_Add;

op1 = impCloneExpr(op1, &tmp, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op1 for vector sum"));
tmp = fgMakeMultiUse(&op1, clsHnd);
op1 = gtNewSimdHWIntrinsicNode(TYP_SIMD16, op1, gtNewIconNode(0x01, TYP_INT), NI_AVX_ExtractVector128,
simdBaseJitType, simdSize, isSimdAsHWIntrinsic);

Expand Down Expand Up @@ -22668,7 +22593,7 @@ GenTree* Compiler::gtNewSimdSumNode(
{
if (simdSize == 8)
{
op1 = impCloneExpr(op1, &tmp, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op1 for vector sum"));
tmp = fgMakeMultiUse(&op1, clsHnd);
tmp = gtNewSimdHWIntrinsicNode(simdType, op1, tmp, NI_AdvSimd_AddPairwise, simdBaseJitType, simdSize,
isSimdAsHWIntrinsic);
}
Expand All @@ -22694,8 +22619,7 @@ GenTree* Compiler::gtNewSimdSumNode(

for (int i = 0; i < haddCount; i++)
{
op1 =
impCloneExpr(op1, &tmp, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op1 for vector sum"));
tmp = fgMakeMultiUse(&op1, clsHnd);
op1 = gtNewSimdHWIntrinsicNode(simdType, op1, tmp, NI_AdvSimd_Arm64_AddPairwise, simdBaseJitType,
simdSize, isSimdAsHWIntrinsic);
}
Expand Down Expand Up @@ -22924,9 +22848,7 @@ GenTree* Compiler::gtNewSimdWidenLowerNode(
{
CORINFO_CLASS_HANDLE clsHnd = gtGetStructHandleForSimdOrHW(type, simdBaseJitType, isSimdAsHWIntrinsic);

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector widen lower"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);

tmp1 = gtNewSimdHWIntrinsicNode(type, op1, tmp1, NI_SSE2_CompareLessThan, simdBaseJitType, simdSize,
isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -23047,8 +22969,7 @@ GenTree* Compiler::gtNewSimdWidenUpperNode(
assert(simdBaseType == TYP_FLOAT);
CORINFO_CLASS_HANDLE clsHnd = gtGetStructHandleForSimdOrHW(type, simdBaseJitType, isSimdAsHWIntrinsic);

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL, nullptr DEBUGARG("Clone op1 for vector widen upper"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);

tmp1 = gtNewSimdHWIntrinsicNode(type, op1, op1Dup, NI_SSE_MoveHighToLow, simdBaseJitType, simdSize,
isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -23100,9 +23021,7 @@ GenTree* Compiler::gtNewSimdWidenUpperNode(
{
CORINFO_CLASS_HANDLE clsHnd = gtGetStructHandleForSimdOrHW(type, simdBaseJitType, isSimdAsHWIntrinsic);

GenTree* op1Dup;
op1 = impCloneExpr(op1, &op1Dup, clsHnd, CHECK_SPILL_ALL,
nullptr DEBUGARG("Clone op1 for vector widen upper"));
GenTree* op1Dup = fgMakeMultiUse(&op1, clsHnd);

tmp1 = gtNewSimdHWIntrinsicNode(type, op1, tmp1, NI_SSE2_CompareLessThan, simdBaseJitType, simdSize,
isSimdAsHWIntrinsic);
Expand Down

0 comments on commit edb2ce8

Please sign in to comment.