Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
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
24 changes: 12 additions & 12 deletions src/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,24 +592,24 @@ void CodeGen::genPutArgStk(GenTreePutArgStk* treeNode)

bool isStruct = (targetType == TYP_STRUCT) || (source->OperGet() == GT_FIELD_LIST);

if (varTypeIsSIMD(targetType))
if (!isStruct) // a normal non-Struct argument
{
assert(!source->isContained());
if (varTypeIsSIMD(targetType))
{
assert(!source->isContained());

regNumber srcReg = genConsumeReg(source);
regNumber srcReg = genConsumeReg(source);

emitAttr storeAttr = emitTypeSize(targetType);
emitAttr storeAttr = emitTypeSize(targetType);

assert((srcReg != REG_NA) && (genIsValidFloatReg(srcReg)));
emit->emitIns_S_R(INS_str, storeAttr, srcReg, varNumOut, argOffsetOut);
assert((srcReg != REG_NA) && (genIsValidFloatReg(srcReg)));
emit->emitIns_S_R(INS_str, storeAttr, srcReg, varNumOut, argOffsetOut);

argOffsetOut += EA_SIZE_IN_BYTES(storeAttr);
assert(argOffsetOut <= argOffsetMax); // We can't write beyound the outgoing area area
return;
}
argOffsetOut += EA_SIZE_IN_BYTES(storeAttr);
assert(argOffsetOut <= argOffsetMax); // We can't write beyound the outgoing area area
return;
}

if (!isStruct) // a normal non-Struct argument
{
instruction storeIns = ins_Store(targetType);
emitAttr storeAttr = emitTypeSize(targetType);

Expand Down
1 change: 1 addition & 0 deletions src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4919,6 +4919,7 @@ class Compiler
GenTree* fgMorphArrayIndex(GenTree* tree);
GenTree* fgMorphCast(GenTree* tree);
GenTree* fgUnwrapProxy(GenTree* objRef);
GenTreeFieldList* fgMorphLclArgToFieldlist(GenTreeLclVarCommon* lcl);
GenTreeCall* fgMorphArgs(GenTreeCall* call);

void fgMakeOutgoingStructArgCopy(GenTreeCall* call,
Expand Down
93 changes: 69 additions & 24 deletions src/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,20 @@ void fgArgTabEntry::Dump()
printf(" %d.%s", node->gtTreeID, GenTree::OpName(node->gtOper));
if (regNum != REG_STK)
{
printf(", %s, regs=%u", getRegName(regNum), numRegs);
printf(", %u reg%s:", numRegs, numRegs == 1 ? "" : "s");
printf(" %s", getRegName(regNum));
#if defined(UNIX_AMD64_ABI)
if (numRegs > 1)
{
printf(" %s", getRegName(otherRegNum));
}
#else // !UNIX_AMD64_ABI
// Note that for all other targets, we rely on the fact that arg regs are sequential.
for (unsigned i = 1; i < numRegs; i++)
{
printf(" %s", getRegName((regNumber)(regNum + i)));
}
#endif // !UNIX_AMD64_ABI
}
if (numSlots > 0)
{
Expand Down Expand Up @@ -4944,6 +4957,9 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry
#ifdef _TARGET_ARM_
if ((fgEntryPtr->isSplit && fgEntryPtr->numSlots + fgEntryPtr->numRegs > 4) ||
(!fgEntryPtr->isSplit && fgEntryPtr->regNum == REG_STK))
#else
if (fgEntryPtr->regNum == REG_STK)
#endif
{
GenTreeLclVarCommon* lcl = nullptr;

Expand All @@ -4962,21 +4978,28 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry
// We need to construct a `GT_OBJ` node for the argmuent,
// so we need to get the address of the lclVar.
lcl = arg->AsLclVarCommon();

arg = gtNewOperNode(GT_ADDR, TYP_I_IMPL, arg);

// Create an Obj of the temp to use it as a call argument.
arg = gtNewObjNode(lvaGetStruct(lcl->gtLclNum), arg);
}
if (lcl != nullptr)
{
// Its fields will need to accessed by address.
lvaSetVarDoNotEnregister(lcl->gtLclNum DEBUG_ARG(DNER_IsStructArg));
if (lvaGetPromotionType(lcl->gtLclNum) == PROMOTION_TYPE_INDEPENDENT)
{
arg = fgMorphLclArgToFieldlist(lcl);
}
else
{
if (!arg->OperIs(GT_OBJ))
{
// Create an Obj of the temp to use it as a call argument.
arg = gtNewOperNode(GT_ADDR, TYP_I_IMPL, arg);
arg = gtNewObjNode(lvaGetStruct(lcl->gtLclNum), arg);
}
// Its fields will need to be accessed by address.
lvaSetVarDoNotEnregister(lcl->gtLclNum DEBUG_ARG(DNER_IsStructArg));
}
}

return arg;
}
#endif

#if FEATURE_MULTIREG_ARGS
// Examine 'arg' and setup argValue objClass and structSize
Expand Down Expand Up @@ -5270,21 +5293,7 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry

if (!varIsFloat)
{
unsigned offset = 0;
GenTreeFieldList* listEntry = nullptr;
// We can use the struct promoted field as arguments
for (unsigned inx = 0; inx < elemCount; inx++)
{
GenTree* lclVar = gtNewLclvNode(varNums[inx], varType[inx], varNums[inx]);
// Create a new tree for 'arg'
// replace the existing LDOBJ(ADDR(LCLVAR))
listEntry = new (this, GT_FIELD_LIST) GenTreeFieldList(lclVar, offset, varType[inx], listEntry);
if (newArg == nullptr)
{
newArg = listEntry;
}
offset += TARGET_POINTER_SIZE;
}
newArg = fgMorphLclArgToFieldlist(varNode);
}
}
}
Expand Down Expand Up @@ -5474,6 +5483,42 @@ GenTree* Compiler::fgMorphMultiregStructArg(GenTree* arg, fgArgTabEntry* fgEntry
return arg;
}

