Skip to content
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
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6670,7 +6670,7 @@ class Compiler
GenTree* fgMorphCopyBlock(GenTree* tree);
private:
GenTree* fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optAssertionPropDone = nullptr);
void fgTryReplaceStructLocalWithFields(GenTree** use);
bool fgTryReplaceStructLocalWithFields(GenTree** use);
GenTree* fgMorphFinalizeIndir(GenTreeIndir* indir);
GenTree* fgOptimizeCast(GenTreeCast* cast);
GenTree* fgOptimizeCastOnStore(GenTree* store);
Expand Down
28 changes: 18 additions & 10 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,7 @@ bool Compiler::fgTryMorphStructArg(CallArg* arg)
#else
*use = fieldList->SoleFieldOrThis();
#endif
*use = fgMorphTree(*use);
}
else
{
Expand Down Expand Up @@ -2335,7 +2336,8 @@ bool Compiler::fgTryMorphStructArg(CallArg* arg)

// Try to see if we can use the promoted fields to pass this argument.
//
if (varDsc->lvPromoted && (varDsc->lvFieldCnt == arg->AbiInfo.CountRegsAndStackSlots()))
if (varDsc->lvPromoted && !varDsc->lvDoNotEnregister &&
(varDsc->lvFieldCnt == arg->AbiInfo.CountRegsAndStackSlots()))
{
bool fieldsMatch = true;

Expand Down Expand Up @@ -2366,6 +2368,7 @@ bool Compiler::fgTryMorphStructArg(CallArg* arg)
if (fieldsMatch)
{
newArg = fgMorphLclToFieldList(lclNode)->SoleFieldOrThis();
newArg = fgMorphTree(newArg);
}
}
}
Expand Down Expand Up @@ -2511,7 +2514,7 @@ bool Compiler::fgTryMorphStructArg(CallArg* arg)
lvaSetVarDoNotEnregister(lclVar->GetLclNum() DEBUGARG(DoNotEnregisterReason::LocalField));
}
}
result->SetMorphed(this);
result = fgMorphTree(result);
return result;
}
else
Expand All @@ -2532,7 +2535,7 @@ bool Compiler::fgTryMorphStructArg(CallArg* arg)
}

GenTree* indir = gtNewIndir(type, addr);
indir->SetMorphed(this, /* doChildren*/ true);
indir->SetMorphed(this, /* doChildren */ true);
return indir;
}
};
Expand Down Expand Up @@ -2593,16 +2596,15 @@ GenTreeFieldList* Compiler::fgMorphLclToFieldList(GenTreeLclVar* lcl)
unsigned fieldLclNum = varDsc->lvFieldLclStart;

GenTreeFieldList* fieldList = new (this, GT_FIELD_LIST) GenTreeFieldList();
fieldList->SetMorphed(this);

for (unsigned i = 0; i < fieldCount; i++)
{
LclVarDsc* fieldVarDsc = lvaGetDesc(fieldLclNum);
GenTree* lclVar = gtNewLclvNode(fieldLclNum, fieldVarDsc->TypeGet());
lclVar->SetMorphed(this);
fieldList->AddField(this, lclVar, fieldVarDsc->lvFldOffset, fieldVarDsc->TypeGet());
fieldLclNum++;
}

return fieldList;
}

Expand Down Expand Up @@ -8366,7 +8368,10 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA
GenTree*& retVal = tree->AsOp()->ReturnValueRef();
if ((retVal != nullptr) && ((genReturnBB == nullptr) || (compCurBB == genReturnBB)))
{
fgTryReplaceStructLocalWithFields(&retVal);
if (fgTryReplaceStructLocalWithFields(&retVal))
{
retVal = fgMorphTree(retVal);
}
}
break;
}
Expand Down Expand Up @@ -8424,19 +8429,22 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA
// Notes:
// Currently only called when the tree parent is a GT_RETURN/GT_SWIFT_ERROR_RET.
//
void Compiler::fgTryReplaceStructLocalWithFields(GenTree** use)
bool Compiler::fgTryReplaceStructLocalWithFields(GenTree** use)
{
if (!(*use)->OperIs(GT_LCL_VAR))
{
return;
return false;
}

LclVarDsc* varDsc = lvaGetDesc((*use)->AsLclVar());

if (!varDsc->lvDoNotEnregister && varDsc->lvPromoted)
if (varDsc->lvDoNotEnregister || !varDsc->lvPromoted)
{
*use = fgMorphLclToFieldList((*use)->AsLclVar());
return false;
}

*use = fgMorphLclToFieldList((*use)->AsLclVar());
return true;
}

//------------------------------------------------------------------------
Expand Down
41 changes: 41 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_113488/Runtime_113488.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Generated by Fuzzlyn v2.5 on 2025-03-13 04:54:06
// Run on X64 Linux
// Seed: 15128240988293741626-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
// Reduced from 188.7 KiB to 0.8 KiB in 00:01:09
// Debug: Outputs 0
// Release: Outputs 1
using System;
using System.Numerics;
using System.Runtime.Intrinsics;
using System.Runtime.CompilerServices;
using Xunit;

public class Runtime_113488
{
[Fact]
public static int TestEntryPoint()
{
S0 vr0 = default(S0);
return M4(vr0, Vector256.Create<ushort>(vr0.M7()));
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static int M4(S0 arg0, Vector256<ushort> arg1)
{
return arg0.F0 == 0 ? 100 : 101;
}

private struct S0
{
public uint F0;
[MethodImpl(MethodImplOptions.NoInlining)]
public ushort M7()
{
this.F0 = 1;
return 0;
}
}
}
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>