1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -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: [[TMP1:%.*]] = icmp ugt i8 [[X:%.*]], 3
20 ; CHECK-NEXT: ret i1 [[TMP1]]
23 %ret = icmp ult i8 %tmp0, %x
27 define i1 @pv(i8 %x, i8 %y) {
29 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
30 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i8 [[TMP0]], [[X:%.*]]
31 ; CHECK-NEXT: ret i1 [[TMP1]]
33 %tmp0 = lshr i8 -1, %y
34 %tmp1 = and i8 %tmp0, %x
35 %ret = icmp ult 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: [[TMP1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 3>
46 ; CHECK-NEXT: ret <2 x i1> [[TMP1]]
48 %tmp0 = and <2 x i8> %x, <i8 3, i8 3>
49 %ret = icmp ult <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: [[TMP1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 15>
56 ; CHECK-NEXT: ret <2 x i1> [[TMP1]]
58 %tmp0 = and <2 x i8> %x, <i8 3, i8 15> ; doesn't have to be splat.
59 %ret = icmp ult <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: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 0>
66 ; CHECK-NEXT: [[RET:%.*]] = icmp ult <2 x i8> [[TMP0]], [[X]]
67 ; CHECK-NEXT: ret <2 x i1> [[RET]]
69 %tmp0 = and <2 x i8> %x, <i8 3, i8 0>
70 %ret = icmp ult <2 x i8> %tmp0, %x
74 define <2 x i1> @p2_vec_nonsplat_edgecase1(<2 x i8> %x) {
75 ; CHECK-LABEL: @p2_vec_nonsplat_edgecase1(
76 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i8> [[X:%.*]], <i8 3, i8 -1>
77 ; CHECK-NEXT: ret <2 x i1> [[TMP1]]
79 %tmp0 = and <2 x i8> %x, <i8 3, i8 -1>
80 %ret = icmp ult <2 x i8> %tmp0, %x
84 define <3 x i1> @p3_vec_splat_undef(<3 x i8> %x) {
85 ; CHECK-LABEL: @p3_vec_splat_undef(
86 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <3 x i8> [[X:%.*]], <i8 3, i8 undef, i8 3>
87 ; CHECK-NEXT: ret <3 x i1> [[TMP1]]
89 %tmp0 = and <3 x i8> %x, <i8 3, i8 undef, i8 3>
90 %ret = icmp ult <3 x i8> %tmp0, %x
94 ; ============================================================================ ;
95 ; Commutativity tests.
96 ; ============================================================================ ;
100 ; The pattern is not commutative. instsimplify will already take care of it.
103 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
104 ; CHECK-NEXT: ret i1 false
108 %ret = icmp ult i8 %x, %tmp0 ; swapped order
112 ; ============================================================================ ;
113 ; Commutativity tests with variable
114 ; ============================================================================ ;
116 define i1 @cv0(i8 %y) {
118 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
119 ; CHECK-NEXT: [[TMP0:%.*]] = lshr i8 -1, [[Y:%.*]]
120 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], [[TMP0]]
121 ; CHECK-NEXT: ret i1 [[TMP1]]
124 %tmp0 = lshr i8 -1, %y
125 %tmp1 = and i8 %x, %tmp0 ; swapped order
126 %ret = icmp ult i8 %tmp1, %x
130 define i1 @cv1(i8 %y) {
132 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
133 ; CHECK-NEXT: ret i1 false
136 %tmp0 = lshr i8 -1, %y
137 %tmp1 = and i8 %tmp0, %x
138 %ret = icmp ult i8 %x, %tmp1 ; swapped order
142 define i1 @cv2(i8 %y) {
144 ; CHECK-NEXT: [[X:%.*]] = call i8 @gen8()
145 ; CHECK-NEXT: ret i1 false
148 %tmp0 = lshr i8 -1, %y
149 %tmp1 = and i8 %x, %tmp0 ; swapped order
150 %ret = icmp ult i8 %x, %tmp1 ; swapped order
154 ; ============================================================================ ;
155 ; One-use tests. We don't care about multi-uses here.
156 ; ============================================================================ ;
158 declare void @use8(i8)
160 define i1 @oneuse0(i8 %x) {
161 ; CHECK-LABEL: @oneuse0(
162 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
163 ; CHECK-NEXT: call void @use8(i8 [[TMP0]])
164 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i8 [[X]], 3
165 ; CHECK-NEXT: ret i1 [[TMP1]]
168 call void @use8(i8 %tmp0)
169 %ret = icmp ult i8 %tmp0, %x
173 ; ============================================================================ ;
175 ; ============================================================================ ;
177 define i1 @n0(i8 %x) {
179 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 4
180 ; CHECK-NEXT: [[RET:%.*]] = icmp ult i8 [[TMP0]], [[X]]
181 ; CHECK-NEXT: ret i1 [[RET]]
183 %tmp0 = and i8 %x, 4 ; power-of-two, but invalid.
184 %ret = icmp ult i8 %tmp0, %x
188 define i1 @n1(i8 %x, i8 %y, i8 %notx) {
190 ; CHECK-NEXT: [[TMP0:%.*]] = and i8 [[X:%.*]], 3
191 ; CHECK-NEXT: [[RET:%.*]] = icmp ult i8 [[TMP0]], [[NOTX:%.*]]
192 ; CHECK-NEXT: ret i1 [[RET]]
195 %ret = icmp ult i8 %tmp0, %notx ; not %x
199 define <2 x i1> @n2(<2 x i8> %x) {
201 ; CHECK-NEXT: [[TMP0:%.*]] = and <2 x i8> [[X:%.*]], <i8 3, i8 16>
202 ; CHECK-NEXT: [[RET:%.*]] = icmp ult <2 x i8> [[TMP0]], [[X]]
203 ; CHECK-NEXT: ret <2 x i1> [[RET]]
205 %tmp0 = and <2 x i8> %x, <i8 3, i8 16> ; only the first one is valid.
206 %ret = icmp ult <2 x i8> %tmp0, %x