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

to Dale for noticing this!

llvm-svn: 47276
This commit is contained in:
Chris Lattner 2008-02-18 17:50:16 +00:00
parent a3318d17d4
commit a378b03483

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);