Skip to content

Commit

Permalink
Use gtNewSimdZeroNode rather than gtNewSIMDVectorZero
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Jun 1, 2021
1 parent 2dc5e64 commit 90ded5b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 30 deletions.
5 changes: 5 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,11 @@ class Compiler
unsigned simdSize,
bool isSimdAsHWIntrinsic);

GenTree* gtNewSimdZeroNode(var_types type,
CorInfoType simdBaseJitType,
unsigned simdSize,
bool isSimdAsHWIntrinsic);

GenTreeHWIntrinsic* gtNewScalarHWIntrinsicNode(var_types type, GenTree* op1, NamedIntrinsic hwIntrinsicID);
GenTreeHWIntrinsic* gtNewScalarHWIntrinsicNode(var_types type,
GenTree* op1,
Expand Down
66 changes: 36 additions & 30 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17460,39 +17460,19 @@ GenTree* Compiler::gtGetSIMDZero(var_types simdType, CorInfoType simdBaseJitType
unsigned size = genTypeSize(simdType);
if (isHWSIMD)
{
#if defined(TARGET_XARCH) && defined(FEATURE_HW_INTRINSICS)
switch (simdType)
{
case TYP_SIMD16:
if (compExactlyDependsOn(InstructionSet_SSE))
{
// We only return the HWIntrinsicNode if SSE is supported, since it is possible for
// the user to disable the SSE HWIntrinsic support via the COMPlus configuration knobs
// even though the hardware vector types are still available.
return gtNewSimdHWIntrinsicNode(simdType, NI_Vector128_get_Zero, simdBaseJitType, size);
}
return nullptr;
case TYP_SIMD32:
if (compExactlyDependsOn(InstructionSet_AVX))
{
// We only return the HWIntrinsicNode if AVX is supported, since it is possible for
// the user to disable the AVX HWIntrinsic support via the COMPlus configuration knobs
// even though the hardware vector types are still available.
return gtNewSimdHWIntrinsicNode(simdType, NI_Vector256_get_Zero, simdBaseJitType, size);
}
return nullptr;
default:
break;
}
#endif // TARGET_XARCH && FEATURE_HW_INTRINSICS
#if defined(FEATURE_HW_INTRINSICS)
return gtNewSimdZeroNode(simdType, simdBaseJitType, size, /* isSimdAsHWIntrinsic */ false);
#else
JITDUMP("Coudn't find the matching SIMD type for %s<%s> in gtGetSIMDZero\n", varTypeName(simdType),
varTypeName(JitType2PreciseVarType(simdBaseJitType)));

return nullptr;
#endif // FEATURE_HW_INTRINSICS
}
else
{
return gtNewSIMDVectorZero(simdType, simdBaseJitType, size);
}
return nullptr;
}
#endif // FEATURE_SIMD

Expand Down Expand Up @@ -19043,11 +19023,11 @@ GenTree* Compiler::gtNewSimdAbsNode(
nullptr DEBUGARG("Clone op1 for vector abs"));

// op1 = op1 < Zero
tmp = gtNewSIMDVectorZero(type, simdBaseJitType, simdSize);
tmp = gtNewSimdZeroNode(type, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
op1 = gtNewSimdCmpOpNode(GT_LT, type, op1, tmp, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);

// tmp = Zero - op1Dup1
tmp = gtNewSIMDVectorZero(type, simdBaseJitType, simdSize);
tmp = gtNewSimdZeroNode(type, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
tmp = gtNewSimdBinOpNode(GT_SUB, type, tmp, op1Dup1, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);

// result = ConditionalSelect(op1, tmp, op1Dup2)
Expand Down Expand Up @@ -21086,7 +21066,7 @@ GenTree* Compiler::gtNewSimdUnOpNode(genTreeOps op,
assert(compIsaSupportedDebugOnly(InstructionSet_AVX));
assert(varTypeIsFloating(simdBaseType) || compIsaSupportedDebugOnly(InstructionSet_AVX2));
}
op2 = gtNewSIMDVectorZero(type, simdBaseJitType, simdSize);
op2 = gtNewSimdZeroNode(type, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);

// Zero - op1
return gtNewSimdBinOpNode(GT_SUB, type, op2, op1, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
Expand Down Expand Up @@ -21125,7 +21105,7 @@ GenTree* Compiler::gtNewSimdUnOpNode(genTreeOps op,
else
{
// Zero - op1
op2 = gtNewSIMDVectorZero(type, simdBaseJitType, simdSize);
op2 = gtNewSimdZeroNode(type, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
return gtNewSimdBinOpNode(GT_SUB, type, op2, op1, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
}
}
Expand Down Expand Up @@ -21229,6 +21209,32 @@ GenTree* Compiler::gtNewSimdWithElementNode(var_types type,
return gtNewSimdHWIntrinsicNode(type, op1, op2, op3, hwIntrinsicID, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
}

GenTree* Compiler::gtNewSimdZeroNode(var_types type,
CorInfoType simdBaseJitType,
unsigned simdSize,
bool isSimdAsHWIntrinsic)
{
assert(IsBaselineSimdIsaSupportedDebugOnly());

assert(varTypeIsSIMD(type));
assert(getSIMDTypeForSize(simdSize) == type);

var_types simdBaseType = JitType2PreciseVarType(simdBaseJitType);
assert(varTypeIsArithmetic(simdBaseType));

NamedIntrinsic intrinsic = NI_Illegal;

#if defined(TARGET_XARCH)
intrinsic = (simdSize == 32) ? NI_Vector256_get_Zero : NI_Vector128_get_Zero;
#elif defined(TARGET_ARM64)
intrinsic = (simdSize == 16) ? NI_Vector128_get_Zero : NI_Vector64_get_Zero;
#else
#error Unsupported platform
#endif // !TARGET_XARCH && !TARGET_ARM64

return gtNewSimdHWIntrinsicNode(type, intrinsic, simdBaseJitType, simdSize, isSimdAsHWIntrinsic);
}

GenTreeHWIntrinsic* Compiler::gtNewScalarHWIntrinsicNode(var_types type, GenTree* op1, NamedIntrinsic hwIntrinsicID)
{
SetOpLclRelatedToSIMDIntrinsic(op1);
Expand Down

0 comments on commit 90ded5b

Please sign in to comment.