From bbc22f16b33191c9871f86b4bf1fc3c9271e0202 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Fri, 6 Dec 2024 10:23:59 -0800 Subject: [PATCH 1/4] Ensure that we don't try and optimize masks for promoted fields --- src/coreclr/jit/optimizemaskconversions.cpp | 11 ++- .../JitBlue/Runtime_110326/Runtime_110326.cs | 90 +++++++++++++++++++ .../Runtime_110326/Runtime_110326.csproj | 12 +++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.csproj diff --git a/src/coreclr/jit/optimizemaskconversions.cpp b/src/coreclr/jit/optimizemaskconversions.cpp index 7ab61c698d7e0..1685581b0523d 100644 --- a/src/coreclr/jit/optimizemaskconversions.cpp +++ b/src/coreclr/jit/optimizemaskconversions.cpp @@ -227,13 +227,22 @@ class MaskConversionsCheckVisitor final : public GenTreeVisitorInvalidateWeight(); return fgWalkResult::WALK_CONTINUE; } + + // Cannot convert any locals that r promoted struct fields + if (varDsc->lvIsStructField) + { + JITDUMP("is struct field. "); + weight->InvalidateWeight(); + return fgWalkResult::WALK_CONTINUE; + } + // TODO: Converting to a mask loses data - as each field is only a single bit. // For parameters, OSR locals, and locals which are used as vectors, then they // cannot be stored as a mask as data will be lost. // For all of these, conversions could be done by creating a new store of type mask. // Then uses as mask could be converted to type mask and pointed to use the new // definition. The weighting would need updating to take this into account. - else if (isLocalUse && !hasConversion) + if (isLocalUse && !hasConversion) { JITDUMP("is used as vector. "); weight->InvalidateWeight(); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs new file mode 100644 index 0000000000000..059a9c4b3d2d0 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs @@ -0,0 +1,90 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Numerics; +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; + +public class Runtime_110326A +{ + public struct S1 + { + public bool bool_2; + public Vector512 v512_short_3; + public Vector512 v512_float_4; + } + + [Fact] + public static void TestEntryPoint() + { + TestClass.Method1(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static ulong Method1() + { + S1 s1_s1_d1_f3_160 = new S1(); + return Vector512.ExtractMostSignificantBits(s1_s1_d1_f3_160.v512_short_3); + } +} + +public class Runtime_110326B +{ + public struct S2_D1_F2 + { + public struct S2_D2_F2 + { + public Vector v_double_0; + } + + public struct S2_D2_F3 + { + public Vector3 v3_10; + } + } + + public struct S2_D1_F3 + { + public struct S2_D2_F3 + { + public Vector256 v256_int_14; + } + + public Vector128 v128_long_13; + public Vector512 v512_uint_16; + } + + [Fact] + public static void TestEntryPoint() + { + TestClass.Method0(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static void Method0() + { + S2_D1_F2.S2_D2_F2 s2_s2_d1_f2_s2_d2_f2_262 = new S2_D1_F2.S2_D2_F2(); + S2_D1_F2.S2_D2_F2 s2_s2_d1_f2_s2_d2_f2_263 = s2_s2_d1_f2_s2_d2_f2_262; + S2_D1_F2.S2_D2_F3 s2_s2_d1_f2_s2_d2_f3_264 = new S2_D1_F2.S2_D2_F3(); + S2_D1_F2.S2_D2_F3 s2_s2_d1_f2_s2_d2_f3_265 = s2_s2_d1_f2_s2_d2_f3_264; + S2_D1_F2 s2_s2_d1_f2_266 = new S2_D1_F2(); + S2_D1_F3.S2_D2_F3 s2_s2_d1_f3_s2_d2_f3_268 = new S2_D1_F3.S2_D2_F3(); + S2_D1_F3 s2_s2_d1_f3_269 = new S2_D1_F3(); + S2_D1_F3 s2_s2_d1_f3_270 = s2_s2_d1_f3_269; + s2_s2_d1_f3_270.v512_uint_16 = Vector512.IsZero(Vector512.AllBitsSet); + + Log("s2_s2_d1_f", s2_s2_d1_f2_s2_d2_f2_262.v_double_0); + Log("s2_s2_d1_f", s2_s2_d1_f2_s2_d2_f2_263.v_double_0); + Log("s2_s2_d1_f", s2_s2_d1_f2_s2_d2_f3_264); + Log("s2_s2_d1_f", s2_s2_d1_f2_s2_d2_f3_265.v3_10); + Log("s2_s2_d1_f", s2_s2_d1_f2_266); + Log("s2_s2_d1_f", s2_s2_d1_f3_s2_d2_f3_268.v256_int_14); + Log("s2_s2_d1_f", s2_s2_d1_f3_269.v128_long_13); + Log("s2_s2_d1_f", s2_s2_d1_f3_270.v128_long_13); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static void Log(string varName, object varValue) + { + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.csproj new file mode 100644 index 0000000000000..1cd524e9fe351 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.csproj @@ -0,0 +1,12 @@ + + + True + + + + + + + + + From 451556b893a91fe2a15d78272eed5f5d05433b40 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Fri, 6 Dec 2024 12:13:56 -0800 Subject: [PATCH 2/4] Add using for Xunit --- .../JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs index 059a9c4b3d2d0..e24571e443c13 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs @@ -4,6 +4,7 @@ using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; +using Xunit; public class Runtime_110326A { From 15afdc7f8ad69345d4d76ed29d8fad756895d08a Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Fri, 6 Dec 2024 12:56:22 -0800 Subject: [PATCH 3/4] Fix test name --- .../JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs index e24571e443c13..dd8cf3be109c1 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs @@ -18,7 +18,7 @@ public struct S1 [Fact] public static void TestEntryPoint() { - TestClass.Method1(); + Runtime_110326A.Method1(); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -58,7 +58,7 @@ public struct S2_D2_F3 [Fact] public static void TestEntryPoint() { - TestClass.Method0(); + Runtime_110326B.Method0(); } [MethodImpl(MethodImplOptions.NoInlining)] From 69712fb277aed00e78d615a5eaeed34f79b8af9e Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Fri, 6 Dec 2024 17:53:49 -0800 Subject: [PATCH 4/4] Make the xunit analyzer happy --- .../JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs index dd8cf3be109c1..8a1b007c9db28 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs @@ -22,7 +22,7 @@ public static void TestEntryPoint() } [MethodImpl(MethodImplOptions.NoInlining)] - public static ulong Method1() + private static ulong Method1() { S1 s1_s1_d1_f3_160 = new S1(); return Vector512.ExtractMostSignificantBits(s1_s1_d1_f3_160.v512_short_3); @@ -62,7 +62,7 @@ public static void TestEntryPoint() } [MethodImpl(MethodImplOptions.NoInlining)] - public static void Method0() + private static void Method0() { S2_D1_F2.S2_D2_F2 s2_s2_d1_f2_s2_d2_f2_262 = new S2_D1_F2.S2_D2_F2(); S2_D1_F2.S2_D2_F2 s2_s2_d1_f2_s2_d2_f2_263 = s2_s2_d1_f2_s2_d2_f2_262; @@ -85,7 +85,7 @@ public static void Method0() } [MethodImpl(MethodImplOptions.NoInlining)] - public static void Log(string varName, object varValue) + private static void Log(string varName, object varValue) { } }