Skip to content

Commit e976830

Browse files
authored
JIT: Make stack size computation in fgCanFastTailCall more precise (#103538)
Two changes: 1. Skip applying alignment when computing a call's arg stack size, which does not make sense/is not correct 2. Round up the incoming parameter stack space in terms of number of slots Without (1) we overestimate the stack size usage for some calls. Without (2) we underestimate the incoming stack size for some methods. Both of these just result in fewer tailcalls than possible, so cause no correctness issues. However, I hit some diffs in #103537 because of them.
1 parent 257e76d commit e976830

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/coreclr/jit/morph.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -5351,7 +5351,7 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason)
53515351
callee->gtArgs.AddFinalArgsAndDetermineABIInfo(this, callee);
53525352

53535353
unsigned calleeArgStackSize = 0;
5354-
unsigned callerArgStackSize = info.compArgStackSize;
5354+
unsigned callerArgStackSize = roundUp(info.compArgStackSize, TARGET_POINTER_SIZE);
53555355

53565356
auto reportFastTailCallDecision = [&](const char* thisFailReason) {
53575357
if (failReason != nullptr)
@@ -5405,8 +5405,12 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason)
54055405

54065406
for (CallArg& arg : callee->gtArgs.Args())
54075407
{
5408-
calleeArgStackSize = roundUp(calleeArgStackSize, arg.AbiInfo.ByteAlignment);
5409-
calleeArgStackSize += arg.AbiInfo.GetStackByteSize();
5408+
unsigned stackSize = arg.AbiInfo.GetStackByteSize();
5409+
if (stackSize > 0)
5410+
{
5411+
calleeArgStackSize = roundUp(calleeArgStackSize, arg.AbiInfo.ByteAlignment);
5412+
calleeArgStackSize += stackSize;
5413+
}
54105414

54115415
#if defined(TARGET_ARM) || defined(TARGET_RISCV64)
54125416
if (arg.AbiInfo.IsSplit())

0 commit comments

Comments
 (0)