From 9b7b5482fa01413a96fe79c42c3e67ee6730cf6d Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Wed, 11 Jan 2023 17:47:14 -0800 Subject: [PATCH] [Attributor] Allow AAs to iterate on their own state Future AAs might need to iterate their own state until they reach a fixpoint. We do not want to forbid that but we want to avoid negative effects or bugs once this happens. As a precaution, we now rerun an AA that did not require outside information. If it does not change anymore we are done, otherwise the AA needs to iterate some more. --- llvm/lib/Transforms/IPO/Attributor.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 50facdb..416f554 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -2411,10 +2411,20 @@ ChangeStatus Attributor::updateAA(AbstractAttribute &AA) { /* CheckBBLivenessOnly */ true)) CS = AA.update(*this); - if (!AA.isQueryAA() && DV.empty()) { - // If the attribute did not query any non-fix information, the state - // will not change and we can indicate that right away. - AAState.indicateOptimisticFixpoint(); + if (!AA.isQueryAA() && DV.empty() && !AA.getState().isAtFixpoint()) { + // If the AA did not rely on outside information but changed, we run it + // again to see if it found a fixpoint. Most AAs do but we don't require + // them to. Hence, it might take the AA multiple iterations to get to a + // fixpoint even if it does not rely on outside information, which is fine. + ChangeStatus RerunCS = ChangeStatus::UNCHANGED; + if (CS == ChangeStatus::CHANGED) + RerunCS = AA.update(*this); + + // If the attribute did not change during the run or rerun, and it still did + // not query any non-fix information, the state will not change and we can + // indicate that right at this point. + if (RerunCS == ChangeStatus::UNCHANGED && !AA.isQueryAA() && DV.empty()) + AAState.indicateOptimisticFixpoint(); } if (!AAState.isAtFixpoint()) -- 2.7.4