llvm.org GIT mirror llvm / 07d7748
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@168447 91177308-0d34-0410-b5e6-96231b3b80d8 Pawel Wodnicki 6 years ago
2 changed file(s) with 32 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
23552355 // Try not to increase register pressure.
23562356 BO0->hasOneUse() && BO1->hasOneUse()) {
23572357 // Determine Y and Z in the form icmp (X+Y), (X+Z).
2358 Value *Y = (A == C || A == D) ? B : A;
2359 Value *Z = (C == A || C == B) ? D : C;
2358 Value *Y, *Z;
2359 if (A == C) {
2360 Y = B;
2361 Z = D;
2362 } else if (A == D) {
2363 Y = B;
2364 Z = C;
2365 } else if (B == C) {
2366 Y = A;
2367 Z = D;
2368 } else if (B == D) {
2369 Y = A;
2370 Z = C;
2371 }
23602372 return new ICmpInst(Pred, Y, Z);
23612373 }
23622374
658658 ; CHECK-NEXT: %c = icmp eq i8 %1, %a
659659 ; CHECK-NEXT: ret i1 %c
660660 }
661
662 define i1 @test65(i64 %A, i64 %B) {
663 %s1 = add i64 %A, %B
664 %s2 = add i64 %A, %B
665 %cmp = icmp eq i64 %s1, %s2
666 ; CHECK: @test65
667 ; CHECK-NEXT: ret i1 true
668 ret i1 %cmp
669 }
670
671 define i1 @test66(i64 %A, i64 %B) {
672 %s1 = add i64 %A, %B
673 %s2 = add i64 %B, %A
674 %cmp = icmp eq i64 %s1, %s2
675 ; CHECK: @test66
676 ; CHECK-NEXT: ret i1 true
677 ret i1 %cmp
678 }