diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -875,8 +875,9 @@ // get an existing value or the insertion position LLVMContextImpl *pImpl = Context.pImpl; std::unique_ptr &Slot = - V.isZero() ? pImpl->IntZeroConstants[V.getBitWidth()] - : pImpl->IntConstants[V]; + V.isZero() ? pImpl->IntZeroConstants[V.getBitWidth()] + : V.isOne() ? pImpl->IntOneConstants[V.getBitWidth()] + : pImpl->IntConstants[V]; if (!Slot) { // Get the corresponding integer type for the bit width of the value. IntegerType *ITy = IntegerType::get(Context, V.getBitWidth()); diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -1447,6 +1447,7 @@ DenseMap ValueNames; DenseMap> IntZeroConstants; + DenseMap> IntOneConstants; DenseMap, DenseMapAPIntKeyInfo> IntConstants; diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -117,6 +117,7 @@ UVConstants.clear(); PVConstants.clear(); IntZeroConstants.clear(); + IntOneConstants.clear(); IntConstants.clear(); FPConstants.clear(); CDSConstants.clear();