[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Reid Spencer
reid at x10sys.com
Sun Mar 25 12:55:51 PDT 2007
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.688 -> 1.689
---
Log message:
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
---
Diffs of the changes: (+18 -16)
InstructionCombining.cpp | 34 ++++++++++++++++++----------------
1 files changed, 18 insertions(+), 16 deletions(-)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.688 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.689
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.688 Sun Mar 25 00:33:51 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Mar 25 14:55:33 2007
@@ -540,9 +540,8 @@
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 @@
/// 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 @@
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 @@
// 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.
More information about the llvm-commits
mailing list