Skip to content

Commit

Permalink
add tests for icmp vector folds
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276472 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rotateright committed Jul 22, 2016
1 parent 3b6613c commit b5911c2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
37 changes: 37 additions & 0 deletions test/Transforms/InstCombine/add.ll
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ define i1 @test10(i8 %A, i8 %b) {
ret i1 %c
}

; FIXME: Vectors should fold the same way.

define <2 x i1> @test10vec(<2 x i8> %a, <2 x i8> %b) {
; CHECK-LABEL: @test10vec(
; CHECK-NEXT: [[C:%.*]] = add <2 x i8> %a, %b
; CHECK-NEXT: [[D:%.*]] = icmp ne <2 x i8> [[C]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[D]]
;
%c = add <2 x i8> %a, %b
%d = icmp ne <2 x i8> %c, zeroinitializer
ret <2 x i1> %d
}

define i1 @test11(i8 %A) {
; CHECK-LABEL: @test11(
; CHECK-NEXT: [[C:%.*]] = icmp ne i8 %A, 1
Expand All @@ -120,6 +133,18 @@ define i1 @test11(i8 %A) {
ret i1 %c
}

; FIXME: Vectors should fold the same way.
define <2 x i1> @test11vec(<2 x i8> %a) {
; CHECK-LABEL: @test11vec(
; CHECK-NEXT: [[B:%.*]] = add <2 x i8> %a, <i8 -1, i8 -1>
; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i8> [[B]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = add <2 x i8> %a, <i8 -1, i8 -1>
%c = icmp ne <2 x i8> %b, zeroinitializer
ret <2 x i1> %c
}

; Should be transformed into shl A, 1?

define i32 @test12(i32 %A, i32 %B) {
Expand Down Expand Up @@ -243,6 +268,18 @@ define i1 @test21(i32 %x) {
ret i1 %y
}

; FIXME: Vectors should fold the same way.
define <2 x i1> @test21vec(<2 x i32> %x) {
; CHECK-LABEL: @test21vec(
; CHECK-NEXT: [[T:%.*]] = add <2 x i32> %x, <i32 4, i32 4>
; CHECK-NEXT: [[Y:%.*]] = icmp eq <2 x i32> [[T]], <i32 123, i32 123>
; CHECK-NEXT: ret <2 x i1> [[Y]]
;
%t = add <2 x i32> %x, <i32 4, i32 4>
%y = icmp eq <2 x i32> %t, <i32 123, i32 123>
ret <2 x i1> %y
}

define i32 @test22(i32 %V) {
; CHECK-LABEL: @test22(
; CHECK-NEXT: switch i32 %V, label %Default [
Expand Down
38 changes: 32 additions & 6 deletions test/Transforms/InstCombine/xor.ll
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@ define i1 @test9(i8 %A) {
ret i1 %C
}

; FIXME: Vectors should fold the same way.

define <2 x i1> @test9vec(<2 x i8> %a) {
; CHECK-LABEL: @test9vec(
; CHECK-NEXT: [[B:%.*]] = xor <2 x i8> %a, <i8 123, i8 123>
; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i8> [[B]], <i8 34, i8 34>
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = xor <2 x i8> %a, <i8 123, i8 123>
%c = icmp eq <2 x i8> %b, <i8 34, i8 34>
ret <2 x i1> %c
}

define i8 @test10(i8 %A) {
; CHECK-LABEL: @test10(
; CHECK-NEXT: [[B:%.*]] = and i8 %A, 3
Expand Down Expand Up @@ -137,6 +150,19 @@ define i1 @test12(i8 %A) {
ret i1 %c
}

; FIXME: Vectors should fold the same way.

define <2 x i1> @test12vec(<2 x i8> %a) {
; CHECK-LABEL: @test12vec(
; CHECK-NEXT: [[B:%.*]] = xor <2 x i8> %a, <i8 4, i8 4>
; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i8> [[B]], zeroinitializer
; CHECK-NEXT: ret <2 x i1> [[C]]
;
%b = xor <2 x i8> %a, <i8 4, i8 4>
%c = icmp ne <2 x i8> %b, zeroinitializer
ret <2 x i1> %c
}

define i1 @test13(i8 %A, i8 %B) {
; CHECK-LABEL: @test13(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i8 %A, %B
Expand Down Expand Up @@ -233,8 +259,8 @@ define i32 @test21(i1 %C, i32 %A, i32 %B) {

define i32 @test22(i1 %X) {
; CHECK-LABEL: @test22(
; CHECK-NEXT: [[TMP1:%.*]] = zext i1 %X to i32
; CHECK-NEXT: ret i32 [[TMP1]]
; CHECK-NEXT: [[Z:%.*]] = zext i1 %X to i32
; CHECK-NEXT: ret i32 [[Z]]
;
%Y = xor i1 %X, true
%Z = zext i1 %Y to i32
Expand All @@ -246,8 +272,8 @@ define i32 @test22(i1 %X) {

define i32 @fold_zext_xor_sandwich(i1 %X) {
; CHECK-LABEL: @fold_zext_xor_sandwich(
; CHECK-NEXT: [[TMP1:%.*]] = zext i1 %X to i32
; CHECK-NEXT: [[Q:%.*]] = xor i32 [[TMP1]], 3
; CHECK-NEXT: [[Z:%.*]] = zext i1 %X to i32
; CHECK-NEXT: [[Q:%.*]] = xor i32 [[Z]], 3
; CHECK-NEXT: ret i32 [[Q]]
;
%Y = xor i1 %X, true
Expand All @@ -258,8 +284,8 @@ define i32 @fold_zext_xor_sandwich(i1 %X) {

define <2 x i32> @fold_zext_xor_sandwich_vec(<2 x i1> %X) {
; CHECK-LABEL: @fold_zext_xor_sandwich_vec(
; CHECK-NEXT: [[TMP1:%.*]] = zext <2 x i1> %X to <2 x i32>
; CHECK-NEXT: [[Q:%.*]] = xor <2 x i32> [[TMP1]], <i32 3, i32 3>
; CHECK-NEXT: [[Z:%.*]] = zext <2 x i1> %X to <2 x i32>
; CHECK-NEXT: [[Q:%.*]] = xor <2 x i32> [[Z]], <i32 3, i32 3>
; CHECK-NEXT: ret <2 x i32> [[Q]]
;
%Y = xor <2 x i1> %X, <i1 true, i1 true>
Expand Down

0 comments on commit b5911c2

Please sign in to comment.