From 32df6797cb5704edb589250f8bfeae8c275e9994 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Mon, 6 Sep 2021 15:14:11 +0300 Subject: [PATCH] Allow instrumentation for methods with explicit tail calls (#58632) --- src/coreclr/jit/fgbasic.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index 6c65586fbca1c..57c94e773ae1b 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -2722,9 +2722,12 @@ unsigned Compiler::fgMakeBasicBlocks(const BYTE* codeAddr, IL_OFFSET codeSize, F if (fgCanSwitchToOptimized() && fgMayExplicitTailCall()) { // Method has an explicit tail call that may run like a loop or may not be generated as a tail - // call in tier 0, switch to optimized to avoid spending too much time running slower code and - // to avoid stack overflow from recursion - fgSwitchToOptimized(); + // call in tier 0, switch to optimized to avoid spending too much time running slower code + if (!opts.jitFlags->IsSet(JitFlags::JIT_FLAG_BBINSTR) || + ((info.compFlags & CORINFO_FLG_DISABLE_TIER0_FOR_LOOPS) != 0)) + { + fgSwitchToOptimized(); + } } } else