For PR1043:

Merge ConstantIntegral and ConstantBool into ConstantInt.
Remove ConstantIntegral and ConstantBool from LLVM.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33073 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Zhou Sheng
2007-01-11 12:24:14 +00:00
parent 057809ac1c
commit 6b6b6ef167
43 changed files with 1974 additions and 1868 deletions
+69 -120
View File
@@ -36,18 +36,19 @@ template<class ConstantClass, class TypeClass>
struct ConvertConstantType;
//===----------------------------------------------------------------------===//
/// This is the shared superclass of boolean and integer constants. This class
/// just defines some common interfaces to be implemented by the subclasses.
/// @brief An abstract class for integer constants.
class ConstantIntegral : public Constant {
/// This is the shared class of boolean and integrer constants. This class
/// represents both boolean and integral constants.
/// @brief Class for constant integers.
class ConstantInt : public Constant {
protected:
uint64_t Val;
ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V);
protected:
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
ConstantInt(const Type *Ty, uint64_t V);
ConstantInt(const Type *Ty, int64_t V);
ConstantInt(bool V);
friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
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.
@@ -62,106 +63,6 @@ public:
unsigned Size = getType()->getPrimitiveSizeInBits();
return (int64_t(Val) << (64-Size)) >> (64-Size);
}
/// This function is implemented by subclasses and will return true iff this
/// constant represents the the "null" value that would be returned by the
/// getNullValue method.
/// @returns true if the constant's value is 0.
/// @brief Determine if the value is null.
virtual bool isNullValue() const = 0;
/// This function is implemented by sublcasses and will return true iff this
/// constant represents the the largest value that may be represented by this
/// constant's type.
/// @returns true if the constant's value is maximal.
/// @brief Determine if the value is maximal.
virtual bool isMaxValue(bool isSigned) const = 0;
/// This function is implemented by subclasses and will return true iff this
/// constant represents the smallest value that may be represented by this
/// constant's type.
/// @returns true if the constant's value is minimal
/// @brief Determine if the value is minimal.
virtual bool isMinValue(bool isSigned) const = 0;
/// This function is implemented by subclasses and will return true iff every
/// bit in this constant is set to true.
/// @returns true if all bits of the constant are ones.
/// @brief Determine if the value is all ones.
virtual bool isAllOnesValue() const = 0;
/// @returns the value for an integer constant of the given type that has all
/// its bits set to true.
/// @brief Get the all ones value
static ConstantIntegral *getAllOnesValue(const Type *Ty);
/// Methods to support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantIntegral *) { return true; }
static bool classof(const Value *V) {
return V->getValueType() == ConstantBoolVal ||
V->getValueType() == ConstantIntVal;
}
};
//===----------------------------------------------------------------------===//
/// This concrete class represents constant values of type BoolTy. There are
/// only two instances of this class constructed: the True and False static
/// members. The constructor is hidden to ensure this invariant.
/// @brief Constant Boolean class
class ConstantBool : public ConstantIntegral {
ConstantBool(bool V);
public:
/// getTrue/getFalse - Return the singleton true/false values.
static ConstantBool *getTrue();
static ConstantBool *getFalse();
/// This method is provided mostly for compatibility with the other
/// ConstantIntegral subclasses.
/// @brief Static factory method for getting a ConstantBool instance.
static ConstantBool *get(bool Value) { return Value ? getTrue() : getFalse();}
/// This method is provided mostly for compatibility with the other
/// ConstantIntegral subclasses.
/// @brief Static factory method for getting a ConstantBool instance.
static ConstantBool *get(const Type *Ty, bool Value) { return get(Value); }
/// Returns the opposite value of this ConstantBool value.
/// @brief Get inverse value.
inline ConstantBool *inverted() const {
return getValue() ? getFalse() : getTrue();
}
/// @returns the value of this ConstantBool
/// @brief return the boolean value of this constant.
inline bool getValue() const { return static_cast<bool>(getZExtValue()); }
/// @see ConstantIntegral for details
/// @brief Implement overrides
virtual bool isNullValue() const { return getValue() == false; }
virtual bool isMaxValue(bool isSigned) const { return getValue() == true; }
virtual bool isMinValue(bool isSigned) const { return getValue() == false; }
virtual bool isAllOnesValue() const { return getValue() == true; }
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const ConstantBool *) { return true; }
static bool classof(const Value *V) {
return V->getValueType() == ConstantBoolVal;
}
};
//===----------------------------------------------------------------------===//
/// This is concrete integer subclass of ConstantIntegral that represents
/// both signed and unsigned integral constants, other than boolean.
/// @brief Class for constant integers.
class ConstantInt : public ConstantIntegral {
protected:
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
ConstantInt(const Type *Ty, uint64_t V);
ConstantInt(const Type *Ty, int64_t V);
friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
public:
/// A helper method that can be used to determine if the constant contained
/// within is equal to a constant. This only works for very small values,
/// because this is all that can be represented with all types.
@@ -172,13 +73,45 @@ public:
return Val == V;
}
/// getTrue/getFalse - Return the singleton true/false values.
static inline ConstantInt *getTrue() {
static ConstantInt *T = 0;
if (T) return T;
return T = new ConstantInt(true);
}
static inline ConstantInt *getFalse() {
static ConstantInt *F = 0;
if (F) return F;
return F = new ConstantInt(false);
}
/// @brief Static factory method for getting a ConstantInt instance which
/// stands for a bool value.
static ConstantInt *get(bool Value) { return Value ? getTrue() : getFalse();}
/// Return a ConstantInt with the specified value for the specified type. The
/// value V will be canonicalized to a uint64_t but accessing it with either
/// getSExtValue() or getZExtValue() (ConstantIntegral) will yield the correct
/// getSExtValue() or getZExtValue() (ConstantInt) will yield the correct
/// sized/signed value for the type Ty.
/// @brief Get a ConstantInt for a specific value.
static ConstantInt *get(const Type *Ty, int64_t V);
/// Returns the opposite value of this ConstantInt value if it's a boolean
/// constant.
/// @brief Get inverse value.
inline ConstantInt *inverted() const {
static ConstantInt *CI = 0;
if (CI) return CI;
return CI = new ConstantInt(getType(), Val ^ (-1));
}
/// @returns the value of this ConstantInt only if it's a boolean type.
/// @brief return the boolean value of this constant.
inline bool getBoolValue() const {
assert(getType() == Type::BoolTy && "Should be a boolean constant!");
return static_cast<bool>(getZExtValue());
}
/// This static method returns true if the type Ty is big enough to
/// represent the value V. This can be used to avoid having the get method
/// assert when V is larger than Ty can represent. Note that there are two
@@ -191,21 +124,30 @@ public:
static bool isValueValidForType(const Type *Ty, uint64_t V);
static bool isValueValidForType(const Type *Ty, int64_t V);
/// This function will return true iff this constant represents the "null"
/// value that would be returned by the getNullValue method.
/// @returns true if this is the null integer value.
/// @see ConstantIntegral for details
/// @brief Implement override.
virtual bool isNullValue() const { return Val == 0; }
/// @brief Determine if the value is null.
virtual bool isNullValue() const {
return Val == 0;
}
/// This function will return true iff every bit in this constant is set
/// to true.
/// @returns true iff this constant's bits are all set to true.
/// @see ConstantIntegral
/// @brief Override implementation
virtual bool isAllOnesValue() const { return getSExtValue() == -1; }
/// @brief Determine if the value is all ones.
virtual bool isAllOnesValue() const {
if (getType() == Type::BoolTy) return getBoolValue() == true;
return getSExtValue() == -1;
}
/// This function will return true iff this constant represents the largest
/// value that may be represented by the constant's type.
/// @returns true iff this is the largest value that may be represented
/// by this type.
/// @see ConstantIntegeral
/// @brief Override implementation
/// @brief Determine if the value is maximal.
virtual bool isMaxValue(bool isSigned) const {
if (getType() == Type::BoolTy) return getBoolValue() == true;
if (isSigned) {
int64_t V = getSExtValue();
if (V < 0) return false; // Be careful about wrap-around on 'long's
@@ -215,11 +157,13 @@ public:
return isAllOnesValue();
}
/// This function will return true iff this constant represents the smallest
/// value that may be represented by this constant's type.
/// @returns true if this is the smallest value that may be represented by
/// this type.
/// @see ConstantIntegral
/// @brief Override implementation
/// @brief Determine if the value is minimal.
virtual bool isMinValue(bool isSigned) const {
if (getType() == Type::BoolTy) return getBoolValue() == false;
if (isSigned) {
int64_t V = getSExtValue();
if (V > 0) return false; // Be careful about wrap-around on 'long's
@@ -229,6 +173,11 @@ public:
return getZExtValue() == 0;
}
/// @returns the value for an integer constant of the given type that has all
/// its bits set to true.
/// @brief Get the all ones value
static ConstantInt *getAllOnesValue(const Type *Ty);
/// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
static inline bool classof(const ConstantInt *) { return true; }
static bool classof(const Value *V) {
+5 -6
View File
@@ -36,12 +36,11 @@
namespace llvm {
class Constant;
class ConstantIntegral;
class ConstantInt;
class Type;
class ConstantRange {
ConstantIntegral *Lower, *Upper;
ConstantInt *Lower, *Upper;
public:
/// Initialize a full (the default) or empty set for the specified type.
///
@@ -61,15 +60,15 @@ class ConstantRange {
/// predicate should be either an ICmpInst::Predicate or FCmpInst::Predicate
/// value.
/// @brief Get a range for a relation with a constant integral.
ConstantRange(unsigned short predicate, ConstantIntegral *C);
ConstantRange(unsigned short predicate, ConstantInt *C);
/// getLower - Return the lower value for this range...
///
ConstantIntegral *getLower() const { return Lower; }
ConstantInt *getLower() const { return Lower; }
/// getUpper - Return the upper value for this range...
///
ConstantIntegral *getUpper() const { return Upper; }
ConstantInt *getUpper() const { return Upper; }
/// getType - Return the LLVM data type of this range.
///
@@ -98,7 +97,7 @@ class ConstantRange {
/// getSingleElement - If this set contains a single element, return it,
/// otherwise return null.
///
ConstantIntegral *getSingleElement() const;
ConstantInt *getSingleElement() const;
/// isSingleElement - Return true if this set contains exactly one member.
///
+2 -2
View File
@@ -356,9 +356,9 @@ struct not_match {
}
private:
bool matchIfNot(Value *LHS, Value *RHS) {
if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(RHS))
if (ConstantInt *CI = dyn_cast<ConstantInt>(RHS))
return CI->isAllOnesValue() && L.match(LHS);
else if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(LHS))
else if (ConstantInt *CI = dyn_cast<ConstantInt>(LHS))
return CI->isAllOnesValue() && L.match(RHS);
return false;
}
-1
View File
@@ -152,7 +152,6 @@ public:
UndefValueVal, // This is an instance of UndefValue
ConstantExprVal, // This is an instance of ConstantExpr
ConstantAggregateZeroVal, // This is an instance of ConstantAggregateNull
ConstantBoolVal, // This is an instance of ConstantBool
ConstantIntVal, // This is an instance of ConstantInt
ConstantFPVal, // This is an instance of ConstantFP
ConstantArrayVal, // This is an instance of ConstantArray
+9 -6
View File
@@ -434,7 +434,8 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size,
if (cast<PointerType>(
BasePtr->getType())->getElementType()->isSized()) {
for (unsigned i = 0; i != GEPOperands.size(); ++i)
if (!isa<ConstantInt>(GEPOperands[i]))
if (!isa<ConstantInt>(GEPOperands[i]) ||
GEPOperands[i]->getType() == Type::BoolTy)
GEPOperands[i] =
Constant::getNullValue(GEPOperands[i]->getType());
int64_t Offset =
@@ -584,8 +585,8 @@ BasicAliasAnalysis::CheckGEPInstructions(
if (G1OC) {
Constant *Compare = ConstantExpr::getICmp(ICmpInst::ICMP_SGT,
G1OC, G2OC);
if (ConstantBool *CV = dyn_cast<ConstantBool>(Compare)) {
if (CV->getValue()) // If they are comparable and G2 > G1
if (ConstantInt *CV = dyn_cast<ConstantInt>(Compare)) {
if (CV->getBoolValue()) // If they are comparable and G2 > G1
std::swap(GEP1Ops, GEP2Ops); // Make GEP1 < GEP2
break;
}
@@ -608,13 +609,15 @@ BasicAliasAnalysis::CheckGEPInstructions(
// Is there anything to check?
if (GEP1Ops.size() > MinOperands) {
for (unsigned i = FirstConstantOper; i != MaxOperands; ++i)
if (isa<ConstantInt>(GEP1Ops[i]) &&
if (isa<ConstantInt>(GEP1Ops[i]) &&
GEP1Ops[i]->getType() != Type::BoolTy &&
!cast<Constant>(GEP1Ops[i])->isNullValue()) {
// Yup, there's a constant in the tail. Set all variables to
// constants in the GEP instruction to make it suiteable for
// TargetData::getIndexedOffset.
for (i = 0; i != MaxOperands; ++i)
if (!isa<ConstantInt>(GEP1Ops[i]))
if (!isa<ConstantInt>(GEP1Ops[i]) ||
GEP1Ops[i]->getType() == Type::BoolTy)
GEP1Ops[i] = Constant::getNullValue(GEP1Ops[i]->getType());
// Okay, now get the offset. This is the relative offset for the full
// instruction.
@@ -667,7 +670,7 @@ BasicAliasAnalysis::CheckGEPInstructions(
const Value *Op2 = i < GEP2Ops.size() ? GEP2Ops[i] : 0;
// If they are equal, use a zero index...
if (Op1 == Op2 && BasePtr1Ty == BasePtr2Ty) {
if (!isa<ConstantInt>(Op1))
if (!isa<ConstantInt>(Op1) || Op1->getType() == Type::BoolTy)
GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Op1->getType());
// Otherwise, just keep the constants we have.
} else {
+25 -25
View File
@@ -30,9 +30,9 @@
#include <ostream>
using namespace llvm;
static ConstantIntegral *getMaxValue(const Type *Ty, bool isSigned = false) {
static ConstantInt *getMaxValue(const Type *Ty, bool isSigned = false) {
if (Ty == Type::BoolTy)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
if (Ty->isInteger()) {
if (isSigned) {
// Calculate 011111111111111...
@@ -47,9 +47,9 @@ static ConstantIntegral *getMaxValue(const Type *Ty, bool isSigned = false) {
}
// Static constructor to create the minimum constant for an integral type...
static ConstantIntegral *getMinValue(const Type *Ty, bool isSigned = false) {
static ConstantInt *getMinValue(const Type *Ty, bool isSigned = false) {
if (Ty == Type::BoolTy)
return ConstantBool::getFalse();
return ConstantInt::getFalse();
if (Ty->isInteger()) {
if (isSigned) {
// Calculate 1111111111000000000000
@@ -62,37 +62,37 @@ static ConstantIntegral *getMinValue(const Type *Ty, bool isSigned = false) {
}
return 0;
}
static ConstantIntegral *Next(ConstantIntegral *CI) {
if (ConstantBool *CB = dyn_cast<ConstantBool>(CI))
return ConstantBool::get(!CB->getValue());
static ConstantInt *Next(ConstantInt *CI) {
if (CI->getType() == Type::BoolTy)
return ConstantInt::get(!CI->getBoolValue());
Constant *Result = ConstantExpr::getAdd(CI,
ConstantInt::get(CI->getType(), 1));
return cast<ConstantIntegral>(Result);
return cast<ConstantInt>(Result);
}
static bool LT(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) {
static bool LT(ConstantInt *A, ConstantInt *B, bool isSigned) {
Constant *C = ConstantExpr::getICmp(
(isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
return cast<ConstantInt>(C)->getBoolValue();
}
static bool LTE(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) {
static bool LTE(ConstantInt *A, ConstantInt *B, bool isSigned) {
Constant *C = ConstantExpr::getICmp(
(isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
return cast<ConstantInt>(C)->getBoolValue();
}
static bool GT(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) {
static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) {
return LT(B, A, isSigned); }
static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B,
static ConstantInt *Min(ConstantInt *A, ConstantInt *B,
bool isSigned) {
return LT(A, B, isSigned) ? A : B;
}
static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B,
static ConstantInt *Max(ConstantInt *A, ConstantInt *B,
bool isSigned) {
return GT(A, B, isSigned) ? A : B;
}
@@ -111,14 +111,14 @@ ConstantRange::ConstantRange(const Type *Ty, bool Full) {
/// Initialize a range to hold the single specified value.
///
ConstantRange::ConstantRange(Constant *V)
: Lower(cast<ConstantIntegral>(V)), Upper(Next(cast<ConstantIntegral>(V))) { }
: Lower(cast<ConstantInt>(V)), Upper(Next(cast<ConstantInt>(V))) { }
/// Initialize a range of values explicitly... this will assert out if
/// Lower==Upper and Lower != Min or Max for its type (or if the two constants
/// have different types)
///
ConstantRange::ConstantRange(Constant *L, Constant *U)
: Lower(cast<ConstantIntegral>(L)), Upper(cast<ConstantIntegral>(U)) {
: Lower(cast<ConstantInt>(L)), Upper(cast<ConstantInt>(U)) {
assert(Lower->getType() == Upper->getType() &&
"Incompatible types for ConstantRange!");
@@ -130,7 +130,7 @@ ConstantRange::ConstantRange(Constant *L, Constant *U)
/// Initialize a set of values that all satisfy the condition with C.
///
ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantIntegral *C) {
ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantInt *C) {
switch (ICmpOpcode) {
default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!");
case ICmpInst::ICMP_EQ: Lower = C; Upper = Next(C); return;
@@ -195,7 +195,7 @@ bool ConstantRange::isWrappedSet(bool isSigned) const {
/// getSingleElement - If this set contains a single element, return it,
/// otherwise return null.
ConstantIntegral *ConstantRange::getSingleElement() const {
ConstantInt *ConstantRange::getSingleElement() const {
if (Upper == Next(Lower)) // Is it a single element range?
return Lower;
return 0;
@@ -292,8 +292,8 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR,
if (!isWrappedSet(isSigned)) {
if (!CR.isWrappedSet(isSigned)) {
ConstantIntegral *L = Max(Lower, CR.Lower, isSigned);
ConstantIntegral *U = Min(Upper, CR.Upper, isSigned);
ConstantInt *L = Max(Lower, CR.Lower, isSigned);
ConstantInt *U = Min(Upper, CR.Upper, isSigned);
if (LT(L, U, isSigned)) // If range isn't empty...
return ConstantRange(L, U);
@@ -306,8 +306,8 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR,
return intersect1Wrapped(*this, CR, isSigned);
else {
// Both ranges are wrapped...
ConstantIntegral *L = Max(Lower, CR.Lower, isSigned);
ConstantIntegral *U = Min(Upper, CR.Upper, isSigned);
ConstantInt *L = Max(Lower, CR.Lower, isSigned);
ConstantInt *U = Min(Upper, CR.Upper, isSigned);
return ConstantRange(L, U);
}
}
+15 -13
View File
@@ -1721,8 +1721,8 @@ ComputeLoadConstantCompareIterationCount(LoadInst *LI, Constant *RHS,
// Evaluate the condition for this iteration.
Result = ConstantExpr::getICmp(predicate, Result, RHS);
if (!isa<ConstantBool>(Result)) break; // Couldn't decide for sure
if (cast<ConstantBool>(Result)->getValue() == false) {
if (!isa<ConstantInt>(Result)) break; // Couldn't decide for sure
if (cast<ConstantInt>(Result)->getBoolValue() == false) {
#if 0
cerr << "\n***\n*** Computed loop count " << *ItCst
<< "\n*** From global " << *GV << "*** BB: " << *L->getHeader()
@@ -1926,11 +1926,13 @@ ComputeIterationCountExhaustively(const Loop *L, Value *Cond, bool ExitWhen) {
unsigned MaxIterations = MaxBruteForceIterations; // Limit analysis.
for (Constant *PHIVal = StartCST;
IterationNum != MaxIterations; ++IterationNum) {
ConstantBool *CondVal =
dyn_cast_or_null<ConstantBool>(EvaluateExpression(Cond, PHIVal));
if (!CondVal) return UnknownValue; // Couldn't symbolically evaluate.
ConstantInt *CondVal =
dyn_cast_or_null<ConstantInt>(EvaluateExpression(Cond, PHIVal));
if (CondVal->getValue() == ExitWhen) {
// Couldn't symbolically evaluate.
if (!CondVal || CondVal->getType() != Type::BoolTy) return UnknownValue;
if (CondVal->getBoolValue() == ExitWhen) {
ConstantEvolutionLoopExitValue[PN] = PHIVal;
++NumBruteForceTripCountsComputed;
return SCEVConstant::get(ConstantInt::get(Type::Int32Ty, IterationNum));
@@ -2199,10 +2201,10 @@ SCEVHandle ScalarEvolutionsImpl::HowFarToZero(SCEV *V, const Loop *L) {
<< " sol#2: " << *R2 << "\n";
#endif
// Pick the smallest positive root value.
if (ConstantBool *CB =
dyn_cast<ConstantBool>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT,
if (ConstantInt *CB =
dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT,
R1->getValue(), R2->getValue()))) {
if (CB->getValue() == false)
if (CB->getBoolValue() == false)
std::swap(R1, R2); // R1 is the minimum root now.
// We can only use this value if the chrec ends up with an exact zero
@@ -2233,7 +2235,7 @@ SCEVHandle ScalarEvolutionsImpl::HowFarToNonZero(SCEV *V, const Loop *L) {
Constant *Zero = Constant::getNullValue(C->getValue()->getType());
Constant *NonZero =
ConstantExpr::getICmp(ICmpInst::ICMP_NE, C->getValue(), Zero);
if (NonZero == ConstantBool::getTrue())
if (NonZero == ConstantInt::getTrue())
return getSCEV(Zero);
return UnknownValue; // Otherwise it will loop infinitely.
}
@@ -2424,10 +2426,10 @@ SCEVHandle SCEVAddRecExpr::getNumIterationsInRange(ConstantRange Range,
SCEVConstant *R2 = dyn_cast<SCEVConstant>(Roots.second);
if (R1) {
// Pick the smallest positive root value.
if (ConstantBool *CB =
dyn_cast<ConstantBool>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT,
if (ConstantInt *CB =
dyn_cast<ConstantInt>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT,
R1->getValue(), R2->getValue()))) {
if (CB->getValue() == false)
if (CB->getBoolValue() == false)
std::swap(R1, R2); // R1 is the minimum root now.
// Make sure the root is not off by one. The returned iteration should
+1 -1
View File
@@ -143,7 +143,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
Value *F = expandInTy(S->getOperand(1), Ty);
// IF the step is by one, just return the inserted IV.
if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(F))
if (ConstantInt *CI = dyn_cast<ConstantInt>(F))
if (CI->getZExtValue() == 1)
return I;
+2 -2
View File
@@ -172,8 +172,8 @@ struct ValID {
case ConstUIntVal :
case ConstSIntVal : return std::string("%") + itostr(ConstPool64);
case ConstantVal:
if (ConstantValue == ConstantBool::getTrue()) return "true";
if (ConstantValue == ConstantBool::getFalse()) return "false";
if (ConstantValue == ConstantInt::getTrue()) return "true";
if (ConstantValue == ConstantInt::getFalse()) return "false";
return "<constant expression>";
default:
assert(0 && "Unknown value!");
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -303,7 +303,7 @@
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 876 "/proj/llvm/llvm-3/lib/AsmParser/llvmAsmParser.y"
#line 876 "/developer/zsth/llvm-gcc-dev/HEAD/llvm/llvm/lib/AsmParser/llvmAsmParser.y"
typedef union YYSTYPE {
llvm::Module *ModuleVal;
llvm::Function *FunctionVal;
+5 -5
View File
@@ -1670,11 +1670,11 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
CHECK_FOR_ERROR
}
| BOOL TRUETOK { // Boolean constants
$$ = ConstantBool::getTrue();
$$ = ConstantInt::getTrue();
CHECK_FOR_ERROR
}
| BOOL FALSETOK { // Boolean constants
$$ = ConstantBool::getFalse();
$$ = ConstantInt::getFalse();
CHECK_FOR_ERROR
}
| FPType FPVAL { // Float & Double constants
@@ -2184,11 +2184,11 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant
CHECK_FOR_ERROR
}
| TRUETOK {
$$ = ValID::create(ConstantBool::getTrue());
$$ = ValID::create(ConstantInt::getTrue());
CHECK_FOR_ERROR
}
| FALSETOK {
$$ = ValID::create(ConstantBool::getFalse());
$$ = ValID::create(ConstantInt::getFalse());
CHECK_FOR_ERROR
}
| NULL_TOK {
@@ -2615,7 +2615,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
cerr << "WARNING: Use of eliminated 'not' instruction:"
<< " Replacing with 'xor'.\n";
Value *Ones = ConstantIntegral::getAllOnesValue($2->getType());
Value *Ones = ConstantInt::getAllOnesValue($2->getType());
if (Ones == 0)
GEN_ERROR("Expected integral type for not instruction!");
+57 -5
View File
@@ -1484,6 +1484,10 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
"' for element #" + utostr(i) +
" of structure initializer!");
// Check to ensure that Type is not packed
if (STy->isPacked())
GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'");
$$ = ConstantStruct::get(STy, *$3);
delete $1; delete $3;
CHECK_FOR_ERROR
@@ -1499,6 +1503,54 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
if (STy->getNumContainedTypes() != 0)
GEN_ERROR("Illegal number of initializers for structure type!");
// Check to ensure that Type is not packed
if (STy->isPacked())
GEN_ERROR("Unpacked Initializer to packed type '" + STy->getDescription() + "'");
$$ = ConstantStruct::get(STy, std::vector<Constant*>());
delete $1;
CHECK_FOR_ERROR
}
| Types '<' '{' ConstVector '}' '>' {
const StructType *STy = dyn_cast<StructType>($1->get());
if (STy == 0)
GEN_ERROR("Cannot make struct constant with type: '" +
(*$1)->getDescription() + "'!");
if ($4->size() != STy->getNumContainedTypes())
GEN_ERROR("Illegal number of initializers for structure type!");
// Check to ensure that constants are compatible with the type initializer!
for (unsigned i = 0, e = $4->size(); i != e; ++i)
if ((*$4)[i]->getType() != STy->getElementType(i))
GEN_ERROR("Expected type '" +
STy->getElementType(i)->getDescription() +
"' for element #" + utostr(i) +
" of structure initializer!");
// Check to ensure that Type is packed
if (!STy->isPacked())
GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'");
$$ = ConstantStruct::get(STy, *$4);
delete $1; delete $4;
CHECK_FOR_ERROR
}
| Types '<' '{' '}' '>' {
if (!UpRefs.empty())
GEN_ERROR("Invalid upreference in type: " + (*$1)->getDescription());
const StructType *STy = dyn_cast<StructType>($1->get());
if (STy == 0)
GEN_ERROR("Cannot make struct constant with type: '" +
(*$1)->getDescription() + "'!");
if (STy->getNumContainedTypes() != 0)
GEN_ERROR("Illegal number of initializers for structure type!");
// Check to ensure that Type is packed
if (!STy->isPacked())
GEN_ERROR("Packed Initializer to unpacked type '" + STy->getDescription() + "'");
$$ = ConstantStruct::get(STy, std::vector<Constant*>());
delete $1;
CHECK_FOR_ERROR
@@ -1618,11 +1670,11 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
CHECK_FOR_ERROR
}
| BOOL TRUETOK { // Boolean constants
$$ = ConstantBool::getTrue();
$$ = ConstantInt::getTrue();
CHECK_FOR_ERROR
}
| BOOL FALSETOK { // Boolean constants
$$ = ConstantBool::getFalse();
$$ = ConstantInt::getFalse();
CHECK_FOR_ERROR
}
| FPType FPVAL { // Float & Double constants
@@ -2132,11 +2184,11 @@ ConstValueRef : ESINT64VAL { // A reference to a direct constant
CHECK_FOR_ERROR
}
| TRUETOK {
$$ = ValID::create(ConstantBool::getTrue());
$$ = ValID::create(ConstantInt::getTrue());
CHECK_FOR_ERROR
}
| FALSETOK {
$$ = ValID::create(ConstantBool::getFalse());
$$ = ValID::create(ConstantInt::getFalse());
CHECK_FOR_ERROR
}
| NULL_TOK {
@@ -2563,7 +2615,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
cerr << "WARNING: Use of eliminated 'not' instruction:"
<< " Replacing with 'xor'.\n";
Value *Ones = ConstantIntegral::getAllOnesValue($2->getType());
Value *Ones = ConstantInt::getAllOnesValue($2->getType());
if (Ones == 0)
GEN_ERROR("Expected integral type for not instruction!");
+1 -1
View File
@@ -1403,7 +1403,7 @@ Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
unsigned Val = read_vbr_uint();
if (Val != 0 && Val != 1)
error("Invalid boolean value read.");
Result = ConstantBool::get(Val == 1);
Result = ConstantInt::get(Val == 1);
if (Handler) Handler->handleConstantValue(Result);
break;
}
+1 -1
View File
@@ -322,7 +322,7 @@ void BytecodeWriter::outputConstant(const Constant *CPV) {
switch (CPV->getType()->getTypeID()) {
case Type::BoolTyID: // Boolean Types
if (cast<ConstantBool>(CPV)->getValue())
if (cast<ConstantInt>(CPV)->getBoolValue())
output_vbr(1U);
else
output_vbr(0U);
+5 -5
View File
@@ -388,11 +388,11 @@ void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
if (CV->isNullValue() || isa<UndefValue>(CV))
O << "0";
else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
assert(CB->getValue());
O << "1";
} else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
O << CI->getSExtValue();
else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
if (CI->getType() == Type::BoolTy) {
assert(CI->getBoolValue());
O << "1";
} else O << CI->getSExtValue();
} else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
// This is a constant address for a global variable or function. Use the
// name of the variable or function as the address value, possibly
+3 -3
View File
@@ -211,7 +211,7 @@ public:
}
virtual void Apply(bool &Field) {
Constant *C = CI->getOperand(I++);
Field = cast<ConstantBool>(C)->getValue();
Field = cast<ConstantInt>(C)->getBoolValue();
}
virtual void Apply(std::string &Field) {
Constant *C = CI->getOperand(I++);
@@ -276,7 +276,7 @@ public:
Elements.push_back(ConstantInt::get(Type::Int64Ty, uint64_t(Field)));
}
virtual void Apply(bool &Field) {
Elements.push_back(ConstantBool::get(Field));
Elements.push_back(ConstantInt::get(Field));
}
virtual void Apply(std::string &Field) {
Elements.push_back(SR.getString(Field));
@@ -426,7 +426,7 @@ public:
}
virtual void Apply(bool &Field) {
Constant *C = CI->getOperand(I++);
IsValid = IsValid && isa<ConstantBool>(C);
IsValid = IsValid && isa<ConstantInt>(C) && C->getType() == Type::BoolTy;
}
virtual void Apply(std::string &Field) {
Constant *C = CI->getOperand(I++);
+12 -12
View File
@@ -649,7 +649,7 @@ SDOperand SelectionDAGLowering::getValue(const Value *V) {
return N = DAG.getNode(ISD::VBUILD_VECTOR,MVT::Vector,&Ops[0],Ops.size());
} else {
// Canonicalize all constant ints to be unsigned.
return N = DAG.getConstant(cast<ConstantIntegral>(C)->getZExtValue(),VT);
return N = DAG.getConstant(cast<ConstantInt>(C)->getZExtValue(),VT);
}
}
@@ -904,7 +904,7 @@ void SelectionDAGLowering::FindMergedConditions(Value *Cond,
}
// Create a CaseBlock record representing this branch.
SelectionDAGISel::CaseBlock CB(ISD::SETEQ, Cond, ConstantBool::getTrue(),
SelectionDAGISel::CaseBlock CB(ISD::SETEQ, Cond, ConstantInt::getTrue(),
TBB, FBB, CurBB);
SwitchCases.push_back(CB);
return;
@@ -1043,7 +1043,7 @@ void SelectionDAGLowering::visitBr(BranchInst &I) {
}
// Create a CaseBlock record representing this branch.
SelectionDAGISel::CaseBlock CB(ISD::SETEQ, CondVal, ConstantBool::getTrue(),
SelectionDAGISel::CaseBlock CB(ISD::SETEQ, CondVal, ConstantInt::getTrue(),
Succ0MBB, Succ1MBB, CurMBB);
// Use visitSwitchCase to actually insert the fast branch sequence for this
// cond branch.
@@ -1058,9 +1058,9 @@ void SelectionDAGLowering::visitSwitchCase(SelectionDAGISel::CaseBlock &CB) {
// Build the setcc now, fold "(X == true)" to X and "(X == false)" to !X to
// handle common cases produced by branch lowering.
if (CB.CmpRHS == ConstantBool::getTrue() && CB.CC == ISD::SETEQ)
if (CB.CmpRHS == ConstantInt::getTrue() && CB.CC == ISD::SETEQ)
Cond = CondLHS;
else if (CB.CmpRHS == ConstantBool::getFalse() && CB.CC == ISD::SETEQ) {
else if (CB.CmpRHS == ConstantInt::getFalse() && CB.CC == ISD::SETEQ) {
SDOperand True = DAG.getConstant(1, CondLHS.getValueType());
Cond = DAG.getNode(ISD::XOR, CondLHS.getValueType(), CondLHS, True);
} else
@@ -1206,8 +1206,8 @@ void SelectionDAGLowering::visitSwitch(SwitchInst &I) {
if ((TLI.isOperationLegal(ISD::BR_JT, MVT::Other) ||
TLI.isOperationLegal(ISD::BRIND, MVT::Other)) &&
Cases.size() > 5) {
uint64_t First =cast<ConstantIntegral>(Cases.front().first)->getZExtValue();
uint64_t Last = cast<ConstantIntegral>(Cases.back().first)->getZExtValue();
uint64_t First =cast<ConstantInt>(Cases.front().first)->getZExtValue();
uint64_t Last = cast<ConstantInt>(Cases.back().first)->getZExtValue();
double Density = (double)Cases.size() / (double)((Last - First) + 1ULL);
if (Density >= 0.3125) {
@@ -1256,7 +1256,7 @@ void SelectionDAGLowering::visitSwitch(SwitchInst &I) {
std::vector<MachineBasicBlock*> DestBBs;
uint64_t TEI = First;
for (CaseItr ii = Cases.begin(), ee = Cases.end(); ii != ee; ++TEI)
if (cast<ConstantIntegral>(ii->first)->getZExtValue() == TEI) {
if (cast<ConstantInt>(ii->first)->getZExtValue() == TEI) {
DestBBs.push_back(ii->second);
++ii;
} else {
@@ -1338,8 +1338,8 @@ void SelectionDAGLowering::visitSwitch(SwitchInst &I) {
// rather than creating a leaf node for it.
if ((LHSR.second - LHSR.first) == 1 &&
LHSR.first->first == CR.GE &&
cast<ConstantIntegral>(C)->getZExtValue() ==
(cast<ConstantIntegral>(CR.GE)->getZExtValue() + 1ULL)) {
cast<ConstantInt>(C)->getZExtValue() ==
(cast<ConstantInt>(CR.GE)->getZExtValue() + 1ULL)) {
TrueBB = LHSR.first->second;
} else {
TrueBB = new MachineBasicBlock(LLVMBB);
@@ -1352,8 +1352,8 @@ void SelectionDAGLowering::visitSwitch(SwitchInst &I) {
// is CR.LT - 1, then we can branch directly to the target block for
// the current Case Value, rather than emitting a RHS leaf node for it.
if ((RHSR.second - RHSR.first) == 1 && CR.LT &&
cast<ConstantIntegral>(RHSR.first->first)->getZExtValue() ==
(cast<ConstantIntegral>(CR.LT)->getZExtValue() - 1ULL)) {
cast<ConstantInt>(RHSR.first->first)->getZExtValue() ==
(cast<ConstantInt>(CR.LT)->getZExtValue() - 1ULL)) {
FalseBB = RHSR.first->second;
} else {
FalseBB = new MachineBasicBlock(LLVMBB);
+1 -1
View File
@@ -399,7 +399,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
switch (C->getType()->getTypeID()) {
#define GET_CONST_VAL(TY, CTY, CLASS, GETMETH) \
case Type::TY##TyID: Result.TY##Val = (CTY)cast<CLASS>(C)->GETMETH(); break
GET_CONST_VAL(Bool , bool , ConstantBool, getValue);
GET_CONST_VAL(Bool , bool , ConstantInt, getBoolValue);
GET_CONST_VAL(Int8 , unsigned char , ConstantInt, getZExtValue);
GET_CONST_VAL(Int16 , unsigned short, ConstantInt, getZExtValue);
GET_CONST_VAL(Int32 , unsigned int , ConstantInt, getZExtValue);
+1 -1
View File
@@ -191,7 +191,7 @@ GenericValue JIT::runFunction(Function *F,
const GenericValue &AV = ArgValues[i];
switch (ArgTy->getTypeID()) {
default: assert(0 && "Unknown argument type for function call!");
case Type::BoolTyID: C = ConstantBool::get(AV.BoolVal); break;
case Type::BoolTyID: C = ConstantInt::get(AV.BoolVal); break;
case Type::Int8TyID: C = ConstantInt::get(ArgTy, AV.Int8Val); break;
case Type::Int16TyID: C = ConstantInt::get(ArgTy, AV.Int16Val); break;
case Type::Int32TyID: C = ConstantInt::get(ArgTy, AV.Int32Val); break;
+25 -25
View File
@@ -30,9 +30,9 @@
#include <ostream>
using namespace llvm;
static ConstantIntegral *getMaxValue(const Type *Ty, bool isSigned = false) {
static ConstantInt *getMaxValue(const Type *Ty, bool isSigned = false) {
if (Ty == Type::BoolTy)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
if (Ty->isInteger()) {
if (isSigned) {
// Calculate 011111111111111...
@@ -47,9 +47,9 @@ static ConstantIntegral *getMaxValue(const Type *Ty, bool isSigned = false) {
}
// Static constructor to create the minimum constant for an integral type...
static ConstantIntegral *getMinValue(const Type *Ty, bool isSigned = false) {
static ConstantInt *getMinValue(const Type *Ty, bool isSigned = false) {
if (Ty == Type::BoolTy)
return ConstantBool::getFalse();
return ConstantInt::getFalse();
if (Ty->isInteger()) {
if (isSigned) {
// Calculate 1111111111000000000000
@@ -62,37 +62,37 @@ static ConstantIntegral *getMinValue(const Type *Ty, bool isSigned = false) {
}
return 0;
}
static ConstantIntegral *Next(ConstantIntegral *CI) {
if (ConstantBool *CB = dyn_cast<ConstantBool>(CI))
return ConstantBool::get(!CB->getValue());
static ConstantInt *Next(ConstantInt *CI) {
if (CI->getType() == Type::BoolTy)
return ConstantInt::get(!CI->getBoolValue());
Constant *Result = ConstantExpr::getAdd(CI,
ConstantInt::get(CI->getType(), 1));
return cast<ConstantIntegral>(Result);
return cast<ConstantInt>(Result);
}
static bool LT(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) {
static bool LT(ConstantInt *A, ConstantInt *B, bool isSigned) {
Constant *C = ConstantExpr::getICmp(
(isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT), A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
return cast<ConstantInt>(C)->getBoolValue();
}
static bool LTE(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) {
static bool LTE(ConstantInt *A, ConstantInt *B, bool isSigned) {
Constant *C = ConstantExpr::getICmp(
(isSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE), A, B);
assert(isa<ConstantBool>(C) && "Constant folding of integrals not impl??");
return cast<ConstantBool>(C)->getValue();
assert(isa<ConstantInt>(C) && "Constant folding of integrals not impl??");
return cast<ConstantInt>(C)->getBoolValue();
}
static bool GT(ConstantIntegral *A, ConstantIntegral *B, bool isSigned) {
static bool GT(ConstantInt *A, ConstantInt *B, bool isSigned) {
return LT(B, A, isSigned); }
static ConstantIntegral *Min(ConstantIntegral *A, ConstantIntegral *B,
static ConstantInt *Min(ConstantInt *A, ConstantInt *B,
bool isSigned) {
return LT(A, B, isSigned) ? A : B;
}
static ConstantIntegral *Max(ConstantIntegral *A, ConstantIntegral *B,
static ConstantInt *Max(ConstantInt *A, ConstantInt *B,
bool isSigned) {
return GT(A, B, isSigned) ? A : B;
}
@@ -111,14 +111,14 @@ ConstantRange::ConstantRange(const Type *Ty, bool Full) {
/// Initialize a range to hold the single specified value.
///
ConstantRange::ConstantRange(Constant *V)
: Lower(cast<ConstantIntegral>(V)), Upper(Next(cast<ConstantIntegral>(V))) { }
: Lower(cast<ConstantInt>(V)), Upper(Next(cast<ConstantInt>(V))) { }
/// Initialize a range of values explicitly... this will assert out if
/// Lower==Upper and Lower != Min or Max for its type (or if the two constants
/// have different types)
///
ConstantRange::ConstantRange(Constant *L, Constant *U)
: Lower(cast<ConstantIntegral>(L)), Upper(cast<ConstantIntegral>(U)) {
: Lower(cast<ConstantInt>(L)), Upper(cast<ConstantInt>(U)) {
assert(Lower->getType() == Upper->getType() &&
"Incompatible types for ConstantRange!");
@@ -130,7 +130,7 @@ ConstantRange::ConstantRange(Constant *L, Constant *U)
/// Initialize a set of values that all satisfy the condition with C.
///
ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantIntegral *C) {
ConstantRange::ConstantRange(unsigned short ICmpOpcode, ConstantInt *C) {
switch (ICmpOpcode) {
default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!");
case ICmpInst::ICMP_EQ: Lower = C; Upper = Next(C); return;
@@ -195,7 +195,7 @@ bool ConstantRange::isWrappedSet(bool isSigned) const {
/// getSingleElement - If this set contains a single element, return it,
/// otherwise return null.
ConstantIntegral *ConstantRange::getSingleElement() const {
ConstantInt *ConstantRange::getSingleElement() const {
if (Upper == Next(Lower)) // Is it a single element range?
return Lower;
return 0;
@@ -292,8 +292,8 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR,
if (!isWrappedSet(isSigned)) {
if (!CR.isWrappedSet(isSigned)) {
ConstantIntegral *L = Max(Lower, CR.Lower, isSigned);
ConstantIntegral *U = Min(Upper, CR.Upper, isSigned);
ConstantInt *L = Max(Lower, CR.Lower, isSigned);
ConstantInt *U = Min(Upper, CR.Upper, isSigned);
if (LT(L, U, isSigned)) // If range isn't empty...
return ConstantRange(L, U);
@@ -306,8 +306,8 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR,
return intersect1Wrapped(*this, CR, isSigned);
else {
// Both ranges are wrapped...
ConstantIntegral *L = Max(Lower, CR.Lower, isSigned);
ConstantIntegral *U = Min(Upper, CR.Upper, isSigned);
ConstantInt *L = Max(Lower, CR.Lower, isSigned);
ConstantInt *U = Min(Upper, CR.Upper, isSigned);
return ConstantRange(L, U);
}
}
+13 -14
View File
@@ -826,22 +826,21 @@ void CWriter::printConstant(Constant *CPV) {
return;
}
if (ConstantBool *CB = dyn_cast<ConstantBool>(CPV)) {
Out << (CB->getValue() ? '1' : '0') ;
return;
}
if (ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
const Type* Ty = CI->getType();
Out << "((";
printPrimitiveType(Out, Ty, false) << ')';
if (CI->isMinValue(true))
Out << CI->getZExtValue() << 'u';
else
Out << CI->getSExtValue();
if (Ty->getPrimitiveSizeInBits() > 32)
Out << "ll";
Out << ')';
if (Ty == Type::BoolTy)
Out << (CI->getBoolValue() ? '1' : '0') ;
else {
Out << "((";
printPrimitiveType(Out, Ty, false) << ')';
if (CI->isMinValue(true))
Out << CI->getZExtValue() << 'u';
else
Out << CI->getSExtValue();
if (Ty->getPrimitiveSizeInBits() > 32)
Out << "ll";
Out << ')';
}
return;
}
+12 -9
View File
@@ -711,7 +711,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
// keep track of whether the global was initialized yet or not.
GlobalVariable *InitBool =
new GlobalVariable(Type::BoolTy, false, GlobalValue::InternalLinkage,
ConstantBool::getFalse(), GV->getName()+".init");
ConstantInt::getFalse(), GV->getName()+".init");
bool InitBoolUsed = false;
// Loop over all uses of GV, processing them in turn.
@@ -731,7 +731,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
default: assert(0 && "Unknown ICmp Predicate!");
case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_SLT:
LV = ConstantBool::getFalse(); // X < null -> always false
LV = ConstantInt::getFalse(); // X < null -> always false
break;
case ICmpInst::ICMP_ULE:
case ICmpInst::ICMP_SLE:
@@ -753,7 +753,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
} else {
StoreInst *SI = cast<StoreInst>(GV->use_back());
// The global is initialized when the store to it occurs.
new StoreInst(ConstantBool::getTrue(), InitBool, SI);
new StoreInst(ConstantInt::getTrue(), InitBool, SI);
SI->eraseFromParent();
}
@@ -1140,7 +1140,7 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal,
static void ShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
// Create the new global, initializing it to false.
GlobalVariable *NewGV = new GlobalVariable(Type::BoolTy, false,
GlobalValue::InternalLinkage, ConstantBool::getFalse(),
GlobalValue::InternalLinkage, ConstantInt::getFalse(),
GV->getName()+".b");
GV->getParent()->getGlobalList().insert(GV, NewGV);
@@ -1161,7 +1161,7 @@ static void ShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
// Only do this if we weren't storing a loaded value.
Value *StoreVal;
if (StoringOther || SI->getOperand(0) == InitVal)
StoreVal = ConstantBool::get(StoringOther);
StoreVal = ConstantInt::get(StoringOther);
else {
// Otherwise, we are storing a previously loaded copy. To do this,
// change the copy from copying the original value to just copying the
@@ -1797,10 +1797,13 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
if (BI->isUnconditional()) {
NewBB = BI->getSuccessor(0);
} else {
ConstantBool *Cond =
dyn_cast<ConstantBool>(getVal(Values, BI->getCondition()));
if (!Cond) return false; // Cannot determine.
NewBB = BI->getSuccessor(!Cond->getValue());
ConstantInt *Cond =
dyn_cast<ConstantInt>(getVal(Values, BI->getCondition()));
// Cannot determine.
if (!Cond || Cond->getType() != Type::BoolTy)
return false;
NewBB = BI->getSuccessor(!Cond->getBoolValue());
}
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(CurInst)) {
ConstantInt *Val =
@@ -460,7 +460,7 @@ void ProfilerRS::ProcessBackEdge(BasicBlock* src, BasicBlock* dst, Function& F)
//b:
new BranchInst(cast<BasicBlock>(Translate(dst)), bbC);
new BranchInst(dst, cast<BasicBlock>(Translate(dst)),
ConstantBool::get(true), bbCp);
ConstantInt::get(true), bbCp);
//c:
{
TerminatorInst* iB = src->getTerminator();
@@ -516,7 +516,7 @@ bool ProfilerRS::runOnFunction(Function& F) {
TerminatorInst* T = F.getEntryBlock().getTerminator();
ReplaceInstWithInst(T, new BranchInst(T->getSuccessor(0),
cast<BasicBlock>(Translate(T->getSuccessor(0))),
ConstantBool::get(true)));
ConstantInt::get(true)));
//do whatever is needed now that the function is duplicated
c->PrepFunction(&F);
+3 -2
View File
@@ -133,12 +133,13 @@ void CondProp::SimplifyPredecessors(BranchInst *BI) {
// constants. Walk from the end to remove operands from the end when
// possible, and to avoid invalidating "i".
for (unsigned i = PN->getNumIncomingValues(); i != 0; --i)
if (ConstantBool *CB = dyn_cast<ConstantBool>(PN->getIncomingValue(i-1))) {
if (ConstantInt *CB = dyn_cast<ConstantInt>(PN->getIncomingValue(i-1))) {
if (CB->getType() != Type::BoolTy) continue;
// If we have a constant, forward the edge from its current to its
// ultimate destination.
bool PHIGone = PN->getNumIncomingValues() == 2;
RevectorBlockTo(PN->getIncomingBlock(i-1),
BI->getSuccessor(CB->getValue() == 0));
BI->getSuccessor(CB->getBoolValue() == 0));
++NumBrThread;
// If there were two predecessors before this simplification, the PHI node
+78 -76
View File
@@ -472,7 +472,7 @@ bool CEE::ForwardCorrelatedEdgeDestination(TerminatorInst *TI, unsigned SuccNo,
} else if (CmpInst *CI = dyn_cast<CmpInst>(I)) {
Relation::KnownResult Res = getCmpResult(CI, NewRI);
if (Res == Relation::Unknown) return false;
PropagateEquality(CI, ConstantBool::get(Res), NewRI);
PropagateEquality(CI, ConstantInt::get(Res), NewRI);
} else {
assert(isa<BranchInst>(*I) && "Unexpected instruction type!");
}
@@ -484,10 +484,11 @@ bool CEE::ForwardCorrelatedEdgeDestination(TerminatorInst *TI, unsigned SuccNo,
if (PredicateVI.getReplacement() &&
isa<Constant>(PredicateVI.getReplacement()) &&
!isa<GlobalValue>(PredicateVI.getReplacement())) {
ConstantBool *CB = cast<ConstantBool>(PredicateVI.getReplacement());
ConstantInt *CB = cast<ConstantInt>(PredicateVI.getReplacement());
// Forward to the successor that corresponds to the branch we will take.
ForwardSuccessorTo(TI, SuccNo, BI->getSuccessor(!CB->getValue()), NewRI);
ForwardSuccessorTo(TI, SuccNo,
BI->getSuccessor(!CB->getBoolValue()), NewRI);
return true;
}
@@ -782,12 +783,12 @@ void CEE::PropagateBranchInfo(BranchInst *BI) {
// Propagate information into the true block...
//
PropagateEquality(BI->getCondition(), ConstantBool::getTrue(),
PropagateEquality(BI->getCondition(), ConstantInt::getTrue(),
getRegionInfo(BI->getSuccessor(0)));
// Propagate information into the false block...
//
PropagateEquality(BI->getCondition(), ConstantBool::getFalse(),
PropagateEquality(BI->getCondition(), ConstantInt::getFalse(),
getRegionInfo(BI->getSuccessor(1)));
}
@@ -832,78 +833,79 @@ void CEE::PropagateEquality(Value *Op0, Value *Op1, RegionInfo &RI) {
// it's a constant, then see if the other one is one of a setcc instruction,
// an AND, OR, or XOR instruction.
//
if (ConstantBool *CB = dyn_cast<ConstantBool>(Op1)) {
if (Instruction *Inst = dyn_cast<Instruction>(Op0)) {
// If we know that this instruction is an AND instruction, and the result
// is true, this means that both operands to the OR are known to be true
// as well.
//
if (CB->getValue() && Inst->getOpcode() == Instruction::And) {
PropagateEquality(Inst->getOperand(0), CB, RI);
PropagateEquality(Inst->getOperand(1), CB, RI);
}
// If we know that this instruction is an OR instruction, and the result
// is false, this means that both operands to the OR are know to be false
// as well.
//
if (!CB->getValue() && Inst->getOpcode() == Instruction::Or) {
PropagateEquality(Inst->getOperand(0), CB, RI);
PropagateEquality(Inst->getOperand(1), CB, RI);
}
// If we know that this instruction is a NOT instruction, we know that the
// operand is known to be the inverse of whatever the current value is.
//
if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(Inst))
if (BinaryOperator::isNot(BOp))
PropagateEquality(BinaryOperator::getNotArgument(BOp),
ConstantBool::get(!CB->getValue()), RI);
// If we know the value of a FCmp instruction, propagate the information
// about the relation into this region as well.
//
if (FCmpInst *FCI = dyn_cast<FCmpInst>(Inst)) {
if (CB->getValue()) { // If we know the condition is true...
// Propagate info about the LHS to the RHS & RHS to LHS
PropagateRelation(FCI->getPredicate(), FCI->getOperand(0),
FCI->getOperand(1), RI);
PropagateRelation(FCI->getSwappedPredicate(),
FCI->getOperand(1), FCI->getOperand(0), RI);
} else { // If we know the condition is false...
// We know the opposite of the condition is true...
FCmpInst::Predicate C = FCI->getInversePredicate();
PropagateRelation(C, FCI->getOperand(0), FCI->getOperand(1), RI);
PropagateRelation(FCmpInst::getSwappedPredicate(C),
FCI->getOperand(1), FCI->getOperand(0), RI);
if (Op1->getType() == Type::BoolTy)
if (ConstantInt *CB = dyn_cast<ConstantInt>(Op1)) {
if (Instruction *Inst = dyn_cast<Instruction>(Op0)) {
// If we know that this instruction is an AND instruction, and the result
// is true, this means that both operands to the OR are known to be true
// as well.
//
if (CB->getBoolValue() && Inst->getOpcode() == Instruction::And) {
PropagateEquality(Inst->getOperand(0), CB, RI);
PropagateEquality(Inst->getOperand(1), CB, RI);
}
// If we know that this instruction is an OR instruction, and the result
// is false, this means that both operands to the OR are know to be false
// as well.
//
if (!CB->getBoolValue() && Inst->getOpcode() == Instruction::Or) {
PropagateEquality(Inst->getOperand(0), CB, RI);
PropagateEquality(Inst->getOperand(1), CB, RI);
}
// If we know that this instruction is a NOT instruction, we know that the
// operand is known to be the inverse of whatever the current value is.
//
if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(Inst))
if (BinaryOperator::isNot(BOp))
PropagateEquality(BinaryOperator::getNotArgument(BOp),
ConstantInt::get(!CB->getBoolValue()), RI);
// If we know the value of a FCmp instruction, propagate the information
// about the relation into this region as well.
//
if (FCmpInst *FCI = dyn_cast<FCmpInst>(Inst)) {
if (CB->getBoolValue()) { // If we know the condition is true...
// Propagate info about the LHS to the RHS & RHS to LHS
PropagateRelation(FCI->getPredicate(), FCI->getOperand(0),
FCI->getOperand(1), RI);
PropagateRelation(FCI->getSwappedPredicate(),
FCI->getOperand(1), FCI->getOperand(0), RI);
} else { // If we know the condition is false...
// We know the opposite of the condition is true...
FCmpInst::Predicate C = FCI->getInversePredicate();
PropagateRelation(C, FCI->getOperand(0), FCI->getOperand(1), RI);
PropagateRelation(FCmpInst::getSwappedPredicate(C),
FCI->getOperand(1), FCI->getOperand(0), RI);
}
}
}
// If we know the value of a ICmp instruction, propagate the information
// about the relation into this region as well.
//
if (ICmpInst *ICI = dyn_cast<ICmpInst>(Inst)) {
if (CB->getValue()) { // If we know the condition is true...
// Propagate info about the LHS to the RHS & RHS to LHS
PropagateRelation(ICI->getPredicate(), ICI->getOperand(0),
ICI->getOperand(1), RI);
PropagateRelation(ICI->getSwappedPredicate(), ICI->getOperand(1),
ICI->getOperand(1), RI);
// If we know the value of a ICmp instruction, propagate the information
// about the relation into this region as well.
//
if (ICmpInst *ICI = dyn_cast<ICmpInst>(Inst)) {
if (CB->getBoolValue()) { // If we know the condition is true...
// Propagate info about the LHS to the RHS & RHS to LHS
PropagateRelation(ICI->getPredicate(), ICI->getOperand(0),
ICI->getOperand(1), RI);
PropagateRelation(ICI->getSwappedPredicate(), ICI->getOperand(1),
ICI->getOperand(1), RI);
} else { // If we know the condition is false ...
// We know the opposite of the condition is true...
ICmpInst::Predicate C = ICI->getInversePredicate();
} else { // If we know the condition is false ...
// We know the opposite of the condition is true...
ICmpInst::Predicate C = ICI->getInversePredicate();
PropagateRelation(C, ICI->getOperand(0), ICI->getOperand(1), RI);
PropagateRelation(ICmpInst::getSwappedPredicate(C),
ICI->getOperand(1), ICI->getOperand(0), RI);
PropagateRelation(C, ICI->getOperand(0), ICI->getOperand(1), RI);
PropagateRelation(ICmpInst::getSwappedPredicate(C),
ICI->getOperand(1), ICI->getOperand(0), RI);
}
}
}
}
}
// Propagate information about Op0 to Op1 & visa versa
PropagateRelation(ICmpInst::ICMP_EQ, Op0, Op1, RI);
@@ -992,7 +994,7 @@ void CEE::IncorporateInstruction(Instruction *Inst, RegionInfo &RI) {
// See if we can figure out a result for this instruction...
Relation::KnownResult Result = getCmpResult(CI, RI);
if (Result != Relation::Unknown) {
PropagateEquality(CI, ConstantBool::get(Result != 0), RI);
PropagateEquality(CI, ConstantInt::get(Result != 0), RI);
}
}
}
@@ -1066,7 +1068,7 @@ bool CEE::SimplifyBasicBlock(BasicBlock &BB, const RegionInfo &RI) {
DEBUG(cerr << "Replacing icmp with " << Result
<< " constant: " << *CI);
CI->replaceAllUsesWith(ConstantBool::get((bool)Result));
CI->replaceAllUsesWith(ConstantInt::get((bool)Result));
// The instruction is now dead, remove it from the program.
CI->getParent()->getInstList().erase(CI);
++NumCmpRemoved;
@@ -1120,7 +1122,7 @@ Relation::KnownResult CEE::getCmpResult(CmpInst *CI,
if (Constant *Result = ConstantFoldInstruction(CI)) {
// Wow, this is easy, directly eliminate the ICmpInst.
DEBUG(cerr << "Replacing cmp with constant fold: " << *CI);
return cast<ConstantBool>(Result)->getValue()
return cast<ConstantInt>(Result)->getBoolValue()
? Relation::KnownTrue : Relation::KnownFalse;
}
} else {
@@ -1143,7 +1145,7 @@ Relation::KnownResult CEE::getCmpResult(CmpInst *CI,
// Op1. Check to see if we know anything about comparing value with a
// constant, and if we can use this info to fold the icmp.
//
if (ConstantIntegral *C = dyn_cast<ConstantIntegral>(Op1)) {
if (ConstantInt *C = dyn_cast<ConstantInt>(Op1)) {
// Check to see if we already know the result of this comparison...
ConstantRange R = ConstantRange(predicate, C);
ConstantRange Int = R.intersectWith(Op0VI->getBounds(),
@@ -1189,7 +1191,7 @@ bool Relation::contradicts(unsigned Op,
// If this is a relationship with a constant, make sure that this relationship
// does not contradict properties known about the bounds of the constant.
//
if (ConstantIntegral *C = dyn_cast<ConstantIntegral>(Val))
if (ConstantInt *C = dyn_cast<ConstantInt>(Val))
if (Op >= ICmpInst::FIRST_ICMP_PREDICATE &&
Op <= ICmpInst::LAST_ICMP_PREDICATE)
if (ConstantRange(Op, C).intersectWith(VI.getBounds(),
@@ -1247,7 +1249,7 @@ bool Relation::incorporate(unsigned Op, ValueInfo &VI) {
// If this is a relationship with a constant, make sure that we update the
// range that is possible for the value to have...
//
if (ConstantIntegral *C = dyn_cast<ConstantIntegral>(Val))
if (ConstantInt *C = dyn_cast<ConstantInt>(Val))
if (Op >= ICmpInst::FIRST_ICMP_PREDICATE &&
Op <= ICmpInst::LAST_ICMP_PREDICATE)
VI.getBounds() = ConstantRange(Op, C).intersectWith(VI.getBounds(),
+108 -110
View File
@@ -302,10 +302,10 @@ namespace {
Instruction *FoldPHIArgBinOpIntoPHI(PHINode &PN);
Instruction *OptAndOp(Instruction *Op, ConstantIntegral *OpRHS,
ConstantIntegral *AndRHS, BinaryOperator &TheAnd);
Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
ConstantInt *AndRHS, BinaryOperator &TheAnd);
Value *FoldLogicalPlusAnd(Value *LHS, Value *RHS, ConstantIntegral *Mask,
Value *FoldLogicalPlusAnd(Value *LHS, Value *RHS, ConstantInt *Mask,
bool isSub, Instruction &I);
Instruction *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
bool isSigned, bool Inside, Instruction &IB);
@@ -484,7 +484,7 @@ static inline Value *dyn_castNotVal(Value *V) {
return BinaryOperator::getNotArgument(V);
// Constants can be considered to be not'ed values...
if (ConstantIntegral *C = dyn_cast<ConstantIntegral>(V))
if (ConstantInt *C = dyn_cast<ConstantInt>(V))
return ConstantExpr::getNot(C);
return 0;
}
@@ -531,14 +531,6 @@ static ConstantInt *SubOne(ConstantInt *C) {
ConstantInt::get(C->getType(), 1)));
}
/// GetConstantInType - Return a ConstantInt with the specified type and value.
///
static ConstantIntegral *GetConstantInType(const Type *Ty, uint64_t Val) {
if (Ty->getTypeID() == Type::BoolTyID)
return ConstantBool::get(Val);
return ConstantInt::get(Ty, Val);
}
/// ComputeMaskedBits - Determine which of the bits specified in Mask are
/// known to be either zero or one and return them in the KnownZero/KnownOne
@@ -552,7 +544,7 @@ static void ComputeMaskedBits(Value *V, uint64_t Mask, uint64_t &KnownZero,
// optimized based on the contradictory assumption that it is non-zero.
// Because instcombine aggressively folds operations with undef args anyway,
// this won't lose us code quality.
if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V)) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
// We know all of the bits for a constant!
KnownOne = CI->getZExtValue() & Mask;
KnownZero = ~KnownOne & Mask;
@@ -763,7 +755,7 @@ static bool ShrinkDemandedConstant(Instruction *I, unsigned OpNo,
// This is producing any bits that are not needed, shrink the RHS.
uint64_t Val = Demanded & OpC->getZExtValue();
I->setOperand(OpNo, GetConstantInType(OpC->getType(), Val));
I->setOperand(OpNo, ConstantInt::get(OpC->getType(), Val));
return true;
}
@@ -824,7 +816,7 @@ static void ComputeUnsignedMinMaxValuesFromKnownBits(const Type *Ty,
bool InstCombiner::SimplifyDemandedBits(Value *V, uint64_t DemandedMask,
uint64_t &KnownZero, uint64_t &KnownOne,
unsigned Depth) {
if (ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V)) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
// We know all of the bits for a constant!
KnownOne = CI->getZExtValue() & DemandedMask;
KnownZero = ~KnownOne & DemandedMask;
@@ -965,8 +957,8 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, uint64_t DemandedMask,
// e.g. (X | C1) ^ C2 --> (X | C1) & ~C2 iff (C1&C2) == C2
if ((DemandedMask & (KnownZero|KnownOne)) == DemandedMask) { // all known
if ((KnownOne & KnownOne2) == KnownOne) {
Constant *AndC = GetConstantInType(I->getType(),
~KnownOne & DemandedMask);
Constant *AndC = ConstantInt::get(I->getType(),
~KnownOne & DemandedMask);
Instruction *And =
BinaryOperator::createAnd(I->getOperand(0), AndC, "tmp");
InsertNewInstBefore(And, *I);
@@ -1250,7 +1242,7 @@ bool InstCombiner::SimplifyDemandedBits(Value *V, uint64_t DemandedMask,
// If the client is only demanding bits that we know, return the known
// constant.
if ((DemandedMask & (KnownZero|KnownOne)) == DemandedMask)
return UpdateValueUsesWith(I, GetConstantInType(I->getType(), KnownOne));
return UpdateValueUsesWith(I, ConstantInt::get(I->getType(), KnownOne));
return false;
}
@@ -2280,7 +2272,7 @@ Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
UpdateValueUsesWith(CondI, ConstantBool::getFalse());
UpdateValueUsesWith(CondI, ConstantInt::getFalse());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(2));
else
@@ -2293,7 +2285,7 @@ Instruction *InstCombiner::commonDivTransforms(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
UpdateValueUsesWith(CondI, ConstantBool::getTrue());
UpdateValueUsesWith(CondI, ConstantInt::getTrue());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(1));
else
@@ -2513,7 +2505,7 @@ Instruction *InstCombiner::commonRemTransforms(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
UpdateValueUsesWith(CondI, ConstantBool::getFalse());
UpdateValueUsesWith(CondI, ConstantInt::getFalse());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(2));
else
@@ -2525,7 +2517,7 @@ Instruction *InstCombiner::commonRemTransforms(BinaryOperator &I) {
if (ST->isNullValue()) {
Instruction *CondI = dyn_cast<Instruction>(SI->getOperand(0));
if (CondI && CondI->getParent() == I.getParent())
UpdateValueUsesWith(CondI, ConstantBool::getTrue());
UpdateValueUsesWith(CondI, ConstantInt::getTrue());
else if (I.getParent() != SI->getParent() || SI->hasOneUse())
I.setOperand(1, SI->getOperand(1));
else
@@ -2758,7 +2750,7 @@ static unsigned getICmpCode(const ICmpInst *ICI) {
static Value *getICmpValue(bool sign, unsigned code, Value *LHS, Value *RHS) {
switch (code) {
default: assert(0 && "Illegal ICmp code!");
case 0: return ConstantBool::getFalse();
case 0: return ConstantInt::getFalse();
case 1:
if (sign)
return new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS);
@@ -2781,7 +2773,7 @@ static Value *getICmpValue(bool sign, unsigned code, Value *LHS, Value *RHS) {
return new ICmpInst(ICmpInst::ICMP_SLE, LHS, RHS);
else
return new ICmpInst(ICmpInst::ICMP_ULE, LHS, RHS);
case 7: return ConstantBool::getTrue();
case 7: return ConstantInt::getTrue();
}
}
@@ -2839,8 +2831,8 @@ struct FoldICmpLogical {
// the Op parameter is 'OP', OpRHS is 'C1', and AndRHS is 'C2'. Op is
// guaranteed to be either a shift instruction or a binary operator.
Instruction *InstCombiner::OptAndOp(Instruction *Op,
ConstantIntegral *OpRHS,
ConstantIntegral *AndRHS,
ConstantInt *OpRHS,
ConstantInt *AndRHS,
BinaryOperator &TheAnd) {
Value *X = Op->getOperand(0);
Constant *Together = 0;
@@ -2911,7 +2903,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
// We know that the AND will not produce any of the bits shifted in, so if
// the anded constant includes them, clear them now!
//
Constant *AllOne = ConstantIntegral::getAllOnesValue(AndRHS->getType());
Constant *AllOne = ConstantInt::getAllOnesValue(AndRHS->getType());
Constant *ShlMask = ConstantExpr::getShl(AllOne, OpRHS);
Constant *CI = ConstantExpr::getAnd(AndRHS, ShlMask);
@@ -2929,7 +2921,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
// the anded constant includes them, clear them now! This only applies to
// unsigned shifts, because a signed shr may bring in set bits!
//
Constant *AllOne = ConstantIntegral::getAllOnesValue(AndRHS->getType());
Constant *AllOne = ConstantInt::getAllOnesValue(AndRHS->getType());
Constant *ShrMask = ConstantExpr::getLShr(AllOne, OpRHS);
Constant *CI = ConstantExpr::getAnd(AndRHS, ShrMask);
@@ -2946,7 +2938,7 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
// See if this is shifting in some sign extension, then masking it out
// with an and.
if (Op->hasOneUse()) {
Constant *AllOne = ConstantIntegral::getAllOnesValue(AndRHS->getType());
Constant *AllOne = ConstantInt::getAllOnesValue(AndRHS->getType());
Constant *ShrMask = ConstantExpr::getLShr(AllOne, OpRHS);
Constant *C = ConstantExpr::getAnd(AndRHS, ShrMask);
if (C == AndRHS) { // Masking out bits shifted in.
@@ -2972,8 +2964,8 @@ Instruction *InstCombiner::OptAndOp(Instruction *Op,
Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
bool isSigned, bool Inside,
Instruction &IB) {
assert(cast<ConstantBool>(ConstantExpr::getICmp((isSigned ?
ICmpInst::ICMP_SLE:ICmpInst::ICMP_ULE), Lo, Hi))->getValue() &&
assert(cast<ConstantInt>(ConstantExpr::getICmp((isSigned ?
ICmpInst::ICMP_SLE:ICmpInst::ICMP_ULE), Lo, Hi))->getBoolValue() &&
"Lo is not <= Hi in range emission code!");
if (Inside) {
@@ -2981,7 +2973,7 @@ Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
return new ICmpInst(ICmpInst::ICMP_NE, V, V);
// V >= Min && V < Hi --> V < Hi
if (cast<ConstantIntegral>(Lo)->isMinValue(isSigned)) {
if (cast<ConstantInt>(Lo)->isMinValue(isSigned)) {
ICmpInst::Predicate pred = (isSigned ?
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT);
return new ICmpInst(pred, V, Hi);
@@ -3000,7 +2992,7 @@ Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
// V < Min || V >= Hi ->'V > Hi-1'
Hi = SubOne(cast<ConstantInt>(Hi));
if (cast<ConstantIntegral>(Lo)->isMinValue(isSigned)) {
if (cast<ConstantInt>(Lo)->isMinValue(isSigned)) {
ICmpInst::Predicate pred = (isSigned ?
ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT);
return new ICmpInst(pred, V, Hi);
@@ -3018,7 +3010,7 @@ Instruction *InstCombiner::InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
// any number of 0s on either side. The 1s are allowed to wrap from LSB to
// MSB, so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is
// not, since all 1s are not contiguous.
static bool isRunOfOnes(ConstantIntegral *Val, unsigned &MB, unsigned &ME) {
static bool isRunOfOnes(ConstantInt *Val, unsigned &MB, unsigned &ME) {
uint64_t V = Val->getZExtValue();
if (!isShiftedMask_64(V)) return false;
@@ -3042,7 +3034,7 @@ static bool isRunOfOnes(ConstantIntegral *Val, unsigned &MB, unsigned &ME) {
/// return (A +/- B).
///
Value *InstCombiner::FoldLogicalPlusAnd(Value *LHS, Value *RHS,
ConstantIntegral *Mask, bool isSub,
ConstantInt *Mask, bool isSub,
Instruction &I) {
Instruction *LHSI = dyn_cast<Instruction>(LHS);
if (!LHSI || LHSI->getNumOperands() != 2 ||
@@ -3106,7 +3098,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
KnownZero, KnownOne))
return &I;
if (ConstantIntegral *AndRHS = dyn_cast<ConstantIntegral>(Op1)) {
if (ConstantInt *AndRHS = dyn_cast<ConstantInt>(Op1)) {
uint64_t AndRHSMask = AndRHS->getZExtValue();
uint64_t TypeMask = Op0->getType()->getIntegralTypeMask();
uint64_t NotAndRHS = AndRHSMask^TypeMask;
@@ -3272,7 +3264,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst);
ICmpInst *LHS = cast<ICmpInst>(Op0);
if (cast<ConstantBool>(Cmp)->getValue()) {
if (cast<ConstantInt>(Cmp)->getBoolValue()) {
std::swap(LHS, RHS);
std::swap(LHSCst, RHSCst);
std::swap(LHSCC, RHSCC);
@@ -3294,7 +3286,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
case ICmpInst::ICMP_EQ: // (X == 13 & X == 15) -> false
case ICmpInst::ICMP_UGT: // (X == 13 & X > 15) -> false
case ICmpInst::ICMP_SGT: // (X == 13 & X > 15) -> false
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
case ICmpInst::ICMP_NE: // (X == 13 & X != 15) -> X == 13
case ICmpInst::ICMP_ULT: // (X == 13 & X < 15) -> X == 13
case ICmpInst::ICMP_SLT: // (X == 13 & X < 15) -> X == 13
@@ -3331,7 +3323,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
default: assert(0 && "Unknown integer condition code!");
case ICmpInst::ICMP_EQ: // (X u< 13 & X == 15) -> false
case ICmpInst::ICMP_UGT: // (X u< 13 & X u> 15) -> false
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
case ICmpInst::ICMP_SGT: // (X u< 13 & X s> 15) -> no change
break;
case ICmpInst::ICMP_NE: // (X u< 13 & X != 15) -> X u< 13
@@ -3346,7 +3338,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
default: assert(0 && "Unknown integer condition code!");
case ICmpInst::ICMP_EQ: // (X s< 13 & X == 15) -> false
case ICmpInst::ICMP_SGT: // (X s< 13 & X s> 15) -> false
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
case ICmpInst::ICMP_UGT: // (X s< 13 & X u> 15) -> no change
break;
case ICmpInst::ICMP_NE: // (X s< 13 & X != 15) -> X < 13
@@ -3563,7 +3555,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
if (isa<UndefValue>(Op1))
return ReplaceInstUsesWith(I, // X | undef -> -1
ConstantIntegral::getAllOnesValue(I.getType()));
ConstantInt::getAllOnesValue(I.getType()));
// or X, X = X
if (Op0 == Op1)
@@ -3578,7 +3570,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return &I;
// or X, -1 == -1
if (ConstantIntegral *RHS = dyn_cast<ConstantIntegral>(Op1)) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
ConstantInt *C1 = 0; Value *X = 0;
// (X & C1) | C2 --> (X | C2) & (C1|C2)
if (match(Op0, m_And(m_Value(X), m_ConstantInt(C1))) && isOnlyUse(Op0)) {
@@ -3692,7 +3684,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
if (match(Op0, m_Not(m_Value(A)))) { // ~A | Op1
if (A == Op1) // ~A | A == -1
return ReplaceInstUsesWith(I,
ConstantIntegral::getAllOnesValue(I.getType()));
ConstantInt::getAllOnesValue(I.getType()));
} else {
A = 0;
}
@@ -3700,7 +3692,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
if (match(Op1, m_Not(m_Value(B)))) { // Op0 | ~B
if (Op0 == B)
return ReplaceInstUsesWith(I,
ConstantIntegral::getAllOnesValue(I.getType()));
ConstantInt::getAllOnesValue(I.getType()));
// (~A | ~B) == (~(A & B)) - De Morgan's Law
if (A && isOnlyUse(Op0) && isOnlyUse(Op1)) {
@@ -3731,7 +3723,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst);
ICmpInst *LHS = cast<ICmpInst>(Op0);
if (cast<ConstantBool>(Cmp)->getValue()) {
if (cast<ConstantInt>(Cmp)->getBoolValue()) {
std::swap(LHS, RHS);
std::swap(LHSCst, RHSCst);
std::swap(LHSCC, RHSCC);
@@ -3779,7 +3771,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
case ICmpInst::ICMP_NE: // (X != 13 | X != 15) -> true
case ICmpInst::ICMP_ULT: // (X != 13 | X u< 15) -> true
case ICmpInst::ICMP_SLT: // (X != 13 | X s< 15) -> true
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
}
break;
case ICmpInst::ICMP_ULT:
@@ -3826,7 +3818,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
break;
case ICmpInst::ICMP_NE: // (X u> 13 | X != 15) -> true
case ICmpInst::ICMP_ULT: // (X u> 13 | X u< 15) -> true
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
case ICmpInst::ICMP_SLT: // (X u> 13 | X s< 15) -> no change
break;
}
@@ -3841,7 +3833,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
break;
case ICmpInst::ICMP_NE: // (X s> 13 | X != 15) -> true
case ICmpInst::ICMP_SLT: // (X s> 13 | X s< 15) -> true
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
case ICmpInst::ICMP_ULT: // (X s> 13 | X u< 15) -> no change
break;
}
@@ -3905,10 +3897,10 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
KnownZero, KnownOne))
return &I;
if (ConstantIntegral *RHS = dyn_cast<ConstantIntegral>(Op1)) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
// xor (icmp A, B), true = not (icmp A, B) = !icmp A, B
if (ICmpInst *ICI = dyn_cast<ICmpInst>(Op0))
if (RHS == ConstantBool::getTrue() && ICI->hasOneUse())
if (RHS == ConstantInt::getTrue() && ICI->hasOneUse())
return new ICmpInst(ICI->getInversePredicate(),
ICI->getOperand(0), ICI->getOperand(1));
@@ -3973,12 +3965,12 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
if (Value *X = dyn_castNotVal(Op0)) // ~A ^ A == -1
if (X == Op1)
return ReplaceInstUsesWith(I,
ConstantIntegral::getAllOnesValue(I.getType()));
ConstantInt::getAllOnesValue(I.getType()));
if (Value *X = dyn_castNotVal(Op1)) // A ^ ~A == -1
if (X == Op0)
return ReplaceInstUsesWith(I,
ConstantIntegral::getAllOnesValue(I.getType()));
ConstantInt::getAllOnesValue(I.getType()));
if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1))
if (Op1I->getOpcode() == Instruction::Or) {
@@ -4160,7 +4152,7 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
EmitIt = false; // This is indexing into a zero sized array?
} else if (isa<ConstantInt>(C))
return ReplaceInstUsesWith(I, // No comparison is needed here.
ConstantBool::get(Cond == ICmpInst::ICMP_NE));
ConstantInt::get(Cond == ICmpInst::ICMP_NE));
}
if (EmitIt) {
@@ -4184,7 +4176,7 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
return InVal;
else
// No comparison is needed here, all indexes = 0
ReplaceInstUsesWith(I, ConstantBool::get(Cond == ICmpInst::ICMP_EQ));
ReplaceInstUsesWith(I, ConstantInt::get(Cond == ICmpInst::ICMP_EQ));
}
// Only lower this if the icmp is the only user of the GEP or if we expect
@@ -4261,7 +4253,7 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
if (NumDifferences == 0) // SAME GEP?
return ReplaceInstUsesWith(I, // No comparison is needed here.
ConstantBool::get(Cond == ICmpInst::ICMP_EQ));
ConstantInt::get(Cond == ICmpInst::ICMP_EQ));
else if (NumDifferences == 1) {
Value *LHSV = GEPLHS->getOperand(DiffOperand);
Value *RHSV = GEPRHS->getOperand(DiffOperand);
@@ -4289,7 +4281,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
// fcmp pred X, X
if (Op0 == Op1)
return ReplaceInstUsesWith(I, ConstantBool::get(isTrueWhenEqual(I)));
return ReplaceInstUsesWith(I, ConstantInt::get(isTrueWhenEqual(I)));
if (isa<UndefValue>(Op1)) // fcmp pred X, undef -> undef
return ReplaceInstUsesWith(I, UndefValue::get(Type::BoolTy));
@@ -4341,7 +4333,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// icmp X, X
if (Op0 == Op1)
return ReplaceInstUsesWith(I, ConstantBool::get(isTrueWhenEqual(I)));
return ReplaceInstUsesWith(I, ConstantInt::get(isTrueWhenEqual(I)));
if (isa<UndefValue>(Op1)) // X icmp undef -> undef
return ReplaceInstUsesWith(I, UndefValue::get(Type::BoolTy));
@@ -4351,7 +4343,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (GlobalValue *GV0 = dyn_cast<GlobalValue>(Op0))
if (GlobalValue *GV1 = dyn_cast<GlobalValue>(Op1))
if (!GV0->hasExternalWeakLinkage() || !GV1->hasExternalWeakLinkage())
return ReplaceInstUsesWith(I, ConstantBool::get(!isTrueWhenEqual(I)));
return ReplaceInstUsesWith(I, ConstantInt::get(!isTrueWhenEqual(I)));
// icmp <global/alloca*/null>, <global/alloca*/null> - Global/Stack value
// addresses never equal each other! We already know that Op0 != Op1.
@@ -4359,7 +4351,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
isa<ConstantPointerNull>(Op0)) &&
(isa<GlobalValue>(Op1) || isa<AllocaInst>(Op1) ||
isa<ConstantPointerNull>(Op1)))
return ReplaceInstUsesWith(I, ConstantBool::get(!isTrueWhenEqual(I)));
return ReplaceInstUsesWith(I, ConstantInt::get(!isTrueWhenEqual(I)));
// icmp's with boolean values can always be turned into bitwise operations
if (Ty == Type::BoolTy) {
@@ -4403,7 +4395,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
default: break;
case ICmpInst::ICMP_ULT: // A <u MIN -> FALSE
if (CI->isMinValue(false))
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
if (CI->isMaxValue(false)) // A <u MAX -> A != MAX
return new ICmpInst(ICmpInst::ICMP_NE, Op0,Op1);
if (isMinValuePlusOne(CI,false)) // A <u MIN+1 -> A == MIN
@@ -4412,7 +4404,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case ICmpInst::ICMP_SLT:
if (CI->isMinValue(true)) // A <s MIN -> FALSE
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
if (CI->isMaxValue(true)) // A <s MAX -> A != MAX
return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
if (isMinValuePlusOne(CI,true)) // A <s MIN+1 -> A == MIN
@@ -4421,7 +4413,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case ICmpInst::ICMP_UGT:
if (CI->isMaxValue(false)) // A >u MAX -> FALSE
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
if (CI->isMinValue(false)) // A >u MIN -> A != MIN
return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
if (isMaxValueMinusOne(CI, false)) // A >u MAX-1 -> A == MAX
@@ -4430,7 +4422,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case ICmpInst::ICMP_SGT:
if (CI->isMaxValue(true)) // A >s MAX -> FALSE
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
if (CI->isMinValue(true)) // A >s MIN -> A != MIN
return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
if (isMaxValueMinusOne(CI, true)) // A >s MAX-1 -> A == MAX
@@ -4439,7 +4431,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case ICmpInst::ICMP_ULE:
if (CI->isMaxValue(false)) // A <=u MAX -> TRUE
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
if (CI->isMinValue(false)) // A <=u MIN -> A == MIN
return new ICmpInst(ICmpInst::ICMP_EQ, Op0, Op1);
if (isMaxValueMinusOne(CI,false)) // A <=u MAX-1 -> A != MAX
@@ -4448,7 +4440,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case ICmpInst::ICMP_SLE:
if (CI->isMaxValue(true)) // A <=s MAX -> TRUE
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
if (CI->isMinValue(true)) // A <=s MIN -> A == MIN
return new ICmpInst(ICmpInst::ICMP_EQ, Op0, Op1);
if (isMaxValueMinusOne(CI,true)) // A <=s MAX-1 -> A != MAX
@@ -4457,7 +4449,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case ICmpInst::ICMP_UGE:
if (CI->isMinValue(false)) // A >=u MIN -> TRUE
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
if (CI->isMaxValue(false)) // A >=u MAX -> A == MAX
return new ICmpInst(ICmpInst::ICMP_EQ, Op0, Op1);
if (isMinValuePlusOne(CI,false)) // A >=u MIN-1 -> A != MIN
@@ -4466,7 +4458,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case ICmpInst::ICMP_SGE:
if (CI->isMinValue(true)) // A >=s MIN -> TRUE
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
if (CI->isMaxValue(true)) // A >=s MAX -> A == MAX
return new ICmpInst(ICmpInst::ICMP_EQ, Op0, Op1);
if (isMinValuePlusOne(CI,true)) // A >=s MIN-1 -> A != MIN
@@ -4514,35 +4506,35 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
default: assert(0 && "Unknown icmp opcode!");
case ICmpInst::ICMP_EQ:
if (UMax < URHSVal || UMin > URHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
break;
case ICmpInst::ICMP_NE:
if (UMax < URHSVal || UMin > URHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
break;
case ICmpInst::ICMP_ULT:
if (UMax < URHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
if (UMin > URHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
break;
case ICmpInst::ICMP_UGT:
if (UMin > URHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
if (UMax < URHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
break;
case ICmpInst::ICMP_SLT:
if (SMax < SRHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
if (SMin > SRHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
break;
case ICmpInst::ICMP_SGT:
if (SMin > SRHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
if (SMax < SRHSVal)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
break;
}
}
@@ -4634,9 +4626,9 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// As a special case, check to see if this means that the
// result is always true or false now.
if (I.getPredicate() == ICmpInst::ICMP_EQ)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
if (I.getPredicate() == ICmpInst::ICMP_NE)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
} else {
I.setOperand(1, NewCst);
Constant *NewAndCST;
@@ -4699,7 +4691,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
ConstantExpr::getShl(ConstantExpr::getLShr(CI, ShAmt), ShAmt);
if (Comp != CI) {// Comparing against a bit that we know is zero.
bool IsICMP_NE = I.getPredicate() == ICmpInst::ICMP_NE;
Constant *Cst = ConstantBool::get(IsICMP_NE);
Constant *Cst = ConstantInt::get(IsICMP_NE);
return ReplaceInstUsesWith(I, Cst);
}
@@ -4743,7 +4735,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (Comp != CI) {// Comparing against a bit that we know is zero.
bool IsICMP_NE = I.getPredicate() == ICmpInst::ICMP_NE;
Constant *Cst = ConstantBool::get(IsICMP_NE);
Constant *Cst = ConstantInt::get(IsICMP_NE);
return ReplaceInstUsesWith(I, Cst);
}
@@ -4859,7 +4851,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
default: assert(0 && "Unhandled icmp opcode!");
case ICmpInst::ICMP_EQ:
if (LoOverflow && HiOverflow)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
else if (HiOverflow)
return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SGE :
ICmpInst::ICMP_UGE, X, LoBound);
@@ -4871,7 +4863,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
true, I);
case ICmpInst::ICMP_NE:
if (LoOverflow && HiOverflow)
return ReplaceInstUsesWith(I, ConstantBool::getTrue());
return ReplaceInstUsesWith(I, ConstantInt::getTrue());
else if (HiOverflow)
return new ICmpInst(DivIsSigned ? ICmpInst::ICMP_SLT :
ICmpInst::ICMP_ULT, X, LoBound);
@@ -4884,12 +4876,12 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
case ICmpInst::ICMP_ULT:
case ICmpInst::ICMP_SLT:
if (LoOverflow)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
return new ICmpInst(predicate, X, LoBound);
case ICmpInst::ICMP_UGT:
case ICmpInst::ICMP_SGT:
if (HiOverflow)
return ReplaceInstUsesWith(I, ConstantBool::getFalse());
return ReplaceInstUsesWith(I, ConstantInt::getFalse());
if (predicate == ICmpInst::ICMP_UGT)
return new ICmpInst(ICmpInst::ICMP_UGE, X, HiBound);
else
@@ -4965,7 +4957,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
if (Constant *BOC = dyn_cast<Constant>(BO->getOperand(1))) {
Constant *NotCI = ConstantExpr::getNot(CI);
if (!ConstantExpr::getAnd(BOC, NotCI)->isNullValue())
return ReplaceInstUsesWith(I, ConstantBool::get(isICMP_NE));
return ReplaceInstUsesWith(I, ConstantInt::get(isICMP_NE));
}
break;
@@ -4975,7 +4967,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// comparison can never succeed!
if (!ConstantExpr::getAnd(CI,
ConstantExpr::getNot(BOC))->isNullValue())
return ReplaceInstUsesWith(I, ConstantBool::get(isICMP_NE));
return ReplaceInstUsesWith(I, ConstantInt::get(isICMP_NE));
// If we have ((X & C) == C), turn it into ((X & C) != 0).
if (CI == BOC && isOneBitSet(CI))
@@ -5302,9 +5294,9 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
// First, handle some easy cases. We know the result cannot be equal at this
// point so handle the ICI.isEquality() cases
if (ICI.getPredicate() == ICmpInst::ICMP_EQ)
return ReplaceInstUsesWith(ICI, ConstantBool::getFalse());
return ReplaceInstUsesWith(ICI, ConstantInt::getFalse());
if (ICI.getPredicate() == ICmpInst::ICMP_NE)
return ReplaceInstUsesWith(ICI, ConstantBool::getTrue());
return ReplaceInstUsesWith(ICI, ConstantInt::getTrue());
// Evaluate the comparison for LT (we invert for GT below). LE and GE cases
// should have been folded away previously and not enter in here.
@@ -5312,20 +5304,20 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
if (isSignedCmp) {
// We're performing a signed comparison.
if (cast<ConstantInt>(CI)->getSExtValue() < 0)
Result = ConstantBool::getFalse(); // X < (small) --> false
Result = ConstantInt::getFalse(); // X < (small) --> false
else
Result = ConstantBool::getTrue(); // X < (large) --> true
Result = ConstantInt::getTrue(); // X < (large) --> true
} else {
// We're performing an unsigned comparison.
if (isSignedExt) {
// We're performing an unsigned comp with a sign extended value.
// This is true if the input is >= 0. [aka >s -1]
Constant *NegOne = ConstantIntegral::getAllOnesValue(SrcTy);
Constant *NegOne = ConstantInt::getAllOnesValue(SrcTy);
Result = InsertNewInstBefore(new ICmpInst(ICmpInst::ICMP_SGT, LHSCIOp,
NegOne, ICI.getName()), ICI);
} else {
// Unsigned extend & unsigned compare -> always true.
Result = ConstantBool::getTrue();
Result = ConstantInt::getTrue();
}
}
@@ -5620,7 +5612,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
// because it can not turn an arbitrary bit of A into a sign bit.
if (isUnsignedShift || isLeftShift) {
// Calculate bitmask for what gets shifted off the edge.
Constant *C = ConstantIntegral::getAllOnesValue(I.getType());
Constant *C = ConstantInt::getAllOnesValue(I.getType());
if (isLeftShift)
C = ConstantExpr::getShl(C, ShiftAmt1C);
else
@@ -5653,7 +5645,7 @@ Instruction *InstCombiner::FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
ConstantInt::get(Type::Int8Ty, ShiftAmt1-ShiftAmt2));
InsertNewInstBefore(Shift, I);
C = ConstantIntegral::getAllOnesValue(Shift->getType());
C = ConstantInt::getAllOnesValue(Shift->getType());
C = ConstantExpr::getShl(C, Op1);
return BinaryOperator::createAnd(Shift, C, Op->getName()+".mask");
}
@@ -6105,7 +6097,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
// cast (xor bool X, true) to int --> xor (cast bool X to int), 1
if (isa<ZExtInst>(CI) && SrcBitSize == 1 &&
SrcI->getOpcode() == Instruction::Xor &&
Op1 == ConstantBool::getTrue() &&
Op1 == ConstantInt::getTrue() &&
(!Op0->hasOneUse() || !isa<CmpInst>(Op0))) {
Value *New = InsertOperandCastBefore(Instruction::ZExt, Op0, DestTy, &CI);
return BinaryOperator::createXor(New, ConstantInt::get(CI.getType(), 1));
@@ -6190,7 +6182,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
if (Op1CV && (Op1CV != (KnownZero^TypeMask))) {
// (X&4) == 2 --> false
// (X&4) != 2 --> true
Constant *Res = ConstantBool::get(isNE);
Constant *Res = ConstantInt::get(isNE);
Res = ConstantExpr::getZExt(Res, CI.getType());
return ReplaceInstUsesWith(CI, Res);
}
@@ -6560,8 +6552,9 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
// select true, X, Y -> X
// select false, X, Y -> Y
if (ConstantBool *C = dyn_cast<ConstantBool>(CondVal))
return ReplaceInstUsesWith(SI, C->getValue() ? TrueVal : FalseVal);
if (ConstantInt *C = dyn_cast<ConstantInt>(CondVal))
if (C->getType() == Type::BoolTy)
return ReplaceInstUsesWith(SI, C->getBoolValue() ? TrueVal : FalseVal);
// select C, X, X -> X
if (TrueVal == FalseVal)
@@ -6578,9 +6571,11 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
return ReplaceInstUsesWith(SI, FalseVal);
}
if (SI.getType() == Type::BoolTy)
if (ConstantBool *C = dyn_cast<ConstantBool>(TrueVal)) {
if (C->getValue()) {
if (SI.getType() == Type::BoolTy) {
ConstantInt *C;
if ((C = dyn_cast<ConstantInt>(TrueVal)) &&
C->getType() == Type::BoolTy) {
if (C->getBoolValue()) {
// Change: A = select B, true, C --> A = or B, C
return BinaryOperator::createOr(CondVal, FalseVal);
} else {
@@ -6590,8 +6585,9 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
"not."+CondVal->getName()), SI);
return BinaryOperator::createAnd(NotCond, FalseVal);
}
} else if (ConstantBool *C = dyn_cast<ConstantBool>(FalseVal)) {
if (C->getValue() == false) {
} else if ((C = dyn_cast<ConstantInt>(FalseVal)) &&
C->getType() == Type::BoolTy) {
if (C->getBoolValue() == false) {
// Change: A = select B, C, false --> A = and B, C
return BinaryOperator::createAnd(CondVal, TrueVal);
} else {
@@ -6602,6 +6598,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
return BinaryOperator::createOr(NotCond, TrueVal);
}
}
}
// Selecting between two integer constants?
if (ConstantInt *TrueValC = dyn_cast<ConstantInt>(TrueVal))
@@ -7135,7 +7132,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
Instruction *OldCall = CS.getInstruction();
// If the call and callee calling conventions don't match, this call must
// be unreachable, as the call is undefined.
new StoreInst(ConstantBool::getTrue(),
new StoreInst(ConstantInt::getTrue(),
UndefValue::get(PointerType::get(Type::BoolTy)), OldCall);
if (!OldCall->use_empty())
OldCall->replaceAllUsesWith(UndefValue::get(OldCall->getType()));
@@ -7148,7 +7145,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
// This instruction is not reachable, just remove it. We insert a store to
// undef so that we know that this code is not reachable, despite the fact
// that we can't modify the CFG here.
new StoreInst(ConstantBool::getTrue(),
new StoreInst(ConstantInt::getTrue(),
UndefValue::get(PointerType::get(Type::BoolTy)),
CS.getInstruction());
@@ -7159,7 +7156,7 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
if (InvokeInst *II = dyn_cast<InvokeInst>(CS.getInstruction())) {
// Don't break the CFG, insert a dummy cond branch.
new BranchInst(II->getNormalDest(), II->getUnwindDest(),
ConstantBool::getTrue(), II);
ConstantInt::getTrue(), II);
}
return EraseInstFromFunction(*CS.getInstruction());
}
@@ -7940,7 +7937,7 @@ Instruction *InstCombiner::visitFreeInst(FreeInst &FI) {
// free undef -> unreachable.
if (isa<UndefValue>(Op)) {
// Insert a new store to null because we cannot modify the CFG here.
new StoreInst(ConstantBool::getTrue(),
new StoreInst(ConstantInt::getTrue(),
UndefValue::get(PointerType::get(Type::BoolTy)), &FI);
return EraseInstFromFunction(FI);
}
@@ -9051,8 +9048,9 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
// only visit the reachable successor.
TerminatorInst *TI = BB->getTerminator();
if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
if (BI->isConditional() && isa<ConstantBool>(BI->getCondition())) {
bool CondVal = cast<ConstantBool>(BI->getCondition())->getValue();
if (BI->isConditional() && isa<ConstantInt>(BI->getCondition()) &&
BI->getCondition()->getType() == Type::BoolTy) {
bool CondVal = cast<ConstantInt>(BI->getCondition())->getBoolValue();
AddReachableCodeToWorklist(BI->getSuccessor(!CondVal), Visited, WorkList,
TD);
return;
+34 -30
View File
@@ -171,7 +171,7 @@ bool LoopUnswitch::visitLoop(Loop *L) {
// See if this, or some part of it, is loop invariant. If so, we can
// unswitch on it if we desire.
Value *LoopCond = FindLIVLoopCondition(BI->getCondition(), L, Changed);
if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::getTrue(),
if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantInt::getTrue(),
L)) {
++NumBranches;
return true;
@@ -195,7 +195,7 @@ bool LoopUnswitch::visitLoop(Loop *L) {
BBI != E; ++BBI)
if (SelectInst *SI = dyn_cast<SelectInst>(BBI)) {
Value *LoopCond = FindLIVLoopCondition(SI->getCondition(), L, Changed);
if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantBool::getTrue(),
if (LoopCond && UnswitchIfProfitable(LoopCond, ConstantInt::getTrue(),
L)) {
++NumSelects;
return true;
@@ -286,9 +286,9 @@ static bool IsTrivialUnswitchCondition(Loop *L, Value *Cond, Constant **Val = 0,
// side-effects. If so, determine the value of Cond that causes it to do
// this.
if ((LoopExitBB = isTrivialLoopExitBlock(L, BI->getSuccessor(0)))) {
if (Val) *Val = ConstantBool::getTrue();
if (Val) *Val = ConstantInt::getTrue();
} else if ((LoopExitBB = isTrivialLoopExitBlock(L, BI->getSuccessor(1)))) {
if (Val) *Val = ConstantBool::getFalse();
if (Val) *Val = ConstantInt::getFalse();
}
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(HeaderTerm)) {
// If this isn't a switch on Cond, we can't handle it.
@@ -486,9 +486,9 @@ static void EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val,
// Insert a conditional branch on LIC to the two preheaders. The original
// code is the true version and the new code is the false version.
Value *BranchVal = LIC;
if (!isa<ConstantBool>(Val))
if (Val->getType() != Type::BoolTy)
BranchVal = new ICmpInst(ICmpInst::ICMP_EQ, LIC, Val, "tmp", InsertPt);
else if (Val != ConstantBool::getTrue())
else if (Val != ConstantInt::getTrue())
// We want to enter the new loop when the condition is true.
std::swap(TrueDest, FalseDest);
@@ -919,12 +919,12 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
// If we know that LIC == Val, or that LIC == NotVal, just replace uses of LIC
// in the loop with the appropriate one directly.
if (IsEqual || isa<ConstantBool>(Val)) {
if (IsEqual || (isa<ConstantInt>(Val) && Val->getType() == Type::BoolTy)) {
Value *Replacement;
if (IsEqual)
Replacement = Val;
else
Replacement = ConstantBool::get(!cast<ConstantBool>(Val)->getValue());
Replacement = ConstantInt::get(!cast<ConstantInt>(Val)->getBoolValue());
for (unsigned i = 0, e = Users.size(); i != e; ++i)
if (Instruction *U = cast<Instruction>(Users[i])) {
@@ -962,7 +962,7 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
Instruction* OldTerm = Old->getTerminator();
new BranchInst(Split, SI->getSuccessor(i),
ConstantBool::getTrue(), OldTerm);
ConstantInt::getTrue(), OldTerm);
Old->getTerminator()->eraseFromParent();
@@ -1025,32 +1025,36 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist) {
// Special case hacks that appear commonly in unswitched code.
switch (I->getOpcode()) {
case Instruction::Select:
if (ConstantBool *CB = dyn_cast<ConstantBool>(I->getOperand(0))) {
ReplaceUsesOfWith(I, I->getOperand(!CB->getValue()+1), Worklist);
if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(0))) {
ReplaceUsesOfWith(I, I->getOperand(!CB->getBoolValue()+1), Worklist);
continue;
}
break;
case Instruction::And:
if (isa<ConstantBool>(I->getOperand(0))) // constant -> RHS
if (isa<ConstantInt>(I->getOperand(0)) &&
I->getOperand(0)->getType() == Type::BoolTy) // constant -> RHS
cast<BinaryOperator>(I)->swapOperands();
if (ConstantBool *CB = dyn_cast<ConstantBool>(I->getOperand(1))) {
if (CB->getValue()) // X & 1 -> X
ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
else // X & 0 -> 0
ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
continue;
}
if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1)))
if (CB->getType() == Type::BoolTy) {
if (CB->getBoolValue()) // X & 1 -> X
ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
else // X & 0 -> 0
ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
continue;
}
break;
case Instruction::Or:
if (isa<ConstantBool>(I->getOperand(0))) // constant -> RHS
if (isa<ConstantInt>(I->getOperand(0)) &&
I->getOperand(0)->getType() == Type::BoolTy) // constant -> RHS
cast<BinaryOperator>(I)->swapOperands();
if (ConstantBool *CB = dyn_cast<ConstantBool>(I->getOperand(1))) {
if (CB->getValue()) // X | 1 -> 1
ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
else // X | 0 -> X
ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
continue;
}
if (ConstantInt *CB = dyn_cast<ConstantInt>(I->getOperand(1)))
if (CB->getType() == Type::BoolTy) {
if (CB->getBoolValue()) // X | 1 -> 1
ReplaceUsesOfWith(I, I->getOperand(1), Worklist);
else // X | 0 -> X
ReplaceUsesOfWith(I, I->getOperand(0), Worklist);
continue;
}
break;
case Instruction::Br: {
BranchInst *BI = cast<BranchInst>(I);
@@ -1084,14 +1088,14 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist) {
LI->removeBlock(Succ);
Succ->eraseFromParent();
++NumSimplify;
} else if (ConstantBool *CB = dyn_cast<ConstantBool>(BI->getCondition())){
} else if (ConstantInt *CB = dyn_cast<ConstantInt>(BI->getCondition())){
// Conditional branch. Turn it into an unconditional branch, then
// remove dead blocks.
break; // FIXME: Enable.
DOUT << "Folded branch: " << *BI;
BasicBlock *DeadSucc = BI->getSuccessor(CB->getValue());
BasicBlock *LiveSucc = BI->getSuccessor(!CB->getValue());
BasicBlock *DeadSucc = BI->getSuccessor(CB->getBoolValue());
BasicBlock *LiveSucc = BI->getSuccessor(!CB->getBoolValue());
DeadSucc->removePredecessor(BI->getParent(), true);
Worklist.push_back(new BranchInst(LiveSucc, BI));
BI->eraseFromParent();
+31 -26
View File
@@ -357,16 +357,16 @@ namespace {
std::vector<Node> Nodes;
std::vector<std::pair<ConstantIntegral *, unsigned> > Constants;
std::vector<std::pair<ConstantInt *, unsigned> > Constants;
void initializeConstant(Constant *C, unsigned index) {
ConstantIntegral *CI = dyn_cast<ConstantIntegral>(C);
ConstantInt *CI = dyn_cast<ConstantInt>(C);
if (!CI) return;
// XXX: instead of O(n) calls to addInequality, just find the 2, 3 or 4
// nodes that are nearest less than or greater than (signed or unsigned).
for (std::vector<std::pair<ConstantIntegral *, unsigned> >::iterator
for (std::vector<std::pair<ConstantInt *, unsigned> >::iterator
I = Constants.begin(), E = Constants.end(); I != E; ++I) {
ConstantIntegral *Other = I->first;
ConstantInt *Other = I->first;
if (CI->getType() == Other->getType()) {
unsigned lv = 0;
@@ -1046,7 +1046,7 @@ namespace {
if (Constant *C1 = dyn_cast<Constant>(V1))
if (Constant *C2 = dyn_cast<Constant>(V2))
return ConstantExpr::getCompare(Pred, C1, C2) ==
ConstantBool::getTrue();
ConstantInt::getTrue();
// XXX: this is lousy. If we're passed a Constant, then we might miss
// some relationships if it isn't in the IG because the relationships
@@ -1100,7 +1100,7 @@ namespace {
case Instruction::And: {
// "and int %a, %b" EQ -1 then %a EQ -1 and %b EQ -1
// "and bool %a, %b" EQ true then %a EQ true and %b EQ true
ConstantIntegral *CI = ConstantIntegral::getAllOnesValue(Ty);
ConstantInt *CI = ConstantInt::getAllOnesValue(Ty);
if (Canonical == CI) {
add(CI, Op0, ICmpInst::ICMP_EQ, NewContext);
add(CI, Op1, ICmpInst::ICMP_EQ, NewContext);
@@ -1127,13 +1127,17 @@ namespace {
Value *RHS = Op1;
if (!isa<Constant>(LHS)) std::swap(LHS, RHS);
if (ConstantBool *CB = dyn_cast<ConstantBool>(Canonical)) {
if (ConstantBool *A = dyn_cast<ConstantBool>(LHS))
add(RHS, ConstantBool::get(A->getValue() ^ CB->getValue()),
ICmpInst::ICMP_EQ, NewContext);
ConstantInt *CB, *A;
if ((CB = dyn_cast<ConstantInt>(Canonical)) &&
CB->getType() == Type::BoolTy) {
if ((A = dyn_cast<ConstantInt>(LHS)) &&
A->getType() == Type::BoolTy)
add(RHS, ConstantInt::get(A->getBoolValue() ^
CB->getBoolValue()),
ICmpInst::ICMP_EQ, NewContext);
}
if (Canonical == LHS) {
if (isa<ConstantIntegral>(Canonical))
if (isa<ConstantInt>(Canonical))
add(RHS, Constant::getNullValue(Ty), ICmpInst::ICMP_EQ,
NewContext);
} else if (isRelatedBy(LHS, Canonical, ICmpInst::ICMP_NE)) {
@@ -1148,10 +1152,10 @@ namespace {
// "icmp ult int %a, int %y" EQ true then %a u< y
// etc.
if (Canonical == ConstantBool::getTrue()) {
if (Canonical == ConstantInt::getTrue()) {
add(IC->getOperand(0), IC->getOperand(1), IC->getPredicate(),
NewContext);
} else if (Canonical == ConstantBool::getFalse()) {
} else if (Canonical == ConstantInt::getFalse()) {
add(IC->getOperand(0), IC->getOperand(1),
ICmpInst::getInversePredicate(IC->getPredicate()), NewContext);
}
@@ -1167,11 +1171,11 @@ namespace {
if (isRelatedBy(True, False, ICmpInst::ICMP_NE)) {
if (Canonical == IG.canonicalize(True, Top) ||
isRelatedBy(Canonical, False, ICmpInst::ICMP_NE))
add(SI->getCondition(), ConstantBool::getTrue(),
add(SI->getCondition(), ConstantInt::getTrue(),
ICmpInst::ICMP_EQ, NewContext);
else if (Canonical == IG.canonicalize(False, Top) ||
isRelatedBy(I, True, ICmpInst::ICMP_NE))
add(SI->getCondition(), ConstantBool::getFalse(),
add(SI->getCondition(), ConstantInt::getFalse(),
ICmpInst::ICMP_EQ, NewContext);
}
}
@@ -1188,8 +1192,8 @@ namespace {
Value *Op0 = IG.canonicalize(BO->getOperand(0), Top);
Value *Op1 = IG.canonicalize(BO->getOperand(1), Top);
if (ConstantIntegral *CI0 = dyn_cast<ConstantIntegral>(Op0))
if (ConstantIntegral *CI1 = dyn_cast<ConstantIntegral>(Op1)) {
if (ConstantInt *CI0 = dyn_cast<ConstantInt>(Op0))
if (ConstantInt *CI1 = dyn_cast<ConstantInt>(Op1)) {
add(BO, ConstantExpr::get(BO->getOpcode(), CI0, CI1),
ICmpInst::ICMP_EQ, NewContext);
return;
@@ -1207,7 +1211,7 @@ namespace {
return;
}
} else if (BO->getOpcode() == Instruction::And) {
Constant *AllOnes = ConstantIntegral::getAllOnesValue(BO->getType());
Constant *AllOnes = ConstantInt::getAllOnesValue(BO->getType());
if (Op0 == AllOnes) {
add(BO, Op1, ICmpInst::ICMP_EQ, NewContext);
return;
@@ -1244,8 +1248,9 @@ namespace {
Constant *One = NULL;
if (isa<ConstantInt>(Unknown))
One = ConstantInt::get(Ty, 1);
else if (isa<ConstantBool>(Unknown))
One = ConstantBool::getTrue();
else if (isa<ConstantInt>(Unknown) &&
Unknown->getType() == Type::BoolTy)
One = ConstantInt::getTrue();
if (One) add(Unknown, One, ICmpInst::ICMP_EQ, NewContext);
break;
@@ -1264,9 +1269,9 @@ namespace {
ICmpInst::Predicate Pred = IC->getPredicate();
if (isRelatedBy(Op0, Op1, Pred)) {
add(IC, ConstantBool::getTrue(), ICmpInst::ICMP_EQ, NewContext);
add(IC, ConstantInt::getTrue(), ICmpInst::ICMP_EQ, NewContext);
} else if (isRelatedBy(Op0, Op1, ICmpInst::getInversePredicate(Pred))) {
add(IC, ConstantBool::getFalse(), ICmpInst::ICMP_EQ, NewContext);
add(IC, ConstantInt::getFalse(), ICmpInst::ICMP_EQ, NewContext);
}
// TODO: make the predicate more strict, if possible.
@@ -1278,9 +1283,9 @@ namespace {
// %b EQ %c then %a EQ %b
Value *Canonical = IG.canonicalize(SI->getCondition(), Top);
if (Canonical == ConstantBool::getTrue()) {
if (Canonical == ConstantInt::getTrue()) {
add(SI, SI->getTrueValue(), ICmpInst::ICMP_EQ, NewContext);
} else if (Canonical == ConstantBool::getFalse()) {
} else if (Canonical == ConstantInt::getFalse()) {
add(SI, SI->getFalseValue(), ICmpInst::ICMP_EQ, NewContext);
} else if (IG.canonicalize(SI->getTrueValue(), Top) ==
IG.canonicalize(SI->getFalseValue(), Top)) {
@@ -1565,13 +1570,13 @@ namespace {
if (Dest == TrueDest) {
DOUT << "(" << DTNode->getBlock()->getName() << ") true set:\n";
VRPSolver VRP(IG, UB, PS->Forest, PS->modified, Dest);
VRP.add(ConstantBool::getTrue(), Condition, ICmpInst::ICMP_EQ);
VRP.add(ConstantInt::getTrue(), Condition, ICmpInst::ICMP_EQ);
VRP.solve();
DEBUG(IG.dump());
} else if (Dest == FalseDest) {
DOUT << "(" << DTNode->getBlock()->getName() << ") false set:\n";
VRPSolver VRP(IG, UB, PS->Forest, PS->modified, Dest);
VRP.add(ConstantBool::getFalse(), Condition, ICmpInst::ICMP_EQ);
VRP.add(ConstantInt::getFalse(), Condition, ICmpInst::ICMP_EQ);
VRP.solve();
DEBUG(IG.dump());
}
+2 -2
View File
@@ -537,7 +537,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
}
// Check for destructive annihilation due to a constant being used.
if (ConstantIntegral *CstVal = dyn_cast<ConstantIntegral>(Ops.back().Op))
if (ConstantInt *CstVal = dyn_cast<ConstantInt>(Ops.back().Op))
switch (Opcode) {
default: break;
case Instruction::And:
@@ -591,7 +591,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
return Constant::getNullValue(X->getType());
} else if (Opcode == Instruction::Or) { // ...|X|~X = -1
++NumAnnihil;
return ConstantIntegral::getAllOnesValue(X->getType());
return ConstantInt::getAllOnesValue(X->getType());
}
}
}
+12 -10
View File
@@ -416,13 +416,14 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI,
} else {
LatticeVal &BCValue = getValueState(BI->getCondition());
if (BCValue.isOverdefined() ||
(BCValue.isConstant() && !isa<ConstantBool>(BCValue.getConstant()))) {
(BCValue.isConstant() &&
BCValue.getConstant()->getType() != Type::BoolTy)) {
// Overdefined condition variables, and branches on unfoldable constant
// conditions, mean the branch could go either way.
Succs[0] = Succs[1] = true;
} else if (BCValue.isConstant()) {
// Constant condition variables mean the branch can only go a single way
Succs[BCValue.getConstant() == ConstantBool::getFalse()] = true;
Succs[BCValue.getConstant() == ConstantInt::getFalse()] = true;
}
}
} else if (isa<InvokeInst>(&TI)) {
@@ -476,11 +477,11 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) {
return true;
} else if (BCValue.isConstant()) {
// Not branching on an evaluatable constant?
if (!isa<ConstantBool>(BCValue.getConstant())) return true;
if (BCValue.getConstant()->getType() != Type::BoolTy) return true;
// Constant condition variables mean the branch can only go a single way
return BI->getSuccessor(BCValue.getConstant() ==
ConstantBool::getFalse()) == To;
ConstantInt::getFalse()) == To;
}
return false;
}
@@ -646,10 +647,11 @@ void SCCPSolver::visitSelectInst(SelectInst &I) {
LatticeVal &CondValue = getValueState(I.getCondition());
if (CondValue.isUndefined())
return;
if (CondValue.isConstant()) {
if (ConstantBool *CondCB = dyn_cast<ConstantBool>(CondValue.getConstant())){
mergeInValue(&I, getValueState(CondCB->getValue() ? I.getTrueValue()
: I.getFalseValue()));
if (CondValue.isConstant() &&
CondValue.getConstant()->getType() == Type::BoolTy) {
if (ConstantInt *CondCB = dyn_cast<ConstantInt>(CondValue.getConstant())){
mergeInValue(&I, getValueState(CondCB->getBoolValue() ? I.getTrueValue()
: I.getFalseValue()));
return;
}
}
@@ -712,8 +714,8 @@ void SCCPSolver::visitBinaryOperator(Instruction &I) {
return; // X and 0 = 0
}
} else {
if (ConstantIntegral *CI =
dyn_cast<ConstantIntegral>(NonOverdefVal->getConstant()))
if (ConstantInt *CI =
dyn_cast<ConstantInt>(NonOverdefVal->getConstant()))
if (CI->isAllOnesValue()) {
markConstant(IV, &I, NonOverdefVal->getConstant());
return; // X or -1 = -1
+8 -5
View File
@@ -226,11 +226,14 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB) {
if (const BranchInst *BI = dyn_cast<BranchInst>(OldTI)) {
if (BI->isConditional()) {
// If the condition was a known constant in the callee...
ConstantBool *Cond = dyn_cast<ConstantBool>(BI->getCondition());
if (Cond == 0) // Or is a known constant in the caller...
Cond = dyn_cast_or_null<ConstantBool>(ValueMap[BI->getCondition()]);
if (Cond) { // Constant fold to uncond branch!
BasicBlock *Dest = BI->getSuccessor(!Cond->getValue());
ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition());
// Or is a known constant in the caller...
if (Cond == 0)
Cond = dyn_cast_or_null<ConstantInt>(ValueMap[BI->getCondition()]);
// Constant fold to uncond branch!
if (Cond) {
BasicBlock *Dest = BI->getSuccessor(!Cond->getBoolValue());
ValueMap[OldTI] = new BranchInst(Dest, NewBB);
CloneBlock(Dest);
TerminatorDone = true;
+1 -1
View File
@@ -470,7 +470,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
case 0:
case 1: break; // No value needed.
case 2: // Conditional branch, return a bool
brVal = ConstantBool::get(!SuccNum);
brVal = ConstantInt::get(!SuccNum);
break;
default:
brVal = ConstantInt::get(Type::Int16Ty, SuccNum);
+3 -3
View File
@@ -173,11 +173,11 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) {
BasicBlock *Dest1 = cast<BasicBlock>(BI->getOperand(0));
BasicBlock *Dest2 = cast<BasicBlock>(BI->getOperand(1));
if (ConstantBool *Cond = dyn_cast<ConstantBool>(BI->getCondition())) {
if (ConstantInt *Cond = dyn_cast<ConstantInt>(BI->getCondition())) {
// Are we branching on constant?
// YES. Change to unconditional branch...
BasicBlock *Destination = Cond->getValue() ? Dest1 : Dest2;
BasicBlock *OldDest = Cond->getValue() ? Dest2 : Dest1;
BasicBlock *Destination = Cond->getBoolValue() ? Dest1 : Dest2;
BasicBlock *OldDest = Cond->getBoolValue() ? Dest2 : Dest1;
//cerr << "Function: " << T->getParent()->getParent()
// << "\nRemoving branch from " << T->getParent()
+8 -5
View File
@@ -968,12 +968,14 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
// Okay, this is a simple enough basic block. See if any phi values are
// constants.
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
if (ConstantBool *CB = dyn_cast<ConstantBool>(PN->getIncomingValue(i))) {
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
ConstantInt *CB;
if ((CB = dyn_cast<ConstantInt>(PN->getIncomingValue(i))) &&
CB->getType() == Type::BoolTy) {
// Okay, we now know that all edges from PredBB should be revectored to
// branch to RealDest.
BasicBlock *PredBB = PN->getIncomingBlock(i);
BasicBlock *RealDest = BI->getSuccessor(!CB->getValue());
BasicBlock *RealDest = BI->getSuccessor(!CB->getBoolValue());
if (RealDest == BB) continue; // Skip self loops.
@@ -1037,6 +1039,7 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
// Recurse, simplifying any other constants.
return FoldCondBranchOnPHI(BI) | true;
}
}
return false;
}
@@ -1506,7 +1509,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
if (BB->getSinglePredecessor()) {
// Turn this into a branch on constant.
bool CondIsTrue = PBI->getSuccessor(0) == BB;
BI->setCondition(ConstantBool::get(CondIsTrue));
BI->setCondition(ConstantInt::get(CondIsTrue));
return SimplifyCFG(BB); // Nuke the branch on constant.
}
@@ -1522,7 +1525,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
PBI->getCondition() == BI->getCondition() &&
PBI->getSuccessor(0) != PBI->getSuccessor(1)) {
bool CondIsTrue = PBI->getSuccessor(0) == BB;
NewPN->addIncoming(ConstantBool::get(CondIsTrue), *PI);
NewPN->addIncoming(ConstantInt::get(CondIsTrue), *PI);
} else {
NewPN->addIncoming(BI->getCondition(), *PI);
}
+1 -1
View File
@@ -28,7 +28,7 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) {
return VMSlot = const_cast<Value*>(V);
if (Constant *C = const_cast<Constant*>(dyn_cast<Constant>(V))) {
if (isa<ConstantIntegral>(C) || isa<ConstantFP>(C) ||
if (isa<ConstantInt>(C) || isa<ConstantFP>(C) ||
isa<ConstantPointerNull>(C) || isa<ConstantAggregateZero>(C) ||
isa<UndefValue>(C))
return VMSlot = C; // Primitive constants map directly
+4 -4
View File
@@ -438,10 +438,10 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV,
SlotMachine *Machine) {
const int IndentSize = 4;
static std::string Indent = "\n";
if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
Out << (CB->getValue() ? "true" : "false");
} else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Out << CI->getSExtValue();
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
if (CI->getType() == Type::BoolTy)
Out << (CI->getBoolValue() ? "true" : "false");
else Out << CI->getSExtValue();
} else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
// We would like to output the FP constant value in exponential notation,
// but we cannot do this if doing so will lose precision. Check here to
+168 -172
View File
@@ -174,11 +174,11 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
return 0; // Can't fold.
case Instruction::FPToUI:
if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V))
return ConstantIntegral::get(DestTy,(uint64_t) FPC->getValue());
return ConstantInt::get(DestTy,(uint64_t) FPC->getValue());
return 0; // Can't fold.
case Instruction::FPToSI:
if (const ConstantFP *FPC = dyn_cast<ConstantFP>(V))
return ConstantIntegral::get(DestTy,(int64_t) FPC->getValue());
return ConstantInt::get(DestTy,(int64_t) FPC->getValue());
return 0; // Can't fold.
case Instruction::IntToPtr: //always treated as unsigned
if (V->isNullValue()) // Is it an integral null value?
@@ -186,27 +186,27 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
return 0; // Other pointer types cannot be casted
case Instruction::PtrToInt: // always treated as unsigned
if (V->isNullValue()) // is it a null pointer value?
return ConstantIntegral::get(DestTy, 0);
return ConstantInt::get(DestTy, 0);
return 0; // Other pointer types cannot be casted
case Instruction::UIToFP:
if (const ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V))
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
return ConstantFP::get(DestTy, double(CI->getZExtValue()));
return 0;
case Instruction::SIToFP:
if (const ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V))
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
return ConstantFP::get(DestTy, double(CI->getSExtValue()));
return 0;
case Instruction::ZExt:
if (const ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V))
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
return ConstantInt::get(DestTy, CI->getZExtValue());
return 0;
case Instruction::SExt:
if (const ConstantIntegral *CI = dyn_cast<ConstantIntegral>(V))
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
return ConstantInt::get(DestTy, CI->getSExtValue());
return 0;
case Instruction::Trunc:
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) // Can't trunc a bool
return ConstantIntegral::get(DestTy, CI->getZExtValue());
return ConstantInt::get(DestTy, CI->getZExtValue());
return 0;
case Instruction::BitCast:
if (SrcTy == DestTy)
@@ -316,8 +316,9 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
Constant *llvm::ConstantFoldSelectInstruction(const Constant *Cond,
const Constant *V1,
const Constant *V2) {
if (const ConstantBool *CB = dyn_cast<ConstantBool>(Cond))
return const_cast<Constant*>(CB->getValue() ? V1 : V2);
if (const ConstantInt *CB = dyn_cast<ConstantInt>(Cond))
if (CB->getType() == Type::BoolTy)
return const_cast<Constant*>(CB->getBoolValue() ? V1 : V2);
if (isa<UndefValue>(V1)) return const_cast<Constant*>(V2);
if (isa<UndefValue>(V2)) return const_cast<Constant*>(V1);
@@ -552,76 +553,70 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
// At this point we know neither constant is an UndefValue nor a ConstantExpr
// so look at directly computing the value.
if (const ConstantBool *CB1 = dyn_cast<ConstantBool>(C1)) {
if (const ConstantBool *CB2 = dyn_cast<ConstantBool>(C2)) {
switch (Opcode) {
if (const ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
if (const ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
if (CI1->getType() == Type::BoolTy && CI2->getType() == Type::BoolTy) {
switch (Opcode) {
default:
break;
case Instruction::And:
return ConstantInt::get(CI1->getBoolValue() & CI2->getBoolValue());
case Instruction::Or:
return ConstantInt::get(CI1->getBoolValue() | CI2->getBoolValue());
case Instruction::Xor:
return ConstantInt::get(CI1->getBoolValue() ^ CI2->getBoolValue());
}
} else {
uint64_t C1Val = CI1->getZExtValue();
uint64_t C2Val = CI2->getZExtValue();
switch (Opcode) {
default:
break;
case Instruction::Add:
return ConstantInt::get(C1->getType(), C1Val + C2Val);
case Instruction::Sub:
return ConstantInt::get(C1->getType(), C1Val - C2Val);
case Instruction::Mul:
return ConstantInt::get(C1->getType(), C1Val * C2Val);
case Instruction::UDiv:
if (CI2->isNullValue()) // X / 0 -> can't fold
return 0;
return ConstantInt::get(C1->getType(), C1Val / C2Val);
case Instruction::SDiv:
if (CI2->isNullValue()) return 0; // X / 0 -> can't fold
if (CI2->isAllOnesValue() &&
(((CI1->getType()->getPrimitiveSizeInBits() == 64) &&
(CI1->getSExtValue() == INT64_MIN)) ||
(CI1->getSExtValue() == -CI1->getSExtValue())))
return 0; // MIN_INT / -1 -> overflow
return ConstantInt::get(C1->getType(),
CI1->getSExtValue() / CI2->getSExtValue());
case Instruction::URem:
if (C2->isNullValue()) return 0; // X / 0 -> can't fold
return ConstantInt::get(C1->getType(), C1Val % C2Val);
case Instruction::SRem:
if (CI2->isNullValue()) return 0; // X % 0 -> can't fold
if (CI2->isAllOnesValue() &&
(((CI1->getType()->getPrimitiveSizeInBits() == 64) &&
(CI1->getSExtValue() == INT64_MIN)) ||
(CI1->getSExtValue() == -CI1->getSExtValue())))
return 0; // MIN_INT % -1 -> overflow
return ConstantInt::get(C1->getType(),
CI1->getSExtValue() % CI2->getSExtValue());
case Instruction::And:
return ConstantBool::get(CB1->getValue() & CB2->getValue());
return ConstantInt::get(C1->getType(), C1Val & C2Val);
case Instruction::Or:
return ConstantBool::get(CB1->getValue() | CB2->getValue());
return ConstantInt::get(C1->getType(), C1Val | C2Val);
case Instruction::Xor:
return ConstantBool::get(CB1->getValue() ^ CB2->getValue());
}
}
} else if (const ConstantInt *CI1 = dyn_cast<ConstantInt>(C1)) {
if (const ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) {
uint64_t C1Val = CI1->getZExtValue();
uint64_t C2Val = CI2->getZExtValue();
switch (Opcode) {
default:
break;
case Instruction::Add:
return ConstantInt::get(C1->getType(), C1Val + C2Val);
case Instruction::Sub:
return ConstantInt::get(C1->getType(), C1Val - C2Val);
case Instruction::Mul:
return ConstantInt::get(C1->getType(), C1Val * C2Val);
case Instruction::UDiv:
if (CI2->isNullValue()) // X / 0 -> can't fold
return 0;
return ConstantInt::get(C1->getType(), C1Val / C2Val);
case Instruction::SDiv:
if (CI2->isNullValue()) return 0; // X / 0 -> can't fold
if (CI2->isAllOnesValue() &&
(((CI1->getType()->getPrimitiveSizeInBits() == 64) &&
(CI1->getSExtValue() == INT64_MIN)) ||
(CI1->getSExtValue() == -CI1->getSExtValue())))
return 0; // MIN_INT / -1 -> overflow
return ConstantInt::get(C1->getType(),
CI1->getSExtValue() / CI2->getSExtValue());
case Instruction::URem:
if (C2->isNullValue()) return 0; // X / 0 -> can't fold
return ConstantInt::get(C1->getType(), C1Val % C2Val);
case Instruction::SRem:
if (CI2->isNullValue()) return 0; // X % 0 -> can't fold
if (CI2->isAllOnesValue() &&
(((CI1->getType()->getPrimitiveSizeInBits() == 64) &&
(CI1->getSExtValue() == INT64_MIN)) ||
(CI1->getSExtValue() == -CI1->getSExtValue())))
return 0; // MIN_INT % -1 -> overflow
return ConstantInt::get(C1->getType(),
CI1->getSExtValue() % CI2->getSExtValue());
case Instruction::And:
return ConstantInt::get(C1->getType(), C1Val & C2Val);
case Instruction::Or:
return ConstantInt::get(C1->getType(), C1Val | C2Val);
case Instruction::Xor:
return ConstantInt::get(C1->getType(), C1Val ^ C2Val);
case Instruction::Shl:
if (C2Val >= CI1->getType()->getPrimitiveSizeInBits())
C2Val = CI1->getType()->getPrimitiveSizeInBits() - 1;
return ConstantInt::get(C1->getType(), C1Val << C2Val);
case Instruction::LShr:
if (C2Val >= CI1->getType()->getPrimitiveSizeInBits())
C2Val = CI1->getType()->getPrimitiveSizeInBits() - 1;
return ConstantInt::get(C1->getType(), C1Val >> C2Val);
case Instruction::AShr:
if (C2Val >= CI1->getType()->getPrimitiveSizeInBits())
C2Val = CI1->getType()->getPrimitiveSizeInBits() - 1;
return ConstantInt::get(C1->getType(),
CI1->getSExtValue() >> C2Val);
return ConstantInt::get(C1->getType(), C1Val ^ C2Val);
case Instruction::Shl:
return ConstantInt::get(C1->getType(), C1Val << C2Val);
case Instruction::LShr:
return ConstantInt::get(C1->getType(), C1Val >> C2Val);
case Instruction::AShr:
return ConstantInt::get(C1->getType(),
CI1->getSExtValue() >> C2Val);
}
}
}
} else if (const ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
@@ -765,20 +760,20 @@ static FCmpInst::Predicate evaluateFCmpRelation(const Constant *V1,
if (!isa<ConstantExpr>(V1)) {
if (!isa<ConstantExpr>(V2)) {
// We distilled thisUse the standard constant folder for a few cases
ConstantBool *R = 0;
ConstantInt *R = 0;
Constant *C1 = const_cast<Constant*>(V1);
Constant *C2 = const_cast<Constant*>(V2);
R = dyn_cast<ConstantBool>(
R = dyn_cast<ConstantInt>(
ConstantExpr::getFCmp(FCmpInst::FCMP_OEQ, C1, C2));
if (R && R->getValue())
if (R && R->getBoolValue())
return FCmpInst::FCMP_OEQ;
R = dyn_cast<ConstantBool>(
R = dyn_cast<ConstantInt>(
ConstantExpr::getFCmp(FCmpInst::FCMP_OLT, C1, C2));
if (R && R->getValue())
if (R && R->getBoolValue())
return FCmpInst::FCMP_OLT;
R = dyn_cast<ConstantBool>(
R = dyn_cast<ConstantInt>(
ConstantExpr::getFCmp(FCmpInst::FCMP_OGT, C1, C2));
if (R && R->getValue())
if (R && R->getBoolValue())
return FCmpInst::FCMP_OGT;
// Nothing more we can do
@@ -832,20 +827,20 @@ static ICmpInst::Predicate evaluateICmpRelation(const Constant *V1,
if (!isa<GlobalValue>(V2) && !isa<ConstantExpr>(V2)) {
// We distilled this down to a simple case, use the standard constant
// folder.
ConstantBool *R = 0;
ConstantInt *R = 0;
Constant *C1 = const_cast<Constant*>(V1);
Constant *C2 = const_cast<Constant*>(V2);
ICmpInst::Predicate pred = ICmpInst::ICMP_EQ;
R = dyn_cast<ConstantBool>(ConstantExpr::getICmp(pred, C1, C2));
if (R && R->getValue())
R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
if (R && R->getBoolValue())
return pred;
pred = isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
R = dyn_cast<ConstantBool>(ConstantExpr::getICmp(pred, C1, C2));
if (R && R->getValue())
R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
if (R && R->getBoolValue())
return pred;
pred = isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
R = dyn_cast<ConstantBool>(ConstantExpr::getICmp(pred, C1, C2));
if (R && R->getValue())
R = dyn_cast<ConstantInt>(ConstantExpr::getICmp(pred, C1, C2));
if (R && R->getBoolValue())
return pred;
// If we couldn't figure it out, bail.
@@ -1013,14 +1008,14 @@ static ICmpInst::Predicate evaluateICmpRelation(const Constant *V1,
// are non-zero then we have a difference, otherwise we are equal.
for (; i < CE1->getNumOperands(); ++i)
if (!CE1->getOperand(i)->isNullValue())
if (isa<ConstantIntegral>(CE1->getOperand(i)))
if (isa<ConstantInt>(CE1->getOperand(i)))
return isSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
else
return ICmpInst::BAD_ICMP_PREDICATE; // Might be equal.
for (; i < CE2->getNumOperands(); ++i)
if (!CE2->getOperand(i)->isNullValue())
if (isa<ConstantIntegral>(CE2->getOperand(i)))
if (isa<ConstantInt>(CE2->getOperand(i)))
return isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
else
return ICmpInst::BAD_ICMP_PREDICATE; // Might be equal.
@@ -1049,34 +1044,35 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C2))
if (!GV->hasExternalWeakLinkage()) // External weak GV can be null
if (pred == ICmpInst::ICMP_EQ)
return ConstantBool::getFalse();
return ConstantInt::getFalse();
else if (pred == ICmpInst::ICMP_NE)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
// icmp eq/ne(GV,null) -> false/true
} else if (C2->isNullValue()) {
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C1))
if (!GV->hasExternalWeakLinkage()) // External weak GV can be null
if (pred == ICmpInst::ICMP_EQ)
return ConstantBool::getFalse();
return ConstantInt::getFalse();
else if (pred == ICmpInst::ICMP_NE)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
}
if (isa<ConstantBool>(C1) && isa<ConstantBool>(C2)) {
bool C1Val = cast<ConstantBool>(C1)->getValue();
bool C2Val = cast<ConstantBool>(C2)->getValue();
if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2) &&
C1->getType() == Type::BoolTy && C2->getType() == Type::BoolTy) {
bool C1Val = cast<ConstantInt>(C1)->getBoolValue();
bool C2Val = cast<ConstantInt>(C2)->getBoolValue();
switch (pred) {
default: assert(0 && "Invalid ICmp Predicate"); return 0;
case ICmpInst::ICMP_EQ: return ConstantBool::get(C1Val == C2Val);
case ICmpInst::ICMP_NE: return ConstantBool::get(C1Val != C2Val);
case ICmpInst::ICMP_ULT:return ConstantBool::get(C1Val < C2Val);
case ICmpInst::ICMP_UGT:return ConstantBool::get(C1Val > C2Val);
case ICmpInst::ICMP_ULE:return ConstantBool::get(C1Val <= C2Val);
case ICmpInst::ICMP_UGE:return ConstantBool::get(C1Val >= C2Val);
case ICmpInst::ICMP_SLT:return ConstantBool::get(C1Val < C2Val);
case ICmpInst::ICMP_SGT:return ConstantBool::get(C1Val > C2Val);
case ICmpInst::ICMP_SLE:return ConstantBool::get(C1Val <= C2Val);
case ICmpInst::ICMP_SGE:return ConstantBool::get(C1Val >= C2Val);
case ICmpInst::ICMP_EQ: return ConstantInt::get(C1Val == C2Val);
case ICmpInst::ICMP_NE: return ConstantInt::get(C1Val != C2Val);
case ICmpInst::ICMP_ULT:return ConstantInt::get(C1Val < C2Val);
case ICmpInst::ICMP_UGT:return ConstantInt::get(C1Val > C2Val);
case ICmpInst::ICMP_ULE:return ConstantInt::get(C1Val <= C2Val);
case ICmpInst::ICMP_UGE:return ConstantInt::get(C1Val >= C2Val);
case ICmpInst::ICMP_SLT:return ConstantInt::get(C1Val < C2Val);
case ICmpInst::ICMP_SGT:return ConstantInt::get(C1Val > C2Val);
case ICmpInst::ICMP_SLE:return ConstantInt::get(C1Val <= C2Val);
case ICmpInst::ICMP_SGE:return ConstantInt::get(C1Val >= C2Val);
}
} else if (isa<ConstantInt>(C1) && isa<ConstantInt>(C2)) {
if (ICmpInst::isSignedPredicate(ICmpInst::Predicate(pred))) {
@@ -1084,22 +1080,22 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
int64_t V2 = cast<ConstantInt>(C2)->getSExtValue();
switch (pred) {
default: assert(0 && "Invalid ICmp Predicate"); return 0;
case ICmpInst::ICMP_SLT:return ConstantBool::get(V1 < V2);
case ICmpInst::ICMP_SGT:return ConstantBool::get(V1 > V2);
case ICmpInst::ICMP_SLE:return ConstantBool::get(V1 <= V2);
case ICmpInst::ICMP_SGE:return ConstantBool::get(V1 >= V2);
case ICmpInst::ICMP_SLT:return ConstantInt::get(V1 < V2);
case ICmpInst::ICMP_SGT:return ConstantInt::get(V1 > V2);
case ICmpInst::ICMP_SLE:return ConstantInt::get(V1 <= V2);
case ICmpInst::ICMP_SGE:return ConstantInt::get(V1 >= V2);
}
} else {
uint64_t V1 = cast<ConstantInt>(C1)->getZExtValue();
uint64_t V2 = cast<ConstantInt>(C2)->getZExtValue();
switch (pred) {
default: assert(0 && "Invalid ICmp Predicate"); return 0;
case ICmpInst::ICMP_EQ: return ConstantBool::get(V1 == V2);
case ICmpInst::ICMP_NE: return ConstantBool::get(V1 != V2);
case ICmpInst::ICMP_ULT:return ConstantBool::get(V1 < V2);
case ICmpInst::ICMP_UGT:return ConstantBool::get(V1 > V2);
case ICmpInst::ICMP_ULE:return ConstantBool::get(V1 <= V2);
case ICmpInst::ICMP_UGE:return ConstantBool::get(V1 >= V2);
case ICmpInst::ICMP_EQ: return ConstantInt::get(V1 == V2);
case ICmpInst::ICMP_NE: return ConstantInt::get(V1 != V2);
case ICmpInst::ICMP_ULT:return ConstantInt::get(V1 < V2);
case ICmpInst::ICMP_UGT:return ConstantInt::get(V1 > V2);
case ICmpInst::ICMP_ULE:return ConstantInt::get(V1 <= V2);
case ICmpInst::ICMP_UGE:return ConstantInt::get(V1 >= V2);
}
}
} else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
@@ -1107,42 +1103,42 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
double C2Val = cast<ConstantFP>(C2)->getValue();
switch (pred) {
default: assert(0 && "Invalid FCmp Predicate"); return 0;
case FCmpInst::FCMP_FALSE: return ConstantBool::getFalse();
case FCmpInst::FCMP_TRUE: return ConstantBool::getTrue();
case FCmpInst::FCMP_FALSE: return ConstantInt::getFalse();
case FCmpInst::FCMP_TRUE: return ConstantInt::getTrue();
case FCmpInst::FCMP_UNO:
return ConstantBool::get(C1Val != C1Val || C2Val != C2Val);
return ConstantInt::get(C1Val != C1Val || C2Val != C2Val);
case FCmpInst::FCMP_ORD:
return ConstantBool::get(C1Val == C1Val && C2Val == C2Val);
return ConstantInt::get(C1Val == C1Val && C2Val == C2Val);
case FCmpInst::FCMP_UEQ:
if (C1Val != C1Val || C2Val != C2Val)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
/* FALL THROUGH */
case FCmpInst::FCMP_OEQ: return ConstantBool::get(C1Val == C2Val);
case FCmpInst::FCMP_OEQ: return ConstantInt::get(C1Val == C2Val);
case FCmpInst::FCMP_UNE:
if (C1Val != C1Val || C2Val != C2Val)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
/* FALL THROUGH */
case FCmpInst::FCMP_ONE: return ConstantBool::get(C1Val != C2Val);
case FCmpInst::FCMP_ONE: return ConstantInt::get(C1Val != C2Val);
case FCmpInst::FCMP_ULT:
if (C1Val != C1Val || C2Val != C2Val)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
/* FALL THROUGH */
case FCmpInst::FCMP_OLT: return ConstantBool::get(C1Val < C2Val);
case FCmpInst::FCMP_OLT: return ConstantInt::get(C1Val < C2Val);
case FCmpInst::FCMP_UGT:
if (C1Val != C1Val || C2Val != C2Val)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
/* FALL THROUGH */
case FCmpInst::FCMP_OGT: return ConstantBool::get(C1Val > C2Val);
case FCmpInst::FCMP_OGT: return ConstantInt::get(C1Val > C2Val);
case FCmpInst::FCMP_ULE:
if (C1Val != C1Val || C2Val != C2Val)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
/* FALL THROUGH */
case FCmpInst::FCMP_OLE: return ConstantBool::get(C1Val <= C2Val);
case FCmpInst::FCMP_OLE: return ConstantInt::get(C1Val <= C2Val);
case FCmpInst::FCMP_UGE:
if (C1Val != C1Val || C2Val != C2Val)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
/* FALL THROUGH */
case FCmpInst::FCMP_OGE: return ConstantBool::get(C1Val >= C2Val);
case FCmpInst::FCMP_OGE: return ConstantInt::get(C1Val >= C2Val);
}
} else if (const ConstantPacked *CP1 = dyn_cast<ConstantPacked>(C1)) {
if (const ConstantPacked *CP2 = dyn_cast<ConstantPacked>(C2)) {
@@ -1151,7 +1147,7 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
Constant *C= ConstantExpr::getFCmp(FCmpInst::FCMP_OEQ,
const_cast<Constant*>(CP1->getOperand(i)),
const_cast<Constant*>(CP2->getOperand(i)));
if (ConstantBool *CB = dyn_cast<ConstantBool>(C))
if (ConstantInt *CB = dyn_cast<ConstantInt>(C))
return CB;
}
// Otherwise, could not decide from any element pairs.
@@ -1161,7 +1157,7 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
Constant *C = ConstantExpr::getICmp(ICmpInst::ICMP_EQ,
const_cast<Constant*>(CP1->getOperand(i)),
const_cast<Constant*>(CP2->getOperand(i)));
if (ConstantBool *CB = dyn_cast<ConstantBool>(C))
if (ConstantInt *CB = dyn_cast<ConstantInt>(C))
return CB;
}
// Otherwise, could not decide from any element pairs.
@@ -1186,40 +1182,40 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
case FCmpInst::BAD_FCMP_PREDICATE:
break; // Couldn't determine anything about these constants.
case FCmpInst::FCMP_OEQ: // We know that C1 == C2
return ConstantBool::get(
return ConstantInt::get(
pred == FCmpInst::FCMP_UEQ || pred == FCmpInst::FCMP_OEQ ||
pred == FCmpInst::FCMP_ULE || pred == FCmpInst::FCMP_OLE ||
pred == FCmpInst::FCMP_UGE || pred == FCmpInst::FCMP_OGE);
case FCmpInst::FCMP_OLT: // We know that C1 < C2
return ConstantBool::get(
return ConstantInt::get(
pred == FCmpInst::FCMP_UNE || pred == FCmpInst::FCMP_ONE ||
pred == FCmpInst::FCMP_ULT || pred == FCmpInst::FCMP_OLT ||
pred == FCmpInst::FCMP_ULE || pred == FCmpInst::FCMP_OLE);
case FCmpInst::FCMP_OGT: // We know that C1 > C2
return ConstantBool::get(
return ConstantInt::get(
pred == FCmpInst::FCMP_UNE || pred == FCmpInst::FCMP_ONE ||
pred == FCmpInst::FCMP_UGT || pred == FCmpInst::FCMP_OGT ||
pred == FCmpInst::FCMP_UGE || pred == FCmpInst::FCMP_OGE);
case FCmpInst::FCMP_OLE: // We know that C1 <= C2
// We can only partially decide this relation.
if (pred == FCmpInst::FCMP_UGT || pred == FCmpInst::FCMP_OGT)
return ConstantBool::getFalse();
return ConstantInt::getFalse();
if (pred == FCmpInst::FCMP_ULT || pred == FCmpInst::FCMP_OLT)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
break;
case FCmpInst::FCMP_OGE: // We known that C1 >= C2
// We can only partially decide this relation.
if (pred == FCmpInst::FCMP_ULT || pred == FCmpInst::FCMP_OLT)
return ConstantBool::getFalse();
return ConstantInt::getFalse();
if (pred == FCmpInst::FCMP_UGT || pred == FCmpInst::FCMP_OGT)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
break;
case ICmpInst::ICMP_NE: // We know that C1 != C2
// We can only partially decide this relation.
if (pred == FCmpInst::FCMP_OEQ || pred == FCmpInst::FCMP_UEQ)
return ConstantBool::getFalse();
return ConstantInt::getFalse();
if (pred == FCmpInst::FCMP_ONE || pred == FCmpInst::FCMP_UNE)
return ConstantBool::getTrue();
return ConstantInt::getTrue();
break;
}
} else {
@@ -1231,61 +1227,61 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
case ICmpInst::ICMP_EQ: // We know the constants are equal!
// If we know the constants are equal, we can decide the result of this
// computation precisely.
return ConstantBool::get(pred == ICmpInst::ICMP_EQ ||
pred == ICmpInst::ICMP_ULE ||
pred == ICmpInst::ICMP_SLE ||
pred == ICmpInst::ICMP_UGE ||
pred == ICmpInst::ICMP_SGE);
return ConstantInt::get(pred == ICmpInst::ICMP_EQ ||
pred == ICmpInst::ICMP_ULE ||
pred == ICmpInst::ICMP_SLE ||
pred == ICmpInst::ICMP_UGE ||
pred == ICmpInst::ICMP_SGE);
case ICmpInst::ICMP_ULT:
// If we know that C1 < C2, we can decide the result of this computation
// precisely.
return ConstantBool::get(pred == ICmpInst::ICMP_ULT ||
pred == ICmpInst::ICMP_NE ||
pred == ICmpInst::ICMP_ULE);
return ConstantInt::get(pred == ICmpInst::ICMP_ULT ||
pred == ICmpInst::ICMP_NE ||
pred == ICmpInst::ICMP_ULE);
case ICmpInst::ICMP_SLT:
// If we know that C1 < C2, we can decide the result of this computation
// precisely.
return ConstantBool::get(pred == ICmpInst::ICMP_SLT ||
pred == ICmpInst::ICMP_NE ||
pred == ICmpInst::ICMP_SLE);
return ConstantInt::get(pred == ICmpInst::ICMP_SLT ||
pred == ICmpInst::ICMP_NE ||
pred == ICmpInst::ICMP_SLE);
case ICmpInst::ICMP_UGT:
// If we know that C1 > C2, we can decide the result of this computation
// precisely.
return ConstantBool::get(pred == ICmpInst::ICMP_UGT ||
pred == ICmpInst::ICMP_NE ||
pred == ICmpInst::ICMP_UGE);
return ConstantInt::get(pred == ICmpInst::ICMP_UGT ||
pred == ICmpInst::ICMP_NE ||
pred == ICmpInst::ICMP_UGE);
case ICmpInst::ICMP_SGT:
// If we know that C1 > C2, we can decide the result of this computation
// precisely.
return ConstantBool::get(pred == ICmpInst::ICMP_SGT ||
pred == ICmpInst::ICMP_NE ||
pred == ICmpInst::ICMP_SGE);
return ConstantInt::get(pred == ICmpInst::ICMP_SGT ||
pred == ICmpInst::ICMP_NE ||
pred == ICmpInst::ICMP_SGE);
case ICmpInst::ICMP_ULE:
// If we know that C1 <= C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_UGT) return ConstantBool::getFalse();
if (pred == ICmpInst::ICMP_ULT) return ConstantBool::getTrue();
if (pred == ICmpInst::ICMP_UGT) return ConstantInt::getFalse();
if (pred == ICmpInst::ICMP_ULT) return ConstantInt::getTrue();
break;
case ICmpInst::ICMP_SLE:
// If we know that C1 <= C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_SGT) return ConstantBool::getFalse();
if (pred == ICmpInst::ICMP_SLT) return ConstantBool::getTrue();
if (pred == ICmpInst::ICMP_SGT) return ConstantInt::getFalse();
if (pred == ICmpInst::ICMP_SLT) return ConstantInt::getTrue();
break;
case ICmpInst::ICMP_UGE:
// If we know that C1 >= C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_ULT) return ConstantBool::getFalse();
if (pred == ICmpInst::ICMP_UGT) return ConstantBool::getTrue();
if (pred == ICmpInst::ICMP_ULT) return ConstantInt::getFalse();
if (pred == ICmpInst::ICMP_UGT) return ConstantInt::getTrue();
break;
case ICmpInst::ICMP_SGE:
// If we know that C1 >= C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_SLT) return ConstantBool::getFalse();
if (pred == ICmpInst::ICMP_SGT) return ConstantBool::getTrue();
if (pred == ICmpInst::ICMP_SLT) return ConstantInt::getFalse();
if (pred == ICmpInst::ICMP_SGT) return ConstantInt::getTrue();
break;
case ICmpInst::ICMP_NE:
// If we know that C1 != C2, we can only partially decide this relation.
if (pred == ICmpInst::ICMP_EQ) return ConstantBool::getFalse();
if (pred == ICmpInst::ICMP_NE) return ConstantBool::getTrue();
if (pred == ICmpInst::ICMP_EQ) return ConstantInt::getFalse();
if (pred == ICmpInst::ICMP_NE) return ConstantInt::getTrue();
break;
}
+12 -31
View File
@@ -93,7 +93,7 @@ bool Constant::canTrap() const {
Constant *Constant::getNullValue(const Type *Ty) {
switch (Ty->getTypeID()) {
case Type::BoolTyID: {
static Constant *NullBool = ConstantBool::get(false);
static Constant *NullBool = ConstantInt::get(false);
return NullBool;
}
case Type::Int8TyID: {
@@ -135,9 +135,9 @@ Constant *Constant::getNullValue(const Type *Ty) {
// Static constructor to create an integral constant with all bits set
ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) {
ConstantInt *ConstantInt::getAllOnesValue(const Type *Ty) {
switch (Ty->getTypeID()) {
case Type::BoolTyID: return ConstantBool::getTrue();
case Type::BoolTyID: return ConstantInt::getTrue();
case Type::Int8TyID:
case Type::Int16TyID:
case Type::Int32TyID:
@@ -152,7 +152,7 @@ ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) {
ConstantPacked *ConstantPacked::getAllOnesValue(const PackedType *Ty) {
std::vector<Constant*> Elts;
Elts.resize(Ty->getNumElements(),
ConstantIntegral::getAllOnesValue(Ty->getElementType()));
ConstantInt::getAllOnesValue(Ty->getElementType()));
assert(Elts[0] && "Not a packed integer type!");
return cast<ConstantPacked>(ConstantPacked::get(Elts));
}
@@ -165,16 +165,12 @@ ConstantPacked *ConstantPacked::getAllOnesValue(const PackedType *Ty) {
//===----------------------------------------------------------------------===//
// Normal Constructors
ConstantIntegral::ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V)
: Constant(Ty, VT, 0, 0), Val(V) {
}
ConstantBool::ConstantBool(bool V)
: ConstantIntegral(Type::BoolTy, ConstantBoolVal, uint64_t(V)) {
ConstantInt::ConstantInt(bool V)
: Constant(Type::BoolTy, ConstantIntVal, 0, 0), Val(uint64_t(V)) {
}
ConstantInt::ConstantInt(const Type *Ty, uint64_t V)
: ConstantIntegral(Ty, ConstantIntVal, V) {
: Constant(Ty, ConstantIntVal, 0, 0), Val(Ty == Type::BoolTy ? bool(V) : V) {
}
ConstantFP::ConstantFP(const Type *Ty, double V)
@@ -383,9 +379,9 @@ Constant *ConstantExpr::getNeg(Constant *C) {
return get(Instruction::Sub, ConstantFP::get(C->getType(), -0.0), C);
}
Constant *ConstantExpr::getNot(Constant *C) {
assert(isa<ConstantIntegral>(C) && "Cannot NOT a nonintegral type!");
assert(isa<ConstantInt>(C) && "Cannot NOT a nonintegral type!");
return get(Instruction::Xor, C,
ConstantIntegral::getAllOnesValue(C->getType()));
ConstantInt::getAllOnesValue(C->getType()));
}
Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2) {
return get(Instruction::Add, C1, C2);
@@ -555,6 +551,7 @@ getWithOperands(const std::vector<Constant*> &Ops) const {
bool ConstantInt::isValueValidForType(const Type *Ty, uint64_t Val) {
switch (Ty->getTypeID()) {
default: return false; // These can't be represented as integers!
case Type::BoolTyID: return Val == 0 || Val == 1;
case Type::Int8TyID: return Val <= UINT8_MAX;
case Type::Int16TyID: return Val <= UINT16_MAX;
case Type::Int32TyID: return Val <= UINT32_MAX;
@@ -565,6 +562,7 @@ bool ConstantInt::isValueValidForType(const Type *Ty, uint64_t Val) {
bool ConstantInt::isValueValidForType(const Type *Ty, int64_t Val) {
switch (Ty->getTypeID()) {
default: return false; // These can't be represented as integers!
case Type::BoolTyID: return (Val == 0 || Val == 1);
case Type::Int8TyID: return (Val >= INT8_MIN && Val <= INT8_MAX);
case Type::Int16TyID: return (Val >= INT16_MIN && Val <= UINT16_MAX);
case Type::Int32TyID: return (Val >= INT32_MIN && Val <= UINT32_MAX);
@@ -830,19 +828,6 @@ public:
}
//---- ConstantBool::get*() implementation.
ConstantBool *ConstantBool::getTrue() {
static ConstantBool *T = 0;
if (T) return T;
return T = new ConstantBool(true);
}
ConstantBool *ConstantBool::getFalse() {
static ConstantBool *F = 0;
if (F) return F;
return F = new ConstantBool(false);
}
//---- ConstantInt::get() implementations...
//
static ManagedStatic<ValueMap<uint64_t, Type, ConstantInt> > IntConstants;
@@ -853,11 +838,7 @@ static ManagedStatic<ValueMap<uint64_t, Type, ConstantInt> > 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) {
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);
if (Ty == Type::BoolTy) return ConstantInt::get(V&1);
return IntConstants->getOrCreate(Ty, V & Ty->getIntegralTypeMask());
}
+5 -5
View File
@@ -1118,10 +1118,10 @@ BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
Instruction *InsertBefore) {
Constant *C;
if (const PackedType *PTy = dyn_cast<PackedType>(Op->getType())) {
C = ConstantIntegral::getAllOnesValue(PTy->getElementType());
C = ConstantInt::getAllOnesValue(PTy->getElementType());
C = ConstantPacked::get(std::vector<Constant*>(PTy->getNumElements(), C));
} else {
C = ConstantIntegral::getAllOnesValue(Op->getType());
C = ConstantInt::getAllOnesValue(Op->getType());
}
return new BinaryOperator(Instruction::Xor, Op, C,
@@ -1133,11 +1133,11 @@ BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
Constant *AllOnes;
if (const PackedType *PTy = dyn_cast<PackedType>(Op->getType())) {
// Create a vector of all ones values.
Constant *Elt = ConstantIntegral::getAllOnesValue(PTy->getElementType());
Constant *Elt = ConstantInt::getAllOnesValue(PTy->getElementType());
AllOnes =
ConstantPacked::get(std::vector<Constant*>(PTy->getNumElements(), Elt));
} else {
AllOnes = ConstantIntegral::getAllOnesValue(Op->getType());
AllOnes = ConstantInt::getAllOnesValue(Op->getType());
}
return new BinaryOperator(Instruction::Xor, Op, AllOnes,
@@ -1147,7 +1147,7 @@ BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
// isConstantAllOnes - Helper function for several functions below
static inline bool isConstantAllOnes(const Value *V) {
return isa<ConstantIntegral>(V) &&cast<ConstantIntegral>(V)->isAllOnesValue();
return isa<ConstantInt>(V) &&cast<ConstantInt>(V)->isAllOnesValue();
}
bool BinaryOperator::isNeg(const Value *V) {
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -333,7 +333,7 @@
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
#line 802 "/proj/llvm/llvm-3/tools/llvm-upgrade/UpgradeParser.y"
#line 802 "/developer/zsth/llvm-gcc-dev/HEAD/llvm/llvm/tools/llvm-upgrade/UpgradeParser.y"
typedef union YYSTYPE {
std::string* String;
const TypeInfo* Type;
+7 -6
View File
@@ -668,12 +668,13 @@ void CppWriter::printConstant(const Constant *CV) {
// Skip variables and functions, we emit them elsewhere
return;
}
if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
Out << "ConstantBool* " << constName << " = ConstantBool::get("
<< (CB->getValue() ? "true" : "false") << ");";
} else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Out << "ConstantInt* " << constName << " = ConstantInt::get("
<< typeName << ", " << CI->getZExtValue() << ");";
if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
if (CI->getType() == Type::BoolTy)
Out << "ConstantInt* " << constName << " = ConstantInt::get("
<< (CI->getBoolValue() ? "true" : "false") << ");";
else
Out << "ConstantInt* " << constName << " = ConstantInt::get("
<< typeName << ", " << CI->getZExtValue() << ");";
} else if (isa<ConstantAggregateZero>(CV)) {
Out << "ConstantAggregateZero* " << constName
<< " = ConstantAggregateZero::get(" << typeName << ");";