summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-25 19:55:33 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-25 19:55:33 +0000
commit624766f8a2d271205bdc931d9cf5f3ebb59d88f9 (patch)
treea245c0164dfae1911f33e7ec51bfd5f19e0e6d9d /llvm/lib
parent7037826c869384263775f136aecb16ffb9dcdaba (diff)
downloadbcm5719-llvm-624766f8a2d271205bdc931d9cf5f3ebb59d88f9.tar.gz
bcm5719-llvm-624766f8a2d271205bdc931d9cf5f3ebb59d88f9.zip
Some cleanup from review:
* Don't assume shift amounts are <= 64 bits * Avoid creating an extra APInt in SubOne and AddOne by using -- and ++ * Add another use of getLowBitsSet * Convert a series of if statements to a switch llvm-svn: 35339
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 1884e30de9e..c1a0fefccfc 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -540,9 +540,8 @@ static inline Value *dyn_castFoldableMul(Value *V, ConstantInt *&CST) {
if (I->getOpcode() == Instruction::Shl)
if ((CST = dyn_cast<ConstantInt>(I->getOperand(1)))) {
// The multiplier is really 1 << CST.
- APInt Multiplier(V->getType()->getPrimitiveSizeInBits(), 0);
- Multiplier.set(CST->getZExtValue()); // set bit is == 1 << CST
- CST = ConstantInt::get(Multiplier);
+ Constant *One = ConstantInt::get(V->getType(), 1);
+ CST = cast<ConstantInt>(ConstantExpr::getShl(One, CST));
return I->getOperand(0);
}
}
@@ -561,13 +560,13 @@ static User *dyn_castGetElementPtr(Value *V) {
/// AddOne - Add one to a ConstantInt
static ConstantInt *AddOne(ConstantInt *C) {
- APInt One(C->getType()->getPrimitiveSizeInBits(),1);
- return ConstantInt::get(C->getValue() + One);
+ APInt Val(C->getValue());
+ return ConstantInt::get(++Val);
}
/// SubOne - Subtract one from a ConstantInt
static ConstantInt *SubOne(ConstantInt *C) {
- APInt One(C->getType()->getPrimitiveSizeInBits(),1);
- return ConstantInt::get(C->getValue() - One);
+ APInt Val(C->getValue());
+ return ConstantInt::get(--Val);
}
/// Add - Add two ConstantInts together
static ConstantInt *Add(ConstantInt *C1, ConstantInt *C2) {
@@ -752,7 +751,7 @@ static void ComputeMaskedBits(Value *V, const APInt& Mask, APInt& KnownZero,
assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?");
KnownZero <<= ShiftAmt;
KnownOne <<= ShiftAmt;
- KnownZero |= APInt(BitWidth, 1ULL).shl(ShiftAmt)-1; // low bits known 0
+ KnownZero |= APInt::getLowBitsSet(BitWidth, ShiftAmt); // low bits known 0
return;
}
break;
@@ -4654,14 +4653,17 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// appropriate icmp lt or icmp gt instruction. Since the border cases have
// already been handled above, this requires little checking.
//
- if (I.getPredicate() == ICmpInst::ICMP_ULE)
- return new ICmpInst(ICmpInst::ICMP_ULT, Op0, AddOne(CI));
- if (I.getPredicate() == ICmpInst::ICMP_SLE)
- return new ICmpInst(ICmpInst::ICMP_SLT, Op0, AddOne(CI));
- if (I.getPredicate() == ICmpInst::ICMP_UGE)
- return new ICmpInst( ICmpInst::ICMP_UGT, Op0, SubOne(CI));
- if (I.getPredicate() == ICmpInst::ICMP_SGE)
- return new ICmpInst(ICmpInst::ICMP_SGT, Op0, SubOne(CI));
+ switch (I.getPredicate()) {
+ default: break;
+ case ICmpInst::ICMP_ULE:
+ return new ICmpInst(ICmpInst::ICMP_ULT, Op0, AddOne(CI));
+ case ICmpInst::ICMP_SLE:
+ return new ICmpInst(ICmpInst::ICMP_SLT, Op0, AddOne(CI));
+ case ICmpInst::ICMP_UGE:
+ return new ICmpInst( ICmpInst::ICMP_UGT, Op0, SubOne(CI));
+ case ICmpInst::ICMP_SGE:
+ return new ICmpInst(ICmpInst::ICMP_SGT, Op0, SubOne(CI));
+ }
// See if we can fold the comparison based on bits known to be zero or one
// in the input.
OpenPOWER on IntegriCloud