Skip to content

Commit c884372

Browse files
Fix VNZeroForType's handling of SIMD types
Previously this codepath was reachable, but did not matter as the returned values were immediately discarded because of the conservative logic in VNApplySelectorsTypeCheck. This is still more or less the case, but let's just fix it properly.
1 parent 132f31f commit c884372

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/coreclr/jit/valuenum.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,12 @@ ValueNum ValueNumStore::VNZeroForType(var_types typ)
18141814
case TYP_SIMD12:
18151815
case TYP_SIMD16:
18161816
case TYP_SIMD32:
1817-
return VNForLongCon(0);
1817+
// We do not have the base type - a "fake" one will have to do. Note that we cannot
1818+
// use the HWIntrinsic "get_Zero" VNFunc here. This is because they only represent
1819+
// "fully zeroed" vectors, and here we may be loading one from memory, leaving upper
1820+
// bits undefined. So using "SIMD_Init" is "the next best thing", so to speak, and
1821+
// TYP_FLOAT is one of the more popular base types, so that's why we use it here.
1822+
return VNForFunc(typ, VNF_SIMD_Init, VNForFloatCon(0), VNForSimdType(genTypeSize(typ), TYP_FLOAT));
18181823
#endif // FEATURE_SIMD
18191824

18201825
// These should be unreached.
@@ -1860,6 +1865,17 @@ ValueNum ValueNumStore::VNOneForType(var_types typ)
18601865
}
18611866
}
18621867

1868+
#ifdef FEATURE_SIMD
1869+
ValueNum ValueNumStore::VNForSimdType(unsigned simdSize, var_types simdBaseType)
1870+
{
1871+
ValueNum baseTypeVN = VNForIntCon(INT32(simdBaseType));
1872+
ValueNum sizeVN = VNForIntCon(simdSize);
1873+
ValueNum simdTypeVN = VNForFunc(TYP_REF, VNF_SimdType, sizeVN, baseTypeVN);
1874+
1875+
return simdTypeVN;
1876+
}
1877+
#endif // FEATURE_SIMD
1878+
18631879
class Object* ValueNumStore::s_specialRefConsts[] = {nullptr, nullptr, nullptr};
18641880

18651881
//----------------------------------------------------------------------------------------
@@ -9510,9 +9526,7 @@ void Compiler::fgValueNumberSimd(GenTree* tree)
95109526

95119527
if (encodeResultType)
95129528
{
9513-
ValueNum vnSize = vnStore->VNForIntCon(simdNode->GetSimdSize());
9514-
ValueNum vnBaseType = vnStore->VNForIntCon(INT32(simdNode->GetSimdBaseType()));
9515-
ValueNum simdTypeVN = vnStore->VNForFunc(TYP_REF, VNF_SimdType, vnSize, vnBaseType);
9529+
ValueNum simdTypeVN = vnStore->VNForSimdType(simdNode->GetSimdSize(), simdNode->GetSimdBaseType());
95169530
resvnp.SetBoth(simdTypeVN);
95179531

95189532
#ifdef DEBUG
@@ -9627,9 +9641,8 @@ void Compiler::fgValueNumberHWIntrinsic(GenTree* tree)
96279641

96289642
if (encodeResultType)
96299643
{
9630-
ValueNum vnSize = vnStore->VNForIntCon(hwIntrinsicNode->GetSimdSize());
9631-
ValueNum vnBaseType = vnStore->VNForIntCon(INT32(hwIntrinsicNode->GetSimdBaseType()));
9632-
ValueNum simdTypeVN = vnStore->VNForFunc(TYP_REF, VNF_SimdType, vnSize, vnBaseType);
9644+
ValueNum simdTypeVN =
9645+
vnStore->VNForSimdType(hwIntrinsicNode->GetSimdSize(), hwIntrinsicNode->GetSimdBaseType());
96339646
resvnp.SetBoth(simdTypeVN);
96349647

96359648
#ifdef DEBUG

src/coreclr/jit/valuenum.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ class ValueNumStore
463463
// It returns NoVN for a "typ" that has no one value, such as TYP_REF.
464464
ValueNum VNOneForType(var_types typ);
465465

466+
#ifdef FEATURE_SIMD
467+
// A helper function for constructing VNF_SimdType VNs.
468+
ValueNum VNForSimdType(unsigned simdSize, var_types simdBaseType);
469+
#endif // FEATURE_SIMD
470+
466471
// Create or return the existimg value number representing a singleton exception set
467472
// for the the exception value "x".
468473
ValueNum VNExcSetSingleton(ValueNum x);

0 commit comments

Comments
 (0)