summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-04-07 16:28:01 +0000
committerChris Lattner <sabre@nondot.org>2005-04-07 16:28:01 +0000
commitc7f3c1a00e2769535bb1f6bf1d238723109e70ff (patch)
tree1ee037670a427c287b472a0dee4aa16cf148d0ab /llvm/lib/Transforms
parentdd83183c1e365a8a0641b75289f86c0f1fcfd49f (diff)
downloadbcm5719-llvm-c7f3c1a00e2769535bb1f6bf1d238723109e70ff.tar.gz
bcm5719-llvm-c7f3c1a00e2769535bb1f6bf1d238723109e70ff.zip
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
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp10
1 files changed, 8 insertions, 2 deletions
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<BinaryOperator>(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<ConstantInt>(I.getOperand(0))) {
+ if (ConstantInt *CI2 = dyn_cast<ConstantInt>(Op1I->getOperand(1)))
+ // C1-(X+C2) --> (C1-C2)-X
+ return BinaryOperator::createSub(ConstantExpr::getSub(CI1, CI2),
+ Op1I->getOperand(0));
+ }
}
if (Op1I->hasOneUse()) {
OpenPOWER on IntegriCloud