From 2149a9dfec7df41c6f9a2a221fe7751a2f8c1ada Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Sun, 25 Mar 2007 19:55:33 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35339 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/InstructionCombining.cpp | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 1884e30de9e..c1a0fefccfc 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/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(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(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.