From: Chris Lattner Date: Thu, 7 Apr 2005 16:28:01 +0000 (+0000) Subject: Implement InstCombine/add.ll:test28, transforming C1-(X+C2) --> (C1-C2)-X. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=08954a26e4b1f54a9552b34f81cf6e570fefa67d;p=oota-llvm.git Implement InstCombine/add.ll:test28, transforming C1-(X+C2) --> (C1-C2)-X. This occurs several dozen times in specint2k, particularly in crafty and gcc apparently. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21136 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 9e40dc3239f..c1eb3ebe45f 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -795,10 +795,16 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { if (BinaryOperator *Op1I = dyn_cast(Op1)) { if (Op1I->getOpcode() == Instruction::Add && !Op0->getType()->isFloatingPoint()) { - if (Op1I->getOperand(0) == Op0) // X-(X+Y) == -Y + if (Op1I->getOperand(0) == Op0) // X-(X+Y) == -Y return BinaryOperator::createNeg(Op1I->getOperand(1), I.getName()); - else if (Op1I->getOperand(1) == Op0) // X-(Y+X) == -Y + else if (Op1I->getOperand(1) == Op0) // X-(Y+X) == -Y return BinaryOperator::createNeg(Op1I->getOperand(0), I.getName()); + else if (ConstantInt *CI1 = dyn_cast(I.getOperand(0))) { + if (ConstantInt *CI2 = dyn_cast(Op1I->getOperand(1))) + // C1-(X+C2) --> (C1-C2)-X + return BinaryOperator::createSub(ConstantExpr::getSub(CI1, CI2), + Op1I->getOperand(0)); + } } if (Op1I->hasOneUse()) {