aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorZhou Sheng <zhousheng00@gmail.com>2007-01-11 12:24:14 +0000
committerZhou Sheng <zhousheng00@gmail.com>2007-01-11 12:24:14 +0000
commit6b6b6ef1677fa71b1072c2911b4c1f9524a558c9 (patch)
tree480ecf010ac5facd1bc29ab57441253691bb42d6 /lib/Transforms/Scalar
parent057809ac1c78c3456e8f1481330fa2bcd2b85029 (diff)
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
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r--lib/Transforms/Scalar/CondPropagate.cpp5
-rw-r--r--lib/Transforms/Scalar/CorrelatedExprs.cpp156
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp218
-rw-r--r--lib/Transforms/Scalar/LoopUnswitch.cpp64
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp57
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp4
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp22
7 files changed, 269 insertions, 257 deletions
diff --git a/lib/Transforms/Scalar/CondPropagate.cpp b/lib/Transforms/Scalar/CondPropagate.cpp
index 49a849625b..4ca5c5e7b7 100644
--- a/lib/Transforms/Scalar/CondPropagate.cpp
+++ b/lib/Transforms/Scalar/CondPropagate.cpp
@@ -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
diff --git a/lib/Transforms/Scalar/CorrelatedExprs.cpp b/lib/Transforms/Scalar/CorrelatedExprs.cpp
index 203b7fa238..44d3ad5cc2 100644
--- a/lib/Transforms/Scalar/CorrelatedExprs.cpp
+++ b/lib/Transforms/Scalar/CorrelatedExprs.cpp
@@ -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 (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 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 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);
-
- } 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);
+ // 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();
+
+ 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(),
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index c8b38b8603..e82f373801 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -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-