[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Nate Begeman
natebegeman at mac.com
Sat Feb 4 23:37:00 PST 2006
Changes in directory llvm/lib/CodeGen/SelectionDAG:
DAGCombiner.cpp updated: 1.96 -> 1.97
---
Log message:
Handle urem by shifted powers of 2.
---
Diffs of the changes: (+15 -4)
DAGCombiner.cpp | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.96 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.97
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.96 Sun Feb 5 01:20:23 2006
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Sun Feb 5 01:36:48 2006
@@ -786,10 +786,11 @@
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 @@
// 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();
}
More information about the llvm-commits
mailing list