diff options
author | Sanjay Patel <spatel@rotateright.com> | 2015-04-29 22:30:02 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2015-04-29 22:30:02 +0000 |
commit | 04b0e92766a6224dc877ae7b936a07cbf11983a2 (patch) | |
tree | af2dc1e248178d060a37d36eb19951db3bdffd96 /llvm/lib | |
parent | 3114703b5c62c7c71d5da3200bb609d558952006 (diff) | |
download | bcm5719-llvm-04b0e92766a6224dc877ae7b936a07cbf11983a2.tar.gz bcm5719-llvm-04b0e92766a6224dc877ae7b936a07cbf11983a2.zip |
generalize binop reassociation; NFC
Move the fold introduced in r236031:
http://reviews.llvm.org/rL236031
to its own helper function, so we can use it for other binops.
This is a preliminary step before partially solving:
https://llvm.org/bugs/show_bug.cgi?id=21768
https://llvm.org/bugs/show_bug.cgi?id=23116
llvm-svn: 236171
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 5a9b49d7761..2a9f8e1d304 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -7647,6 +7647,33 @@ SDValue DAGCombiner::visitFSUBForFMACombine(SDNode *N) { return SDValue(); } +static SDValue ReassociateBinops(SDNode *N, SelectionDAG &DAG) { + assert(N->getNumOperands() == 2 && "Invalid node for binop reassociation"); + SDValue N0 = N->getOperand(0); + SDValue N1 = N->getOperand(1); + EVT VT = N->getValueType(0); + SDLoc DL(N); + unsigned Opcode = N->getOpcode(); + + // Canonicalize chains of this operation to LHS to allow the following fold. + if (N0.getOpcode() != Opcode && N1.getOpcode() == Opcode) + return DAG.getNode(Opcode, DL, VT, N1, N0); + + // Convert a chain of 3 dependent operations into 2 independent operations + // and 1 dependent operation: + // (op N0: (op N00: (op z, w), N01: y), N1: x) -> + // (op N00: (op z, w), (op N1: x, N01: y)) + if (N0.getOpcode() == Opcode && N0.hasOneUse() && N1.getOpcode() != Opcode) { + SDValue N00 = N0.getOperand(0); + if (N00.getOpcode() == Opcode) { + SDValue N01 = N0.getOperand(1); + SDValue NewOp = DAG.getNode(Opcode, DL, VT, N1, N01); + return DAG.getNode(Opcode, DL, VT, N00, NewOp); + } + } + return SDValue(); +} + SDValue DAGCombiner::visitFADD(SDNode *N) { SDValue N0 = N->getOperand(0); SDValue N1 = N->getOperand(1); @@ -7781,24 +7808,10 @@ SDValue DAGCombiner::visitFADD(SDNode *N) { N0.getOperand(0), DAG.getConstantFP(4.0, DL, VT)); } } - - // Canonicalize chains of adds to LHS to simplify the following transform. - if (N0.getOpcode() != ISD::FADD && N1.getOpcode() == ISD::FADD) - return DAG.getNode(ISD::FADD, DL, VT, N1, N0); - // Convert a chain of 3 dependent operations into 2 independent operations - // and 1 dependent operation: - // (fadd N0: (fadd N00: (fadd z, w), N01: y), N1: x) -> - // (fadd N00: (fadd z, w), (fadd N1: x, N01: y)) - if (N0.getOpcode() == ISD::FADD && N0.hasOneUse() && - N1.getOpcode() != ISD::FADD) { - SDValue N00 = N0.getOperand(0); - if (N00.getOpcode() == ISD::FADD) { - SDValue N01 = N0.getOperand(1); - SDValue NewAdd = DAG.getNode(ISD::FADD, DL, VT, N1, N01); - return DAG.getNode(ISD::FADD, DL, VT, N00, NewAdd); - } - } + if (SDValue Reassociated = ReassociateBinops(N, DAG)) + return Reassociated; + } // enable-unsafe-fp-math // FADD -> FMA combines: |