Morph assert fix.
authorsivarv <sivarv@microsoft.com>
Wed, 8 Mar 2017 01:15:47 +0000 (17:15 -0800)
committersivarv <sivarv@microsoft.com>
Wed, 8 Mar 2017 01:22:09 +0000 (17:22 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/f6b9eb39d97cc0a2cf26b73574a0c38e226d4e0b

src/coreclr/src/jit/morph.cpp

index 3eb565a..80ba2dd 100644 (file)
@@ -17251,10 +17251,30 @@ Compiler::fgWalkResult Compiler::fgMorphStructField(GenTreePtr tree, fgWalkData*
                 tree->gtFlags &= ~GTF_GLOB_REF;
 
                 GenTreePtr parent = fgWalkPre->parentStack->Index(1);
-                if ((parent->gtOper == GT_ASG) && (parent->gtOp.gtOp1 == tree))
+                if (parent->gtOper == GT_ASG)
                 {
-                    tree->gtFlags |= GTF_VAR_DEF;
-                    tree->gtFlags |= GTF_DONT_CSE;
+                    if (parent->gtOp.gtOp1 == tree)
+                    {
+                        tree->gtFlags |= GTF_VAR_DEF;
+                        tree->gtFlags |= GTF_DONT_CSE;
+                    }
+
+                    // Promotion of struct containing struct fields where the field
+                    // is a struct with a single pointer sized scalar type field: in
+                    // this case struct promotion uses the type  of the underlying
+                    // scalar field as the type of struct field instead of recursively
+                    // promoting. This can lead to a case where we have a block-asgn
+                    // with its RHS replaced with a scalar type.  Mark RHS value as
+                    // DONT_CSE so that assertion prop will not do const propagation.
+                    // The reason this is required is that if RHS of a block-asg is a
+                    // constant, then it is interpreted as init-block incorrectly.
+                    //
+                    // TODO - This can also be avoided if we implement recursive struct
+                    // promotion.
+                    if (varTypeIsStruct(parent) && parent->gtOp.gtOp2 == tree && !varTypeIsStruct(tree))
+                    {
+                        tree->gtFlags |= GTF_DONT_CSE;
+                    }
                 }
 #ifdef DEBUG
                 if (verbose)