aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-09 01:29:19 +0000
committerChris Lattner <sabre@nondot.org>2002-05-09 01:29:19 +0000
commit403717156bc185f545cd343ad3524ded927fc394 (patch)
treef54b794ee8cebf5c4c0f0af5d97e59b2359ce1a3 /lib/Transforms/Scalar
parent8c7333e17c5e2214a99d24596d8f41cb9e392183 (diff)
downloadexternal_llvm-403717156bc185f545cd343ad3524ded927fc394.zip
external_llvm-403717156bc185f545cd343ad3524ded927fc394.tar.gz
external_llvm-403717156bc185f545cd343ad3524ded927fc394.tar.bz2
Add ability to transform (x - (y - z)) into (x + (z - y))
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2566 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index a77bcb9..9625398 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -180,6 +180,19 @@ Instruction *InstCombiner::visitSub(BinaryOperator *I) {
if (Value *V = dyn_castNegInst(Op1))
return BinaryOperator::create(Instruction::Add, Op0, V);
+ // Replace (x - (y - z)) with (x + (z - y)) if the (y - z) subexpression is
+ // not used by anyone else...
+ //
+ if (BinaryOperator *Op1I = dyn_cast<BinaryOperator>(Op1))
+ if (Op1I->use_size() == 1) {
+ // Swap the two operands of the subexpr...
+ Value *IIOp0 = Op1I->getOperand(0), *IIOp1 = Op1I->getOperand(1);
+ Op1I->setOperand(0, IIOp1);
+ Op1I->setOperand(1, IIOp0);
+
+ // Create the new top level add instruction...
+ return BinaryOperator::create(Instruction::Add, Op0, Op1);
+ }
return 0;
}