diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-03-15 05:12:00 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-03-15 05:12:00 +0000 |
commit | 5a89434236a4d6ad5fa6a570cbf3e717b757a148 (patch) | |
tree | 2db37a708ff855bf7bc52d2c360a5f428df68616 | |
parent | 59c5d7bf2cc64a1e600c0fb190841dc2b15dbf71 (diff) | |
download | llvm-5a89434236a4d6ad5fa6a570cbf3e717b757a148.tar.gz llvm-5a89434236a4d6ad5fa6a570cbf3e717b757a148.tar.bz2 llvm-5a89434236a4d6ad5fa6a570cbf3e717b757a148.tar.xz |
Add a xform to the DAG combiner.
Transform:
(fsub x, (fadd x, y)) -> (fneg y) and
(fsub x, (fadd y, x)) -> (fneg y)
if 'unsafe math' is specified.
<rdar://problem/7540295>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152777 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index e3c14b0873..8337d763ac 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -5568,6 +5568,23 @@ SDValue DAGCombiner::visitFSUB(SDNode *N) { return DAG.getNode(ISD::FADD, N->getDebugLoc(), VT, N0, GetNegatedExpression(N1, DAG, LegalOperations)); + // If 'unsafe math' is enabled, fold + // (fsub x, (fadd x, y)) -> (fneg y) & + // (fsub x, (fadd y, x)) -> (fneg y) + if (DAG.getTarget().Options.UnsafeFPMath) { + if (N1.getOpcode() == ISD::FADD) { + SDValue N10 = N1->getOperand(0); + SDValue N11 = N1->getOperand(1); + + if (N10 == N0 && isNegatibleForFree(N11, LegalOperations, TLI, + &DAG.getTarget().Options)) + return GetNegatedExpression(N11, DAG, LegalOperations); + else if (N11 == N0 && isNegatibleForFree(N10, LegalOperations, TLI, + &DAG.getTarget().Options)) + return GetNegatedExpression(N10, DAG, LegalOperations); + } + } + return SDValue(); } |