From: Johannes Doerfert Date: Tue, 15 Mar 2022 17:34:04 +0000 (-0500) Subject: [Attributor] Move recursion reasoning into `AA::isPotentiallyReachable` X-Git-Tag: upstream/15.0.7~11356 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a8610d752306b48f914eb21108f2d1cb1fd6b710;p=platform%2Fupstream%2Fllvm.git [Attributor] Move recursion reasoning into `AA::isPotentiallyReachable` With D106397 we ensured that `AAReachability` will not answer queries for potentially recursive functions. This was necessary as we did not treat recursion explicitly otherwise. Now that we have `AA::isPotentiallyReachable` we can make `AAReachability` a purely intra-procedural AA which does not care about recursion. `AA::isPotentiallyReachable`, however, does already deal with "going back" the call graph and can now do so for potentially recursive functions. --- diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index d2c9653..489914b 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -519,6 +519,8 @@ isPotentiallyReachable(Attributor &A, const Instruction &FromI, SmallVector Worklist; Worklist.push_back(&FromI); + const auto &NoRecurseAA = A.getAAFor( + QueryingAA, IRPosition::function(ToFn), DepClassTy::OPTIONAL); while (!Worklist.empty()) { const Instruction *CurFromI = Worklist.pop_back_val(); if (!Visited.insert(CurFromI).second) @@ -538,7 +540,8 @@ isPotentiallyReachable(Attributor &A, const Instruction &FromI, << *ToI << " [Intra]\n"); if (Result) return true; - continue; + if (NoRecurseAA.isAssumedNoRecurse()) + continue; } // TODO: If we can go arbitrarily backwards we will eventually reach an diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index fc97946..b8c4864 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -3071,10 +3071,6 @@ struct AAReachabilityImpl : AAReachability { /// See AbstractAttribute::updateImpl(...). ChangeStatus updateImpl(Attributor &A) override { - const auto &NoRecurseAA = A.getAAFor( - *this, IRPosition::function(*getAnchorScope()), DepClassTy::REQUIRED); - if (!NoRecurseAA.isAssumedNoRecurse()) - return indicatePessimisticFixpoint(); return ChangeStatus::UNCHANGED; } }; @@ -3306,12 +3302,6 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl { return true; if (ScopeFn) { - const auto &ReachabilityAA = A.getAAFor( - *this, IRPosition::function(*ScopeFn), DepClassTy::OPTIONAL); - - if (!ReachabilityAA.isAssumedReachable(A, *UserI, *getCtxI())) - return true; - if (auto *CB = dyn_cast(UserI)) { if (CB->isArgOperand(&U)) { @@ -3325,6 +3315,9 @@ struct AANoAliasCallSiteArgument final : AANoAliasImpl { return true; } } + + if (!AA::isPotentiallyReachable(A, *UserI, *getCtxI(), *this)) + return true; } // For cases which can potentially have more users