diff options
author | Dale Johannesen <dalej@apple.com> | 2010-12-17 21:45:49 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2010-12-17 21:45:49 +0000 |
commit | cd538afa52415b8b565d93510dee2475a9e4f76f (patch) | |
tree | c61be19a41e2d220c656c4275fdda2bdfdd7d912 /llvm/lib/CodeGen | |
parent | 01a984023dca90352b338fbb097de2f390f6af07 (diff) | |
download | bcm5719-llvm-cd538afa52415b8b565d93510dee2475a9e4f76f.tar.gz bcm5719-llvm-cd538afa52415b8b565d93510dee2475a9e4f76f.zip |
Add a transform to DAG Combiner. This improves the
code for the case where 32-bit divide by constant is
turned into 64-bit multiply by constant. 8771012.
llvm-svn: 122090
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index be5a5bc1a5e..522ebee73cf 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -3171,6 +3171,26 @@ SDValue DAGCombiner::visitSRL(SDNode *N) { DAG.getConstant(c1 + c2, N1.getValueType())); } + // fold (srl (trunc (srl x, c1)), c2) -> 0 or (trunc (srl x, (add c1, c2))) + // This is only valid if the OpSizeInBits + c1 = size of inner shift + if (N1C && N0.getOpcode() == ISD::TRUNCATE && + N0.getOperand(0).getOpcode() == ISD::SRL && + N0.getOperand(0)->getOperand(1).getOpcode() == ISD::Constant) { + uint64_t c1 = + cast<ConstantSDNode>(N0.getOperand(0)->getOperand(1))->getZExtValue(); + uint64_t c2 = N1C->getZExtValue(); + EVT InnerShiftVT = N0.getOperand(0)->getOperand(1).getValueType(); + uint64_t InnerShiftSize = InnerShiftVT.getScalarType().getSizeInBits(); + if (c1 + OpSizeInBits == InnerShiftSize) { + if (c1 + c2 >= InnerShiftSize) + return DAG.getConstant(0, VT); + return DAG.getNode(ISD::TRUNCATE, N0->getDebugLoc(), VT, + DAG.getNode(ISD::SRL, N0->getDebugLoc(), InnerShiftVT, + N0.getOperand(0)->getOperand(0), + DAG.getConstant(c1 + c2, InnerShiftVT))); + } + } + // fold (srl (shl x, c), c) -> (and x, cst2) if (N1C && N0.getOpcode() == ISD::SHL && N0.getOperand(1) == N1 && N0.getValueSizeInBits() <= 64) { |