X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FConstants.cpp;h=cb7c9e63059ad86c1a92ae44b479b402ea7dc18f;hb=be63d589633bbfa068b923c60eaaeee1b27647c5;hp=c2c3c40df1c4dba6604da278ad8c395f0ff8bb4e;hpb=3b666f3b591b2e251e0edde332b98bfd9ee25cfd;p=oota-llvm.git diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index c2c3c40df1c..cb7c9e63059 100644 --- a/lib/IR/Constants.cpp +++ b/lib/IR/Constants.cpp @@ -2810,17 +2810,41 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To, void ConstantVector::replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U) { assert(isa(To) && "Cannot make Constant refer to non-constant!"); + Constant *ToC = cast(To); SmallVector Values; Values.reserve(getNumOperands()); // Build replacement array... + unsigned NumUpdated = 0; for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { Constant *Val = getOperand(i); - if (Val == From) Val = cast(To); + if (Val == From) { + ++NumUpdated; + Val = ToC; + } Values.push_back(Val); } - Constant *Replacement = get(Values); - replaceUsesOfWithOnConstantImpl(Replacement); + if (Constant *C = getImpl(Values)) { + replaceUsesOfWithOnConstantImpl(C); + return; + } + + // Update to the new value. Optimize for the case when we have a single + // operand that we're changing, but handle bulk updates efficiently. + auto &pImpl = getType()->getContext().pImpl; + pImpl->VectorConstants.remove(this); + + if (NumUpdated == 1) { + unsigned OperandToUpdate = U - OperandList; + assert(getOperand(OperandToUpdate) == From && "ReplaceAllUsesWith broken!"); + setOperand(OperandToUpdate, ToC); + } else { + for (unsigned I = 0, E = getNumOperands(); I != E; ++I) + if (getOperand(I) == From) + setOperand(I, ToC); + } + + pImpl->VectorConstants.insert(this); } void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV,