From 347d5b64324d300ea40cee67e332ccd8669fa08a Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Sun, 25 Sep 2016 23:12:04 +0000 Subject: [PATCH] [SCEV] Have ExitNotTakenInfo keep a pointer to its predicate; NFC SCEVUnionPredicate is a "heavyweight" structure, so it is beneficial to store the (optional) data out of line. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282366 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/ScalarEvolution.h | 10 ++++++++-- lib/Analysis/ScalarEvolution.cpp | 26 +++++++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h index 0c615d150eb..64c0378ec6f 100644 --- a/include/llvm/Analysis/ScalarEvolution.h +++ b/include/llvm/Analysis/ScalarEvolution.h @@ -581,10 +581,16 @@ private: struct ExitNotTakenInfo { AssertingVH ExitingBlock; const SCEV *ExactNotTaken; - SCEVUnionPredicate Predicate; + std::unique_ptr Predicate; bool hasAlwaysTruePredicate() const { - return Predicate.isAlwaysTrue(); + return !Predicate || Predicate->isAlwaysTrue(); } + + explicit ExitNotTakenInfo(AssertingVH ExitingBlock, + const SCEV *ExactNotTaken, + std::unique_ptr Predicate) + : ExitingBlock(ExitingBlock), ExactNotTaken(ExactNotTaken), + Predicate(std::move(Predicate)) {} }; /// Information about the backedge-taken count of a loop. This currently diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 32ef53f4c9c..a5b1be08df6 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -5442,7 +5442,7 @@ ScalarEvolution::getPredicatedBackedgeTakenInfo(const Loop *L) { BackedgeTakenInfo Result = computeBackedgeTakenCount(L, /*AllowPredicates=*/true); - return PredicatedBackedgeTakenCounts.find(L)->second = Result; + return PredicatedBackedgeTakenCounts.find(L)->second = std::move(Result); } const ScalarEvolution::BackedgeTakenInfo & @@ -5517,7 +5517,7 @@ ScalarEvolution::getBackedgeTakenInfo(const Loop *L) { // recusive call to getBackedgeTakenInfo (on a different // loop), which would invalidate the iterator computed // earlier. - return BackedgeTakenCounts.find(L)->second = Result; + return BackedgeTakenCounts.find(L)->second = std::move(Result); } void ScalarEvolution::forgetLoop(const Loop *L) { @@ -5615,8 +5615,8 @@ ScalarEvolution::BackedgeTakenInfo::getExact(ScalarEvolution *SE, BECount = ENT.ExactNotTaken; else if (BECount != ENT.ExactNotTaken) return SE->getCouldNotCompute(); - if (Preds) - Preds->add(&ENT.Predicate); + if (Preds && !ENT.hasAlwaysTruePredicate()) + Preds->add(ENT.Predicate.get()); assert((Preds || ENT.hasAlwaysTruePredicate()) && "Predicate should be always true!"); @@ -5670,13 +5670,17 @@ ScalarEvolution::BackedgeTakenInfo::BackedgeTakenInfo( ArrayRef ExitCounts, bool Complete, const SCEV *MaxCount) : MaxAndComplete(MaxCount, Complete) { - std::transform(ExitCounts.begin(), ExitCounts.end(), - std::back_inserter(ExitNotTaken), - [&](const ScalarEvolution::EdgeExitInfo &EEI) { - BasicBlock *ExitBB = EEI.first; - const ExitLimit &EL = EEI.second; - return ExitNotTakenInfo({ExitBB, EL.ExactNotTaken, EL.Predicate}); - }); + std::transform( + ExitCounts.begin(), ExitCounts.end(), std::back_inserter(ExitNotTaken), + [&](const ScalarEvolution::EdgeExitInfo &EEI) { + BasicBlock *ExitBB = EEI.first; + const ExitLimit &EL = EEI.second; + if (EL.Predicate.isAlwaysTrue()) + return ExitNotTakenInfo(ExitBB, EL.ExactNotTaken, nullptr); + return ExitNotTakenInfo( + ExitBB, EL.ExactNotTaken, + llvm::make_unique(std::move(EL.Predicate))); + }); } /// Invalidate this result and free the ExitNotTakenInfo array. -- 2.11.0