[llvm] [Analysis]: Allow inlining recursive call IF recursion depth is 1. (PR #119677)
Hassnaa Hamdi via llvm-commits
llvm-commits at lists.llvm.org
Tue May 13 03:54:20 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()) {
----------------
hassnaaHamdi wrote:
Today, I will create a patch for the ValueTracking, and another patch for resolving your comments on InlineCost.
https://github.com/llvm/llvm-project/pull/119677
More information about the llvm-commits
mailing list