Index: lib/Transforms/Scalar/RewriteStatepointsForGC.cpp =================================================================== --- lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -732,7 +732,7 @@ #ifndef NDEBUG DEBUG(dbgs() << "States after initialization:\n"); - for (auto Pair : States) { + for (const auto &Pair : States) { DEBUG(dbgs() << " " << Pair.second << " for " << *Pair.first << "\n"); } #endif @@ -757,8 +757,9 @@ // Since this is computing a fixed point, the order of visit does not // effect the result. TODO: We could use a worklist here and make this run // much faster. - for (auto Pair : States) { + for (auto &Pair : States) { Value *BDV = Pair.first; + BDVState &State = Pair.second; assert(!isKnownBaseResult(BDV) && "why did it get added?"); // Given an input value for the current instruction, return a BDVState @@ -794,10 +795,9 @@ NewState = meetBDVState(NewState, getStateForInput(SV->getOperand(1))); } - BDVState OldState = States[BDV]; - if (OldState != NewState) { + if (State != NewState) { Progress = true; - States[BDV] = NewState; + State = NewState; } } @@ -807,16 +807,16 @@ #ifndef NDEBUG DEBUG(dbgs() << "States after meet iteration:\n"); - for (auto Pair : States) { + for (const auto &Pair : States) { DEBUG(dbgs() << " " << Pair.second << " for " << *Pair.first << "\n"); } #endif // Insert Phis for all conflicts // TODO: adjust naming patterns to avoid this order of iteration dependency - for (auto Pair : States) { + for (auto &Pair : States) { Instruction *I = cast(Pair.first); - BDVState State = Pair.second; + BDVState &State = Pair.second; assert(!isKnownBaseResult(I) && "why did it get added?"); assert(!State.isUnknown() && "Optimistic algorithm didn't complete!"); @@ -833,7 +833,7 @@ auto *BaseInst = ExtractElementInst::Create( State.getBaseValue(), EE->getIndexOperand(), "base_ee", EE); BaseInst->setMetadata("is_base_value", MDNode::get(I->getContext(), {})); - States[I] = BDVState(BDVState::Base, BaseInst); + State = BDVState(BDVState::Base, BaseInst); } // Since we're joining a vector and scalar base, they can never be the @@ -880,7 +880,7 @@ Instruction *BaseInst = MakeBaseInstPlaceholder(I); // Add metadata marking this as a base value BaseInst->setMetadata("is_base_value", MDNode::get(I->getContext(), {})); - States[I] = BDVState(BDVState::Conflict, BaseInst); + State = BDVState(BDVState::Conflict, BaseInst); } // Returns a instruction which produces the base pointer for a given @@ -911,7 +911,7 @@ // Fixup all the inputs of the new PHIs. Visit order needs to be // deterministic and predictable because we're naming newly created // instructions. - for (auto Pair : States) { + for (const auto &Pair : States) { Instruction *BDV = cast(Pair.first); BDVState State = Pair.second; @@ -1001,7 +1001,7 @@ // Cache all of our results so we can cheaply reuse them // NOTE: This is actually two caches: one of the base defining value // relation and one of the base pointer relation! FIXME - for (auto Pair : States) { + for (const auto &Pair : States) { auto *BDV = Pair.first; Value *Base = Pair.second.getBaseValue(); assert(BDV && Base);