Run fgMorphCopyBlock for newly inserted assignment
authorJonghyun Park <parjong@gmail.com>
Wed, 1 Jun 2016 22:35:08 +0000 (07:35 +0900)
committerJonghyun Park <parjong@gmail.com>
Wed, 1 Jun 2016 23:10:45 +0000 (08:10 +0900)
When one return modification is turned on, the current implementation of
fgMorphBlocks converts the return statement as an assigment at the end of
block aftter fgMorphStmts is performed.

As a result, unfortunately, the newly inserted assignment statement is
never morphed, which results in some strange behavior inside codegen
(which is discussed in dotnet/coreclr#5357).

This commit tries to run fgMorphCopyBlock on newly inserted assignment in
order to fix dotnet/coreclr#5357.

Commit migrated from https://github.com/dotnet/coreclr/commit/6b81f2252f1815b6c5cf6776206d623e625e1712

src/coreclr/src/jit/morph.cpp

index e09e96b..495f0e2 100644 (file)
@@ -14856,7 +14856,9 @@ void                Compiler::fgMorphBlocks()
                     noway_assert(ret->gtGetOp1() != nullptr);
                     noway_assert(ret->gtGetOp2() == nullptr);
 
-                    last->gtStmt.gtStmtExpr = gtNewTempAssign(genReturnLocal, ret->gtGetOp1());
+                    GenTreePtr tree = gtNewTempAssign(genReturnLocal, ret->gtGetOp1());
+
+                    last->gtStmt.gtStmtExpr = (tree->OperIsCopyBlkOp()) ? fgMorphCopyBlock(tree) : tree;
 
                     //make sure that copy-prop ignores this assignment.
                     last->gtStmt.gtStmtExpr->gtFlags |= GTF_DONT_CSE;