[llvm] [Analysis]: Allow inlining recursive call IF recursion depth is 1. (PR #119677)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed May 7 13:15:57 PDT 2025
================
@@ -1676,6 +1680,79 @@ bool CallAnalyzer::visitGetElementPtr(GetElementPtrInst &I) {
return isGEPFree(I);
}
+// Simplify \p Cmp if RHS is const and we can ValueTrack LHS.
+// This handles the case only when the Cmp instruction is guarding a recursive
+// call that will cause the Cmp to fail/succeed for the recursive call.
+bool CallAnalyzer::simplifyCmpInstForRecCall(CmpInst &Cmp) {
+ // Bail out if LHS is not a function argument or RHS is NOT const:
+ if (!isa<Argument>(Cmp.getOperand(0)) || !isa<Constant>(Cmp.getOperand(1)))
+ return false;
+ auto *CmpOp = Cmp.getOperand(0);
+ Function *F = Cmp.getFunction();
+ // Iterate over the users of the function to check if it's a recursive
+ // function:
+ for (auto *U : F->users()) {
----------------
nikic wrote:
My concern here is that there may be multiple calls of the function, only one of which is the recursive call you are interested in. We will separate compute the cost for each of these call-sites -- but we will treat each of them as if they were the recursive call, and thus incorrectly assign them a lower cost. Instead, we should only do this when trying to inline the actual recursive call, as given by CandidateCall.
https://github.com/llvm/llvm-project/pull/119677
More information about the llvm-commits
mailing list