[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Apr 7 09:28:14 PDT 2005
Changes in directory llvm/lib/Transforms/Scalar:
InstructionCombining.cpp updated: 1.318 -> 1.319
---
Log message:
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.
---
Diffs of the changes: (+8 -2)
InstructionCombining.cpp | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.318 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.319
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.318 Thu Apr 7 11:15:25 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu Apr 7 11:28:01 2005
@@ -795,10 +795,16 @@
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()) {
More information about the llvm-commits
mailing list