[InstCombine] add/move tests for or-of-icmps; NFC

If we had these tests, the bug caused by https://reviews.llvm.org/rL299851 would have been caught sooner.
There's also an assert in the code that should have caught that bug, but the assert line itself has a bug.

llvm-svn: 300201
This commit is contained in:
Sanjay Patel 2017-04-13 15:46:39 +00:00
parent 85a530fb59
commit 104e36a0e9
2 changed files with 61 additions and 26 deletions

View File

@ -1123,19 +1123,6 @@ define i1 @test68(i32 %x) {
ret i1 %cmp
}
; PR14708
define i1 @test69(i32 %c) {
; CHECK-LABEL: @test69(
; CHECK-NEXT: [[TMP1:%.*]] = or i32 %c, 32
; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 97
; CHECK-NEXT: ret i1 [[TMP2]]
;
%1 = icmp eq i32 %c, 97
%2 = icmp eq i32 %c, 65
%3 = or i1 %1, %2
ret i1 %3
}
; PR15940
define i1 @test70(i32 %X) {
; CHECK-LABEL: @test70(

View File

@ -207,31 +207,79 @@ define <2 x i1> @test18vec(<2 x i32> %A) {
ret <2 x i1> %D
}
define i1 @test19(i32 %A) {
; CHECK-LABEL: @test19(
; CHECK-NEXT: [[TMP1:%.*]] = or i32 %A, 1
; if LHSC and RHSC differ only by one bit:
; (A == C1 || A == C2) -> (A | (C1 ^ C2)) == C2
; PR14708: https://bugs.llvm.org/show_bug.cgi?id=14708
define i1 @cmp_eq_with_one_bit_diff_constants1(i32 %x) {
; CHECK-LABEL: @cmp_eq_with_one_bit_diff_constants1(
; CHECK-NEXT: [[TMP1:%.*]] = or i32 %x, 1
; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 51
; CHECK-NEXT: ret i1 [[TMP2]]
;
%B = icmp eq i32 %A, 50
%C = icmp eq i32 %A, 51
%D = or i1 %B, %C
ret i1 %D
%cmp1 = icmp eq i32 %x, 50
%cmp2 = icmp eq i32 %x, 51
%or = or i1 %cmp1, %cmp2
ret i1 %or
}
; The constants are not necessarily off-by-one, just off-by-one-bit.
define i1 @cmp_eq_with_one_bit_diff_constants2(i32 %x) {
; CHECK-LABEL: @cmp_eq_with_one_bit_diff_constants2(
; CHECK-NEXT: [[TMP1:%.*]] = or i32 %x, 32
; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 97
; CHECK-NEXT: ret i1 [[TMP2]]
;
%cmp1 = icmp eq i32 %x, 97
%cmp2 = icmp eq i32 %x, 65
%or = or i1 %cmp1, %cmp2
ret i1 %or
}
; Make sure the constants are treated as unsigned when comparing them.
define i1 @cmp_eq_with_one_bit_diff_constants3(i8 %x) {
; CHECK-LABEL: @cmp_eq_with_one_bit_diff_constants3(
; CHECK-NEXT: [[TMP1:%.*]] = or i8 %x, -128
; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], -2
; CHECK-NEXT: ret i1 [[TMP2]]
;
%cmp1 = icmp eq i8 %x, 254
%cmp2 = icmp eq i8 %x, 126
%or = or i1 %cmp1, %cmp2
ret i1 %or
}
; Use an 'add' to eliminate an icmp if the constants are off-by-one (not off-by-one-bit).
; (X == 13 | X == 14) -> X-13 <u 2
define i1 @cmp_eq_with_diff_one(i8 %x) {
; CHECK-LABEL: @cmp_eq_with_diff_one(
; CHECK-NEXT: [[X_OFF:%.*]] = add i8 %x, -13
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[X_OFF]], 2
; CHECK-NEXT: ret i1 [[TMP1]]
;
%cmp1 = icmp eq i8 %x, 13
%cmp2 = icmp eq i8 %x, 14
%or = or i1 %cmp1, %cmp2
ret i1 %or
}
; Make sure the constants are treated as signed when comparing them.
; PR32524: https://bugs.llvm.org/show_bug.cgi?id=32524
define i1 @or_icmps_eq_diff1(i32 %x) {
; CHECK-LABEL: @or_icmps_eq_diff1(
define i1 @cmp_eq_with_diff_one_signed(i32 %x) {
; CHECK-LABEL: @cmp_eq_with_diff_one_signed(
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 %x, -1
; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 %x, 0
; CHECK-NEXT: [[LOGIC:%.*]] = or i1 [[CMP1]], [[CMP2]]
; CHECK-NEXT: ret i1 [[LOGIC]]
; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP1]], [[CMP2]]
; CHECK-NEXT: ret i1 [[OR]]
;
%cmp1 = icmp eq i32 %x, -1
%cmp2 = icmp eq i32 %x, 0
%logic = or i1 %cmp1, %cmp2
ret i1 %logic
%or = or i1 %cmp1, %cmp2
ret i1 %or
}
define i32 @test20(i32 %x) {