From a7f129cce3ee1ccbc119d771ae517f7e4f18b782 Mon Sep 17 00:00:00 2001 From: Carol Eidt Date: Tue, 15 May 2018 13:57:09 -0700 Subject: Add tests for struct-related issues --- .../Regression/JitBlue/GitHub_1133/GitHub_1133.cs | 56 +++++++++ .../JitBlue/GitHub_1133/GitHub_1133.csproj | 38 ++++++ .../JitBlue/GitHub_11407/GitHub_11407.cs | 28 +++++ .../JitBlue/GitHub_11407/GitHub_11407.csproj | 38 ++++++ .../Regression/JitBlue/GitHub_1161/GitHub_1161.cs | 42 +++++++ .../JitBlue/GitHub_1161/GitHub_1161.csproj | 38 ++++++ .../JitBlue/GitHub_11816/GitHub_11816.cs | 134 +++++++++++++++++++++ .../JitBlue/GitHub_11816/GitHub_11816.csproj | 38 ++++++ .../Regression/JitBlue/GitHub_2003/GitHub_2003.cs | 65 ++++++++++ .../JitBlue/GitHub_2003/GitHub_2003.csproj | 38 ++++++ .../Regression/JitBlue/GitHub_5556/GitHub_5556.cs | 52 ++++++++ .../JitBlue/GitHub_5556/GitHub_5556.csproj | 38 ++++++ 12 files changed, 605 insertions(+) create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_1133/GitHub_1133.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_1133/GitHub_1133.csproj create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_11407/GitHub_11407.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_11407/GitHub_11407.csproj create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_1161/GitHub_1161.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_1161/GitHub_1161.csproj create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_11816/GitHub_11816.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_11816/GitHub_11816.csproj create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_2003/GitHub_2003.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_2003/GitHub_2003.csproj create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_5556/GitHub_5556.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_5556/GitHub_5556.csproj (limited to 'tests/src') diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_1133/GitHub_1133.cs b/tests/src/JIT/Regression/JitBlue/GitHub_1133/GitHub_1133.cs new file mode 100644 index 0000000000..0b941f170f --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_1133/GitHub_1133.cs @@ -0,0 +1,56 @@ +// 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_1133 +{ + static Guid s_dt; + + [MethodImpl(MethodImplOptions.NoInlining)] + private static Guid TestValueTypesInInlinedMethods() + { + var dt = new Guid(); + + // This method, once inlined, should directly copy the newly created 'Guid' to s_dt. + Method1(dt); + + return dt; + } + + private static void Method1(Guid dt) + { + Method2(dt); + } + + private static void Method2(Guid dt) + { + Method3(dt); + } + + private static void Method3(Guid dt) + { + s_dt = dt; + } + + public static int Main() + { + int result = 100; + try + { + Guid g = TestValueTypesInInlinedMethods(); + if (g != s_dt) + { + result = -1; + } + } + catch (Exception) + { + result = -1; + } + + return result; + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_1133/GitHub_1133.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_1133/GitHub_1133.csproj new file mode 100644 index 0000000000..5bd417ae6c --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_1133/GitHub_1133.csproj @@ -0,0 +1,38 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-B8089FFA8D79} + 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 + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_11407/GitHub_11407.cs b/tests/src/JIT/Regression/JitBlue/GitHub_11407/GitHub_11407.cs new file mode 100644 index 0000000000..dcdbe72035 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_11407/GitHub_11407.cs @@ -0,0 +1,28 @@ +// 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. + +// This test has two effectively identical initializations of an +// array of byte vs. an array of structs containing a single byte field. +// They should generate the same code. + +using System; +using System.Runtime.CompilerServices; + +class GitHub_11407 +{ + struct foo { public byte b1, b2, b3, b4; } + [MethodImpl(MethodImplOptions.NoInlining)] + static foo getfoo() { return new foo(); } + + static int Main() + { + int returnVal = 100; + foo myFoo = getfoo(); + if (myFoo.b1 != 0 || myFoo.b2 != 0 || myFoo.b3 != 0 || myFoo.b4 != 0) + { + returnVal = -1; + } + return returnVal; + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_11407/GitHub_11407.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_11407/GitHub_11407.csproj new file mode 100644 index 0000000000..5bd417ae6c --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_11407/GitHub_11407.csproj @@ -0,0 +1,38 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-B8089FFA8D79} + 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 + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_1161/GitHub_1161.cs b/tests/src/JIT/Regression/JitBlue/GitHub_1161/GitHub_1161.cs new file mode 100644 index 0000000000..1e83bf2ca9 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_1161/GitHub_1161.cs @@ -0,0 +1,42 @@ +// 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. + +// This test illustrates a limitation in the JIT in that it will not promote +// a struct that has a single double register. See GitHub issue #1161. + +using System; +using System.Runtime.CompilerServices; + +class GitHub_1161 +{ + struct Number + { + private double value; + public static implicit operator Number(double value) + { + return new Number { value = value }; + } + public static implicit operator double(Number number) + { + return number.value; + } + public static Number operator +(Number x, Number y) + { + return x.value + y.value; + } + } + class Program + { + [MethodImpl(MethodImplOptions.NoInlining)] + static int Test() + { + Number x = 4, y = 2; + return (int)(x + y); + } + static int Main() + { + return (Test() == 6) ? 100 : -1; + } + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_1161/GitHub_1161.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_1161/GitHub_1161.csproj new file mode 100644 index 0000000000..5bd417ae6c --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_1161/GitHub_1161.csproj @@ -0,0 +1,38 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-B8089FFA8D79} + 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 + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_11816/GitHub_11816.cs b/tests/src/JIT/Regression/JitBlue/GitHub_11816/GitHub_11816.cs new file mode 100644 index 0000000000..985b1ff393 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_11816/GitHub_11816.cs @@ -0,0 +1,134 @@ +// 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. + +// This test captures the redundant struct zeroing from GitHub issue #11816. +// Since the issue was filed, the 'TestStructManuallyInlined' case has apparently +// gotten worse, as there is a MEMSET of the large struct to 0. + +using System; +using System.Numerics; +using System.Runtime.CompilerServices; + +class GitHub_11816 +{ + struct StructType + { + public Vector A; + public Vector B; + public Vector C; + public Vector D; + public Vector E; + public Vector F; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static Vector GetVector() + { + return new Vector(100); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void DoSomeWorkWithAStruct(ref Vector source, out Vector result) + { + StructType u; + u.A = new Vector(2) * source; + u.B = new Vector(3) * source; + u.C = new Vector(4) * source; + u.D = new Vector(5) * source; + u.E = new Vector(6) * source; + u.F = new Vector(7) * source; + result = u.A + u.B + u.C + u.D + u.E + u.F; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static float TestStruct() + { + Vector f = GetVector(); + for (int i = 0; i < 100; ++i) + { + DoSomeWorkWithAStruct(ref f, out f); + } + return f[0]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static void DoSomeWorkWithAStructAggressiveInlining(ref Vector source, out Vector result) + { + StructType u; + u.A = new Vector(2) * source; + u.B = new Vector(3) * source; + u.C = new Vector(4) * source; + u.D = new Vector(5) * source; + u.E = new Vector(6) * source; + u.F = new Vector(7) * source; + result = u.A + u.B + u.C + u.D + u.E + u.F; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static float TestStructAggressiveInlining() + { + Vector f = GetVector(); + for (int i = 0; i < 100; ++i) + { + DoSomeWorkWithAStructAggressiveInlining(ref f, out f); + } + return f[0]; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static float TestStructManuallyInlined() + { + Vector f = GetVector(); + for (int i = 0; i < 100; ++i) + { + StructType u; + u.A = new Vector(2) * f; + u.B = new Vector(3) * f; + u.C = new Vector(4) * f; + u.D = new Vector(5) * f; + u.E = new Vector(6) * f; + u.F = new Vector(7) * f; + f = u.A + u.B + u.C + u.D + u.E + u.F; + } + return f[0]; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + static void DoSomeWorkStructless(ref Vector source, out Vector result) + { + var a = new Vector(2) * source; + var b = new Vector(3) * source; + var c = new Vector(4) * source; + var d = new Vector(5) * source; + var e = new Vector(6) * source; + var f = new Vector(7) * source; + result = d + e + f + a + b + c; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static float TestStructless() + { + Vector f = GetVector(); + for (int i = 0; i < 100; ++i) + { + DoSomeWorkStructless(ref f, out f); + } + return f[0]; + } + + static int Main() + { + float value = 0.0F; + value += TestStruct(); + value -= TestStructAggressiveInlining(); + value += TestStructManuallyInlined(); + value -= TestStructless(); + if (!float.IsNaN(value)) + { + Console.WriteLine(value.ToString()); + return -1; + } + return 100; + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_11816/GitHub_11816.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_11816/GitHub_11816.csproj new file mode 100644 index 0000000000..5bd417ae6c --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_11816/GitHub_11816.csproj @@ -0,0 +1,38 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-B8089FFA8D79} + 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 + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_2003/GitHub_2003.cs b/tests/src/JIT/Regression/JitBlue/GitHub_2003/GitHub_2003.cs new file mode 100644 index 0000000000..77bb77661a --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_2003/GitHub_2003.cs @@ -0,0 +1,65 @@ +// 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. + +// This test has two effectively identical initializations of an +// array of byte vs. an array of structs containing a single byte field. +// They should generate the same code. + +using System; +using System.Runtime.CompilerServices; + +class GitHub_2003 +{ + static byte[] byteArray; + struct MyByte + { + private readonly byte _byte; + public MyByte(byte b) + { + _byte = b; + } + + public byte Value + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get { return _byte; } + } + } + static MyByte[] myByteArray; + + [MethodImpl(MethodImplOptions.NoInlining)] + static void initByteArray() + { + for (int j = 0; j < byteArray.Length; j++) + { + byteArray[j] = 123; + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void initMyByteArray() + { + for (int j = 0; j < myByteArray.Length; j++) + { + myByteArray[j] = new MyByte(123); + } + } + + static int Main() + { + byteArray = new byte[100]; + myByteArray = new MyByte[100]; + initByteArray(); + initMyByteArray(); + int returnVal = 100; + for (int j = 0; j < 100; j++) + { + if (byteArray[j] != myByteArray[j].Value) + { + returnVal = -1; + } + } + return returnVal; + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_2003/GitHub_2003.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_2003/GitHub_2003.csproj new file mode 100644 index 0000000000..5bd417ae6c --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_2003/GitHub_2003.csproj @@ -0,0 +1,38 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-B8089FFA8D79} + 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 + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_5556/GitHub_5556.cs b/tests/src/JIT/Regression/JitBlue/GitHub_5556/GitHub_5556.cs new file mode 100644 index 0000000000..3cfea7642f --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_5556/GitHub_5556.cs @@ -0,0 +1,52 @@ +// 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. + +// This test has two effectively identical methods, one of which copies +// its input paramter to a local, allowing it to be promoted. +// The JIT should be able to generate identical code for these. + +using System; +using System.Runtime.CompilerServices; + +class GitHub_5556 +{ + [MethodImpl(MethodImplOptions.NoInlining)] + public static long SpanAsParam(Span span) + { + long value = 0; + for (int i = 0; i < span.Length; i++) + { + value = span[i]; + } + return value; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static long SpanWithLocalCopy(Span span) + { + var spanLocal = span; + long value = 0; + for (int i = 0; i < spanLocal.Length; i++) + { + value = spanLocal[i]; + } + return value; + } + + static int Main() + { + long[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + Span mySpan = new Span(a); + int returnVal = 100; + if (SpanAsParam(mySpan) != 9) + { + returnVal = -1; + } + if (SpanWithLocalCopy(mySpan) != 9) + { + returnVal = -1; + } + return returnVal; + } +} diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_5556/GitHub_5556.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_5556/GitHub_5556.csproj new file mode 100644 index 0000000000..5bd417ae6c --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_5556/GitHub_5556.csproj @@ -0,0 +1,38 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-B8089FFA8D79} + 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 + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3