diff options
author | Chris Lattner <sabre@nondot.org> | 2007-01-08 23:04:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-01-08 23:04:05 +0000 |
commit | 0199fd6d59ee1598338c8ad5512fb65129fc6548 (patch) | |
tree | 8ca88e27f974677cc0fa43287985752aa62a46fb /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | 8b574a767e0af891f4498c3a42e592f4a23e48f3 (diff) | |
download | bcm5719-llvm-0199fd6d59ee1598338c8ad5512fb65129fc6548.tar.gz bcm5719-llvm-0199fd6d59ee1598338c8ad5512fb65129fc6548.zip |
Implement some trivial FP foldings when -enable-unsafe-fp-math is specified.
This implements CodeGen/PowerPC/unsafe-math.ll
llvm-svn: 33024
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 33509536eb5..76a60f0f478 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -35,6 +35,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" #include "llvm/Target/TargetLowering.h" +#include "llvm/Target/TargetOptions.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/CommandLine.h" #include <algorithm> @@ -2401,6 +2402,13 @@ SDOperand DAGCombiner::visitFADD(SDNode *N) { // fold ((-A) + B) -> B-A if (N0.getOpcode() == ISD::FNEG) return DAG.getNode(ISD::FSUB, VT, N1, N0.getOperand(0)); + + // If allowed, fold (fadd (fadd x, c1), c2) -> (fadd x, (fadd c1, c2)) + if (UnsafeFPMath && N1CFP && N0.getOpcode() == ISD::FADD && + N0.Val->hasOneUse() && isa<ConstantFPSDNode>(N0.getOperand(1))) + return DAG.getNode(ISD::FADD, VT, N0.getOperand(0), + DAG.getNode(ISD::FADD, VT, N0.getOperand(1), N1)); + return SDOperand(); } @@ -2436,6 +2444,13 @@ SDOperand DAGCombiner::visitFMUL(SDNode *N) { // fold (fmul X, 2.0) -> (fadd X, X) if (N1CFP && N1CFP->isExactlyValue(+2.0)) return DAG.getNode(ISD::FADD, VT, N0, N0); + + // If allowed, fold (fmul (fmul x, c1), c2) -> (fmul x, (fmul c1, c2)) + if (UnsafeFPMath && N1CFP && N0.getOpcode() == ISD::FMUL && + N0.Val->hasOneUse() && isa<ConstantFPSDNode>(N0.getOperand(1))) + return DAG.getNode(ISD::FMUL, VT, N0.getOperand(0), + DAG.getNode(ISD::FMUL, VT, N0.getOperand(1), N1)); + return SDOperand(); } |