[llvm-branch-commits] [llvm-branch] r168447 - in /llvm/branches/release_32: ./ lib/Transforms/InstCombine/InstCombineCompares.cpp test/Transforms/InstCombine/icmp.ll

Pawel Wodnicki pawel at 32bitmicro.com
Wed Nov 21 11:01:53 PST 2012


Author: pawel
Date: Wed Nov 21 13:01:53 2012
New Revision: 168447

URL: http://llvm.org/viewvc/llvm-project?rev=168447&view=rev
Log:
Merging r168181: into 3.2 release branch.

Fix PR14361: wrong simplification of A+B==B+A.  You may think that the old logic
replaced by this patch is equivalent to the new logic, but you'd be wrong, and
that's exactly where the bug was.  There's a similar bug in instsimplify which
manifests itself as instsimplify failing to simplify this, rather than doing it
wrong, see next commit.

Modified:
    llvm/branches/release_32/   (props changed)
    llvm/branches/release_32/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/branches/release_32/test/Transforms/InstCombine/icmp.ll

Propchange: llvm/branches/release_32/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Nov 21 13:01:53 2012
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,167718-167719,167731,167737,167743,167750,167784,167811,167817,167855,167860-167864,167875,167942,167948,167966,168001,168035,168189,168197-168198,168227,168316,168319,168346,168352,168361
+/llvm/trunk:155241,167718-167719,167731,167737,167743,167750,167784,167811,167817,167855,167860-167864,167875,167942,167948,167966,168001,168035,168181,168189,168197-168198,168227,168316,168319,168346,168352,168361

Modified: llvm/branches/release_32/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_32/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=168447&r1=168446&r2=168447&view=diff
==============================================================================
--- llvm/branches/release_32/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/branches/release_32/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Nov 21 13:01:53 2012
@@ -2356,8 +2356,20 @@
         // Try not to increase register pressure.
         BO0->hasOneUse() && BO1->hasOneUse()) {
       // Determine Y and Z in the form icmp (X+Y), (X+Z).
-      Value *Y = (A == C || A == D) ? B : A;
-      Value *Z = (C == A || C == B) ? D : C;
+      Value *Y, *Z;
+      if (A == C) {
+        Y = B;
+        Z = D;
+      } else if (A == D) {
+        Y = B;
+        Z = C;
+      } else if (B == C) {
+        Y = A;
+        Z = D;
+      } else if (B == D) {
+        Y = A;
+        Z = C;
+      }
       return new ICmpInst(Pred, Y, Z);
     }
 

Modified: llvm/branches/release_32/test/Transforms/InstCombine/icmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_32/test/Transforms/InstCombine/icmp.ll?rev=168447&r1=168446&r2=168447&view=diff
==============================================================================
--- llvm/branches/release_32/test/Transforms/InstCombine/icmp.ll (original)
+++ llvm/branches/release_32/test/Transforms/InstCombine/icmp.ll Wed Nov 21 13:01:53 2012
@@ -659,3 +659,21 @@
 ; CHECK-NEXT: %c = icmp eq i8 %1, %a
 ; CHECK-NEXT: ret i1 %c
 }
+
+define i1 @test65(i64 %A, i64 %B) {
+  %s1 = add i64 %A, %B
+  %s2 = add i64 %A, %B
+  %cmp = icmp eq i64 %s1, %s2
+; CHECK: @test65
+; CHECK-NEXT: ret i1 true
+  ret i1 %cmp
+}
+
+define i1 @test66(i64 %A, i64 %B) {
+  %s1 = add i64 %A, %B
+  %s2 = add i64 %B, %A
+  %cmp = icmp eq i64 %s1, %s2
+; CHECK: @test66
+; CHECK-NEXT: ret i1 true
+  ret i1 %cmp
+}





More information about the llvm-branch-commits mailing list