diff options
author | Duncan Sands <baldrick@free.fr> | 2012-04-07 20:04:00 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2012-04-07 20:04:00 +0000 |
commit | 5f8397a9344aafd3591f03d1dbb93688d1fee728 (patch) | |
tree | 6dd69d749f106dc7b469c4faeb47b7d38387f187 /llvm/lib/CodeGen | |
parent | 75a1cf327a96f1b1ea9a033a1d80fd49830ddaac (diff) | |
download | bcm5719-llvm-5f8397a9344aafd3591f03d1dbb93688d1fee728.tar.gz bcm5719-llvm-5f8397a9344aafd3591f03d1dbb93688d1fee728.zip |
Convert floating point division by a constant into multiplication by the
reciprocal if converting to the reciprocal is exact. Do it even if inexact
if -ffast-math. This substantially speeds up ac.f90 from the polyhedron
benchmarks.
llvm-svn: 154265
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index e03668777d8..e0fd3abfb45 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -5725,6 +5725,19 @@ SDValue DAGCombiner::visitFDIV(SDNode *N) { if (N0CFP && N1CFP && VT != MVT::ppcf128) return DAG.getNode(ISD::FDIV, N->getDebugLoc(), VT, N0, N1); + // fold (fdiv X, c2) -> fmul X, 1/c2 if there is no precision loss or if + // losing precision is acceptable. + if (N1CFP && VT != MVT::ppcf128) { + // Compute the reciprocal 1.0 / c2. + APFloat N1APF = N1CFP->getValueAPF(); + APFloat Recip(N1APF.getSemantics(), 1); // 1.0 + APFloat::opStatus st = Recip.divide(N1APF, APFloat::rmNearestTiesToEven); + // Only do the transform if the reciprocal is not too horrible (eg not NaN). + if (st == APFloat::opOK || (st == APFloat::opInexact && + DAG.getTarget().Options.UnsafeFPMath)) + return DAG.getNode(ISD::FMUL, N->getDebugLoc(), VT, N0, + DAG.getConstantFP(Recip, VT)); + } // (fdiv (fneg X), (fneg Y)) -> (fdiv X, Y) if (char LHSNeg = isNegatibleForFree(N0, LegalOperations, TLI, |