[llvm] [NFC ]Add a helper function isTailCall for getting libcall in SelectionDAG (PR #155256)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 25 08:08:37 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-selectiondag

Author: zhijian lin (diggerlin)

<details>
<summary>Changes</summary>

Based on comment of https://github.com/llvm/llvm-project/pull/153600#discussion_r2285729269,  Add a helper function isTailCall for getting libcall in SelectionDAG. 

---
Full diff: https://github.com/llvm/llvm-project/pull/155256.diff


1 Files Affected:

- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+11-12) 


``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 4b7fc45908119..cc9cd50e2c6f9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9012,6 +9012,14 @@ static void checkAddrSpaceIsValidForLibcall(const TargetLowering *TLI,
   }
 }
 
+static bool isTailCall(const CallInst *CI, const SelectionDAG *SelDAG,
+                       bool IsLowerToLibCall) {
+  bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
+  return CI && CI->isTailCall() &&
+         isInTailCallPosition(*CI, SelDAG->getTarget(),
+                              ReturnsFirstArg && IsLowerToLibCall);
+}
+
 std::pair<SDValue, SDValue>
 SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
                         SDValue Mem1, SDValue Size, const CallInst *CI) {
@@ -9033,10 +9041,7 @@ SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
       GetEntry(getDataLayout().getIntPtrType(*getContext()), Size)};
 
   TargetLowering::CallLoweringInfo CLI(*this);
-  bool IsTailCall = false;
-  bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
-  IsTailCall = CI && CI->isTailCall() &&
-               isInTailCallPosition(*CI, getTarget(), ReturnsFirstArg);
+  bool IsTailCall = isTailCall(CI, this, /*LowerToLibCall*/ true);
 
   CLI.setDebugLoc(dl)
       .setChain(Chain)
@@ -9117,10 +9122,7 @@ SDValue SelectionDAG::getMemcpy(
     IsTailCall = *OverrideTailCall;
   } else {
     bool LowersToMemcpy = StringRef(MemCpyName) == StringRef("memcpy");
-    bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
-    IsTailCall = CI && CI->isTailCall() &&
-                 isInTailCallPosition(*CI, getTarget(),
-                                      ReturnsFirstArg && LowersToMemcpy);
+    IsTailCall = isTailCall(CI, this, LowersToMemcpy);
   }
 
   CLI.setDebugLoc(dl)
@@ -9234,10 +9236,7 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
   } else {
     bool LowersToMemmove =
         TLI->getLibcallName(RTLIB::MEMMOVE) == StringRef("memmove");
-    bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
-    IsTailCall = CI && CI->isTailCall() &&
-                 isInTailCallPosition(*CI, getTarget(),
-                                      ReturnsFirstArg && LowersToMemmove);
+    IsTailCall = isTailCall(CI, this, LowersToMemmove);
   }
 
   CLI.setDebugLoc(dl)

``````````

</details>


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


More information about the llvm-commits mailing list