[InstCombine] allow X / C -> X * (1.0/C) for vector splat FP constants

llvm-svn: 325237
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 5457f19..57a3055 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1319,21 +1319,19 @@
 
 /// Try to convert X/C into X * (1/C).
 static Instruction *foldFDivConstantDivisor(BinaryOperator &FDiv) {
-  // TODO: Handle vector constants.
-  ConstantFP *CFP;
-  if (!match(FDiv.getOperand(1), m_ConstantFP(CFP)))
+  // TODO: Handle non-splat vector constants.
+  const APFloat *C;
+  if (!match(FDiv.getOperand(1), m_APFloat(C)))
     return nullptr;
 
-  const APFloat &FpVal = CFP->getValueAPF();
-  APFloat Reciprocal(FpVal.getSemantics());
-
   // This returns false if the inverse would be a denormal.
-  bool HasRecip = FpVal.getExactInverse(&Reciprocal);
+  APFloat Reciprocal(C->getSemantics());
+  bool HasRecip = C->getExactInverse(&Reciprocal);
   // If the inverse is not exact, we may still be able to convert if we are
   // not operating with strict math.
-  if (!HasRecip && FDiv.hasAllowReciprocal() && FpVal.isFiniteNonZero()) {
-    Reciprocal = APFloat(FpVal.getSemantics(), 1.0f);
-    Reciprocal.divide(FpVal, APFloat::rmNearestTiesToEven);
+  if (!HasRecip && FDiv.hasAllowReciprocal() && C->isFiniteNonZero()) {
+    Reciprocal = APFloat(C->getSemantics(), 1.0f);
+    Reciprocal.divide(*C, APFloat::rmNearestTiesToEven);
     // Disallow denormal constants because we don't know what would happen
     // on all targets.
     // TODO: Function attributes can tell us that denorms are flushed?
@@ -1343,7 +1341,7 @@
   if (!HasRecip)
     return nullptr;
 
-  auto *RecipCFP = ConstantFP::get(FDiv.getContext(), Reciprocal);
+  auto *RecipCFP = ConstantFP::get(FDiv.getType(), Reciprocal);
   return BinaryOperator::CreateFMul(FDiv.getOperand(0), RecipCFP);
 }