Updating SSE_StaticCast and AVX_StaticCast to set the correct type on the returned...
authorTanner Gooding <tagoo@outlook.com>
Sat, 30 Jun 2018 05:21:22 +0000 (22:21 -0700)
committerTanner Gooding <tagoo@outlook.com>
Tue, 3 Jul 2018 01:59:29 +0000 (18:59 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/e3292deddb16defb8d431ec456cf351dd95102c1

src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/hwintrinsicxarch.cpp
src/coreclr/src/jit/simd.cpp

index 2cbf668..da134df 100644 (file)
@@ -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);
index 850ff37..1fe22cf 100644 (file)
@@ -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;
index 5931b83..6008243 100644 (file)
@@ -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.