Skip to content

Commit

Permalink
Fix PR14361: wrong simplification of A+B==B+A. You may think that the…
Browse files Browse the repository at this point in the history
… 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/trunk@168181 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
CunningBaldrick committed Nov 16, 2012
1 parent 661dfdc commit afe4539
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2356,8 +2356,20 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
// 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);
}

Expand Down
18 changes: 18 additions & 0 deletions test/Transforms/InstCombine/icmp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,21 @@ define i1 @test64(i8 %a, i32 %b) nounwind {
; 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
}

0 comments on commit afe4539

Please sign in to comment.