Implement PR2298. This transforms:
authorChris Lattner <sabre@nondot.org>
Fri, 9 May 2008 05:19:28 +0000 (05:19 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 9 May 2008 05:19:28 +0000 (05:19 +0000)
   ~x < ~y --> y < x
   -x == -y --> x == y

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50882 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/not.ll
test/Transforms/InstCombine/sub.ll

index 772ef63121b099f30c702f815ae968b8ecc3a11e..e8b60f890c29b4d156dbf82a0db44582fead2578 100644 (file)
@@ -5658,8 +5658,21 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
         return R;
   }
   
+  // ~x < ~y --> y < x
+  { Value *A, *B;
+    if (match(Op0, m_Not(m_Value(A))) &&
+        match(Op1, m_Not(m_Value(B))))
+      return new ICmpInst(I.getPredicate(), B, A);
+  }
+  
   if (I.isEquality()) {
     Value *A, *B, *C, *D;
+    
+    // -x == -y --> x == y
+    if (match(Op0, m_Neg(m_Value(A))) &&
+        match(Op1, m_Neg(m_Value(B))))
+      return new ICmpInst(I.getPredicate(), A, B);
+    
     if (match(Op0, m_Xor(m_Value(A), m_Value(B)))) {
       if (A == Op1 || B == Op1) {    // (A^B) == A  ->  B == 0
         Value *OtherVal = A == Op1 ? B : A;
index 757e1de940ce2db87d31d20e6fc3fa6b42963637..a79e51871818f99e7466060d14bb9bf2def4eb51 100644 (file)
@@ -42,3 +42,13 @@ define i32 @test5(i32 %A, i32 %B) {
         ret i32 %d
 }
 
+; PR2298
+define i8 @test6(i32 %a, i32 %b) zeroext nounwind  {
+entry:
+       %tmp1not = xor i32 %a, -1               ; <i32> [#uses=1]
+       %tmp2not = xor i32 %b, -1               ; <i32> [#uses=1]
+       %tmp3 = icmp slt i32 %tmp1not, %tmp2not         ; <i1> [#uses=1]
+       %retval67 = zext i1 %tmp3 to i8         ; <i8> [#uses=1]
+       ret i8 %retval67
+}
+
index 9ee8b068450ad714c5d44fea9bc10717774d295c..da6d710f6bc26af4f45c9085132da256d1e2efad 100644 (file)
@@ -134,3 +134,13 @@ define i1 @test21(i32 %g, i32 %h) {
        %tmp.4 = icmp ne i32 %tmp.2, %g         ; <i1> [#uses=1]
        ret i1 %tmp.4
 }
+
+; PR2298
+define i8 @test22(i32 %a, i32 %b) zeroext nounwind  {
+       %tmp2 = sub i32 0, %a           ; <i32> [#uses=1]
+       %tmp4 = sub i32 0, %b           ; <i32> [#uses=1]
+       %tmp5 = icmp eq i32 %tmp2, %tmp4                ; <i1> [#uses=1]
+       %retval89 = zext i1 %tmp5 to i8         ; <i8> [#uses=1]
+       ret i8 %retval89
+}
+