diff options
author | Chris Lattner <sabre@nondot.org> | 2010-04-15 05:28:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-04-15 05:28:43 +0000 |
commit | 828c441a908fce30c16921936fcab5a9c063ea69 (patch) | |
tree | 226d1a8b111b0e4fcf7ca88b4f9e5a81daa135f2 | |
parent | b7920f1c4e1cb2aeb06740780c1f7a23fdb8f505 (diff) | |
download | external_llvm-828c441a908fce30c16921936fcab5a9c063ea69.zip external_llvm-828c441a908fce30c16921936fcab5a9c063ea69.tar.gz external_llvm-828c441a908fce30c16921936fcab5a9c063ea69.tar.bz2 |
add a simple dag combine to replace trivial shl+lshr with
and. This happens with the store->load narrowing stuff.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101348 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 9 | ||||
-rw-r--r-- | test/CodeGen/ARM/sbfx.ll | 2 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 671c507..5974aff 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -2735,6 +2735,15 @@ SDValue DAGCombiner::visitSRL(SDNode *N) { return DAG.getNode(ISD::SRL, N->getDebugLoc(), VT, N0.getOperand(0), DAG.getConstant(c1 + c2, N1.getValueType())); } + + // fold (srl (shl x, c), c) -> (and x, cst2) + if (N1C && N0.getOpcode() == ISD::SHL && N0.getOperand(1) == N1 && + N0.getValueSizeInBits() <= 64) { + uint64_t ShAmt = N1C->getZExtValue()+64-N0.getValueSizeInBits(); + return DAG.getNode(ISD::AND, N->getDebugLoc(), VT, N0.getOperand(0), + DAG.getConstant(~0ULL >> ShAmt, VT)); + } + // fold (srl (anyextend x), c) -> (anyextend (srl x, c)) if (N1C && N0.getOpcode() == ISD::ANY_EXTEND) { diff --git a/test/CodeGen/ARM/sbfx.ll b/test/CodeGen/ARM/sbfx.ll index 6f1d87d..d29693e 100644 --- a/test/CodeGen/ARM/sbfx.ll +++ b/test/CodeGen/ARM/sbfx.ll @@ -12,7 +12,7 @@ entry: define i32 @f2(i32 %a) { entry: ; CHECK: f2: -; CHECK: ubfx r0, r0, #0, #20 +; CHECK: bfc r0, #20, #12 %tmp = shl i32 %a, 12 %tmp2 = lshr i32 %tmp, 12 ret i32 %tmp2 |