Skip to content

Commit 07d7748

Browse files
committed
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
1 parent b30ce3e commit 07d7748

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,8 +2356,20 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
23562356
// Try not to increase register pressure.
23572357
BO0->hasOneUse() && BO1->hasOneUse()) {
23582358
// Determine Y and Z in the form icmp (X+Y), (X+Z).
2359-
Value *Y = (A == C || A == D) ? B : A;
2360-
Value *Z = (C == A || C == B) ? D : C;
2359+
Value *Y, *Z;
2360+
if (A == C) {
2361+
Y = B;
2362+
Z = D;
2363+
} else if (A == D) {
2364+
Y = B;
2365+
Z = C;
2366+
} else if (B == C) {
2367+
Y = A;
2368+
Z = D;
2369+
} else if (B == D) {
2370+
Y = A;
2371+
Z = C;
2372+
}
23612373
return new ICmpInst(Pred, Y, Z);
23622374
}
23632375

test/Transforms/InstCombine/icmp.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,21 @@ define i1 @test64(i8 %a, i32 %b) nounwind {
659659
; CHECK-NEXT: %c = icmp eq i8 %1, %a
660660
; CHECK-NEXT: ret i1 %c
661661
}
662+
663+
define i1 @test65(i64 %A, i64 %B) {
664+
%s1 = add i64 %A, %B
665+
%s2 = add i64 %A, %B
666+
%cmp = icmp eq i64 %s1, %s2
667+
; CHECK: @test65
668+
; CHECK-NEXT: ret i1 true
669+
ret i1 %cmp
670+
}
671+
672+
define i1 @test66(i64 %A, i64 %B) {
673+
%s1 = add i64 %A, %B
674+
%s2 = add i64 %B, %A
675+
%cmp = icmp eq i64 %s1, %s2
676+
; CHECK: @test66
677+
; CHECK-NEXT: ret i1 true
678+
ret i1 %cmp
679+
}

0 commit comments

Comments
 (0)