From: Florian Hahn Date: Wed, 30 Sep 2020 11:39:30 +0000 (+0100) Subject: [SCEV] Verify that all mapped SCEV AddRecs refer to valid loops. X-Git-Tag: llvmorg-13-init~10527 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0eab9d5823815c6520697f8d725c402c88e5d050;p=platform%2Fupstream%2Fllvm.git [SCEV] Verify that all mapped SCEV AddRecs refer to valid loops. This check helps to guard against cases where expressions referring to invalidated/deleted loops are not properly invalidated. The additional check is motivated by the reproducer shared for 8fdac7cb7abb and I think in general make sense as a sanity check. Reviewed By: reames Differential Revision: https://reviews.llvm.org/D88166 --- diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 7567109..8759f86 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -12005,6 +12005,25 @@ void ScalarEvolution::verify() const { std::abort(); } } + + // Collect all valid loops currently in LoopInfo. + SmallPtrSet ValidLoops; + SmallVector Worklist(LI.begin(), LI.end()); + while (!Worklist.empty()) { + Loop *L = Worklist.pop_back_val(); + if (ValidLoops.contains(L)) + continue; + ValidLoops.insert(L); + Worklist.append(L->begin(), L->end()); + } + // Check for SCEV expressions referencing invalid/deleted loops. + for (auto &KV : ValueExprMap) { + auto *AR = dyn_cast(KV.second); + if (!AR) + continue; + assert(ValidLoops.contains(AR->getLoop()) && + "AddRec references invalid loop"); + } } bool ScalarEvolution::invalidate(