1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[NFC][InstCombine] Revisit canonicalize-constant-low-bit-mask-and-icmp-s* tests in preparatio for PR42198.

The `icmp sgt`/`icmp sle` variants are, too, miscompiles:
https://rise4fun.com/Alive/JFNP
https://rise4fun.com/Alive/jHvL
A precondition 'x != 0' was forgotten by me.

While ensuring test coverage for `-1`, also add test coverage
for `0` mask. Mask `0` is allowed for all the folds,
mask `-1` is allowed for all the folds with unsigned `icmp` pred.
Constant mask `0` is missed though.

https://bugs.llvm.org/show_bug.cgi?id=42198

llvm-svn: 362910
This commit is contained in:
Roman Lebedev 2019-06-09 16:30:14 +00:00
parent 836775cb4b
commit 08f625dc49
10 changed files with 451 additions and 227 deletions

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x u<= C
; Iff: isPowerOf2(C + 1)
; C can be 0 and -1.
; ============================================================================ ;
; Basic positive tests
@ -59,6 +60,26 @@ define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase0(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase0(
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp eq <2 x i8> [[TMP0]], [[X]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp eq <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ule <2 x i8> [[X:%.*]], <i8 3, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp eq <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <3 x i8> [[X:%.*]], <i8 4, i8 undef, i8 4>

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x u> C
; Iff: isPowerOf2(C + 1)
; C can be 0 and -1.
; ============================================================================ ;
; Basic positive tests
@ -59,6 +60,26 @@ define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase0(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase0(
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp ne <2 x i8> [[TMP0]], [[X]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp ne <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp ne <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x s<= C
; Iff: isPowerOf2(C + 1)
; C must not be -1, but may be 0.
; ============================================================================ ;
; Basic positive tests
@ -47,6 +48,17 @@ define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase(
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp sge <2 x i8> [[TMP0]], [[X]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp sge <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <3 x i8> [[X:%.*]], <i8 4, i8 undef, i8 4>
@ -80,9 +92,7 @@ define i1 @oneuse0(i8 %x) {
; Negative tests
; ============================================================================ ;
; ============================================================================ ;
; Commutativity tests.
; ============================================================================ ;
declare i8 @gen8()
@ -100,57 +110,7 @@ define i1 @c0() {
}
; ============================================================================ ;
; Commutativity tests with variable
; ============================================================================ ;
; Ok, this one should fold. We only testing commutativity of 'and'.
define i1 @cv0(i8 %y) {
; CHECK-LABEL: @cv0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[TMP1]], [[X]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %x, %tmp0 ; swapped order
%ret = icmp sge i8 %tmp1, %x
ret i1 %ret
}
define i1 @cv1(i8 %y) {
; CHECK-LABEL: @cv1(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X]]
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[X]], [[TMP1]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp sge i8 %x, %tmp1 ; swapped order
ret i1 %ret
}
define i1 @cv2(i8 %y) {
; CHECK-LABEL: @cv2(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[X]], [[TMP1]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %x, %tmp0 ; swapped order
%ret = icmp sge i8 %x, %tmp1 ; swapped order
ret i1 %ret
}
; ============================================================================ ;
; Normal negative tests
; Rest of negative tests
; ============================================================================ ;
define i1 @n0(i8 %x) {
@ -224,3 +184,50 @@ define <3 x i1> @n4_vec(<3 x i8> %x) {
%ret = icmp sge <3 x i8> %tmp0, %x
ret <3 x i1> %ret
}
; Commutativity tests with variable
define i1 @cv0(i8 %y) {
; CHECK-LABEL: @cv0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[TMP1]], [[X]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %x, %tmp0 ; swapped order
%ret = icmp sge i8 %tmp1, %x
ret i1 %ret
}
define i1 @cv1(i8 %y) {
; CHECK-LABEL: @cv1(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X]]
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[X]], [[TMP1]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp sge i8 %x, %tmp1 ; swapped order
ret i1 %ret
}
define i1 @cv2(i8 %y) {
; CHECK-LABEL: @cv2(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
; CHECK-NEXT: [[RET:%.*]] = icmp sge i8 [[X]], [[TMP1]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %x, %tmp0 ; swapped order
%ret = icmp sge i8 %x, %tmp1 ; swapped order
ret i1 %ret
}

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x s> C
; Iff: isPowerOf2(C + 1)
; C must not be -1, but may be 0.
; NOTE: this pattern is not commutative!
@ -31,20 +32,6 @@ define i1 @p0() {
ret i1 %ret
}
define i1 @pv(i8 %y) {
; CHECK-LABEL: @pv(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X]], [[TMP0]]
; CHECK-NEXT: ret i1 [[TMP1]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp sgt i8 %x, %tmp1
ret i1 %ret
}
; ============================================================================ ;
; Vector tests
; ============================================================================ ;
@ -73,6 +60,19 @@ define <2 x i1> @p2_vec_nonsplat() {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase() {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp sgt <2 x i8> [[X]], [[TMP0]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp sgt <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef() {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()
@ -110,9 +110,7 @@ define i1 @oneuse0() {
; Negative tests
; ============================================================================ ;
; ============================================================================ ;
; Commutativity tests.
; ============================================================================ ;
define i1 @c0(i8 %x) {
; CHECK-LABEL: @c0(
@ -126,9 +124,92 @@ define i1 @c0(i8 %x) {
}
; ============================================================================ ;
; Commutativity tests with variable
; Rest of negative tests
; ============================================================================ ;
define i1 @n0() {
; CHECK-LABEL: @n0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 4
; CHECK-NEXT: [[RET:%.*]] = icmp sgt i8 [[X]], [[TMP0]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
%ret = icmp sgt i8 %x, %tmp0
ret i1 %ret
}
define i1 @n1(i8 %y, i8 %notx) {
; CHECK-LABEL: @n1(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 3
; CHECK-NEXT: [[RET:%.*]] = icmp sgt i8 [[TMP0]], [[NOTX:%.*]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = and i8 %x, 3
%ret = icmp sgt i8 %tmp0, %notx ; not %x
ret i1 %ret
}
define <2 x i1> @n2() {
; CHECK-LABEL: @n2(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X]], <i8 3, i8 16>
; CHECK-NEXT: [[RET:%.*]] = icmp sgt <2 x i8> [[X]], [[TMP0]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.
%ret = icmp sgt <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
; ============================================================================ ;
; Potential miscompiles.
; ============================================================================ ;
define i1 @pv(i8 %y) {
; CHECK-LABEL: @pv(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i8 [[X]], [[TMP0]]
; CHECK-NEXT: ret i1 [[TMP1]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp sgt i8 %x, %tmp1
ret i1 %ret
}
define <2 x i1> @n3_vec() {
; CHECK-LABEL: @n3_vec(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X]], <i8 3, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp sgt <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
define <3 x i1> @n4_vec() {
; CHECK-LABEL: @n4_vec(
; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <3 x i8> [[X]], <i8 3, i8 undef, i8 -1>
; CHECK-NEXT: ret <3 x i1> [[TMP1]]
;
%x = call <3 x i8> @gen3x8()
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 -1>
%ret = icmp sgt <3 x i8> %x, %tmp0
ret <3 x i1> %ret
}
; Commutativity tests with variable
; Ok, this one should fold. We only testing commutativity of 'and'.
define i1 @cv0_GOOD(i8 %y) {
; CHECK-LABEL: @cv0_GOOD(
@ -171,46 +252,3 @@ define i1 @cv2(i8 %x, i8 %y) {
%ret = icmp sgt i8 %tmp1, %x ; swapped order
ret i1 %ret
}
; ============================================================================ ;
; Normal negative tests
; ============================================================================ ;
define i1 @n0() {
; CHECK-LABEL: @n0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 4
; CHECK-NEXT: [[RET:%.*]] = icmp sgt i8 [[X]], [[TMP0]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
%ret = icmp sgt i8 %x, %tmp0
ret i1 %ret
}
define i1 @n1(i8 %y, i8 %notx) {
; CHECK-LABEL: @n1(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 3
; CHECK-NEXT: [[RET:%.*]] = icmp sgt i8 [[TMP0]], [[NOTX:%.*]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = and i8 %x, 3
%ret = icmp sgt i8 %tmp0, %notx ; not %x
ret i1 %ret
}
define <2 x i1> @n2() {
; CHECK-LABEL: @n2(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X]], <i8 3, i8 16>
; CHECK-NEXT: [[RET:%.*]] = icmp sgt <2 x i8> [[X]], [[TMP0]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.
%ret = icmp sgt <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x s<= C
; Iff: isPowerOf2(C + 1)
; C must not be -1, but may be 0.
; NOTE: this pattern is not commutative!
@ -31,20 +32,6 @@ define i1 @p0() {
ret i1 %ret
}
define i1 @pv(i8 %y) {
; CHECK-LABEL: @pv(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = icmp sle i8 [[X]], [[TMP0]]
; CHECK-NEXT: ret i1 [[TMP1]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp sle i8 %x, %tmp1
ret i1 %ret
}
; ============================================================================ ;
; Vector tests
; ============================================================================ ;
@ -73,6 +60,19 @@ define <2 x i1> @p2_vec_nonsplat() {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase() {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp sle <2 x i8> [[X]], [[TMP0]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp sle <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef() {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()
@ -110,9 +110,7 @@ define i1 @oneuse0() {
; Negative tests
; ============================================================================ ;
; ============================================================================ ;
; Commutativity tests.
; ============================================================================ ;
define i1 @c0(i8 %x) {
; CHECK-LABEL: @c0(
@ -126,10 +124,92 @@ define i1 @c0(i8 %x) {
}
; ============================================================================ ;
; Commutativity tests with variable
; Rest of negative tests
; ============================================================================ ;
; Ok, this one should fold. We only testing commutativity of 'and'.
define i1 @n0() {
; CHECK-LABEL: @n0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 4
; CHECK-NEXT: [[RET:%.*]] = icmp sle i8 [[X]], [[TMP0]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
%ret = icmp sle i8 %x, %tmp0
ret i1 %ret
}
define i1 @n1(i8 %y, i8 %notx) {
; CHECK-LABEL: @n1(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 3
; CHECK-NEXT: [[RET:%.*]] = icmp sle i8 [[TMP0]], [[NOTX:%.*]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = and i8 %x, 3
%ret = icmp sle i8 %tmp0, %notx ; not %x
ret i1 %ret
}
define <2 x i1> @n2() {
; CHECK-LABEL: @n2(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X]], <i8 3, i8 16>
; CHECK-NEXT: [[RET:%.*]] = icmp sle <2 x i8> [[X]], [[TMP0]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.
%ret = icmp sle <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
; ============================================================================ ;
; Potential miscompiles.
; ============================================================================ ;
define i1 @pv(i8 %y) {
; CHECK-LABEL: @pv(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = icmp sle i8 [[X]], [[TMP0]]
; CHECK-NEXT: ret i1 [[TMP1]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp sle i8 %x, %tmp1
ret i1 %ret
}
define <2 x i1> @n3_vec() {
; CHECK-LABEL: @n3_vec(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <2 x i8> [[X]], <i8 4, i8 0>
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp sle <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
define <3 x i1> @n4_vec() {
; CHECK-LABEL: @n4_vec(
; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()
; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <3 x i8> [[X]], <i8 4, i8 undef, i8 0>
; CHECK-NEXT: ret <3 x i1> [[TMP1]]
;
%x = call <3 x i8> @gen3x8()
%tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 -1>
%ret = icmp sle <3 x i8> %x, %tmp0
ret <3 x i1> %ret
}
; Commutativity tests with variable
define i1 @cv0_GOOD(i8 %y) {
; CHECK-LABEL: @cv0_GOOD(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
@ -171,46 +251,3 @@ define i1 @cv2(i8 %x, i8 %y) {
%ret = icmp sle i8 %tmp1, %x ; swapped order
ret i1 %ret
}
; ============================================================================ ;
; Normal negative tests
; ============================================================================ ;
define i1 @n0() {
; CHECK-LABEL: @n0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 4
; CHECK-NEXT: [[RET:%.*]] = icmp sle i8 [[X]], [[TMP0]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
%ret = icmp sle i8 %x, %tmp0
ret i1 %ret
}
define i1 @n1(i8 %y, i8 %notx) {
; CHECK-LABEL: @n1(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X]], 3
; CHECK-NEXT: [[RET:%.*]] = icmp sle i8 [[TMP0]], [[NOTX:%.*]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = and i8 %x, 3
%ret = icmp sle i8 %tmp0, %notx ; not %x
ret i1 %ret
}
define <2 x i1> @n2() {
; CHECK-LABEL: @n2(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X]], <i8 3, i8 16>
; CHECK-NEXT: [[RET:%.*]] = icmp sle <2 x i8> [[X]], [[TMP0]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.
%ret = icmp sle <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x s> C
; Iff: isPowerOf2(C + 1)
; C must not be -1, but may be 0.
; ============================================================================ ;
; Basic positive tests
@ -47,6 +48,17 @@ define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase(
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp slt <2 x i8> [[TMP0]], [[X]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp slt <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>
@ -80,9 +92,7 @@ define i1 @oneuse0(i8 %x) {
; Negative tests
; ============================================================================ ;
; ============================================================================ ;
; Commutativity tests.
; ============================================================================ ;
declare i8 @gen8()
@ -100,57 +110,7 @@ define i1 @c0() {
}
; ============================================================================ ;
; Commutativity tests with variable
; ============================================================================ ;
; Ok, this one should fold. We only testing commutativity of 'and'.
define i1 @cv0(i8 %y) {
; CHECK-LABEL: @cv0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP1]], [[X]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %x, %tmp0 ; swapped order
%ret = icmp slt i8 %tmp1, %x
ret i1 %ret
}
define i1 @cv1(i8 %y) {
; CHECK-LABEL: @cv1(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X]]
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[X]], [[TMP1]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp slt i8 %x, %tmp1 ; swapped order
ret i1 %ret
}
define i1 @cv2(i8 %y) {
; CHECK-LABEL: @cv2(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[X]], [[TMP1]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %x, %tmp0 ; swapped order
%ret = icmp slt i8 %x, %tmp1 ; swapped order
ret i1 %ret
}
; ============================================================================ ;
; Normal negative tests
; Rest of negative tests
; ============================================================================ ;
define i1 @n0(i8 %x) {
@ -224,3 +184,50 @@ define <3 x i1> @n4(<3 x i8> %x) {
%ret = icmp slt <3 x i8> %tmp0, %x
ret <3 x i1> %ret
}
; Commutativity tests with variable
define i1 @cv0(i8 %y) {
; CHECK-LABEL: @cv0(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[TMP1]], [[X]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %x, %tmp0 ; swapped order
%ret = icmp slt i8 %tmp1, %x
ret i1 %ret
}
define i1 @cv1(i8 %y) {
; CHECK-LABEL: @cv1(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[TMP0]], [[X]]
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[X]], [[TMP1]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %tmp0, %x
%ret = icmp slt i8 %x, %tmp1 ; swapped order
ret i1 %ret
}
define i1 @cv2(i8 %y) {
; CHECK-LABEL: @cv2(
; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], [[TMP0]]
; CHECK-NEXT: [[RET:%.*]] = icmp slt i8 [[X]], [[TMP1]]
; CHECK-NEXT: ret i1 [[RET]]
;
%x = call i8 @gen8()
%tmp0 = lshr i8 -1, %y
%tmp1 = and i8 %x, %tmp0 ; swapped order
%ret = icmp slt i8 %x, %tmp1 ; swapped order
ret i1 %ret
}

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x u<= C
; Iff: isPowerOf2(C + 1)
; C can be 0 and -1.
; ============================================================================ ;
; Basic positive tests
@ -59,6 +60,26 @@ define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase0(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase0(
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp uge <2 x i8> [[TMP0]], [[X]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp uge <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ule <2 x i8> [[X:%.*]], <i8 3, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp uge <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ult <3 x i8> [[X:%.*]], <i8 4, i8 undef, i8 4>

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x u> C
; Iff: isPowerOf2(C + 1)
; C can be 0 and -1.
declare i8 @gen8()
declare <2 x i8> @gen2x8()
@ -71,6 +72,30 @@ define <2 x i1> @p2_vec_nonsplat() {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase0() {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase0(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp ugt <2 x i8> [[X]], [[TMP0]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp ugt <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase1() {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i8> [[X]], <i8 3, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp ugt <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef() {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x u<= C
; Iff: isPowerOf2(C + 1)
; C can be 0 and -1.
declare i8 @gen8()
declare <2 x i8> @gen2x8()
@ -71,6 +72,30 @@ define <2 x i1> @p2_vec_nonsplat() {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase0() {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase0(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp ule <2 x i8> [[X]], [[TMP0]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp ule <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase1() {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(
; CHECK-NEXT: [[X:%.*]] = call <2 x i8> @gen2x8()
; CHECK-NEXT: [[TMP1:%.*]] = icmp ule <2 x i8> [[X]], <i8 3, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%x = call <2 x i8> @gen2x8()
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp ule <2 x i8> %x, %tmp0
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef() {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[X:%.*]] = call <3 x i8> @gen3x8()

View File

@ -8,6 +8,7 @@
; Should be transformed into:
; x u> C
; Iff: isPowerOf2(C + 1)
; C can be 0 and -1.
; ============================================================================ ;
; Basic positive tests
@ -59,6 +60,27 @@ define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase0(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase0(
; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 0>
; CHECK-NEXT: [[RET:%.*]] = icmp ult <2 x i8> [[TMP0]], [[X]]
; CHECK-NEXT: ret <2 x i1> [[RET]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 0>
%ret = icmp ult <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) {
; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 -1>
; CHECK-NEXT: ret <2 x i1> [[TMP1]]
;
%tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
%ret = icmp ult <2 x i8> %tmp0, %x
ret <2 x i1> %ret
}
define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
; CHECK-LABEL: @p3_vec_splat_undef(
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>