mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-27 14:24:40 +00:00
InstSimplify: Fix a bug when INT_MIN is in a sdiv
When INT_MIN is the numerator in a sdiv, we would not properly handle overflow when calculating the bounds of possible values; abs(INT_MIN) is not a meaningful number. Instead, check and handle INT_MIN by reasoning that the largest value is INT_MIN/-2 and the smallest value is INT_MIN. This fixes PR20199. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212307 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1948,9 +1948,15 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
|
||||
if (!CI2->isZero())
|
||||
Upper = NegOne.udiv(CI2->getValue()) + 1;
|
||||
} else if (match(LHS, m_SDiv(m_ConstantInt(CI2), m_Value()))) {
|
||||
// 'sdiv CI2, x' produces [-|CI2|, |CI2|].
|
||||
Upper = CI2->getValue().abs() + 1;
|
||||
Lower = (-Upper) + 1;
|
||||
if (CI2->isMinSignedValue()) {
|
||||
// 'sdiv INT_MIN, x' produces [INT_MIN, INT_MIN / -2].
|
||||
Lower = CI2->getValue();
|
||||
Upper = Lower.lshr(1) + 1;
|
||||
} else {
|
||||
// 'sdiv CI2, x' produces [-|CI2|, |CI2|].
|
||||
Upper = CI2->getValue().abs() + 1;
|
||||
Lower = (-Upper) + 1;
|
||||
}
|
||||
} else if (match(LHS, m_SDiv(m_Value(), m_ConstantInt(CI2)))) {
|
||||
// 'sdiv x, CI2' produces [INT_MIN / CI2, INT_MAX / CI2].
|
||||
APInt IntMin = APInt::getSignedMinValue(Width);
|
||||
|
Reference in New Issue
Block a user