//------------------------------------------------------------------------
// fgMorphLclArgToFieldlist: Morph a GT_LCL_VAR node to a GT_FIELD_LIST of its promoted fields
//
// Arguments:
// lcl - The GT_LCL_VAR node we will transform
//
// Return value:
// The new GT_FIELD_LIST that we have created.
//
GenTreeFieldList* Compiler::fgMorphLclArgToFieldlist(GenTreeLclVarCommon* lcl)
{
LclVarDsc* varDsc = &(lvaTable[lcl->gtLclNum]);
assert(varDsc->lvPromoted == true);

unsigned offset = 0;
unsigned fieldCount = varDsc->lvFieldCnt;
GenTreeFieldList* listEntry = nullptr;
GenTreeFieldList* newArg = nullptr;
unsigned fieldLclNum = varDsc->lvFieldLclStart;

// We can use the struct promoted field as arguments
for (unsigned i = 0; i < fieldCount; i++)
{
LclVarDsc* fieldVarDsc = &lvaTable[fieldLclNum];
GenTree* lclVar = gtNewLclvNode(fieldLclNum, fieldVarDsc->lvType);
listEntry = new (this, GT_FIELD_LIST) GenTreeFieldList(lclVar, offset, fieldVarDsc->lvType, listEntry);
if (newArg == nullptr)
{
newArg = listEntry;
}
offset += TARGET_POINTER_SIZE;
fieldLclNum++;
}
return newArg;
}

