Also fold (A+B) == A -> B == 0 when the add is commuted.

llvm-svn: 125411
This commit is contained in:
Benjamin Kramer
2011-02-11 21:46:48 +00:00
parent 7936a8a488
commit 1800d823de
2 changed files with 23 additions and 13 deletions

View File

@@ -2351,12 +2351,14 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
Constant::getNullValue(B->getType()));
// (A+B) == A -> B == 0
if (match(Op0, m_Add(m_Specific(Op1), m_Value(B))))
if (match(Op0, m_Add(m_Specific(Op1), m_Value(B))) ||
match(Op0, m_Add(m_Value(B), m_Specific(Op1))))
return new ICmpInst(I.getPredicate(), B,
Constant::getNullValue(B->getType()));
// A == (A+B) -> B == 0
if (match(Op1, m_Add(m_Specific(Op0), m_Value(B))))
if (match(Op1, m_Add(m_Specific(Op0), m_Value(B))) ||
match(Op1, m_Add(m_Value(B), m_Specific(Op0))))
return new ICmpInst(I.getPredicate(), B,
Constant::getNullValue(B->getType()));