From 089448cb2ef0457c18a0beea0421489af2409c33 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Fri, 29 Jun 2018 22:21:22 -0700 Subject: [PATCH] Updating SSE_StaticCast and AVX_StaticCast to set the correct type on the returned node. Commit migrated from https://github.com/dotnet/coreclr/commit/e3292deddb16defb8d431ec456cf351dd95102c1 --- src/coreclr/src/jit/compiler.h | 2 +- src/coreclr/src/jit/hwintrinsicxarch.cpp | 4 ++-- src/coreclr/src/jit/simd.cpp | 14 +++++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/coreclr/src/jit/compiler.h b/src/coreclr/src/jit/compiler.h index 2cbf668..da134df 100644 --- a/src/coreclr/src/jit/compiler.h +++ b/src/coreclr/src/jit/compiler.h @@ -7527,7 +7527,7 @@ private: // Pops and returns GenTree node from importers type stack. // Normalizes TYP_STRUCT value in case of GT_CALL, GT_RET_EXPR and arg nodes. - GenTree* impSIMDPopStack(var_types type, bool expectAddr = false); + GenTree* impSIMDPopStack(var_types type, bool expectAddr = false, CORINFO_CLASS_HANDLE structType = nullptr); // Create a GT_SIMD tree for a Get property of SIMD vector with a fixed index. GenTreeSIMD* impSIMDGetFixed(var_types simdType, var_types baseType, unsigned simdSize, int index); diff --git a/src/coreclr/src/jit/hwintrinsicxarch.cpp b/src/coreclr/src/jit/hwintrinsicxarch.cpp index 850ff37..1fe22cf 100644 --- a/src/coreclr/src/jit/hwintrinsicxarch.cpp +++ b/src/coreclr/src/jit/hwintrinsicxarch.cpp @@ -911,7 +911,7 @@ GenTree* Compiler::impSSEIntrinsic(NamedIntrinsic intrinsic, // the type system. It is safe to do this here since the retNode type // and the signature return type are both TYP_SIMD16. assert(sig->numArgs == 1); - retNode = impSIMDPopStack(TYP_SIMD16); + retNode = impSIMDPopStack(TYP_SIMD16, false, sig->retTypeClass); SetOpLclRelatedToSIMDIntrinsic(retNode); assert(retNode->gtType == getSIMDTypeForSize(getSIMDTypeSizeInBytes(sig->retTypeSigClass))); break; @@ -1232,7 +1232,7 @@ GenTree* Compiler::impAvxOrAvx2Intrinsic(NamedIntrinsic intrinsic, // the type system. It is safe to do this here since the retNode type // and the signature return type are both TYP_SIMD32. assert(sig->numArgs == 1); - retNode = impSIMDPopStack(TYP_SIMD32); + retNode = impSIMDPopStack(TYP_SIMD32, false, sig->retTypeClass); SetOpLclRelatedToSIMDIntrinsic(retNode); assert(retNode->gtType == getSIMDTypeForSize(getSIMDTypeSizeInBytes(sig->retTypeSigClass))); break; diff --git a/src/coreclr/src/jit/simd.cpp b/src/coreclr/src/jit/simd.cpp index 5931b83..6008243 100644 --- a/src/coreclr/src/jit/simd.cpp +++ b/src/coreclr/src/jit/simd.cpp @@ -997,12 +997,15 @@ const SIMDIntrinsicInfo* Compiler::getSIMDIntrinsicInfo(CORINFO_CLASS_HANDLE* in // Arguments: // type - the type of value that the caller expects to be popped off the stack. // expectAddr - if true indicates we are expecting type stack entry to be a TYP_BYREF. +// structType - the class handle to use when normalizing if it is not the same as the stack entry class handle; +// this can happen for certain scenarios, such as folding away a static cast, where we want the +// value popped to have the type that would have been returned. // // Notes: // If the popped value is a struct, and the expected type is a simd type, it will be set // to that type, otherwise it will assert if the type being popped is not the expected type. -GenTree* Compiler::impSIMDPopStack(var_types type, bool expectAddr) +GenTree* Compiler::impSIMDPopStack(var_types type, bool expectAddr, CORINFO_CLASS_HANDLE structType) { StackEntry se = impPopStack(); typeInfo ti = se.seTypeInfo; @@ -1046,8 +1049,13 @@ GenTree* Compiler::impSIMDPopStack(var_types type, bool expectAddr) if (varTypeIsStruct(tree) && ((tree->OperGet() == GT_RET_EXPR) || (tree->OperGet() == GT_CALL) || isParam)) { assert(ti.IsType(TI_STRUCT)); - CORINFO_CLASS_HANDLE structType = ti.GetClassHandleForValueClass(); - tree = impNormStructVal(tree, structType, (unsigned)CHECK_SPILL_ALL); + + if (structType == nullptr) + { + structType = ti.GetClassHandleForValueClass(); + } + + tree = impNormStructVal(tree, structType, (unsigned)CHECK_SPILL_ALL); } // Now set the type of the tree to the specialized SIMD struct type, if applicable. -- 2.7.4