[llvm] [FuncAttrs] Relax norecurse attribute inference (PR #139943)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 6 01:25:02 PDT 2025
================
@@ -2071,24 +2072,36 @@ static void addNoRecurseAttrs(const SCCNodeSet &SCCNodes,
if (!F || !F->hasExactDefinition() || F->doesNotRecurse())
return;
- // If all of the calls in F are identifiable and are to norecurse functions, F
- // is norecurse. This check also detects self-recursion as F is not currently
- // marked norecurse, so any called from F to F will not be marked norecurse.
- for (auto &BB : *F)
- for (auto &I : BB.instructionsWithoutDebug())
+ if (F->hasAddressTaken())
----------------
david-arm wrote:
Hmm, thinking about this now I'm not sure it solves problems like this:
```
foo() -> bar() -> moo() -> foo()
```
or
```
boo() -> foo() -> bar() -> moo() -> boo()
```
where effectively foo() is recursive despite foo() not directly calling itself? I think the previous version of your patch solved this problem, although @nikic mentioned FunctionAttrs probably isn't the right place for deeper inspection. For a full analysis I think you still need to inspect the call graph. I'm not sure how useful this is, but you could check that all functions called by `foo()` don't make any function calls themselves? I don't know if this is a quick and easy check, or whether it's just as computationally expensive as your previous version?
https://github.com/llvm/llvm-project/pull/139943
More information about the llvm-commits
mailing list