Minor efficiency tweak, suggested by Patrick Meredith

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13341 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2004-05-04 15:19:33 +00:00
parent 96e68f9ab1
commit 32ed46b36e

View File

@ -12,10 +12,10 @@
// simplification happens. // simplification happens.
// //
// This pass combines things like: // This pass combines things like:
// %Y = add int 1, %X // %Y = add int %X, 1
// %Z = add int 1, %Y // %Z = add int %Y, 1
// into: // into:
// %Z = add int 2, %X // %Z = add int %X, 2
// //
// This is a simple worklist driven algorithm. // This is a simple worklist driven algorithm.
// //
@ -887,7 +887,7 @@ Instruction *InstCombiner::visitRem(BinaryOperator &I) {
// if so, convert to a bitwise and. // if so, convert to a bitwise and.
if (ConstantUInt *C = dyn_cast<ConstantUInt>(RHS)) if (ConstantUInt *C = dyn_cast<ConstantUInt>(RHS))
if (uint64_t Val = C->getValue()) // Don't break X % 0 (divide by zero) if (uint64_t Val = C->getValue()) // Don't break X % 0 (divide by zero)
if (Log2(Val)) if (!(Val & Val-1)) // Power of 2
return BinaryOperator::create(Instruction::And, I.getOperand(0), return BinaryOperator::create(Instruction::And, I.getOperand(0),
ConstantUInt::get(I.getType(), Val-1)); ConstantUInt::get(I.getType(), Val-1));
} }