diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index d515c130e99..509a6dbc12f 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -370,13 +370,13 @@ private: /// by properly seeding constants etc. LatticeVal &getValueState(Value *V) { assert(!isa(V->getType()) && "Should use getStructValueState"); - - // TODO: Change to do insert+find in one operation. - DenseMap::iterator I = ValueState.find(V); - if (I != ValueState.end()) - return I->second; // Common case, already in the map. - LatticeVal &LV = ValueState[V]; + std::pair::iterator, bool> I = + ValueState.insert(std::make_pair(V, LatticeVal())); + LatticeVal &LV = I.first->second; + + if (!I.second) + return LV; // Common case, already in the map. if (Constant *C = dyn_cast(V)) { // Undef values remain undefined. @@ -395,15 +395,15 @@ private: assert(isa(V->getType()) && "Should use getValueState"); assert(i < cast(V->getType())->getNumElements() && "Invalid element #"); - - // TODO: Change to do insert+find in one operation. - DenseMap, LatticeVal>::iterator - I = StructValueState.find(std::make_pair(V, i)); - if (I != StructValueState.end()) - return I->second; // Common case, already in the map. - - LatticeVal &LV = StructValueState[std::make_pair(V, i)]; - + + std::pair, LatticeVal>::iterator, + bool> I = StructValueState.insert( + std::make_pair(std::make_pair(V, i), LatticeVal())); + LatticeVal &LV = I.first->second; + + if (!I.second) + return LV; // Common case, already in the map. + if (Constant *C = dyn_cast(V)) { if (isa(C)) ; // Undef values remain undefined.