[PATCH] D108762: [NFC][X86] Sret return register cleanup

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 26 06:09:15 PDT 2021


urnathan created this revision.
urnathan added a reviewer: rnk.
Herald added subscribers: pengfei, hiraditya, kristof.beyls.
urnathan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In working on the in-memory sret tail-calling problem, I ran into this.  As I want to adjust this code for sret, I figured it best to get this change in first.  It turns out that there are no paths into LowerFormalParms that have already specified the sret register.  We always materialize a virtual and then assign it to the physical reg at the point of the return.  Thus the 'if (!reg)' body is always reachable.  Tested by (a) grepping for setSRetReturnReg calls (there are no others), and (b) building and testing with this assert added.


https://reviews.llvm.org/D108762

Files:
  llvm/lib/Target/X86/X86ISelLowering.cpp


Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -3960,12 +3960,12 @@
     // the argument into a virtual register so that we can access it from the
     // return points.
     if (Ins[I].Flags.isSRet()) {
-      Register Reg = FuncInfo->getSRetReturnReg();
-      if (!Reg) {
-        MVT PtrTy = getPointerTy(DAG.getDataLayout());
-        Reg = MF.getRegInfo().createVirtualRegister(getRegClassFor(PtrTy));
-        FuncInfo->setSRetReturnReg(Reg);
-      }
+      assert(!FuncInfo->getSRetReturnReg() &&
+             "SRet return has already been set");
+      MVT PtrTy = getPointerTy(DAG.getDataLayout());
+      Register Reg =
+          MF.getRegInfo().createVirtualRegister(getRegClassFor(PtrTy));
+      FuncInfo->setSRetReturnReg(Reg);
       SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[I]);
       Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
       break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108762.368858.patch
Type: text/x-patch
Size: 1074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210826/c7dddc1f/attachment.bin>


More information about the llvm-commits mailing list