xref: /llvm-project/llvm/test/Analysis/ValueTracking/knownbits-bmi-pattern.ll (revision 38fffa630ee80163dc65e759392ad29798905679)
1c8fb2775SNoah Goldstein; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2c8fb2775SNoah Goldstein; RUN: opt -S -passes=instcombine < %s | FileCheck %s
3c8fb2775SNoah Goldstein
4c8fb2775SNoah Goldsteindeclare void @llvm.assume(i1)
5c8fb2775SNoah Goldstein
6c8fb2775SNoah Goldsteindefine i1 @blsmsk_eq_is_false(i32 %x) {
7c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_eq_is_false(
8c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i1 false
9c8fb2775SNoah Goldstein;
10c8fb2775SNoah Goldstein  %x1 = or i32 %x, 10
11c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
12c8fb2775SNoah Goldstein  %x3 = xor i32 %x1, %x2
13c8fb2775SNoah Goldstein  %z = icmp eq i32 %x3, 8
14c8fb2775SNoah Goldstein  ret i1 %z
15c8fb2775SNoah Goldstein}
16c8fb2775SNoah Goldstein
17c8fb2775SNoah Goldsteindefine <2 x i1> @blsmsk_ne_is_true_vec(<2 x i32> %x) {
18c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_ne_is_true_vec(
19*38fffa63SPaul Walker; CHECK-NEXT:    ret <2 x i1> splat (i1 true)
20c8fb2775SNoah Goldstein;
21c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 10, i32 10>
22c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> %x1, <i32 1, i32 1>
23c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
24c8fb2775SNoah Goldstein  %z = icmp ne <2 x i32> %x3, <i32 8, i32 8>
25c8fb2775SNoah Goldstein  ret <2 x i1> %z
26c8fb2775SNoah Goldstein}
27c8fb2775SNoah Goldstein
28c8fb2775SNoah Goldsteindefine <2 x i1> @blsmsk_ne_is_true_diff_vec(<2 x i32> %x) {
29c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_ne_is_true_diff_vec(
30*38fffa63SPaul Walker; CHECK-NEXT:    ret <2 x i1> splat (i1 true)
31c8fb2775SNoah Goldstein;
32c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 10, i32 130>
33c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> %x1, <i32 1, i32 1>
34c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
35c8fb2775SNoah Goldstein  %z = icmp ne <2 x i32> %x3, <i32 8, i32 8>
36c8fb2775SNoah Goldstein  ret <2 x i1> %z
37c8fb2775SNoah Goldstein}
38c8fb2775SNoah Goldstein
39c8fb2775SNoah Goldsteindefine i1 @blsmsk_ge_is_false(i32 %x) {
40c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_ge_is_false(
414fcfff4fSNoah Goldstein; CHECK-NEXT:    ret i1 false
42c8fb2775SNoah Goldstein;
43c8fb2775SNoah Goldstein  %x1 = or i32 %x, 10
44c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
45c8fb2775SNoah Goldstein  %x3 = xor i32 %x1, %x2
46c8fb2775SNoah Goldstein  %z = icmp uge i32 %x3, 8
47c8fb2775SNoah Goldstein  ret i1 %z
48c8fb2775SNoah Goldstein}
49c8fb2775SNoah Goldstein
50c8fb2775SNoah Goldsteindefine <2 x i1> @blsmsk_gt_is_false_vec(<2 x i32> %x) {
51c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_gt_is_false_vec(
524fcfff4fSNoah Goldstein; CHECK-NEXT:    ret <2 x i1> zeroinitializer
53c8fb2775SNoah Goldstein;
54c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 10, i32 10>
55c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> %x1, <i32 1, i32 1>
56c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
57c8fb2775SNoah Goldstein  %z = icmp ugt <2 x i32> %x3, <i32 8, i32 8>
58c8fb2775SNoah Goldstein  ret <2 x i1> %z
59c8fb2775SNoah Goldstein}
60c8fb2775SNoah Goldstein
61c8fb2775SNoah Goldsteindefine i1 @blsmsk_signed_is_false(i32 %x) {
62c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_signed_is_false(
639a8f517fSNoah Goldstein; CHECK-NEXT:    ret i1 false
64c8fb2775SNoah Goldstein;
65c8fb2775SNoah Goldstein  %x1 = or i32 %x, 10
66c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
67c8fb2775SNoah Goldstein  %x3 = xor i32 %x1, %x2
68c8fb2775SNoah Goldstein  %z = icmp slt i32 %x3, 0
69c8fb2775SNoah Goldstein  ret i1 %z
70c8fb2775SNoah Goldstein}
71c8fb2775SNoah Goldstein
72c8fb2775SNoah Goldsteindefine i32 @blsmsk_add_eval(i32 %x) {
73c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_add_eval(
749a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 33
75c8fb2775SNoah Goldstein;
76c8fb2775SNoah Goldstein  %x1 = or i32 %x, 9
77c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
78c8fb2775SNoah Goldstein  %x3 = xor i32 %x2, %x1
79c8fb2775SNoah Goldstein  %z = add i32 %x3, 32
80c8fb2775SNoah Goldstein  ret i32 %z
81c8fb2775SNoah Goldstein}
82c8fb2775SNoah Goldstein
83c8fb2775SNoah Goldsteindefine <2 x i32> @blsmsk_add_eval_vec(<2 x i32> %x) {
84c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_add_eval_vec(
85*38fffa63SPaul Walker; CHECK-NEXT:    ret <2 x i32> splat (i32 33)
86c8fb2775SNoah Goldstein;
87c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 9, i32 9>
88c8fb2775SNoah Goldstein  %x2 = add <2 x i32> %x1, <i32 -1, i32 -1>
89c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
90c8fb2775SNoah Goldstein  %z = add <2 x i32> %x3, <i32 32, i32 32>
91c8fb2775SNoah Goldstein  ret <2 x i32> %z
92c8fb2775SNoah Goldstein}
93c8fb2775SNoah Goldstein
94c8fb2775SNoah Goldsteindefine i32 @blsmsk_sub_eval(i32 %x) {
95c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_sub_eval(
964fcfff4fSNoah Goldstein; CHECK-NEXT:    ret i32 -31
97c8fb2775SNoah Goldstein;
98c8fb2775SNoah Goldstein  %x1 = or i32 %x, 9
99c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
100c8fb2775SNoah Goldstein  %x3 = xor i32 %x1, %x2
101c8fb2775SNoah Goldstein  %z = sub i32 %x3, 32
102c8fb2775SNoah Goldstein  ret i32 %z
103c8fb2775SNoah Goldstein}
104c8fb2775SNoah Goldstein
105c8fb2775SNoah Goldsteindefine i32 @blsmsk_or_eval(i32 %x) {
106c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_or_eval(
1079a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 33
108c8fb2775SNoah Goldstein;
109c8fb2775SNoah Goldstein  %x1 = or i32 %x, 129
110c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
111c8fb2775SNoah Goldstein  %x3 = xor i32 %x2, %x1
112c8fb2775SNoah Goldstein  %z = or i32 %x3, 32
113c8fb2775SNoah Goldstein  ret i32 %z
114c8fb2775SNoah Goldstein}
115c8fb2775SNoah Goldstein
116c8fb2775SNoah Goldsteindefine <2 x i32> @blsmsk_or_eval_vec(<2 x i32> %x) {
117c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_or_eval_vec(
118*38fffa63SPaul Walker; CHECK-NEXT:    ret <2 x i32> splat (i32 33)
119c8fb2775SNoah Goldstein;
120c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 9, i32 9>
121c8fb2775SNoah Goldstein  %x2 = add <2 x i32> %x1, <i32 -1, i32 -1>
122c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
123c8fb2775SNoah Goldstein  %z = or <2 x i32> %x3, <i32 32, i32 32>
124c8fb2775SNoah Goldstein  ret <2 x i32> %z
125c8fb2775SNoah Goldstein}
126c8fb2775SNoah Goldstein
127c8fb2775SNoah Goldsteindefine i32 @blsmsk_xor_eval(i32 %x) {
128c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_xor_eval(
1299a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 33
130c8fb2775SNoah Goldstein;
131c8fb2775SNoah Goldstein  %x1 = or i32 %x, 255
132c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
133c8fb2775SNoah Goldstein  %x3 = xor i32 %x1, %x2
134c8fb2775SNoah Goldstein  %z = xor i32 %x3, 32
135c8fb2775SNoah Goldstein  ret i32 %z
136c8fb2775SNoah Goldstein}
137c8fb2775SNoah Goldstein
138c8fb2775SNoah Goldsteindefine i32 @blsmsk_and_eval(i32 %x) {
139c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_and_eval(
140c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 0
141c8fb2775SNoah Goldstein;
142c8fb2775SNoah Goldstein  %x1 = or i32 %x, 34
143c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
144c8fb2775SNoah Goldstein  %x3 = xor i32 %x2, %x1
145c8fb2775SNoah Goldstein  %z = and i32 %x3, 32
146c8fb2775SNoah Goldstein  ret i32 %z
147c8fb2775SNoah Goldstein}
148c8fb2775SNoah Goldstein
149c8fb2775SNoah Goldsteindefine <2 x i32> @blsmsk_and_eval_vec(<2 x i32> %x) {
150c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_and_eval_vec(
151c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i32> zeroinitializer
152c8fb2775SNoah Goldstein;
153c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 34, i32 34>
154c8fb2775SNoah Goldstein  %x2 = add <2 x i32> %x1, <i32 -1, i32 -1>
155c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
156c8fb2775SNoah Goldstein  %z = and <2 x i32> %x3, <i32 32, i32 32>
157c8fb2775SNoah Goldstein  ret <2 x i32> %z
158c8fb2775SNoah Goldstein}
159c8fb2775SNoah Goldstein
160c8fb2775SNoah Goldsteindefine i32 @blsmsk_and_eval2(i32 %x) {
161c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_and_eval2(
162c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X1:%.*]] = or i32 [[X:%.*]], 10
163c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = add i32 [[X1]], 63
164a1058776SNikita Popov; CHECK-NEXT:    [[X3:%.*]] = xor i32 [[X]], [[X2]]
165c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = and i32 [[X3]], 32
166c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 [[Z]]
167c8fb2775SNoah Goldstein;
168c8fb2775SNoah Goldstein  %x1 = or i32 %x, 10
169c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
170c8fb2775SNoah Goldstein  %x3 = xor i32 %x1, %x2
171c8fb2775SNoah Goldstein  %z = and i32 %x3, 32
172c8fb2775SNoah Goldstein  ret i32 %z
173c8fb2775SNoah Goldstein}
174c8fb2775SNoah Goldstein
175c8fb2775SNoah Goldsteindefine <2 x i32> @blsmsk_and_eval3_vec(<2 x i32> %x) {
176c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_and_eval3_vec(
177*38fffa63SPaul Walker; CHECK-NEXT:    [[X1:%.*]] = or <2 x i32> [[X:%.*]], splat (i32 34)
178*38fffa63SPaul Walker; CHECK-NEXT:    [[X2:%.*]] = add <2 x i32> [[X1]], splat (i32 63)
179c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = xor <2 x i32> [[X2]], [[X1]]
180c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = and <2 x i32> [[X3]], <i32 16, i32 32>
181c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i32> [[Z]]
182c8fb2775SNoah Goldstein;
183c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 34, i32 34>
184c8fb2775SNoah Goldstein  %x2 = add <2 x i32> %x1, <i32 -1, i32 -1>
185c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
186c8fb2775SNoah Goldstein  %z = and <2 x i32> %x3, <i32 16, i32 32>
187c8fb2775SNoah Goldstein  ret <2 x i32> %z
188c8fb2775SNoah Goldstein}
189c8fb2775SNoah Goldstein
190c8fb2775SNoah Goldsteindefine i1 @blsmsk_eq_is_false_assume(i32 %x) {
191c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_eq_is_false_assume(
192c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 4
193c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
194c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
1959a8f517fSNoah Goldstein; CHECK-NEXT:    ret i1 false
196c8fb2775SNoah Goldstein;
197c8fb2775SNoah Goldstein  %lb = and i32 %x, 4
198c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
199c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
200c8fb2775SNoah Goldstein  %x2 = add i32 %x, -1
201c8fb2775SNoah Goldstein  %x3 = xor i32 %x2, %x
202c8fb2775SNoah Goldstein  %z = icmp eq i32 %x3, 8
203c8fb2775SNoah Goldstein  ret i1 %z
204c8fb2775SNoah Goldstein}
205c8fb2775SNoah Goldstein
206c8fb2775SNoah Goldsteindefine i1 @blsmsk_gt_is_false_assume(i32 %x) {
207c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_gt_is_false_assume(
208c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 2
209c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
210c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
2114fcfff4fSNoah Goldstein; CHECK-NEXT:    ret i1 false
212c8fb2775SNoah Goldstein;
213c8fb2775SNoah Goldstein  %lb = and i32 %x, 2
214c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
215c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
216c8fb2775SNoah Goldstein  %x2 = sub i32 %x, 1
217c8fb2775SNoah Goldstein  %x3 = xor i32 %x2, %x
218c8fb2775SNoah Goldstein  %z = icmp ugt i32 %x3, 8
219c8fb2775SNoah Goldstein  ret i1 %z
220c8fb2775SNoah Goldstein}
221c8fb2775SNoah Goldstein
222c8fb2775SNoah Goldsteindefine i32 @blsmsk_add_eval_assume(i32 %x) {
223c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_add_eval_assume(
224c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 1
225c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
226c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
2279a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 33
228c8fb2775SNoah Goldstein;
229c8fb2775SNoah Goldstein  %lb = and i32 %x, 1
230c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
231c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
232c8fb2775SNoah Goldstein  %x2 = sub i32 %x, 1
233c8fb2775SNoah Goldstein  %x3 = xor i32 %x2, %x
234c8fb2775SNoah Goldstein  %z = add i32 %x3, 32
235c8fb2775SNoah Goldstein  ret i32 %z
236c8fb2775SNoah Goldstein}
237c8fb2775SNoah Goldstein
238c8fb2775SNoah Goldsteindefine <2 x i32> @blsmsk_add_eval_assume_vec(<2 x i32> %x) {
239c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_add_eval_assume_vec(
240c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = trunc <2 x i32> [[X:%.*]] to <2 x i1>
241c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP0:%.*]] = extractelement <2 x i1> [[CMP]], i64 0
242c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP0]])
243c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP1:%.*]] = extractelement <2 x i1> [[CMP]], i64 1
244c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP1]])
245*38fffa63SPaul Walker; CHECK-NEXT:    [[X2:%.*]] = add <2 x i32> [[X]], splat (i32 -1)
246c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = xor <2 x i32> [[X2]], [[X]]
247*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = add <2 x i32> [[X3]], splat (i32 32)
248c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i32> [[Z]]
249c8fb2775SNoah Goldstein;
250c8fb2775SNoah Goldstein  %lb = and <2 x i32> %x, <i32 1, i32 1>
251c8fb2775SNoah Goldstein  %cmp = icmp ne <2 x i32> %lb, <i32 0, i32 0>
252c8fb2775SNoah Goldstein  %cmp0 = extractelement <2 x i1> %cmp, i32 0
253c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp0)
254c8fb2775SNoah Goldstein  %cmp1 = extractelement <2 x i1> %cmp, i32 1
255c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp1)
256c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> %x, <i32 1, i32 1>
257c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x
258c8fb2775SNoah Goldstein  %z = add <2 x i32> %x3, <i32 32, i32 32>
259c8fb2775SNoah Goldstein  ret <2 x i32> %z
260c8fb2775SNoah Goldstein}
261c8fb2775SNoah Goldstein
262c8fb2775SNoah Goldsteindefine i32 @blsmsk_sub_eval_assume(i32 %x) {
263c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_sub_eval_assume(
264c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 1
265c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
266c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
2674fcfff4fSNoah Goldstein; CHECK-NEXT:    ret i32 -31
268c8fb2775SNoah Goldstein;
269c8fb2775SNoah Goldstein  %lb = and i32 %x, 1
270c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
271c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
272c8fb2775SNoah Goldstein  %x2 = sub i32 %x, 1
273c8fb2775SNoah Goldstein  %x3 = xor i32 %x, %x2
274c8fb2775SNoah Goldstein  %z = sub i32 %x3, 32
275c8fb2775SNoah Goldstein  ret i32 %z
276c8fb2775SNoah Goldstein}
277c8fb2775SNoah Goldstein
278c8fb2775SNoah Goldsteindefine i32 @blsmsk_or_eval_assume(i32 %x) {
279c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_or_eval_assume(
280c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 1
281c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
282c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
2839a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 33
284c8fb2775SNoah Goldstein;
285c8fb2775SNoah Goldstein  %lb = and i32 %x, 1
286c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
287c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
288c8fb2775SNoah Goldstein  %x2 = sub i32 %x, 1
289c8fb2775SNoah Goldstein  %x3 = xor i32 %x2, %x
290c8fb2775SNoah Goldstein  %z = or i32 %x3, 32
291c8fb2775SNoah Goldstein  ret i32 %z
292c8fb2775SNoah Goldstein}
293c8fb2775SNoah Goldstein
294c8fb2775SNoah Goldsteindefine i32 @blsmsk_and_eval_assume(i32 %x) {
295c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_and_eval_assume(
296c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 4
297c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
298c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
299c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = add i32 [[X]], 63
300c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = xor i32 [[X2]], [[X]]
301c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = and i32 [[X3]], 32
302c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 [[Z]]
303c8fb2775SNoah Goldstein;
304c8fb2775SNoah Goldstein  %lb = and i32 %x, 4
305c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
306c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
307c8fb2775SNoah Goldstein  %x2 = sub i32 %x, 1
308c8fb2775SNoah Goldstein  %x3 = xor i32 %x2, %x
309c8fb2775SNoah Goldstein  %z = and i32 %x3, 32
310c8fb2775SNoah Goldstein  ret i32 %z
311c8fb2775SNoah Goldstein}
312c8fb2775SNoah Goldstein
313c8fb2775SNoah Goldstein
314c8fb2775SNoah Goldsteindefine <2 x i1> @blsi_eq_is_false_vec(<2 x i32> %x) {
315c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_eq_is_false_vec(
316c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i1> zeroinitializer
317c8fb2775SNoah Goldstein;
318c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 10, i32 10>
319c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> <i32 0, i32 0>, %x1
320c8fb2775SNoah Goldstein  %x3 = and <2 x i32> %x1, %x2
321c8fb2775SNoah Goldstein  %z = icmp eq <2 x i32> %x3, <i32 8, i32 8>
322c8fb2775SNoah Goldstein  ret <2 x i1> %z
323c8fb2775SNoah Goldstein}
324c8fb2775SNoah Goldstein
325c8fb2775SNoah Goldsteindefine i1 @blsi_ne_is_true(i32 %x) {
326c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_ne_is_true(
327c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i1 true
328c8fb2775SNoah Goldstein;
329c8fb2775SNoah Goldstein  %x1 = or i32 %x, 10
330c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x1
331c8fb2775SNoah Goldstein  %x3 = and i32 %x1, %x2
332c8fb2775SNoah Goldstein  %z = icmp ne i32 %x3, 8
333c8fb2775SNoah Goldstein  ret i1 %z
334c8fb2775SNoah Goldstein}
335c8fb2775SNoah Goldstein
336c8fb2775SNoah Goldsteindefine <2 x i1> @blsi_ge_is_false_vec(<2 x i32> %x) {
337c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_ge_is_false_vec(
338*38fffa63SPaul Walker; CHECK-NEXT:    [[X1:%.*]] = or <2 x i32> [[X:%.*]], splat (i32 10)
339c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X1]]
340a1058776SNikita Popov; CHECK-NEXT:    [[X3:%.*]] = and <2 x i32> [[X]], [[X2]]
341*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = icmp ugt <2 x i32> [[X3]], splat (i32 7)
342c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i1> [[Z]]
343c8fb2775SNoah Goldstein;
344c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 10, i32 10>
345c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> <i32 0, i32 0>, %x1
346c8fb2775SNoah Goldstein  %x3 = and <2 x i32> %x1, %x2
347c8fb2775SNoah Goldstein  %z = icmp uge <2 x i32> %x3, <i32 8, i32 8>
348c8fb2775SNoah Goldstein  ret <2 x i1> %z
349c8fb2775SNoah Goldstein}
350c8fb2775SNoah Goldstein
351c8fb2775SNoah Goldsteindefine <2 x i1> @blsi_ge_is_false_diff_vec(<2 x i32> %x) {
352c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_ge_is_false_diff_vec(
353c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X1:%.*]] = or <2 x i32> [[X:%.*]], <i32 10, i32 11>
354c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X1]]
355a1058776SNikita Popov; CHECK-NEXT:    [[X3:%.*]] = and <2 x i32> [[X]], [[X2]]
356*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = icmp ugt <2 x i32> [[X3]], splat (i32 7)
357c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i1> [[Z]]
358c8fb2775SNoah Goldstein;
359c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 10, i32 11>
360c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> <i32 0, i32 0>, %x1
361c8fb2775SNoah Goldstein  %x3 = and <2 x i32> %x1, %x2
362c8fb2775SNoah Goldstein  %z = icmp uge <2 x i32> %x3, <i32 8, i32 8>
363c8fb2775SNoah Goldstein  ret <2 x i1> %z
364c8fb2775SNoah Goldstein}
365c8fb2775SNoah Goldstein
366c8fb2775SNoah Goldsteindefine i1 @blsi_gt_is_false(i32 %x) {
367c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_gt_is_false(
3684fcfff4fSNoah Goldstein; CHECK-NEXT:    ret i1 false
369c8fb2775SNoah Goldstein;
370c8fb2775SNoah Goldstein  %x1 = or i32 %x, 10
371c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x1
372c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x1
373c8fb2775SNoah Goldstein  %z = icmp ugt i32 %x3, 8
374c8fb2775SNoah Goldstein  ret i1 %z
375c8fb2775SNoah Goldstein}
376c8fb2775SNoah Goldstein
377c8fb2775SNoah Goldstein
378c8fb2775SNoah Goldsteindefine i32 @blsi_add_eval(i32 %x) {
379c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_add_eval(
3809a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 33
381c8fb2775SNoah Goldstein;
382c8fb2775SNoah Goldstein  %x1 = or i32 %x, 9
383c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x1
384c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x1
385c8fb2775SNoah Goldstein  %z = add i32 %x3, 32
386c8fb2775SNoah Goldstein  ret i32 %z
387c8fb2775SNoah Goldstein}
388c8fb2775SNoah Goldstein
389c8fb2775SNoah Goldsteindefine i32 @blsi_sub_eval(i32 %x) {
390c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_sub_eval(
3919a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 -31
392c8fb2775SNoah Goldstein;
393c8fb2775SNoah Goldstein  %x1 = or i32 %x, 33
394c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x1
395c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x1
396c8fb2775SNoah Goldstein  %z = sub i32 %x3, 32
397c8fb2775SNoah Goldstein  ret i32 %z
398c8fb2775SNoah Goldstein}
399c8fb2775SNoah Goldstein
400c8fb2775SNoah Goldsteindefine <2 x i32> @blsi_sub_eval_vec(<2 x i32> %x) {
401c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_sub_eval_vec(
402*38fffa63SPaul Walker; CHECK-NEXT:    ret <2 x i32> splat (i32 -31)
403c8fb2775SNoah Goldstein;
404c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 33, i32 33>
405c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> <i32 0, i32 0>, %x1
406c8fb2775SNoah Goldstein  %x3 = and <2 x i32> %x1, %x2
407c8fb2775SNoah Goldstein  %z = sub <2 x i32> %x3, <i32 32, i32 32>
408c8fb2775SNoah Goldstein  ret <2 x i32> %z
409c8fb2775SNoah Goldstein}
410c8fb2775SNoah Goldstein
411c8fb2775SNoah Goldsteindefine i32 @blsi_or_eval(i32 %x) {
412c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_or_eval(
4139a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 33
414c8fb2775SNoah Goldstein;
415c8fb2775SNoah Goldstein  %x1 = or i32 %x, 129
416c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x1
417c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x1
418c8fb2775SNoah Goldstein  %z = or i32 %x3, 32
419c8fb2775SNoah Goldstein  ret i32 %z
420c8fb2775SNoah Goldstein}
421c8fb2775SNoah Goldstein
422c8fb2775SNoah Goldsteindefine <2 x i32> @blsi_xor_eval_vec(<2 x i32> %x) {
423c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_xor_eval_vec(
424*38fffa63SPaul Walker; CHECK-NEXT:    ret <2 x i32> splat (i32 33)
425c8fb2775SNoah Goldstein;
426c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 33, i32 33>
427c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> <i32 0, i32 0>, %x1
428c8fb2775SNoah Goldstein  %x3 = and <2 x i32> %x2, %x1
429c8fb2775SNoah Goldstein  %z = xor <2 x i32> %x3, <i32 32, i32 32>
430c8fb2775SNoah Goldstein  ret <2 x i32> %z
431c8fb2775SNoah Goldstein}
432c8fb2775SNoah Goldstein
433c8fb2775SNoah Goldsteindefine i32 @blsi_and_eval(i32 %x) {
434c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_and_eval(
435c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 0
436c8fb2775SNoah Goldstein;
437c8fb2775SNoah Goldstein  %x1 = or i32 %x, 34
438c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x1
439c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x1
440c8fb2775SNoah Goldstein  %z = and i32 %x3, 32
441c8fb2775SNoah Goldstein  ret i32 %z
442c8fb2775SNoah Goldstein}
443c8fb2775SNoah Goldstein
444c8fb2775SNoah Goldsteindefine <2 x i32> @blsi_and_eval2_vec(<2 x i32> %x) {
445c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_and_eval2_vec(
446*38fffa63SPaul Walker; CHECK-NEXT:    [[X1:%.*]] = or <2 x i32> [[X:%.*]], splat (i32 30)
447c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X1]]
448a1058776SNikita Popov; CHECK-NEXT:    [[X3:%.*]] = and <2 x i32> [[X]], [[X2]]
449*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = and <2 x i32> [[X3]], splat (i32 32)
450c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i32> [[Z]]
451c8fb2775SNoah Goldstein;
452c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 30, i32 30>
453c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> <i32 0, i32 0>, %x1
454c8fb2775SNoah Goldstein  %x3 = and <2 x i32> %x1, %x2
455c8fb2775SNoah Goldstein  %z = and <2 x i32> %x3, <i32 32, i32 32>
456c8fb2775SNoah Goldstein  ret <2 x i32> %z
457c8fb2775SNoah Goldstein}
458c8fb2775SNoah Goldstein
459c8fb2775SNoah Goldsteindefine i32 @blsi_and_eval3(i32 %x) {
460c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_and_eval3(
461c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X1:%.*]] = or i32 [[X:%.*]], 34
462c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = sub nsw i32 0, [[X1]]
463a1058776SNikita Popov; CHECK-NEXT:    [[X3:%.*]] = and i32 [[X]], [[X2]]
464c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = and i32 [[X3]], 208
465c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 [[Z]]
466c8fb2775SNoah Goldstein;
467c8fb2775SNoah Goldstein  %x1 = or i32 %x, 34
468c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x1
469c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x1
470c8fb2775SNoah Goldstein  %z = and i32 %x3, 240
471c8fb2775SNoah Goldstein  ret i32 %z
472c8fb2775SNoah Goldstein}
473c8fb2775SNoah Goldstein
474c8fb2775SNoah Goldsteindefine <2 x i1> @blsi_eq_is_false_assume_vec(<2 x i32> %x) {
475c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_eq_is_false_assume_vec(
476*38fffa63SPaul Walker; CHECK-NEXT:    [[LB:%.*]] = and <2 x i32> [[X:%.*]], splat (i32 2)
477c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne <2 x i32> [[LB]], zeroinitializer
478c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP0:%.*]] = extractelement <2 x i1> [[CMP]], i64 0
479c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP0]])
480c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP1:%.*]] = extractelement <2 x i1> [[CMP]], i64 1
481c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP1]])
482c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = sub <2 x i32> zeroinitializer, [[X]]
483a1058776SNikita Popov; CHECK-NEXT:    [[X3:%.*]] = and <2 x i32> [[X]], [[X2]]
484*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = icmp eq <2 x i32> [[X3]], splat (i32 8)
485c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i1> [[Z]]
486c8fb2775SNoah Goldstein;
487c8fb2775SNoah Goldstein  %lb = and <2 x i32> %x, <i32 2, i32 2>
488c8fb2775SNoah Goldstein  %cmp = icmp ne <2 x i32> %lb, <i32 0, i32 0>
489c8fb2775SNoah Goldstein  %cmp0 = extractelement <2 x i1> %cmp, i32 0
490c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp0)
491c8fb2775SNoah Goldstein  %cmp1 = extractelement <2 x i1> %cmp, i32 1
492c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp1)
493c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> <i32 0, i32 0>, %x
494c8fb2775SNoah Goldstein  %x3 = and <2 x i32> %x2, %x
495c8fb2775SNoah Goldstein  %z = icmp eq <2 x i32> %x3, <i32 8, i32 8>
496c8fb2775SNoah Goldstein  ret <2 x i1> %z
497c8fb2775SNoah Goldstein}
498c8fb2775SNoah Goldstein
499c8fb2775SNoah Goldsteindefine i1 @blsi_ne_is_true_assume(i32 %x) {
500c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_ne_is_true_assume(
501c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 4
502c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
503c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
5049a8f517fSNoah Goldstein; CHECK-NEXT:    ret i1 true
505c8fb2775SNoah Goldstein;
506c8fb2775SNoah Goldstein  %lb = and i32 %x, 4
507c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
508c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
509c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x
510c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x
511c8fb2775SNoah Goldstein  %z = icmp ne i32 %x3, 8
512c8fb2775SNoah Goldstein  ret i1 %z
513c8fb2775SNoah Goldstein}
514c8fb2775SNoah Goldstein
515c8fb2775SNoah Goldsteindefine i1 @blsi_ge_is_false_assume(i32 %x) {
516c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_ge_is_false_assume(
517c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 4
518c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
519c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
5204fcfff4fSNoah Goldstein; CHECK-NEXT:    ret i1 false
521c8fb2775SNoah Goldstein;
522c8fb2775SNoah Goldstein  %lb = and i32 %x, 4
523c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
524c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
525c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x
526c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x
527c8fb2775SNoah Goldstein  %z = icmp uge i32 %x3, 8
528c8fb2775SNoah Goldstein  ret i1 %z
529c8fb2775SNoah Goldstein}
530c8fb2775SNoah Goldstein
531c8fb2775SNoah Goldsteindefine <2 x i1> @blsi_cmp_eq_diff_bits_vec(<2 x i32> %x) {
532c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_cmp_eq_diff_bits_vec(
533c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X1:%.*]] = or <2 x i32> [[X:%.*]], <i32 1, i32 2>
534c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = sub <2 x i32> zeroinitializer, [[X1]]
535c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = and <2 x i32> [[X1]], [[X2]]
536*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = icmp eq <2 x i32> [[X3]], splat (i32 32)
537c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i1> [[Z]]
538c8fb2775SNoah Goldstein;
539c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 1, i32 2>
540c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> <i32 0, i32 0>, %x1
541c8fb2775SNoah Goldstein  %x3 = and <2 x i32> %x1, %x2
542c8fb2775SNoah Goldstein  %z = icmp eq <2 x i32> %x3, <i32 32, i32 32>
543c8fb2775SNoah Goldstein  ret <2 x i1> %z
544c8fb2775SNoah Goldstein}
545c8fb2775SNoah Goldstein
546c8fb2775SNoah Goldsteindefine i32 @blsi_xor_eval_assume(i32 %x) {
547c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_xor_eval_assume(
548c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 1
549c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
550c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
5519a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 33
552c8fb2775SNoah Goldstein;
553c8fb2775SNoah Goldstein  %lb = and i32 %x, 1
554c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
555c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
556c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x
557c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x
558c8fb2775SNoah Goldstein  %z = xor i32 %x3, 32
559c8fb2775SNoah Goldstein  ret i32 %z
560c8fb2775SNoah Goldstein}
561c8fb2775SNoah Goldstein
562c8fb2775SNoah Goldsteindefine i32 @blsi_and_eval_assume(i32 %x) {
563c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_and_eval_assume(
564c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 8
565c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
566c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
5679a8f517fSNoah Goldstein; CHECK-NEXT:    ret i32 0
568c8fb2775SNoah Goldstein;
569c8fb2775SNoah Goldstein  %lb = and i32 %x, 8
570c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
571c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
572c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x
573c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x
574c8fb2775SNoah Goldstein  %z = and i32 %x3, 32
575c8fb2775SNoah Goldstein  ret i32 %z
576c8fb2775SNoah Goldstein}
577c8fb2775SNoah Goldstein
578c8fb2775SNoah Goldsteindefine <2 x i1> @blsmsk_ne_no_proof_vec(<2 x i32> %x) {
579c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_ne_no_proof_vec(
580*38fffa63SPaul Walker; CHECK-NEXT:    [[X1:%.*]] = or <2 x i32> [[X:%.*]], splat (i32 10)
581c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = add nsw <2 x i32> [[X1]], <i32 -2, i32 -3>
582c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = xor <2 x i32> [[X2]], [[X1]]
583*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = icmp ne <2 x i32> [[X3]], splat (i32 8)
584c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i1> [[Z]]
585c8fb2775SNoah Goldstein;
586c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 10, i32 10>
587c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> %x1, <i32 2, i32 3>
588c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
589c8fb2775SNoah Goldstein  %z = icmp ne <2 x i32> %x3, <i32 8, i32 8>
590c8fb2775SNoah Goldstein  ret <2 x i1> %z
591c8fb2775SNoah Goldstein}
592c8fb2775SNoah Goldstein
593c8fb2775SNoah Goldsteindefine <2 x i32> @blsmsk_add_noeval_vec(<2 x i32> %x) {
594c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_add_noeval_vec(
595*38fffa63SPaul Walker; CHECK-NEXT:    [[X1:%.*]] = or <2 x i32> [[X:%.*]], splat (i32 9)
596c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = add <2 x i32> [[X1]], <i32 1, i32 -2>
597c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = xor <2 x i32> [[X2]], [[X1]]
598*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = add <2 x i32> [[X3]], splat (i32 32)
599c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i32> [[Z]]
600c8fb2775SNoah Goldstein;
601c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 9, i32 9>
602c8fb2775SNoah Goldstein  %x2 = add <2 x i32> %x1, <i32 1, i32 -2>
603c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
604c8fb2775SNoah Goldstein  %z = add <2 x i32> %x3, <i32 32, i32 32>
605c8fb2775SNoah Goldstein  ret <2 x i32> %z
606c8fb2775SNoah Goldstein}
607c8fb2775SNoah Goldstein
608c8fb2775SNoah Goldsteindefine i1 @blsmsk_eq_no_proof(i32 %x) {
609c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_eq_no_proof(
610c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i1 false
611c8fb2775SNoah Goldstein;
612c8fb2775SNoah Goldstein  %x1 = or i32 %x, 10
613c8fb2775SNoah Goldstein  %x2 = add i32 %x1, -2
614c8fb2775SNoah Goldstein  %x3 = xor i32 %x2, %x1
615c8fb2775SNoah Goldstein  %z = icmp eq i32 %x3, 8
616c8fb2775SNoah Goldstein  ret i1 %z
617c8fb2775SNoah Goldstein}
618c8fb2775SNoah Goldstein
619c8fb2775SNoah Goldstein
620c8fb2775SNoah Goldsteindefine i32 @blsmsk_add_no_eval(i32 %x) {
621c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_add_no_eval(
622c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X1:%.*]] = or i32 [[X:%.*]], 9
623c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = add nsw i32 [[X1]], -3
624c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = xor i32 [[X1]], [[X2]]
625c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = add i32 [[X3]], 32
626c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 [[Z]]
627c8fb2775SNoah Goldstein;
628c8fb2775SNoah Goldstein  %x1 = or i32 %x, 9
629c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 3
630c8fb2775SNoah Goldstein  %x3 = xor i32 %x1, %x2
631c8fb2775SNoah Goldstein  %z = add i32 %x3, 32
632c8fb2775SNoah Goldstein  ret i32 %z
633c8fb2775SNoah Goldstein}
634c8fb2775SNoah Goldstein
635c8fb2775SNoah Goldsteindefine i32 @blsmsk_add_no_eval2(i32 %x) {
636c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_add_no_eval2(
637c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X1:%.*]] = or i32 [[X:%.*]], 256
638c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = add nsw i32 [[X1]], -1
639c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = xor i32 [[X1]], [[X2]]
6409a8f517fSNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = add nuw nsw i32 [[X3]], 32
641c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 [[Z]]
642c8fb2775SNoah Goldstein;
643c8fb2775SNoah Goldstein  %x1 = or i32 %x, 256
644c8fb2775SNoah Goldstein  %x2 = sub i32 %x1, 1
645c8fb2775SNoah Goldstein  %x3 = xor i32 %x1, %x2
646c8fb2775SNoah Goldstein  %z = add i32 %x3, 32
647c8fb2775SNoah Goldstein  ret i32 %z
648c8fb2775SNoah Goldstein}
649c8fb2775SNoah Goldstein
650c8fb2775SNoah Goldsteindefine <2 x i32> @blsmsk_xor_no_eval_vec(<2 x i32> %x) {
651c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_xor_no_eval_vec(
652*38fffa63SPaul Walker; CHECK-NEXT:    [[X1:%.*]] = or <2 x i32> [[X:%.*]], splat (i32 34)
653c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = add <2 x i32> [[X1]], <i32 -9, i32 1>
654c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = xor <2 x i32> [[X2]], [[X1]]
655*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = xor <2 x i32> [[X3]], splat (i32 32)
656c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i32> [[Z]]
657c8fb2775SNoah Goldstein;
658c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 34, i32 34>
659c8fb2775SNoah Goldstein  %x2 = add <2 x i32> %x1, <i32 -9, i32 1>
660c8fb2775SNoah Goldstein  %x3 = xor <2 x i32> %x2, %x1
661c8fb2775SNoah Goldstein  %z = xor <2 x i32> %x3, <i32 32, i32 32>
662c8fb2775SNoah Goldstein  ret <2 x i32> %z
663c8fb2775SNoah Goldstein}
664c8fb2775SNoah Goldstein
665c8fb2775SNoah Goldsteindefine i32 @blsmsk_xor_no_eval_assume(i32 %x) {
666c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_xor_no_eval_assume(
667c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 1
668c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[LB]], 0
669c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
670c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = add i32 [[X]], -1
671a1058776SNikita Popov; CHECK-NEXT:    [[X3:%.*]] = xor i32 [[X]], [[X2]]
672c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = xor i32 [[X3]], 32
673c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 [[Z]]
674c8fb2775SNoah Goldstein;
675c8fb2775SNoah Goldstein  %lb = and i32 %x, 1
676c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 1
677c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
678c8fb2775SNoah Goldstein  %x2 = sub i32 %x, 1
679c8fb2775SNoah Goldstein  %x3 = xor i32 %x, %x2
680c8fb2775SNoah Goldstein  %z = xor i32 %x3, 32
681c8fb2775SNoah Goldstein  ret i32 %z
682c8fb2775SNoah Goldstein}
683c8fb2775SNoah Goldstein
684c8fb2775SNoah Goldsteindefine i32 @blsmsk_xor_no_eval_assume2(i32 %x) {
685c8fb2775SNoah Goldstein; CHECK-LABEL: @blsmsk_xor_no_eval_assume2(
686c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i32 [[X:%.*]], 128
687c8fb2775SNoah Goldstein; CHECK-NEXT:    [[CMP:%.*]] = icmp ne i32 [[LB]], 0
688c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[CMP]])
689c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = add nsw i32 [[X]], -1
690a1058776SNikita Popov; CHECK-NEXT:    [[X3:%.*]] = xor i32 [[X]], [[X2]]
691c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = xor i32 [[X3]], 32
692c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 [[Z]]
693c8fb2775SNoah Goldstein;
694c8fb2775SNoah Goldstein  %lb = and i32 %x, 128
695c8fb2775SNoah Goldstein  %cmp = icmp ne i32 %lb, 0
696c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %cmp)
697c8fb2775SNoah Goldstein  %x2 = sub i32 %x, 1
698c8fb2775SNoah Goldstein  %x3 = xor i32 %x, %x2
699c8fb2775SNoah Goldstein  %z = xor i32 %x3, 32
700c8fb2775SNoah Goldstein  ret i32 %z
701c8fb2775SNoah Goldstein}
702c8fb2775SNoah Goldstein
703c8fb2775SNoah Goldsteindefine i1 @blsi_ne_no_proof2(i32 %x) {
704c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_ne_no_proof2(
705c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X1:%.*]] = or i32 [[X:%.*]], 512
706c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = sub nsw i32 0, [[X1]]
707c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = and i32 [[X1]], [[X2]]
708c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = icmp ne i32 [[X3]], 8
709c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i1 [[Z]]
710c8fb2775SNoah Goldstein;
711c8fb2775SNoah Goldstein  %x1 = or i32 %x, 512
712c8fb2775SNoah Goldstein  %x2 = sub i32 0, %x1
713c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x1
714c8fb2775SNoah Goldstein  %z = icmp ne i32 %x3, 8
715c8fb2775SNoah Goldstein  ret i1 %z
716c8fb2775SNoah Goldstein}
717c8fb2775SNoah Goldstein
718c8fb2775SNoah Goldstein
719c8fb2775SNoah Goldsteindefine i32 @blsi_or_no_eval(i32 %x) {
720c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_or_no_eval(
721c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X1:%.*]] = or i32 [[X:%.*]], 129
722c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = sub nsw i32 2, [[X1]]
723c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = and i32 [[X2]], [[X1]]
724c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = or i32 [[X3]], 32
725c8fb2775SNoah Goldstein; CHECK-NEXT:    ret i32 [[Z]]
726c8fb2775SNoah Goldstein;
727c8fb2775SNoah Goldstein  %x1 = or i32 %x, 129
728c8fb2775SNoah Goldstein  %x2 = sub i32 2, %x1
729c8fb2775SNoah Goldstein  %x3 = and i32 %x2, %x1
730c8fb2775SNoah Goldstein  %z = or i32 %x3, 32
731c8fb2775SNoah Goldstein  ret i32 %z
732c8fb2775SNoah Goldstein}
733c8fb2775SNoah Goldstein
734c8fb2775SNoah Goldsteindefine <2 x i32> @blsi_or_no_partial_eval_vec(<2 x i32> %x) {
735c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_or_no_partial_eval_vec(
736*38fffa63SPaul Walker; CHECK-NEXT:    [[X1:%.*]] = or <2 x i32> [[X:%.*]], splat (i32 30)
737c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X2:%.*]] = sub nsw <2 x i32> <i32 0, i32 1>, [[X1]]
738c8fb2775SNoah Goldstein; CHECK-NEXT:    [[X3:%.*]] = and <2 x i32> [[X1]], [[X2]]
739*38fffa63SPaul Walker; CHECK-NEXT:    [[Z:%.*]] = or <2 x i32> [[X3]], splat (i32 32)
740c8fb2775SNoah Goldstein; CHECK-NEXT:    ret <2 x i32> [[Z]]
741c8fb2775SNoah Goldstein;
742c8fb2775SNoah Goldstein  %x1 = or <2 x i32> %x, <i32 30, i32 30>
743c8fb2775SNoah Goldstein  %x2 = sub <2 x i32> <i32 0, i32 1>, %x1
744c8fb2775SNoah Goldstein  %x3 = and <2 x i32> %x1, %x2
745c8fb2775SNoah Goldstein  %z = or <2 x i32> %x3, <i32 32, i32 32>
746c8fb2775SNoah Goldstein  ret <2 x i32> %z
747c8fb2775SNoah Goldstein}
748c8fb2775SNoah Goldstein
749c8fb2775SNoah Goldstein
750c8fb2775SNoah Goldstein;; Test that if we have different knowledge about lowbit of X/-X that we select the minimum.
751c8fb2775SNoah Goldsteindefine i1 @blsi_differing_lowbits(i8 %x) {
752c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_differing_lowbits(
7539a8f517fSNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = sub i8 0, [[X:%.*]]
754c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i8 [[Z]], 2
755c8fb2775SNoah Goldstein; CHECK-NEXT:    [[NE:%.*]] = icmp ne i8 [[LB]], 0
756c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[NE]])
7579a8f517fSNoah Goldstein; CHECK-NEXT:    ret i1 false
758c8fb2775SNoah Goldstein;
759c8fb2775SNoah Goldstein  %y = or i8 %x, 8
760c8fb2775SNoah Goldstein  %z = sub i8 0, %y
761c8fb2775SNoah Goldstein  %lb = and i8 %z, 2
762c8fb2775SNoah Goldstein  %ne = icmp ne i8 %lb, 0
763c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %ne)
764c8fb2775SNoah Goldstein  %o = and i8 %z, %y
765c8fb2775SNoah Goldstein  %r = icmp eq i8 %o, 4
766c8fb2775SNoah Goldstein  ret i1 %r
767c8fb2775SNoah Goldstein}
768c8fb2775SNoah Goldstein
769c8fb2775SNoah Goldsteindefine i1 @blsi_differing_lowbits2(i8 %x) {
770c8fb2775SNoah Goldstein; CHECK-LABEL: @blsi_differing_lowbits2(
771c8fb2775SNoah Goldstein; CHECK-NEXT:    [[Z:%.*]] = sub nsw i8 0, [[X:%.*]]
772c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB:%.*]] = and i8 [[Z]], 8
773c8fb2775SNoah Goldstein; CHECK-NEXT:    [[NE:%.*]] = icmp ne i8 [[LB]], 0
774c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[NE]])
775c8fb2775SNoah Goldstein; CHECK-NEXT:    [[LB2:%.*]] = and i8 [[X]], 2
776c8fb2775SNoah Goldstein; CHECK-NEXT:    [[NE2:%.*]] = icmp ne i8 [[LB2]], 0
777c8fb2775SNoah Goldstein; CHECK-NEXT:    call void @llvm.assume(i1 [[NE2]])
7789a8f517fSNoah Goldstein; CHECK-NEXT:    ret i1 false
779c8fb2775SNoah Goldstein;
780c8fb2775SNoah Goldstein  %z = sub i8 0, %x
781c8fb2775SNoah Goldstein  %lb = and i8 %z, 8
782c8fb2775SNoah Goldstein  %ne = icmp ne i8 %lb, 0
783c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %ne)
784c8fb2775SNoah Goldstein  %lb2 = and i8 %x, 2
785c8fb2775SNoah Goldstein  %ne2 = icmp ne i8 %lb2, 0
786c8fb2775SNoah Goldstein  call void @llvm.assume(i1 %ne2)
787c8fb2775SNoah Goldstein  %o = and i8 %z, %x
788c8fb2775SNoah Goldstein  %r = icmp eq i8 %o, 4
789c8fb2775SNoah Goldstein  ret i1 %r
790c8fb2775SNoah Goldstein}
791