diff options
| author | Chris Lattner <sabre@nondot.org> | 2002-05-09 01:29:19 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2002-05-09 01:29:19 +0000 |
| commit | ad3c495225f261d2acd6930ffbe9f0682f0219dd (patch) | |
| tree | 523bfd4a98142a5efbd3b6b29be6d30b1566c814 /llvm/lib/Transforms | |
| parent | c5a41d8af18d61cdc31a83538d2eddece154a9e1 (diff) | |
| download | bcm5719-llvm-ad3c495225f261d2acd6930ffbe9f0682f0219dd.tar.gz bcm5719-llvm-ad3c495225f261d2acd6930ffbe9f0682f0219dd.zip | |
Add ability to transform (x - (y - z)) into (x + (z - y))
llvm-svn: 2566
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index a77bcb95864..9625398017a 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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; } |

