mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 20:29:48 +00:00
Handle urem by shifted powers of 2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26001 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fb5e4bdded
commit
c031e33b68
@ -786,10 +786,11 @@ SDOperand DAGCombiner::visitUDIV(SDNode *N) {
|
|||||||
if (ConstantSDNode *SHC = dyn_cast<ConstantSDNode>(N1.getOperand(0))) {
|
if (ConstantSDNode *SHC = dyn_cast<ConstantSDNode>(N1.getOperand(0))) {
|
||||||
if (isPowerOf2_64(SHC->getValue())) {
|
if (isPowerOf2_64(SHC->getValue())) {
|
||||||
MVT::ValueType ADDVT = N1.getOperand(1).getValueType();
|
MVT::ValueType ADDVT = N1.getOperand(1).getValueType();
|
||||||
return DAG.getNode(ISD::SRL, VT, N0,
|
SDOperand Add = DAG.getNode(ISD::ADD, ADDVT, N1.getOperand(1),
|
||||||
DAG.getNode(ISD::ADD, ADDVT, N1.getOperand(1),
|
DAG.getConstant(Log2_64(SHC->getValue()),
|
||||||
DAG.getConstant(Log2_64(SHC->getValue()),
|
ADDVT));
|
||||||
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)
|
// fold (urem x, pow2) -> (and x, pow2-1)
|
||||||
if (N1C && !N1C->isNullValue() && isPowerOf2_64(N1C->getValue()))
|
if (N1C && !N1C->isNullValue() && isPowerOf2_64(N1C->getValue()))
|
||||||
return DAG.getNode(ISD::AND, VT, N0, DAG.getConstant(N1C->getValue()-1,VT));
|
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();
|
return SDOperand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user