From 776b2bf39f3ef429d9e92633d3de4337f8b42bfc Mon Sep 17 00:00:00 2001 From: Eugene Rozenfeld Date: Fri, 15 Sep 2017 13:34:21 -0700 Subject: [PATCH] Fix check for recursive call in the importer. (#13990) The check for recursive call was incorrect when processing an inlineee. The change had no diffs with jit-diff --frameworks --tests so I added a test where this change results in a codegen diff: the call to C is inlined with this change but is not inlined without it. --- src/jit/compiler.h | 7 +++- src/jit/importer.cpp | 2 +- .../JIT/opt/FastTailCall/FastTailCallInlining.cs | 39 +++++++++++++++++++ .../opt/FastTailCall/FastTailCallInlining.csproj | 45 ++++++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 tests/src/JIT/opt/FastTailCall/FastTailCallInlining.cs create mode 100644 tests/src/JIT/opt/FastTailCall/FastTailCallInlining.csproj diff --git a/src/jit/compiler.h b/src/jit/compiler.h index 86917d9..7c99a69 100644 --- a/src/jit/compiler.h +++ b/src/jit/compiler.h @@ -2218,7 +2218,12 @@ public: // Note when inlining, this looks for calls back to the root method. bool gtIsRecursiveCall(GenTreeCall* call) { - return (call->gtCallMethHnd == impInlineRoot()->info.compMethodHnd); + return gtIsRecursiveCall(call->gtCallMethHnd); + } + + bool gtIsRecursiveCall(CORINFO_METHOD_HANDLE callMethodHandle) + { + return (callMethodHandle == impInlineRoot()->info.compMethodHnd); } //------------------------------------------------------------------------- diff --git a/src/jit/importer.cpp b/src/jit/importer.cpp index 580e2b8..90d1618 100644 --- a/src/jit/importer.cpp +++ b/src/jit/importer.cpp @@ -6993,7 +6993,7 @@ var_types Compiler::impImportCall(OPCODE opcode, exactContextNeedsRuntimeLookup = callInfo->exactContextNeedsRuntimeLookup == TRUE; // Recursive call is treated as a loop to the begining of the method. - if (methHnd == info.compMethodHnd) + if (gtIsRecursiveCall(methHnd)) { #ifdef DEBUG if (verbose) diff --git a/tests/src/JIT/opt/FastTailCall/FastTailCallInlining.cs b/tests/src/JIT/opt/FastTailCall/FastTailCallInlining.cs new file mode 100644 index 0000000..81ffd72 --- /dev/null +++ b/tests/src/JIT/opt/FastTailCall/FastTailCallInlining.cs @@ -0,0 +1,39 @@ +// 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; + +public class Test +{ + public static int Main() + { + A(2); + return 100; + } + + public static void A(int i) + { + if (i > 0) + { + B(--i); + } + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void B(int i) + { + C(i); + A(--i); + } + + public static void C(int i) + { + Console.WriteLine("In C"); + if (i==0) + { + Console.WriteLine("In C"); + } + } +} diff --git a/tests/src/JIT/opt/FastTailCall/FastTailCallInlining.csproj b/tests/src/JIT/opt/FastTailCall/FastTailCallInlining.csproj new file mode 100644 index 0000000..4481224 --- /dev/null +++ b/tests/src/JIT/opt/FastTailCall/FastTailCallInlining.csproj @@ -0,0 +1,45 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + + + + + + + + + False + + + + + None + True + True + True + True + True + True + $(DefineConstants);CORECLR + + + + + + + + + + + -- 2.7.4