Add a check missing from my last commit and avoid a potential overflow situation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122258 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer 2010-12-20 20:00:31 +00:00
parent 87790abb08
commit b0de244f23

View File

@ -1449,13 +1449,13 @@ Value *InstCombiner::FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS) {
} }
} }
// (icmp ult (X + CA), C1) | (icmp eq X, C2) -> (icmp ult (X + CA), C1 + 1) // (icmp ult (X + CA), C1) | (icmp eq X, C2) -> (icmp ule (X + CA), C1)
// iff C2 + CA == C1. // iff C2 + CA == C1.
if (LHSCC == ICmpInst::ICMP_ULT) { if (LHSCC == ICmpInst::ICMP_ULT && RHSCC == ICmpInst::ICMP_EQ) {
ConstantInt *AddCst; ConstantInt *AddCst;
if (match(Val, m_Add(m_Specific(Val2), m_ConstantInt(AddCst)))) if (match(Val, m_Add(m_Specific(Val2), m_ConstantInt(AddCst))))
if (RHSCst->getValue() + AddCst->getValue() == LHSCst->getValue()) if (RHSCst->getValue() + AddCst->getValue() == LHSCst->getValue())
return Builder->CreateICmp(LHSCC, Val, AddOne(LHSCst)); return Builder->CreateICmpULE(Val, LHSCst);
} }
// From here on, we only handle: // From here on, we only handle: