From da4e544809b3b10b7db8dc170331988d817240d7 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 11 Sep 2023 12:38:32 +0200 Subject: [PATCH] JIT: DNER multiregs with SIMD12s (#91674) Locals with SIMD12 fields will span multiple registers when they end up as multireg returns, so these should always be DNER'd. Fix #91214 --- src/coreclr/jit/lower.cpp | 22 ++++++++++ .../JitBlue/Runtime_91062/Runtime_91062.cs | 2 +- .../JitBlue/Runtime_91170/Runtime_91170.cs | 2 +- .../JitBlue/Runtime_91174/Runtime_91174.cs | 2 +- .../JitBlue/Runtime_91214/Runtime_91214.cs | 40 +++++++++++++++++++ .../Runtime_91214/Runtime_91214.csproj | 8 ++++ .../JitBlue/Runtime_91335/Runtime_91335.cs | 2 +- 7 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.csproj diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 7983f4aad47e5..16df99387128a 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -7506,6 +7506,28 @@ bool Lowering::CheckMultiRegLclVar(GenTreeLclVar* lclNode, int registerCount) if (registerCount == varDsc->lvFieldCnt) { canEnregisterAsMultiReg = true; + +#ifdef FEATURE_SIMD + // TYP_SIMD12 breaks the above invariant that "we won't have + // matching reg and field counts"; for example, consider + // + // * STORE_LCL_VAR(CALL) + // * RETURN(LCL_VAR) + // + // These return in two GPR registers, while the fields of the + // local are stored in SIMD and GPR register, so registerCount + // == varDsc->lvFieldCnt == 2. But the backend cannot handle + // this. + + for (int i = 0; i < varDsc->lvFieldCnt; i++) + { + if (comp->lvaGetDesc(varDsc->lvFieldLclStart + i)->TypeGet() == TYP_SIMD12) + { + canEnregisterAsMultiReg = false; + break; + } + } +#endif } } } diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91062/Runtime_91062.cs b/src/tests/JIT/Regression/JitBlue/Runtime_91062/Runtime_91062.cs index 8886bd2044ab0..562d2029ff85c 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_91062/Runtime_91062.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91062/Runtime_91062.cs @@ -1,5 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license.aa +// The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91170/Runtime_91170.cs b/src/tests/JIT/Regression/JitBlue/Runtime_91170/Runtime_91170.cs index afb26b6def0bc..7f3e9293eba97 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_91170/Runtime_91170.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91170/Runtime_91170.cs @@ -1,5 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license.aa +// The .NET Foundation licenses this file to you under the MIT license. // Found by Antigen diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91174/Runtime_91174.cs b/src/tests/JIT/Regression/JitBlue/Runtime_91174/Runtime_91174.cs index 9d9fc4ec64d55..3ae45f998542b 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_91174/Runtime_91174.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91174/Runtime_91174.cs @@ -1,5 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license.aa +// The .NET Foundation licenses this file to you under the MIT license. using System; using System.Runtime.CompilerServices; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs b/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs new file mode 100644 index 0000000000000..d30adf6e60cf1 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Found by Antigen + +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; +using System.Numerics; +using Xunit; + +public class Runtime_91214 +{ + [Fact] + public static void TestEntryPoint() + { + Method0(); + } + + struct S + { + public Vector3 v3; + public bool b; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static S Method2() + { + return default; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Method0() + { + S s = Method2(); + Log(null, s.v3); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static void Log(object a, object b) { } +} \ No newline at end of file diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.csproj new file mode 100644 index 0000000000000..de6d5e08882e8 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.csproj @@ -0,0 +1,8 @@ + + + True + + + + + diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91335/Runtime_91335.cs b/src/tests/JIT/Regression/JitBlue/Runtime_91335/Runtime_91335.cs index b89d6c71d78ce..067b25abb8e82 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_91335/Runtime_91335.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91335/Runtime_91335.cs @@ -1,5 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license.aa +// The .NET Foundation licenses this file to you under the MIT license. // Found by Antigen