Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/8.0-staging] JIT: Home float parameters before integer parameters #98749

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6154,8 +6154,14 @@ void CodeGen::genFnProlog()
};

#if defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_ARM)
assignIncomingRegisterArgs(&intRegState);
// Handle float parameters first; in the presence of struct promotion
// we can have parameters that are homed into float registers but
// passed in integer registers. So make sure we get those out of the
// integer registers before we potentially override those as part of
// handling integer parameters.

assignIncomingRegisterArgs(&floatRegState);
assignIncomingRegisterArgs(&intRegState);
#else
assignIncomingRegisterArgs(&intRegState);
#endif
Expand Down
15 changes: 15 additions & 0 deletions src/coreclr/jit/lsra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,21 @@ bool LinearScan::isRegCandidate(LclVarDsc* varDsc)
return false;
}

// Avoid allocating parameters that are passed in float regs into integer
// registers. We currently home float registers before integer registers,
// so that kind of enregistration can trash integer registers containing
// other parameters.
// We assume that these cases will be homed to float registers if they are
// promoted.
// TODO-CQ: Combine integer and float register homing to handle these kinds
// of conflicts.
if ((varDsc->TypeGet() == TYP_STRUCT) && varDsc->lvIsRegArg && !varDsc->lvPromoted &&
varTypeUsesIntReg(varDsc->GetRegisterType()) && genIsValidFloatReg(varDsc->GetArgReg()))
{
compiler->lvaSetVarDoNotEnregister(lclNum DEBUGARG(DoNotEnregisterReason::IsStructArg));
return false;
}

// Are we not optimizing and we have exception handlers?
// if so mark all args and locals as volatile, so that they
// won't ever get enregistered.
Expand Down
37 changes: 37 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_96306/Runtime_96306.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Numerics;
using System.Runtime.CompilerServices;
using Xunit;

public class Runtime_96306
{
[Fact]
public static int TestEntryPoint()
{
return Foo(new Point2D { V = new Vector2(101, -1) }, 100);
}

// 'a' is passed in rcx but homed into xmm1 after promotion.
// 'scale' is passed in xmm1 but spilled because of the call to Bar.
// We must take care that we spill 'scale' before we home 'a'.
[MethodImpl(MethodImplOptions.NoInlining)]
private static int Foo(Point2D a, float scale)
{
Bar();
return ReturnValue(scale);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static int ReturnValue(float value) => (int)value;

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Bar() { }

private struct Point2D
{
public Vector2 V;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
<DebugType>None</DebugType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
Loading