1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 define i1 @reduction_logical_or(<4 x i1> %x) {
5 ; CHECK-LABEL: @reduction_logical_or(
6 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i1> [[X:%.*]] to i4
7 ; CHECK-NEXT: [[R:%.*]] = icmp ne i4 [[TMP1]], 0
8 ; CHECK-NEXT: ret i1 [[R]]
10 %r = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> %x)
14 define i1 @reduction_logical_or_nxv2i1(<vscale x 2 x i1> %x) {
15 ; CHECK-LABEL: @reduction_logical_or_nxv2i1(
16 ; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.or.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
17 ; CHECK-NEXT: ret i1 [[R]]
19 %r = call i1 @llvm.vector.reduce.or.nxv2i1(<vscale x 2 x i1> %x)
23 define i1 @reduction_logical_and(<4 x i1> %x) {
24 ; CHECK-LABEL: @reduction_logical_and(
25 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i1> [[X:%.*]] to i4
26 ; CHECK-NEXT: [[R:%.*]] = icmp eq i4 [[TMP1]], -1
27 ; CHECK-NEXT: ret i1 [[R]]
29 %r = call i1 @llvm.vector.reduce.and.v4i1(<4 x i1> %x)
33 define i1 @reduction_logical_and_nxv2i1(<vscale x 2 x i1> %x) {
34 ; CHECK-LABEL: @reduction_logical_and_nxv2i1(
35 ; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
36 ; CHECK-NEXT: ret i1 [[R]]
38 %r = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> %x)
42 define i1 @reduction_logical_mul(<2 x i1> %x) {
43 ; CHECK-LABEL: @reduction_logical_mul(
44 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[X:%.*]] to i2
45 ; CHECK-NEXT: [[R:%.*]] = icmp eq i2 [[TMP1]], -1
46 ; CHECK-NEXT: ret i1 [[R]]
48 %r = call i1 @llvm.vector.reduce.mul.v4i1(<2 x i1> %x)
52 define i1 @reduction_logical_mul_nxv2i1(<vscale x 2 x i1> %x) {
53 ; CHECK-LABEL: @reduction_logical_mul_nxv2i1(
54 ; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
55 ; CHECK-NEXT: ret i1 [[R]]
57 %r = call i1 @llvm.vector.reduce.mul.nxv2i1(<vscale x 2 x i1> %x)
61 define i1 @reduction_logical_xor(<2 x i1> %x) {
62 ; CHECK-LABEL: @reduction_logical_xor(
63 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[X:%.*]] to i2
64 ; CHECK-NEXT: [[TMP2:%.*]] = call range(i2 0, -1) i2 @llvm.ctpop.i2(i2 [[TMP1]])
65 ; CHECK-NEXT: [[R:%.*]] = trunc i2 [[TMP2]] to i1
66 ; CHECK-NEXT: ret i1 [[R]]
68 %r = call i1 @llvm.vector.reduce.xor.v4i1(<2 x i1> %x)
72 define i1 @reduction_logical_xor_nxv2i1(<vscale x 2 x i1> %x) {
73 ; CHECK-LABEL: @reduction_logical_xor_nxv2i1(
74 ; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.add.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
75 ; CHECK-NEXT: ret i1 [[R]]
77 %r = call i1 @llvm.vector.reduce.xor.nxv2i1(<vscale x 2 x i1> %x)
81 define i1 @reduction_logical_smin(<2 x i1> %x) {
82 ; CHECK-LABEL: @reduction_logical_smin(
83 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[X:%.*]] to i2
84 ; CHECK-NEXT: [[R:%.*]] = icmp ne i2 [[TMP1]], 0
85 ; CHECK-NEXT: ret i1 [[R]]
87 %r = call i1 @llvm.vector.reduce.smin.v4i1(<2 x i1> %x)
91 define i1 @reduction_logical_smin_nxv2i1(<vscale x 2 x i1> %x) {
92 ; CHECK-LABEL: @reduction_logical_smin_nxv2i1(
93 ; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.or.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
94 ; CHECK-NEXT: ret i1 [[R]]
96 %r = call i1 @llvm.vector.reduce.smin.nxv2i1(<vscale x 2 x i1> %x)
100 define i1 @reduction_logical_smax(<2 x i1> %x) {
101 ; CHECK-LABEL: @reduction_logical_smax(
102 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[X:%.*]] to i2
103 ; CHECK-NEXT: [[R:%.*]] = icmp eq i2 [[TMP1]], -1
104 ; CHECK-NEXT: ret i1 [[R]]
106 %r = call i1 @llvm.vector.reduce.smax.v4i1(<2 x i1> %x)
110 define i1 @reduction_logical_smax_nxv2i1(<vscale x 2 x i1> %x) {
111 ; CHECK-LABEL: @reduction_logical_smax_nxv2i1(
112 ; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
113 ; CHECK-NEXT: ret i1 [[R]]
115 %r = call i1 @llvm.vector.reduce.smax.nxv2i1(<vscale x 2 x i1> %x)
119 define i1 @reduction_logical_umin(<2 x i1> %x) {
120 ; CHECK-LABEL: @reduction_logical_umin(
121 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[X:%.*]] to i2
122 ; CHECK-NEXT: [[R:%.*]] = icmp eq i2 [[TMP1]], -1
123 ; CHECK-NEXT: ret i1 [[R]]
125 %r = call i1 @llvm.vector.reduce.umin.v4i1(<2 x i1> %x)
129 define i1 @reduction_logical_umin_nxv2i1(<vscale x 2 x i1> %x) {
130 ; CHECK-LABEL: @reduction_logical_umin_nxv2i1(
131 ; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
132 ; CHECK-NEXT: ret i1 [[R]]
134 %r = call i1 @llvm.vector.reduce.umin.nxv2i1(<vscale x 2 x i1> %x)
138 define i1 @reduction_logical_umax(<2 x i1> %x) {
139 ; CHECK-LABEL: @reduction_logical_umax(
140 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[X:%.*]] to i2
141 ; CHECK-NEXT: [[R:%.*]] = icmp ne i2 [[TMP1]], 0
142 ; CHECK-NEXT: ret i1 [[R]]
144 %r = call i1 @llvm.vector.reduce.umax.v4i1(<2 x i1> %x)
148 define i1 @reduction_logical_umax_nxv2i1(<vscale x 2 x i1> %x) {
149 ; CHECK-LABEL: @reduction_logical_umax_nxv2i1(
150 ; CHECK-NEXT: [[R:%.*]] = call i1 @llvm.vector.reduce.or.nxv2i1(<vscale x 2 x i1> [[X:%.*]])
151 ; CHECK-NEXT: ret i1 [[R]]
153 %r = call i1 @llvm.vector.reduce.umax.nxv2i1(<vscale x 2 x i1> %x)
158 define i1 @reduction_logical_or_reverse_nxv2i1(<vscale x 2 x i1> %p) {
159 ; CHECK-LABEL: @reduction_logical_or_reverse_nxv2i1(
160 ; CHECK-NEXT: [[RED:%.*]] = call i1 @llvm.vector.reduce.or.nxv2i1(<vscale x 2 x i1> [[P:%.*]])
161 ; CHECK-NEXT: ret i1 [[RED]]
163 %rev = call <vscale x 2 x i1> @llvm.vector.reverse.nxv2i1(<vscale x 2 x i1> %p)
164 %red = call i1 @llvm.vector.reduce.or.nxv2i1(<vscale x 2 x i1> %rev)
168 define i1 @reduction_logical_or_reverse_v2i1(<2 x i1> %p) {
169 ; CHECK-LABEL: @reduction_logical_or_reverse_v2i1(
170 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[P:%.*]] to i2
171 ; CHECK-NEXT: [[RED:%.*]] = icmp ne i2 [[TMP1]], 0
172 ; CHECK-NEXT: ret i1 [[RED]]
174 %rev = call <2 x i1> @llvm.vector.reverse.v2i1(<2 x i1> %p)
175 %red = call i1 @llvm.vector.reduce.or.v2i1(<2 x i1> %rev)
179 define i1 @reduction_logical_and_reverse_nxv2i1(<vscale x 2 x i1> %p) {
180 ; CHECK-LABEL: @reduction_logical_and_reverse_nxv2i1(
181 ; CHECK-NEXT: [[RED:%.*]] = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> [[P:%.*]])
182 ; CHECK-NEXT: ret i1 [[RED]]
184 %rev = call <vscale x 2 x i1> @llvm.vector.reverse.nxv2i1(<vscale x 2 x i1> %p)
185 %red = call i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1> %rev)
189 define i1 @reduction_logical_and_reverse_v2i1(<2 x i1> %p) {
190 ; CHECK-LABEL: @reduction_logical_and_reverse_v2i1(
191 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[P:%.*]] to i2
192 ; CHECK-NEXT: [[RED:%.*]] = icmp eq i2 [[TMP1]], -1
193 ; CHECK-NEXT: ret i1 [[RED]]
195 %rev = call <2 x i1> @llvm.vector.reverse.v2i1(<2 x i1> %p)
196 %red = call i1 @llvm.vector.reduce.and.v2i1(<2 x i1> %rev)
200 define i1 @reduction_logical_xor_reverse_nxv2i1(<vscale x 2 x i1> %p) {
201 ; CHECK-LABEL: @reduction_logical_xor_reverse_nxv2i1(
202 ; CHECK-NEXT: [[RED:%.*]] = call i1 @llvm.vector.reduce.add.nxv2i1(<vscale x 2 x i1> [[P:%.*]])
203 ; CHECK-NEXT: ret i1 [[RED]]
205 %rev = call <vscale x 2 x i1> @llvm.vector.reverse.nxv2i1(<vscale x 2 x i1> %p)
206 %red = call i1 @llvm.vector.reduce.xor.nxv2i1(<vscale x 2 x i1> %rev)
210 define i1 @reduction_logical_xor_reverse_v2i1(<2 x i1> %p) {
211 ; CHECK-LABEL: @reduction_logical_xor_reverse_v2i1(
212 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i1> [[P:%.*]] to i2
213 ; CHECK-NEXT: [[TMP2:%.*]] = call range(i2 0, -1) i2 @llvm.ctpop.i2(i2 [[TMP1]])
214 ; CHECK-NEXT: [[RED:%.*]] = trunc i2 [[TMP2]] to i1
215 ; CHECK-NEXT: ret i1 [[RED]]
217 %rev = call <2 x i1> @llvm.vector.reverse.v2i1(<2 x i1> %p)
218 %red = call i1 @llvm.vector.reduce.xor.v2i1(<2 x i1> %rev)
222 declare i1 @llvm.vector.reduce.or.v4i1(<4 x i1>)
223 declare i1 @llvm.vector.reduce.or.nxv2i1(<vscale x 2 x i1>)
224 declare i1 @llvm.vector.reduce.or.v2i1(<2 x i1>)
225 declare i1 @llvm.vector.reduce.and.v4i1(<4 x i1>)
226 declare i1 @llvm.vector.reduce.and.nxv2i1(<vscale x 2 x i1>)
227 declare i1 @llvm.vector.reduce.and.v2i1(<2 x i1>)
228 declare i1 @llvm.vector.reduce.xor.nxv2i1(<vscale x 2 x i1>)
229 declare i1 @llvm.vector.reduce.xor.v2i1(<2 x i1>)
230 declare i1 @llvm.vector.reduce.mul.nxv2i1(<vscale x 2 x i1>)
231 declare i1 @llvm.vector.reduce.mul.v2i1(<2 x i1>)
232 declare i1 @llvm.vector.reduce.smin.nxv2i1(<vscale x 2 x i1>)
233 declare i1 @llvm.vector.reduce.smin.v2i1(<2 x i1>)
234 declare i1 @llvm.vector.reduce.smax.nxv2i1(<vscale x 2 x i1>)
235 declare i1 @llvm.vector.reduce.smax.v2i1(<2 x i1>)
236 declare i1 @llvm.vector.reduce.umin.nxv2i1(<vscale x 2 x i1>)
237 declare i1 @llvm.vector.reduce.umin.v2i1(<2 x i1>)
238 declare i1 @llvm.vector.reduce.umax.nxv2i1(<vscale x 2 x i1>)
239 declare i1 @llvm.vector.reduce.umax.v2i1(<2 x i1>)
240 declare <vscale x 2 x i1> @llvm.vector.reverse.nxv2i1(<vscale x 2 x i1>)
241 declare <2 x i1> @llvm.vector.reverse.v2i1(<2 x i1>)