diff options
| author | Chris Lattner <sabre@nondot.org> | 2006-02-28 06:23:04 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2006-02-28 06:23:04 +0000 |
| commit | 0f8a727c49f3dd6d64926e9a1d76bbd71eb6801d (patch) | |
| tree | 241427991f310fc2b7aac463fa79e501b00be000 /llvm/lib/CodeGen/SelectionDAG | |
| parent | b70f141893266f8e065fec991e271b6cb3708865 (diff) | |
| download | bcm5719-llvm-0f8a727c49f3dd6d64926e9a1d76bbd71eb6801d.tar.gz bcm5719-llvm-0f8a727c49f3dd6d64926e9a1d76bbd71eb6801d.zip | |
fold (sra (sra x, c1), c2) -> (sra x, c1+c2)
llvm-svn: 26416
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index b9c560d1215..da63be3a1e1 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -23,9 +23,6 @@ // FIXME: mul (x, const) -> shifts + adds // FIXME: undef values // FIXME: make truncate see through SIGN_EXTEND and AND -// FIXME: (sra (sra x, c1), c2) -> (sra x, c1+c2) -// FIXME: verify that getNode can't return extends with an operand whose type -// is >= to that of the extend. // FIXME: divide by zero is currently left unfolded. do we want to turn this // into an undef? // FIXME: select ne (select cc, 1, 0), 0, true, false -> select cc, true, false @@ -1367,6 +1364,17 @@ SDOperand DAGCombiner::visitSRA(SDNode *N) { return DAG.getNode(ISD::SIGN_EXTEND_INREG, VT, N0.getOperand(0), DAG.getValueType(EVT)); } + + // fold (sra (sra x, c1), c2) -> (sra x, c1+c2) + if (N1C && N0.getOpcode() == ISD::SRA) { + if (ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(N0.getOperand(1))) { + unsigned Sum = N1C->getValue() + C1->getValue(); + if (Sum >= MVT::getSizeInBits(VT)) Sum = MVT::getSizeInBits(VT)-1; + return DAG.getNode(ISD::SRA, VT, N0.getOperand(0), + DAG.getConstant(Sum, N1C->getValueType(0))); + } + } + // If the sign bit is known to be zero, switch this to a SRL. if (TLI.MaskedValueIsZero(N0, MVT::getIntVTSignBit(VT))) return DAG.getNode(ISD::SRL, VT, N0, N1); |

