Skip to content

Commit

Permalink
[release/8.0] JIT: DNER multiregs with SIMD12 (#91878)
Browse files Browse the repository at this point in the history
* 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

* Fix test build
  • Loading branch information
jakobbotsch authored Sep 11, 2023
1 parent 93bc3d4 commit 4147efb
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7484,6 +7484,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<struct{Vector3, int}>(CALL)
// * RETURN(LCL_VAR<struct{Vector3, int}>)
//
// 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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
40 changes: 40 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_91214/Runtime_91214.cs
Original file line number Diff line number Diff line change
@@ -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) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 4147efb

Please sign in to comment.