[llvm] r304856 - [Constants] Use isUIntN/isIntN from MathExtras instead of reimplementing the same code. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 17:58:05 PDT 2017


Author: ctopper
Date: Tue Jun  6 19:58:05 2017
New Revision: 304856

URL: http://llvm.org/viewvc/llvm-project?rev=304856&view=rev
Log:
[Constants] Use isUIntN/isIntN from MathExtras instead of reimplementing the same code. NFC

Modified:
    llvm/trunk/lib/IR/Constants.cpp

Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=304856&r1=304855&r2=304856&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Tue Jun  6 19:58:05 2017
@@ -1157,21 +1157,14 @@ bool ConstantInt::isValueValidForType(Ty
   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) {




More information about the llvm-commits mailing list