summaryrefslogtreecommitdiff
path: root/lib/IR/Constants.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/IR/Constants.cpp')
-rw-r--r--lib/IR/Constants.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp
index 8b0ff66334a7..27150a89d9b2 100644
--- a/lib/IR/Constants.cpp
+++ b/lib/IR/Constants.cpp
@@ -127,7 +127,7 @@ bool Constant::isOneValue() const {
// Check for FP which are bitcasted from 1 integers
if (const ConstantFP *CFP = dyn_cast<ConstantFP>(this))
- return CFP->getValueAPF().bitcastToAPInt() == 1;
+ return CFP->getValueAPF().bitcastToAPInt().isOneValue();
// Check for constant vectors which are splats of 1 values.
if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
@@ -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) {