From d564cb38d13aa11f3debd093d06403e23a37d64d Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Wed, 11 Dec 2024 01:15:14 -0800 Subject: [PATCH] Ensure that we don't try and optimize masks for promoted fields (#110485) * Ensure that we don't try and optimize masks for promoted fields * Add using for Xunit * Fix test name * Make the xunit analyzer happy --- src/coreclr/jit/optimizemaskconversions.cpp | 11 ++- .../JitBlue/Runtime_110326/Runtime_110326.cs | 91 +++++++++++++++++++ .../Runtime_110326/Runtime_110326.csproj | 12 +++ 3 files changed, 113 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..8a1b007c9db28 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_110326/Runtime_110326.cs @@ -0,0 +1,91 @@ +// 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; +using Xunit; + +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() + { + Runtime_110326A.Method1(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private 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() + { + Runtime_110326B.Method0(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + 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; + 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)] + private 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 + + + + + + + + +