Transforming -A + -B --> -(A + B) isn't safe for FP, thanks

to Dale for noticing this!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47276 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2008-02-18 17:50:16 +00:00
parent 913b19f6fc
commit e10c0b9d66

View File

@ -2092,10 +2092,12 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
// -A + B --> B - A
// -A + -B --> -(A + B)
if (Value *LHSV = dyn_castNegVal(LHS)) {
if (Value *RHSV = dyn_castNegVal(RHS)) {
Instruction *NewAdd = BinaryOperator::createAdd(LHSV, RHSV, "sum");
InsertNewInstBefore(NewAdd, I);
return BinaryOperator::createNeg(NewAdd);
if (LHS->getType()->isIntOrIntVector()) {
if (Value *RHSV = dyn_castNegVal(RHS)) {
Instruction *NewAdd = BinaryOperator::createAdd(LHSV, RHSV, "sum");
InsertNewInstBefore(NewAdd, I);
return BinaryOperator::createNeg(NewAdd);
}
}
return BinaryOperator::createSub(RHS, LHSV);