From 39820ca657f2a6dd758973a72133a3556599c3d9 Mon Sep 17 00:00:00 2001 From: Brian Sullivan Date: Fri, 20 Sep 2019 12:05:01 -0700 Subject: [PATCH] New fix - only disable GT_CLS_VAR's --- src/jit/optimizer.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/jit/optimizer.cpp b/src/jit/optimizer.cpp index b63c454d6cea..7072bbfdaef0 100644 --- a/src/jit/optimizer.cpp +++ b/src/jit/optimizer.cpp @@ -6795,8 +6795,21 @@ void Compiler::optHoistLoopBlocks(unsigned loopNum, ArrayStack* blo bool IsTreeVNInvariant(GenTree* tree) { - return m_compiler->optVNIsLoopInvariant(tree->gtVNPair.GetLiberal(), m_loopNum, - &m_hoistContext->m_curLoopVnInvariantCache); + ValueNum vn = tree->gtVNPair.GetLiberal(); + + if (m_compiler->vnStore->IsVNConstant(vn)) + { + // It is unsafe to allow a GT_CLS_VAR that has been assigned a constant. + // The logic in optVNIsLoopInvariant woudl consider it to be loop-invariant, even + // if the assignment of the constant to the GT_CLS_VAR was inside the loop. + // + if (tree->OperIs(GT_CLS_VAR)) + { + return false; + } + } + + return m_compiler->optVNIsLoopInvariant(vn, m_loopNum, &m_hoistContext->m_curLoopVnInvariantCache); } public: