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
49 changes: 45 additions & 4 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3239,11 +3239,11 @@ void Lowering::LowerFastTailCall(GenTreeCall* call)
if (!putargs.Empty())
{
GenTree* firstPutargStk = putargs.Bottom(0);
GenTree* firstPutargStkOp = firstPutargStk->gtGetOp1();
GenTree* firstPutargStkOp = FirstOperand(firstPutargStk);
for (int i = 1; i < putargs.Height(); i++)
{
firstPutargStk = LIR::FirstNode(firstPutargStk, putargs.Bottom(i));
firstPutargStkOp = LIR::FirstNode(firstPutargStkOp, putargs.Bottom(i)->gtGetOp1());
firstPutargStkOp = LIR::FirstNode(firstPutargStkOp, FirstOperand(putargs.Bottom(i)));
}
// Since this is a fast tailcall each PUTARG_STK will place the argument in the
// _incoming_ arg space area. This will effectively overwrite our already existing
Expand Down Expand Up @@ -3279,6 +3279,10 @@ void Lowering::LowerFastTailCall(GenTreeCall* call)
continue;
}

JITDUMP(
"PUTARG_STK [%06u] overwrites [%06u..%06u); parameter V%03u lives in [%06u..%06u); may need defensive copies\n",
Compiler::dspTreeID(put), overwrittenStart, overwrittenEnd, callerArgLclNum, argStart, argEnd);

// Codegen cannot handle a partially overlapping copy. For
// example, if we have
// bar(S16 stack, S32 stack2)
Expand All @@ -3287,10 +3291,11 @@ void Lowering::LowerFastTailCall(GenTreeCall* call)
// ahead. It is possible that this PUTARG_STK is the only use,
// in which case we will need to introduce a temp, so look for
// uses starting from it. Note that we assume that in-place
// copies are OK.
// copies are ok provided the source is a scalar value.
GenTree* lookForUsesFrom = put->gtNext;
if (overwrittenStart != argStart)
if ((overwrittenStart != argStart) || put->gtGetOp1()->OperIsFieldList())
{
JITDUMP("Non-atomic copy may be self-interfering. Expanding search...\n");
lookForUsesFrom = firstPutargStkOp;
}

Expand Down Expand Up @@ -3354,7 +3359,43 @@ void Lowering::LowerFastTailCall(GenTreeCall* call)
unreached();
#endif
}

//------------------------------------------------------------------------
// FirstOperand:
// Find the earliest operand of a node.
//
// Arguments:
// node - The node
//
// Returns:
// The earliest evaluated operand.
//
GenTree* Lowering::FirstOperand(GenTree* node)
{
struct Helper
{
GenTree* Result = nullptr;

void Visit(GenTree* node)
{
node->VisitOperands([=](GenTree* op) {
Result = Result == nullptr ? op : LIR::FirstNode(Result, op);

if (op->isContained())
{
Visit(op);
}

return GenTree::VisitResult::Continue;
});
}
};

Helper helper;
helper.Visit(node);
return helper.Result;
}

//------------------------------------------------------------------------
// RehomeArgForFastTailCall: Introduce temps for args that may be overwritten
// during fast tailcall sequence.
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lower.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class Lowering final : public Phase
GenTree* LowerNonvirtPinvokeCall(GenTreeCall* call);
GenTree* LowerTailCallViaJitHelper(GenTreeCall* callNode, GenTree* callTarget);
void LowerFastTailCall(GenTreeCall* callNode);
GenTree* FirstOperand(GenTree* node);
void RehomeArgForFastTailCall(unsigned int lclNum,
GenTree* insertTempBefore,
GenTree* lookForUsesStart,
Expand Down
28 changes: 28 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_122138/Runtime_122138.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

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

public class Runtime_122138
{
[MethodImpl(MethodImplOptions.NoOptimization)]
[Fact]
public static void TestEntryPoint()
{
var test = new Runtime_122138();
test.Method1(0, 0, 0, 999, 999);
}

private void Method1(int a, int b, int c, int value1, int? value2)
{
Method2(1, 2, 3, value1, value2);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void Method2(long a, int b, int c, int? value1, int? value2)
{
Assert.Equal(value1, value2);
}
}
1 change: 1 addition & 0 deletions src/tests/JIT/Regression/Regression_ro_1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<Compile Include="JitBlue\Runtime_120414\Runtime_120414.cs" />
<Compile Include="JitBlue\Runtime_120522\Runtime_120522.cs" />
<Compile Include="JitBlue\Runtime_121711\Runtime_121711.cs" />
<Compile Include="JitBlue\Runtime_122138\Runtime_122138.cs" />
<Compile Include="JitBlue\Runtime_31615\Runtime_31615.cs" />
<Compile Include="JitBlue\Runtime_33884\Runtime_33884.cs" />
<Compile Include="JitBlue\Runtime_38920\Runtime_38920.cs" />
Expand Down
Loading