diff options
| author | Nate Begeman <natebegeman@mac.com> | 2006-02-05 07:36:48 +0000 |
|---|---|---|
| committer | Nate Begeman <natebegeman@mac.com> | 2006-02-05 07:36:48 +0000 |
| commit | c89fdf1eb35f4002f744849a8db97a99d84cfbf8 (patch) | |
| tree | 11ce221e2536c0c0a9ad5f09c80b87d4460cd88b /llvm/lib | |
| parent | 25d178bece6fef191ec0a8ff85659d8abe22dba0 (diff) | |
| download | bcm5719-llvm-c89fdf1eb35f4002f744849a8db97a99d84cfbf8.tar.gz bcm5719-llvm-c89fdf1eb35f4002f744849a8db97a99d84cfbf8.zip | |
Handle urem by shifted powers of 2.
llvm-svn: 26001
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 5315d9e11f5..533fd70de02 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -786,10 +786,11 @@ SDOperand DAGCombiner::visitUDIV(SDNode *N) { if (ConstantSDNode *SHC = dyn_cast<ConstantSDNode>(N1.getOperand(0))) { if (isPowerOf2_64(SHC->getValue())) { MVT::ValueType ADDVT = N1.getOperand(1).getValueType(); - return DAG.getNode(ISD::SRL, VT, N0, - DAG.getNode(ISD::ADD, ADDVT, N1.getOperand(1), - DAG.getConstant(Log2_64(SHC->getValue()), - ADDVT))); + SDOperand Add = DAG.getNode(ISD::ADD, ADDVT, N1.getOperand(1), + DAG.getConstant(Log2_64(SHC->getValue()), + ADDVT)); + WorkList.push_back(Add.Val); + return DAG.getNode(ISD::SRL, VT, N0, Add); } } } @@ -833,6 +834,16 @@ SDOperand DAGCombiner::visitUREM(SDNode *N) { // fold (urem x, pow2) -> (and x, pow2-1) if (N1C && !N1C->isNullValue() && isPowerOf2_64(N1C->getValue())) return DAG.getNode(ISD::AND, VT, N0, DAG.getConstant(N1C->getValue()-1,VT)); + // fold (urem x, (shl pow2, y)) -> (and x, (add (shl pow2, y), -1)) + if (N1.getOpcode() == ISD::SHL) { + if (ConstantSDNode *SHC = dyn_cast<ConstantSDNode>(N1.getOperand(0))) { + if (isPowerOf2_64(SHC->getValue())) { + SDOperand Add = DAG.getNode(ISD::ADD, VT, N1, DAG.getConstant(-1, VT)); + WorkList.push_back(Add.Val); + return DAG.getNode(ISD::AND, VT, N0, Add); + } + } + } return SDOperand(); } |

