From e4fad0493335967a2646786a54b4bad98da40d70 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 29 Aug 2023 13:39:24 +0200 Subject: [PATCH] Fix multireg return --- src/coreclr/jit/lower.cpp | 21 ++++++++++ .../JitBlue/Runtime_91214/Runtime_91214.cs | 40 +++++++++++++++++++ .../Runtime_91214/Runtime_91214.csproj | 8 ++++ 3 files changed, 69 insertions(+) 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 960f6d9c2eb7c..d0fa2db80259b 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -7483,7 +7483,28 @@ bool Lowering::CheckMultiRegLclVar(GenTreeLclVar* lclNode, int registerCount) { if (registerCount == varDsc->lvFieldCnt) { + int hfaFields = 0; canEnregisterAsMultiReg = true; + for (unsigned i = 0; i < varDsc->lvFieldCnt; ++i) + { + LclVarDsc* fieldDesc = comp->lvaGetDesc(varDsc->lvFieldLclStart + i); + if (fieldDesc->lvIsHfa()) + { + // Let's see if all fields are HFAs + hfaFields++; + } + else if (((fieldDesc->lvFldOffset % REGSIZE_BYTES) != 0) || (fieldDesc->lvSize() >= REGSIZE_BYTES)) + { + // Otherwise, we expect two ints/longs + canEnregisterAsMultiReg = false; + break; + } + } + if (hfaFields != registerCount) + { + // A mix of HFAs with non-HFAs + canEnregisterAsMultiReg = false; + } } } } 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..767e467a0254c --- /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.aa + +// 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) { } +} 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 + + + + +