From c7f3c1a00e2769535bb1f6bf1d238723109e70ff Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 7 Apr 2005 16:28:01 +0000 Subject: 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. llvm-svn: 21136 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 9e40dc3239f..c1eb3ebe45f 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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()) { -- cgit v1.2.3