[llvm-commits] [llvm] r124567 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCompares.cpp test/Transforms/InstCombine/add.ll
Anders Carlsson
andersca at mac.com
Sun Jan 30 14:01:13 PST 2011
Author: andersca
Date: Sun Jan 30 16:01:13 2011
New Revision: 124567
URL: http://llvm.org/viewvc/llvm-project?rev=124567&view=rev
Log:
Recognize and simplify
(A+B) == A -> B == 0
A == (A+B) -> B == 0
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/add.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=124567&r1=124566&r2=124567&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Sun Jan 30 16:01:13 2011
@@ -2341,7 +2341,17 @@
if (match(Op1, m_Sub(m_Specific(Op0), m_Value(B))))
return new ICmpInst(I.getPredicate(), B,
Constant::getNullValue(B->getType()));
-
+
+ // (A+B) == A -> B == 0
+ if (match(Op0, m_Add(m_Specific(Op1), m_Value(B))))
+ 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))))
+ return new ICmpInst(I.getPredicate(), B,
+ Constant::getNullValue(B->getType()));
+
// (X&Z) == (Y&Z) -> (X^Y) & Z == 0
if (Op0->hasOneUse() && Op1->hasOneUse() &&
match(Op0, m_And(m_Value(A), m_Value(B))) &&
Modified: llvm/trunk/test/Transforms/InstCombine/add.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/add.ll?rev=124567&r1=124566&r2=124567&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/add.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/add.ll Sun Jan 30 16:01:13 2011
@@ -275,3 +275,19 @@
%q = and i32 %z, 1 ; always zero
ret i32 %q
}
+
+define i32 @test37(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %add = add nsw i32 %a, %b
+ %cmp = icmp eq i32 %add, %a
+ %conv = zext i1 %cmp to i32
+ ret i32 %conv
+}
+
+define i32 @test38(i32 %a, i32 %b) nounwind readnone {
+entry:
+ %add = add nsw i32 %a, %b
+ %cmp = icmp eq i32 %add, %a
+ %conv = zext i1 %cmp to i32
+ ret i32 %conv
+}
More information about the llvm-commits
mailing list