1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; https://bugs.llvm.org/show_bug.cgi?id=38123
8 ; Should be transformed into:
10 ; Iff: isPowerOf2(C + 1)
13 ; ============================================================================ ;
14 ; Basic positive tests
15 ; ============================================================================ ;
17 define i1 @p0(i8 %x) {
19 ; CHECK-NEXT: [[RET:%.*]] = icmp ult i8 [[X:%.*]], 4
20 ; CHECK-NEXT: ret i1 [[RET]]
23 %ret = icmp uge i8 %tmp0, %x
27 define i1 @pv(i8 %x, i8 %y) {
29 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
30 ; CHECK-NEXT: [[RET:%.*]] = icmp ule i8 [[X:%.*]], [[TMP0]]
31 ; CHECK-NEXT: ret i1 [[RET]]
33 %tmp0 = lshr i8 -1, %y
34 %tmp1 = and i8 %tmp0, %x
35 %ret = icmp uge i8 %tmp1, %x
39 ; ============================================================================ ;
41 ; ============================================================================ ;
43 define <2 x i1> @p1_vec_splat(<2 x i8> %x) {
44 ; CHECK-LABEL: @p1_vec_splat(
45 ; CHECK-NEXT: [[RET:%.*]] = icmp ult <2 x i8> [[X:%.*]], splat (i8 4)
46 ; CHECK-NEXT: ret <2 x i1> [[RET]]
48 %tmp0 = and <2 x i8> %x, <i8 3, i8 3>
49 %ret = icmp uge <2 x i8> %tmp0, %x
53 define <2 x i1> @p2_vec_nonsplat(<2 x i8> %x) {
54 ; CHECK-LABEL: @p2_vec_nonsplat(
55 ; CHECK-NEXT: [[RET:%.*]] = icmp ult <2 x i8> [[X:%.*]], <i8 4, i8 16>
56 ; CHECK-NEXT: ret <2 x i1> [[RET]]
58 %tmp0 = and <2 x i8> %x, <i8 3, i8 15> ; doesn't have to be splat.
59 %ret = icmp uge <2 x i8> %tmp0, %x
63 define <2 x i1> @p2_vec_nonsplat_edgecase0(<2 x i8> %x) {
64 ; CHECK-LABEL: @p2_vec_nonsplat_edgecase0(
65 ; CHECK-NEXT: [[RET:%.*]] = icmp ult <2 x i8> [[X:%.*]], <i8 4, i8 1>
66 ; CHECK-NEXT: ret <2 x i1> [[RET]]
68 %tmp0 = and <2 x i8> %x, <i8 3, i8 0>
69 %ret = icmp uge <2 x i8> %tmp0, %x
72 define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) {
73 ; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(
74 ; CHECK-NEXT: [[RET:%.*]] = icmp ule <2 x i8> [[X:%.*]], <i8 3, i8 -1>
75 ; CHECK-NEXT: ret <2 x i1> [[RET]]
77 %tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
78 %ret = icmp uge <2 x i8> %tmp0, %x
82 define <3 x i1> @p3_vec_splat_poison(<3 x i8> %x) {
83 ; CHECK-LABEL: @p3_vec_splat_poison(
84 ; CHECK-NEXT: [[RET:%.*]] = icmp ult <3 x i8> [[X:%.*]], splat (i8 4)
85 ; CHECK-NEXT: ret <3 x i1> [[RET]]
87 %tmp0 = and <3 x i8> %x, <i8 3, i8 poison, i8 3>
88 %ret = icmp uge <3 x i8> %tmp0, %x
92 ; ============================================================================ ;
93 ; Commutativity tests.
94 ; ============================================================================ ;
98 ; The pattern is not commutative. instsimplify will already take care of it.
101 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
102 ; CHECK-NEXT: ret i1 true
106 %ret = icmp uge i8 %x, %tmp0 ; swapped order
110 ; ============================================================================ ;
111 ; Commutativity tests with variable
112 ; ============================================================================ ;
114 define i1 @cv0(i8 %y) {
116 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
117 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
118 ; CHECK-NEXT: [[RET:%.*]] = icmp ule i8 [[X]], [[TMP0]]
119 ; CHECK-NEXT: ret i1 [[RET]]
122 %tmp0 = lshr i8 -1, %y
123 %tmp1 = and i8 %x, %tmp0 ; swapped order
124 %ret = icmp uge i8 %tmp1, %x
128 define i1 @cv1(i8 %y) {
130 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
131 ; CHECK-NEXT: ret i1 true
134 %tmp0 = lshr i8 -1, %y
135 %tmp1 = and i8 %tmp0, %x
136 %ret = icmp uge i8 %x, %tmp1 ; swapped order
140 define i1 @cv2(i8 %y) {
142 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
143 ; CHECK-NEXT: ret i1 true
146 %tmp0 = lshr i8 -1, %y
147 %tmp1 = and i8 %x, %tmp0 ; swapped order
148 %ret = icmp uge i8 %x, %tmp1 ; swapped order
152 ; ============================================================================ ;
153 ; One-use tests. We don't care about multi-uses here.
154 ; ============================================================================ ;
156 declare void @use8(i8)
158 define i1 @oneuse0(i8 %x) {
159 ; CHECK-LABEL: @oneuse0(
160 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
161 ; CHECK-NEXT: call void @use8(i8 [[TMP0]])
162 ; CHECK-NEXT: [[RET:%.*]] = icmp ult i8 [[X]], 4
163 ; CHECK-NEXT: ret i1 [[RET]]
166 call void @use8(i8 %tmp0)
167 %ret = icmp uge i8 %tmp0, %x
171 ; ============================================================================ ;
173 ; ============================================================================ ;
175 define i1 @n0(i8 %x) {
177 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -5
178 ; CHECK-NEXT: [[RET:%.*]] = icmp eq i8 [[TMP1]], 0
179 ; CHECK-NEXT: ret i1 [[RET]]
181 %tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
182 %ret = icmp uge i8 %tmp0, %x
186 define i1 @n1(i8 %x, i8 %y, i8 %notx) {
188 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
189 ; CHECK-NEXT: [[RET:%.*]] = icmp uge i8 [[TMP0]], [[NOTX:%.*]]
190 ; CHECK-NEXT: ret i1 [[RET]]
193 %ret = icmp uge i8 %tmp0, %notx ; not %x
197 define <2 x i1> @n2(<2 x i8> %x) {
199 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -4, i8 -17>
200 ; CHECK-NEXT: [[RET:%.*]] = icmp eq <2 x i8> [[TMP1]], zeroinitializer
201 ; CHECK-NEXT: ret <2 x i1> [[RET]]
203 %tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.
204 %ret = icmp uge <2 x i8> %tmp0, %x