[llvm] [NFC ]Add a helper function isTailCall for getting libcall in SelectionDAG (PR #155256)
zhijian lin via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 8 12:13:03 PDT 2025
https://github.com/diggerlin updated https://github.com/llvm/llvm-project/pull/155256
>From 955e081ab06f3f46601f15e673c3f44367516a8e Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Mon, 25 Aug 2025 15:09:14 +0000
Subject: [PATCH 1/4] add a helper function isTailCall
---
.../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 23 +++++++++----------
1 file changed, 11 insertions(+), 12 deletions(-)
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)
>From 1dbfb70d871ae8bd13bfdd8a2f9a6a7410cc0755 Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Tue, 2 Sep 2025 18:22:05 +0000
Subject: [PATCH 2/4] address comment
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index cc9cd50e2c6f9..11943037ca7ec 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9012,12 +9012,14 @@ static void checkAddrSpaceIsValidForLibcall(const TargetLowering *TLI,
}
}
-static bool isTailCall(const CallInst *CI, const SelectionDAG *SelDAG,
- bool IsLowerToLibCall) {
- bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI);
+static bool isInTailCallPositionWrapper(const CallInst *CI,
+ const SelectionDAG *SelDAG,
+ bool IsLowerToLibCall) {
+
return CI && CI->isTailCall() &&
isInTailCallPosition(*CI, SelDAG->getTarget(),
- ReturnsFirstArg && IsLowerToLibCall);
+ funcReturnsFirstArgOfCall(*CI) &&
+ IsLowerToLibCall);
}
std::pair<SDValue, SDValue>
@@ -9041,7 +9043,8 @@ SelectionDAG::getMemcmp(SDValue Chain, const SDLoc &dl, SDValue Mem0,
GetEntry(getDataLayout().getIntPtrType(*getContext()), Size)};
TargetLowering::CallLoweringInfo CLI(*this);
- bool IsTailCall = isTailCall(CI, this, /*LowerToLibCall*/ true);
+ bool IsTailCall =
+ isInTailCallPositionWrapper(CI, this, /*LowerToLibCall*/ true);
CLI.setDebugLoc(dl)
.setChain(Chain)
@@ -9122,7 +9125,7 @@ SDValue SelectionDAG::getMemcpy(
IsTailCall = *OverrideTailCall;
} else {
bool LowersToMemcpy = StringRef(MemCpyName) == StringRef("memcpy");
- IsTailCall = isTailCall(CI, this, LowersToMemcpy);
+ IsTailCall = isInTailCallPositionWrapper(CI, this, LowersToMemcpy);
}
CLI.setDebugLoc(dl)
@@ -9236,7 +9239,7 @@ SDValue SelectionDAG::getMemmove(SDValue Chain, const SDLoc &dl, SDValue Dst,
} else {
bool LowersToMemmove =
TLI->getLibcallName(RTLIB::MEMMOVE) == StringRef("memmove");
- IsTailCall = isTailCall(CI, this, LowersToMemmove);
+ IsTailCall = isInTailCallPositionWrapper(CI, this, LowersToMemmove);
}
CLI.setDebugLoc(dl)
>From 18c8ba8fe0169682a7085250eaf6e566ad6142a9 Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Mon, 8 Sep 2025 16:06:02 +0000
Subject: [PATCH 3/4] address comment
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 11943037ca7ec..a71e3c30a95bd 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9014,12 +9014,12 @@ static void checkAddrSpaceIsValidForLibcall(const TargetLowering *TLI,
static bool isInTailCallPositionWrapper(const CallInst *CI,
const SelectionDAG *SelDAG,
- bool IsLowerToLibCall) {
+ bool AllowReturnsFirstArg) {
return CI && CI->isTailCall() &&
isInTailCallPosition(*CI, SelDAG->getTarget(),
- funcReturnsFirstArgOfCall(*CI) &&
- IsLowerToLibCall);
+ AllowReturnsFirstArg &&
+ funcReturnsFirstArgOfCall(*CI));
}
std::pair<SDValue, SDValue>
>From 3bb9426bfc122a9f3312a80c1c08f8d426fcd697 Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Mon, 8 Sep 2025 19:18:32 +0000
Subject: [PATCH 4/4] address comment
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index a71e3c30a95bd..7e5360e151b33 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9015,9 +9015,11 @@ static void checkAddrSpaceIsValidForLibcall(const TargetLowering *TLI,
static bool isInTailCallPositionWrapper(const CallInst *CI,
const SelectionDAG *SelDAG,
bool AllowReturnsFirstArg) {
-
- return CI && CI->isTailCall() &&
- isInTailCallPosition(*CI, SelDAG->getTarget(),
+ if (!CI || !CI->isTailCall())
+ return false;
+ // TODO: Fix "returns-first-arg" determination so it doesn't depend on which
+ // helper symbol we lower to.
+ return isInTailCallPosition(*CI, SelDAG->getTarget(),
AllowReturnsFirstArg &&
funcReturnsFirstArgOfCall(*CI));
}
More information about the llvm-commits
mailing list