From 39820ca657f2a6dd758973a72133a3556599c3d9 Mon Sep 17 00:00:00 2001 From: Brian Sullivan Date: Fri, 20 Sep 2019 12:05:01 -0700 Subject: [PATCH 1/3] 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: From e511f560fe73734c1aed2798546e05ac9d66ec44 Mon Sep 17 00:00:00 2001 From: Brian Sullivan Date: Fri, 20 Sep 2019 14:05:30 -0700 Subject: [PATCH 2/3] Fix typo --- src/jit/optimizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jit/optimizer.cpp b/src/jit/optimizer.cpp index 7072bbfdaef0..f1b75a29f5ac 100644 --- a/src/jit/optimizer.cpp +++ b/src/jit/optimizer.cpp @@ -6800,7 +6800,7 @@ void Compiler::optHoistLoopBlocks(unsigned loopNum, ArrayStack* blo 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 + // The logic in optVNIsLoopInvariant would 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)) From 37fed7f7be4ccb049f87984c7388e9a0ee420baf Mon Sep 17 00:00:00 2001 From: Brian Sullivan Date: Sat, 21 Sep 2019 13:57:25 -0700 Subject: [PATCH 3/3] Added back test: JIT\Regression\JitBlue\GitHub_26417 --- .../JitBlue/GitHub_26417/GitHub_26417.cs | 47 +++++++++++++++++++ .../JitBlue/GitHub_26417/GitHub_26417.csproj | 12 +++++ 2 files changed, 59 insertions(+) create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.csproj diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.cs b/tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.cs new file mode 100644 index 000000000000..6871962398e4 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.cs @@ -0,0 +1,47 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Runtime.CompilerServices; + +class GitHub_26417 +{ + static int _a; + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + static void MyWriteLine(int v) + { + Console.WriteLine(v); + if (v == 0) + { + throw new Exception(); + } + } + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + static void Test() + { + _a = 1; + + while (_a == 1) + { + MyWriteLine(_a); + _a = 0; + } + } + + static int Main() + { + int result = 100; + try { + Test(); + } + catch (Exception) + { + Console.WriteLine("FAILED"); + result = -1; + } + return result; + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.csproj new file mode 100644 index 000000000000..f3e1cbd44b40 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_26417/GitHub_26417.csproj @@ -0,0 +1,12 @@ + + + Exe + + + None + True + + + + +