Skip to content

Commit

Permalink
JIT: DNER multiregs with SIMD12s (#91674)
Browse files Browse the repository at this point in the history
Locals with SIMD12 fields will span multiple registers when they end up
as multireg returns, so these should always be DNER'd.

Fix #91214
  • Loading branch information
jakobbotsch authored Sep 11, 2023
1 parent 6d5ea33 commit da4e544
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<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
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;
using System.Runtime.CompilerServices;
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>
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

0 comments on commit da4e544

Please sign in to comment.