From: Pat Gavlin Date: Mon, 21 Nov 2016 21:25:49 +0000 (-0800) Subject: Do not treat certain calls as intrinsics for RyuJIT/x86. X-Git-Tag: submit/tizen/20210909.063632~11030^2~8846^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8fb215b5b42c5b803563bc3c569e8d814cdc1c17;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Do not treat certain calls as intrinsics for RyuJIT/x86. On x86 RyuJIT, importing intrinsics that are implemented as user calls can cause incorrect calculation of the depth of the stack if these intrinsics are used as arguments to another call. This causes bad code generation for certain EH constructs. Instead of implementing these intrinsics as intrinsics, simply import them as calls. Commit migrated from https://github.com/dotnet/coreclr/commit/2e210ce935a31268a02b52a10be69bc5e951071c --- diff --git a/src/coreclr/src/jit/importer.cpp b/src/coreclr/src/jit/importer.cpp index 1802125..46ecf03 100644 --- a/src/coreclr/src/jit/importer.cpp +++ b/src/coreclr/src/jit/importer.cpp @@ -3344,9 +3344,9 @@ GenTreePtr Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, op1 = nullptr; -#ifdef LEGACY_BACKEND +#if defined(LEGACY_BACKEND) if (IsTargetIntrinsic(intrinsicID)) -#else +#elif !defined(_TARGET_X86_) // Intrinsics that are not implemented directly by target instructions will // be re-materialized as users calls in rationalizer. For prefixed tail calls, // don't do this optimization, because @@ -3354,6 +3354,11 @@ GenTreePtr Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, // b) It will be non-trivial task or too late to re-materialize a surviving // tail prefixed GT_INTRINSIC as tail call in rationalizer. if (!IsIntrinsicImplementedByUserCall(intrinsicID) || !tailCall) +#else + // On x86 RyuJIT, importing intrinsics that are implemented as user calls can cause incorrect calculation + // of the depth of the stack if these intrinsics are used as arguments to another call. This causes bad + // code generation for certain EH constructs. + if (!IsIntrinsicImplementedByUserCall(intrinsicID)) #endif { switch (sig->numArgs) diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_280127/DevDiv_280127.cs b/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_280127/DevDiv_280127.cs new file mode 100644 index 0000000..3f8270f --- /dev/null +++ b/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_280127/DevDiv_280127.cs @@ -0,0 +1,37 @@ +// 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; + +// The original repro for this test was an assertion after code generation that the actual maximum depth of the stack +// was less than or identical to the estimated depth of the stack as calculated during morph. The calculation was +// incorrect when a math intrinsic was used as an argument to a function with on-stack parameters (e.g. the call to +// `M` on line 18). + +static class C +{ + struct S + { + int a, b, c, d; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static int N(S s, float d) + { + return 100; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static int M(double d) + { + N(new S(), (float)(Math.Atan2(d, 2.0) * 180 / Math.PI)); + return 100; + } + + static int Main() + { + return M(2.0); + } +} diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_280127/DevDiv_280127.csproj b/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_280127/DevDiv_280127.csproj new file mode 100644 index 0000000..ec9776d --- /dev/null +++ b/src/coreclr/tests/src/JIT/Regression/JitBlue/DevDiv_280127/DevDiv_280127.csproj @@ -0,0 +1,46 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + + 7a9bfb7d + + + + + + + + + False + + + + + True + + + + + + + + + $(JitPackagesConfigFileDirectory)minimal\project.json + $(JitPackagesConfigFileDirectory)minimal\project.lock.json + + + + +