[llvm] [AArch64] Skip storing of stack arguments when lowering tail calls (PR #126735)

Jon Roelofs via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 11 09:06:37 PST 2025


================
@@ -9328,10 +9328,25 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
       }
       unsigned LocMemOffset = VA.getLocMemOffset();
       int32_t Offset = LocMemOffset + BEAlign;
-      SDValue PtrOff = DAG.getIntPtrConstant(Offset, DL);
-      PtrOff = DAG.getNode(ISD::ADD, DL, PtrVT, StackPtr, PtrOff);
 
       if (IsTailCall) {
+        // When the frame pointer is perfectly aligned for the tail call and the
+        // same stack argument is passed down, omit storing it if is immutable
+        // and already in the right offset.
+        if (FPDiff == 0) {
+          if (auto *LoadNode = dyn_cast<LoadSDNode>(Arg)) {
+            if (auto *FINode =
+                    dyn_cast<FrameIndexSDNode>(LoadNode->getBasePtr())) {
+              MachineFrameInfo &MFI = MF.getFrameInfo();
+              int FI = FINode->getIndex();
+              if (LoadNode->getMemoryVT() == VA.getValVT() &&
----------------
jroelofs wrote:

Also, probably needs a couple tests for `zeroext`/`sext` args to make sure we do the right thing for smaller-than-32-bits args. In particular, we should make sure that when caller/callee don't agree on sign extension, that we still emit the caller-required part of that, and when they do agree we may omit it.

https://github.com/llvm/llvm-project/pull/126735


More information about the llvm-commits mailing list