[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Nov 4 19:07:01 PST 2003
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.139 -> 1.140
---
Log message:
Fix bug with previous implementation:
- // ~(c-X) == X-(c-1) == X+(-c+1)
+ // ~(c-X) == X-c-1 == X+(-c-1)
Implement: C - ~X == X + (1+C)
---
Diffs of the changes: (+11 -4)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.139 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.140
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.139 Tue Nov 4 17:50:51 2003
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Nov 4 19:06:05 2003
@@ -488,11 +488,18 @@
if (Value *V = dyn_castNegVal(Op1))
return BinaryOperator::create(Instruction::Add, Op0, V);
- // Replace (-1 - A) with (~A)...
- if (ConstantInt *C = dyn_cast<ConstantInt>(Op0))
+ if (ConstantInt *C = dyn_cast<ConstantInt>(Op0)) {
+ // Replace (-1 - A) with (~A)...
if (C->isAllOnesValue())
return BinaryOperator::createNot(Op1);
+ // C - ~X == X + (1+C)
+ if (BinaryOperator::isNot(Op1))
+ return BinaryOperator::create(Instruction::Add,
+ BinaryOperator::getNotArgument(cast<BinaryOperator>(Op1)),
+ *C + *ConstantInt::get(I.getType(), 1));
+ }
+
if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1))
if (Op1I->hasOneUse()) {
// Replace (x - (y - z)) with (x + (z - y)) if the (y - z) subexpression
@@ -1001,10 +1008,10 @@
return new SetCondInst(SCI->getInverseCondition(),
SCI->getOperand(0), SCI->getOperand(1));
- // ~(c-X) == X-(c-1) == X+(-c+1)
+ // ~(c-X) == X-c-1 == X+(-c-1)
if (Op0I->getOpcode() == Instruction::Sub && RHS->isAllOnesValue() &&
isa<Constant>(Op0I->getOperand(0))) {
- Constant *ConstantRHS = *-*cast<Constant>(Op0I->getOperand(0)) +
+ Constant *ConstantRHS = *-*cast<Constant>(Op0I->getOperand(0)) -
*ConstantInt::get(I.getType(), 1);
return BinaryOperator::create(Instruction::Add, Op0I->getOperand(1),
ConstantRHS);
More information about the llvm-commits
mailing list