Skip to content

Commit 077cee5

Browse files
committed
Merging r168186: into the 3.2 release branch.
InstructionSimplify should be able to simplify A+B==B+A to 'true' but wasn't due to the same logic bug that caused PR14361. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@168593 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 12c349d commit 077cee5

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/Analysis/InstructionSimplify.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,20 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
20652065
if (A && C && (A == C || A == D || B == C || B == D) &&
20662066
NoLHSWrapProblem && NoRHSWrapProblem) {
20672067
// Determine Y and Z in the form icmp (X+Y), (X+Z).
2068-
Value *Y = (A == C || A == D) ? B : A;
2069-
Value *Z = (C == A || C == B) ? D : C;
2068+
Value *Y, *Z;
2069+
if (A == C) {
2070+
Y = B;
2071+
Z = D;
2072+
} else if (A == D) {
2073+
Y = B;
2074+
Z = C;
2075+
} else if (B == C) {
2076+
Y = A;
2077+
Z = D;
2078+
} else if (B == D) {
2079+
Y = A;
2080+
Z = C;
2081+
}
20702082
if (Value *V = SimplifyICmpInst(Pred, Y, Z, Q, MaxRecurse-1))
20712083
return V;
20722084
}

test/Transforms/InstSimplify/compare.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,15 @@ define i1 @add5(i32 %x, i32 %y) {
266266
; CHECK: ret i1 true
267267
}
268268

269+
define i1 @add6(i64 %A, i64 %B) {
270+
; CHECK: @add6
271+
%s1 = add i64 %A, %B
272+
%s2 = add i64 %B, %A
273+
%cmp = icmp eq i64 %s1, %s2
274+
ret i1 %cmp
275+
; CHECK: ret i1 true
276+
}
277+
269278
define i1 @addpowtwo(i32 %x, i32 %y) {
270279
; CHECK: @addpowtwo
271280
%l = lshr i32 %x, 1

0 commit comments

Comments
 (0)