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

JIT ARM32: Fix passing odd sized structs from arbitrary sources #70075

Merged
merged 4 commits into from
Jun 7, 2022
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
14 changes: 13 additions & 1 deletion src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,18 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
makeOutArgCopy = true;
}

// If the arg may go into registers (both fully or split)
// then we cannot handle passing it from an arbitrary
// source if it would require passing a 3 byte chunk.
// Placing 3 bytes into a register requires multiple loads/shifts/or.
// In theory we could more easily support it for split args
// as those load registers fully always, but currently we
// do not.
if ((arg.AbiInfo.NumRegs > 0) && ((passingSize % REGSIZE_BYTES) == 3))
{
makeOutArgCopy = true;
}

if (structSize < TARGET_POINTER_SIZE)
{
makeOutArgCopy = true;
Expand Down Expand Up @@ -3854,7 +3866,7 @@ GenTree* Compiler::fgMorphMultiregStructArg(CallArg* arg)
break;
#endif // (TARGET_ARM64) || (UNIX_AMD64_ABI) || (TARGET_LOONGARCH64)
default:
noway_assert(!"NYI: odd sized struct in fgMorphMultiregStructArg");
noway_assert(!"Cannot load odd sized last element from arbitrary source");
break;
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/tests/JIT/Directed/StructABI/SevenByteStruct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

// On ARM32 the following has S0 passed in two registers, which requires passing 3 bytes in the last register.
// We cannot do that in a single load from an arbitrary source and must copy it to a local first.

public struct S0
{
public byte F0;
public byte F1;
public byte F2;
public byte F3;
public byte F4;
public byte F5;
public byte F6;
}

public class SevenByteStruct
{
public static S0 s_4 = new S0 { F0 = 1, F1 = 2, F2 = 3, F3 = 4, F4 = 5, F5 = 6, F6 = 7 };
public static int Main()
{
ref S0 vr0 = ref s_4;
int sum = M35(vr0);
return sum == 28 ? 100 : -1;
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static int M35(S0 arg0)
{
return arg0.F0 + arg0.F1 + arg0.F2 + arg0.F3 + arg0.F4 + arg0.F5 + arg0.F6;
}
}
12 changes: 12 additions & 0 deletions src/tests/JIT/Directed/StructABI/SevenByteStruct.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType>PdbOnly</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="SevenByteStruct.cs" />
</ItemGroup>
</Project>
18 changes: 0 additions & 18 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,6 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Stress/ABI/pinvokes_do/**">
<Issue>https://github.com/dotnet/runtime/issues/66745</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Stress/ABI/tailcalls_d/**">
<Issue>https://github.com/dotnet/runtime/issues/70042</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Stress/ABI/tailcalls_do/**">
<Issue>https://github.com/dotnet/runtime/issues/70042</Issue>
</ExcludeList>
</ItemGroup>

<!-- Windows arm64 specific excludes -->
Expand Down Expand Up @@ -678,18 +672,6 @@
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/Runtime_56953/Runtime_56953/*">
<Issue>https://github.com/dotnet/runtime/issues/57856</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Stress/ABI/tailcalls_d/**">
<Issue>https://github.com/dotnet/runtime/issues/68837</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Stress/ABI/tailcalls_do/**">
<Issue>https://github.com/dotnet/runtime/issues/68837</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Stress/ABI/pinvokes_d/**">
<Issue>https://github.com/dotnet/runtime/issues/68837</Issue>
</ExcludeList>
<ExcludeList Include = "$(XunitTestBinBase)/JIT/Stress/ABI/pinvokes_do/**">
<Issue>https://github.com/dotnet/runtime/issues/68837</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/profiler/multiple/multiple/*">
<Issue>https://github.com/dotnet/runtime/issues/57875</Issue>
</ExcludeList>
Expand Down