diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 61659bfbd126df..ddd4f6a3b8af85 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1281,7 +1281,7 @@ class ScalarEvolution { DenseMap MinTrailingZerosCache; /// Return the Value set from which the SCEV expr is generated. - ValueSetVector *getSCEVValues(const SCEV *S); + ArrayRef getSCEVValues(const SCEV *S); /// Private helper method for the GetMinTrailingZeros method uint32_t GetMinTrailingZerosImpl(const SCEV *S); diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 05ee7da8860902..aa7f124ce4d30d 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -4280,11 +4280,10 @@ bool ScalarEvolution::containsAddRecurrence(const SCEV *S) { /// Return the ValueOffsetPair set for \p S. \p S can be represented /// by the value and offset from any ValueOffsetPair in the set. -ScalarEvolution::ValueSetVector * -ScalarEvolution::getSCEVValues(const SCEV *S) { +ArrayRef ScalarEvolution::getSCEVValues(const SCEV *S) { ExprValueMapType::iterator SI = ExprValueMap.find_as(S); if (SI == ExprValueMap.end()) - return nullptr; + return None; #ifndef NDEBUG if (VerifySCEVMap) { // Check there is no dangling Value in the set returned. @@ -4292,7 +4291,7 @@ ScalarEvolution::getSCEVValues(const SCEV *S) { assert(ValueExprMap.count(V)); } #endif - return &SI->second; + return SI->second.getArrayRef(); } /// Erase Value from ValueExprMap and ExprValueMap. ValueExprMap.erase(V) @@ -4301,11 +4300,11 @@ ScalarEvolution::getSCEVValues(const SCEV *S) { void ScalarEvolution::eraseValueFromMap(Value *V) { ValueExprMapType::iterator I = ValueExprMap.find_as(V); if (I != ValueExprMap.end()) { - const SCEV *S = I->second; - // Remove V from the set of ExprValueMap[S] - if (auto *SV = getSCEVValues(S)) - SV->remove(V); - ValueExprMap.erase(V); + auto EVIt = ExprValueMap.find(I->second); + bool Removed = EVIt->second.remove(V); + (void) Removed; + assert(Removed && "Value not in ExprValueMap?"); + ValueExprMap.erase(I); } } diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 00c5b5053f9e3e..327d15d1b90db0 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -1872,17 +1872,17 @@ Value *SCEVExpander::expandCodeForImpl(const SCEV *SH, Type *Ty, bool Root) { Value *SCEVExpander::FindValueInExprValueMap(const SCEV *S, const Instruction *InsertPt) { - auto *Set = SE.getSCEVValues(S); + ArrayRef Set = SE.getSCEVValues(S); // If the expansion is not in CanonicalMode, and the SCEV contains any // sub scAddRecExpr type SCEV, it is required to expand the SCEV literally. if (CanonicalMode || !SE.containsAddRecurrence(S)) { // If S is scConstant, it may be worse to reuse an existing Value. - if (S->getSCEVType() != scConstant && Set) { + if (S->getSCEVType() != scConstant) { // Choose a Value from the set which dominates the InsertPt. // InsertPt should be inside the Value's parent loop so as not to break // the LCSSA form. - for (Value *V : *Set) { - Instruction *EntInst = dyn_cast_or_null(V); + for (Value *V : Set) { + Instruction *EntInst = dyn_cast(V); if (!EntInst) continue;