summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-11-05 01:06:05 +0000
committerChris Lattner <sabre@nondot.org>2003-11-05 01:06:05 +0000
commit8f2f598024797107e29785ccda5d7d3dbc61616a (patch)
tree604e6c79d3bc4983a81d7a8445fa5b3e04be70b7
parentb6ca46e0f9e57a6d82a0b64dab76c8d641b7a303 (diff)
downloadbcm5719-llvm-8f2f598024797107e29785ccda5d7d3dbc61616a.tar.gz
bcm5719-llvm-8f2f598024797107e29785ccda5d7d3dbc61616a.zip
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) llvm-svn: 9715
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index dafd7568f8a..4a5f1fbcfc3 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -488,11 +488,18 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
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 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
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);
OpenPOWER on IntegriCloud