From c67dde844d31fe55f6c5915d3bdc53b77fe183e6 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 6 Sep 2023 15:22:44 +0200 Subject: [PATCH 1/2] JIT: DNER multiregs with SIMD12s Locals with SIMD12 fields will never match the ABI 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 a32fc24e95931b..19c3c1b9d6d168 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -7499,6 +7499,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 8886bd2044ab04..562d2029ff85c5 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 afb26b6def0bc0..7f3e9293eba974 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 9d9fc4ec64d558..3ae45f998542b4 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 00000000000000..624b0c3a7885cb --- /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(); + } + + public struct S + { + public Vector3 v3; + public bool b; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static S Method2() + { + return default; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static void Method0() + { + S s = Method2(); + Log(null, s.v3); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public 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 00000000000000..de6d5e08882e86 --- /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 b89d6c71d78ce5..067b25abb8e826 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 From dabab29c8b1414eaafce4c536b95b3f2fb9c30a2 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Thu, 7 Sep 2023 00:38:38 +0200 Subject: [PATCH 2/2] Fix test build --- .../JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs b/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs index 624b0c3a7885cb..d30adf6e60cf11 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs @@ -16,25 +16,25 @@ public static void TestEntryPoint() Method0(); } - public struct S + struct S { public Vector3 v3; public bool b; } [MethodImpl(MethodImplOptions.NoInlining)] - public static S Method2() + static S Method2() { return default; } [MethodImpl(MethodImplOptions.NoInlining)] - public static void Method0() + static void Method0() { S s = Method2(); Log(null, s.v3); } [MethodImpl(MethodImplOptions.NoInlining)] - public static void Log(object a, object b) { } + static void Log(object a, object b) { } } \ No newline at end of file