diff options
author | Evan Cheng <evan.cheng@apple.com> | 2007-01-19 17:51:44 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2007-01-19 17:51:44 +0000 |
commit | 42d7ccfd8e672bf3a5d42052f8da50f0d610afb2 (patch) | |
tree | 2c7a0d4bb0d44b93c89092e87280739686f61eac /lib/CodeGen/SelectionDAG/DAGCombiner.cpp | |
parent | b6a7aa7e9dd4e8a27034a5fa4d7786d791572bd8 (diff) |
Remove this xform:
(shl (add x, c1), c2) -> (add (shl x, c2), c1<<c2)
Replace it with:
(add (shl (add x, c1), c2), ) -> (add (add (shl x, c2), c1<<c2), )
This fixes test/CodeGen/ARM/smul.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33361 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r-- | lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 654f6c5269..fa48d546dd 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -653,6 +653,22 @@ SDOperand DAGCombiner::visitTokenFactor(SDNode *N) { return Result; } +static +SDOperand combineShlAddConstant(SDOperand N0, SDOperand N1, SelectionDAG &DAG) { + MVT::ValueType VT = N0.getValueType(); + SDOperand N00 = N0.getOperand(0); + SDOperand N01 = N0.getOperand(1); + ConstantSDNode *N01C = dyn_cast<ConstantSDNode>(N01); + if (N01C && N00.getOpcode() == ISD::ADD && N00.Val->hasOneUse() && + isa<ConstantSDNode>(N00.getOperand(1))) { + N0 = DAG.getNode(ISD::ADD, VT, + DAG.getNode(ISD::SHL, VT, N00.getOperand(0), N01), + DAG.getNode(ISD::SHL, VT, N00.getOperand(1), N01)); + return DAG.getNode(ISD::ADD, VT, N0, N1); + } + return SDOperand(); +} + SDOperand DAGCombiner::visitADD(SDNode *N) { SDOperand N0 = N->getOperand(0); SDOperand N1 = N->getOperand(1); @@ -711,6 +727,16 @@ SDOperand DAGCombiner::visitADD(SDNode *N) { } } + // fold (add (shl (add x, c1), c2), ) -> (add (add (shl x, c2), c1<<c2), ) + if (N0.getOpcode() == ISD::SHL && N0.Val->hasOneUse()) { + SDOperand Result = combineShlAddConstant(N0, N1, DAG); + if (Result.Val) return Result; + } + if (N1.getOpcode() == ISD::SHL && N1.Val->hasOneUse()) { + SDOperand Result = combineShlAddConstant(N1, N0, DAG); + if (Result.Val) return Result; + } + return SDOperand(); } @@ -1615,13 +1641,6 @@ SDOperand DAGCombiner::visitSHL(SDNode *N) { if (N1C && N0.getOpcode() == ISD::SRA && N1 == N0.getOperand(1)) return DAG.getNode(ISD::AND, VT, N0.getOperand(0), DAG.getConstant(~0ULL << N1C->getValue(), VT)); - // fold (shl (add x, c1), c2) -> (add (shl x, c2), c1<<c2) - if (N1C && N0.getOpcode() == ISD::ADD && N0.Val->hasOneUse() && - isa<ConstantSDNode>(N0.getOperand(1))) { - return DAG.getNode(ISD::ADD, VT, - DAG.getNode(ISD::SHL, VT, N0.getOperand(0), N1), - DAG.getNode(ISD::SHL, VT, N0.getOperand(1), N1)); - } return SDOperand(); } |