1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -expand-reductions -S | FileCheck %s
3 ; Tests without a target which should expand all reductions
4 declare i64 @llvm.experimental.vector.reduce.add.v2i64(<2 x i64>)
5 declare i64 @llvm.experimental.vector.reduce.mul.v2i64(<2 x i64>)
6 declare i64 @llvm.experimental.vector.reduce.and.v2i64(<2 x i64>)
7 declare i64 @llvm.experimental.vector.reduce.or.v2i64(<2 x i64>)
8 declare i64 @llvm.experimental.vector.reduce.xor.v2i64(<2 x i64>)
10 declare float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float, <4 x float>)
11 declare float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float, <4 x float>)
13 declare i64 @llvm.experimental.vector.reduce.smax.v2i64(<2 x i64>)
14 declare i64 @llvm.experimental.vector.reduce.smin.v2i64(<2 x i64>)
15 declare i64 @llvm.experimental.vector.reduce.umax.v2i64(<2 x i64>)
16 declare i64 @llvm.experimental.vector.reduce.umin.v2i64(<2 x i64>)
18 declare double @llvm.experimental.vector.reduce.fmax.v2f64(<2 x double>)
19 declare double @llvm.experimental.vector.reduce.fmin.v2f64(<2 x double>)
22 define i64 @add_i64(<2 x i64> %vec) {
23 ; CHECK-LABEL: @add_i64(
25 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x i64> [[VEC:%.*]], <2 x i64> undef, <2 x i32> <i32 1, i32 undef>
26 ; CHECK-NEXT: [[BIN_RDX:%.*]] = add <2 x i64> [[VEC]], [[RDX_SHUF]]
27 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x i64> [[BIN_RDX]], i32 0
28 ; CHECK-NEXT: ret i64 [[TMP0]]
31 %r = call i64 @llvm.experimental.vector.reduce.add.v2i64(<2 x i64> %vec)
35 define i64 @mul_i64(<2 x i64> %vec) {
36 ; CHECK-LABEL: @mul_i64(
38 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x i64> [[VEC:%.*]], <2 x i64> undef, <2 x i32> <i32 1, i32 undef>
39 ; CHECK-NEXT: [[BIN_RDX:%.*]] = mul <2 x i64> [[VEC]], [[RDX_SHUF]]
40 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x i64> [[BIN_RDX]], i32 0
41 ; CHECK-NEXT: ret i64 [[TMP0]]
44 %r = call i64 @llvm.experimental.vector.reduce.mul.v2i64(<2 x i64> %vec)
48 define i64 @and_i64(<2 x i64> %vec) {
49 ; CHECK-LABEL: @and_i64(
51 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x i64> [[VEC:%.*]], <2 x i64> undef, <2 x i32> <i32 1, i32 undef>
52 ; CHECK-NEXT: [[BIN_RDX:%.*]] = and <2 x i64> [[VEC]], [[RDX_SHUF]]
53 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x i64> [[BIN_RDX]], i32 0
54 ; CHECK-NEXT: ret i64 [[TMP0]]
57 %r = call i64 @llvm.experimental.vector.reduce.and.v2i64(<2 x i64> %vec)
61 define i64 @or_i64(<2 x i64> %vec) {
62 ; CHECK-LABEL: @or_i64(
64 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x i64> [[VEC:%.*]], <2 x i64> undef, <2 x i32> <i32 1, i32 undef>
65 ; CHECK-NEXT: [[BIN_RDX:%.*]] = or <2 x i64> [[VEC]], [[RDX_SHUF]]
66 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x i64> [[BIN_RDX]], i32 0
67 ; CHECK-NEXT: ret i64 [[TMP0]]
70 %r = call i64 @llvm.experimental.vector.reduce.or.v2i64(<2 x i64> %vec)
74 define i64 @xor_i64(<2 x i64> %vec) {
75 ; CHECK-LABEL: @xor_i64(
77 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x i64> [[VEC:%.*]], <2 x i64> undef, <2 x i32> <i32 1, i32 undef>
78 ; CHECK-NEXT: [[BIN_RDX:%.*]] = xor <2 x i64> [[VEC]], [[RDX_SHUF]]
79 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x i64> [[BIN_RDX]], i32 0
80 ; CHECK-NEXT: ret i64 [[TMP0]]
83 %r = call i64 @llvm.experimental.vector.reduce.xor.v2i64(<2 x i64> %vec)
87 define float @fadd_f32(<4 x float> %vec) {
88 ; CHECK-LABEL: @fadd_f32(
90 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <4 x float> [[VEC:%.*]], <4 x float> undef, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
91 ; CHECK-NEXT: [[BIN_RDX:%.*]] = fadd fast <4 x float> [[VEC]], [[RDX_SHUF]]
92 ; CHECK-NEXT: [[RDX_SHUF1:%.*]] = shufflevector <4 x float> [[BIN_RDX]], <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
93 ; CHECK-NEXT: [[BIN_RDX2:%.*]] = fadd fast <4 x float> [[BIN_RDX]], [[RDX_SHUF1]]
94 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x float> [[BIN_RDX2]], i32 0
95 ; CHECK-NEXT: [[TMP1:%.*]] = fadd fast float 0.000000e+00, [[TMP0]]
96 ; CHECK-NEXT: ret float [[TMP1]]
99 %r = call fast float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float 0.0, <4 x float> %vec)
103 define float @fadd_f32_accum(float %accum, <4 x float> %vec) {
104 ; CHECK-LABEL: @fadd_f32_accum(
106 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <4 x float> [[VEC:%.*]], <4 x float> undef, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
107 ; CHECK-NEXT: [[BIN_RDX:%.*]] = fadd fast <4 x float> [[VEC]], [[RDX_SHUF]]
108 ; CHECK-NEXT: [[RDX_SHUF1:%.*]] = shufflevector <4 x float> [[BIN_RDX]], <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
109 ; CHECK-NEXT: [[BIN_RDX2:%.*]] = fadd fast <4 x float> [[BIN_RDX]], [[RDX_SHUF1]]
110 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x float> [[BIN_RDX2]], i32 0
111 ; CHECK-NEXT: [[TMP1:%.*]] = fadd fast float %accum, [[TMP0]]
112 ; CHECK-NEXT: ret float [[TMP1]]
115 %r = call fast float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %accum, <4 x float> %vec)
119 define float @fadd_f32_strict(<4 x float> %vec) {
120 ; CHECK-LABEL: @fadd_f32_strict(
122 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x float> [[VEC:%.*]], i32 0
123 ; CHECK-NEXT: [[BIN_RDX:%.*]] = fadd float undef, [[TMP0]]
124 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[VEC]], i32 1
125 ; CHECK-NEXT: [[BIN_RDX1:%.*]] = fadd float [[BIN_RDX]], [[TMP1]]
126 ; CHECK-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[VEC]], i32 2
127 ; CHECK-NEXT: [[BIN_RDX2:%.*]] = fadd float [[BIN_RDX1]], [[TMP2]]
128 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[VEC]], i32 3
129 ; CHECK-NEXT: [[BIN_RDX3:%.*]] = fadd float [[BIN_RDX2]], [[TMP3]]
130 ; CHECK-NEXT: ret float [[BIN_RDX3]]
133 %r = call float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float undef, <4 x float> %vec)
137 define float @fadd_f32_strict_accum(float %accum, <4 x float> %vec) {
138 ; CHECK-LABEL: @fadd_f32_strict_accum(
140 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x float> [[VEC:%.*]], i32 0
141 ; CHECK-NEXT: [[BIN_RDX:%.*]] = fadd float [[ACCUM:%.*]], [[TMP0]]
142 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[VEC]], i32 1
143 ; CHECK-NEXT: [[BIN_RDX1:%.*]] = fadd float [[BIN_RDX]], [[TMP1]]
144 ; CHECK-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[VEC]], i32 2
145 ; CHECK-NEXT: [[BIN_RDX2:%.*]] = fadd float [[BIN_RDX1]], [[TMP2]]
146 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[VEC]], i32 3
147 ; CHECK-NEXT: [[BIN_RDX3:%.*]] = fadd float [[BIN_RDX2]], [[TMP3]]
148 ; CHECK-NEXT: ret float [[BIN_RDX3]]
151 %r = call float @llvm.experimental.vector.reduce.v2.fadd.f32.v4f32(float %accum, <4 x float> %vec)
155 define float @fmul_f32(<4 x float> %vec) {
156 ; CHECK-LABEL: @fmul_f32(
158 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <4 x float> [[VEC:%.*]], <4 x float> undef, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
159 ; CHECK-NEXT: [[BIN_RDX:%.*]] = fmul fast <4 x float> [[VEC]], [[RDX_SHUF]]
160 ; CHECK-NEXT: [[RDX_SHUF1:%.*]] = shufflevector <4 x float> [[BIN_RDX]], <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
161 ; CHECK-NEXT: [[BIN_RDX2:%.*]] = fmul fast <4 x float> [[BIN_RDX]], [[RDX_SHUF1]]
162 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x float> [[BIN_RDX2]], i32 0
163 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float 1.000000e+00, [[TMP0]]
164 ; CHECK-NEXT: ret float [[TMP1]]
167 %r = call fast float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float 1.0, <4 x float> %vec)
171 define float @fmul_f32_accum(float %accum, <4 x float> %vec) {
172 ; CHECK-LABEL: @fmul_f32_accum(
174 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <4 x float> [[VEC:%.*]], <4 x float> undef, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
175 ; CHECK-NEXT: [[BIN_RDX:%.*]] = fmul fast <4 x float> [[VEC]], [[RDX_SHUF]]
176 ; CHECK-NEXT: [[RDX_SHUF1:%.*]] = shufflevector <4 x float> [[BIN_RDX]], <4 x float> undef, <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
177 ; CHECK-NEXT: [[BIN_RDX2:%.*]] = fmul fast <4 x float> [[BIN_RDX]], [[RDX_SHUF1]]
178 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x float> [[BIN_RDX2]], i32 0
179 ; CHECK-NEXT: [[TMP1:%.*]] = fmul fast float %accum, [[TMP0]]
180 ; CHECK-NEXT: ret float [[TMP1]]
183 %r = call fast float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %accum, <4 x float> %vec)
187 define float @fmul_f32_strict(<4 x float> %vec) {
188 ; CHECK-LABEL: @fmul_f32_strict(
190 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x float> [[VEC:%.*]], i32 0
191 ; CHECK-NEXT: [[BIN_RDX:%.*]] = fmul float undef, [[TMP0]]
192 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[VEC]], i32 1
193 ; CHECK-NEXT: [[BIN_RDX1:%.*]] = fmul float [[BIN_RDX]], [[TMP1]]
194 ; CHECK-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[VEC]], i32 2
195 ; CHECK-NEXT: [[BIN_RDX2:%.*]] = fmul float [[BIN_RDX1]], [[TMP2]]
196 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[VEC]], i32 3
197 ; CHECK-NEXT: [[BIN_RDX3:%.*]] = fmul float [[BIN_RDX2]], [[TMP3]]
198 ; CHECK-NEXT: ret float [[BIN_RDX3]]
201 %r = call float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float undef, <4 x float> %vec)
205 define float @fmul_f32_strict_accum(float %accum, <4 x float> %vec) {
206 ; CHECK-LABEL: @fmul_f32_strict_accum(
208 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x float> [[VEC:%.*]], i32 0
209 ; CHECK-NEXT: [[BIN_RDX:%.*]] = fmul float [[ACCUM:%.*]], [[TMP0]]
210 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[VEC]], i32 1
211 ; CHECK-NEXT: [[BIN_RDX1:%.*]] = fmul float [[BIN_RDX]], [[TMP1]]
212 ; CHECK-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[VEC]], i32 2
213 ; CHECK-NEXT: [[BIN_RDX2:%.*]] = fmul float [[BIN_RDX1]], [[TMP2]]
214 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[VEC]], i32 3
215 ; CHECK-NEXT: [[BIN_RDX3:%.*]] = fmul float [[BIN_RDX2]], [[TMP3]]
216 ; CHECK-NEXT: ret float [[BIN_RDX3]]
219 %r = call float @llvm.experimental.vector.reduce.v2.fmul.f32.v4f32(float %accum, <4 x float> %vec)
223 define i64 @smax_i64(<2 x i64> %vec) {
224 ; CHECK-LABEL: @smax_i64(
226 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x i64> [[VEC:%.*]], <2 x i64> undef, <2 x i32> <i32 1, i32 undef>
227 ; CHECK-NEXT: [[RDX_MINMAX_CMP:%.*]] = icmp sgt <2 x i64> [[VEC]], [[RDX_SHUF]]
228 ; CHECK-NEXT: [[RDX_MINMAX_SELECT:%.*]] = select <2 x i1> [[RDX_MINMAX_CMP]], <2 x i64> [[VEC]], <2 x i64> [[RDX_SHUF]]
229 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x i64> [[RDX_MINMAX_SELECT]], i32 0
230 ; CHECK-NEXT: ret i64 [[TMP0]]
233 %r = call i64 @llvm.experimental.vector.reduce.smax.v2i64(<2 x i64> %vec)
237 define i64 @smin_i64(<2 x i64> %vec) {
238 ; CHECK-LABEL: @smin_i64(
240 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x i64> [[VEC:%.*]], <2 x i64> undef, <2 x i32> <i32 1, i32 undef>
241 ; CHECK-NEXT: [[RDX_MINMAX_CMP:%.*]] = icmp slt <2 x i64> [[VEC]], [[RDX_SHUF]]
242 ; CHECK-NEXT: [[RDX_MINMAX_SELECT:%.*]] = select <2 x i1> [[RDX_MINMAX_CMP]], <2 x i64> [[VEC]], <2 x i64> [[RDX_SHUF]]
243 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x i64> [[RDX_MINMAX_SELECT]], i32 0
244 ; CHECK-NEXT: ret i64 [[TMP0]]
247 %r = call i64 @llvm.experimental.vector.reduce.smin.v2i64(<2 x i64> %vec)
251 define i64 @umax_i64(<2 x i64> %vec) {
252 ; CHECK-LABEL: @umax_i64(
254 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x i64> [[VEC:%.*]], <2 x i64> undef, <2 x i32> <i32 1, i32 undef>
255 ; CHECK-NEXT: [[RDX_MINMAX_CMP:%.*]] = icmp ugt <2 x i64> [[VEC]], [[RDX_SHUF]]
256 ; CHECK-NEXT: [[RDX_MINMAX_SELECT:%.*]] = select <2 x i1> [[RDX_MINMAX_CMP]], <2 x i64> [[VEC]], <2 x i64> [[RDX_SHUF]]
257 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x i64> [[RDX_MINMAX_SELECT]], i32 0
258 ; CHECK-NEXT: ret i64 [[TMP0]]
261 %r = call i64 @llvm.experimental.vector.reduce.umax.v2i64(<2 x i64> %vec)
265 define i64 @umin_i64(<2 x i64> %vec) {
266 ; CHECK-LABEL: @umin_i64(
268 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x i64> [[VEC:%.*]], <2 x i64> undef, <2 x i32> <i32 1, i32 undef>
269 ; CHECK-NEXT: [[RDX_MINMAX_CMP:%.*]] = icmp ult <2 x i64> [[VEC]], [[RDX_SHUF]]
270 ; CHECK-NEXT: [[RDX_MINMAX_SELECT:%.*]] = select <2 x i1> [[RDX_MINMAX_CMP]], <2 x i64> [[VEC]], <2 x i64> [[RDX_SHUF]]
271 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x i64> [[RDX_MINMAX_SELECT]], i32 0
272 ; CHECK-NEXT: ret i64 [[TMP0]]
275 %r = call i64 @llvm.experimental.vector.reduce.umin.v2i64(<2 x i64> %vec)
279 define double @fmax_f64(<2 x double> %vec) {
280 ; CHECK-LABEL: @fmax_f64(
282 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x double> [[VEC:%.*]], <2 x double> undef, <2 x i32> <i32 1, i32 undef>
283 ; CHECK-NEXT: [[RDX_MINMAX_CMP:%.*]] = fcmp fast ogt <2 x double> [[VEC]], [[RDX_SHUF]]
284 ; CHECK-NEXT: [[RDX_MINMAX_SELECT:%.*]] = select fast <2 x i1> [[RDX_MINMAX_CMP]], <2 x double> [[VEC]], <2 x double> [[RDX_SHUF]]
285 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x double> [[RDX_MINMAX_SELECT]], i32 0
286 ; CHECK-NEXT: ret double [[TMP0]]
289 %r = call double @llvm.experimental.vector.reduce.fmax.v2f64(<2 x double> %vec)
293 define double @fmin_f64(<2 x double> %vec) {
294 ; CHECK-LABEL: @fmin_f64(
296 ; CHECK-NEXT: [[RDX_SHUF:%.*]] = shufflevector <2 x double> [[VEC:%.*]], <2 x double> undef, <2 x i32> <i32 1, i32 undef>
297 ; CHECK-NEXT: [[RDX_MINMAX_CMP:%.*]] = fcmp fast olt <2 x double> [[VEC]], [[RDX_SHUF]]
298 ; CHECK-NEXT: [[RDX_MINMAX_SELECT:%.*]] = select fast <2 x i1> [[RDX_MINMAX_CMP]], <2 x double> [[VEC]], <2 x double> [[RDX_SHUF]]
299 ; CHECK-NEXT: [[TMP0:%.*]] = extractelement <2 x double> [[RDX_MINMAX_SELECT]], i32 0
300 ; CHECK-NEXT: ret double [[TMP0]]
303 %r = call double @llvm.experimental.vector.reduce.fmin.v2f64(<2 x double> %vec)