diff options
author | Chris Lattner <sabre@nondot.org> | 2005-05-09 17:06:45 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-05-09 17:06:45 +0000 |
commit | 1ab1691da91a5c5f3d08bee58135105360a0dbf6 (patch) | |
tree | 9a93227b01e931be454e547a6280dece7583cf95 /llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | |
parent | 05990f3302079a0407d9b06fdb2a223f115aa0b6 (diff) | |
download | bcm5719-llvm-1ab1691da91a5c5f3d08bee58135105360a0dbf6.tar.gz bcm5719-llvm-1ab1691da91a5c5f3d08bee58135105360a0dbf6.zip |
Fold shifts into subsequent SHL's. These shifts often arise due to addrses
arithmetic lowering.
llvm-svn: 21818
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 26aa570e937..faeb872528b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -946,6 +946,34 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, return getNode(ISD::UNDEF, N1.getValueType()); } if (C2 == 0) return N1; + + if (Opcode == ISD::SHL && N1.getNumOperands() == 2) + if (ConstantSDNode *OpSA = dyn_cast<ConstantSDNode>(N1.getOperand(1))) { + unsigned OpSAC = OpSA->getValue(); + if (N1.getOpcode() == ISD::SHL) { + if (C2+OpSAC >= MVT::getSizeInBits(N1.getValueType())) + return getConstant(0, N1.getValueType()); + return getNode(ISD::SHL, N1.getValueType(), N1.getOperand(0), + getConstant(C2+OpSAC, N2.getValueType())); + } else if (N1.getOpcode() == ISD::SRL) { + // (X >> C1) << C2: if C2 > C1, ((X & ~0<<C1) << C2-C1) + SDOperand Mask = getNode(ISD::AND, VT, N1.getOperand(0), + getConstant(~0ULL << OpSAC, VT)); + if (C2 > OpSAC) { + return getNode(ISD::SHL, VT, Mask, + getConstant(C2-OpSAC, N2.getValueType())); + } else { + // (X >> C1) << C2: if C2 <= C1, ((X & ~0<<C1) >> C1-C2) + return getNode(ISD::SRL, VT, Mask, + getConstant(OpSAC-C2, N2.getValueType())); + } + } else if (N1.getOpcode() == ISD::SRA) { + // if C1 == C2, just mask out low bits. + if (C2 == OpSAC) + return getNode(ISD::AND, VT, N1.getOperand(0), + getConstant(~0ULL << C2, VT)); + } + } break; case ISD::AND: |