[llvm-commits] [llvm] r125411 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineCompares.cpp test/Transforms/InstCombine/add.ll

Benjamin Kramer benny.kra at googlemail.com
Fri Feb 11 13:46:49 PST 2011


Author: d0k
Date: Fri Feb 11 15:46:48 2011
New Revision: 125411

URL: http://llvm.org/viewvc/llvm-project?rev=125411&view=rev
Log:
Also fold (A+B) == A -> B == 0 when the add is commuted.

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=125411&r1=125410&r2=125411&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Fri Feb 11 15:46:48 2011
@@ -2351,12 +2351,14 @@
                           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()));
 

Modified: llvm/trunk/test/Transforms/InstCombine/add.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/add.ll?rev=125411&r1=125410&r2=125411&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/add.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/add.ll Fri Feb 11 15:46:48 2011
@@ -276,18 +276,26 @@
 	ret i32 %q
 }
 
-define i32 @test37(i32 %a, i32 %b) nounwind readnone {
-entry:
-  %add = add nsw i32 %a, %b
+define i1 @test37(i32 %a, i32 %b) nounwind readnone {
+  %add = add i32 %a, %b
   %cmp = icmp eq i32 %add, %a
-  %conv = zext i1 %cmp to i32
-  ret i32 %conv
+  ret i1 %cmp
 }
 
-define i32 @test38(i32 %a, i32 %b) nounwind readnone {
-entry:
-  %add = add nsw i32 %a, %b
+define i1 @test38(i32 %a, i32 %b) nounwind readnone {
+  %add = add i32 %a, %b
+  %cmp = icmp eq i32 %add, %b
+  ret i1 %cmp
+}
+
+define i1 @test39(i32 %a, i32 %b) nounwind readnone {
+  %add = add i32 %b, %a
   %cmp = icmp eq i32 %add, %a
-  %conv = zext i1 %cmp to i32
-  ret i32 %conv
+  ret i1 %cmp
+}
+
+define i1 @test40(i32 %a, i32 %b) nounwind readnone {
+  %add = add i32 %b, %a
+  %cmp = icmp eq i32 %add, %b
+  ret i1 %cmp
 }





More information about the llvm-commits mailing list