mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-26 23:24:34 +00:00
Teach ComputeNumSignBits about signed divisions.
http://reviews.llvm.org/D8028 rdar://20023136 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231140 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1723,6 +1723,23 @@ unsigned ComputeNumSignBits(Value *V, const DataLayout *TD,
|
||||
Tmp = TyBits - U->getOperand(0)->getType()->getScalarSizeInBits();
|
||||
return ComputeNumSignBits(U->getOperand(0), TD, Depth+1, Q) + Tmp;
|
||||
|
||||
case Instruction::SDiv:
|
||||
const APInt *Denominator;
|
||||
// sdiv X, C -> adds log(C) sign bits.
|
||||
if (match(U->getOperand(1), m_APInt(Denominator))) {
|
||||
|
||||
// Ignore non-positive denominator.
|
||||
if (!Denominator->isStrictlyPositive())
|
||||
break;
|
||||
|
||||
// Calculate the incoming numerator bits.
|
||||
unsigned NumBits = ComputeNumSignBits(U->getOperand(0), TD, Depth+1, Q);
|
||||
|
||||
// Add floor(log(C)) bits to the numerator bits.
|
||||
return std::min(TyBits, NumBits + Denominator->logBase2());
|
||||
}
|
||||
break;
|
||||
|
||||
case Instruction::AShr: {
|
||||
Tmp = ComputeNumSignBits(U->getOperand(0), TD, Depth+1, Q);
|
||||
// ashr X, C -> adds C sign bits. Vectors too.
|
||||
|
Reference in New Issue
Block a user