From: Craig Topper Date: Wed, 7 Jun 2017 00:58:05 +0000 (+0000) Subject: [Constants] Use isUIntN/isIntN from MathExtras instead of reimplementing the same... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a26780d808b1cad47687c86bd423fea9b912aa16;p=llvm [Constants] Use isUIntN/isIntN from MathExtras instead of reimplementing the same code. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304856 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index 84a57e593dc..27150a89d9b 100644 --- a/lib/IR/Constants.cpp +++ b/lib/IR/Constants.cpp @@ -1157,21 +1157,14 @@ bool ConstantInt::isValueValidForType(Type *Ty, uint64_t Val) { unsigned NumBits = Ty->getIntegerBitWidth(); // assert okay if (Ty->isIntegerTy(1)) return Val == 0 || Val == 1; - if (NumBits >= 64) - return true; // always true, has to fit in largest type - uint64_t Max = (1ll << NumBits) - 1; - return Val <= Max; + return isUIntN(NumBits, Val); } bool ConstantInt::isValueValidForType(Type *Ty, int64_t Val) { unsigned NumBits = Ty->getIntegerBitWidth(); if (Ty->isIntegerTy(1)) return Val == 0 || Val == 1 || Val == -1; - if (NumBits >= 64) - return true; // always true, has to fit in largest type - int64_t Min = -(1ll << (NumBits-1)); - int64_t Max = (1ll << (NumBits-1)) - 1; - return (Val >= Min && Val <= Max); + return isIntN(NumBits, Val); } bool ConstantFP::isValueValidForType(Type *Ty, const APFloat& Val) {