Skip to content

Commit

Permalink
JIT: Make stack size computation in fgCanFastTailCall more precise (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
jakobbotsch authored Jun 17, 2024
1 parent 257e76d commit e976830
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5351,7 +5351,7 @@ bool Compiler::fgCanFastTailCall(GenTreeCall* callee, const char** failReason)
callee->gtArgs.AddFinalArgsAndDetermineABIInfo(this, callee);

unsigned calleeArgStackSize = 0;
unsigned callerArgStackSize = info.compArgStackSize;
unsigned callerArgStackSize = roundUp(info.compArgStackSize, TARGET_POINTER_SIZE);

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

for (CallArg& arg : callee->gtArgs.Args())
{
calleeArgStackSize = roundUp(calleeArgStackSize, arg.AbiInfo.ByteAlignment);
calleeArgStackSize += arg.AbiInfo.GetStackByteSize();
unsigned stackSize = arg.AbiInfo.GetStackByteSize();
if (stackSize > 0)
{
calleeArgStackSize = roundUp(calleeArgStackSize, arg.AbiInfo.ByteAlignment);
calleeArgStackSize += stackSize;
}

#if defined(TARGET_ARM) || defined(TARGET_RISCV64)
if (arg.AbiInfo.IsSplit())
Expand Down

0 comments on commit e976830

Please sign in to comment.