// Make a copy of a struct variable if necessary, to pass to a callee.
// returns: tree that computes address of the outgoing arg
void Compiler::fgMakeOutgoingStructArgCopy(
Expand Down
101 changes: 101 additions & 0 deletions tests/src/JIT/Regression/JitBlue/GitHub_16377/GitHub_16377.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need the standard header above.


class GitHub_16377
{
public static ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> CreateLong<T1, T2, T3, T4, T5, T6, T7, TRest>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest) where TRest : struct
{
return new ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>(item1, item2, item3, item4, item5, item6, item7, rest);
}

public static Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> CreateLongRef<T1, T2, T3, T4, T5, T6, T7, TRest>(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, TRest rest)
{
return new Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>(item1, item2, item3, item4, item5, item6, item7, rest);
}

public static void AssertEqual(string s1, string s2)
{
if (!s1.Equals(s2))
{
throw new Exception();
}
}

static void Test()
{
{
var vtWithNull = CreateLong(1, 2, 3, 4, 5, 6, 7, new ValueTuple<string>(null));
var tupleWithNull = CreateLongRef(1, 2, 3, 4, 5, 6, 7, new Tuple<string>(null));
AssertEqual("(1, 2, 3, 4, 5, 6, 7, )", vtWithNull.ToString());
AssertEqual(tupleWithNull.ToString(), vtWithNull.ToString());
}

{
var vtWithNull = CreateLong(1, 2, 3, 4, 5, 6, 7, new ValueTuple<string>(null));
var tupleWithNull = CreateLongRef(1, 2, 3, 4, 5, 6, 7, new Tuple<string>(null));
AssertEqual("(1, 2, 3, 4, 5, 6, 7, )", vtWithNull.ToString());
AssertEqual(tupleWithNull.ToString(), vtWithNull.ToString());
}

{
var vtWithNull = CreateLong(1, 2, 3, 4, 5, 6, 7, new ValueTuple<string, string>(null, null));
var tupleWithNull = CreateLongRef(1, 2, 3, 4, 5, 6, 7, new Tuple<string, string>(null, null));
AssertEqual("(1, 2, 3, 4, 5, 6, 7, , )", vtWithNull.ToString());
AssertEqual(tupleWithNull.ToString(), vtWithNull.ToString());
}

{
var vtWithNull = CreateLong(1, 2, 3, 4, 5, 6, 7, new ValueTuple<string, string, string>(null, null, null));
var tupleWithNull = CreateLongRef(1, 2, 3, 4, 5, 6, 7, new Tuple<string, string, string>(null, null, null));
AssertEqual("(1, 2, 3, 4, 5, 6, 7, , , )", vtWithNull.ToString());
AssertEqual(tupleWithNull.ToString(), vtWithNull.ToString());
}

{
var vtWithNull = CreateLong(1, 2, 3, 4, 5, 6, 7, new ValueTuple<string, string, string, string>(null, null, null, null));
var tupleWithNull = CreateLongRef(1, 2, 3, 4, 5, 6, 7, new Tuple<string, string, string, string>(null, null, null, null));
AssertEqual("(1, 2, 3, 4, 5, 6, 7, , , , )", vtWithNull.ToString());
AssertEqual(tupleWithNull.ToString(), vtWithNull.ToString());
}

{
var vtWithNull = CreateLong(1, 2, 3, 4, 5, 6, 7, new ValueTuple<string, string, string, string, string>(null, null, null, null, null));
var tupleWithNull = CreateLongRef(1, 2, 3, 4, 5, 6, 7, new Tuple<string, string, string, string, string>(null, null, null, null, null));
AssertEqual("(1, 2, 3, 4, 5, 6, 7, , , , , )", vtWithNull.ToString());
AssertEqual(tupleWithNull.ToString(), vtWithNull.ToString());
}

{
var vtWithNull = CreateLong(1, 2, 3, 4, 5, 6, 7, new ValueTuple<string, string, string, string, string, string>(null, null, null, null, null, null));
var tupleWithNull = CreateLongRef(1, 2, 3, 4, 5, 6, 7, new Tuple<string, string, string, string, string, string>(null, null, null, null, null, null));
AssertEqual("(1, 2, 3, 4, 5, 6, 7, , , , , , )", vtWithNull.ToString());
AssertEqual(tupleWithNull.ToString(), vtWithNull.ToString());
}

{
var vtWithNull = CreateLong(1, 2, 3, 4, 5, 6, 7, new ValueTuple<string, string, string, string, string, string, string>(null, null, null, null, null, null, null));
var tupleWithNull = CreateLongRef(1, 2, 3, 4, 5, 6, 7, new Tuple<string, string, string, string, string, string, string>(null, null, null, null, null, null, null));
AssertEqual("(1, 2, 3, 4, 5, 6, 7, , , , , , , )", vtWithNull.ToString());
AssertEqual(tupleWithNull.ToString(), vtWithNull.ToString());
}
}

public static int Main()
{
int result = 0;
try
{
Test();
result = 100;
}
catch (Exception)
{
result = -1;
}

return result;
}
}
38 changes: 38 additions & 0 deletions tests/src/JIT/Regression/JitBlue/GitHub_16377/GitHub_16377.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{95DFC527-4DC1-495E-97D7-B8089FFA8D79}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<PropertyGroup>
<DebugType></DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
</Project>