From 782f0d28cb144dab4ebdc1f311f492ad2394f1d2 Mon Sep 17 00:00:00 2001 From: Sergey Andreenko Date: Fri, 26 Jun 2020 10:03:39 -0700 Subject: [PATCH 1/4] Require struct handler to be set after for CSE. --- src/coreclr/src/jit/optcse.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/coreclr/src/jit/optcse.cpp b/src/coreclr/src/jit/optcse.cpp index ddf7d8af1d6a68..82036d8983de44 100644 --- a/src/coreclr/src/jit/optcse.cpp +++ b/src/coreclr/src/jit/optcse.cpp @@ -2638,17 +2638,15 @@ class CSE_Heuristic // If all occurances were in GT_IND nodes it could still be NO_CLASS_HANDLE // CORINFO_CLASS_HANDLE structHnd = successfulCandidate->CseDsc()->csdStructHnd; - assert((structHnd != NO_CLASS_HANDLE) || (cseLclVarTyp != TYP_STRUCT)); - if (structHnd != NO_CLASS_HANDLE) - { - m_pCompiler->lvaSetStruct(cseLclVarNum, structHnd, false); - } -#ifdef FEATURE_SIMD - else if (varTypeIsSIMD(cseLclVarTyp)) + if (structHnd == NO_CLASS_HANDLE) { - m_pCompiler->lvaGetDesc(cseLclVarNum)->lvSIMDType = true; + assert(varTypeIsSIMD(cseLclVarTyp)); + // We are not setting it for `SIMD* indir` during the first path + // because it is not precise, see `optValnumCSE_Index`. + structHnd = m_pCompiler->gtGetStructHandle(successfulCandidate->CseDsc()->csdTree); } -#endif // FEATURE_SIMD + assert(structHnd != NO_CLASS_HANDLE); + m_pCompiler->lvaSetStruct(cseLclVarNum, structHnd, false); } m_pCompiler->lvaTable[cseLclVarNum].lvType = cseLclVarTyp; m_pCompiler->lvaTable[cseLclVarNum].lvIsCSE = true; @@ -3216,7 +3214,7 @@ bool Compiler::optIsCSEcandidate(GenTree* tree) // If this is a struct type, we can only consider it for CSE-ing if we can get at // its handle, so that we can create a temp. - if ((type == TYP_STRUCT) && (gtGetStructHandleIfPresent(tree) == NO_CLASS_HANDLE)) + if (varTypeIsStruct(type) && (gtGetStructHandleIfPresent(tree) == NO_CLASS_HANDLE)) { return false; } From 6294a31ea8822e60da832ba37491f3c83a77b8b4 Mon Sep 17 00:00:00 2001 From: Sergey Andreenko Date: Tue, 30 Jun 2020 03:10:24 -0700 Subject: [PATCH 2/4] Reenable the test. --- src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs b/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs index e51357e61fefb4..fc82fb83850f01 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Matrix4x4Tests.cs @@ -500,7 +500,6 @@ public void Matrix4x4CreateRotationYCenterTest() // A test for CreateFromAxisAngle(Vector3f,float) [Fact] - [SkipOnCoreClr("https://github.com/dotnet/runtime/issues/36586", RuntimeTestModes.JitStress)] public void Matrix4x4CreateFromAxisAngleTest() { float radians = MathHelper.ToRadians(-30.0f); From 8b5c7ab86ab9b85b3075ebbb42c91dc77665c5fe Mon Sep 17 00:00:00 2001 From: Sergey Andreenko Date: Tue, 30 Jun 2020 14:41:49 -0700 Subject: [PATCH 3/4] fix for empty cache --- src/coreclr/src/jit/hwintrinsic.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coreclr/src/jit/hwintrinsic.cpp b/src/coreclr/src/jit/hwintrinsic.cpp index dcff6dcaaefcce..0ce3ec25b69f5c 100644 --- a/src/coreclr/src/jit/hwintrinsic.cpp +++ b/src/coreclr/src/jit/hwintrinsic.cpp @@ -91,6 +91,10 @@ var_types Compiler::getBaseTypeFromArgIfNeeded(NamedIntrinsic intrinsic, CORINFO_CLASS_HANDLE Compiler::gtGetStructHandleForHWSIMD(var_types simdType, var_types simdBaseType) { + if (m_simdHandleCache == nullptr) + { + return NO_CLASS_HANDLE; + } if (simdType == TYP_SIMD16) { switch (simdBaseType) From 702211ebd52fd01d5ed3df43d3bb66365d29a651 Mon Sep 17 00:00:00 2001 From: Sergey Andreenko Date: Tue, 30 Jun 2020 21:10:50 -0700 Subject: [PATCH 4/4] Update the comment. --- src/coreclr/src/jit/optcse.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/jit/optcse.cpp b/src/coreclr/src/jit/optcse.cpp index 82036d8983de44..b7ece7ced07374 100644 --- a/src/coreclr/src/jit/optcse.cpp +++ b/src/coreclr/src/jit/optcse.cpp @@ -3212,8 +3212,8 @@ bool Compiler::optIsCSEcandidate(GenTree* tree) return false; } - // If this is a struct type, we can only consider it for CSE-ing if we can get at - // its handle, so that we can create a temp. + // If this is a struct type (including SIMD*), we can only consider it for CSE-ing + // if we can get its handle, so that we can create a temp. if (varTypeIsStruct(type) && (gtGetStructHandleIfPresent(tree) == NO_CLASS_HANDLE)) { return false;