mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-11 13:44:28 +00:00
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
This commit is contained in:
parent
b6a7aa7e9d
commit
42d7ccfd8e
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user