Skip to content

Commit 928ff30

Browse files
authored
JIT: Home float parameters before integer parameters (#96439)
Parameters that are going into float registers can come from integer registers in the presence of struct promotion. We need to home those before integer parameters or the source register could have been overridden by the integer parameter homing logic. Ideally it seems like the homing logic should be unified to handle all parameters simultaneously, but this seems like a simple enough fix. I do not think we have ABIs where we have the opposite kind constraint (integer parameters coming from float registers). Fix #96306
1 parent 9e31c21 commit 928ff30

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/coreclr/jit/codegencommon.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6243,8 +6243,14 @@ void CodeGen::genFnProlog()
62436243
};
62446244

62456245
#if defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_ARM)
6246-
assignIncomingRegisterArgs(&intRegState);
6246+
// Handle float parameters first; in the presence of struct promotion
6247+
// we can have parameters that are homed into float registers but
6248+
// passed in integer registers. So make sure we get those out of the
6249+
// integer registers before we potentially override those as part of
6250+
// handling integer parameters.
6251+
62476252
assignIncomingRegisterArgs(&floatRegState);
6253+
assignIncomingRegisterArgs(&intRegState);
62486254
#else
62496255
assignIncomingRegisterArgs(&intRegState);
62506256
#endif
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Numerics;
5+
using System.Runtime.CompilerServices;
6+
using Xunit;
7+
8+
public class Runtime_96306
9+
{
10+
[Fact]
11+
public static int TestEntryPoint()
12+
{
13+
return Foo(new Point2D { V = new Vector2(101, -1) }, 100);
14+
}
15+
16+
// 'a' is passed in rcx but homed into xmm1 after promotion.
17+
// 'scale' is passed in xmm1 but spilled because of the call to Bar.
18+
// We must take care that we spill 'scale' before we home 'a'.
19+
[MethodImpl(MethodImplOptions.NoInlining)]
20+
private static int Foo(Point2D a, float scale)
21+
{
22+
Bar();
23+
return ReturnValue(scale);
24+
}
25+
26+
[MethodImpl(MethodImplOptions.NoInlining)]
27+
private static int ReturnValue(float value) => (int)value;
28+
29+
[MethodImpl(MethodImplOptions.NoInlining)]
30+
private static void Bar() { }
31+
32+
private struct Point2D
33+
{
34+
public Vector2 V;
35+
}
36+
}
37+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
<DebugType>None</DebugType>
5+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="$(MSBuildProjectName).cs" />
9+
</ItemGroup>
10+
</Project>

0 commit comments

Comments
 (0)