[llvm-commits] [llvm] r154296 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp test/CodeGen/X86/fdiv.ll
Duncan Sands
baldrick at free.fr
Sun Apr 8 11:08:13 PDT 2012
Author: baldrick
Date: Sun Apr 8 13:08:12 2012
New Revision: 154296
URL: http://llvm.org/viewvc/llvm-project?rev=154296&view=rev
Log:
Only have codegen turn fdiv by a constant into fmul by the reciprocal
when -ffast-math, i.e. don't just always do it if the reciprocal can
be formed exactly. There is already an IR level transform that does
that, and it does it more carefully.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/X86/fdiv.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=154296&r1=154295&r2=154296&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Sun Apr 8 13:08:12 2012
@@ -5725,16 +5725,14 @@
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) {
+ // fold (fdiv X, c2) -> fmul X, 1/c2 if losing precision is acceptable.
+ if (N1CFP && VT != MVT::ppcf128 && DAG.getTarget().Options.UnsafeFPMath) {
// 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))
+ if (st == APFloat::opOK || st == APFloat::opInexact)
return DAG.getNode(ISD::FMUL, N->getDebugLoc(), VT, N0,
DAG.getConstantFP(Recip, VT));
}
Modified: llvm/trunk/test/CodeGen/X86/fdiv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fdiv.ll?rev=154296&r1=154295&r2=154296&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fdiv.ll (original)
+++ llvm/trunk/test/CodeGen/X86/fdiv.ll Sun Apr 8 13:08:12 2012
@@ -1,22 +1,17 @@
-; RUN: llc < %s -march=x86-64 | FileCheck %s
-; RUN: llc < %s -march=x86-64 -enable-unsafe-fp-math | FileCheck -check-prefix=UNSAFE %s
+; RUN: llc < %s -march=x86-64 -enable-unsafe-fp-math | FileCheck %s
define double @exact(double %x) {
-; Exact division by a constant always converted to multiplication.
+; Exact division by a constant converted to multiplication.
; CHECK: @exact
; CHECK: mulsd
-; UNSAFE: @exact
-; UNSAFE: mulsd
%div = fdiv double %x, 2.0
ret double %div
}
define double @inexact(double %x) {
-; Inexact division by a constant converted to multiplication if unsafe-math.
+; Inexact division by a constant converted to multiplication.
; CHECK: @inexact
-; CHECK: divsd
-; UNSAFE: @inexact
-; UNSAFE: mulsd
+; CHECK: mulsd
%div = fdiv double %x, 0x41DFFFFFFFC00000
ret double %div
}
@@ -25,8 +20,6 @@
; No conversion to multiplication if too funky.
; CHECK: @funky
; CHECK: divsd
-; UNSAFE: @funky
-; UNSAFE: divsd
%div = fdiv double %x, 0.0
ret double %div
}
More information about the llvm-commits
mailing list