Unnecessary Win64 stack allocations...

I'm trying to understand the Win64 case of the code below, from X86RegisterInfo.cpp:

  // If this is x86-64 and the Red Zone is not disabled, if we are a leaf
  // function, and use up to 128 bytes of stack space, don't have a frame
  // pointer, calls, or dynamic alloca then we do not need to adjust the
  // stack pointer (we fit in the Red Zone).
  if (Is64Bit && !Fn->hasFnAttr(Attribute::NoRedZone) &&
      !needsStackRealignment(MF) &&
      !MFI->hasVarSizedObjects() && // No dynamic alloca.
      !MFI->adjustsStack() && // No calls.
      !IsWin64) { // Win64 has no Red Zone
    uint64_t MinSize = X86FI->getCalleeSavedFrameSize();
    if (HasFP) MinSize += SlotSize;
    StackSize = std::max(MinSize, StackSize > 128 ? StackSize - 128 : 0);
    MFI->setStackSize(StackSize);
  } else if (IsWin64) {
    // We need to always allocate 32 bytes as register spill area.
    // FIXME: We might reuse these 32 bytes for leaf functions.
    StackSize += 32;
    MFI->setStackSize(StackSize);
  }

Why is it always allocating the register spill area? In a simple little test case, I was able to verify that, if that code was removed, the register parameters would properly get saved to their shadow space.

Cameron Esfahani
dirty@apple.com

"Americans are very skilled at creating a custom meaning from something that's mass-produced."

Ann Powers

Hello, Cameron

Why is it always allocating the register spill area? In a simple little test case, I was able to verify that, if that code was removed, the register parameters would properly get saved to their shadow space.

Yes, they are saved, but someone should allocate space for them :slight_smile:
Otherwise they will overwrite / can be overwritten by other stuff.