[InstCombine] -X / C --> X / -C for FP

We already do this in DAGCombiner, but it should 
also be good to eliminate the fsub use in IR.

llvm-svn: 325648
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index cb42d24..ec62beb 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1285,12 +1285,18 @@
   return nullptr;
 }
 
-/// Try to convert X/C into X * (1/C).
+/// Remove negation and try to convert division into multiplication.
 static Instruction *foldFDivConstantDivisor(BinaryOperator &I) {
   Constant *C;
   if (!match(I.getOperand(1), m_Constant(C)))
     return nullptr;
 
+  // -X / C --> X / -C
+  Value *X;
+  if (match(I.getOperand(0), m_FNeg(m_Value(X))))
+    return BinaryOperator::CreateWithCopiedFlags(Instruction::FDiv, X,
+                                                 ConstantExpr::getFNeg(C), &I);
+
   // If the constant divisor has an exact inverse, this is always safe. If not,
   // then we can still create a reciprocal if fast-math-flags allow it and the
   // constant is a regular number (not zero, infinite, or denormal).
@@ -1305,6 +1311,7 @@
   if (!RecipC->isNormalFP())
     return nullptr;
 
+  // X / C --> X * (1 / C)
   return BinaryOperator::CreateWithCopiedFlags(
       Instruction::FMul, I.getOperand(0), RecipC, &I);
 }
@@ -1345,11 +1352,11 @@
                                   SQ.getWithInstruction(&I)))
     return replaceInstUsesWith(I, V);
 
-  if (Instruction *FMul = foldFDivConstantDivisor(I))
-    return FMul;
+  if (Instruction *R = foldFDivConstantDivisor(I))
+    return R;
 
-  if (Instruction *NewFDiv = foldFDivConstantDividend(I))
-    return NewFDiv;
+  if (Instruction *R = foldFDivConstantDividend(I))
+    return R;
 
   if (isa<Constant>(Op0))
     if (SelectInst *SI = dyn_cast<SelectInst>(Op1))