Fixes GitHub Issue 16065
authorBrian Sullivan <briansul@microsoft.com>
Wed, 7 Feb 2018 02:27:52 +0000 (18:27 -0800)
committerBrian Sullivan <briansul@microsoft.com>
Thu, 8 Feb 2018 02:20:35 +0000 (18:20 -0800)
commit36ca001ea94c41305ab4834dd31b7d3c2210892a
tree458359dec181d1198c2e2231326b7cee78de98b0
parent2d9eba9706e67c565c6acf628784244f7711d80f
Fixes GitHub Issue 16065
Bug in the CSE phase when a CSE use contains a CSE def

For the error cases we could unmark or discard a CSE def. This CSE def might be needed when
 performing a subsequent CSE replacement.  This could lead to an uninitialized value being
 used for the CSE use.

Changed optUnmarkCSE method to return a bool instead of a void.
Changed optValuenumCSE_UnmarkCSEs  to take a write-back mutable wbKeepList argument
Removed an unreachable code block in fgRemoveStmt and replaced it with a noway_assert
Added method headers for optUnmarkCSE and optUnmarkCSEs
Removed the code that allowed unmarking of a CSE def, instead we return false
Retyped the second arguments to optUnmarksCSEs and optValueNumCSE_UnmarkCSEs
 to support appending new nodes to keep using wbKeepList
Code modifications to PerformCSE() to support collecting both persistent side effects and
 any nested CSE defs found in CSE uses.  Move the location of the call to
optValueNumCSE_UnmarkCSEs so that it comes before the decision to create a GT_COMMA node
 for the cse use.

Commit migrated from https://github.com/dotnet/coreclr/commit/eee738adae200f39296e0d3536be07b19be7649e
src/coreclr/src/jit/compiler.h
src/coreclr/src/jit/flowgraph.cpp
src/coreclr/src/jit/optcse.cpp
src/coreclr/tests/src/JIT/opt/CSE/GitHub_16065a.cs [new file with mode: 0644]
src/coreclr/tests/src/JIT/opt/CSE/GitHub_16065a.csproj [new file with mode: 0644]
src/coreclr/tests/src/JIT/opt/CSE/GitHub_16065b.cs [new file with mode: 0644]
src/coreclr/tests/src/JIT/opt/CSE/GitHub_16065b.csproj [new file with mode: 0644]