-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[NFC ]Add a helper function isTailCall for getting libcall in SelectionDAG #155256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-llvm-selectiondag Author: zhijian lin (diggerlin) ChangesBased on comment of #153600 (comment), Add a helper function isTailCall for getting libcall in SelectionDAG. Full diff: https://github.com/llvm/llvm-project/pull/155256.diff 1 Files Affected:
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)
|
bool ReturnsFirstArg = CI && funcReturnsFirstArgOfCall(*CI); | ||
return CI && CI->isTailCall() && | ||
isInTailCallPosition(*CI, SelDAG->getTarget(), | ||
ReturnsFirstArg && IsLowerToLibCall); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires explanation. The arguments for the calls that are generated are not changed by this condition. Why would ReturnsFirstArg be different?
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will always return false for a null CallInst, but you have 2 null checks on it. Tail call should be possible even without the CallInst? I thought we handled tail call of new calls already?
At least turn into early exit or pull the null checks into the caller
@@ -9012,6 +9012,14 @@ static void checkAddrSpaceIsValidForLibcall(const TargetLowering *TLI, | |||
} | |||
} | |||
|
|||
static bool isTailCall(const CallInst *CI, const SelectionDAG *SelDAG, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name isn't quite right. This is more like an extended version of isInTailCallPosition.
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, why do you need the IR analysis for funcReturnsFirstArgOfCall? You know that based on the properties of the known libcall without looking at the IR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's about what the caller returns, not what the library call returns, for tail call deliberations.
Based on comment of #153600 (comment), Add a helper function isTailCall for getting libcall in SelectionDAG.