Skip to content

JIT: Fix tailcall rehoming logic for some interfering operands #116468

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

Merged
merged 3 commits into from
Jun 10, 2025
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
12 changes: 7 additions & 5 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3338,10 +3338,12 @@ void Lowering::LowerFastTailCall(GenTreeCall* call)
GenTree* startNonGCNode = nullptr;
if (!putargs.Empty())
{
GenTree* firstPutargStk = putargs.Bottom(0);
GenTree* firstPutargStk = putargs.Bottom(0);
GenTree* firstPutargStkOp = firstPutargStk->gtGetOp1();
for (int i = 1; i < putargs.Height(); i++)
{
firstPutargStk = LIR::FirstNode(firstPutargStk, putargs.Bottom(i));
firstPutargStk = LIR::FirstNode(firstPutargStk, putargs.Bottom(i));
firstPutargStkOp = LIR::FirstNode(firstPutargStkOp, putargs.Bottom(i)->gtGetOp1());
}
// 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 @@ -3389,10 +3391,10 @@ void Lowering::LowerFastTailCall(GenTreeCall* call)
GenTree* lookForUsesFrom = put->gtNext;
if (overwrittenStart != argStart)
{
lookForUsesFrom = firstPutargStk;
lookForUsesFrom = firstPutargStkOp;
}

RehomeArgForFastTailCall(callerArgLclNum, firstPutargStk, lookForUsesFrom, call);
RehomeArgForFastTailCall(callerArgLclNum, firstPutargStkOp, lookForUsesFrom, call);
// The above call can introduce temps and invalidate the pointer.
callerArgDsc = comp->lvaGetDesc(callerArgLclNum);

Expand All @@ -3406,7 +3408,7 @@ void Lowering::LowerFastTailCall(GenTreeCall* call)
unsigned int fieldsEnd = fieldsFirst + callerArgDsc->lvFieldCnt;
for (unsigned int j = fieldsFirst; j < fieldsEnd; j++)
{
RehomeArgForFastTailCall(j, firstPutargStk, lookForUsesFrom, call);
RehomeArgForFastTailCall(j, firstPutargStkOp, lookForUsesFrom, call);
}
}
}
Expand Down
63 changes: 63 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_116466/Runtime_116466.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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 v3.2 on 2025-06-08 15:45:13
// Run on X64 Linux
// Seed: 5301785820831683815-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
// Reduced from 219.4 KiB to 1.8 KiB in 00:06:09
// Debug: Outputs 1
// Release: Outputs 0
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using Xunit;

public class Runtime_116466
{
static Vector256<uint> s_19;
[ThreadStatic]
static sbyte s_25;
static int s_result;

[Fact]
public static int TestEntryPoint()
{
s_25 = 123;
var vr3 = new S0(100);
var vr4 = new S1();
M11(vr3, vr4);
return s_result;
}

static short M11(S0 arg0, S1 arg7)
{
s_19 = s_19;
var vr2 = Vector128.CreateScalar(0UL).AsVector();
return M12(vr2, s_25, arg0);
}

[MethodImpl(MethodImplOptions.NoInlining)]
static short M12(Vector<ulong> arg0, sbyte arg2, S0 arg3)
{
short var1 = arg3.F7;
s_result = var1;
return arg3.F3;
}

struct S0
{
public short F3;
public Vector<ushort> F6;
public short F7;
public S0(short f7) : this()
{
F7 = f7;
}
}

struct S1
{
public S0 F0;
}
}
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>
Loading