diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-02-15 13:55:52 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-02-15 13:55:52 +0000 |
commit | 6a0f667077fcd7f8af813384b34f3937702388d4 (patch) | |
tree | a1d89fe8e5656f9174f089fd1ab4a48bd73df02f /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | b5f8ca47e716c7817acfdf9fa59c6932439726a3 (diff) | |
download | bcm5719-llvm-6a0f667077fcd7f8af813384b34f3937702388d4.tar.gz bcm5719-llvm-6a0f667077fcd7f8af813384b34f3937702388d4.zip |
[InstCombine] allow X / C -> X * (1.0/C) for vector splat FP constants
llvm-svn: 325237
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 5457f19d7f4..57a30558a98 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -1319,21 +1319,19 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { /// 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 @@ static Instruction *foldFDivConstantDivisor(BinaryOperator &FDiv) { 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); } |