diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index f78ace36f83..a0ad89fac4f 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -44,6 +44,10 @@ protected: uint64_t Val; ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V); public: + + /// ConstantIntegral::get - Return a bool or integer constant. + static ConstantIntegral *get(const Type *Ty, int64_t V); + /// Return the constant as a 64-bit unsigned integer value after it /// has been zero extended as appropriate for the type of this constant. /// @brief Return the zero extended value. diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 06dcbb38a7b..c36fea94869 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -929,9 +929,12 @@ static ManagedStatic > IntConstants; // just return the stored value while getSExtValue has to convert back to sign // extended. getZExtValue is more common in LLVM than getSExtValue(). ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) { - unsigned Size = Ty->getPrimitiveSizeInBits(); - uint64_t ZeroExtendedCanonicalization = V & (~uint64_t(0UL) >> (64-Size)); - return IntConstants->getOrCreate(Ty, ZeroExtendedCanonicalization ); + return IntConstants->getOrCreate(Ty, V & Ty->getIntegralTypeMask()); +} + +ConstantIntegral *ConstantIntegral::get(const Type *Ty, int64_t V) { + if (Ty == Type::BoolTy) return ConstantBool::get(V&1); + return IntConstants->getOrCreate(Ty, V & Ty->getIntegralTypeMask()); } //---- ConstantFP::get() implementation...