[llvm] [Analysis]: Allow inlining recursive call IF recursion depth is 1. (PR #119677)
Hassnaa Hamdi via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 15:00:53 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:
Yeah, I got your point. Yes, I agree with you.
I think there should be a patch for ValueTracking changes, and another following patch for the 2 points you mentioned about the Inliner.
https://github.com/llvm/llvm-project/pull/119677
More information about the llvm-commits
mailing list