Import pre-release gcc-5.0 to new vendor branch
[dragonfly.git] / contrib / gcc-5.0 / gcc / config / i386 / sse.md
1 ;; GCC machine description for SSE instructions
2 ;; Copyright (C) 2005-2015 Free Software Foundation, Inc.
3 ;;
4 ;; This file is part of GCC.
5 ;;
6 ;; GCC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 3, or (at your option)
9 ;; any later version.
10 ;;
11 ;; GCC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;; GNU General Public License for more details.
15 ;;
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING3.  If not see
18 ;; <http://www.gnu.org/licenses/>.
19
20 (define_c_enum "unspec" [
21   ;; SSE
22   UNSPEC_MOVNT
23   UNSPEC_LOADU
24   UNSPEC_STOREU
25
26   ;; SSE3
27   UNSPEC_LDDQU
28
29   ;; SSSE3
30   UNSPEC_PSHUFB
31   UNSPEC_PSIGN
32   UNSPEC_PALIGNR
33
34   ;; For SSE4A support
35   UNSPEC_EXTRQI
36   UNSPEC_EXTRQ
37   UNSPEC_INSERTQI
38   UNSPEC_INSERTQ
39
40   ;; For SSE4.1 support
41   UNSPEC_BLENDV
42   UNSPEC_INSERTPS
43   UNSPEC_DP
44   UNSPEC_MOVNTDQA
45   UNSPEC_MPSADBW
46   UNSPEC_PHMINPOSUW
47   UNSPEC_PTEST
48
49   ;; For SSE4.2 support
50   UNSPEC_PCMPESTR
51   UNSPEC_PCMPISTR
52
53   ;; For FMA4 support
54   UNSPEC_FMADDSUB
55   UNSPEC_XOP_UNSIGNED_CMP
56   UNSPEC_XOP_TRUEFALSE
57   UNSPEC_XOP_PERMUTE
58   UNSPEC_FRCZ
59
60   ;; For AES support
61   UNSPEC_AESENC
62   UNSPEC_AESENCLAST
63   UNSPEC_AESDEC
64   UNSPEC_AESDECLAST
65   UNSPEC_AESIMC
66   UNSPEC_AESKEYGENASSIST
67
68   ;; For PCLMUL support
69   UNSPEC_PCLMUL
70
71   ;; For AVX support
72   UNSPEC_PCMP
73   UNSPEC_VPERMIL
74   UNSPEC_VPERMIL2
75   UNSPEC_VPERMIL2F128
76   UNSPEC_CAST
77   UNSPEC_VTESTP
78   UNSPEC_VCVTPH2PS
79   UNSPEC_VCVTPS2PH
80
81   ;; For AVX2 support
82   UNSPEC_VPERMVAR
83   UNSPEC_VPERMTI
84   UNSPEC_GATHER
85   UNSPEC_VSIBADDR
86
87   ;; For AVX512F support
88   UNSPEC_VPERMI2
89   UNSPEC_VPERMT2
90   UNSPEC_VPERMI2_MASK
91   UNSPEC_UNSIGNED_FIX_NOTRUNC
92   UNSPEC_UNSIGNED_PCMP
93   UNSPEC_TESTM
94   UNSPEC_TESTNM
95   UNSPEC_SCATTER
96   UNSPEC_RCP14
97   UNSPEC_RSQRT14
98   UNSPEC_FIXUPIMM
99   UNSPEC_SCALEF
100   UNSPEC_VTERNLOG
101   UNSPEC_GETEXP
102   UNSPEC_GETMANT
103   UNSPEC_ALIGN
104   UNSPEC_CONFLICT
105   UNSPEC_COMPRESS
106   UNSPEC_COMPRESS_STORE
107   UNSPEC_EXPAND
108   UNSPEC_MASKED_EQ
109   UNSPEC_MASKED_GT
110
111   ;; For embed. rounding feature
112   UNSPEC_EMBEDDED_ROUNDING
113
114   ;; For AVX512PF support
115   UNSPEC_GATHER_PREFETCH
116   UNSPEC_SCATTER_PREFETCH
117
118   ;; For AVX512ER support
119   UNSPEC_EXP2
120   UNSPEC_RCP28
121   UNSPEC_RSQRT28
122
123   ;; For SHA support
124   UNSPEC_SHA1MSG1
125   UNSPEC_SHA1MSG2
126   UNSPEC_SHA1NEXTE
127   UNSPEC_SHA1RNDS4
128   UNSPEC_SHA256MSG1
129   UNSPEC_SHA256MSG2
130   UNSPEC_SHA256RNDS2
131
132   ;; For AVX512BW support
133   UNSPEC_DBPSADBW
134   UNSPEC_PMADDUBSW512
135   UNSPEC_PMADDWD512
136   UNSPEC_PSHUFHW
137   UNSPEC_PSHUFLW
138   UNSPEC_CVTINT2MASK
139
140   ;; For AVX512DQ support
141   UNSPEC_REDUCE
142   UNSPEC_FPCLASS
143   UNSPEC_RANGE
144
145   ;; For AVX512IFMA support
146   UNSPEC_VPMADD52LUQ
147   UNSPEC_VPMADD52HUQ
148
149   ;; For AVX512VBMI support
150   UNSPEC_VPMULTISHIFT
151 ])
152
153 (define_c_enum "unspecv" [
154   UNSPECV_LDMXCSR
155   UNSPECV_STMXCSR
156   UNSPECV_CLFLUSH
157   UNSPECV_MONITOR
158   UNSPECV_MWAIT
159   UNSPECV_VZEROALL
160   UNSPECV_VZEROUPPER
161 ])
162
163 ;; All vector modes including V?TImode, used in move patterns.
164 (define_mode_iterator VMOVE
165   [(V64QI "TARGET_AVX512F") (V32QI "TARGET_AVX") V16QI
166    (V32HI "TARGET_AVX512F") (V16HI "TARGET_AVX") V8HI
167    (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX") V4SI
168    (V8DI "TARGET_AVX512F")  (V4DI "TARGET_AVX") V2DI
169    (V4TI "TARGET_AVX512BW") (V2TI "TARGET_AVX") V1TI
170    (V16SF "TARGET_AVX512F") (V8SF "TARGET_AVX") V4SF
171    (V8DF "TARGET_AVX512F")  (V4DF "TARGET_AVX") V2DF])
172
173 ;; All AVX-512{F,VL} vector modes. Supposed TARGET_AVX512F baseline.
174 (define_mode_iterator V48_AVX512VL
175   [V16SI (V8SI "TARGET_AVX512VL") (V4SI "TARGET_AVX512VL")
176    V8DI  (V4DI "TARGET_AVX512VL") (V2DI "TARGET_AVX512VL")
177    V16SF (V8SF "TARGET_AVX512VL") (V4SF "TARGET_AVX512VL")
178    V8DF  (V4DF "TARGET_AVX512VL") (V2DF "TARGET_AVX512VL")])
179
180 ;; 1,2 byte AVX-512{BW,VL} vector modes. Supposed TARGET_AVX512BW baseline.
181 (define_mode_iterator VI12_AVX512VL
182   [V64QI (V16QI "TARGET_AVX512VL") (V32QI "TARGET_AVX512VL")
183    V32HI (V16HI "TARGET_AVX512VL") (V8HI "TARGET_AVX512VL")])
184
185 (define_mode_iterator VI1_AVX512VL
186   [V64QI (V16QI "TARGET_AVX512VL") (V32QI "TARGET_AVX512VL")])
187
188 ;; All vector modes
189 (define_mode_iterator V
190   [(V32QI "TARGET_AVX") V16QI
191    (V16HI "TARGET_AVX") V8HI
192    (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX") V4SI
193    (V8DI "TARGET_AVX512F")  (V4DI "TARGET_AVX") V2DI
194    (V16SF "TARGET_AVX512F") (V8SF "TARGET_AVX") V4SF
195    (V8DF "TARGET_AVX512F")  (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
196
197 ;; All 128bit vector modes
198 (define_mode_iterator V_128
199   [V16QI V8HI V4SI V2DI V4SF (V2DF "TARGET_SSE2")])
200
201 ;; All 256bit vector modes
202 (define_mode_iterator V_256
203   [V32QI V16HI V8SI V4DI V8SF V4DF])
204
205 ;; All 512bit vector modes
206 (define_mode_iterator V_512 [V64QI V32HI V16SI V8DI V16SF V8DF])
207
208 ;; All 256bit and 512bit vector modes
209 (define_mode_iterator V_256_512
210   [V32QI V16HI V8SI V4DI V8SF V4DF
211    (V64QI "TARGET_AVX512F") (V32HI "TARGET_AVX512F") (V16SI "TARGET_AVX512F")
212    (V8DI "TARGET_AVX512F") (V16SF "TARGET_AVX512F") (V8DF "TARGET_AVX512F")])
213
214 ;; All vector float modes
215 (define_mode_iterator VF
216   [(V16SF "TARGET_AVX512F") (V8SF "TARGET_AVX") V4SF
217    (V8DF "TARGET_AVX512F") (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
218
219 ;; 128- and 256-bit float vector modes
220 (define_mode_iterator VF_128_256
221   [(V8SF "TARGET_AVX") V4SF
222    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
223
224 ;; All SFmode vector float modes
225 (define_mode_iterator VF1
226   [(V16SF "TARGET_AVX512F") (V8SF "TARGET_AVX") V4SF])
227
228 ;; 128- and 256-bit SF vector modes
229 (define_mode_iterator VF1_128_256
230   [(V8SF "TARGET_AVX") V4SF])
231
232 (define_mode_iterator VF1_128_256VL
233   [V8SF (V4SF "TARGET_AVX512VL")])
234
235 ;; All DFmode vector float modes
236 (define_mode_iterator VF2
237   [(V8DF "TARGET_AVX512F") (V4DF "TARGET_AVX") V2DF])
238
239 ;; 128- and 256-bit DF vector modes
240 (define_mode_iterator VF2_128_256
241   [(V4DF "TARGET_AVX") V2DF])
242
243 (define_mode_iterator VF2_512_256
244   [(V8DF "TARGET_AVX512F") V4DF])
245
246 (define_mode_iterator VF2_512_256VL
247   [V8DF (V4DF "TARGET_AVX512VL")])
248
249 ;; All 128bit vector float modes
250 (define_mode_iterator VF_128
251   [V4SF (V2DF "TARGET_SSE2")])
252
253 ;; All 256bit vector float modes
254 (define_mode_iterator VF_256
255   [V8SF V4DF])
256
257 ;; All 512bit vector float modes
258 (define_mode_iterator VF_512
259   [V16SF V8DF])
260
261 (define_mode_iterator VI48_AVX512VL
262   [V16SI (V8SI  "TARGET_AVX512VL") (V4SI  "TARGET_AVX512VL")
263    V8DI  (V4DI  "TARGET_AVX512VL") (V2DI  "TARGET_AVX512VL")])
264
265 (define_mode_iterator VF_AVX512VL
266   [V16SF (V8SF "TARGET_AVX512VL") (V4SF "TARGET_AVX512VL")
267    V8DF (V4DF "TARGET_AVX512VL") (V2DF "TARGET_AVX512VL")])
268
269 (define_mode_iterator VF2_AVX512VL
270   [V8DF (V4DF "TARGET_AVX512VL") (V2DF "TARGET_AVX512VL")])
271
272 (define_mode_iterator VF1_AVX512VL
273   [V16SF (V8SF "TARGET_AVX512VL") (V4SF "TARGET_AVX512VL")])
274
275 ;; All vector integer modes
276 (define_mode_iterator VI
277   [(V16SI "TARGET_AVX512F") (V8DI "TARGET_AVX512F")
278    (V64QI "TARGET_AVX512BW") (V32QI "TARGET_AVX") V16QI
279    (V32HI "TARGET_AVX512BW") (V16HI "TARGET_AVX") V8HI
280    (V8SI "TARGET_AVX") V4SI
281    (V4DI "TARGET_AVX") V2DI])
282
283 (define_mode_iterator VI_AVX2
284   [(V64QI "TARGET_AVX512BW") (V32QI "TARGET_AVX2") V16QI
285    (V32HI "TARGET_AVX512BW") (V16HI "TARGET_AVX2") V8HI
286    (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX2") V4SI
287    (V8DI "TARGET_AVX512F") (V4DI "TARGET_AVX2") V2DI])
288
289 ;; All QImode vector integer modes
290 (define_mode_iterator VI1
291   [(V32QI "TARGET_AVX") V16QI])
292
293 (define_mode_iterator VI_ULOADSTORE_BW_AVX512VL
294   [V64QI
295    V32HI (V8HI "TARGET_AVX512VL") (V16HI "TARGET_AVX512VL")])
296
297 (define_mode_iterator VI_ULOADSTORE_F_AVX512VL
298   [V16SI (V8SI "TARGET_AVX512VL") (V4SI "TARGET_AVX512VL")
299    V8DI (V4DI "TARGET_AVX512VL") (V2DI "TARGET_AVX512VL")])
300
301 ;; All DImode vector integer modes
302 (define_mode_iterator VI8
303   [(V8DI "TARGET_AVX512F") (V4DI "TARGET_AVX") V2DI])
304
305 (define_mode_iterator VI8_AVX512VL
306   [V8DI (V4DI "TARGET_AVX512VL") (V2DI "TARGET_AVX512VL")])
307
308 (define_mode_iterator VI8_256_512
309   [V8DI (V4DI "TARGET_AVX512VL")])
310
311 (define_mode_iterator VI1_AVX2
312   [(V32QI "TARGET_AVX2") V16QI])
313
314 (define_mode_iterator VI1_AVX512
315   [(V64QI "TARGET_AVX512BW") (V32QI "TARGET_AVX2") V16QI])
316
317 (define_mode_iterator VI2_AVX2
318   [(V32HI "TARGET_AVX512BW") (V16HI "TARGET_AVX2") V8HI])
319
320 (define_mode_iterator VI2_AVX512F
321   [(V32HI "TARGET_AVX512F") (V16HI "TARGET_AVX2") V8HI])
322
323 (define_mode_iterator VI4_AVX
324   [(V8SI "TARGET_AVX") V4SI])
325
326 (define_mode_iterator VI4_AVX2
327   [(V8SI "TARGET_AVX2") V4SI])
328
329 (define_mode_iterator VI4_AVX512F
330   [(V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX2") V4SI])
331
332 (define_mode_iterator VI4_AVX512VL
333   [V16SI (V8SI "TARGET_AVX512VL") (V4SI "TARGET_AVX512VL")])
334
335 (define_mode_iterator VI48_AVX512F_AVX512VL
336   [V4SI V8SI (V16SI "TARGET_AVX512F")
337    (V2DI "TARGET_AVX512VL") (V4DI "TARGET_AVX512VL") (V8DI "TARGET_AVX512F")])
338
339 (define_mode_iterator VI2_AVX512VL
340   [(V8HI "TARGET_AVX512VL") (V16HI "TARGET_AVX512VL") V32HI])
341
342 (define_mode_iterator VI8_AVX2_AVX512BW
343   [(V8DI "TARGET_AVX512BW") (V4DI "TARGET_AVX2") V2DI])
344
345 (define_mode_iterator VI8_AVX2
346   [(V4DI "TARGET_AVX2") V2DI])
347
348 (define_mode_iterator VI8_AVX2_AVX512F
349   [(V8DI "TARGET_AVX512F") (V4DI "TARGET_AVX2") V2DI])
350
351 (define_mode_iterator VI4_128_8_256
352   [V4SI V4DI])
353
354 ;; All V8D* modes
355 (define_mode_iterator V8FI
356   [V8DF V8DI])
357
358 ;; All V16S* modes
359 (define_mode_iterator V16FI
360   [V16SF V16SI])
361
362 ;; ??? We should probably use TImode instead.
363 (define_mode_iterator VIMAX_AVX2
364   [(V4TI "TARGET_AVX512BW") (V2TI "TARGET_AVX2") V1TI])
365
366 ;; ??? This should probably be dropped in favor of VIMAX_AVX2.
367 (define_mode_iterator SSESCALARMODE
368   [(V4TI "TARGET_AVX512BW") (V2TI "TARGET_AVX2") TI])
369
370 (define_mode_iterator VI12_AVX2
371   [(V64QI "TARGET_AVX512BW") (V32QI "TARGET_AVX2") V16QI
372    (V32HI "TARGET_AVX512BW") (V16HI "TARGET_AVX2") V8HI])
373
374 (define_mode_iterator VI24_AVX2
375   [(V16HI "TARGET_AVX2") V8HI
376    (V8SI "TARGET_AVX2") V4SI])
377
378 (define_mode_iterator VI124_AVX512F
379   [(V32QI "TARGET_AVX2") V16QI
380    (V32HI "TARGET_AVX512F") (V16HI "TARGET_AVX2") V8HI
381    (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX2") V4SI])
382
383 (define_mode_iterator VI124_AVX2
384   [(V32QI "TARGET_AVX2") V16QI
385    (V16HI "TARGET_AVX2") V8HI
386    (V8SI "TARGET_AVX2") V4SI])
387
388 (define_mode_iterator VI2_AVX2_AVX512BW
389   [(V32HI "TARGET_AVX512BW") (V16HI "TARGET_AVX2") V8HI])
390
391 (define_mode_iterator VI48_AVX2
392   [(V8SI "TARGET_AVX2") V4SI
393    (V4DI "TARGET_AVX2") V2DI])
394
395 (define_mode_iterator VI248_AVX2_8_AVX512F
396   [(V16HI "TARGET_AVX2") V8HI
397    (V8SI "TARGET_AVX2") V4SI
398    (V8DI "TARGET_AVX512F") (V4DI "TARGET_AVX2") V2DI])
399
400 (define_mode_iterator VI248_AVX512BW_AVX512VL
401   [(V32HI "TARGET_AVX512BW") 
402    (V4DI "TARGET_AVX512VL") V16SI V8DI])
403
404 ;; Suppose TARGET_AVX512VL as baseline
405 (define_mode_iterator VI24_AVX512BW_1
406  [(V16HI "TARGET_AVX512BW") (V8HI "TARGET_AVX512BW")
407   V8SI V4SI])
408    
409 (define_mode_iterator VI48_AVX512F
410   [(V16SI "TARGET_AVX512F") V8SI V4SI
411    (V8DI "TARGET_AVX512F") V4DI V2DI])
412
413 (define_mode_iterator V48_AVX2
414   [V4SF V2DF
415    V8SF V4DF
416    (V4SI "TARGET_AVX2") (V2DI "TARGET_AVX2")
417    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")])
418
419 (define_mode_attr avx512
420   [(V16QI "avx512vl") (V32QI "avx512vl") (V64QI "avx512bw")
421    (V8HI  "avx512vl") (V16HI  "avx512vl") (V32HI "avx512bw")
422    (V4SI  "avx512vl") (V8SI  "avx512vl") (V16SI "avx512f")
423    (V2DI  "avx512vl") (V4DI  "avx512vl") (V8DI "avx512f")
424    (V4SF "avx512vl") (V8SF "avx512vl") (V16SF "avx512f")
425    (V2DF "avx512vl") (V4DF "avx512vl") (V8DF "avx512f")])
426
427 (define_mode_attr sse2_avx_avx512f
428   [(V16QI "sse2") (V32QI "avx") (V64QI "avx512f")
429    (V8HI  "avx512vl") (V16HI  "avx512vl") (V32HI "avx512bw")
430    (V4SI  "sse2") (V8SI  "avx") (V16SI "avx512f")
431    (V2DI  "avx512vl") (V4DI  "avx512vl") (V8DI "avx512f")
432    (V16SF "avx512f") (V8SF "avx") (V4SF "avx")
433    (V8DF "avx512f") (V4DF "avx") (V2DF "avx")])
434
435 (define_mode_attr sse2_avx2
436   [(V16QI "sse2") (V32QI "avx2") (V64QI "avx512bw")
437    (V8HI "sse2") (V16HI "avx2") (V32HI "avx512bw")
438    (V4SI "sse2") (V8SI "avx2") (V16SI "avx512f")
439    (V2DI "sse2") (V4DI "avx2") (V8DI "avx512f")
440    (V1TI "sse2") (V2TI "avx2") (V4TI "avx512bw")])
441
442 (define_mode_attr ssse3_avx2
443    [(V16QI "ssse3") (V32QI "avx2") (V64QI "avx512bw")
444     (V4HI "ssse3") (V8HI "ssse3") (V16HI "avx2") (V32HI "avx512bw")
445     (V4SI "ssse3") (V8SI "avx2")
446     (V2DI "ssse3") (V4DI "avx2")
447     (TI "ssse3") (V2TI "avx2") (V4TI "avx512bw")])
448
449 (define_mode_attr sse4_1_avx2
450    [(V16QI "sse4_1") (V32QI "avx2") (V64QI "avx512bw")
451     (V8HI "sse4_1") (V16HI "avx2") (V32HI "avx512bw")
452     (V4SI "sse4_1") (V8SI "avx2") (V16SI "avx512f")
453     (V2DI "sse4_1") (V4DI "avx2") (V8DI "avx512dq")])
454
455 (define_mode_attr avx_avx2
456   [(V4SF "avx") (V2DF "avx")
457    (V8SF "avx") (V4DF "avx")
458    (V4SI "avx2") (V2DI "avx2")
459    (V8SI "avx2") (V4DI "avx2")])
460
461 (define_mode_attr vec_avx2
462   [(V16QI "vec") (V32QI "avx2")
463    (V8HI "vec") (V16HI "avx2")
464    (V4SI "vec") (V8SI "avx2")
465    (V2DI "vec") (V4DI "avx2")])
466
467 (define_mode_attr avx2_avx512
468   [(V4SI "avx2") (V8SI "avx2") (V16SI "avx512f")
469    (V2DI "avx2") (V4DI "avx2") (V8DI "avx512f")
470    (V4SF "avx2") (V8SF "avx2") (V16SF "avx512f")
471    (V2DF "avx2") (V4DF "avx2") (V8DF "avx512f")
472    (V8HI "avx512vl") (V16HI "avx512vl") (V32HI "avx512bw")])
473
474 (define_mode_attr shuffletype
475   [(V16SF "f") (V16SI "i") (V8DF "f") (V8DI "i")
476   (V8SF "f") (V8SI "i") (V4DF "f") (V4DI "i")
477   (V4SF "f") (V4SI "i") (V2DF "f") (V2DI "i")
478   (V32QI "i") (V16HI "u") (V16QI "i") (V8HI "i")
479   (V64QI "i") (V1TI "i") (V2TI "i")])
480
481 (define_mode_attr ssequartermode
482   [(V16SF "V4SF") (V8DF "V2DF") (V16SI "V4SI") (V8DI "V2DI")])
483
484 (define_mode_attr ssedoublemodelower
485   [(V16QI "v16hi") (V32QI "v32hi") (V64QI "v64hi")
486    (V8HI "v8si")   (V16HI "v16si") (V32HI "v32si")
487    (V4SI "v4di")   (V8SI "v8di")   (V16SI "v16di")])
488
489 (define_mode_attr ssedoublemode
490   [(V16SF "V32SF") (V16SI "V32SI") (V8DI "V16DI") (V8DF "V16DF")
491    (V8SF "V16SF") (V8SI "V16SI") (V4DI "V8DI") (V4DF "V8DF")
492    (V16HI "V16SI") (V8HI "V8SI") (V4HI "V4SI") (V4SI "V4DI")
493    (V32HI "V32SI") (V32QI "V32HI") (V16QI "V16HI") (V64QI "V64HI")])
494
495 (define_mode_attr ssebytemode
496   [(V8DI "V64QI") (V4DI "V32QI") (V2DI "V16QI")])
497
498 ;; All 128bit vector integer modes
499 (define_mode_iterator VI_128 [V16QI V8HI V4SI V2DI])
500
501 ;; All 256bit vector integer modes
502 (define_mode_iterator VI_256 [V32QI V16HI V8SI V4DI])
503
504 ;; All 512bit vector integer modes
505 (define_mode_iterator VI_512 [V64QI V32HI V16SI V8DI])
506
507 ;; Various 128bit vector integer mode combinations
508 (define_mode_iterator VI12_128 [V16QI V8HI])
509 (define_mode_iterator VI14_128 [V16QI V4SI])
510 (define_mode_iterator VI124_128 [V16QI V8HI V4SI])
511 (define_mode_iterator VI24_128 [V8HI V4SI])
512 (define_mode_iterator VI248_128 [V8HI V4SI V2DI])
513 (define_mode_iterator VI48_128 [V4SI V2DI])
514
515 ;; Various 256bit and 512 vector integer mode combinations
516 (define_mode_iterator VI124_256 [V32QI V16HI V8SI])
517 (define_mode_iterator VI124_256_AVX512F_AVX512BW
518   [V32QI V16HI V8SI
519    (V64QI "TARGET_AVX512BW")
520    (V32HI "TARGET_AVX512BW")
521    (V16SI "TARGET_AVX512F")])
522 (define_mode_iterator VI48_256 [V8SI V4DI])
523 (define_mode_iterator VI48_512 [V16SI V8DI])
524 (define_mode_iterator VI4_256_8_512 [V8SI V8DI])
525 (define_mode_iterator VI_AVX512BW
526   [V16SI V8DI (V32HI "TARGET_AVX512BW") (V64QI "TARGET_AVX512BW")])
527
528 ;; Int-float size matches
529 (define_mode_iterator VI4F_128 [V4SI V4SF])
530 (define_mode_iterator VI8F_128 [V2DI V2DF])
531 (define_mode_iterator VI4F_256 [V8SI V8SF])
532 (define_mode_iterator VI8F_256 [V4DI V4DF])
533 (define_mode_iterator VI8F_256_512
534   [V4DI V4DF (V8DI "TARGET_AVX512F") (V8DF "TARGET_AVX512F")])
535 (define_mode_iterator VI48F_256_512
536   [V8SI V8SF
537   (V16SI "TARGET_AVX512F") (V16SF "TARGET_AVX512F")
538   (V8DI  "TARGET_AVX512F") (V8DF  "TARGET_AVX512F")
539   (V4DI  "TARGET_AVX512VL") (V4DF  "TARGET_AVX512VL")])
540 (define_mode_iterator VF48_I1248
541   [V16SI V16SF V8DI V8DF V32HI V64QI])
542 (define_mode_iterator VI48F
543   [V16SI V16SF V8DI V8DF
544    (V8SI "TARGET_AVX512VL") (V8SF "TARGET_AVX512VL")
545    (V4DI "TARGET_AVX512VL") (V4DF "TARGET_AVX512VL")
546    (V4SI "TARGET_AVX512VL") (V4SF "TARGET_AVX512VL")
547    (V2DI "TARGET_AVX512VL") (V2DF "TARGET_AVX512VL")])
548 (define_mode_iterator VI48F_256 [V8SI V8SF V4DI V4DF])
549
550 ;; Mapping from float mode to required SSE level
551 (define_mode_attr sse
552   [(SF "sse") (DF "sse2")
553    (V4SF "sse") (V2DF "sse2")
554    (V16SF "avx512f") (V8SF "avx")
555    (V8DF "avx512f") (V4DF "avx")])
556
557 (define_mode_attr sse2
558   [(V16QI "sse2") (V32QI "avx") (V64QI "avx512f")
559    (V2DI "sse2") (V4DI "avx") (V8DI "avx512f")])
560
561 (define_mode_attr sse3
562   [(V16QI "sse3") (V32QI "avx")])
563
564 (define_mode_attr sse4_1
565   [(V4SF "sse4_1") (V2DF "sse4_1")
566    (V8SF "avx") (V4DF "avx")
567    (V8DF "avx512f")])
568
569 (define_mode_attr avxsizesuffix
570   [(V64QI "512") (V32HI "512") (V16SI "512") (V8DI "512")
571    (V32QI "256") (V16HI "256") (V8SI "256") (V4DI "256")
572    (V16QI "") (V8HI "") (V4SI "") (V2DI "")
573    (V16SF "512") (V8DF "512")
574    (V8SF "256") (V4DF "256")
575    (V4SF "") (V2DF "")])
576
577 ;; SSE instruction mode
578 (define_mode_attr sseinsnmode
579   [(V64QI "XI") (V32HI "XI") (V16SI "XI") (V8DI "XI") (V4TI "XI")
580    (V32QI "OI") (V16HI "OI") (V8SI "OI") (V4DI "OI") (V2TI "OI")
581    (V16QI "TI") (V8HI "TI") (V4SI "TI") (V2DI "TI") (V1TI "TI")
582    (V16SF "V16SF") (V8DF "V8DF")
583    (V8SF "V8SF") (V4DF "V4DF")
584    (V4SF "V4SF") (V2DF "V2DF")
585    (TI "TI")])
586
587 ;; Mapping of vector modes to corresponding mask size
588 (define_mode_attr avx512fmaskmode
589   [(V64QI "DI") (V32QI "SI") (V16QI "HI")
590    (V32HI "SI") (V16HI "HI") (V8HI  "QI") (V4HI "QI")
591    (V16SI "HI") (V8SI  "QI") (V4SI  "QI")
592    (V8DI  "QI") (V4DI  "QI") (V2DI  "QI")
593    (V16SF "HI") (V8SF  "QI") (V4SF  "QI")
594    (V8DF  "QI") (V4DF  "QI") (V2DF  "QI")])
595
596 ;; Mapping of vector float modes to an integer mode of the same size
597 (define_mode_attr sseintvecmode
598   [(V16SF "V16SI") (V8DF  "V8DI")
599    (V8SF  "V8SI")  (V4DF  "V4DI")
600    (V4SF  "V4SI")  (V2DF  "V2DI")
601    (V16SI "V16SI") (V8DI  "V8DI")
602    (V8SI  "V8SI")  (V4DI  "V4DI")
603    (V4SI  "V4SI")  (V2DI  "V2DI")
604    (V16HI "V16HI") (V8HI  "V8HI")
605    (V32HI "V32HI") (V64QI "V64QI")
606    (V32QI "V32QI") (V16QI "V16QI")])
607
608 (define_mode_attr sseintvecmode2
609   [(V8DF "XI") (V4DF "OI") (V2DF "TI")
610    (V8SF "OI") (V4SF "TI")])
611
612 (define_mode_attr sseintvecmodelower
613   [(V16SF "v16si") (V8DF "v8di")
614    (V8SF "v8si") (V4DF "v4di")
615    (V4SF "v4si") (V2DF "v2di")
616    (V8SI "v8si") (V4DI "v4di")
617    (V4SI "v4si") (V2DI "v2di")
618    (V16HI "v16hi") (V8HI "v8hi")
619    (V32QI "v32qi") (V16QI "v16qi")])
620
621 ;; Mapping of vector modes to a vector mode of double size
622 (define_mode_attr ssedoublevecmode
623   [(V32QI "V64QI") (V16HI "V32HI") (V8SI "V16SI") (V4DI "V8DI")
624    (V16QI "V32QI") (V8HI "V16HI") (V4SI "V8SI") (V2DI "V4DI")
625    (V8SF "V16SF") (V4DF "V8DF")
626    (V4SF "V8SF") (V2DF "V4DF")])
627
628 ;; Mapping of vector modes to a vector mode of half size
629 (define_mode_attr ssehalfvecmode
630   [(V64QI "V32QI") (V32HI "V16HI") (V16SI "V8SI") (V8DI "V4DI")
631    (V32QI "V16QI") (V16HI  "V8HI") (V8SI  "V4SI") (V4DI "V2DI")
632    (V16QI  "V8QI") (V8HI   "V4HI") (V4SI  "V2SI")
633    (V16SF "V8SF") (V8DF "V4DF")
634    (V8SF  "V4SF") (V4DF "V2DF")
635    (V4SF  "V2SF")])
636
637 ;; Mapping of vector modes ti packed single mode of the same size
638 (define_mode_attr ssePSmode
639   [(V16SI "V16SF") (V8DF "V16SF")
640    (V16SF "V16SF") (V8DI "V16SF")
641    (V64QI "V16SF") (V32QI "V8SF") (V16QI "V4SF")
642    (V32HI "V16SF") (V16HI "V8SF") (V8HI "V4SF")
643    (V8SI "V8SF") (V4SI "V4SF")
644    (V4DI "V8SF") (V2DI "V4SF")
645    (V4TI "V16SF") (V2TI "V8SF") (V1TI "V4SF")
646    (V8SF "V8SF") (V4SF "V4SF")
647    (V4DF "V8SF") (V2DF "V4SF")])
648
649 (define_mode_attr ssePSmode2
650   [(V8DI "V8SF") (V4DI "V4SF")])
651
652 ;; Mapping of vector modes back to the scalar modes
653 (define_mode_attr ssescalarmode
654   [(V64QI "QI") (V32QI "QI") (V16QI "QI")
655    (V32HI "HI") (V16HI "HI") (V8HI "HI")
656    (V16SI "SI") (V8SI "SI")  (V4SI "SI")
657    (V8DI "DI")  (V4DI "DI")  (V2DI "DI")
658    (V16SF "SF") (V8SF "SF")  (V4SF "SF")
659    (V8DF "DF")  (V4DF "DF")  (V2DF "DF")])
660
661 ;; Mapping of vector modes to the 128bit modes
662 (define_mode_attr ssexmmmode
663   [(V64QI "V16QI") (V32QI "V16QI") (V16QI "V16QI")
664    (V32HI "V8HI")  (V16HI "V8HI") (V8HI "V8HI")
665    (V16SI "V4SI")  (V8SI "V4SI")  (V4SI "V4SI")
666    (V8DI "V2DI")   (V4DI "V2DI")  (V2DI "V2DI")
667    (V16SF "V4SF")  (V8SF "V4SF")  (V4SF "V4SF")
668    (V8DF "V2DF")   (V4DF "V2DF")  (V2DF "V2DF")])
669
670 ;; Pointer size override for scalar modes (Intel asm dialect)
671 (define_mode_attr iptr
672   [(V32QI "b") (V16HI "w") (V8SI "k") (V4DI "q")
673    (V16QI "b") (V8HI "w") (V4SI "k") (V2DI "q")
674    (V8SF "k") (V4DF "q")
675    (V4SF "k") (V2DF "q")
676    (SF "k") (DF "q")])
677
678 ;; Number of scalar elements in each vector type
679 (define_mode_attr ssescalarnum
680   [(V64QI "64") (V16SI "16") (V8DI "8")
681    (V32QI "32") (V16HI "16") (V8SI "8") (V4DI "4")
682    (V16QI "16") (V8HI "8") (V4SI "4") (V2DI "2")
683    (V16SF "16") (V8DF "8")
684    (V8SF "8") (V4DF "4")
685    (V4SF "4") (V2DF "2")])
686
687 ;; Mask of scalar elements in each vector type
688 (define_mode_attr ssescalarnummask
689   [(V32QI "31") (V16HI "15") (V8SI "7") (V4DI "3")
690    (V16QI "15") (V8HI "7") (V4SI "3") (V2DI "1")
691    (V8SF "7") (V4DF "3")
692    (V4SF "3") (V2DF "1")])
693
694 (define_mode_attr ssescalarsize
695   [(V8DI  "64") (V4DI  "64") (V2DI  "64")
696    (V64QI "8") (V32QI "8") (V16QI "8")
697    (V32HI "16") (V16HI "16") (V8HI "16")
698    (V16SI "32") (V8SI "32") (V4SI "32")
699    (V16SF "32") (V8DF "64")])
700
701 ;; SSE prefix for integer vector modes
702 (define_mode_attr sseintprefix
703   [(V2DI  "p") (V2DF  "")
704    (V4DI  "p") (V4DF  "")
705    (V8DI  "p") (V8DF  "")
706    (V4SI  "p") (V4SF  "")
707    (V8SI  "p") (V8SF  "")
708    (V16SI "p") (V16SF "")
709    (V16QI "p") (V8HI "p")
710    (V32QI "p") (V16HI "p")
711    (V64QI "p") (V32HI "p")])
712
713 ;; SSE scalar suffix for vector modes
714 (define_mode_attr ssescalarmodesuffix
715   [(SF "ss") (DF "sd")
716    (V8SF "ss") (V4DF "sd")
717    (V4SF "ss") (V2DF "sd")
718    (V8SI "ss") (V4DI "sd")
719    (V4SI "d")])
720
721 ;; Pack/unpack vector modes
722 (define_mode_attr sseunpackmode
723   [(V16QI "V8HI") (V8HI "V4SI") (V4SI "V2DI")
724    (V32QI "V16HI") (V16HI "V8SI") (V8SI "V4DI")
725    (V32HI "V16SI") (V64QI "V32HI") (V16SI "V8DI")])
726
727 (define_mode_attr ssepackmode
728   [(V8HI "V16QI") (V4SI "V8HI") (V2DI "V4SI")
729    (V16HI "V32QI") (V8SI "V16HI") (V4DI "V8SI")
730    (V32HI "V64QI") (V16SI "V32HI") (V8DI "V16SI")])
731
732 ;; Mapping of the max integer size for xop rotate immediate constraint
733 (define_mode_attr sserotatemax
734   [(V16QI "7") (V8HI "15") (V4SI "31") (V2DI "63")])
735
736 ;; Mapping of mode to cast intrinsic name
737 (define_mode_attr castmode
738  [(V8SI "si") (V8SF "ps") (V4DF "pd")
739   (V16SI "si") (V16SF "ps") (V8DF "pd")])
740
741 ;; Instruction suffix for sign and zero extensions.
742 (define_code_attr extsuffix [(sign_extend "sx") (zero_extend "zx")])
743
744 ;; i128 for integer vectors and TARGET_AVX2, f128 otherwise.
745 ;; i64x4 or f64x4 for 512bit modes.
746 (define_mode_attr i128
747   [(V16SF "f64x4") (V8SF "f128") (V8DF "f64x4") (V4DF "f128")
748    (V64QI "i64x4") (V32QI "%~128") (V32HI "i64x4") (V16HI "%~128")
749    (V16SI "i64x4") (V8SI "%~128") (V8DI "i64x4") (V4DI "%~128")])
750
751 ;; Mix-n-match
752 (define_mode_iterator AVX256MODE2P [V8SI V8SF V4DF])
753 (define_mode_iterator AVX512MODE2P [V16SI V16SF V8DF])
754
755 ;; Mapping for dbpsabbw modes
756 (define_mode_attr dbpsadbwmode
757   [(V32HI "V64QI") (V16HI "V32QI") (V8HI "V16QI")])
758
759 ;; Mapping suffixes for broadcast
760 (define_mode_attr bcstscalarsuff
761   [(V64QI "b")  (V32QI "b") (V16QI "b")
762    (V32HI "w")  (V16HI "w") (V8HI "w")
763    (V16SI "d")  (V8SI "d")  (V4SI "d")
764    (V8DI "q")   (V4DI "q")  (V2DI "q")
765    (V16SF "ss") (V8SF "ss") (V4SF "ss")
766    (V8DF "sd")  (V4DF "sd") (V2DF "sd")])
767
768 ;; Tie mode of assembler operand to mode iterator
769 (define_mode_attr concat_tg_mode
770   [(V32QI "t") (V16HI "t") (V8SI "t") (V4DI "t") (V8SF "t") (V4DF "t")
771    (V64QI "g") (V32HI "g") (V16SI "g") (V8DI "g") (V16SF "g") (V8DF "g")])
772
773
774 ;; Include define_subst patterns for instructions with mask
775 (include "subst.md")
776
777 ;; Patterns whose name begins with "sse{,2,3}_" are invoked by intrinsics.
778
779 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
780 ;;
781 ;; Move patterns
782 ;;
783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
784
785 ;; All of these patterns are enabled for SSE1 as well as SSE2.
786 ;; This is essential for maintaining stable calling conventions.
787
788 (define_expand "mov<mode>"
789   [(set (match_operand:VMOVE 0 "nonimmediate_operand")
790         (match_operand:VMOVE 1 "nonimmediate_operand"))]
791   "TARGET_SSE"
792 {
793   ix86_expand_vector_move (<MODE>mode, operands);
794   DONE;
795 })
796
797 (define_insn "*mov<mode>_internal"
798   [(set (match_operand:VMOVE 0 "nonimmediate_operand"               "=v,v ,m")
799         (match_operand:VMOVE 1 "nonimmediate_or_sse_const_operand"  "C ,vm,v"))]
800   "TARGET_SSE
801    && (register_operand (operands[0], <MODE>mode)
802        || register_operand (operands[1], <MODE>mode))"
803 {
804   int mode = get_attr_mode (insn);
805   switch (which_alternative)
806     {
807     case 0:
808       return standard_sse_constant_opcode (insn, operands[1]);
809     case 1:
810     case 2:
811       /* There is no evex-encoded vmov* for sizes smaller than 64-bytes
812          in avx512f, so we need to use workarounds, to access sse registers
813          16-31, which are evex-only. In avx512vl we don't need workarounds.  */
814       if (TARGET_AVX512F && <MODE_SIZE> < 64 && !TARGET_AVX512VL
815           && ((REG_P (operands[0]) && EXT_REX_SSE_REGNO_P (REGNO (operands[0])))
816               || (REG_P (operands[1]) && EXT_REX_SSE_REGNO_P (REGNO (operands[1])))))
817         {
818           if (memory_operand (operands[0], <MODE>mode))
819             {
820               if (<MODE_SIZE> == 32)
821                 return "vextract<shuffletype>64x4\t{$0x0, %g1, %0|%0, %g1, 0x0}";
822               else if (<MODE_SIZE> == 16)
823                 return "vextract<shuffletype>32x4\t{$0x0, %g1, %0|%0, %g1, 0x0}";
824               else
825                 gcc_unreachable ();
826             }
827           else if (memory_operand (operands[1], <MODE>mode))
828             {
829               if (<MODE_SIZE> == 32)
830                 return "vbroadcast<shuffletype>64x4\t{%1, %g0|%g0, %1}";
831               else if (<MODE_SIZE> == 16)
832                 return "vbroadcast<shuffletype>32x4\t{%1, %g0|%g0, %1}";
833               else
834                 gcc_unreachable ();
835             }
836           else
837             /* Reg -> reg move is always aligned.  Just use wider move.  */
838             switch (mode)
839               {
840               case MODE_V8SF:
841               case MODE_V4SF:
842                 return "vmovaps\t{%g1, %g0|%g0, %g1}";
843               case MODE_V4DF:
844               case MODE_V2DF:
845                 return "vmovapd\t{%g1, %g0|%g0, %g1}";
846               case MODE_OI:
847               case MODE_TI:
848                 return "vmovdqa64\t{%g1, %g0|%g0, %g1}";
849               default:
850                 gcc_unreachable ();
851               }
852         }
853       switch (mode)
854         {
855         case MODE_V16SF:
856         case MODE_V8SF:
857         case MODE_V4SF:
858           if (TARGET_AVX
859               && (misaligned_operand (operands[0], <MODE>mode)
860                   || misaligned_operand (operands[1], <MODE>mode)))
861             return "vmovups\t{%1, %0|%0, %1}";
862           else
863             return "%vmovaps\t{%1, %0|%0, %1}";
864
865         case MODE_V8DF:
866         case MODE_V4DF:
867         case MODE_V2DF:
868           if (TARGET_AVX
869               && (misaligned_operand (operands[0], <MODE>mode)
870                   || misaligned_operand (operands[1], <MODE>mode)))
871             return "vmovupd\t{%1, %0|%0, %1}";
872           else
873             return "%vmovapd\t{%1, %0|%0, %1}";
874
875         case MODE_OI:
876         case MODE_TI:
877           if (TARGET_AVX
878               && (misaligned_operand (operands[0], <MODE>mode)
879                   || misaligned_operand (operands[1], <MODE>mode)))
880             return TARGET_AVX512VL ? "vmovdqu64\t{%1, %0|%0, %1}"
881                                    : "vmovdqu\t{%1, %0|%0, %1}";
882           else
883             return TARGET_AVX512VL ? "vmovdqa64\t{%1, %0|%0, %1}"
884                                    : "%vmovdqa\t{%1, %0|%0, %1}";
885         case MODE_XI:
886           if (misaligned_operand (operands[0], <MODE>mode)
887               || misaligned_operand (operands[1], <MODE>mode))
888             return "vmovdqu64\t{%1, %0|%0, %1}";
889           else
890             return "vmovdqa64\t{%1, %0|%0, %1}";
891
892         default:
893           gcc_unreachable ();
894         }
895     default:
896       gcc_unreachable ();
897     }
898 }
899   [(set_attr "type" "sselog1,ssemov,ssemov")
900    (set_attr "prefix" "maybe_vex")
901    (set (attr "mode")
902         (cond [(and (match_test "<MODE_SIZE> == 16")
903                     (ior (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
904                          (and (eq_attr "alternative" "2")
905                               (match_test "TARGET_SSE_TYPELESS_STORES"))))
906                  (const_string "<ssePSmode>")
907                (match_test "TARGET_AVX")
908                  (const_string "<sseinsnmode>")
909                (ior (not (match_test "TARGET_SSE2"))
910                     (match_test "optimize_function_for_size_p (cfun)"))
911                  (const_string "V4SF")
912                (and (eq_attr "alternative" "0")
913                     (match_test "TARGET_SSE_LOAD0_BY_PXOR"))
914                  (const_string "TI")
915               ]
916               (const_string "<sseinsnmode>")))])
917
918 (define_insn "<avx512>_load<mode>_mask"
919   [(set (match_operand:V48_AVX512VL 0 "register_operand" "=v,v")
920         (vec_merge:V48_AVX512VL
921           (match_operand:V48_AVX512VL 1 "nonimmediate_operand" "v,m")
922           (match_operand:V48_AVX512VL 2 "vector_move_operand" "0C,0C")
923           (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk,Yk")))]
924   "TARGET_AVX512F"
925 {
926   static char buf [64];
927
928   const char *insn_op;
929   const char *sse_suffix;
930   const char *align;
931   if (FLOAT_MODE_P (GET_MODE_INNER (<MODE>mode)))
932     {
933       insn_op = "vmov";
934       sse_suffix = "<ssemodesuffix>";
935     }
936   else
937     {
938       insn_op = "vmovdq";
939       sse_suffix = "<ssescalarsize>";
940     }
941
942   if (misaligned_operand (operands[1], <MODE>mode))
943     align = "u";
944   else
945     align = "a";
946
947   snprintf (buf, sizeof (buf), "%s%s%s\t{%%1, %%0%%{%%3%%}%%N2|%%0%%{%%3%%}%%N2, %%1}",
948             insn_op, align, sse_suffix);
949   return buf;
950 }
951   [(set_attr "type" "ssemov")
952    (set_attr "prefix" "evex")
953    (set_attr "memory" "none,load")
954    (set_attr "mode" "<sseinsnmode>")])
955
956 (define_insn "<avx512>_load<mode>_mask"
957   [(set (match_operand:VI12_AVX512VL 0 "register_operand" "=v,v")
958         (vec_merge:VI12_AVX512VL
959           (match_operand:VI12_AVX512VL 1 "nonimmediate_operand" "v,m")
960           (match_operand:VI12_AVX512VL 2 "vector_move_operand" "0C,0C")
961           (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk,Yk")))]
962   "TARGET_AVX512BW"
963   "vmovdqu<ssescalarsize>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
964   [(set_attr "type" "ssemov")
965    (set_attr "prefix" "evex")
966    (set_attr "memory" "none,load")
967    (set_attr "mode" "<sseinsnmode>")])
968
969 (define_insn "<avx512>_blendm<mode>"
970   [(set (match_operand:V48_AVX512VL 0 "register_operand" "=v")
971         (vec_merge:V48_AVX512VL
972           (match_operand:V48_AVX512VL 2 "nonimmediate_operand" "vm")
973           (match_operand:V48_AVX512VL 1 "register_operand" "v")
974           (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk")))]
975   "TARGET_AVX512F"
976   "vblendm<ssemodesuffix>\t{%2, %1, %0%{%3%}|%0%{%3%}, %1, %2}"
977   [(set_attr "type" "ssemov")
978    (set_attr "prefix" "evex")
979    (set_attr "mode" "<sseinsnmode>")])
980
981 (define_insn "<avx512>_blendm<mode>"
982   [(set (match_operand:VI12_AVX512VL 0 "register_operand" "=v")
983         (vec_merge:VI12_AVX512VL
984           (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm")
985           (match_operand:VI12_AVX512VL 1 "register_operand" "v")
986           (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk")))]
987   "TARGET_AVX512BW"
988   "vpblendm<ssemodesuffix>\t{%2, %1, %0%{%3%}|%0%{%3%}, %1, %2}"
989   [(set_attr "type" "ssemov")
990    (set_attr "prefix" "evex")
991    (set_attr "mode" "<sseinsnmode>")])
992
993 (define_insn "<avx512>_store<mode>_mask"
994   [(set (match_operand:V48_AVX512VL 0 "memory_operand" "=m")
995         (vec_merge:V48_AVX512VL
996           (match_operand:V48_AVX512VL 1 "register_operand" "v")
997           (match_dup 0)
998           (match_operand:<avx512fmaskmode> 2 "register_operand" "Yk")))]
999   "TARGET_AVX512F"
1000 {
1001   static char buf [64];
1002
1003   const char *insn_op;
1004   const char *sse_suffix;
1005   const char *align;
1006   if (FLOAT_MODE_P (GET_MODE_INNER (<MODE>mode)))
1007     {
1008       insn_op = "vmov";
1009       sse_suffix = "<ssemodesuffix>";
1010     }
1011   else
1012     {
1013       insn_op = "vmovdq";
1014       sse_suffix = "<ssescalarsize>";
1015     }
1016
1017   if (misaligned_operand (operands[1], <MODE>mode))
1018     align = "u";
1019   else
1020     align = "a";
1021
1022   snprintf (buf, sizeof (buf), "%s%s%s\t{%%1, %%0%%{%%2%%}|%%0%%{%%2%%}, %%1}",
1023             insn_op, align, sse_suffix);
1024   return buf;
1025 }
1026   [(set_attr "type" "ssemov")
1027    (set_attr "prefix" "evex")
1028    (set_attr "memory" "store")
1029    (set_attr "mode" "<sseinsnmode>")])
1030
1031 (define_insn "<avx512>_store<mode>_mask"
1032   [(set (match_operand:VI12_AVX512VL 0 "memory_operand" "=m")
1033         (vec_merge:VI12_AVX512VL
1034           (match_operand:VI12_AVX512VL 1 "register_operand" "v")
1035           (match_dup 0)
1036           (match_operand:<avx512fmaskmode> 2 "register_operand" "Yk")))]
1037   "TARGET_AVX512BW"
1038   "vmovdqu<ssescalarsize>\t{%1, %0%{%2%}|%0%{%2%}, %1}"
1039   [(set_attr "type" "ssemov")
1040    (set_attr "prefix" "evex")
1041    (set_attr "memory" "store")
1042    (set_attr "mode" "<sseinsnmode>")])
1043
1044 (define_insn "sse2_movq128"
1045   [(set (match_operand:V2DI 0 "register_operand" "=x")
1046         (vec_concat:V2DI
1047           (vec_select:DI
1048             (match_operand:V2DI 1 "nonimmediate_operand" "xm")
1049             (parallel [(const_int 0)]))
1050           (const_int 0)))]
1051   "TARGET_SSE2"
1052   "%vmovq\t{%1, %0|%0, %q1}"
1053   [(set_attr "type" "ssemov")
1054    (set_attr "prefix" "maybe_vex")
1055    (set_attr "mode" "TI")])
1056
1057 ;; Move a DI from a 32-bit register pair (e.g. %edx:%eax) to an xmm.
1058 ;; We'd rather avoid this entirely; if the 32-bit reg pair was loaded
1059 ;; from memory, we'd prefer to load the memory directly into the %xmm
1060 ;; register.  To facilitate this happy circumstance, this pattern won't
1061 ;; split until after register allocation.  If the 64-bit value didn't
1062 ;; come from memory, this is the best we can do.  This is much better
1063 ;; than storing %edx:%eax into a stack temporary and loading an %xmm
1064 ;; from there.
1065
1066 (define_insn_and_split "movdi_to_sse"
1067   [(parallel
1068     [(set (match_operand:V4SI 0 "register_operand" "=?x,x")
1069           (subreg:V4SI (match_operand:DI 1 "nonimmediate_operand" "r,m") 0))
1070      (clobber (match_scratch:V4SI 2 "=&x,X"))])]
1071   "!TARGET_64BIT && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC"
1072   "#"
1073   "&& reload_completed"
1074   [(const_int 0)]
1075 {
1076  if (register_operand (operands[1], DImode))
1077    {
1078       /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
1079          Assemble the 64-bit DImode value in an xmm register.  */
1080       emit_insn (gen_sse2_loadld (operands[0], CONST0_RTX (V4SImode),
1081                                   gen_rtx_SUBREG (SImode, operands[1], 0)));
1082       emit_insn (gen_sse2_loadld (operands[2], CONST0_RTX (V4SImode),
1083                                   gen_rtx_SUBREG (SImode, operands[1], 4)));
1084       emit_insn (gen_vec_interleave_lowv4si (operands[0], operands[0],
1085                                              operands[2]));
1086    }
1087  else if (memory_operand (operands[1], DImode))
1088    {
1089      rtx tmp = gen_reg_rtx (V2DImode);
1090      emit_insn (gen_vec_concatv2di (tmp, operands[1], const0_rtx));
1091      emit_move_insn (operands[0], gen_lowpart (V4SImode, tmp));
1092    }
1093  else
1094    gcc_unreachable ();
1095 })
1096
1097 (define_split
1098   [(set (match_operand:V4SF 0 "register_operand")
1099         (match_operand:V4SF 1 "zero_extended_scalar_load_operand"))]
1100   "TARGET_SSE && reload_completed"
1101   [(set (match_dup 0)
1102         (vec_merge:V4SF
1103           (vec_duplicate:V4SF (match_dup 1))
1104           (match_dup 2)
1105           (const_int 1)))]
1106 {
1107   operands[1] = simplify_gen_subreg (SFmode, operands[1], V4SFmode, 0);
1108   operands[2] = CONST0_RTX (V4SFmode);
1109 })
1110
1111 (define_split
1112   [(set (match_operand:V2DF 0 "register_operand")
1113         (match_operand:V2DF 1 "zero_extended_scalar_load_operand"))]
1114   "TARGET_SSE2 && reload_completed"
1115   [(set (match_dup 0) (vec_concat:V2DF (match_dup 1) (match_dup 2)))]
1116 {
1117   operands[1] = simplify_gen_subreg (DFmode, operands[1], V2DFmode, 0);
1118   operands[2] = CONST0_RTX (DFmode);
1119 })
1120
1121 (define_expand "movmisalign<mode>"
1122   [(set (match_operand:VMOVE 0 "nonimmediate_operand")
1123         (match_operand:VMOVE 1 "nonimmediate_operand"))]
1124   "TARGET_SSE"
1125 {
1126   ix86_expand_vector_move_misalign (<MODE>mode, operands);
1127   DONE;
1128 })
1129
1130 (define_expand "<sse>_loadu<ssemodesuffix><avxsizesuffix><mask_name>"
1131   [(set (match_operand:VF 0 "register_operand")
1132         (unspec:VF [(match_operand:VF 1 "nonimmediate_operand")]
1133           UNSPEC_LOADU))]
1134   "TARGET_SSE && <mask_mode512bit_condition>"
1135 {
1136   /* For AVX, normal *mov<mode>_internal pattern will handle unaligned loads
1137      just fine if misaligned_operand is true, and without the UNSPEC it can
1138      be combined with arithmetic instructions.  If misaligned_operand is
1139      false, still emit UNSPEC_LOADU insn to honor user's request for
1140      misaligned load.  */
1141   if (TARGET_AVX
1142       && misaligned_operand (operands[1], <MODE>mode))
1143     {
1144       rtx src = operands[1];
1145       if (<mask_applied>)
1146         src = gen_rtx_VEC_MERGE (<MODE>mode, operands[1],
1147                                  operands[2 * <mask_applied>],
1148                                  operands[3 * <mask_applied>]);
1149       emit_insn (gen_rtx_SET (VOIDmode, operands[0], src));
1150       DONE;
1151     }
1152 })
1153
1154 (define_insn "*<sse>_loadu<ssemodesuffix><avxsizesuffix><mask_name>"
1155   [(set (match_operand:VF 0 "register_operand" "=v")
1156         (unspec:VF
1157           [(match_operand:VF 1 "nonimmediate_operand" "vm")]
1158           UNSPEC_LOADU))]
1159   "TARGET_SSE && <mask_mode512bit_condition>"
1160 {
1161   switch (get_attr_mode (insn))
1162     {
1163     case MODE_V16SF:
1164     case MODE_V8SF:
1165     case MODE_V4SF:
1166       return "%vmovups\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}";
1167     default:
1168       return "%vmovu<ssemodesuffix>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}";
1169     }
1170 }
1171   [(set_attr "type" "ssemov")
1172    (set_attr "movu" "1")
1173    (set_attr "ssememalign" "8")
1174    (set_attr "prefix" "maybe_vex")
1175    (set (attr "mode")
1176         (cond [(and (match_test "<MODE_SIZE> == 16")
1177                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
1178                  (const_string "<ssePSmode>")
1179                (match_test "TARGET_AVX")
1180                  (const_string "<MODE>")
1181                (match_test "optimize_function_for_size_p (cfun)")
1182                  (const_string "V4SF")
1183               ]
1184               (const_string "<MODE>")))])
1185
1186 (define_insn "<sse>_storeu<ssemodesuffix><avxsizesuffix>"
1187   [(set (match_operand:VF 0 "memory_operand" "=m")
1188         (unspec:VF
1189           [(match_operand:VF 1 "register_operand" "v")]
1190           UNSPEC_STOREU))]
1191   "TARGET_SSE"
1192 {
1193   switch (get_attr_mode (insn))
1194     {
1195     case MODE_V16SF:
1196     case MODE_V8SF:
1197     case MODE_V4SF:
1198       return "%vmovups\t{%1, %0|%0, %1}";
1199     default:
1200       return "%vmovu<ssemodesuffix>\t{%1, %0|%0, %1}";
1201     }
1202 }
1203   [(set_attr "type" "ssemov")
1204    (set_attr "movu" "1")
1205    (set_attr "ssememalign" "8")
1206    (set_attr "prefix" "maybe_vex")
1207    (set (attr "mode")
1208         (cond [(and (match_test "<MODE_SIZE> == 16")
1209                     (ior (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
1210                          (match_test "TARGET_SSE_TYPELESS_STORES")))
1211                  (const_string "<ssePSmode>")
1212                (match_test "TARGET_AVX")
1213                  (const_string "<MODE>")
1214                (match_test "optimize_function_for_size_p (cfun)")
1215                  (const_string "V4SF")
1216               ]
1217               (const_string "<MODE>")))])
1218
1219 (define_insn "<avx512>_storeu<ssemodesuffix><avxsizesuffix>_mask"
1220   [(set (match_operand:VF_AVX512VL 0 "memory_operand" "=m")
1221         (vec_merge:VF_AVX512VL
1222           (unspec:VF_AVX512VL
1223             [(match_operand:VF_AVX512VL 1 "register_operand" "v")]
1224             UNSPEC_STOREU)
1225           (match_dup 0)
1226           (match_operand:<avx512fmaskmode> 2 "register_operand" "Yk")))]
1227   "TARGET_AVX512F"
1228 {
1229   switch (get_attr_mode (insn))
1230     {
1231     case MODE_V16SF:
1232     case MODE_V8SF:
1233     case MODE_V4SF:
1234       return "vmovups\t{%1, %0%{%2%}|%0%{%2%}, %1}";
1235     default:
1236       return "vmovu<ssemodesuffix>\t{%1, %0%{%2%}|%0%{%2%}, %1}";
1237     }
1238 }
1239   [(set_attr "type" "ssemov")
1240    (set_attr "movu" "1")
1241    (set_attr "memory" "store")
1242    (set_attr "prefix" "evex")
1243    (set_attr "mode" "<sseinsnmode>")])
1244
1245 /* For AVX, normal *mov<mode>_internal pattern will handle unaligned loads
1246    just fine if misaligned_operand is true, and without the UNSPEC it can
1247    be combined with arithmetic instructions.  If misaligned_operand is
1248    false, still emit UNSPEC_LOADU insn to honor user's request for
1249    misaligned load.  */
1250 (define_expand "<sse2_avx_avx512f>_loaddqu<mode><mask_name>"
1251   [(set (match_operand:VI1 0 "register_operand")
1252         (unspec:VI1
1253           [(match_operand:VI1 1 "nonimmediate_operand")]
1254           UNSPEC_LOADU))]
1255   "TARGET_SSE2 && <mask_avx512vl_condition> && <mask_avx512bw_condition>"
1256 {
1257   if (TARGET_AVX
1258       && misaligned_operand (operands[1], <MODE>mode))
1259     {
1260       rtx src = operands[1];
1261       if (<mask_applied>)
1262         src = gen_rtx_VEC_MERGE (<MODE>mode, operands[1],
1263                                  operands[2 * <mask_applied>],
1264                                  operands[3 * <mask_applied>]);
1265       emit_insn (gen_rtx_SET (VOIDmode, operands[0], src));
1266       DONE;
1267     }
1268 })
1269
1270 (define_expand "<sse2_avx_avx512f>_loaddqu<mode><mask_name>"
1271   [(set (match_operand:VI_ULOADSTORE_BW_AVX512VL 0 "register_operand")
1272         (unspec:VI_ULOADSTORE_BW_AVX512VL
1273           [(match_operand:VI_ULOADSTORE_BW_AVX512VL 1 "nonimmediate_operand")]
1274           UNSPEC_LOADU))]
1275   "TARGET_AVX512BW"
1276 {
1277   if (misaligned_operand (operands[1], <MODE>mode))
1278     {
1279       rtx src = operands[1];
1280       if (<mask_applied>)
1281         src = gen_rtx_VEC_MERGE (<MODE>mode, operands[1],
1282                                  operands[2 * <mask_applied>],
1283                                  operands[3 * <mask_applied>]);
1284       emit_insn (gen_rtx_SET (VOIDmode, operands[0], src));
1285       DONE;
1286     }
1287 })
1288
1289 (define_expand "<sse2_avx_avx512f>_loaddqu<mode><mask_name>"
1290   [(set (match_operand:VI_ULOADSTORE_F_AVX512VL 0 "register_operand")
1291         (unspec:VI_ULOADSTORE_F_AVX512VL
1292           [(match_operand:VI_ULOADSTORE_F_AVX512VL 1 "nonimmediate_operand")]
1293           UNSPEC_LOADU))]
1294   "TARGET_AVX512F"
1295 {
1296   if (misaligned_operand (operands[1], <MODE>mode))
1297     {
1298       rtx src = operands[1];
1299       if (<mask_applied>)
1300         src = gen_rtx_VEC_MERGE (<MODE>mode, operands[1],
1301                                  operands[2 * <mask_applied>],
1302                                  operands[3 * <mask_applied>]);
1303       emit_insn (gen_rtx_SET (VOIDmode, operands[0], src));
1304       DONE;
1305     }
1306 })
1307
1308 (define_insn "*<sse2_avx_avx512f>_loaddqu<mode><mask_name>"
1309   [(set (match_operand:VI1 0 "register_operand" "=v")
1310         (unspec:VI1
1311           [(match_operand:VI1 1 "nonimmediate_operand" "vm")]
1312           UNSPEC_LOADU))]
1313   "TARGET_SSE2 && <mask_avx512vl_condition> && <mask_avx512bw_condition>"
1314 {
1315   switch (get_attr_mode (insn))
1316     {
1317     case MODE_V8SF:
1318     case MODE_V4SF:
1319       return "%vmovups\t{%1, %0|%0, %1}";
1320     default:
1321       if (!(TARGET_AVX512VL && TARGET_AVX512BW))
1322         return "%vmovdqu\t{%1, %0|%0, %1}";
1323       else
1324         return "vmovdqu<ssescalarsize>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}";
1325     }
1326 }
1327   [(set_attr "type" "ssemov")
1328    (set_attr "movu" "1")
1329    (set_attr "ssememalign" "8")
1330    (set (attr "prefix_data16")
1331      (if_then_else
1332        (match_test "TARGET_AVX")
1333      (const_string "*")
1334      (const_string "1")))
1335    (set_attr "prefix" "maybe_vex")
1336    (set (attr "mode")
1337         (cond [(and (match_test "<MODE_SIZE> == 16")
1338                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
1339                  (const_string "<ssePSmode>")
1340                (match_test "TARGET_AVX")
1341                  (const_string "<sseinsnmode>")
1342                (match_test "optimize_function_for_size_p (cfun)")
1343                  (const_string "V4SF")
1344               ]
1345               (const_string "<sseinsnmode>")))])
1346
1347 (define_insn "*<sse2_avx_avx512f>_loaddqu<mode><mask_name>"
1348   [(set (match_operand:VI_ULOADSTORE_BW_AVX512VL 0 "register_operand" "=v")
1349         (unspec:VI_ULOADSTORE_BW_AVX512VL
1350           [(match_operand:VI_ULOADSTORE_BW_AVX512VL 1 "nonimmediate_operand" "vm")]
1351           UNSPEC_LOADU))]
1352   "TARGET_AVX512BW"
1353   "vmovdqu<ssescalarsize>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}";
1354   [(set_attr "type" "ssemov")
1355    (set_attr "movu" "1")
1356    (set_attr "ssememalign" "8")
1357    (set_attr "prefix" "maybe_evex")])
1358
1359 (define_insn "*<sse2_avx_avx512f>_loaddqu<mode><mask_name>"
1360   [(set (match_operand:VI_ULOADSTORE_F_AVX512VL 0 "register_operand" "=v")
1361         (unspec:VI_ULOADSTORE_F_AVX512VL
1362           [(match_operand:VI_ULOADSTORE_F_AVX512VL 1 "nonimmediate_operand" "vm")]
1363           UNSPEC_LOADU))]
1364   "TARGET_AVX512F"
1365   "vmovdqu<ssescalarsize>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}";
1366   [(set_attr "type" "ssemov")
1367    (set_attr "movu" "1")
1368    (set_attr "ssememalign" "8")
1369    (set_attr "prefix" "maybe_evex")])
1370
1371 (define_insn "<sse2_avx_avx512f>_storedqu<mode>"
1372   [(set (match_operand:VI1 0 "memory_operand" "=m")
1373         (unspec:VI1
1374           [(match_operand:VI1 1 "register_operand" "v")]
1375           UNSPEC_STOREU))]
1376   "TARGET_SSE2"
1377 {
1378   switch (get_attr_mode (insn))
1379     {
1380     case MODE_V16SF:
1381     case MODE_V8SF:
1382     case MODE_V4SF:
1383       return "%vmovups\t{%1, %0|%0, %1}";
1384     default:
1385       switch (<MODE>mode)
1386       {
1387       case V32QImode:
1388       case V16QImode:
1389         if (!(TARGET_AVX512VL && TARGET_AVX512BW))
1390           return "%vmovdqu\t{%1, %0|%0, %1}";
1391       default:
1392           return "vmovdqu<ssescalarsize>\t{%1, %0|%0, %1}";
1393       }
1394     }
1395 }
1396   [(set_attr "type" "ssemov")
1397    (set_attr "movu" "1")
1398    (set_attr "ssememalign" "8")
1399    (set (attr "prefix_data16")
1400      (if_then_else
1401        (match_test "TARGET_AVX")
1402      (const_string "*")
1403      (const_string "1")))
1404    (set_attr "prefix" "maybe_vex")
1405    (set (attr "mode")
1406         (cond [(and (match_test "<MODE_SIZE> == 16")
1407                     (ior (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
1408                          (match_test "TARGET_SSE_TYPELESS_STORES")))
1409                  (const_string "<ssePSmode>")
1410                (match_test "TARGET_AVX")
1411                  (const_string "<sseinsnmode>")
1412                (match_test "optimize_function_for_size_p (cfun)")
1413                  (const_string "V4SF")
1414               ]
1415               (const_string "<sseinsnmode>")))])
1416
1417 (define_insn "<sse2_avx_avx512f>_storedqu<mode>"
1418   [(set (match_operand:VI_ULOADSTORE_BW_AVX512VL 0 "memory_operand" "=m")
1419         (unspec:VI_ULOADSTORE_BW_AVX512VL
1420           [(match_operand:VI_ULOADSTORE_BW_AVX512VL 1 "register_operand" "v")]
1421           UNSPEC_STOREU))]
1422   "TARGET_AVX512BW"
1423   "vmovdqu<ssescalarsize>\t{%1, %0|%0, %1}"
1424   [(set_attr "type" "ssemov")
1425    (set_attr "movu" "1")
1426    (set_attr "ssememalign" "8")
1427    (set_attr "prefix" "maybe_evex")])
1428
1429 (define_insn "<sse2_avx_avx512f>_storedqu<mode>"
1430   [(set (match_operand:VI_ULOADSTORE_F_AVX512VL 0 "memory_operand" "=m")
1431         (unspec:VI_ULOADSTORE_F_AVX512VL
1432           [(match_operand:VI_ULOADSTORE_F_AVX512VL 1 "register_operand" "v")]
1433           UNSPEC_STOREU))]
1434   "TARGET_AVX512F"
1435   "vmovdqu<ssescalarsize>\t{%1, %0|%0, %1}"
1436   [(set_attr "type" "ssemov")
1437    (set_attr "movu" "1")
1438    (set_attr "ssememalign" "8")
1439    (set_attr "prefix" "maybe_vex")])
1440
1441 (define_insn "<avx512>_storedqu<mode>_mask"
1442   [(set (match_operand:VI48_AVX512VL 0 "memory_operand" "=m")
1443         (vec_merge:VI48_AVX512VL
1444           (unspec:VI48_AVX512VL
1445             [(match_operand:VI48_AVX512VL 1 "register_operand" "v")]
1446             UNSPEC_STOREU)
1447           (match_dup 0)
1448           (match_operand:<avx512fmaskmode> 2 "register_operand" "Yk")))]
1449   "TARGET_AVX512F"
1450   "vmovdqu<ssescalarsize>\t{%1, %0%{%2%}|%0%{%2%}, %1}"
1451   [(set_attr "type" "ssemov")
1452    (set_attr "movu" "1")
1453    (set_attr "memory" "store")
1454    (set_attr "prefix" "evex")
1455    (set_attr "mode" "<sseinsnmode>")])
1456
1457 (define_insn "<avx512>_storedqu<mode>_mask"
1458   [(set (match_operand:VI12_AVX512VL 0 "memory_operand" "=m")
1459         (vec_merge:VI12_AVX512VL
1460           (unspec:VI12_AVX512VL
1461             [(match_operand:VI12_AVX512VL 1 "register_operand" "v")]
1462             UNSPEC_STOREU)
1463           (match_dup 0)
1464           (match_operand:<avx512fmaskmode> 2 "register_operand" "Yk")))]
1465   "TARGET_AVX512BW"
1466   "vmovdqu<ssescalarsize>\t{%1, %0%{%2%}|%0%{%2%}, %1}"
1467   [(set_attr "type" "ssemov")
1468    (set_attr "movu" "1")
1469    (set_attr "memory" "store")
1470    (set_attr "prefix" "evex")
1471    (set_attr "mode" "<sseinsnmode>")])
1472
1473 (define_insn "<sse3>_lddqu<avxsizesuffix>"
1474   [(set (match_operand:VI1 0 "register_operand" "=x")
1475         (unspec:VI1 [(match_operand:VI1 1 "memory_operand" "m")]
1476                     UNSPEC_LDDQU))]
1477   "TARGET_SSE3"
1478   "%vlddqu\t{%1, %0|%0, %1}"
1479   [(set_attr "type" "ssemov")
1480    (set_attr "movu" "1")
1481    (set_attr "ssememalign" "8")
1482    (set (attr "prefix_data16")
1483      (if_then_else
1484        (match_test "TARGET_AVX")
1485      (const_string "*")
1486      (const_string "0")))
1487    (set (attr "prefix_rep")
1488      (if_then_else
1489        (match_test "TARGET_AVX")
1490      (const_string "*")
1491      (const_string "1")))
1492    (set_attr "prefix" "maybe_vex")
1493    (set_attr "mode" "<sseinsnmode>")])
1494
1495 (define_insn "sse2_movnti<mode>"
1496   [(set (match_operand:SWI48 0 "memory_operand" "=m")
1497         (unspec:SWI48 [(match_operand:SWI48 1 "register_operand" "r")]
1498                       UNSPEC_MOVNT))]
1499   "TARGET_SSE2"
1500   "movnti\t{%1, %0|%0, %1}"
1501   [(set_attr "type" "ssemov")
1502    (set_attr "prefix_data16" "0")
1503    (set_attr "mode" "<MODE>")])
1504
1505 (define_insn "<sse>_movnt<mode>"
1506   [(set (match_operand:VF 0 "memory_operand" "=m")
1507         (unspec:VF
1508           [(match_operand:VF 1 "register_operand" "v")]
1509           UNSPEC_MOVNT))]
1510   "TARGET_SSE"
1511   "%vmovnt<ssemodesuffix>\t{%1, %0|%0, %1}"
1512   [(set_attr "type" "ssemov")
1513    (set_attr "prefix" "maybe_vex")
1514    (set_attr "mode" "<MODE>")])
1515
1516 (define_insn "<sse2>_movnt<mode>"
1517   [(set (match_operand:VI8 0 "memory_operand" "=m")
1518         (unspec:VI8 [(match_operand:VI8 1 "register_operand" "v")]
1519                     UNSPEC_MOVNT))]
1520   "TARGET_SSE2"
1521   "%vmovntdq\t{%1, %0|%0, %1}"
1522   [(set_attr "type" "ssecvt")
1523    (set (attr "prefix_data16")
1524      (if_then_else
1525        (match_test "TARGET_AVX")
1526      (const_string "*")
1527      (const_string "1")))
1528    (set_attr "prefix" "maybe_vex")
1529    (set_attr "mode" "<sseinsnmode>")])
1530
1531 ; Expand patterns for non-temporal stores.  At the moment, only those
1532 ; that directly map to insns are defined; it would be possible to
1533 ; define patterns for other modes that would expand to several insns.
1534
1535 ;; Modes handled by storent patterns.
1536 (define_mode_iterator STORENT_MODE
1537   [(DI "TARGET_SSE2 && TARGET_64BIT") (SI "TARGET_SSE2")
1538    (SF "TARGET_SSE4A") (DF "TARGET_SSE4A")
1539    (V8DI "TARGET_AVX512F") (V4DI "TARGET_AVX") (V2DI "TARGET_SSE2")
1540    (V16SF "TARGET_AVX512F") (V8SF "TARGET_AVX") V4SF
1541    (V8DF "TARGET_AVX512F") (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
1542
1543 (define_expand "storent<mode>"
1544   [(set (match_operand:STORENT_MODE 0 "memory_operand")
1545         (unspec:STORENT_MODE
1546           [(match_operand:STORENT_MODE 1 "register_operand")]
1547           UNSPEC_MOVNT))]
1548   "TARGET_SSE")
1549
1550 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1551 ;;
1552 ;; Parallel floating point arithmetic
1553 ;;
1554 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1555
1556 (define_expand "<code><mode>2"
1557   [(set (match_operand:VF 0 "register_operand")
1558         (absneg:VF
1559           (match_operand:VF 1 "register_operand")))]
1560   "TARGET_SSE"
1561   "ix86_expand_fp_absneg_operator (<CODE>, <MODE>mode, operands); DONE;")
1562
1563 (define_insn_and_split "*absneg<mode>2"
1564   [(set (match_operand:VF 0 "register_operand" "=x,x,v,v")
1565         (match_operator:VF 3 "absneg_operator"
1566           [(match_operand:VF 1 "nonimmediate_operand" "0, xm, v, m")]))
1567    (use (match_operand:VF 2 "nonimmediate_operand"    "xm, 0, vm,v"))]
1568   "TARGET_SSE"
1569   "#"
1570   "&& reload_completed"
1571   [(const_int 0)]
1572 {
1573   enum rtx_code absneg_op;
1574   rtx op1, op2;
1575   rtx t;
1576
1577   if (TARGET_AVX)
1578     {
1579       if (MEM_P (operands[1]))
1580         op1 = operands[2], op2 = operands[1];
1581       else
1582         op1 = operands[1], op2 = operands[2];
1583     }
1584   else
1585     {
1586       op1 = operands[0];
1587       if (rtx_equal_p (operands[0], operands[1]))
1588         op2 = operands[2];
1589       else
1590         op2 = operands[1];
1591     }
1592
1593   absneg_op = GET_CODE (operands[3]) == NEG ? XOR : AND;
1594   t = gen_rtx_fmt_ee (absneg_op, <MODE>mode, op1, op2);
1595   t = gen_rtx_SET (VOIDmode, operands[0], t);
1596   emit_insn (t);
1597   DONE;
1598 }
1599   [(set_attr "isa" "noavx,noavx,avx,avx")])
1600
1601 (define_expand "<plusminus_insn><mode>3<mask_name><round_name>"
1602   [(set (match_operand:VF 0 "register_operand")
1603         (plusminus:VF
1604           (match_operand:VF 1 "<round_nimm_predicate>")
1605           (match_operand:VF 2 "<round_nimm_predicate>")))]
1606   "TARGET_SSE && <mask_mode512bit_condition> && <round_mode512bit_condition>"
1607   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
1608
1609 (define_insn "*<plusminus_insn><mode>3<mask_name><round_name>"
1610   [(set (match_operand:VF 0 "register_operand" "=x,v")
1611         (plusminus:VF
1612           (match_operand:VF 1 "<round_nimm_predicate>" "<comm>0,v")
1613           (match_operand:VF 2 "<round_nimm_predicate>" "xm,<round_constraint>")))]
1614   "TARGET_SSE && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands) && <mask_mode512bit_condition> && <round_mode512bit_condition>"
1615   "@
1616    <plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
1617    v<plusminus_mnemonic><ssemodesuffix>\t{<round_mask_op3>%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2<round_mask_op3>}"
1618   [(set_attr "isa" "noavx,avx")
1619    (set_attr "type" "sseadd")
1620    (set_attr "prefix" "<mask_prefix3>")
1621    (set_attr "mode" "<MODE>")])
1622
1623 (define_insn "<sse>_vm<plusminus_insn><mode>3<round_name>"
1624   [(set (match_operand:VF_128 0 "register_operand" "=x,v")
1625         (vec_merge:VF_128
1626           (plusminus:VF_128
1627             (match_operand:VF_128 1 "register_operand" "0,v")
1628             (match_operand:VF_128 2 "nonimmediate_operand" "xm,<round_constraint>"))
1629           (match_dup 1)
1630           (const_int 1)))]
1631   "TARGET_SSE"
1632   "@
1633    <plusminus_mnemonic><ssescalarmodesuffix>\t{%2, %0|%0, %<iptr>2}
1634    v<plusminus_mnemonic><ssescalarmodesuffix>\t{<round_op3>%2, %1, %0|%0, %1, %<iptr>2<round_op3>}"
1635   [(set_attr "isa" "noavx,avx")
1636    (set_attr "type" "sseadd")
1637    (set_attr "prefix" "<round_prefix>")
1638    (set_attr "mode" "<ssescalarmode>")])
1639
1640 (define_expand "mul<mode>3<mask_name><round_name>"
1641   [(set (match_operand:VF 0 "register_operand")
1642         (mult:VF
1643           (match_operand:VF 1 "<round_nimm_predicate>")
1644           (match_operand:VF 2 "<round_nimm_predicate>")))]
1645   "TARGET_SSE && <mask_mode512bit_condition> && <round_mode512bit_condition>"
1646   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
1647
1648 (define_insn "*mul<mode>3<mask_name><round_name>"
1649   [(set (match_operand:VF 0 "register_operand" "=x,v")
1650         (mult:VF
1651           (match_operand:VF 1 "<round_nimm_predicate>" "%0,v")
1652           (match_operand:VF 2 "<round_nimm_predicate>" "xm,<round_constraint>")))]
1653   "TARGET_SSE && ix86_binary_operator_ok (MULT, <MODE>mode, operands) && <mask_mode512bit_condition> && <round_mode512bit_condition>"
1654   "@
1655    mul<ssemodesuffix>\t{%2, %0|%0, %2}
1656    vmul<ssemodesuffix>\t{<round_mask_op3>%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2<round_mask_op3>}"
1657   [(set_attr "isa" "noavx,avx")
1658    (set_attr "type" "ssemul")
1659    (set_attr "prefix" "<mask_prefix3>")
1660    (set_attr "btver2_decode" "direct,double")
1661    (set_attr "mode" "<MODE>")])
1662
1663 (define_insn "<sse>_vm<multdiv_mnemonic><mode>3<round_name>"
1664   [(set (match_operand:VF_128 0 "register_operand" "=x,v")
1665         (vec_merge:VF_128
1666           (multdiv:VF_128
1667             (match_operand:VF_128 1 "register_operand" "0,v")
1668             (match_operand:VF_128 2 "nonimmediate_operand" "xm,<round_constraint>"))
1669           (match_dup 1)
1670           (const_int 1)))]
1671   "TARGET_SSE"
1672   "@
1673    <multdiv_mnemonic><ssescalarmodesuffix>\t{%2, %0|%0, %<iptr>2}
1674    v<multdiv_mnemonic><ssescalarmodesuffix>\t{<round_op3>%2, %1, %0|%0, %1, %<iptr>2<round_op3>}"
1675   [(set_attr "isa" "noavx,avx")
1676    (set_attr "type" "sse<multdiv_mnemonic>")
1677    (set_attr "prefix" "<round_prefix>")
1678    (set_attr "btver2_decode" "direct,double")
1679    (set_attr "mode" "<ssescalarmode>")])
1680
1681 (define_expand "div<mode>3"
1682   [(set (match_operand:VF2 0 "register_operand")
1683         (div:VF2 (match_operand:VF2 1 "register_operand")
1684                  (match_operand:VF2 2 "nonimmediate_operand")))]
1685   "TARGET_SSE2"
1686   "ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);")
1687
1688 (define_expand "div<mode>3"
1689   [(set (match_operand:VF1 0 "register_operand")
1690         (div:VF1 (match_operand:VF1 1 "register_operand")
1691                  (match_operand:VF1 2 "nonimmediate_operand")))]
1692   "TARGET_SSE"
1693 {
1694   ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);
1695
1696   if (TARGET_SSE_MATH
1697       && TARGET_RECIP_VEC_DIV
1698       && !optimize_insn_for_size_p ()
1699       && flag_finite_math_only && !flag_trapping_math
1700       && flag_unsafe_math_optimizations)
1701     {
1702       ix86_emit_swdivsf (operands[0], operands[1], operands[2], <MODE>mode);
1703       DONE;
1704     }
1705 })
1706
1707 (define_insn "<sse>_div<mode>3<mask_name><round_name>"
1708   [(set (match_operand:VF 0 "register_operand" "=x,v")
1709         (div:VF
1710           (match_operand:VF 1 "register_operand" "0,v")
1711           (match_operand:VF 2 "<round_nimm_predicate>" "xm,<round_constraint>")))]
1712   "TARGET_SSE && <mask_mode512bit_condition> && <round_mode512bit_condition>"
1713   "@
1714    div<ssemodesuffix>\t{%2, %0|%0, %2}
1715    vdiv<ssemodesuffix>\t{<round_mask_op3>%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2<round_mask_op3>}"
1716   [(set_attr "isa" "noavx,avx")
1717    (set_attr "type" "ssediv")
1718    (set_attr "prefix" "<mask_prefix3>")
1719    (set_attr "mode" "<MODE>")])
1720
1721 (define_insn "<sse>_rcp<mode>2"
1722   [(set (match_operand:VF1_128_256 0 "register_operand" "=x")
1723         (unspec:VF1_128_256
1724           [(match_operand:VF1_128_256 1 "nonimmediate_operand" "xm")] UNSPEC_RCP))]
1725   "TARGET_SSE"
1726   "%vrcpps\t{%1, %0|%0, %1}"
1727   [(set_attr "type" "sse")
1728    (set_attr "atom_sse_attr" "rcp")
1729    (set_attr "btver2_sse_attr" "rcp")
1730    (set_attr "prefix" "maybe_vex")
1731    (set_attr "mode" "<MODE>")])
1732
1733 (define_insn "sse_vmrcpv4sf2"
1734   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1735         (vec_merge:V4SF
1736           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
1737                        UNSPEC_RCP)
1738           (match_operand:V4SF 2 "register_operand" "0,x")
1739           (const_int 1)))]
1740   "TARGET_SSE"
1741   "@
1742    rcpss\t{%1, %0|%0, %k1}
1743    vrcpss\t{%1, %2, %0|%0, %2, %k1}"
1744   [(set_attr "isa" "noavx,avx")
1745    (set_attr "type" "sse")
1746    (set_attr "ssememalign" "32")
1747    (set_attr "atom_sse_attr" "rcp")
1748    (set_attr "btver2_sse_attr" "rcp")
1749    (set_attr "prefix" "orig,vex")
1750    (set_attr "mode" "SF")])
1751
1752 (define_insn "<mask_codefor>rcp14<mode><mask_name>"
1753   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
1754         (unspec:VF_AVX512VL
1755           [(match_operand:VF_AVX512VL 1 "nonimmediate_operand" "vm")]
1756           UNSPEC_RCP14))]
1757   "TARGET_AVX512F"
1758   "vrcp14<ssemodesuffix>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
1759   [(set_attr "type" "sse")
1760    (set_attr "prefix" "evex")
1761    (set_attr "mode" "<MODE>")])
1762
1763 (define_insn "srcp14<mode>"
1764   [(set (match_operand:VF_128 0 "register_operand" "=v")
1765         (vec_merge:VF_128
1766           (unspec:VF_128
1767             [(match_operand:VF_128 1 "nonimmediate_operand" "vm")]
1768             UNSPEC_RCP14)
1769           (match_operand:VF_128 2 "register_operand" "v")
1770           (const_int 1)))]
1771   "TARGET_AVX512F"
1772   "vrcp14<ssescalarmodesuffix>\t{%1, %2, %0|%0, %2, %1}"
1773   [(set_attr "type" "sse")
1774    (set_attr "prefix" "evex")
1775    (set_attr "mode" "<MODE>")])
1776
1777 (define_expand "sqrt<mode>2"
1778   [(set (match_operand:VF2 0 "register_operand")
1779         (sqrt:VF2 (match_operand:VF2 1 "nonimmediate_operand")))]
1780   "TARGET_SSE2")
1781
1782 (define_expand "sqrt<mode>2"
1783   [(set (match_operand:VF1 0 "register_operand")
1784         (sqrt:VF1 (match_operand:VF1 1 "nonimmediate_operand")))]
1785   "TARGET_SSE"
1786 {
1787   if (TARGET_SSE_MATH
1788       && TARGET_RECIP_VEC_SQRT
1789       && !optimize_insn_for_size_p ()
1790       && flag_finite_math_only && !flag_trapping_math
1791       && flag_unsafe_math_optimizations)
1792     {
1793       ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, false);
1794       DONE;
1795     }
1796 })
1797
1798 (define_insn "<sse>_sqrt<mode>2<mask_name><round_name>"
1799   [(set (match_operand:VF 0 "register_operand" "=v")
1800         (sqrt:VF (match_operand:VF 1 "<round_nimm_predicate>" "<round_constraint>")))]
1801   "TARGET_SSE && <mask_mode512bit_condition> && <round_mode512bit_condition>"
1802   "%vsqrt<ssemodesuffix>\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
1803   [(set_attr "type" "sse")
1804    (set_attr "atom_sse_attr" "sqrt")
1805    (set_attr "btver2_sse_attr" "sqrt")
1806    (set_attr "prefix" "maybe_vex")
1807    (set_attr "mode" "<MODE>")])
1808
1809 (define_insn "<sse>_vmsqrt<mode>2<round_name>"
1810   [(set (match_operand:VF_128 0 "register_operand" "=x,v")
1811         (vec_merge:VF_128
1812           (sqrt:VF_128
1813             (match_operand:VF_128 1 "nonimmediate_operand" "xm,<round_constraint>"))
1814           (match_operand:VF_128 2 "register_operand" "0,v")
1815           (const_int 1)))]
1816   "TARGET_SSE"
1817   "@
1818    sqrt<ssescalarmodesuffix>\t{%1, %0|%0, %<iptr>1}
1819    vsqrt<ssescalarmodesuffix>\t{<round_op3>%1, %2, %0|%0, %2, %<iptr>1<round_op3>}"
1820   [(set_attr "isa" "noavx,avx")
1821    (set_attr "type" "sse")
1822    (set_attr "atom_sse_attr" "sqrt")
1823    (set_attr "prefix" "<round_prefix>")
1824    (set_attr "btver2_sse_attr" "sqrt")
1825    (set_attr "mode" "<ssescalarmode>")])
1826
1827 (define_expand "rsqrt<mode>2"
1828   [(set (match_operand:VF1_128_256 0 "register_operand")
1829         (unspec:VF1_128_256
1830           [(match_operand:VF1_128_256 1 "nonimmediate_operand")] UNSPEC_RSQRT))]
1831   "TARGET_SSE_MATH"
1832 {
1833   ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, true);
1834   DONE;
1835 })
1836
1837 (define_insn "<sse>_rsqrt<mode>2"
1838   [(set (match_operand:VF1_128_256 0 "register_operand" "=x")
1839         (unspec:VF1_128_256
1840           [(match_operand:VF1_128_256 1 "nonimmediate_operand" "xm")] UNSPEC_RSQRT))]
1841   "TARGET_SSE"
1842   "%vrsqrtps\t{%1, %0|%0, %1}"
1843   [(set_attr "type" "sse")
1844    (set_attr "prefix" "maybe_vex")
1845    (set_attr "mode" "<MODE>")])
1846
1847 (define_insn "<mask_codefor>rsqrt14<mode><mask_name>"
1848   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
1849         (unspec:VF_AVX512VL
1850           [(match_operand:VF_AVX512VL 1 "nonimmediate_operand" "vm")]
1851           UNSPEC_RSQRT14))]
1852   "TARGET_AVX512F"
1853   "vrsqrt14<ssemodesuffix>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
1854   [(set_attr "type" "sse")
1855    (set_attr "prefix" "evex")
1856    (set_attr "mode" "<MODE>")])
1857
1858 (define_insn "rsqrt14<mode>"
1859   [(set (match_operand:VF_128 0 "register_operand" "=v")
1860         (vec_merge:VF_128
1861           (unspec:VF_128
1862             [(match_operand:VF_128 1 "nonimmediate_operand" "vm")]
1863             UNSPEC_RSQRT14)
1864           (match_operand:VF_128 2 "register_operand" "v")
1865           (const_int 1)))]
1866   "TARGET_AVX512F"
1867   "vrsqrt14<ssescalarmodesuffix>\t{%1, %2, %0|%0, %2, %1}"
1868   [(set_attr "type" "sse")
1869    (set_attr "prefix" "evex")
1870    (set_attr "mode" "<MODE>")])
1871
1872 (define_insn "sse_vmrsqrtv4sf2"
1873   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1874         (vec_merge:V4SF
1875           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
1876                        UNSPEC_RSQRT)
1877           (match_operand:V4SF 2 "register_operand" "0,x")
1878           (const_int 1)))]
1879   "TARGET_SSE"
1880   "@
1881    rsqrtss\t{%1, %0|%0, %k1}
1882    vrsqrtss\t{%1, %2, %0|%0, %2, %k1}"
1883   [(set_attr "isa" "noavx,avx")
1884    (set_attr "type" "sse")
1885    (set_attr "ssememalign" "32")
1886    (set_attr "prefix" "orig,vex")
1887    (set_attr "mode" "SF")])
1888
1889 ;; ??? For !flag_finite_math_only, the representation with SMIN/SMAX
1890 ;; isn't really correct, as those rtl operators aren't defined when
1891 ;; applied to NaNs.  Hopefully the optimizers won't get too smart on us.
1892
1893 (define_expand "<code><mode>3<mask_name><round_saeonly_name>"
1894   [(set (match_operand:VF 0 "register_operand")
1895         (smaxmin:VF
1896           (match_operand:VF 1 "<round_saeonly_nimm_predicate>")
1897           (match_operand:VF 2 "<round_saeonly_nimm_predicate>")))]
1898   "TARGET_SSE && <mask_mode512bit_condition> && <round_saeonly_mode512bit_condition>"
1899 {
1900   if (!flag_finite_math_only)
1901     operands[1] = force_reg (<MODE>mode, operands[1]);
1902   ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
1903 })
1904
1905 (define_insn "*<code><mode>3_finite<mask_name><round_saeonly_name>"
1906   [(set (match_operand:VF 0 "register_operand" "=x,v")
1907         (smaxmin:VF
1908           (match_operand:VF 1 "<round_saeonly_nimm_predicate>" "%0,v")
1909           (match_operand:VF 2 "<round_saeonly_nimm_predicate>" "xm,<round_saeonly_constraint>")))]
1910   "TARGET_SSE && flag_finite_math_only
1911    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)
1912    && <mask_mode512bit_condition> && <round_saeonly_mode512bit_condition>"
1913   "@
1914    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
1915    v<maxmin_float><ssemodesuffix>\t{<round_saeonly_mask_op3>%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2<round_saeonly_mask_op3>}"
1916   [(set_attr "isa" "noavx,avx")
1917    (set_attr "type" "sseadd")
1918    (set_attr "btver2_sse_attr" "maxmin")
1919    (set_attr "prefix" "<mask_prefix3>")
1920    (set_attr "mode" "<MODE>")])
1921
1922 (define_insn "*<code><mode>3<mask_name><round_saeonly_name>"
1923   [(set (match_operand:VF 0 "register_operand" "=x,v")
1924         (smaxmin:VF
1925           (match_operand:VF 1 "register_operand" "0,v")
1926           (match_operand:VF 2 "<round_saeonly_nimm_predicate>" "xm,<round_saeonly_constraint>")))]
1927   "TARGET_SSE && !flag_finite_math_only
1928    && <mask_mode512bit_condition> && <round_saeonly_mode512bit_condition>"
1929   "@
1930    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
1931    v<maxmin_float><ssemodesuffix>\t{<round_saeonly_mask_op3>%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2<round_saeonly_mask_op3>}"
1932   [(set_attr "isa" "noavx,avx")
1933    (set_attr "type" "sseadd")
1934    (set_attr "btver2_sse_attr" "maxmin")
1935    (set_attr "prefix" "<mask_prefix3>")
1936    (set_attr "mode" "<MODE>")])
1937
1938 (define_insn "<sse>_vm<code><mode>3<round_saeonly_name>"
1939   [(set (match_operand:VF_128 0 "register_operand" "=x,v")
1940         (vec_merge:VF_128
1941           (smaxmin:VF_128
1942             (match_operand:VF_128 1 "register_operand" "0,v")
1943             (match_operand:VF_128 2 "nonimmediate_operand" "xm,<round_saeonly_constraint>"))
1944          (match_dup 1)
1945          (const_int 1)))]
1946   "TARGET_SSE"
1947   "@
1948    <maxmin_float><ssescalarmodesuffix>\t{%2, %0|%0, %<iptr>2}
1949    v<maxmin_float><ssescalarmodesuffix>\t{<round_saeonly_op3>%2, %1, %0|%0, %1, %<iptr>2<round_saeonly_op3>}"
1950   [(set_attr "isa" "noavx,avx")
1951    (set_attr "type" "sse")
1952    (set_attr "btver2_sse_attr" "maxmin")
1953    (set_attr "prefix" "<round_saeonly_prefix>")
1954    (set_attr "mode" "<ssescalarmode>")])
1955
1956 ;; These versions of the min/max patterns implement exactly the operations
1957 ;;   min = (op1 < op2 ? op1 : op2)
1958 ;;   max = (!(op1 < op2) ? op1 : op2)
1959 ;; Their operands are not commutative, and thus they may be used in the
1960 ;; presence of -0.0 and NaN.
1961
1962 (define_insn "*ieee_smin<mode>3"
1963   [(set (match_operand:VF 0 "register_operand" "=v,v")
1964         (unspec:VF
1965           [(match_operand:VF 1 "register_operand" "0,v")
1966            (match_operand:VF 2 "nonimmediate_operand" "vm,vm")]
1967          UNSPEC_IEEE_MIN))]
1968   "TARGET_SSE"
1969   "@
1970    min<ssemodesuffix>\t{%2, %0|%0, %2}
1971    vmin<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1972   [(set_attr "isa" "noavx,avx")
1973    (set_attr "type" "sseadd")
1974    (set_attr "prefix" "orig,vex")
1975    (set_attr "mode" "<MODE>")])
1976
1977 (define_insn "*ieee_smax<mode>3"
1978   [(set (match_operand:VF 0 "register_operand" "=v,v")
1979         (unspec:VF
1980           [(match_operand:VF 1 "register_operand" "0,v")
1981            (match_operand:VF 2 "nonimmediate_operand" "vm,vm")]
1982          UNSPEC_IEEE_MAX))]
1983   "TARGET_SSE"
1984   "@
1985    max<ssemodesuffix>\t{%2, %0|%0, %2}
1986    vmax<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1987   [(set_attr "isa" "noavx,avx")
1988    (set_attr "type" "sseadd")
1989    (set_attr "prefix" "orig,vex")
1990    (set_attr "mode" "<MODE>")])
1991
1992 (define_insn "avx_addsubv4df3"
1993   [(set (match_operand:V4DF 0 "register_operand" "=x")
1994         (vec_merge:V4DF
1995           (plus:V4DF
1996             (match_operand:V4DF 1 "register_operand" "x")
1997             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
1998           (minus:V4DF (match_dup 1) (match_dup 2))
1999           (const_int 10)))]
2000   "TARGET_AVX"
2001   "vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
2002   [(set_attr "type" "sseadd")
2003    (set_attr "prefix" "vex")
2004    (set_attr "mode" "V4DF")])
2005
2006 (define_insn "sse3_addsubv2df3"
2007   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
2008         (vec_merge:V2DF
2009           (plus:V2DF
2010             (match_operand:V2DF 1 "register_operand" "0,x")
2011             (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm"))
2012           (minus:V2DF (match_dup 1) (match_dup 2))
2013           (const_int 2)))]
2014   "TARGET_SSE3"
2015   "@
2016    addsubpd\t{%2, %0|%0, %2}
2017    vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
2018   [(set_attr "isa" "noavx,avx")
2019    (set_attr "type" "sseadd")
2020    (set_attr "atom_unit" "complex")
2021    (set_attr "prefix" "orig,vex")
2022    (set_attr "mode" "V2DF")])
2023
2024 (define_insn "avx_addsubv8sf3"
2025   [(set (match_operand:V8SF 0 "register_operand" "=x")
2026         (vec_merge:V8SF
2027           (plus:V8SF
2028             (match_operand:V8SF 1 "register_operand" "x")
2029             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
2030           (minus:V8SF (match_dup 1) (match_dup 2))
2031           (const_int 170)))]
2032   "TARGET_AVX"
2033   "vaddsubps\t{%2, %1, %0|%0, %1, %2}"
2034   [(set_attr "type" "sseadd")
2035    (set_attr "prefix" "vex")
2036    (set_attr "mode" "V8SF")])
2037
2038 (define_insn "sse3_addsubv4sf3"
2039   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
2040         (vec_merge:V4SF
2041           (plus:V4SF
2042             (match_operand:V4SF 1 "register_operand" "0,x")
2043             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
2044           (minus:V4SF (match_dup 1) (match_dup 2))
2045           (const_int 10)))]
2046   "TARGET_SSE3"
2047   "@
2048    addsubps\t{%2, %0|%0, %2}
2049    vaddsubps\t{%2, %1, %0|%0, %1, %2}"
2050   [(set_attr "isa" "noavx,avx")
2051    (set_attr "type" "sseadd")
2052    (set_attr "prefix" "orig,vex")
2053    (set_attr "prefix_rep" "1,*")
2054    (set_attr "mode" "V4SF")])
2055
2056 (define_insn "avx_h<plusminus_insn>v4df3"
2057   [(set (match_operand:V4DF 0 "register_operand" "=x")
2058         (vec_concat:V4DF
2059           (vec_concat:V2DF
2060             (plusminus:DF
2061               (vec_select:DF
2062                 (match_operand:V4DF 1 "register_operand" "x")
2063                 (parallel [(const_int 0)]))
2064               (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
2065             (plusminus:DF
2066               (vec_select:DF
2067                 (match_operand:V4DF 2 "nonimmediate_operand" "xm")
2068                 (parallel [(const_int 0)]))
2069               (vec_select:DF (match_dup 2) (parallel [(const_int 1)]))))
2070           (vec_concat:V2DF
2071             (plusminus:DF
2072               (vec_select:DF (match_dup 1) (parallel [(const_int 2)]))
2073               (vec_select:DF (match_dup 1) (parallel [(const_int 3)])))
2074             (plusminus:DF
2075               (vec_select:DF (match_dup 2) (parallel [(const_int 2)]))
2076               (vec_select:DF (match_dup 2) (parallel [(const_int 3)]))))))]
2077   "TARGET_AVX"
2078   "vh<plusminus_mnemonic>pd\t{%2, %1, %0|%0, %1, %2}"
2079   [(set_attr "type" "sseadd")
2080    (set_attr "prefix" "vex")
2081    (set_attr "mode" "V4DF")])
2082
2083 (define_expand "sse3_haddv2df3"
2084   [(set (match_operand:V2DF 0 "register_operand")
2085         (vec_concat:V2DF
2086           (plus:DF
2087             (vec_select:DF
2088               (match_operand:V2DF 1 "register_operand")
2089               (parallel [(const_int 0)]))
2090             (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
2091           (plus:DF
2092             (vec_select:DF
2093               (match_operand:V2DF 2 "nonimmediate_operand")
2094               (parallel [(const_int 0)]))
2095             (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))))]
2096   "TARGET_SSE3")
2097
2098 (define_insn "*sse3_haddv2df3"
2099   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
2100         (vec_concat:V2DF
2101           (plus:DF
2102             (vec_select:DF
2103               (match_operand:V2DF 1 "register_operand" "0,x")
2104               (parallel [(match_operand:SI 3 "const_0_to_1_operand")]))
2105             (vec_select:DF
2106               (match_dup 1)
2107               (parallel [(match_operand:SI 4 "const_0_to_1_operand")])))
2108           (plus:DF
2109             (vec_select:DF
2110               (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm")
2111               (parallel [(match_operand:SI 5 "const_0_to_1_operand")]))
2112             (vec_select:DF
2113               (match_dup 2)
2114               (parallel [(match_operand:SI 6 "const_0_to_1_operand")])))))]
2115   "TARGET_SSE3
2116    && INTVAL (operands[3]) != INTVAL (operands[4])
2117    && INTVAL (operands[5]) != INTVAL (operands[6])"
2118   "@
2119    haddpd\t{%2, %0|%0, %2}
2120    vhaddpd\t{%2, %1, %0|%0, %1, %2}"
2121   [(set_attr "isa" "noavx,avx")
2122    (set_attr "type" "sseadd")
2123    (set_attr "prefix" "orig,vex")
2124    (set_attr "mode" "V2DF")])
2125
2126 (define_insn "sse3_hsubv2df3"
2127   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
2128         (vec_concat:V2DF
2129           (minus:DF
2130             (vec_select:DF
2131               (match_operand:V2DF 1 "register_operand" "0,x")
2132               (parallel [(const_int 0)]))
2133             (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
2134           (minus:DF
2135             (vec_select:DF
2136               (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm")
2137               (parallel [(const_int 0)]))
2138             (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))))]
2139   "TARGET_SSE3"
2140   "@
2141    hsubpd\t{%2, %0|%0, %2}
2142    vhsubpd\t{%2, %1, %0|%0, %1, %2}"
2143   [(set_attr "isa" "noavx,avx")
2144    (set_attr "type" "sseadd")
2145    (set_attr "prefix" "orig,vex")
2146    (set_attr "mode" "V2DF")])
2147
2148 (define_insn "*sse3_haddv2df3_low"
2149   [(set (match_operand:DF 0 "register_operand" "=x,x")
2150         (plus:DF
2151           (vec_select:DF
2152             (match_operand:V2DF 1 "register_operand" "0,x")
2153             (parallel [(match_operand:SI 2 "const_0_to_1_operand")]))
2154           (vec_select:DF
2155             (match_dup 1)
2156             (parallel [(match_operand:SI 3 "const_0_to_1_operand")]))))]
2157   "TARGET_SSE3
2158    && INTVAL (operands[2]) != INTVAL (operands[3])"
2159   "@
2160    haddpd\t{%0, %0|%0, %0}
2161    vhaddpd\t{%1, %1, %0|%0, %1, %1}"
2162   [(set_attr "isa" "noavx,avx")
2163    (set_attr "type" "sseadd1")
2164    (set_attr "prefix" "orig,vex")
2165    (set_attr "mode" "V2DF")])
2166
2167 (define_insn "*sse3_hsubv2df3_low"
2168   [(set (match_operand:DF 0 "register_operand" "=x,x")
2169         (minus:DF
2170           (vec_select:DF
2171             (match_operand:V2DF 1 "register_operand" "0,x")
2172             (parallel [(const_int 0)]))
2173           (vec_select:DF
2174             (match_dup 1)
2175             (parallel [(const_int 1)]))))]
2176   "TARGET_SSE3"
2177   "@
2178    hsubpd\t{%0, %0|%0, %0}
2179    vhsubpd\t{%1, %1, %0|%0, %1, %1}"
2180   [(set_attr "isa" "noavx,avx")
2181    (set_attr "type" "sseadd1")
2182    (set_attr "prefix" "orig,vex")
2183    (set_attr "mode" "V2DF")])
2184
2185 (define_insn "avx_h<plusminus_insn>v8sf3"
2186   [(set (match_operand:V8SF 0 "register_operand" "=x")
2187         (vec_concat:V8SF
2188           (vec_concat:V4SF
2189             (vec_concat:V2SF
2190               (plusminus:SF
2191                 (vec_select:SF
2192                   (match_operand:V8SF 1 "register_operand" "x")
2193                   (parallel [(const_int 0)]))
2194                 (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
2195               (plusminus:SF
2196                 (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
2197                 (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
2198             (vec_concat:V2SF
2199               (plusminus:SF
2200                 (vec_select:SF
2201                   (match_operand:V8SF 2 "nonimmediate_operand" "xm")
2202                   (parallel [(const_int 0)]))
2203                 (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
2204               (plusminus:SF
2205                 (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
2206                 (vec_select:SF (match_dup 2) (parallel [(const_int 3)])))))
2207           (vec_concat:V4SF
2208             (vec_concat:V2SF
2209               (plusminus:SF
2210                 (vec_select:SF (match_dup 1) (parallel [(const_int 4)]))
2211                 (vec_select:SF (match_dup 1) (parallel [(const_int 5)])))
2212               (plusminus:SF
2213                 (vec_select:SF (match_dup 1) (parallel [(const_int 6)]))
2214                 (vec_select:SF (match_dup 1) (parallel [(const_int 7)]))))
2215             (vec_concat:V2SF
2216               (plusminus:SF
2217                 (vec_select:SF (match_dup 2) (parallel [(const_int 4)]))
2218                 (vec_select:SF (match_dup 2) (parallel [(const_int 5)])))
2219               (plusminus:SF
2220                 (vec_select:SF (match_dup 2) (parallel [(const_int 6)]))
2221                 (vec_select:SF (match_dup 2) (parallel [(const_int 7)])))))))]
2222   "TARGET_AVX"
2223   "vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
2224   [(set_attr "type" "sseadd")
2225    (set_attr "prefix" "vex")
2226    (set_attr "mode" "V8SF")])
2227
2228 (define_insn "sse3_h<plusminus_insn>v4sf3"
2229   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
2230         (vec_concat:V4SF
2231           (vec_concat:V2SF
2232             (plusminus:SF
2233               (vec_select:SF
2234                 (match_operand:V4SF 1 "register_operand" "0,x")
2235                 (parallel [(const_int 0)]))
2236               (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
2237             (plusminus:SF
2238               (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
2239               (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
2240           (vec_concat:V2SF
2241             (plusminus:SF
2242               (vec_select:SF
2243                 (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm")
2244                 (parallel [(const_int 0)]))
2245               (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
2246             (plusminus:SF
2247               (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
2248               (vec_select:SF (match_dup 2) (parallel [(const_int 3)]))))))]
2249   "TARGET_SSE3"
2250   "@
2251    h<plusminus_mnemonic>ps\t{%2, %0|%0, %2}
2252    vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
2253   [(set_attr "isa" "noavx,avx")
2254    (set_attr "type" "sseadd")
2255    (set_attr "atom_unit" "complex")
2256    (set_attr "prefix" "orig,vex")
2257    (set_attr "prefix_rep" "1,*")
2258    (set_attr "mode" "V4SF")])
2259
2260 (define_expand "reduc_splus_v8df"
2261   [(match_operand:V8DF 0 "register_operand")
2262    (match_operand:V8DF 1 "register_operand")]
2263   "TARGET_AVX512F"
2264 {
2265   ix86_expand_reduc (gen_addv8df3, operands[0], operands[1]);
2266   DONE;
2267 })
2268
2269 (define_expand "reduc_splus_v4df"
2270   [(match_operand:V4DF 0 "register_operand")
2271    (match_operand:V4DF 1 "register_operand")]
2272   "TARGET_AVX"
2273 {
2274   rtx tmp = gen_reg_rtx (V4DFmode);
2275   rtx tmp2 = gen_reg_rtx (V4DFmode);
2276   emit_insn (gen_avx_haddv4df3 (tmp, operands[1], operands[1]));
2277   emit_insn (gen_avx_vperm2f128v4df3 (tmp2, tmp, tmp, GEN_INT (1)));
2278   emit_insn (gen_addv4df3 (operands[0], tmp, tmp2));
2279   DONE;
2280 })
2281
2282 (define_expand "reduc_splus_v2df"
2283   [(match_operand:V2DF 0 "register_operand")
2284    (match_operand:V2DF 1 "register_operand")]
2285   "TARGET_SSE3"
2286 {
2287   emit_insn (gen_sse3_haddv2df3 (operands[0], operands[1], operands[1]));
2288   DONE;
2289 })
2290
2291 (define_expand "reduc_splus_v16sf"
2292   [(match_operand:V16SF 0 "register_operand")
2293    (match_operand:V16SF 1 "register_operand")]
2294   "TARGET_AVX512F"
2295 {
2296   ix86_expand_reduc (gen_addv16sf3, operands[0], operands[1]);
2297   DONE;
2298 })
2299
2300 (define_expand "reduc_splus_v8sf"
2301   [(match_operand:V8SF 0 "register_operand")
2302    (match_operand:V8SF 1 "register_operand")]
2303   "TARGET_AVX"
2304 {
2305   rtx tmp = gen_reg_rtx (V8SFmode);
2306   rtx tmp2 = gen_reg_rtx (V8SFmode);
2307   emit_insn (gen_avx_haddv8sf3 (tmp, operands[1], operands[1]));
2308   emit_insn (gen_avx_haddv8sf3 (tmp2, tmp, tmp));
2309   emit_insn (gen_avx_vperm2f128v8sf3 (tmp, tmp2, tmp2, GEN_INT (1)));
2310   emit_insn (gen_addv8sf3 (operands[0], tmp, tmp2));
2311   DONE;
2312 })
2313
2314 (define_expand "reduc_splus_v4sf"
2315   [(match_operand:V4SF 0 "register_operand")
2316    (match_operand:V4SF 1 "register_operand")]
2317   "TARGET_SSE"
2318 {
2319   if (TARGET_SSE3)
2320     {
2321       rtx tmp = gen_reg_rtx (V4SFmode);
2322       emit_insn (gen_sse3_haddv4sf3 (tmp, operands[1], operands[1]));
2323       emit_insn (gen_sse3_haddv4sf3 (operands[0], tmp, tmp));
2324     }
2325   else
2326     ix86_expand_reduc (gen_addv4sf3, operands[0], operands[1]);
2327   DONE;
2328 })
2329
2330 ;; Modes handled by reduc_sm{in,ax}* patterns.
2331 (define_mode_iterator REDUC_SMINMAX_MODE
2332   [(V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
2333    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")
2334    (V8SF "TARGET_AVX") (V4DF "TARGET_AVX")
2335    (V4SF "TARGET_SSE") (V64QI "TARGET_AVX512BW")
2336    (V32HI "TARGET_AVX512BW") (V16SI "TARGET_AVX512F")
2337    (V8DI "TARGET_AVX512F") (V16SF "TARGET_AVX512F")
2338    (V8DF "TARGET_AVX512F")])
2339
2340 (define_expand "reduc_<code>_<mode>"
2341   [(smaxmin:REDUC_SMINMAX_MODE
2342      (match_operand:REDUC_SMINMAX_MODE 0 "register_operand")
2343      (match_operand:REDUC_SMINMAX_MODE 1 "register_operand"))]
2344   ""
2345 {
2346   ix86_expand_reduc (gen_<code><mode>3, operands[0], operands[1]);
2347   DONE;
2348 })
2349
2350 (define_expand "reduc_<code>_<mode>"
2351   [(umaxmin:VI_AVX512BW
2352      (match_operand:VI_AVX512BW 0 "register_operand")
2353      (match_operand:VI_AVX512BW 1 "register_operand"))]
2354   "TARGET_AVX512F"
2355 {
2356   ix86_expand_reduc (gen_<code><mode>3, operands[0], operands[1]);
2357   DONE;
2358 })
2359
2360 (define_expand "reduc_<code>_<mode>"
2361   [(umaxmin:VI_256
2362      (match_operand:VI_256 0 "register_operand")
2363      (match_operand:VI_256 1 "register_operand"))]
2364   "TARGET_AVX2"
2365 {
2366   ix86_expand_reduc (gen_<code><mode>3, operands[0], operands[1]);
2367   DONE;
2368 })
2369
2370 (define_expand "reduc_umin_v8hi"
2371   [(umin:V8HI
2372      (match_operand:V8HI 0 "register_operand")
2373      (match_operand:V8HI 1 "register_operand"))]
2374   "TARGET_SSE4_1"
2375 {
2376   ix86_expand_reduc (gen_uminv8hi3, operands[0], operands[1]);
2377   DONE;
2378 })
2379
2380 (define_insn "<mask_codefor>reducep<mode><mask_name>"
2381   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
2382         (unspec:VF_AVX512VL
2383           [(match_operand:VF_AVX512VL 1 "nonimmediate_operand" "vm")
2384            (match_operand:SI 2 "const_0_to_255_operand")]
2385           UNSPEC_REDUCE))]
2386   "TARGET_AVX512DQ"
2387   "vreduce<ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
2388   [(set_attr "type" "sse")
2389    (set_attr "prefix" "evex")
2390    (set_attr "mode" "<MODE>")])
2391
2392 (define_insn "reduces<mode>"
2393   [(set (match_operand:VF_128 0 "register_operand" "=v")
2394         (vec_merge:VF_128
2395           (unspec:VF_128
2396             [(match_operand:VF_128 1 "register_operand" "v")
2397              (match_operand:VF_128 2 "nonimmediate_operand" "vm")
2398              (match_operand:SI 3 "const_0_to_255_operand")]
2399             UNSPEC_REDUCE)
2400           (match_dup 1)
2401           (const_int 1)))]
2402   "TARGET_AVX512DQ"
2403   "vreduce<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2404   [(set_attr "type" "sse")
2405    (set_attr "prefix" "evex")
2406    (set_attr "mode" "<MODE>")])
2407
2408 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2409 ;;
2410 ;; Parallel floating point comparisons
2411 ;;
2412 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2413
2414 (define_insn "avx_cmp<mode>3"
2415   [(set (match_operand:VF_128_256 0 "register_operand" "=x")
2416         (unspec:VF_128_256
2417           [(match_operand:VF_128_256 1 "register_operand" "x")
2418            (match_operand:VF_128_256 2 "nonimmediate_operand" "xm")
2419            (match_operand:SI 3 "const_0_to_31_operand" "n")]
2420           UNSPEC_PCMP))]
2421   "TARGET_AVX"
2422   "vcmp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
2423   [(set_attr "type" "ssecmp")
2424    (set_attr "length_immediate" "1")
2425    (set_attr "prefix" "vex")
2426    (set_attr "mode" "<MODE>")])
2427
2428 (define_insn "avx_vmcmp<mode>3"
2429   [(set (match_operand:VF_128 0 "register_operand" "=x")
2430         (vec_merge:VF_128
2431           (unspec:VF_128
2432             [(match_operand:VF_128 1 "register_operand" "x")
2433              (match_operand:VF_128 2 "nonimmediate_operand" "xm")
2434              (match_operand:SI 3 "const_0_to_31_operand" "n")]
2435             UNSPEC_PCMP)
2436          (match_dup 1)
2437          (const_int 1)))]
2438   "TARGET_AVX"
2439   "vcmp<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %<iptr>2, %3}"
2440   [(set_attr "type" "ssecmp")
2441    (set_attr "length_immediate" "1")
2442    (set_attr "prefix" "vex")
2443    (set_attr "mode" "<ssescalarmode>")])
2444
2445 (define_insn "*<sse>_maskcmp<mode>3_comm"
2446   [(set (match_operand:VF_128_256 0 "register_operand" "=x,x")
2447         (match_operator:VF_128_256 3 "sse_comparison_operator"
2448           [(match_operand:VF_128_256 1 "register_operand" "%0,x")
2449            (match_operand:VF_128_256 2 "nonimmediate_operand" "xm,xm")]))]
2450   "TARGET_SSE
2451    && GET_RTX_CLASS (GET_CODE (operands[3])) == RTX_COMM_COMPARE"
2452   "@
2453    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
2454    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2455   [(set_attr "isa" "noavx,avx")
2456    (set_attr "type" "ssecmp")
2457    (set_attr "length_immediate" "1")
2458    (set_attr "prefix" "orig,vex")
2459    (set_attr "mode" "<MODE>")])
2460
2461 (define_insn "<sse>_maskcmp<mode>3"
2462   [(set (match_operand:VF_128_256 0 "register_operand" "=x,x")
2463         (match_operator:VF_128_256 3 "sse_comparison_operator"
2464           [(match_operand:VF_128_256 1 "register_operand" "0,x")
2465            (match_operand:VF_128_256 2 "nonimmediate_operand" "xm,xm")]))]
2466   "TARGET_SSE"
2467   "@
2468    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
2469    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2470   [(set_attr "isa" "noavx,avx")
2471    (set_attr "type" "ssecmp")
2472    (set_attr "length_immediate" "1")
2473    (set_attr "prefix" "orig,vex")
2474    (set_attr "mode" "<MODE>")])
2475
2476 (define_insn "<sse>_vmmaskcmp<mode>3"
2477   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
2478         (vec_merge:VF_128
2479          (match_operator:VF_128 3 "sse_comparison_operator"
2480            [(match_operand:VF_128 1 "register_operand" "0,x")
2481             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm")])
2482          (match_dup 1)
2483          (const_int 1)))]
2484   "TARGET_SSE"
2485   "@
2486    cmp%D3<ssescalarmodesuffix>\t{%2, %0|%0, %<iptr>2}
2487    vcmp%D3<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %<iptr>2}"
2488   [(set_attr "isa" "noavx,avx")
2489    (set_attr "type" "ssecmp")
2490    (set_attr "length_immediate" "1,*")
2491    (set_attr "prefix" "orig,vex")
2492    (set_attr "mode" "<ssescalarmode>")])
2493
2494 (define_mode_attr cmp_imm_predicate
2495   [(V16SF "const_0_to_31_operand")  (V8DF "const_0_to_31_operand")
2496    (V16SI "const_0_to_7_operand")   (V8DI "const_0_to_7_operand")
2497    (V8SF "const_0_to_31_operand")   (V4DF "const_0_to_31_operand")
2498    (V8SI "const_0_to_7_operand")    (V4DI "const_0_to_7_operand")
2499    (V4SF "const_0_to_31_operand")   (V2DF "const_0_to_31_operand")
2500    (V4SI "const_0_to_7_operand")    (V2DI "const_0_to_7_operand")
2501    (V32HI "const_0_to_7_operand")   (V64QI "const_0_to_7_operand")
2502    (V16HI "const_0_to_7_operand")   (V32QI "const_0_to_7_operand")
2503    (V8HI "const_0_to_7_operand")    (V16QI "const_0_to_7_operand")])
2504
2505 (define_insn "<avx512>_cmp<mode>3<mask_scalar_merge_name><round_saeonly_name>"
2506   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
2507         (unspec:<avx512fmaskmode>
2508           [(match_operand:V48_AVX512VL 1 "register_operand" "v")
2509            (match_operand:V48_AVX512VL 2 "nonimmediate_operand" "<round_saeonly_constraint>")
2510            (match_operand:SI 3 "<cmp_imm_predicate>" "n")]
2511           UNSPEC_PCMP))]
2512   "TARGET_AVX512F && <round_saeonly_mode512bit_condition>"
2513   "v<sseintprefix>cmp<ssemodesuffix>\t{%3, <round_saeonly_mask_scalar_merge_op4>%2, %1, %0<mask_scalar_merge_operand4>|%0<mask_scalar_merge_operand4>, %1, %2<round_saeonly_mask_scalar_merge_op4>, %3}"
2514   [(set_attr "type" "ssecmp")
2515    (set_attr "length_immediate" "1")
2516    (set_attr "prefix" "evex")
2517    (set_attr "mode" "<sseinsnmode>")])
2518
2519 (define_insn "<avx512>_cmp<mode>3<mask_scalar_merge_name>"
2520   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
2521         (unspec:<avx512fmaskmode>
2522           [(match_operand:VI12_AVX512VL 1 "register_operand" "v")
2523            (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm")
2524            (match_operand:SI 3 "<cmp_imm_predicate>" "n")]
2525           UNSPEC_PCMP))]
2526   "TARGET_AVX512BW"
2527   "vpcmp<ssemodesuffix>\t{%3, %2, %1, %0<mask_scalar_merge_operand4>|%0<mask_scalar_merge_operand4>, %1, %2, %3}"
2528   [(set_attr "type" "ssecmp")
2529    (set_attr "length_immediate" "1")
2530    (set_attr "prefix" "evex")
2531    (set_attr "mode" "<sseinsnmode>")])
2532
2533 (define_insn "<avx512>_ucmp<mode>3<mask_scalar_merge_name>"
2534   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
2535         (unspec:<avx512fmaskmode>
2536           [(match_operand:VI12_AVX512VL 1 "register_operand" "v")
2537            (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm")
2538            (match_operand:SI 3 "const_0_to_7_operand" "n")]
2539           UNSPEC_UNSIGNED_PCMP))]
2540   "TARGET_AVX512BW"
2541   "vpcmpu<ssemodesuffix>\t{%3, %2, %1, %0<mask_scalar_merge_operand4>|%0<mask_scalar_merge_operand4>, %1, %2, %3}"
2542   [(set_attr "type" "ssecmp")
2543    (set_attr "length_immediate" "1")
2544    (set_attr "prefix" "evex")
2545    (set_attr "mode" "<sseinsnmode>")])
2546
2547 (define_insn "<avx512>_ucmp<mode>3<mask_scalar_merge_name>"
2548   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
2549         (unspec:<avx512fmaskmode>
2550           [(match_operand:VI48_AVX512VL 1 "register_operand" "v")
2551            (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm")
2552            (match_operand:SI 3 "const_0_to_7_operand" "n")]
2553           UNSPEC_UNSIGNED_PCMP))]
2554   "TARGET_AVX512F"
2555   "vpcmpu<ssemodesuffix>\t{%3, %2, %1, %0<mask_scalar_merge_operand4>|%0<mask_scalar_merge_operand4>, %1, %2, %3}"
2556   [(set_attr "type" "ssecmp")
2557    (set_attr "length_immediate" "1")
2558    (set_attr "prefix" "evex")
2559    (set_attr "mode" "<sseinsnmode>")])
2560
2561 (define_insn "avx512f_vmcmp<mode>3<round_saeonly_name>"
2562   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
2563         (and:<avx512fmaskmode>
2564           (unspec:<avx512fmaskmode>
2565             [(match_operand:VF_128 1 "register_operand" "v")
2566              (match_operand:VF_128 2 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
2567              (match_operand:SI 3 "const_0_to_31_operand" "n")]
2568             UNSPEC_PCMP)
2569           (const_int 1)))]
2570   "TARGET_AVX512F"
2571   "vcmp<ssescalarmodesuffix>\t{%3, <round_saeonly_op4>%2, %1, %0|%0, %1, %2<round_saeonly_op4>, %3}"
2572   [(set_attr "type" "ssecmp")
2573    (set_attr "length_immediate" "1")
2574    (set_attr "prefix" "evex")
2575    (set_attr "mode" "<ssescalarmode>")])
2576
2577 (define_insn "avx512f_vmcmp<mode>3_mask<round_saeonly_name>"
2578   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
2579         (and:<avx512fmaskmode>
2580           (unspec:<avx512fmaskmode>
2581             [(match_operand:VF_128 1 "register_operand" "v")
2582              (match_operand:VF_128 2 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
2583              (match_operand:SI 3 "const_0_to_31_operand" "n")]
2584             UNSPEC_PCMP)
2585           (and:<avx512fmaskmode>
2586             (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")
2587             (const_int 1))))]
2588   "TARGET_AVX512F"
2589   "vcmp<ssescalarmodesuffix>\t{%3, <round_saeonly_op5>%2, %1, %0%{%4%}|%0%{%4%}, %1, %2<round_saeonly_op5>, %3}"
2590   [(set_attr "type" "ssecmp")
2591    (set_attr "length_immediate" "1")
2592    (set_attr "prefix" "evex")
2593    (set_attr "mode" "<ssescalarmode>")])
2594
2595 (define_insn "avx512f_maskcmp<mode>3"
2596   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
2597         (match_operator:<avx512fmaskmode> 3 "sse_comparison_operator"
2598           [(match_operand:VF 1 "register_operand" "v")
2599            (match_operand:VF 2 "nonimmediate_operand" "vm")]))]
2600   "TARGET_SSE"
2601   "vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2602   [(set_attr "type" "ssecmp")
2603    (set_attr "length_immediate" "1")
2604    (set_attr "prefix" "evex")
2605    (set_attr "mode" "<sseinsnmode>")])
2606
2607 (define_insn "<sse>_comi<round_saeonly_name>"
2608   [(set (reg:CCFP FLAGS_REG)
2609         (compare:CCFP
2610           (vec_select:MODEF
2611             (match_operand:<ssevecmode> 0 "register_operand" "v")
2612             (parallel [(const_int 0)]))
2613           (vec_select:MODEF
2614             (match_operand:<ssevecmode> 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
2615             (parallel [(const_int 0)]))))]
2616   "SSE_FLOAT_MODE_P (<MODE>mode)"
2617   "%vcomi<ssemodesuffix>\t{<round_saeonly_op2>%1, %0|%0, %<iptr>1<round_saeonly_op2>}"
2618   [(set_attr "type" "ssecomi")
2619    (set_attr "prefix" "maybe_vex")
2620    (set_attr "prefix_rep" "0")
2621    (set (attr "prefix_data16")
2622         (if_then_else (eq_attr "mode" "DF")
2623                       (const_string "1")
2624                       (const_string "0")))
2625    (set_attr "mode" "<MODE>")])
2626
2627 (define_insn "<sse>_ucomi<round_saeonly_name>"
2628   [(set (reg:CCFPU FLAGS_REG)
2629         (compare:CCFPU
2630           (vec_select:MODEF
2631             (match_operand:<ssevecmode> 0 "register_operand" "v")
2632             (parallel [(const_int 0)]))
2633           (vec_select:MODEF
2634             (match_operand:<ssevecmode> 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
2635             (parallel [(const_int 0)]))))]
2636   "SSE_FLOAT_MODE_P (<MODE>mode)"
2637   "%vucomi<ssemodesuffix>\t{<round_saeonly_op2>%1, %0|%0, %<iptr>1<round_saeonly_op2>}"
2638   [(set_attr "type" "ssecomi")
2639    (set_attr "prefix" "maybe_vex")
2640    (set_attr "prefix_rep" "0")
2641    (set (attr "prefix_data16")
2642         (if_then_else (eq_attr "mode" "DF")
2643                       (const_string "1")
2644                       (const_string "0")))
2645    (set_attr "mode" "<MODE>")])
2646
2647 (define_expand "vcond<V_512:mode><VF_512:mode>"
2648   [(set (match_operand:V_512 0 "register_operand")
2649         (if_then_else:V_512
2650           (match_operator 3 ""
2651             [(match_operand:VF_512 4 "nonimmediate_operand")
2652              (match_operand:VF_512 5 "nonimmediate_operand")])
2653           (match_operand:V_512 1 "general_operand")
2654           (match_operand:V_512 2 "general_operand")))]
2655   "TARGET_AVX512F
2656    && (GET_MODE_NUNITS (<V_512:MODE>mode)
2657        == GET_MODE_NUNITS (<VF_512:MODE>mode))"
2658 {
2659   bool ok = ix86_expand_fp_vcond (operands);
2660   gcc_assert (ok);
2661   DONE;
2662 })
2663
2664 (define_expand "vcond<V_256:mode><VF_256:mode>"
2665   [(set (match_operand:V_256 0 "register_operand")
2666         (if_then_else:V_256
2667           (match_operator 3 ""
2668             [(match_operand:VF_256 4 "nonimmediate_operand")
2669              (match_operand:VF_256 5 "nonimmediate_operand")])
2670           (match_operand:V_256 1 "general_operand")
2671           (match_operand:V_256 2 "general_operand")))]
2672   "TARGET_AVX
2673    && (GET_MODE_NUNITS (<V_256:MODE>mode)
2674        == GET_MODE_NUNITS (<VF_256:MODE>mode))"
2675 {
2676   bool ok = ix86_expand_fp_vcond (operands);
2677   gcc_assert (ok);
2678   DONE;
2679 })
2680
2681 (define_expand "vcond<V_128:mode><VF_128:mode>"
2682   [(set (match_operand:V_128 0 "register_operand")
2683         (if_then_else:V_128
2684           (match_operator 3 ""
2685             [(match_operand:VF_128 4 "nonimmediate_operand")
2686              (match_operand:VF_128 5 "nonimmediate_operand")])
2687           (match_operand:V_128 1 "general_operand")
2688           (match_operand:V_128 2 "general_operand")))]
2689   "TARGET_SSE
2690    && (GET_MODE_NUNITS (<V_128:MODE>mode)
2691        == GET_MODE_NUNITS (<VF_128:MODE>mode))"
2692 {
2693   bool ok = ix86_expand_fp_vcond (operands);
2694   gcc_assert (ok);
2695   DONE;
2696 })
2697
2698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2699 ;;
2700 ;; Parallel floating point logical operations
2701 ;;
2702 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2703
2704 (define_insn "<sse>_andnot<mode>3<mask_name>"
2705   [(set (match_operand:VF_128_256 0 "register_operand" "=x,v")
2706         (and:VF_128_256
2707           (not:VF_128_256
2708             (match_operand:VF_128_256 1 "register_operand" "0,v"))
2709           (match_operand:VF_128_256 2 "nonimmediate_operand" "xm,vm")))]
2710   "TARGET_SSE && <mask_avx512vl_condition>"
2711 {
2712   static char buf[128];
2713   const char *ops;
2714   const char *suffix;
2715
2716   switch (get_attr_mode (insn))
2717     {
2718     case MODE_V8SF:
2719     case MODE_V4SF:
2720       suffix = "ps";
2721       break;
2722     default:
2723       suffix = "<ssemodesuffix>";
2724     }
2725
2726   switch (which_alternative)
2727     {
2728     case 0:
2729       ops = "andn%s\t{%%2, %%0|%%0, %%2}";
2730       break;
2731     case 1:
2732       ops = "vandn%s\t{%%2, %%1, %%0<mask_operand3_1>|%%0<mask_operand3_1>, %%1, %%2}";
2733       break;
2734     default:
2735       gcc_unreachable ();
2736     }
2737
2738   /* There is no vandnp[sd] in avx512f.  Use vpandn[qd].  */
2739   if (<mask_applied> && !TARGET_AVX512DQ)
2740     {
2741       suffix = GET_MODE_INNER (<MODE>mode) == DFmode ? "q" : "d";
2742       ops = "vpandn%s\t{%%2, %%1, %%0<mask_operand3_1>|%%0<mask_operand3_1>, %%1, %%2}";
2743     }
2744
2745   snprintf (buf, sizeof (buf), ops, suffix);
2746   return buf;
2747 }
2748   [(set_attr "isa" "noavx,avx")
2749    (set_attr "type" "sselog")
2750    (set_attr "prefix" "orig,maybe_evex")
2751    (set (attr "mode")
2752         (cond [(and (match_test "<MODE_SIZE> == 16")
2753                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
2754                  (const_string "<ssePSmode>")
2755                (match_test "TARGET_AVX")
2756                  (const_string "<MODE>")
2757                (match_test "optimize_function_for_size_p (cfun)")
2758                  (const_string "V4SF")
2759                ]
2760                (const_string "<MODE>")))])
2761
2762
2763 (define_insn "<sse>_andnot<mode>3<mask_name>"
2764   [(set (match_operand:VF_512 0 "register_operand" "=v")
2765         (and:VF_512
2766           (not:VF_512
2767             (match_operand:VF_512 1 "register_operand" "v"))
2768           (match_operand:VF_512 2 "nonimmediate_operand" "vm")))]
2769   "TARGET_AVX512F"
2770 {
2771   static char buf[128];
2772   const char *ops;
2773   const char *suffix;
2774
2775   suffix = "<ssemodesuffix>";
2776   ops = "";
2777
2778   /* There is no vandnp[sd] in avx512f.  Use vpandn[qd].  */
2779   if (!TARGET_AVX512DQ)
2780     {
2781       suffix = GET_MODE_INNER (<MODE>mode) == DFmode ? "q" : "d";
2782       ops = "p";
2783     }
2784
2785   snprintf (buf, sizeof (buf),
2786             "v%sandn%s\t{%%2, %%1, %%0<mask_operand3_1>|%%0<mask_operand3_1>, %%1, %%2}",
2787             ops, suffix);
2788   return buf;
2789 }
2790   [(set_attr "type" "sselog")
2791    (set_attr "prefix" "evex")
2792    (set_attr "mode" "<sseinsnmode>")])
2793
2794 (define_expand "<code><mode>3<mask_name>"
2795   [(set (match_operand:VF_128_256 0 "register_operand")
2796        (any_logic:VF_128_256
2797          (match_operand:VF_128_256 1 "nonimmediate_operand")
2798          (match_operand:VF_128_256 2 "nonimmediate_operand")))]
2799   "TARGET_SSE && <mask_avx512vl_condition>"
2800   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
2801
2802 (define_expand "<code><mode>3<mask_name>"
2803   [(set (match_operand:VF_512 0 "register_operand")
2804        (any_logic:VF_512
2805          (match_operand:VF_512 1 "nonimmediate_operand")
2806          (match_operand:VF_512 2 "nonimmediate_operand")))]
2807   "TARGET_AVX512F"
2808   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
2809
2810 (define_insn "*<code><mode>3<mask_name>"
2811   [(set (match_operand:VF_128_256 0 "register_operand" "=x,v")
2812         (any_logic:VF_128_256
2813           (match_operand:VF_128_256 1 "nonimmediate_operand" "%0,v")
2814           (match_operand:VF_128_256 2 "nonimmediate_operand" "xm,vm")))]
2815   "TARGET_SSE && <mask_avx512vl_condition>
2816    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
2817 {
2818   static char buf[128];
2819   const char *ops;
2820   const char *suffix;
2821
2822   switch (get_attr_mode (insn))
2823     {
2824     case MODE_V8SF:
2825     case MODE_V4SF:
2826       suffix = "ps";
2827       break;
2828     default:
2829       suffix = "<ssemodesuffix>";
2830     }
2831
2832   switch (which_alternative)
2833     {
2834     case 0:
2835       ops = "<logic>%s\t{%%2, %%0|%%0, %%2}";
2836       break;
2837     case 1:
2838       ops = "v<logic>%s\t{%%2, %%1, %%0<mask_operand3_1>|%%0<mask_operand3_1>, %%1, %%2}";
2839       break;
2840     default:
2841       gcc_unreachable ();
2842     }
2843
2844   /* There is no v<logic>p[sd] in avx512f.  Use vp<logic>[dq].  */
2845   if (<mask_applied> && !TARGET_AVX512DQ)
2846     {
2847       suffix = GET_MODE_INNER (<MODE>mode) == DFmode ? "q" : "d";
2848       ops = "vp<logic>%s\t{%%2, %%1, %%0<mask_operand3_1>|%%0<mask_operand3_1>, %%1, %%2}";
2849     }
2850
2851   snprintf (buf, sizeof (buf), ops, suffix);
2852   return buf;
2853 }
2854   [(set_attr "isa" "noavx,avx")
2855    (set_attr "type" "sselog")
2856    (set_attr "prefix" "orig,maybe_evex")
2857    (set (attr "mode")
2858         (cond [(and (match_test "<MODE_SIZE> == 16")
2859                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
2860                  (const_string "<ssePSmode>")
2861                (match_test "TARGET_AVX")
2862                  (const_string "<MODE>")
2863                (match_test "optimize_function_for_size_p (cfun)")
2864                  (const_string "V4SF")
2865                ]
2866                (const_string "<MODE>")))])
2867
2868 (define_insn "*<code><mode>3<mask_name>"
2869   [(set (match_operand:VF_512 0 "register_operand" "=v")
2870         (any_logic:VF_512
2871           (match_operand:VF_512 1 "nonimmediate_operand" "%v")
2872           (match_operand:VF_512 2 "nonimmediate_operand" "vm")))]
2873   "TARGET_AVX512F && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
2874 {
2875   static char buf[128];
2876   const char *ops;
2877   const char *suffix;
2878
2879   suffix = "<ssemodesuffix>";
2880   ops = "";
2881
2882   /* There is no v<logic>p[sd] in avx512f.  Use vp<logic>[dq].  */
2883   if ((<MODE_SIZE> == 64 || <mask_applied>) && !TARGET_AVX512DQ)
2884     {
2885       suffix = GET_MODE_INNER (<MODE>mode) == DFmode ? "q" : "d";
2886       ops = "p";
2887     }
2888
2889   snprintf (buf, sizeof (buf),
2890            "v%s<logic>%s\t{%%2, %%1, %%0<mask_operand3_1>|%%0<mask_operand3_1>, %%1, %%2}",
2891            ops, suffix);
2892   return buf;
2893 }
2894   [(set_attr "type" "sselog")
2895    (set_attr "prefix" "evex")
2896    (set_attr "mode" "<sseinsnmode>")])
2897
2898 (define_expand "copysign<mode>3"
2899   [(set (match_dup 4)
2900         (and:VF
2901           (not:VF (match_dup 3))
2902           (match_operand:VF 1 "nonimmediate_operand")))
2903    (set (match_dup 5)
2904         (and:VF (match_dup 3)
2905                 (match_operand:VF 2 "nonimmediate_operand")))
2906    (set (match_operand:VF 0 "register_operand")
2907         (ior:VF (match_dup 4) (match_dup 5)))]
2908   "TARGET_SSE"
2909 {
2910   operands[3] = ix86_build_signbit_mask (<MODE>mode, 1, 0);
2911
2912   operands[4] = gen_reg_rtx (<MODE>mode);
2913   operands[5] = gen_reg_rtx (<MODE>mode);
2914 })
2915
2916 ;; Also define scalar versions.  These are used for abs, neg, and
2917 ;; conditional move.  Using subregs into vector modes causes register
2918 ;; allocation lossage.  These patterns do not allow memory operands
2919 ;; because the native instructions read the full 128-bits.
2920
2921 (define_insn "*andnot<mode>3"
2922   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
2923         (and:MODEF
2924           (not:MODEF
2925             (match_operand:MODEF 1 "register_operand" "0,x"))
2926             (match_operand:MODEF 2 "register_operand" "x,x")))]
2927   "SSE_FLOAT_MODE_P (<MODE>mode)"
2928 {
2929   static char buf[32];
2930   const char *ops;
2931   const char *suffix
2932     = (get_attr_mode (insn) == MODE_V4SF) ? "ps" : "<ssevecmodesuffix>";
2933
2934   switch (which_alternative)
2935     {
2936     case 0:
2937       ops = "andn%s\t{%%2, %%0|%%0, %%2}";
2938       break;
2939     case 1:
2940       ops = "vandn%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
2941       break;
2942     default:
2943       gcc_unreachable ();
2944     }
2945
2946   snprintf (buf, sizeof (buf), ops, suffix);
2947   return buf;
2948 }
2949   [(set_attr "isa" "noavx,avx")
2950    (set_attr "type" "sselog")
2951    (set_attr "prefix" "orig,vex")
2952    (set (attr "mode")
2953         (cond [(and (match_test "<MODE_SIZE> == 16")
2954                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
2955                  (const_string "V4SF")
2956                (match_test "TARGET_AVX")
2957                  (const_string "<ssevecmode>")
2958                (match_test "optimize_function_for_size_p (cfun)")
2959                  (const_string "V4SF")
2960                ]
2961                (const_string "<ssevecmode>")))])
2962
2963 (define_insn "*andnottf3"
2964   [(set (match_operand:TF 0 "register_operand" "=x,x")
2965         (and:TF
2966           (not:TF (match_operand:TF 1 "register_operand" "0,x"))
2967           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
2968   "TARGET_SSE"
2969 {
2970   static char buf[32];
2971   const char *ops;
2972   const char *tmp
2973     = (get_attr_mode (insn) == MODE_V4SF) ? "andnps" : "pandn";
2974
2975   switch (which_alternative)
2976     {
2977     case 0:
2978       ops = "%s\t{%%2, %%0|%%0, %%2}";
2979       break;
2980     case 1:
2981       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
2982       break;
2983     default:
2984       gcc_unreachable ();
2985     }
2986
2987   snprintf (buf, sizeof (buf), ops, tmp);
2988   return buf;
2989 }
2990   [(set_attr "isa" "noavx,avx")
2991    (set_attr "type" "sselog")
2992    (set (attr "prefix_data16")
2993      (if_then_else
2994        (and (eq_attr "alternative" "0")
2995             (eq_attr "mode" "TI"))
2996        (const_string "1")
2997        (const_string "*")))
2998    (set_attr "prefix" "orig,vex")
2999    (set (attr "mode")
3000         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
3001                  (const_string "V4SF")
3002                (match_test "TARGET_AVX")
3003                  (const_string "TI")
3004                (ior (not (match_test "TARGET_SSE2"))
3005                     (match_test "optimize_function_for_size_p (cfun)"))
3006                  (const_string "V4SF")
3007                ]
3008                (const_string "TI")))])
3009
3010 (define_insn "*<code><mode>3"
3011   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
3012         (any_logic:MODEF
3013           (match_operand:MODEF 1 "register_operand" "%0,x")
3014           (match_operand:MODEF 2 "register_operand" "x,x")))]
3015   "SSE_FLOAT_MODE_P (<MODE>mode)"
3016 {
3017   static char buf[32];
3018   const char *ops;
3019   const char *suffix
3020     = (get_attr_mode (insn) == MODE_V4SF) ? "ps" : "<ssevecmodesuffix>";
3021
3022   switch (which_alternative)
3023     {
3024     case 0:
3025       ops = "<logic>%s\t{%%2, %%0|%%0, %%2}";
3026       break;
3027     case 1:
3028       ops = "v<logic>%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
3029       break;
3030     default:
3031       gcc_unreachable ();
3032     }
3033
3034   snprintf (buf, sizeof (buf), ops, suffix);
3035   return buf;
3036 }
3037   [(set_attr "isa" "noavx,avx")
3038    (set_attr "type" "sselog")
3039    (set_attr "prefix" "orig,vex")
3040    (set (attr "mode")
3041         (cond [(and (match_test "<MODE_SIZE> == 16")
3042                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
3043                  (const_string "V4SF")
3044                (match_test "TARGET_AVX")
3045                  (const_string "<ssevecmode>")
3046                (match_test "optimize_function_for_size_p (cfun)")
3047                  (const_string "V4SF")
3048                ]
3049                (const_string "<ssevecmode>")))])
3050
3051 (define_expand "<code>tf3"
3052   [(set (match_operand:TF 0 "register_operand")
3053         (any_logic:TF
3054           (match_operand:TF 1 "nonimmediate_operand")
3055           (match_operand:TF 2 "nonimmediate_operand")))]
3056   "TARGET_SSE"
3057   "ix86_fixup_binary_operands_no_copy (<CODE>, TFmode, operands);")
3058
3059 (define_insn "*<code>tf3"
3060   [(set (match_operand:TF 0 "register_operand" "=x,x")
3061         (any_logic:TF
3062           (match_operand:TF 1 "nonimmediate_operand" "%0,x")
3063           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
3064   "TARGET_SSE
3065    && ix86_binary_operator_ok (<CODE>, TFmode, operands)"
3066 {
3067   static char buf[32];
3068   const char *ops;
3069   const char *tmp
3070     = (get_attr_mode (insn) == MODE_V4SF) ? "<logic>ps" : "p<logic>";
3071
3072   switch (which_alternative)
3073     {
3074     case 0:
3075       ops = "%s\t{%%2, %%0|%%0, %%2}";
3076       break;
3077     case 1:
3078       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
3079       break;
3080     default:
3081       gcc_unreachable ();
3082     }
3083
3084   snprintf (buf, sizeof (buf), ops, tmp);
3085   return buf;
3086 }
3087   [(set_attr "isa" "noavx,avx")
3088    (set_attr "type" "sselog")
3089    (set (attr "prefix_data16")
3090      (if_then_else
3091        (and (eq_attr "alternative" "0")
3092             (eq_attr "mode" "TI"))
3093        (const_string "1")
3094        (const_string "*")))
3095    (set_attr "prefix" "orig,vex")
3096    (set (attr "mode")
3097         (cond [(match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL")
3098                  (const_string "V4SF")
3099                (match_test "TARGET_AVX")
3100                  (const_string "TI")
3101                (ior (not (match_test "TARGET_SSE2"))
3102                     (match_test "optimize_function_for_size_p (cfun)"))
3103                  (const_string "V4SF")
3104                ]
3105                (const_string "TI")))])
3106
3107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3108 ;;
3109 ;; FMA floating point multiply/accumulate instructions.  These include
3110 ;; scalar versions of the instructions as well as vector versions.
3111 ;;
3112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3113
3114 ;; The standard names for scalar FMA are only available with SSE math enabled.
3115 ;; CPUID bit AVX512F enables evex encoded scalar and 512-bit fma.  It doesn't
3116 ;; care about FMA bit, so we enable fma for TARGET_AVX512F even when TARGET_FMA
3117 ;; and TARGET_FMA4 are both false.
3118 ;; TODO: In theory AVX512F does not automatically imply FMA, and without FMA
3119 ;; one must force the EVEX encoding of the fma insns.  Ideally we'd improve
3120 ;; GAS to allow proper prefix selection.  However, for the moment all hardware
3121 ;; that supports AVX512F also supports FMA so we can ignore this for now.
3122 (define_mode_iterator FMAMODEM
3123   [(SF "TARGET_SSE_MATH && (TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F)")
3124    (DF "TARGET_SSE_MATH && (TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F)")
3125    (V4SF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512VL")
3126    (V2DF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512VL")
3127    (V8SF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512VL")
3128    (V4DF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512VL")
3129    (V16SF "TARGET_AVX512F")
3130    (V8DF "TARGET_AVX512F")])
3131
3132 (define_expand "fma<mode>4"
3133   [(set (match_operand:FMAMODEM 0 "register_operand")
3134         (fma:FMAMODEM
3135           (match_operand:FMAMODEM 1 "nonimmediate_operand")
3136           (match_operand:FMAMODEM 2 "nonimmediate_operand")
3137           (match_operand:FMAMODEM 3 "nonimmediate_operand")))])
3138
3139 (define_expand "fms<mode>4"
3140   [(set (match_operand:FMAMODEM 0 "register_operand")
3141         (fma:FMAMODEM
3142           (match_operand:FMAMODEM 1 "nonimmediate_operand")
3143           (match_operand:FMAMODEM 2 "nonimmediate_operand")
3144           (neg:FMAMODEM (match_operand:FMAMODEM 3 "nonimmediate_operand"))))])
3145
3146 (define_expand "fnma<mode>4"
3147   [(set (match_operand:FMAMODEM 0 "register_operand")
3148         (fma:FMAMODEM
3149           (neg:FMAMODEM (match_operand:FMAMODEM 1 "nonimmediate_operand"))
3150           (match_operand:FMAMODEM 2 "nonimmediate_operand")
3151           (match_operand:FMAMODEM 3 "nonimmediate_operand")))])
3152
3153 (define_expand "fnms<mode>4"
3154   [(set (match_operand:FMAMODEM 0 "register_operand")
3155         (fma:FMAMODEM
3156           (neg:FMAMODEM (match_operand:FMAMODEM 1 "nonimmediate_operand"))
3157           (match_operand:FMAMODEM 2 "nonimmediate_operand")
3158           (neg:FMAMODEM (match_operand:FMAMODEM 3 "nonimmediate_operand"))))])
3159
3160 ;; The builtins for intrinsics are not constrained by SSE math enabled.
3161 (define_mode_iterator FMAMODE_AVX512
3162  [(SF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F")
3163   (DF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F")
3164   (V4SF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512VL")
3165   (V2DF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512VL")
3166   (V8SF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512VL")
3167   (V4DF "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512VL")
3168   (V16SF "TARGET_AVX512F")
3169   (V8DF "TARGET_AVX512F")])
3170
3171 (define_mode_iterator FMAMODE
3172   [SF DF V4SF V2DF V8SF V4DF])
3173
3174 (define_expand "fma4i_fmadd_<mode>"
3175   [(set (match_operand:FMAMODE_AVX512 0 "register_operand")
3176         (fma:FMAMODE_AVX512
3177           (match_operand:FMAMODE_AVX512 1 "nonimmediate_operand")
3178           (match_operand:FMAMODE_AVX512 2 "nonimmediate_operand")
3179           (match_operand:FMAMODE_AVX512 3 "nonimmediate_operand")))])
3180
3181 (define_expand "<avx512>_fmadd_<mode>_maskz<round_expand_name>"
3182   [(match_operand:VF_AVX512VL 0 "register_operand")
3183    (match_operand:VF_AVX512VL 1 "<round_expand_nimm_predicate>")
3184    (match_operand:VF_AVX512VL 2 "<round_expand_nimm_predicate>")
3185    (match_operand:VF_AVX512VL 3 "<round_expand_nimm_predicate>")
3186    (match_operand:<avx512fmaskmode> 4 "register_operand")]
3187   "TARGET_AVX512F && <round_mode512bit_condition>"
3188 {
3189   emit_insn (gen_fma_fmadd_<mode>_maskz_1<round_expand_name> (
3190     operands[0], operands[1], operands[2], operands[3],
3191     CONST0_RTX (<MODE>mode), operands[4]<round_expand_operand>));
3192   DONE;
3193 })
3194
3195 (define_insn "*fma_fmadd_<mode>"
3196   [(set (match_operand:FMAMODE 0 "register_operand" "=v,v,v,x,x")
3197         (fma:FMAMODE
3198           (match_operand:FMAMODE 1 "nonimmediate_operand" "%0,0,v,x,x")
3199           (match_operand:FMAMODE 2 "nonimmediate_operand" "vm,v,vm,x,m")
3200           (match_operand:FMAMODE 3 "nonimmediate_operand" "v,vm,0,xm,x")))]
3201   "TARGET_FMA || TARGET_FMA4"
3202   "@
3203    vfmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
3204    vfmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
3205    vfmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
3206    vfmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
3207    vfmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
3208   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
3209    (set_attr "type" "ssemuladd")
3210    (set_attr "mode" "<MODE>")])
3211
3212 ;; Suppose AVX-512F as baseline
3213 (define_mode_iterator VF_SF_AVX512VL
3214   [SF V16SF (V8SF "TARGET_AVX512VL") (V4SF "TARGET_AVX512VL")
3215    DF V8DF (V4DF "TARGET_AVX512VL") (V2DF "TARGET_AVX512VL")])
3216
3217 (define_insn "<sd_mask_codefor>fma_fmadd_<mode><sd_maskz_name><round_name>"
3218   [(set (match_operand:VF_SF_AVX512VL 0 "register_operand" "=v,v,v")
3219         (fma:VF_SF_AVX512VL
3220           (match_operand:VF_SF_AVX512VL 1 "<round_nimm_predicate>" "%0,0,v")
3221           (match_operand:VF_SF_AVX512VL 2 "<round_nimm_predicate>" "<round_constraint>,v,<round_constraint>")
3222           (match_operand:VF_SF_AVX512VL 3 "<round_nimm_predicate>" "v,<round_constraint>,0")))]
3223   "TARGET_AVX512F && <sd_mask_mode512bit_condition> && <round_mode512bit_condition>"
3224   "@
3225    vfmadd132<ssemodesuffix>\t{<round_sd_mask_op4>%2, %3, %0<sd_mask_op4>|%0<sd_mask_op4>, %3, %2<round_sd_mask_op4>}
3226    vfmadd213<ssemodesuffix>\t{<round_sd_mask_op4>%3, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %3<round_sd_mask_op4>}
3227    vfmadd231<ssemodesuffix>\t{<round_sd_mask_op4>%2, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %2<round_sd_mask_op4>}"
3228   [(set_attr "type" "ssemuladd")
3229    (set_attr "mode" "<MODE>")])
3230
3231 (define_insn "<avx512>_fmadd_<mode>_mask<round_name>"
3232   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v,v")
3233         (vec_merge:VF_AVX512VL
3234           (fma:VF_AVX512VL
3235             (match_operand:VF_AVX512VL 1 "register_operand" "0,0")
3236             (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>,v")
3237             (match_operand:VF_AVX512VL 3 "nonimmediate_operand" "v,<round_constraint>"))
3238           (match_dup 1)
3239           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk,Yk")))]
3240   "TARGET_AVX512F && <round_mode512bit_condition>"
3241   "@
3242    vfmadd132<ssemodesuffix>\t{<round_op5>%2, %3, %0%{%4%}|%0%{%4%}, %3, %2<round_op5>}
3243    vfmadd213<ssemodesuffix>\t{<round_op5>%3, %2, %0%{%4%}|%0%{%4%}, %2, %3<round_op5>}"
3244   [(set_attr "isa" "fma_avx512f,fma_avx512f")
3245    (set_attr "type" "ssemuladd")
3246    (set_attr "mode" "<MODE>")])
3247
3248 (define_insn "<avx512>_fmadd_<mode>_mask3<round_name>"
3249   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=x")
3250         (vec_merge:VF_AVX512VL
3251           (fma:VF_AVX512VL
3252             (match_operand:VF_AVX512VL 1 "register_operand" "x")
3253             (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>")
3254             (match_operand:VF_AVX512VL 3 "register_operand" "0"))
3255           (match_dup 3)
3256           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
3257   "TARGET_AVX512F"
3258   "vfmadd231<ssemodesuffix>\t{<round_op5>%2, %1, %0%{%4%}|%0%{%4%}, %1, %2<round_op5>}"
3259   [(set_attr "isa" "fma_avx512f")
3260    (set_attr "type" "ssemuladd")
3261    (set_attr "mode" "<MODE>")])
3262
3263 (define_insn "*fma_fmsub_<mode>"
3264   [(set (match_operand:FMAMODE 0 "register_operand" "=v,v,v,x,x")
3265         (fma:FMAMODE
3266           (match_operand:FMAMODE   1 "nonimmediate_operand" "%0,0,v,x,x")
3267           (match_operand:FMAMODE   2 "nonimmediate_operand" "vm,v,vm,x,m")
3268           (neg:FMAMODE
3269             (match_operand:FMAMODE 3 "nonimmediate_operand" "v,vm,0,xm,x"))))]
3270   "TARGET_FMA || TARGET_FMA4"
3271   "@
3272    vfmsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
3273    vfmsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
3274    vfmsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
3275    vfmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
3276    vfmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
3277   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
3278    (set_attr "type" "ssemuladd")
3279    (set_attr "mode" "<MODE>")])
3280
3281 (define_insn "<sd_mask_codefor>fma_fmsub_<mode><sd_maskz_name><round_name>"
3282   [(set (match_operand:VF_SF_AVX512VL 0 "register_operand" "=v,v,v")
3283         (fma:VF_SF_AVX512VL
3284           (match_operand:VF_SF_AVX512VL   1 "<round_nimm_predicate>" "%0,0,v")
3285           (match_operand:VF_SF_AVX512VL   2 "<round_nimm_predicate>" "<round_constraint>,v,<round_constraint>")
3286           (neg:VF_SF_AVX512VL
3287             (match_operand:VF_SF_AVX512VL 3 "<round_nimm_predicate>" "v,<round_constraint>,0"))))]
3288   "TARGET_AVX512F && <sd_mask_mode512bit_condition> && <round_mode512bit_condition>"
3289   "@
3290    vfmsub132<ssemodesuffix>\t{<round_sd_mask_op4>%2, %3, %0<sd_mask_op4>|%0<sd_mask_op4>, %3, %2<round_sd_mask_op4>}
3291    vfmsub213<ssemodesuffix>\t{<round_sd_mask_op4>%3, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %3<round_sd_mask_op4>}
3292    vfmsub231<ssemodesuffix>\t{<round_sd_mask_op4>%2, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %2<round_sd_mask_op4>}"
3293   [(set_attr "type" "ssemuladd")
3294    (set_attr "mode" "<MODE>")])
3295
3296 (define_insn "<avx512>_fmsub_<mode>_mask<round_name>"
3297   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v,v")
3298         (vec_merge:VF_AVX512VL
3299           (fma:VF_AVX512VL
3300             (match_operand:VF_AVX512VL 1 "register_operand" "0,0")
3301             (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>,v")
3302             (neg:VF_AVX512VL
3303               (match_operand:VF_AVX512VL 3 "nonimmediate_operand" "v,<round_constraint>")))
3304           (match_dup 1)
3305           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk,Yk")))]
3306   "TARGET_AVX512F"
3307   "@
3308    vfmsub132<ssemodesuffix>\t{<round_op5>%2, %3, %0%{%4%}|%0%{%4%}, %3, %2<round_op5>}
3309    vfmsub213<ssemodesuffix>\t{<round_op5>%3, %2, %0%{%4%}|%0%{%4%}, %2, %3<round_op5>}"
3310   [(set_attr "isa" "fma_avx512f,fma_avx512f")
3311    (set_attr "type" "ssemuladd")
3312    (set_attr "mode" "<MODE>")])
3313
3314 (define_insn "<avx512>_fmsub_<mode>_mask3<round_name>"
3315   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
3316         (vec_merge:VF_AVX512VL
3317           (fma:VF_AVX512VL
3318             (match_operand:VF_AVX512VL 1 "register_operand" "v")
3319             (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>")
3320             (neg:VF_AVX512VL
3321               (match_operand:VF_AVX512VL 3 "register_operand" "0")))
3322           (match_dup 3)
3323           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
3324   "TARGET_AVX512F && <round_mode512bit_condition>"
3325   "vfmsub231<ssemodesuffix>\t{<round_op5>%2, %1, %0%{%4%}|%0%{%4%}, %1, %2<round_op5>}"
3326   [(set_attr "isa" "fma_avx512f")
3327    (set_attr "type" "ssemuladd")
3328    (set_attr "mode" "<MODE>")])
3329
3330 (define_insn "*fma_fnmadd_<mode>"
3331   [(set (match_operand:FMAMODE 0 "register_operand" "=v,v,v,x,x")
3332         (fma:FMAMODE
3333           (neg:FMAMODE
3334             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0,0,v,x,x"))
3335           (match_operand:FMAMODE   2 "nonimmediate_operand" "vm,v,vm,x,m")
3336           (match_operand:FMAMODE   3 "nonimmediate_operand" "v,vm,0,xm,x")))]
3337   "TARGET_FMA || TARGET_FMA4"
3338   "@
3339    vfnmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
3340    vfnmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
3341    vfnmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
3342    vfnmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
3343    vfnmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
3344   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
3345    (set_attr "type" "ssemuladd")
3346    (set_attr "mode" "<MODE>")])
3347
3348 (define_insn "<sd_mask_codefor>fma_fnmadd_<mode><sd_maskz_name><round_name>"
3349   [(set (match_operand:VF_SF_AVX512VL 0 "register_operand" "=v,v,v")
3350         (fma:VF_SF_AVX512VL
3351           (neg:VF_SF_AVX512VL
3352             (match_operand:VF_SF_AVX512VL 1 "<round_nimm_predicate>" "%0,0,v"))
3353           (match_operand:VF_SF_AVX512VL   2 "<round_nimm_predicate>" "<round_constraint>,v,<round_constraint>")
3354           (match_operand:VF_SF_AVX512VL   3 "<round_nimm_predicate>" "v,<round_constraint>,0")))]
3355   "TARGET_AVX512F && <sd_mask_mode512bit_condition> && <round_mode512bit_condition>"
3356   "@
3357    vfnmadd132<ssemodesuffix>\t{<round_sd_mask_op4>%2, %3, %0<sd_mask_op4>|%0<sd_mask_op4>, %3, %2<round_sd_mask_op4>}
3358    vfnmadd213<ssemodesuffix>\t{<round_sd_mask_op4>%3, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %3<round_sd_mask_op4>}
3359    vfnmadd231<ssemodesuffix>\t{<round_sd_mask_op4>%2, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %2<round_sd_mask_op4>}"
3360   [(set_attr "type" "ssemuladd")
3361    (set_attr "mode" "<MODE>")])
3362
3363 (define_insn "<avx512>_fnmadd_<mode>_mask<round_name>"
3364   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v,v")
3365         (vec_merge:VF_AVX512VL
3366           (fma:VF_AVX512VL
3367             (neg:VF_AVX512VL
3368               (match_operand:VF_AVX512VL 1 "register_operand" "0,0"))
3369             (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>,v")
3370             (match_operand:VF_AVX512VL 3 "nonimmediate_operand" "v,<round_constraint>"))
3371           (match_dup 1)
3372           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk,Yk")))]
3373   "TARGET_AVX512F && <round_mode512bit_condition>"
3374   "@
3375    vfnmadd132<ssemodesuffix>\t{<round_op5>%2, %3, %0%{%4%}|%0%{%4%}, %3, %2<round_op5>}
3376    vfnmadd213<ssemodesuffix>\t{<round_op5>%3, %2, %0%{%4%}|%0%{%4%}, %2, %3<round_op5>}"
3377   [(set_attr "isa" "fma_avx512f,fma_avx512f")
3378    (set_attr "type" "ssemuladd")
3379    (set_attr "mode" "<MODE>")])
3380
3381 (define_insn "<avx512>_fnmadd_<mode>_mask3<round_name>"
3382   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
3383         (vec_merge:VF_AVX512VL
3384           (fma:VF_AVX512VL
3385             (neg:VF_AVX512VL
3386               (match_operand:VF_AVX512VL 1 "register_operand" "v"))
3387             (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>")
3388             (match_operand:VF_AVX512VL 3 "register_operand" "0"))
3389           (match_dup 3)
3390           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
3391   "TARGET_AVX512F && <round_mode512bit_condition>"
3392   "vfnmadd231<ssemodesuffix>\t{<round_op5>%2, %1, %0%{%4%}|%0%{%4%}, %1, %2<round_op5>}"
3393   [(set_attr "isa" "fma_avx512f")
3394    (set_attr "type" "ssemuladd")
3395    (set_attr "mode" "<MODE>")])
3396
3397 (define_insn "*fma_fnmsub_<mode>"
3398   [(set (match_operand:FMAMODE 0 "register_operand" "=v,v,v,x,x")
3399         (fma:FMAMODE
3400           (neg:FMAMODE
3401             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0,0,v,x,x"))
3402           (match_operand:FMAMODE   2 "nonimmediate_operand" "vm,v,vm,x,m")
3403           (neg:FMAMODE
3404             (match_operand:FMAMODE 3 "nonimmediate_operand" "v,vm,0,xm,x"))))]
3405   "TARGET_FMA || TARGET_FMA4"
3406   "@
3407    vfnmsub132<ssemodesuffix>\t{<round_sd_mask_op4>%2, %3, %0<sd_mask_op4>|%0<sd_mask_op4>, %3, %2<round_sd_mask_op4>}
3408    vfnmsub213<ssemodesuffix>\t{<round_sd_mask_op4>%3, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %3<round_sd_mask_op4>}
3409    vfnmsub231<ssemodesuffix>\t{<round_sd_mask_op4>%2, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %2<round_sd_mask_op4>}
3410    vfnmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
3411    vfnmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
3412   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
3413    (set_attr "type" "ssemuladd")
3414    (set_attr "mode" "<MODE>")])
3415
3416 (define_insn "<sd_mask_codefor>fma_fnmsub_<mode><sd_maskz_name><round_name>"
3417   [(set (match_operand:VF_SF_AVX512VL 0 "register_operand" "=v,v,v")
3418         (fma:VF_SF_AVX512VL
3419           (neg:VF_SF_AVX512VL
3420             (match_operand:VF_SF_AVX512VL 1 "<round_nimm_predicate>" "%0,0,v"))
3421           (match_operand:VF_SF_AVX512VL 2 "<round_nimm_predicate>" "<round_constraint>,v,<round_constraint>")
3422           (neg:VF_SF_AVX512VL
3423             (match_operand:VF_SF_AVX512VL 3 "<round_nimm_predicate>" "v,<round_constraint>,0"))))]
3424   "TARGET_AVX512F && <sd_mask_mode512bit_condition> && <round_mode512bit_condition>"
3425   "@
3426    vfnmsub132<ssemodesuffix>\t{<round_sd_mask_op4>%2, %3, %0<sd_mask_op4>|%0<sd_mask_op4>, %3, %2<round_sd_mask_op4>}
3427    vfnmsub213<ssemodesuffix>\t{<round_sd_mask_op4>%3, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %3<round_sd_mask_op4>}
3428    vfnmsub231<ssemodesuffix>\t{<round_sd_mask_op4>%2, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %2<round_sd_mask_op4>}"
3429   [(set_attr "type" "ssemuladd")
3430    (set_attr "mode" "<MODE>")])
3431
3432 (define_insn "<avx512>_fnmsub_<mode>_mask<round_name>"
3433   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v,v")
3434         (vec_merge:VF_AVX512VL
3435           (fma:VF_AVX512VL
3436             (neg:VF_AVX512VL
3437               (match_operand:VF_AVX512VL 1 "register_operand" "0,0"))
3438             (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>,v")
3439             (neg:VF_AVX512VL
3440               (match_operand:VF_AVX512VL 3 "nonimmediate_operand" "v,<round_constraint>")))
3441           (match_dup 1)
3442           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk,Yk")))]
3443   "TARGET_AVX512F && <round_mode512bit_condition>"
3444   "@
3445    vfnmsub132<ssemodesuffix>\t{<round_op5>%2, %3, %0%{%4%}|%0%{%4%}, %3, %2<round_op5>}
3446    vfnmsub213<ssemodesuffix>\t{<round_op5>%3, %2, %0%{%4%}|%0%{%4%}, %2, %3<round_op5>}"
3447   [(set_attr "isa" "fma_avx512f,fma_avx512f")
3448    (set_attr "type" "ssemuladd")
3449    (set_attr "mode" "<MODE>")])
3450
3451 (define_insn "<avx512>_fnmsub_<mode>_mask3<round_name>"
3452   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
3453         (vec_merge:VF_AVX512VL
3454           (fma:VF_AVX512VL
3455             (neg:VF_AVX512VL
3456               (match_operand:VF_AVX512VL 1 "register_operand" "v"))
3457             (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>")
3458             (neg:VF_AVX512VL
3459               (match_operand:VF_AVX512VL 3 "register_operand" "0")))
3460           (match_dup 3)
3461           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
3462   "TARGET_AVX512F"
3463   "vfnmsub231<ssemodesuffix>\t{<round_op5>%2, %1, %0%{%4%}|%0%{%4%}, %1, %2<round_op5>}"
3464   [(set_attr "isa" "fma_avx512f")
3465    (set_attr "type" "ssemuladd")
3466    (set_attr "mode" "<MODE>")])
3467
3468 ;; FMA parallel floating point multiply addsub and subadd operations.
3469
3470 ;; It would be possible to represent these without the UNSPEC as
3471 ;;
3472 ;; (vec_merge
3473 ;;   (fma op1 op2 op3)
3474 ;;   (fma op1 op2 (neg op3))
3475 ;;   (merge-const))
3476 ;;
3477 ;; But this doesn't seem useful in practice.
3478
3479 (define_expand "fmaddsub_<mode>"
3480   [(set (match_operand:VF 0 "register_operand")
3481         (unspec:VF
3482           [(match_operand:VF 1 "nonimmediate_operand")
3483            (match_operand:VF 2 "nonimmediate_operand")
3484            (match_operand:VF 3 "nonimmediate_operand")]
3485           UNSPEC_FMADDSUB))]
3486   "TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F")
3487
3488 (define_expand "<avx512>_fmaddsub_<mode>_maskz<round_expand_name>"
3489   [(match_operand:VF_AVX512VL 0 "register_operand")
3490    (match_operand:VF_AVX512VL 1 "<round_expand_nimm_predicate>")
3491    (match_operand:VF_AVX512VL 2 "<round_expand_nimm_predicate>")
3492    (match_operand:VF_AVX512VL 3 "<round_expand_nimm_predicate>")
3493    (match_operand:<avx512fmaskmode> 4 "register_operand")]
3494   "TARGET_AVX512F"
3495 {
3496   emit_insn (gen_fma_fmaddsub_<mode>_maskz_1<round_expand_name> (
3497     operands[0], operands[1], operands[2], operands[3],
3498     CONST0_RTX (<MODE>mode), operands[4]<round_expand_operand>));
3499   DONE;
3500 })
3501
3502 (define_insn "*fma_fmaddsub_<mode>"
3503   [(set (match_operand:VF_128_256 0 "register_operand" "=v,v,v,x,x")
3504         (unspec:VF_128_256
3505           [(match_operand:VF_128_256 1 "nonimmediate_operand" "%0,0,v,x,x")
3506            (match_operand:VF_128_256 2 "nonimmediate_operand" "vm,v,vm,x,m")
3507            (match_operand:VF_128_256 3 "nonimmediate_operand" "v,vm,0,xm,x")]
3508           UNSPEC_FMADDSUB))]
3509   "TARGET_FMA || TARGET_FMA4"
3510   "@
3511    vfmaddsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
3512    vfmaddsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
3513    vfmaddsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
3514    vfmaddsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
3515    vfmaddsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
3516   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
3517    (set_attr "type" "ssemuladd")
3518    (set_attr "mode" "<MODE>")])
3519
3520 (define_insn "<sd_mask_codefor>fma_fmaddsub_<mode><sd_maskz_name><round_name>"
3521   [(set (match_operand:VF_SF_AVX512VL 0 "register_operand" "=v,v,v")
3522         (unspec:VF_SF_AVX512VL
3523           [(match_operand:VF_SF_AVX512VL 1 "<round_nimm_predicate>" "%0,0,v")
3524            (match_operand:VF_SF_AVX512VL 2 "<round_nimm_predicate>" "<round_constraint>,v,<round_constraint>")
3525            (match_operand:VF_SF_AVX512VL 3 "<round_nimm_predicate>" "v,<round_constraint>,0")]
3526           UNSPEC_FMADDSUB))]
3527   "TARGET_AVX512F && <sd_mask_mode512bit_condition> && <round_mode512bit_condition>"
3528   "@
3529    vfmaddsub132<ssemodesuffix>\t{<round_sd_mask_op4>%2, %3, %0<sd_mask_op4>|%0<sd_mask_op4>, %3, %2<round_sd_mask_op4>}
3530    vfmaddsub213<ssemodesuffix>\t{<round_sd_mask_op4>%3, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %3<round_sd_mask_op4>}
3531    vfmaddsub231<ssemodesuffix>\t{<round_sd_mask_op4>%2, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %2<round_sd_mask_op4>}"
3532   [(set_attr "type" "ssemuladd")
3533    (set_attr "mode" "<MODE>")])
3534
3535 (define_insn "<avx512>_fmaddsub_<mode>_mask<round_name>"
3536   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v,v")
3537         (vec_merge:VF_AVX512VL
3538           (unspec:VF_AVX512VL
3539             [(match_operand:VF_AVX512VL 1 "register_operand" "0,0")
3540              (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>,v")
3541              (match_operand:VF_AVX512VL 3 "nonimmediate_operand" "v,<round_constraint>")]
3542             UNSPEC_FMADDSUB)
3543           (match_dup 1)
3544           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk,Yk")))]
3545   "TARGET_AVX512F"
3546   "@
3547    vfmaddsub132<ssemodesuffix>\t{<round_op5>%2, %3, %0%{%4%}|%0%{%4%}, %3, %2<round_op5>}
3548    vfmaddsub213<ssemodesuffix>\t{<round_op5>%3, %2, %0%{%4%}|%0%{%4%}, %2, %3<round_op5>}"
3549   [(set_attr "isa" "fma_avx512f,fma_avx512f")
3550    (set_attr "type" "ssemuladd")
3551    (set_attr "mode" "<MODE>")])
3552
3553 (define_insn "<avx512>_fmaddsub_<mode>_mask3<round_name>"
3554   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
3555         (vec_merge:VF_AVX512VL
3556           (unspec:VF_AVX512VL
3557             [(match_operand:VF_AVX512VL 1 "register_operand" "v")
3558              (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>")
3559              (match_operand:VF_AVX512VL 3 "register_operand" "0")]
3560             UNSPEC_FMADDSUB)
3561           (match_dup 3)
3562           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
3563   "TARGET_AVX512F"
3564   "vfmaddsub231<ssemodesuffix>\t{<round_op5>%2, %1, %0%{%4%}|%0%{%4%}, %1, %2<round_op5>}"
3565   [(set_attr "isa" "fma_avx512f")
3566    (set_attr "type" "ssemuladd")
3567    (set_attr "mode" "<MODE>")])
3568
3569 (define_insn "*fma_fmsubadd_<mode>"
3570   [(set (match_operand:VF_128_256 0 "register_operand" "=v,v,v,x,x")
3571         (unspec:VF_128_256
3572           [(match_operand:VF_128_256   1 "nonimmediate_operand" "%0,0,v,x,x")
3573            (match_operand:VF_128_256   2 "nonimmediate_operand" "vm,v,vm,x,m")
3574            (neg:VF_128_256
3575              (match_operand:VF_128_256 3 "nonimmediate_operand" "v,vm,0,xm,x"))]
3576           UNSPEC_FMADDSUB))]
3577   "TARGET_FMA || TARGET_FMA4"
3578   "@
3579    vfmsubadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
3580    vfmsubadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
3581    vfmsubadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}
3582    vfmsubadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}
3583    vfmsubadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
3584   [(set_attr "isa" "fma,fma,fma,fma4,fma4")
3585    (set_attr "type" "ssemuladd")
3586    (set_attr "mode" "<MODE>")])
3587
3588 (define_insn "<sd_mask_codefor>fma_fmsubadd_<mode><sd_maskz_name><round_name>"
3589   [(set (match_operand:VF_SF_AVX512VL 0 "register_operand" "=v,v,v")
3590         (unspec:VF_SF_AVX512VL
3591           [(match_operand:VF_SF_AVX512VL   1 "<round_nimm_predicate>" "%0,0,v")
3592            (match_operand:VF_SF_AVX512VL   2 "<round_nimm_predicate>" "<round_constraint>,v,<round_constraint>")
3593            (neg:VF_SF_AVX512VL
3594              (match_operand:VF_SF_AVX512VL 3 "<round_nimm_predicate>" "v,<round_constraint>,0"))]
3595           UNSPEC_FMADDSUB))]
3596   "TARGET_AVX512F && <sd_mask_mode512bit_condition> && <round_mode512bit_condition>"
3597   "@
3598    vfmsubadd132<ssemodesuffix>\t{<round_sd_mask_op4>%2, %3, %0<sd_mask_op4>|%0<sd_mask_op4>, %3, %2<round_sd_mask_op4>}
3599    vfmsubadd213<ssemodesuffix>\t{<round_sd_mask_op4>%3, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %3<round_sd_mask_op4>}
3600    vfmsubadd231<ssemodesuffix>\t{<round_sd_mask_op4>%2, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %2<round_sd_mask_op4>}"
3601   [(set_attr "type" "ssemuladd")
3602    (set_attr "mode" "<MODE>")])
3603
3604 (define_insn "<avx512>_fmsubadd_<mode>_mask<round_name>"
3605   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v,v")
3606         (vec_merge:VF_AVX512VL
3607           (unspec:VF_AVX512VL
3608             [(match_operand:VF_AVX512VL 1 "register_operand" "0,0")
3609              (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>,v")
3610              (neg:VF_AVX512VL
3611                (match_operand:VF_AVX512VL 3 "nonimmediate_operand" "v,<round_constraint>"))]
3612             UNSPEC_FMADDSUB)
3613           (match_dup 1)
3614           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk,Yk")))]
3615   "TARGET_AVX512F"
3616   "@
3617    vfmsubadd132<ssemodesuffix>\t{<round_op5>%2, %3, %0%{%4%}|%0%{%4%}, %3, %2<round_op5>}
3618    vfmsubadd213<ssemodesuffix>\t{<round_op5>%3, %2, %0%{%4%}|%0%{%4%}, %2, %3<round_op5>}"
3619   [(set_attr "isa" "fma_avx512f,fma_avx512f")
3620    (set_attr "type" "ssemuladd")
3621    (set_attr "mode" "<MODE>")])
3622
3623 (define_insn "<avx512>_fmsubadd_<mode>_mask3<round_name>"
3624   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
3625         (vec_merge:VF_AVX512VL
3626           (unspec:VF_AVX512VL
3627             [(match_operand:VF_AVX512VL 1 "register_operand" "v")
3628              (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>")
3629              (neg:VF_AVX512VL
3630                (match_operand:VF_AVX512VL 3 "register_operand" "0"))]
3631             UNSPEC_FMADDSUB)
3632           (match_dup 3)
3633           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
3634   "TARGET_AVX512F"
3635   "vfmsubadd231<ssemodesuffix>\t{<round_op5>%2, %1, %0%{%4%}|%0%{%4%}, %1, %2<round_op5>}"
3636   [(set_attr "isa" "fma_avx512f")
3637    (set_attr "type" "ssemuladd")
3638    (set_attr "mode" "<MODE>")])
3639
3640 ;; FMA3 floating point scalar intrinsics. These merge result with
3641 ;; high-order elements from the destination register.
3642
3643 (define_expand "fmai_vmfmadd_<mode><round_name>"
3644   [(set (match_operand:VF_128 0 "register_operand")
3645         (vec_merge:VF_128
3646           (fma:VF_128
3647             (match_operand:VF_128 1 "<round_nimm_predicate>")
3648             (match_operand:VF_128 2 "<round_nimm_predicate>")
3649             (match_operand:VF_128 3 "<round_nimm_predicate>"))
3650           (match_dup 1)
3651           (const_int 1)))]
3652   "TARGET_FMA")
3653
3654 (define_insn "*fmai_fmadd_<mode>"
3655   [(set (match_operand:VF_128 0 "register_operand" "=v,v")
3656         (vec_merge:VF_128
3657           (fma:VF_128
3658             (match_operand:VF_128 1 "<round_nimm_predicate>" " 0, 0")
3659             (match_operand:VF_128 2 "<round_nimm_predicate>" "<round_constraint>, v")
3660             (match_operand:VF_128 3 "<round_nimm_predicate>" " v,<round_constraint>"))
3661           (match_dup 1)
3662           (const_int 1)))]
3663   "TARGET_FMA || TARGET_AVX512F"
3664   "@
3665    vfmadd132<ssescalarmodesuffix>\t{<round_op4>%2, %3, %0|%0, %<iptr>3, %<iptr>2<round_op4>}
3666    vfmadd213<ssescalarmodesuffix>\t{<round_op4>%3, %2, %0|%0, %<iptr>2, %<iptr>3<round_op4>}"
3667   [(set_attr "type" "ssemuladd")
3668    (set_attr "mode" "<MODE>")])
3669
3670 (define_insn "*fmai_fmsub_<mode>"
3671   [(set (match_operand:VF_128 0 "register_operand" "=v,v")
3672         (vec_merge:VF_128
3673           (fma:VF_128
3674             (match_operand:VF_128   1 "<round_nimm_predicate>" "0,0")
3675             (match_operand:VF_128   2 "<round_nimm_predicate>" "<round_constraint>,v")
3676             (neg:VF_128
3677               (match_operand:VF_128 3 "<round_nimm_predicate>" " v,<round_constraint>")))
3678           (match_dup 1)
3679           (const_int 1)))]
3680   "TARGET_FMA || TARGET_AVX512F"
3681   "@
3682    vfmsub132<ssescalarmodesuffix>\t{<round_op4>%2, %3, %0|%0, %<iptr>3, %<iptr>2<round_op4>}
3683    vfmsub213<ssescalarmodesuffix>\t{<round_op4>%3, %2, %0|%0, %<iptr>2, %<iptr>3<round_op4>}"
3684   [(set_attr "type" "ssemuladd")
3685    (set_attr "mode" "<MODE>")])
3686
3687 (define_insn "*fmai_fnmadd_<mode><round_name>"
3688   [(set (match_operand:VF_128 0 "register_operand" "=v,v")
3689         (vec_merge:VF_128
3690           (fma:VF_128
3691             (neg:VF_128
3692               (match_operand:VF_128 2 "<round_nimm_predicate>" "<round_constraint>,v"))
3693             (match_operand:VF_128   1 "<round_nimm_predicate>" "0,0")
3694             (match_operand:VF_128   3 "<round_nimm_predicate>" "v,<round_constraint>"))
3695           (match_dup 1)
3696           (const_int 1)))]
3697   "TARGET_FMA || TARGET_AVX512F"
3698   "@
3699    vfnmadd132<ssescalarmodesuffix>\t{<round_op4>%2, %3, %0|%0, %<iptr>3, %<iptr>2<round_op4>}
3700    vfnmadd213<ssescalarmodesuffix>\t{<round_op4>%3, %2, %0|%0, %<iptr>2, %<iptr>3<round_op4>}"
3701   [(set_attr "type" "ssemuladd")
3702    (set_attr "mode" "<MODE>")])
3703
3704 (define_insn "*fmai_fnmsub_<mode><round_name>"
3705   [(set (match_operand:VF_128 0 "register_operand" "=v,v")
3706         (vec_merge:VF_128
3707           (fma:VF_128
3708             (neg:VF_128
3709               (match_operand:VF_128 2 "<round_nimm_predicate>" "<round_constraint>, v"))
3710             (match_operand:VF_128   1 "<round_nimm_predicate>" " 0, 0")
3711             (neg:VF_128
3712               (match_operand:VF_128 3 "<round_nimm_predicate>" " v,<round_constraint>")))
3713           (match_dup 1)
3714           (const_int 1)))]
3715   "TARGET_FMA || TARGET_AVX512F"
3716   "@
3717    vfnmsub132<ssescalarmodesuffix>\t{<round_op4>%2, %3, %0|%0, %<iptr>3, %<iptr>2<round_op4>}
3718    vfnmsub213<ssescalarmodesuffix>\t{<round_op4>%3, %2, %0|%0, %<iptr>2, %<iptr>3<round_op4>}"
3719   [(set_attr "type" "ssemuladd")
3720    (set_attr "mode" "<MODE>")])
3721
3722 ;; FMA4 floating point scalar intrinsics.  These write the
3723 ;; entire destination register, with the high-order elements zeroed.
3724
3725 (define_expand "fma4i_vmfmadd_<mode>"
3726   [(set (match_operand:VF_128 0 "register_operand")
3727         (vec_merge:VF_128
3728           (fma:VF_128
3729             (match_operand:VF_128 1 "nonimmediate_operand")
3730             (match_operand:VF_128 2 "nonimmediate_operand")
3731             (match_operand:VF_128 3 "nonimmediate_operand"))
3732           (match_dup 4)
3733           (const_int 1)))]
3734   "TARGET_FMA4"
3735   "operands[4] = CONST0_RTX (<MODE>mode);")
3736
3737 (define_insn "*fma4i_vmfmadd_<mode>"
3738   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
3739         (vec_merge:VF_128
3740           (fma:VF_128
3741             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
3742             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
3743             (match_operand:VF_128 3 "nonimmediate_operand" "xm,x"))
3744           (match_operand:VF_128 4 "const0_operand")
3745           (const_int 1)))]
3746   "TARGET_FMA4"
3747   "vfmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %<iptr>2, %<iptr>3}"
3748   [(set_attr "type" "ssemuladd")
3749    (set_attr "mode" "<MODE>")])
3750
3751 (define_insn "*fma4i_vmfmsub_<mode>"
3752   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
3753         (vec_merge:VF_128
3754           (fma:VF_128
3755             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
3756             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
3757             (neg:VF_128
3758               (match_operand:VF_128 3 "nonimmediate_operand" "xm,x")))
3759           (match_operand:VF_128 4 "const0_operand")
3760           (const_int 1)))]
3761   "TARGET_FMA4"
3762   "vfmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %<iptr>2, %<iptr>3}"
3763   [(set_attr "type" "ssemuladd")
3764    (set_attr "mode" "<MODE>")])
3765
3766 (define_insn "*fma4i_vmfnmadd_<mode>"
3767   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
3768         (vec_merge:VF_128
3769           (fma:VF_128
3770             (neg:VF_128
3771               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
3772             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
3773             (match_operand:VF_128   3 "nonimmediate_operand" "xm,x"))
3774           (match_operand:VF_128 4 "const0_operand")
3775           (const_int 1)))]
3776   "TARGET_FMA4"
3777   "vfnmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %<iptr>2, %<iptr>3}"
3778   [(set_attr "type" "ssemuladd")
3779    (set_attr "mode" "<MODE>")])
3780
3781 (define_insn "*fma4i_vmfnmsub_<mode>"
3782   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
3783         (vec_merge:VF_128
3784           (fma:VF_128
3785             (neg:VF_128
3786               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
3787             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
3788             (neg:VF_128
3789               (match_operand:VF_128   3 "nonimmediate_operand" "xm,x")))
3790           (match_operand:VF_128 4 "const0_operand")
3791           (const_int 1)))]
3792   "TARGET_FMA4"
3793   "vfnmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %<iptr>2, %<iptr>3}"
3794   [(set_attr "type" "ssemuladd")
3795    (set_attr "mode" "<MODE>")])
3796
3797 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3798 ;;
3799 ;; Parallel single-precision floating point conversion operations
3800 ;;
3801 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3802
3803 (define_insn "sse_cvtpi2ps"
3804   [(set (match_operand:V4SF 0 "register_operand" "=x")
3805         (vec_merge:V4SF
3806           (vec_duplicate:V4SF
3807             (float:V2SF (match_operand:V2SI 2 "nonimmediate_operand" "ym")))
3808           (match_operand:V4SF 1 "register_operand" "0")
3809           (const_int 3)))]
3810   "TARGET_SSE"
3811   "cvtpi2ps\t{%2, %0|%0, %2}"
3812   [(set_attr "type" "ssecvt")
3813    (set_attr "mode" "V4SF")])
3814
3815 (define_insn "sse_cvtps2pi"
3816   [(set (match_operand:V2SI 0 "register_operand" "=y")
3817         (vec_select:V2SI
3818           (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
3819                        UNSPEC_FIX_NOTRUNC)
3820           (parallel [(const_int 0) (const_int 1)])))]
3821   "TARGET_SSE"
3822   "cvtps2pi\t{%1, %0|%0, %q1}"
3823   [(set_attr "type" "ssecvt")
3824    (set_attr "unit" "mmx")
3825    (set_attr "mode" "DI")])
3826
3827 (define_insn "sse_cvttps2pi"
3828   [(set (match_operand:V2SI 0 "register_operand" "=y")
3829         (vec_select:V2SI
3830           (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm"))
3831           (parallel [(const_int 0) (const_int 1)])))]
3832   "TARGET_SSE"
3833   "cvttps2pi\t{%1, %0|%0, %q1}"
3834   [(set_attr "type" "ssecvt")
3835    (set_attr "unit" "mmx")
3836    (set_attr "prefix_rep" "0")
3837    (set_attr "mode" "SF")])
3838
3839 (define_insn "sse_cvtsi2ss<round_name>"
3840   [(set (match_operand:V4SF 0 "register_operand" "=x,x,v")
3841         (vec_merge:V4SF
3842           (vec_duplicate:V4SF
3843             (float:SF (match_operand:SI 2 "<round_nimm_predicate>" "r,m,<round_constraint3>")))
3844           (match_operand:V4SF 1 "register_operand" "0,0,v")
3845           (const_int 1)))]
3846   "TARGET_SSE"
3847   "@
3848    cvtsi2ss\t{%2, %0|%0, %2}
3849    cvtsi2ss\t{%2, %0|%0, %2}
3850    vcvtsi2ss\t{<round_op3>%2, %1, %0|%0, %1, %2<round_op3>}"
3851   [(set_attr "isa" "noavx,noavx,avx")
3852    (set_attr "type" "sseicvt")
3853    (set_attr "athlon_decode" "vector,double,*")
3854    (set_attr "amdfam10_decode" "vector,double,*")
3855    (set_attr "bdver1_decode" "double,direct,*")
3856    (set_attr "btver2_decode" "double,double,double")
3857    (set_attr "prefix" "orig,orig,maybe_evex")
3858    (set_attr "mode" "SF")])
3859
3860 (define_insn "sse_cvtsi2ssq<round_name>"
3861   [(set (match_operand:V4SF 0 "register_operand" "=x,x,v")
3862         (vec_merge:V4SF
3863           (vec_duplicate:V4SF
3864             (float:SF (match_operand:DI 2 "<round_nimm_predicate>" "r,m,<round_constraint3>")))
3865           (match_operand:V4SF 1 "register_operand" "0,0,v")
3866           (const_int 1)))]
3867   "TARGET_SSE && TARGET_64BIT"
3868   "@
3869    cvtsi2ssq\t{%2, %0|%0, %2}
3870    cvtsi2ssq\t{%2, %0|%0, %2}
3871    vcvtsi2ssq\t{<round_op3>%2, %1, %0|%0, %1, %2<round_op3>}"
3872   [(set_attr "isa" "noavx,noavx,avx")
3873    (set_attr "type" "sseicvt")
3874    (set_attr "athlon_decode" "vector,double,*")
3875    (set_attr "amdfam10_decode" "vector,double,*")
3876    (set_attr "bdver1_decode" "double,direct,*")
3877    (set_attr "btver2_decode" "double,double,double")
3878    (set_attr "length_vex" "*,*,4")
3879    (set_attr "prefix_rex" "1,1,*")
3880    (set_attr "prefix" "orig,orig,maybe_evex")
3881    (set_attr "mode" "SF")])
3882
3883 (define_insn "sse_cvtss2si<round_name>"
3884   [(set (match_operand:SI 0 "register_operand" "=r,r")
3885         (unspec:SI
3886           [(vec_select:SF
3887              (match_operand:V4SF 1 "<round_nimm_predicate>" "v,<round_constraint2>")
3888              (parallel [(const_int 0)]))]
3889           UNSPEC_FIX_NOTRUNC))]
3890   "TARGET_SSE"
3891   "%vcvtss2si\t{<round_op2>%1, %0|%0, %k1<round_op2>}"
3892   [(set_attr "type" "sseicvt")
3893    (set_attr "athlon_decode" "double,vector")
3894    (set_attr "bdver1_decode" "double,double")
3895    (set_attr "prefix_rep" "1")
3896    (set_attr "prefix" "maybe_vex")
3897    (set_attr "mode" "SI")])
3898
3899 (define_insn "sse_cvtss2si_2"
3900   [(set (match_operand:SI 0 "register_operand" "=r,r")
3901         (unspec:SI [(match_operand:SF 1 "nonimmediate_operand" "v,m")]
3902                    UNSPEC_FIX_NOTRUNC))]
3903   "TARGET_SSE"
3904   "%vcvtss2si\t{%1, %0|%0, %k1}"
3905   [(set_attr "type" "sseicvt")
3906    (set_attr "athlon_decode" "double,vector")
3907    (set_attr "amdfam10_decode" "double,double")
3908    (set_attr "bdver1_decode" "double,double")
3909    (set_attr "prefix_rep" "1")
3910    (set_attr "prefix" "maybe_vex")
3911    (set_attr "mode" "SI")])
3912
3913 (define_insn "sse_cvtss2siq<round_name>"
3914   [(set (match_operand:DI 0 "register_operand" "=r,r")
3915         (unspec:DI
3916           [(vec_select:SF
3917              (match_operand:V4SF 1 "<round_nimm_predicate>" "v,<round_constraint2>")
3918              (parallel [(const_int 0)]))]
3919           UNSPEC_FIX_NOTRUNC))]
3920   "TARGET_SSE && TARGET_64BIT"
3921   "%vcvtss2si{q}\t{<round_op2>%1, %0|%0, %k1<round_op2>}"
3922   [(set_attr "type" "sseicvt")
3923    (set_attr "athlon_decode" "double,vector")
3924    (set_attr "bdver1_decode" "double,double")
3925    (set_attr "prefix_rep" "1")
3926    (set_attr "prefix" "maybe_vex")
3927    (set_attr "mode" "DI")])
3928
3929 (define_insn "sse_cvtss2siq_2"
3930   [(set (match_operand:DI 0 "register_operand" "=r,r")
3931         (unspec:DI [(match_operand:SF 1 "nonimmediate_operand" "v,m")]
3932                    UNSPEC_FIX_NOTRUNC))]
3933   "TARGET_SSE && TARGET_64BIT"
3934   "%vcvtss2si{q}\t{%1, %0|%0, %k1}"
3935   [(set_attr "type" "sseicvt")
3936    (set_attr "athlon_decode" "double,vector")
3937    (set_attr "amdfam10_decode" "double,double")
3938    (set_attr "bdver1_decode" "double,double")
3939    (set_attr "prefix_rep" "1")
3940    (set_attr "prefix" "maybe_vex")
3941    (set_attr "mode" "DI")])
3942
3943 (define_insn "sse_cvttss2si<round_saeonly_name>"
3944   [(set (match_operand:SI 0 "register_operand" "=r,r")
3945         (fix:SI
3946           (vec_select:SF
3947             (match_operand:V4SF 1 "<round_saeonly_nimm_predicate>" "v,<round_saeonly_constraint2>")
3948             (parallel [(const_int 0)]))))]
3949   "TARGET_SSE"
3950   "%vcvttss2si\t{<round_saeonly_op2>%1, %0|%0, %k1<round_saeonly_op2>}"
3951   [(set_attr "type" "sseicvt")
3952    (set_attr "athlon_decode" "double,vector")
3953    (set_attr "amdfam10_decode" "double,double")
3954    (set_attr "bdver1_decode" "double,double")
3955    (set_attr "prefix_rep" "1")
3956    (set_attr "prefix" "maybe_vex")
3957    (set_attr "mode" "SI")])
3958
3959 (define_insn "sse_cvttss2siq<round_saeonly_name>"
3960   [(set (match_operand:DI 0 "register_operand" "=r,r")
3961         (fix:DI
3962           (vec_select:SF
3963             (match_operand:V4SF 1 "<round_saeonly_nimm_predicate>" "v,<round_saeonly_constraint>")
3964             (parallel [(const_int 0)]))))]
3965   "TARGET_SSE && TARGET_64BIT"
3966   "%vcvttss2si{q}\t{<round_saeonly_op2>%1, %0|%0, %k1<round_saeonly_op2>}"
3967   [(set_attr "type" "sseicvt")
3968    (set_attr "athlon_decode" "double,vector")
3969    (set_attr "amdfam10_decode" "double,double")
3970    (set_attr "bdver1_decode" "double,double")
3971    (set_attr "prefix_rep" "1")
3972    (set_attr "prefix" "maybe_vex")
3973    (set_attr "mode" "DI")])
3974
3975 (define_insn "cvtusi2<ssescalarmodesuffix>32<round_name>"
3976   [(set (match_operand:VF_128 0 "register_operand" "=v")
3977         (vec_merge:VF_128
3978           (vec_duplicate:VF_128
3979             (unsigned_float:<ssescalarmode>
3980               (match_operand:SI 2 "<round_nimm_predicate>" "<round_constraint3>")))
3981           (match_operand:VF_128 1 "register_operand" "v")
3982           (const_int 1)))]
3983   "TARGET_AVX512F && <round_modev4sf_condition>"
3984   "vcvtusi2<ssescalarmodesuffix>\t{<round_op3>%2, %1, %0|%0, %1, %2<round_op3>}"
3985   [(set_attr "type" "sseicvt")
3986    (set_attr "prefix" "evex")
3987    (set_attr "mode" "<ssescalarmode>")])
3988
3989 (define_insn "cvtusi2<ssescalarmodesuffix>64<round_name>"
3990   [(set (match_operand:VF_128 0 "register_operand" "=v")
3991         (vec_merge:VF_128
3992           (vec_duplicate:VF_128
3993             (unsigned_float:<ssescalarmode>
3994               (match_operand:DI 2 "<round_nimm_predicate>" "<round_constraint3>")))
3995           (match_operand:VF_128 1 "register_operand" "v")
3996           (const_int 1)))]
3997   "TARGET_AVX512F && TARGET_64BIT"
3998   "vcvtusi2<ssescalarmodesuffix>\t{<round_op3>%2, %1, %0|%0, %1, %2<round_op3>}"
3999   [(set_attr "type" "sseicvt")
4000    (set_attr "prefix" "evex")
4001    (set_attr "mode" "<ssescalarmode>")])
4002
4003 (define_insn "float<sseintvecmodelower><mode>2<mask_name><round_name>"
4004   [(set (match_operand:VF1 0 "register_operand" "=v")
4005         (float:VF1
4006           (match_operand:<sseintvecmode> 1 "<round_nimm_predicate>" "<round_constraint>")))]
4007   "TARGET_SSE2 && <mask_mode512bit_condition> && <round_mode512bit_condition>"
4008   "%vcvtdq2ps\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4009   [(set_attr "type" "ssecvt")
4010    (set_attr "prefix" "maybe_vex")
4011    (set_attr "mode" "<sseinsnmode>")])
4012
4013 (define_insn "ufloat<sseintvecmodelower><mode>2<mask_name><round_name>"
4014   [(set (match_operand:VF1_AVX512VL 0 "register_operand" "=v")
4015         (unsigned_float:VF1_AVX512VL
4016           (match_operand:<sseintvecmode> 1 "nonimmediate_operand" "<round_constraint>")))]
4017   "TARGET_AVX512F"
4018   "vcvtudq2ps\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4019   [(set_attr "type" "ssecvt")
4020    (set_attr "prefix" "evex")
4021    (set_attr "mode" "<MODE>")])
4022
4023 (define_expand "floatuns<sseintvecmodelower><mode>2"
4024   [(match_operand:VF1 0 "register_operand")
4025    (match_operand:<sseintvecmode> 1 "register_operand")]
4026   "TARGET_SSE2 && (<MODE>mode == V4SFmode || TARGET_AVX2)"
4027 {
4028   if (<MODE>mode == V16SFmode)
4029     emit_insn (gen_ufloatv16siv16sf2 (operands[0], operands[1]));
4030   else
4031     if (TARGET_AVX512VL)
4032       {
4033         if (<MODE>mode == V4SFmode)
4034           emit_insn (gen_ufloatv4siv4sf2 (operands[0], operands[1]));
4035         else
4036           emit_insn (gen_ufloatv8siv8sf2 (operands[0], operands[1]));
4037       }
4038   else
4039     ix86_expand_vector_convert_uns_vsivsf (operands[0], operands[1]);
4040
4041   DONE;
4042 })
4043
4044
4045 ;; For <sse2_avx_avx512f>_fix_notrunc<sf2simodelower><mode> insn pattern
4046 (define_mode_attr sf2simodelower
4047   [(V16SI "v16sf") (V8SI "v8sf") (V4SI "v4sf")])
4048
4049 (define_insn "<sse2_avx_avx512f>_fix_notrunc<sf2simodelower><mode><mask_name>"
4050   [(set (match_operand:VI4_AVX 0 "register_operand" "=v")
4051         (unspec:VI4_AVX
4052           [(match_operand:<ssePSmode> 1 "nonimmediate_operand" "vm")]
4053           UNSPEC_FIX_NOTRUNC))]
4054   "TARGET_SSE2 && <mask_mode512bit_condition>"
4055   "%vcvtps2dq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4056   [(set_attr "type" "ssecvt")
4057    (set (attr "prefix_data16")
4058      (if_then_else
4059        (match_test "TARGET_AVX")
4060      (const_string "*")
4061      (const_string "1")))
4062    (set_attr "prefix" "maybe_vex")
4063    (set_attr "mode" "<sseinsnmode>")])
4064
4065 (define_insn "<mask_codefor>avx512f_fix_notruncv16sfv16si<mask_name><round_name>"
4066   [(set (match_operand:V16SI 0 "register_operand" "=v")
4067         (unspec:V16SI
4068           [(match_operand:V16SF 1 "<round_nimm_predicate>" "<round_constraint>")]
4069           UNSPEC_FIX_NOTRUNC))]
4070   "TARGET_AVX512F"
4071   "vcvtps2dq\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4072   [(set_attr "type" "ssecvt")
4073    (set_attr "prefix" "evex")
4074    (set_attr "mode" "XI")])
4075
4076 (define_insn "<mask_codefor><avx512>_ufix_notrunc<sf2simodelower><mode><mask_name><round_name>"
4077   [(set (match_operand:VI4_AVX512VL 0 "register_operand" "=v")
4078         (unspec:VI4_AVX512VL
4079           [(match_operand:<ssePSmode> 1 "nonimmediate_operand" "<round_constraint>")]
4080           UNSPEC_UNSIGNED_FIX_NOTRUNC))]
4081   "TARGET_AVX512F"
4082   "vcvtps2udq\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4083   [(set_attr "type" "ssecvt")
4084    (set_attr "prefix" "evex")
4085    (set_attr "mode" "<sseinsnmode>")])
4086
4087 (define_insn "<mask_codefor>avx512dq_cvtps2qq<mode><mask_name><round_name>"
4088   [(set (match_operand:VI8_256_512 0 "register_operand" "=v")
4089         (unspec:VI8_256_512 [(match_operand:<ssePSmode2> 1 "nonimmediate_operand" "<round_constraint>")]
4090                      UNSPEC_FIX_NOTRUNC))]
4091   "TARGET_AVX512DQ && <round_mode512bit_condition>"
4092   "vcvtps2qq\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4093   [(set_attr "type" "ssecvt")
4094    (set_attr "prefix" "evex")
4095    (set_attr "mode" "<sseinsnmode>")])
4096
4097 (define_insn "<mask_codefor>avx512dq_cvtps2qqv2di<mask_name>"
4098   [(set (match_operand:V2DI 0 "register_operand" "=v")
4099         (unspec:V2DI
4100           [(vec_select:V2SF
4101              (match_operand:V4SF 1 "nonimmediate_operand" "vm")
4102              (parallel [(const_int 0) (const_int 1)]))]
4103           UNSPEC_FIX_NOTRUNC))]
4104   "TARGET_AVX512DQ && TARGET_AVX512VL"
4105   "vcvtps2qq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4106   [(set_attr "type" "ssecvt")
4107    (set_attr "prefix" "evex")
4108    (set_attr "mode" "TI")])
4109
4110 (define_insn "<mask_codefor>avx512dq_cvtps2uqq<mode><mask_name><round_name>"
4111   [(set (match_operand:VI8_256_512 0 "register_operand" "=v")
4112         (unspec:VI8_256_512 [(match_operand:<ssePSmode2> 1 "nonimmediate_operand" "<round_constraint>")]
4113                      UNSPEC_UNSIGNED_FIX_NOTRUNC))]
4114   "TARGET_AVX512DQ && <round_mode512bit_condition>"
4115   "vcvtps2uqq\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4116   [(set_attr "type" "ssecvt")
4117    (set_attr "prefix" "evex")
4118    (set_attr "mode" "<sseinsnmode>")])
4119
4120 (define_insn "<mask_codefor>avx512dq_cvtps2uqqv2di<mask_name>"
4121   [(set (match_operand:V2DI 0 "register_operand" "=v")
4122         (unspec:V2DI
4123           [(vec_select:V2SF
4124              (match_operand:V4SF 1 "nonimmediate_operand" "vm")
4125              (parallel [(const_int 0) (const_int 1)]))]
4126           UNSPEC_UNSIGNED_FIX_NOTRUNC))]
4127   "TARGET_AVX512DQ && TARGET_AVX512VL"
4128   "vcvtps2uqq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4129   [(set_attr "type" "ssecvt")
4130    (set_attr "prefix" "evex")
4131    (set_attr "mode" "TI")])
4132
4133 (define_insn "<fixsuffix>fix_truncv16sfv16si2<mask_name><round_saeonly_name>"
4134   [(set (match_operand:V16SI 0 "register_operand" "=v")
4135         (any_fix:V16SI
4136           (match_operand:V16SF 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")))]
4137   "TARGET_AVX512F"
4138   "vcvttps2<fixsuffix>dq\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}"
4139   [(set_attr "type" "ssecvt")
4140    (set_attr "prefix" "evex")
4141    (set_attr "mode" "XI")])
4142
4143 (define_insn "fix_truncv8sfv8si2<mask_name>"
4144   [(set (match_operand:V8SI 0 "register_operand" "=v")
4145         (fix:V8SI (match_operand:V8SF 1 "nonimmediate_operand" "vm")))]
4146   "TARGET_AVX && <mask_avx512vl_condition>"
4147   "vcvttps2dq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4148   [(set_attr "type" "ssecvt")
4149    (set_attr "prefix" "<mask_prefix>")
4150    (set_attr "mode" "OI")])
4151
4152 (define_insn "fix_truncv4sfv4si2<mask_name>"
4153   [(set (match_operand:V4SI 0 "register_operand" "=v")
4154         (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "vm")))]
4155   "TARGET_SSE2 && <mask_avx512vl_condition>"
4156   "%vcvttps2dq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4157   [(set_attr "type" "ssecvt")
4158    (set (attr "prefix_rep")
4159      (if_then_else
4160        (match_test "TARGET_AVX")
4161      (const_string "*")
4162      (const_string "1")))
4163    (set (attr "prefix_data16")
4164      (if_then_else
4165        (match_test "TARGET_AVX")
4166      (const_string "*")
4167      (const_string "0")))
4168    (set_attr "prefix_data16" "0")
4169    (set_attr "prefix" "<mask_prefix2>")
4170    (set_attr "mode" "TI")])
4171
4172 (define_expand "fixuns_trunc<mode><sseintvecmodelower>2"
4173   [(match_operand:<sseintvecmode> 0 "register_operand")
4174    (match_operand:VF1 1 "register_operand")]
4175   "TARGET_SSE2"
4176 {
4177   if (<MODE>mode == V16SFmode)
4178     emit_insn (gen_ufix_truncv16sfv16si2 (operands[0],
4179                                           operands[1]));
4180   else
4181     {
4182       rtx tmp[3];
4183       tmp[0] = ix86_expand_adjust_ufix_to_sfix_si (operands[1], &tmp[2]);
4184       tmp[1] = gen_reg_rtx (<sseintvecmode>mode);
4185       emit_insn (gen_fix_trunc<mode><sseintvecmodelower>2 (tmp[1], tmp[0]));
4186       emit_insn (gen_xor<sseintvecmodelower>3 (operands[0], tmp[1], tmp[2]));
4187     }
4188   DONE;
4189 })
4190
4191 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4192 ;;
4193 ;; Parallel double-precision floating point conversion operations
4194 ;;
4195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4196
4197 (define_insn "sse2_cvtpi2pd"
4198   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
4199         (float:V2DF (match_operand:V2SI 1 "nonimmediate_operand" "y,m")))]
4200   "TARGET_SSE2"
4201   "cvtpi2pd\t{%1, %0|%0, %1}"
4202   [(set_attr "type" "ssecvt")
4203    (set_attr "unit" "mmx,*")
4204    (set_attr "prefix_data16" "1,*")
4205    (set_attr "mode" "V2DF")])
4206
4207 (define_insn "sse2_cvtpd2pi"
4208   [(set (match_operand:V2SI 0 "register_operand" "=y")
4209         (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
4210                      UNSPEC_FIX_NOTRUNC))]
4211   "TARGET_SSE2"
4212   "cvtpd2pi\t{%1, %0|%0, %1}"
4213   [(set_attr "type" "ssecvt")
4214    (set_attr "unit" "mmx")
4215    (set_attr "bdver1_decode" "double")
4216    (set_attr "btver2_decode" "direct")
4217    (set_attr "prefix_data16" "1")
4218    (set_attr "mode" "DI")])
4219
4220 (define_insn "sse2_cvttpd2pi"
4221   [(set (match_operand:V2SI 0 "register_operand" "=y")
4222         (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm")))]
4223   "TARGET_SSE2"
4224   "cvttpd2pi\t{%1, %0|%0, %1}"
4225   [(set_attr "type" "ssecvt")
4226    (set_attr "unit" "mmx")
4227    (set_attr "bdver1_decode" "double")
4228    (set_attr "prefix_data16" "1")
4229    (set_attr "mode" "TI")])
4230
4231 (define_insn "sse2_cvtsi2sd"
4232   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
4233         (vec_merge:V2DF
4234           (vec_duplicate:V2DF
4235             (float:DF (match_operand:SI 2 "nonimmediate_operand" "r,m,rm")))
4236           (match_operand:V2DF 1 "register_operand" "0,0,x")
4237           (const_int 1)))]
4238   "TARGET_SSE2"
4239   "@
4240    cvtsi2sd\t{%2, %0|%0, %2}
4241    cvtsi2sd\t{%2, %0|%0, %2}
4242    vcvtsi2sd\t{%2, %1, %0|%0, %1, %2}"
4243   [(set_attr "isa" "noavx,noavx,avx")
4244    (set_attr "type" "sseicvt")
4245    (set_attr "athlon_decode" "double,direct,*")
4246    (set_attr "amdfam10_decode" "vector,double,*")
4247    (set_attr "bdver1_decode" "double,direct,*")
4248    (set_attr "btver2_decode" "double,double,double")
4249    (set_attr "prefix" "orig,orig,vex")
4250    (set_attr "mode" "DF")])
4251
4252 (define_insn "sse2_cvtsi2sdq<round_name>"
4253   [(set (match_operand:V2DF 0 "register_operand" "=x,x,v")
4254         (vec_merge:V2DF
4255           (vec_duplicate:V2DF
4256             (float:DF (match_operand:DI 2 "<round_nimm_predicate>" "r,m,<round_constraint3>")))
4257           (match_operand:V2DF 1 "register_operand" "0,0,v")
4258           (const_int 1)))]
4259   "TARGET_SSE2 && TARGET_64BIT"
4260   "@
4261    cvtsi2sdq\t{%2, %0|%0, %2}
4262    cvtsi2sdq\t{%2, %0|%0, %2}
4263    vcvtsi2sdq\t{<round_op3>%2, %1, %0|%0, %1, %2<round_op3>}"
4264   [(set_attr "isa" "noavx,noavx,avx")
4265    (set_attr "type" "sseicvt")
4266    (set_attr "athlon_decode" "double,direct,*")
4267    (set_attr "amdfam10_decode" "vector,double,*")
4268    (set_attr "bdver1_decode" "double,direct,*")
4269    (set_attr "length_vex" "*,*,4")
4270    (set_attr "prefix_rex" "1,1,*")
4271    (set_attr "prefix" "orig,orig,maybe_evex")
4272    (set_attr "mode" "DF")])
4273
4274 (define_insn "avx512f_vcvtss2usi<round_name>"
4275   [(set (match_operand:SI 0 "register_operand" "=r")
4276         (unspec:SI
4277           [(vec_select:SF
4278              (match_operand:V4SF 1 "<round_nimm_predicate>" "<round_constraint>")
4279              (parallel [(const_int 0)]))]
4280           UNSPEC_UNSIGNED_FIX_NOTRUNC))]
4281   "TARGET_AVX512F"
4282   "vcvtss2usi\t{<round_op2>%1, %0|%0, %1<round_op2>}"
4283   [(set_attr "type" "sseicvt")
4284    (set_attr "prefix" "evex")
4285    (set_attr "mode" "SI")])
4286
4287 (define_insn "avx512f_vcvtss2usiq<round_name>"
4288   [(set (match_operand:DI 0 "register_operand" "=r")
4289         (unspec:DI
4290           [(vec_select:SF
4291              (match_operand:V4SF 1 "<round_nimm_predicate>" "<round_constraint>")
4292              (parallel [(const_int 0)]))]
4293           UNSPEC_UNSIGNED_FIX_NOTRUNC))]
4294   "TARGET_AVX512F && TARGET_64BIT"
4295   "vcvtss2usi\t{<round_op2>%1, %0|%0, %1<round_op2>}"
4296   [(set_attr "type" "sseicvt")
4297    (set_attr "prefix" "evex")
4298    (set_attr "mode" "DI")])
4299
4300 (define_insn "avx512f_vcvttss2usi<round_saeonly_name>"
4301   [(set (match_operand:SI 0 "register_operand" "=r")
4302         (unsigned_fix:SI
4303           (vec_select:SF
4304             (match_operand:V4SF 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
4305             (parallel [(const_int 0)]))))]
4306   "TARGET_AVX512F"
4307   "vcvttss2usi\t{<round_saeonly_op2>%1, %0|%0, %1<round_saeonly_op2>}"
4308   [(set_attr "type" "sseicvt")
4309    (set_attr "prefix" "evex")
4310    (set_attr "mode" "SI")])
4311
4312 (define_insn "avx512f_vcvttss2usiq<round_saeonly_name>"
4313   [(set (match_operand:DI 0 "register_operand" "=r")
4314         (unsigned_fix:DI
4315           (vec_select:SF
4316             (match_operand:V4SF 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
4317             (parallel [(const_int 0)]))))]
4318   "TARGET_AVX512F && TARGET_64BIT"
4319   "vcvttss2usi\t{<round_saeonly_op2>%1, %0|%0, %1<round_saeonly_op2>}"
4320   [(set_attr "type" "sseicvt")
4321    (set_attr "prefix" "evex")
4322    (set_attr "mode" "DI")])
4323
4324 (define_insn "avx512f_vcvtsd2usi<round_name>"
4325   [(set (match_operand:SI 0 "register_operand" "=r")
4326         (unspec:SI
4327           [(vec_select:DF
4328              (match_operand:V2DF 1 "<round_nimm_predicate>" "<round_constraint>")
4329              (parallel [(const_int 0)]))]
4330           UNSPEC_UNSIGNED_FIX_NOTRUNC))]
4331   "TARGET_AVX512F"
4332   "vcvtsd2usi\t{<round_op2>%1, %0|%0, %1<round_op2>}"
4333   [(set_attr "type" "sseicvt")
4334    (set_attr "prefix" "evex")
4335    (set_attr "mode" "SI")])
4336
4337 (define_insn "avx512f_vcvtsd2usiq<round_name>"
4338   [(set (match_operand:DI 0 "register_operand" "=r")
4339         (unspec:DI
4340           [(vec_select:DF
4341              (match_operand:V2DF 1 "<round_nimm_predicate>" "<round_constraint>")
4342              (parallel [(const_int 0)]))]
4343           UNSPEC_UNSIGNED_FIX_NOTRUNC))]
4344   "TARGET_AVX512F && TARGET_64BIT"
4345   "vcvtsd2usi\t{<round_op2>%1, %0|%0, %1<round_op2>}"
4346   [(set_attr "type" "sseicvt")
4347    (set_attr "prefix" "evex")
4348    (set_attr "mode" "DI")])
4349
4350 (define_insn "avx512f_vcvttsd2usi<round_saeonly_name>"
4351   [(set (match_operand:SI 0 "register_operand" "=r")
4352         (unsigned_fix:SI
4353           (vec_select:DF
4354             (match_operand:V2DF 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
4355             (parallel [(const_int 0)]))))]
4356   "TARGET_AVX512F"
4357   "vcvttsd2usi\t{<round_saeonly_op2>%1, %0|%0, %1<round_saeonly_op2>}"
4358   [(set_attr "type" "sseicvt")
4359    (set_attr "prefix" "evex")
4360    (set_attr "mode" "SI")])
4361
4362 (define_insn "avx512f_vcvttsd2usiq<round_saeonly_name>"
4363   [(set (match_operand:DI 0 "register_operand" "=r")
4364         (unsigned_fix:DI
4365           (vec_select:DF
4366             (match_operand:V2DF 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
4367             (parallel [(const_int 0)]))))]
4368   "TARGET_AVX512F && TARGET_64BIT"
4369   "vcvttsd2usi\t{<round_saeonly_op2>%1, %0|%0, %1<round_saeonly_op2>}"
4370   [(set_attr "type" "sseicvt")
4371    (set_attr "prefix" "evex")
4372    (set_attr "mode" "DI")])
4373
4374 (define_insn "sse2_cvtsd2si<round_name>"
4375   [(set (match_operand:SI 0 "register_operand" "=r,r")
4376         (unspec:SI
4377           [(vec_select:DF
4378              (match_operand:V2DF 1 "<round_nimm_predicate>" "v,<round_constraint2>")
4379              (parallel [(const_int 0)]))]
4380           UNSPEC_FIX_NOTRUNC))]
4381   "TARGET_SSE2"
4382   "%vcvtsd2si\t{<round_op2>%1, %0|%0, %q1<round_op2>}"
4383   [(set_attr "type" "sseicvt")
4384    (set_attr "athlon_decode" "double,vector")
4385    (set_attr "bdver1_decode" "double,double")
4386    (set_attr "btver2_decode" "double,double")
4387    (set_attr "prefix_rep" "1")
4388    (set_attr "prefix" "maybe_vex")
4389    (set_attr "mode" "SI")])
4390
4391 (define_insn "sse2_cvtsd2si_2"
4392   [(set (match_operand:SI 0 "register_operand" "=r,r")
4393         (unspec:SI [(match_operand:DF 1 "nonimmediate_operand" "v,m")]
4394                    UNSPEC_FIX_NOTRUNC))]
4395   "TARGET_SSE2"
4396   "%vcvtsd2si\t{%1, %0|%0, %q1}"
4397   [(set_attr "type" "sseicvt")
4398    (set_attr "athlon_decode" "double,vector")
4399    (set_attr "amdfam10_decode" "double,double")
4400    (set_attr "bdver1_decode" "double,double")
4401    (set_attr "prefix_rep" "1")
4402    (set_attr "prefix" "maybe_vex")
4403    (set_attr "mode" "SI")])
4404
4405 (define_insn "sse2_cvtsd2siq<round_name>"
4406   [(set (match_operand:DI 0 "register_operand" "=r,r")
4407         (unspec:DI
4408           [(vec_select:DF
4409              (match_operand:V2DF 1 "<round_nimm_predicate>" "v,<round_constraint2>")
4410              (parallel [(const_int 0)]))]
4411           UNSPEC_FIX_NOTRUNC))]
4412   "TARGET_SSE2 && TARGET_64BIT"
4413   "%vcvtsd2si{q}\t{<round_op2>%1, %0|%0, %q1<round_op2>}"
4414   [(set_attr "type" "sseicvt")
4415    (set_attr "athlon_decode" "double,vector")
4416    (set_attr "bdver1_decode" "double,double")
4417    (set_attr "prefix_rep" "1")
4418    (set_attr "prefix" "maybe_vex")
4419    (set_attr "mode" "DI")])
4420
4421 (define_insn "sse2_cvtsd2siq_2"
4422   [(set (match_operand:DI 0 "register_operand" "=r,r")
4423         (unspec:DI [(match_operand:DF 1 "nonimmediate_operand" "v,m")]
4424                    UNSPEC_FIX_NOTRUNC))]
4425   "TARGET_SSE2 && TARGET_64BIT"
4426   "%vcvtsd2si{q}\t{%1, %0|%0, %q1}"
4427   [(set_attr "type" "sseicvt")
4428    (set_attr "athlon_decode" "double,vector")
4429    (set_attr "amdfam10_decode" "double,double")
4430    (set_attr "bdver1_decode" "double,double")
4431    (set_attr "prefix_rep" "1")
4432    (set_attr "prefix" "maybe_vex")
4433    (set_attr "mode" "DI")])
4434
4435 (define_insn "sse2_cvttsd2si<round_saeonly_name>"
4436   [(set (match_operand:SI 0 "register_operand" "=r,r")
4437         (fix:SI
4438           (vec_select:DF
4439             (match_operand:V2DF 1 "<round_saeonly_nimm_predicate>" "v,<round_saeonly_constraint2>")
4440             (parallel [(const_int 0)]))))]
4441   "TARGET_SSE2"
4442   "%vcvttsd2si\t{<round_saeonly_op2>%1, %0|%0, %q1<round_saeonly_op2>}"
4443   [(set_attr "type" "sseicvt")
4444    (set_attr "athlon_decode" "double,vector")
4445    (set_attr "amdfam10_decode" "double,double")
4446    (set_attr "bdver1_decode" "double,double")
4447    (set_attr "btver2_decode" "double,double")
4448    (set_attr "prefix_rep" "1")
4449    (set_attr "prefix" "maybe_vex")
4450    (set_attr "mode" "SI")])
4451
4452 (define_insn "sse2_cvttsd2siq<round_saeonly_name>"
4453   [(set (match_operand:DI 0 "register_operand" "=r,r")
4454         (fix:DI
4455           (vec_select:DF
4456             (match_operand:V2DF 1 "<round_saeonly_nimm_predicate>" "v,<round_saeonly_constraint2>")
4457             (parallel [(const_int 0)]))))]
4458   "TARGET_SSE2 && TARGET_64BIT"
4459   "%vcvttsd2si{q}\t{<round_saeonly_op2>%1, %0|%0, %q1<round_saeonly_op2>}"
4460   [(set_attr "type" "sseicvt")
4461    (set_attr "athlon_decode" "double,vector")
4462    (set_attr "amdfam10_decode" "double,double")
4463    (set_attr "bdver1_decode" "double,double")
4464    (set_attr "prefix_rep" "1")
4465    (set_attr "prefix" "maybe_vex")
4466    (set_attr "mode" "DI")])
4467
4468 ;; For float<si2dfmode><mode>2 insn pattern
4469 (define_mode_attr si2dfmode
4470   [(V8DF "V8SI") (V4DF "V4SI")])
4471 (define_mode_attr si2dfmodelower
4472   [(V8DF "v8si") (V4DF "v4si")])
4473
4474 (define_insn "float<si2dfmodelower><mode>2<mask_name>"
4475   [(set (match_operand:VF2_512_256 0 "register_operand" "=v")
4476         (float:VF2_512_256 (match_operand:<si2dfmode> 1 "nonimmediate_operand" "vm")))]
4477   "TARGET_AVX && <mask_mode512bit_condition>"
4478   "vcvtdq2pd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4479   [(set_attr "type" "ssecvt")
4480    (set_attr "prefix" "maybe_vex")
4481    (set_attr "mode" "<MODE>")])
4482
4483 (define_insn "<floatsuffix>float<sseintvecmodelower><mode>2<mask_name><round_name>"
4484   [(set (match_operand:VF2_AVX512VL 0 "register_operand" "=v")
4485         (any_float:VF2_AVX512VL
4486           (match_operand:<sseintvecmode> 1 "nonimmediate_operand" "vm")))]
4487   "TARGET_AVX512DQ"
4488   "vcvt<floatsuffix>qq2pd\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4489   [(set_attr "type" "ssecvt")
4490    (set_attr "prefix" "evex")
4491    (set_attr "mode" "<MODE>")])
4492
4493 ;; For <floatsuffix>float<sselondveclower><mode> insn patterns
4494 (define_mode_attr qq2pssuff
4495   [(V8SF "") (V4SF "{y}")])
4496
4497 (define_mode_attr sselongvecmode
4498   [(V8SF "V8DI") (V4SF  "V4DI")])
4499
4500 (define_mode_attr sselongvecmodelower
4501   [(V8SF "v8di") (V4SF  "v4di")])
4502
4503 (define_mode_attr sseintvecmode3
4504   [(V8SF "XI") (V4SF "OI")
4505    (V8DF "OI") (V4DF "TI")])
4506
4507 (define_insn "<floatsuffix>float<sselongvecmodelower><mode>2<mask_name><round_name>"
4508   [(set (match_operand:VF1_128_256VL 0 "register_operand" "=v")
4509          (any_float:VF1_128_256VL
4510            (match_operand:<sselongvecmode> 1 "nonimmediate_operand" "<round_constraint>")))]
4511   "TARGET_AVX512DQ && <round_modev8sf_condition>"
4512   "vcvt<floatsuffix>qq2ps<qq2pssuff>\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4513   [(set_attr "type" "ssecvt")
4514    (set_attr "prefix" "evex")
4515    (set_attr "mode" "<MODE>")])
4516
4517 (define_insn "*<floatsuffix>floatv2div2sf2"
4518   [(set (match_operand:V4SF 0 "register_operand" "=v")
4519     (vec_concat:V4SF
4520             (any_float:V2SF (match_operand:V2DI 1 "nonimmediate_operand" "vm"))
4521             (const_vector:V2SF [(const_int 0) (const_int 0)])))]
4522   "TARGET_AVX512DQ && TARGET_AVX512VL"
4523   "vcvt<floatsuffix>qq2ps{x}\t{%1, %0|%0, %1}"
4524   [(set_attr "type" "ssecvt")
4525    (set_attr "prefix" "evex")
4526    (set_attr "mode" "V4SF")])
4527
4528 (define_insn "<floatsuffix>floatv2div2sf2_mask"
4529   [(set (match_operand:V4SF 0 "register_operand" "=v")
4530     (vec_concat:V4SF
4531         (vec_merge:V2SF
4532                 (any_float:V2SF (match_operand:V2DI 1 "nonimmediate_operand" "vm"))
4533             (vec_select:V2SF
4534                 (match_operand:V4SF 2 "vector_move_operand" "0C")
4535                 (parallel [(const_int 0) (const_int 1)]))
4536             (match_operand:QI 3 "register_operand" "Yk"))
4537             (const_vector:V2SF [(const_int 0) (const_int 0)])))]
4538   "TARGET_AVX512DQ && TARGET_AVX512VL"
4539   "vcvt<floatsuffix>qq2ps{x}\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
4540   [(set_attr "type" "ssecvt")
4541    (set_attr "prefix" "evex")
4542    (set_attr "mode" "V4SF")])
4543
4544 (define_insn "ufloat<si2dfmodelower><mode>2<mask_name>"
4545   [(set (match_operand:VF2_512_256VL 0 "register_operand" "=v")
4546         (unsigned_float:VF2_512_256VL
4547           (match_operand:<si2dfmode> 1 "nonimmediate_operand" "vm")))]
4548    "TARGET_AVX512F"
4549    "vcvtudq2pd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4550    [(set_attr "type" "ssecvt")
4551     (set_attr "prefix" "evex")
4552     (set_attr "mode" "<MODE>")])
4553
4554 (define_insn "ufloatv2siv2df2<mask_name>"
4555   [(set (match_operand:V2DF 0 "register_operand" "=v")
4556         (unsigned_float:V2DF
4557           (vec_select:V2SI
4558             (match_operand:V4SI 1 "nonimmediate_operand" "vm")
4559             (parallel [(const_int 0) (const_int 1)]))))]
4560   "TARGET_AVX512VL"
4561   "vcvtudq2pd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4562   [(set_attr "type" "ssecvt")
4563    (set_attr "prefix" "evex")
4564    (set_attr "mode" "V2DF")])
4565
4566 (define_insn "avx512f_cvtdq2pd512_2"
4567   [(set (match_operand:V8DF 0 "register_operand" "=v")
4568         (float:V8DF
4569           (vec_select:V8SI
4570             (match_operand:V16SI 1 "nonimmediate_operand" "vm")
4571             (parallel [(const_int 0) (const_int 1)
4572                        (const_int 2) (const_int 3)
4573                        (const_int 4) (const_int 5)
4574                        (const_int 6) (const_int 7)]))))]
4575   "TARGET_AVX512F"
4576   "vcvtdq2pd\t{%t1, %0|%0, %t1}"
4577   [(set_attr "type" "ssecvt")
4578    (set_attr "prefix" "evex")
4579    (set_attr "mode" "V8DF")])
4580
4581 (define_insn "avx_cvtdq2pd256_2"
4582   [(set (match_operand:V4DF 0 "register_operand" "=v")
4583         (float:V4DF
4584           (vec_select:V4SI
4585             (match_operand:V8SI 1 "nonimmediate_operand" "vm")
4586             (parallel [(const_int 0) (const_int 1)
4587                        (const_int 2) (const_int 3)]))))]
4588   "TARGET_AVX"
4589   "vcvtdq2pd\t{%x1, %0|%0, %x1}"
4590   [(set_attr "type" "ssecvt")
4591    (set_attr "prefix" "maybe_evex")
4592    (set_attr "mode" "V4DF")])
4593
4594 (define_insn "sse2_cvtdq2pd<mask_name>"
4595   [(set (match_operand:V2DF 0 "register_operand" "=v")
4596         (float:V2DF
4597           (vec_select:V2SI
4598             (match_operand:V4SI 1 "nonimmediate_operand" "vm")
4599             (parallel [(const_int 0) (const_int 1)]))))]
4600   "TARGET_SSE2 && <mask_avx512vl_condition>"
4601   "%vcvtdq2pd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %q1}"
4602   [(set_attr "type" "ssecvt")
4603    (set_attr "prefix" "maybe_vex")
4604    (set_attr "ssememalign" "64")
4605    (set_attr "mode" "V2DF")])
4606
4607 (define_insn "<mask_codefor>avx512f_cvtpd2dq512<mask_name><round_name>"
4608   [(set (match_operand:V8SI 0 "register_operand" "=v")
4609         (unspec:V8SI
4610           [(match_operand:V8DF 1 "<round_nimm_predicate>" "<round_constraint>")]
4611           UNSPEC_FIX_NOTRUNC))]
4612   "TARGET_AVX512F"
4613   "vcvtpd2dq\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4614   [(set_attr "type" "ssecvt")
4615    (set_attr "prefix" "evex")
4616    (set_attr "mode" "OI")])
4617
4618 (define_insn "avx_cvtpd2dq256<mask_name>"
4619   [(set (match_operand:V4SI 0 "register_operand" "=v")
4620         (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand" "vm")]
4621                      UNSPEC_FIX_NOTRUNC))]
4622   "TARGET_AVX && <mask_avx512vl_condition>"
4623   "vcvtpd2dq{y}\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4624   [(set_attr "type" "ssecvt")
4625    (set_attr "prefix" "<mask_prefix>")
4626    (set_attr "mode" "OI")])
4627
4628 (define_expand "avx_cvtpd2dq256_2"
4629   [(set (match_operand:V8SI 0 "register_operand")
4630         (vec_concat:V8SI
4631           (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand")]
4632                        UNSPEC_FIX_NOTRUNC)
4633           (match_dup 2)))]
4634   "TARGET_AVX"
4635   "operands[2] = CONST0_RTX (V4SImode);")
4636
4637 (define_insn "*avx_cvtpd2dq256_2"
4638   [(set (match_operand:V8SI 0 "register_operand" "=x")
4639         (vec_concat:V8SI
4640           (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand" "xm")]
4641                        UNSPEC_FIX_NOTRUNC)
4642           (match_operand:V4SI 2 "const0_operand")))]
4643   "TARGET_AVX"
4644   "vcvtpd2dq{y}\t{%1, %x0|%x0, %1}"
4645   [(set_attr "type" "ssecvt")
4646    (set_attr "prefix" "vex")
4647    (set_attr "btver2_decode" "vector")
4648    (set_attr "mode" "OI")])
4649
4650 (define_insn "sse2_cvtpd2dq<mask_name>"
4651   [(set (match_operand:V4SI 0 "register_operand" "=v")
4652         (vec_concat:V4SI
4653           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "vm")]
4654                        UNSPEC_FIX_NOTRUNC)
4655           (const_vector:V2SI [(const_int 0) (const_int 0)])))]
4656   "TARGET_SSE2 && <mask_avx512vl_condition>"
4657 {
4658   if (TARGET_AVX)
4659     return "vcvtpd2dq{x}\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}";
4660   else
4661     return "cvtpd2dq\t{%1, %0|%0, %1}";
4662 }
4663   [(set_attr "type" "ssecvt")
4664    (set_attr "prefix_rep" "1")
4665    (set_attr "prefix_data16" "0")
4666    (set_attr "prefix" "maybe_vex")
4667    (set_attr "mode" "TI")
4668    (set_attr "amdfam10_decode" "double")
4669    (set_attr "athlon_decode" "vector")
4670    (set_attr "bdver1_decode" "double")])
4671
4672 ;; For ufix_notrunc* insn patterns
4673 (define_mode_attr pd2udqsuff
4674   [(V8DF "") (V4DF "{y}")])
4675
4676 (define_insn "ufix_notrunc<mode><si2dfmodelower>2<mask_name><round_name>"
4677   [(set (match_operand:<si2dfmode> 0 "register_operand" "=v")
4678         (unspec:<si2dfmode>
4679           [(match_operand:VF2_512_256VL 1 "nonimmediate_operand" "<round_constraint>")]
4680           UNSPEC_UNSIGNED_FIX_NOTRUNC))]
4681   "TARGET_AVX512F"
4682   "vcvtpd2udq<pd2udqsuff>\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4683   [(set_attr "type" "ssecvt")
4684    (set_attr "prefix" "evex")
4685    (set_attr "mode" "<sseinsnmode>")])
4686
4687 (define_insn "ufix_notruncv2dfv2si2<mask_name>"
4688   [(set (match_operand:V4SI 0 "register_operand" "=v")
4689         (vec_concat:V4SI
4690           (unspec:V2SI
4691             [(match_operand:V2DF 1 "nonimmediate_operand" "vm")]
4692             UNSPEC_UNSIGNED_FIX_NOTRUNC)
4693           (const_vector:V2SI [(const_int 0) (const_int 0)])))]
4694   "TARGET_AVX512VL"
4695   "vcvtpd2udq{x}\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4696   [(set_attr "type" "ssecvt")
4697    (set_attr "prefix" "evex")
4698    (set_attr "mode" "TI")])
4699
4700 (define_insn "<fixsuffix>fix_truncv8dfv8si2<mask_name><round_saeonly_name>"
4701   [(set (match_operand:V8SI 0 "register_operand" "=v")
4702         (any_fix:V8SI
4703           (match_operand:V8DF 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")))]
4704   "TARGET_AVX512F"
4705   "vcvttpd2<fixsuffix>dq\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}"
4706   [(set_attr "type" "ssecvt")
4707    (set_attr "prefix" "evex")
4708    (set_attr "mode" "OI")])
4709
4710 (define_insn "ufix_truncv2dfv2si2<mask_name>"
4711   [(set (match_operand:V4SI 0 "register_operand" "=v")
4712         (vec_concat:V4SI
4713           (unsigned_fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "vm"))
4714           (const_vector:V2SI [(const_int 0) (const_int 0)])))]
4715   "TARGET_AVX512VL"
4716   "vcvttpd2udq{x}\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4717   [(set_attr "type" "ssecvt")
4718    (set_attr "prefix" "evex")
4719    (set_attr "mode" "TI")])
4720
4721 (define_insn "fix_truncv4dfv4si2<mask_name>"
4722   [(set (match_operand:V4SI 0 "register_operand" "=v")
4723         (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" "vm")))]
4724   "TARGET_AVX || (TARGET_AVX512VL && TARGET_AVX512F)"
4725   "vcvttpd2dq{y}\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4726   [(set_attr "type" "ssecvt")
4727    (set_attr "prefix" "maybe_evex")
4728    (set_attr "mode" "OI")])
4729
4730 (define_insn "ufix_truncv4dfv4si2<mask_name>"
4731   [(set (match_operand:V4SI 0 "register_operand" "=v")
4732         (unsigned_fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" "vm")))]
4733   "TARGET_AVX512VL && TARGET_AVX512F"
4734   "vcvttpd2udq{y}\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4735   [(set_attr "type" "ssecvt")
4736    (set_attr "prefix" "maybe_evex")
4737    (set_attr "mode" "OI")])
4738
4739 (define_insn "<fixsuffix>fix_trunc<mode><sseintvecmodelower>2<mask_name><round_saeonly_name>"
4740   [(set (match_operand:<sseintvecmode> 0 "register_operand" "=v")
4741         (any_fix:<sseintvecmode>
4742           (match_operand:VF2_AVX512VL 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")))]
4743   "TARGET_AVX512DQ && <round_saeonly_mode512bit_condition>"
4744   "vcvttpd2<fixsuffix>qq\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}"
4745   [(set_attr "type" "ssecvt")
4746    (set_attr "prefix" "evex")
4747    (set_attr "mode" "<sseintvecmode2>")])
4748
4749 (define_insn "fix_notrunc<mode><sseintvecmodelower>2<mask_name><round_name>"
4750   [(set (match_operand:<sseintvecmode> 0 "register_operand" "=v")
4751         (unspec:<sseintvecmode>
4752           [(match_operand:VF2_AVX512VL 1 "<round_nimm_predicate>" "<round_constraint>")]
4753           UNSPEC_FIX_NOTRUNC))]
4754   "TARGET_AVX512DQ && <round_mode512bit_condition>"
4755   "vcvtpd2qq\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4756   [(set_attr "type" "ssecvt")
4757    (set_attr "prefix" "evex")
4758    (set_attr "mode" "<sseintvecmode2>")])
4759
4760 (define_insn "ufix_notrunc<mode><sseintvecmodelower>2<mask_name><round_name>"
4761   [(set (match_operand:<sseintvecmode> 0 "register_operand" "=v")
4762         (unspec:<sseintvecmode>
4763           [(match_operand:VF2_AVX512VL 1 "nonimmediate_operand" "<round_constraint>")]
4764           UNSPEC_UNSIGNED_FIX_NOTRUNC))]
4765   "TARGET_AVX512DQ && <round_mode512bit_condition>"
4766   "vcvtpd2uqq\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4767   [(set_attr "type" "ssecvt")
4768    (set_attr "prefix" "evex")
4769    (set_attr "mode" "<sseintvecmode2>")])
4770
4771 (define_insn "<fixsuffix>fix_trunc<mode><sselongvecmodelower>2<mask_name><round_saeonly_name>"
4772   [(set (match_operand:<sselongvecmode> 0 "register_operand" "=v")
4773         (any_fix:<sselongvecmode>
4774           (match_operand:VF1_128_256VL 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")))]
4775   "TARGET_AVX512DQ && <round_saeonly_modev8sf_condition>"
4776   "vcvttps2<fixsuffix>qq\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}"
4777   [(set_attr "type" "ssecvt")
4778    (set_attr "prefix" "evex")
4779    (set_attr "mode" "<sseintvecmode3>")])
4780
4781 (define_insn "<fixsuffix>fix_truncv2sfv2di2<mask_name>"
4782   [(set (match_operand:V2DI 0 "register_operand" "=v")
4783         (any_fix:V2DI
4784           (vec_select:V2SF
4785             (match_operand:V4SF 1 "nonimmediate_operand" "vm")
4786             (parallel [(const_int 0) (const_int 1)]))))]
4787   "TARGET_AVX512DQ && TARGET_AVX512VL"
4788   "vcvttps2<fixsuffix>qq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4789   [(set_attr "type" "ssecvt")
4790    (set_attr "prefix" "evex")
4791    (set_attr "mode" "TI")])
4792
4793 (define_insn "ufix_trunc<mode><sseintvecmodelower>2<mask_name>"
4794   [(set (match_operand:<sseintvecmode> 0 "register_operand" "=v")
4795         (unsigned_fix:<sseintvecmode>
4796           (match_operand:VF1_128_256VL 1 "nonimmediate_operand" "vm")))]
4797   "TARGET_AVX512VL"
4798   "vcvttps2udq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4799   [(set_attr "type" "ssecvt")
4800    (set_attr "prefix" "evex")
4801    (set_attr "mode" "<sseintvecmode2>")])
4802
4803 (define_expand "avx_cvttpd2dq256_2"
4804   [(set (match_operand:V8SI 0 "register_operand")
4805         (vec_concat:V8SI
4806           (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand"))
4807           (match_dup 2)))]
4808   "TARGET_AVX"
4809   "operands[2] = CONST0_RTX (V4SImode);")
4810
4811 (define_insn "sse2_cvttpd2dq<mask_name>"
4812   [(set (match_operand:V4SI 0 "register_operand" "=v")
4813         (vec_concat:V4SI
4814           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "vm"))
4815           (const_vector:V2SI [(const_int 0) (const_int 0)])))]
4816   "TARGET_SSE2 && <mask_avx512vl_condition>"
4817 {
4818   if (TARGET_AVX)
4819     return "vcvttpd2dq{x}\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}";
4820   else
4821     return "cvttpd2dq\t{%1, %0|%0, %1}";
4822 }
4823   [(set_attr "type" "ssecvt")
4824    (set_attr "amdfam10_decode" "double")
4825    (set_attr "athlon_decode" "vector")
4826    (set_attr "bdver1_decode" "double")
4827    (set_attr "prefix" "maybe_vex")
4828    (set_attr "mode" "TI")])
4829
4830 (define_insn "sse2_cvtsd2ss<round_name>"
4831   [(set (match_operand:V4SF 0 "register_operand" "=x,x,v")
4832         (vec_merge:V4SF
4833           (vec_duplicate:V4SF
4834             (float_truncate:V2SF
4835               (match_operand:V2DF 2 "nonimmediate_operand" "x,m,<round_constraint>")))
4836           (match_operand:V4SF 1 "register_operand" "0,0,v")
4837           (const_int 1)))]
4838   "TARGET_SSE2"
4839   "@
4840    cvtsd2ss\t{%2, %0|%0, %2}
4841    cvtsd2ss\t{%2, %0|%0, %q2}
4842    vcvtsd2ss\t{<round_op3>%2, %1, %0|%0, %1, %q2<round_op3>}"
4843   [(set_attr "isa" "noavx,noavx,avx")
4844    (set_attr "type" "ssecvt")
4845    (set_attr "athlon_decode" "vector,double,*")
4846    (set_attr "amdfam10_decode" "vector,double,*")
4847    (set_attr "bdver1_decode" "direct,direct,*")
4848    (set_attr "btver2_decode" "double,double,double")
4849    (set_attr "prefix" "orig,orig,<round_prefix>")
4850    (set_attr "mode" "SF")])
4851
4852 (define_insn "sse2_cvtss2sd<round_saeonly_name>"
4853   [(set (match_operand:V2DF 0 "register_operand" "=x,x,v")
4854         (vec_merge:V2DF
4855           (float_extend:V2DF
4856             (vec_select:V2SF
4857               (match_operand:V4SF 2 "<round_saeonly_nimm_predicate>" "x,m,<round_saeonly_constraint>")
4858               (parallel [(const_int 0) (const_int 1)])))
4859           (match_operand:V2DF 1 "register_operand" "0,0,v")
4860           (const_int 1)))]
4861   "TARGET_SSE2"
4862   "@
4863    cvtss2sd\t{%2, %0|%0, %2}
4864    cvtss2sd\t{%2, %0|%0, %k2}
4865    vcvtss2sd\t{<round_saeonly_op3>%2, %1, %0|%0, %1, %k2<round_saeonly_op3>}"
4866   [(set_attr "isa" "noavx,noavx,avx")
4867    (set_attr "type" "ssecvt")
4868    (set_attr "amdfam10_decode" "vector,double,*")
4869    (set_attr "athlon_decode" "direct,direct,*")
4870    (set_attr "bdver1_decode" "direct,direct,*")
4871    (set_attr "btver2_decode" "double,double,double")
4872    (set_attr "prefix" "orig,orig,<round_saeonly_prefix>")
4873    (set_attr "mode" "DF")])
4874
4875 (define_insn "<mask_codefor>avx512f_cvtpd2ps512<mask_name><round_name>"
4876   [(set (match_operand:V8SF 0 "register_operand" "=v")
4877         (float_truncate:V8SF
4878           (match_operand:V8DF 1 "<round_nimm_predicate>" "<round_constraint>")))]
4879   "TARGET_AVX512F"
4880   "vcvtpd2ps\t{<round_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_mask_op2>}"
4881   [(set_attr "type" "ssecvt")
4882    (set_attr "prefix" "evex")
4883    (set_attr "mode" "V8SF")])
4884
4885 (define_insn "avx_cvtpd2ps256<mask_name>"
4886   [(set (match_operand:V4SF 0 "register_operand" "=v")
4887         (float_truncate:V4SF
4888           (match_operand:V4DF 1 "nonimmediate_operand" "vm")))]
4889   "TARGET_AVX && <mask_avx512vl_condition>"
4890   "vcvtpd2ps{y}\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
4891   [(set_attr "type" "ssecvt")
4892    (set_attr "prefix" "maybe_evex")
4893    (set_attr "btver2_decode" "vector")
4894    (set_attr "mode" "V4SF")])
4895
4896 (define_expand "sse2_cvtpd2ps"
4897   [(set (match_operand:V4SF 0 "register_operand")
4898         (vec_concat:V4SF
4899           (float_truncate:V2SF
4900             (match_operand:V2DF 1 "nonimmediate_operand"))
4901           (match_dup 2)))]
4902   "TARGET_SSE2"
4903   "operands[2] = CONST0_RTX (V2SFmode);")
4904
4905 (define_expand "sse2_cvtpd2ps_mask"
4906   [(set (match_operand:V4SF 0 "register_operand")
4907         (vec_merge:V4SF
4908           (vec_concat:V4SF
4909             (float_truncate:V2SF
4910               (match_operand:V2DF 1 "nonimmediate_operand"))
4911             (match_dup 4))
4912           (match_operand:V4SF 2 "register_operand")
4913           (match_operand:QI 3 "register_operand")))]
4914   "TARGET_SSE2"
4915   "operands[4] = CONST0_RTX (V2SFmode);")
4916
4917 (define_insn "*sse2_cvtpd2ps<mask_name>"
4918   [(set (match_operand:V4SF 0 "register_operand" "=v")
4919         (vec_concat:V4SF
4920           (float_truncate:V2SF
4921             (match_operand:V2DF 1 "nonimmediate_operand" "vm"))
4922           (match_operand:V2SF 2 "const0_operand")))]
4923   "TARGET_SSE2 && <mask_avx512vl_condition>"
4924 {
4925   if (TARGET_AVX)
4926     return "vcvtpd2ps{x}\t{%1, %0<mask_operand3>|%0<mask_operand3>, %1}";
4927   else
4928     return "cvtpd2ps\t{%1, %0|%0, %1}";
4929 }
4930   [(set_attr "type" "ssecvt")
4931    (set_attr "amdfam10_decode" "double")
4932    (set_attr "athlon_decode" "vector")
4933    (set_attr "bdver1_decode" "double")
4934    (set_attr "prefix_data16" "1")
4935    (set_attr "prefix" "maybe_vex")
4936    (set_attr "mode" "V4SF")])
4937
4938 ;; For <sse2_avx_avx512f>_cvtps2pd<avxsizesuffix> insn pattern
4939 (define_mode_attr sf2dfmode
4940   [(V8DF "V8SF") (V4DF "V4SF")])
4941
4942 (define_insn "<sse2_avx_avx512f>_cvtps2pd<avxsizesuffix><mask_name><round_saeonly_name>"
4943   [(set (match_operand:VF2_512_256 0 "register_operand" "=v")
4944         (float_extend:VF2_512_256
4945           (match_operand:<sf2dfmode> 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")))]
4946   "TARGET_AVX && <mask_mode512bit_condition> && <round_saeonly_mode512bit_condition>"
4947   "vcvtps2pd\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}"
4948   [(set_attr "type" "ssecvt")
4949    (set_attr "prefix" "maybe_vex")
4950    (set_attr "mode" "<MODE>")])
4951
4952 (define_insn "*avx_cvtps2pd256_2"
4953   [(set (match_operand:V4DF 0 "register_operand" "=x")
4954         (float_extend:V4DF
4955           (vec_select:V4SF
4956             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
4957             (parallel [(const_int 0) (const_int 1)
4958                        (const_int 2) (const_int 3)]))))]
4959   "TARGET_AVX"
4960   "vcvtps2pd\t{%x1, %0|%0, %x1}"
4961   [(set_attr "type" "ssecvt")
4962    (set_attr "prefix" "vex")
4963    (set_attr "mode" "V4DF")])
4964
4965 (define_insn "vec_unpacks_lo_v16sf"
4966   [(set (match_operand:V8DF 0 "register_operand" "=v")
4967         (float_extend:V8DF
4968           (vec_select:V8SF
4969             (match_operand:V16SF 1 "nonimmediate_operand" "vm")
4970             (parallel [(const_int 0) (const_int 1)
4971                        (const_int 2) (const_int 3)
4972                        (const_int 4) (const_int 5)
4973                        (const_int 6) (const_int 7)]))))]
4974   "TARGET_AVX512F"
4975   "vcvtps2pd\t{%t1, %0|%0, %t1}"
4976   [(set_attr "type" "ssecvt")
4977    (set_attr "prefix" "evex")
4978    (set_attr "mode" "V8DF")])
4979
4980 (define_insn "<avx512>_cvt<ssemodesuffix>2mask<mode>"
4981   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
4982         (unspec:<avx512fmaskmode>
4983          [(match_operand:VI12_AVX512VL 1 "register_operand" "v")]
4984          UNSPEC_CVTINT2MASK))]
4985   "TARGET_AVX512BW"
4986   "vpmov<ssemodesuffix>2m\t{%1, %0|%0, %1}"
4987   [(set_attr "prefix" "evex")
4988    (set_attr "mode" "<sseinsnmode>")])
4989
4990 (define_insn "<avx512>_cvt<ssemodesuffix>2mask<mode>"
4991   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
4992         (unspec:<avx512fmaskmode>
4993          [(match_operand:VI48_AVX512VL 1 "register_operand" "v")]
4994          UNSPEC_CVTINT2MASK))]
4995   "TARGET_AVX512DQ"
4996   "vpmov<ssemodesuffix>2m\t{%1, %0|%0, %1}"
4997   [(set_attr "prefix" "evex")
4998    (set_attr "mode" "<sseinsnmode>")])
4999
5000 (define_expand "<avx512>_cvtmask2<ssemodesuffix><mode>"
5001   [(set (match_operand:VI12_AVX512VL 0 "register_operand")
5002         (vec_merge:VI12_AVX512VL
5003           (match_dup 2)
5004           (match_dup 3)
5005           (match_operand:<avx512fmaskmode> 1 "register_operand")))]
5006   "TARGET_AVX512BW"
5007   {
5008     operands[2] = CONSTM1_RTX (<MODE>mode);
5009     operands[3] = CONST0_RTX (<MODE>mode);
5010   })
5011
5012 (define_insn "*<avx512>_cvtmask2<ssemodesuffix><mode>"
5013   [(set (match_operand:VI12_AVX512VL 0 "register_operand" "=v")
5014         (vec_merge:VI12_AVX512VL
5015           (match_operand:VI12_AVX512VL 2 "constm1_operand")
5016           (match_operand:VI12_AVX512VL 3 "const0_operand")
5017           (match_operand:<avx512fmaskmode> 1 "register_operand" "Yk")))]
5018   "TARGET_AVX512BW"
5019   "vpmovm2<ssemodesuffix>\t{%1, %0|%0, %1}"
5020   [(set_attr "prefix" "evex")
5021    (set_attr "mode" "<sseinsnmode>")])
5022
5023 (define_expand "<avx512>_cvtmask2<ssemodesuffix><mode>"
5024   [(set (match_operand:VI48_AVX512VL 0 "register_operand")
5025         (vec_merge:VI48_AVX512VL
5026           (match_dup 2)
5027           (match_dup 3)
5028           (match_operand:<avx512fmaskmode> 1 "register_operand")))]
5029   "TARGET_AVX512DQ"
5030   "{
5031     operands[2] = CONSTM1_RTX (<MODE>mode);
5032     operands[3] = CONST0_RTX (<MODE>mode);
5033   }")
5034
5035 (define_insn "*<avx512>_cvtmask2<ssemodesuffix><mode>"
5036   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
5037         (vec_merge:VI48_AVX512VL
5038           (match_operand:VI48_AVX512VL 2 "constm1_operand")
5039           (match_operand:VI48_AVX512VL 3 "const0_operand")
5040           (match_operand:<avx512fmaskmode> 1 "register_operand" "Yk")))]
5041   "TARGET_AVX512DQ"
5042   "vpmovm2<ssemodesuffix>\t{%1, %0|%0, %1}"
5043   [(set_attr "prefix" "evex")
5044    (set_attr "mode" "<sseinsnmode>")])
5045
5046 (define_insn "sse2_cvtps2pd<mask_name>"
5047   [(set (match_operand:V2DF 0 "register_operand" "=v")
5048         (float_extend:V2DF
5049           (vec_select:V2SF
5050             (match_operand:V4SF 1 "nonimmediate_operand" "vm")
5051             (parallel [(const_int 0) (const_int 1)]))))]
5052   "TARGET_SSE2 && <mask_avx512vl_condition>"
5053   "%vcvtps2pd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %q1}"
5054   [(set_attr "type" "ssecvt")
5055    (set_attr "amdfam10_decode" "direct")
5056    (set_attr "athlon_decode" "double")
5057    (set_attr "bdver1_decode" "double")
5058    (set_attr "prefix_data16" "0")
5059    (set_attr "prefix" "maybe_vex")
5060    (set_attr "mode" "V2DF")])
5061
5062 (define_expand "vec_unpacks_hi_v4sf"
5063   [(set (match_dup 2)
5064    (vec_select:V4SF
5065      (vec_concat:V8SF
5066        (match_dup 2)
5067        (match_operand:V4SF 1 "nonimmediate_operand"))
5068      (parallel [(const_int 6) (const_int 7)
5069                 (const_int 2) (const_int 3)])))
5070   (set (match_operand:V2DF 0 "register_operand")
5071    (float_extend:V2DF
5072      (vec_select:V2SF
5073        (match_dup 2)
5074        (parallel [(const_int 0) (const_int 1)]))))]
5075   "TARGET_SSE2"
5076   "operands[2] = gen_reg_rtx (V4SFmode);")
5077
5078 (define_expand "vec_unpacks_hi_v8sf"
5079   [(set (match_dup 2)
5080         (vec_select:V4SF
5081           (match_operand:V8SF 1 "register_operand")
5082           (parallel [(const_int 4) (const_int 5)
5083                      (const_int 6) (const_int 7)])))
5084    (set (match_operand:V4DF 0 "register_operand")
5085         (float_extend:V4DF
5086           (match_dup 2)))]
5087   "TARGET_AVX"
5088   "operands[2] = gen_reg_rtx (V4SFmode);")
5089
5090 (define_expand "vec_unpacks_hi_v16sf"
5091   [(set (match_dup 2)
5092         (vec_select:V8SF
5093           (match_operand:V16SF 1 "register_operand")
5094           (parallel [(const_int 8) (const_int 9)
5095                      (const_int 10) (const_int 11)
5096                      (const_int 12) (const_int 13)
5097                      (const_int 14) (const_int 15)])))
5098    (set (match_operand:V8DF 0 "register_operand")
5099         (float_extend:V8DF
5100           (match_dup 2)))]
5101 "TARGET_AVX512F"
5102 "operands[2] = gen_reg_rtx (V8SFmode);")
5103
5104 (define_expand "vec_unpacks_lo_v4sf"
5105   [(set (match_operand:V2DF 0 "register_operand")
5106         (float_extend:V2DF
5107           (vec_select:V2SF
5108             (match_operand:V4SF 1 "nonimmediate_operand")
5109             (parallel [(const_int 0) (const_int 1)]))))]
5110   "TARGET_SSE2")
5111
5112 (define_expand "vec_unpacks_lo_v8sf"
5113   [(set (match_operand:V4DF 0 "register_operand")
5114         (float_extend:V4DF
5115           (vec_select:V4SF
5116             (match_operand:V8SF 1 "nonimmediate_operand")
5117             (parallel [(const_int 0) (const_int 1)
5118                        (const_int 2) (const_int 3)]))))]
5119   "TARGET_AVX")
5120
5121 (define_mode_attr sseunpackfltmode
5122   [(V8HI "V4SF") (V4SI "V2DF") (V16HI "V8SF")
5123   (V8SI "V4DF") (V32HI "V16SF") (V16SI "V8DF")])
5124
5125 (define_expand "vec_unpacks_float_hi_<mode>"
5126   [(match_operand:<sseunpackfltmode> 0 "register_operand")
5127    (match_operand:VI2_AVX512F 1 "register_operand")]
5128   "TARGET_SSE2"
5129 {
5130   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
5131
5132   emit_insn (gen_vec_unpacks_hi_<mode> (tmp, operands[1]));
5133   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5134                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
5135   DONE;
5136 })
5137
5138 (define_expand "vec_unpacks_float_lo_<mode>"
5139   [(match_operand:<sseunpackfltmode> 0 "register_operand")
5140    (match_operand:VI2_AVX512F 1 "register_operand")]
5141   "TARGET_SSE2"
5142 {
5143   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
5144
5145   emit_insn (gen_vec_unpacks_lo_<mode> (tmp, operands[1]));
5146   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5147                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
5148   DONE;
5149 })
5150
5151 (define_expand "vec_unpacku_float_hi_<mode>"
5152   [(match_operand:<sseunpackfltmode> 0 "register_operand")
5153    (match_operand:VI2_AVX512F 1 "register_operand")]
5154   "TARGET_SSE2"
5155 {
5156   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
5157
5158   emit_insn (gen_vec_unpacku_hi_<mode> (tmp, operands[1]));
5159   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5160                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
5161   DONE;
5162 })
5163
5164 (define_expand "vec_unpacku_float_lo_<mode>"
5165   [(match_operand:<sseunpackfltmode> 0 "register_operand")
5166    (match_operand:VI2_AVX512F 1 "register_operand")]
5167   "TARGET_SSE2"
5168 {
5169   rtx tmp = gen_reg_rtx (<sseunpackmode>mode);
5170
5171   emit_insn (gen_vec_unpacku_lo_<mode> (tmp, operands[1]));
5172   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
5173                           gen_rtx_FLOAT (<sseunpackfltmode>mode, tmp)));
5174   DONE;
5175 })
5176
5177 (define_expand "vec_unpacks_float_hi_v4si"
5178   [(set (match_dup 2)
5179         (vec_select:V4SI
5180           (match_operand:V4SI 1 "nonimmediate_operand")
5181           (parallel [(const_int 2) (const_int 3)
5182                      (const_int 2) (const_int 3)])))
5183    (set (match_operand:V2DF 0 "register_operand")
5184         (float:V2DF
5185           (vec_select:V2SI
5186           (match_dup 2)
5187             (parallel [(const_int 0) (const_int 1)]))))]
5188   "TARGET_SSE2"
5189   "operands[2] = gen_reg_rtx (V4SImode);")
5190
5191 (define_expand "vec_unpacks_float_lo_v4si"
5192   [(set (match_operand:V2DF 0 "register_operand")
5193         (float:V2DF
5194           (vec_select:V2SI
5195             (match_operand:V4SI 1 "nonimmediate_operand")
5196             (parallel [(const_int 0) (const_int 1)]))))]
5197   "TARGET_SSE2")
5198
5199 (define_expand "vec_unpacks_float_hi_v8si"
5200   [(set (match_dup 2)
5201         (vec_select:V4SI
5202           (match_operand:V8SI 1 "nonimmediate_operand")
5203           (parallel [(const_int 4) (const_int 5)
5204                      (const_int 6) (const_int 7)])))
5205    (set (match_operand:V4DF 0 "register_operand")
5206         (float:V4DF
5207           (match_dup 2)))]
5208   "TARGET_AVX"
5209   "operands[2] = gen_reg_rtx (V4SImode);")
5210
5211 (define_expand "vec_unpacks_float_lo_v8si"
5212   [(set (match_operand:V4DF 0 "register_operand")
5213         (float:V4DF
5214           (vec_select:V4SI
5215             (match_operand:V8SI 1 "nonimmediate_operand")
5216             (parallel [(const_int 0) (const_int 1)
5217                        (const_int 2) (const_int 3)]))))]
5218   "TARGET_AVX")
5219
5220 (define_expand "vec_unpacks_float_hi_v16si"
5221   [(set (match_dup 2)
5222         (vec_select:V8SI
5223           (match_operand:V16SI 1 "nonimmediate_operand")
5224           (parallel [(const_int 8) (const_int 9)
5225                      (const_int 10) (const_int 11)
5226                      (const_int 12) (const_int 13)
5227                      (const_int 14) (const_int 15)])))
5228    (set (match_operand:V8DF 0 "register_operand")
5229         (float:V8DF
5230           (match_dup 2)))]
5231   "TARGET_AVX512F"
5232   "operands[2] = gen_reg_rtx (V8SImode);")
5233
5234 (define_expand "vec_unpacks_float_lo_v16si"
5235   [(set (match_operand:V8DF 0 "register_operand")
5236         (float:V8DF
5237           (vec_select:V8SI
5238             (match_operand:V16SI 1 "nonimmediate_operand")
5239             (parallel [(const_int 0) (const_int 1)
5240                        (const_int 2) (const_int 3)
5241                        (const_int 4) (const_int 5)
5242                        (const_int 6) (const_int 7)]))))]
5243   "TARGET_AVX512F")
5244
5245 (define_expand "vec_unpacku_float_hi_v4si"
5246   [(set (match_dup 5)
5247         (vec_select:V4SI
5248           (match_operand:V4SI 1 "nonimmediate_operand")
5249           (parallel [(const_int 2) (const_int 3)
5250                      (const_int 2) (const_int 3)])))
5251    (set (match_dup 6)
5252         (float:V2DF
5253           (vec_select:V2SI
5254           (match_dup 5)
5255             (parallel [(const_int 0) (const_int 1)]))))
5256    (set (match_dup 7)
5257         (lt:V2DF (match_dup 6) (match_dup 3)))
5258    (set (match_dup 8)
5259         (and:V2DF (match_dup 7) (match_dup 4)))
5260    (set (match_operand:V2DF 0 "register_operand")
5261         (plus:V2DF (match_dup 6) (match_dup 8)))]
5262   "TARGET_SSE2"
5263 {
5264   REAL_VALUE_TYPE TWO32r;
5265   rtx x;
5266   int i;
5267
5268   real_ldexp (&TWO32r, &dconst1, 32);
5269   x = const_double_from_real_value (TWO32r, DFmode);
5270
5271   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
5272   operands[4] = force_reg (V2DFmode,
5273                            ix86_build_const_vector (V2DFmode, 1, x));
5274
5275   operands[5] = gen_reg_rtx (V4SImode);
5276
5277   for (i = 6; i < 9; i++)
5278     operands[i] = gen_reg_rtx (V2DFmode);
5279 })
5280
5281 (define_expand "vec_unpacku_float_lo_v4si"
5282   [(set (match_dup 5)
5283         (float:V2DF
5284           (vec_select:V2SI
5285             (match_operand:V4SI 1 "nonimmediate_operand")
5286             (parallel [(const_int 0) (const_int 1)]))))
5287    (set (match_dup 6)
5288         (lt:V2DF (match_dup 5) (match_dup 3)))
5289    (set (match_dup 7)
5290         (and:V2DF (match_dup 6) (match_dup 4)))
5291    (set (match_operand:V2DF 0 "register_operand")
5292         (plus:V2DF (match_dup 5) (match_dup 7)))]
5293   "TARGET_SSE2"
5294 {
5295   REAL_VALUE_TYPE TWO32r;
5296   rtx x;
5297   int i;
5298
5299   real_ldexp (&TWO32r, &dconst1, 32);
5300   x = const_double_from_real_value (TWO32r, DFmode);
5301
5302   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
5303   operands[4] = force_reg (V2DFmode,
5304                            ix86_build_const_vector (V2DFmode, 1, x));
5305
5306   for (i = 5; i < 8; i++)
5307     operands[i] = gen_reg_rtx (V2DFmode);
5308 })
5309
5310 (define_expand "vec_unpacku_float_hi_v8si"
5311   [(match_operand:V4DF 0 "register_operand")
5312    (match_operand:V8SI 1 "register_operand")]
5313   "TARGET_AVX"
5314 {
5315   REAL_VALUE_TYPE TWO32r;
5316   rtx x, tmp[6];
5317   int i;
5318
5319   real_ldexp (&TWO32r, &dconst1, 32);
5320   x = const_double_from_real_value (TWO32r, DFmode);
5321
5322   tmp[0] = force_reg (V4DFmode, CONST0_RTX (V4DFmode));
5323   tmp[1] = force_reg (V4DFmode, ix86_build_const_vector (V4DFmode, 1, x));
5324   tmp[5] = gen_reg_rtx (V4SImode);
5325
5326   for (i = 2; i < 5; i++)
5327     tmp[i] = gen_reg_rtx (V4DFmode);
5328   emit_insn (gen_vec_extract_hi_v8si (tmp[5], operands[1]));
5329   emit_insn (gen_floatv4siv4df2 (tmp[2], tmp[5]));
5330   emit_insn (gen_rtx_SET (VOIDmode, tmp[3],
5331                           gen_rtx_LT (V4DFmode, tmp[2], tmp[0])));
5332   emit_insn (gen_andv4df3 (tmp[4], tmp[3], tmp[1]));
5333   emit_insn (gen_addv4df3 (operands[0], tmp[2], tmp[4]));
5334   DONE;
5335 })
5336
5337 (define_expand "vec_unpacku_float_hi_v16si"
5338   [(match_operand:V8DF 0 "register_operand")
5339    (match_operand:V16SI 1 "register_operand")]
5340   "TARGET_AVX512F"
5341 {
5342   REAL_VALUE_TYPE TWO32r;
5343   rtx k, x, tmp[4];
5344
5345   real_ldexp (&TWO32r, &dconst1, 32);
5346   x = const_double_from_real_value (TWO32r, DFmode);
5347
5348   tmp[0] = force_reg (V8DFmode, CONST0_RTX (V8DFmode));
5349   tmp[1] = force_reg (V8DFmode, ix86_build_const_vector (V8DFmode, 1, x));
5350   tmp[2] = gen_reg_rtx (V8DFmode);
5351   tmp[3] = gen_reg_rtx (V8SImode);
5352   k = gen_reg_rtx (QImode);
5353
5354   emit_insn (gen_vec_extract_hi_v16si (tmp[3], operands[1]));
5355   emit_insn (gen_floatv8siv8df2 (tmp[2], tmp[3]));
5356   emit_insn (gen_rtx_SET (VOIDmode, k,
5357                           gen_rtx_LT (QImode, tmp[2], tmp[0])));
5358   emit_insn (gen_addv8df3_mask (tmp[2], tmp[2], tmp[1], tmp[2], k));
5359   emit_move_insn (operands[0], tmp[2]);
5360   DONE;
5361 })
5362
5363 (define_expand "vec_unpacku_float_lo_v8si"
5364   [(match_operand:V4DF 0 "register_operand")
5365    (match_operand:V8SI 1 "nonimmediate_operand")]
5366   "TARGET_AVX"
5367 {
5368   REAL_VALUE_TYPE TWO32r;
5369   rtx x, tmp[5];
5370   int i;
5371
5372   real_ldexp (&TWO32r, &dconst1, 32);
5373   x = const_double_from_real_value (TWO32r, DFmode);
5374
5375   tmp[0] = force_reg (V4DFmode, CONST0_RTX (V4DFmode));
5376   tmp[1] = force_reg (V4DFmode, ix86_build_const_vector (V4DFmode, 1, x));
5377
5378   for (i = 2; i < 5; i++)
5379     tmp[i] = gen_reg_rtx (V4DFmode);
5380   emit_insn (gen_avx_cvtdq2pd256_2 (tmp[2], operands[1]));
5381   emit_insn (gen_rtx_SET (VOIDmode, tmp[3],
5382                           gen_rtx_LT (V4DFmode, tmp[2], tmp[0])));
5383   emit_insn (gen_andv4df3 (tmp[4], tmp[3], tmp[1]));
5384   emit_insn (gen_addv4df3 (operands[0], tmp[2], tmp[4]));
5385   DONE;
5386 })
5387
5388 (define_expand "vec_unpacku_float_lo_v16si"
5389   [(match_operand:V8DF 0 "register_operand")
5390    (match_operand:V16SI 1 "nonimmediate_operand")]
5391   "TARGET_AVX512F"
5392 {
5393   REAL_VALUE_TYPE TWO32r;
5394   rtx k, x, tmp[3];
5395
5396   real_ldexp (&TWO32r, &dconst1, 32);
5397   x = const_double_from_real_value (TWO32r, DFmode);
5398
5399   tmp[0] = force_reg (V8DFmode, CONST0_RTX (V8DFmode));
5400   tmp[1] = force_reg (V8DFmode, ix86_build_const_vector (V8DFmode, 1, x));
5401   tmp[2] = gen_reg_rtx (V8DFmode);
5402   k = gen_reg_rtx (QImode);
5403
5404   emit_insn (gen_avx512f_cvtdq2pd512_2 (tmp[2], operands[1]));
5405   emit_insn (gen_rtx_SET (VOIDmode, k,
5406                           gen_rtx_LT (QImode, tmp[2], tmp[0])));
5407   emit_insn (gen_addv8df3_mask (tmp[2], tmp[2], tmp[1], tmp[2], k));
5408   emit_move_insn (operands[0], tmp[2]);
5409   DONE;
5410 })
5411
5412 (define_expand "vec_pack_trunc_<mode>"
5413   [(set (match_dup 3)
5414         (float_truncate:<sf2dfmode>
5415           (match_operand:VF2_512_256 1 "nonimmediate_operand")))
5416    (set (match_dup 4)
5417         (float_truncate:<sf2dfmode>
5418           (match_operand:VF2_512_256 2 "nonimmediate_operand")))
5419    (set (match_operand:<ssePSmode> 0 "register_operand")
5420         (vec_concat:<ssePSmode>
5421           (match_dup 3)
5422           (match_dup 4)))]
5423   "TARGET_AVX"
5424 {
5425   operands[3] = gen_reg_rtx (<sf2dfmode>mode);
5426   operands[4] = gen_reg_rtx (<sf2dfmode>mode);
5427 })
5428
5429 (define_expand "vec_pack_trunc_v2df"
5430   [(match_operand:V4SF 0 "register_operand")
5431    (match_operand:V2DF 1 "nonimmediate_operand")
5432    (match_operand:V2DF 2 "nonimmediate_operand")]
5433   "TARGET_SSE2"
5434 {
5435   rtx tmp0, tmp1;
5436
5437   if (TARGET_AVX && !TARGET_PREFER_AVX128 && optimize_insn_for_speed_p ())
5438     {
5439       tmp0 = gen_reg_rtx (V4DFmode);
5440       tmp1 = force_reg (V2DFmode, operands[1]);
5441
5442       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
5443       emit_insn (gen_avx_cvtpd2ps256 (operands[0], tmp0));
5444     }
5445   else
5446     {
5447       tmp0 = gen_reg_rtx (V4SFmode);
5448       tmp1 = gen_reg_rtx (V4SFmode);
5449
5450       emit_insn (gen_sse2_cvtpd2ps (tmp0, operands[1]));
5451       emit_insn (gen_sse2_cvtpd2ps (tmp1, operands[2]));
5452       emit_insn (gen_sse_movlhps (operands[0], tmp0, tmp1));
5453     }
5454   DONE;
5455 })
5456
5457 (define_expand "vec_pack_sfix_trunc_v8df"
5458   [(match_operand:V16SI 0 "register_operand")
5459    (match_operand:V8DF 1 "nonimmediate_operand")
5460    (match_operand:V8DF 2 "nonimmediate_operand")]
5461   "TARGET_AVX512F"
5462 {
5463   rtx r1, r2;
5464
5465   r1 = gen_reg_rtx (V8SImode);
5466   r2 = gen_reg_rtx (V8SImode);
5467
5468   emit_insn (gen_fix_truncv8dfv8si2 (r1, operands[1]));
5469   emit_insn (gen_fix_truncv8dfv8si2 (r2, operands[2]));
5470   emit_insn (gen_avx_vec_concatv16si (operands[0], r1, r2));
5471   DONE;
5472 })
5473
5474 (define_expand "vec_pack_sfix_trunc_v4df"
5475   [(match_operand:V8SI 0 "register_operand")
5476    (match_operand:V4DF 1 "nonimmediate_operand")
5477    (match_operand:V4DF 2 "nonimmediate_operand")]
5478   "TARGET_AVX"
5479 {
5480   rtx r1, r2;
5481
5482   r1 = gen_reg_rtx (V4SImode);
5483   r2 = gen_reg_rtx (V4SImode);
5484
5485   emit_insn (gen_fix_truncv4dfv4si2 (r1, operands[1]));
5486   emit_insn (gen_fix_truncv4dfv4si2 (r2, operands[2]));
5487   emit_insn (gen_avx_vec_concatv8si (operands[0], r1, r2));
5488   DONE;
5489 })
5490
5491 (define_expand "vec_pack_sfix_trunc_v2df"
5492   [(match_operand:V4SI 0 "register_operand")
5493    (match_operand:V2DF 1 "nonimmediate_operand")
5494    (match_operand:V2DF 2 "nonimmediate_operand")]
5495   "TARGET_SSE2"
5496 {
5497   rtx tmp0, tmp1, tmp2;
5498
5499   if (TARGET_AVX && !TARGET_PREFER_AVX128 && optimize_insn_for_speed_p ())
5500     {
5501       tmp0 = gen_reg_rtx (V4DFmode);
5502       tmp1 = force_reg (V2DFmode, operands[1]);
5503
5504       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
5505       emit_insn (gen_fix_truncv4dfv4si2 (operands[0], tmp0));
5506     }
5507   else
5508     {
5509       tmp0 = gen_reg_rtx (V4SImode);
5510       tmp1 = gen_reg_rtx (V4SImode);
5511       tmp2 = gen_reg_rtx (V2DImode);
5512
5513       emit_insn (gen_sse2_cvttpd2dq (tmp0, operands[1]));
5514       emit_insn (gen_sse2_cvttpd2dq (tmp1, operands[2]));
5515       emit_insn (gen_vec_interleave_lowv2di (tmp2,
5516                                              gen_lowpart (V2DImode, tmp0),
5517                                              gen_lowpart (V2DImode, tmp1)));
5518       emit_move_insn (operands[0], gen_lowpart (V4SImode, tmp2));
5519     }
5520   DONE;
5521 })
5522
5523 (define_mode_attr ssepackfltmode
5524   [(V8DF "V16SI") (V4DF "V8SI") (V2DF "V4SI")])
5525
5526 (define_expand "vec_pack_ufix_trunc_<mode>"
5527   [(match_operand:<ssepackfltmode> 0 "register_operand")
5528    (match_operand:VF2 1 "register_operand")
5529    (match_operand:VF2 2 "register_operand")]
5530   "TARGET_SSE2"
5531 {
5532   if (<MODE>mode == V8DFmode)
5533     {
5534       rtx r1, r2;
5535
5536       r1 = gen_reg_rtx (V8SImode);
5537       r2 = gen_reg_rtx (V8SImode);
5538
5539       emit_insn (gen_ufix_truncv8dfv8si2 (r1, operands[1]));
5540       emit_insn (gen_ufix_truncv8dfv8si2 (r2, operands[2]));
5541       emit_insn (gen_avx_vec_concatv16si (operands[0], r1, r2));
5542     }
5543   else
5544     {
5545       rtx tmp[7];
5546       tmp[0] = ix86_expand_adjust_ufix_to_sfix_si (operands[1], &tmp[2]);
5547       tmp[1] = ix86_expand_adjust_ufix_to_sfix_si (operands[2], &tmp[3]);
5548       tmp[4] = gen_reg_rtx (<ssepackfltmode>mode);
5549       emit_insn (gen_vec_pack_sfix_trunc_<mode> (tmp[4], tmp[0], tmp[1]));
5550       if (<ssepackfltmode>mode == V4SImode || TARGET_AVX2)
5551         {
5552           tmp[5] = gen_reg_rtx (<ssepackfltmode>mode);
5553           ix86_expand_vec_extract_even_odd (tmp[5], tmp[2], tmp[3], 0);
5554         }
5555       else
5556         {
5557           tmp[5] = gen_reg_rtx (V8SFmode);
5558           ix86_expand_vec_extract_even_odd (tmp[5], gen_lowpart (V8SFmode, tmp[2]),
5559                                             gen_lowpart (V8SFmode, tmp[3]), 0);
5560           tmp[5] = gen_lowpart (V8SImode, tmp[5]);
5561         }
5562       tmp[6] = expand_simple_binop (<ssepackfltmode>mode, XOR, tmp[4], tmp[5],
5563                                     operands[0], 0, OPTAB_DIRECT);
5564       if (tmp[6] != operands[0])
5565         emit_move_insn (operands[0], tmp[6]);
5566     }
5567
5568   DONE;
5569 })
5570
5571 (define_expand "vec_pack_sfix_v4df"
5572   [(match_operand:V8SI 0 "register_operand")
5573    (match_operand:V4DF 1 "nonimmediate_operand")
5574    (match_operand:V4DF 2 "nonimmediate_operand")]
5575   "TARGET_AVX"
5576 {
5577   rtx r1, r2;
5578
5579   r1 = gen_reg_rtx (V4SImode);
5580   r2 = gen_reg_rtx (V4SImode);
5581
5582   emit_insn (gen_avx_cvtpd2dq256 (r1, operands[1]));
5583   emit_insn (gen_avx_cvtpd2dq256 (r2, operands[2]));
5584   emit_insn (gen_avx_vec_concatv8si (operands[0], r1, r2));
5585   DONE;
5586 })
5587
5588 (define_expand "vec_pack_sfix_v2df"
5589   [(match_operand:V4SI 0 "register_operand")
5590    (match_operand:V2DF 1 "nonimmediate_operand")
5591    (match_operand:V2DF 2 "nonimmediate_operand")]
5592   "TARGET_SSE2"
5593 {
5594   rtx tmp0, tmp1, tmp2;
5595
5596   if (TARGET_AVX && !TARGET_PREFER_AVX128 && optimize_insn_for_speed_p ())
5597     {
5598       tmp0 = gen_reg_rtx (V4DFmode);
5599       tmp1 = force_reg (V2DFmode, operands[1]);
5600
5601       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
5602       emit_insn (gen_avx_cvtpd2dq256 (operands[0], tmp0));
5603     }
5604   else
5605     {
5606       tmp0 = gen_reg_rtx (V4SImode);
5607       tmp1 = gen_reg_rtx (V4SImode);
5608       tmp2 = gen_reg_rtx (V2DImode);
5609
5610       emit_insn (gen_sse2_cvtpd2dq (tmp0, operands[1]));
5611       emit_insn (gen_sse2_cvtpd2dq (tmp1, operands[2]));
5612       emit_insn (gen_vec_interleave_lowv2di (tmp2,
5613                                              gen_lowpart (V2DImode, tmp0),
5614                                              gen_lowpart (V2DImode, tmp1)));
5615       emit_move_insn (operands[0], gen_lowpart (V4SImode, tmp2));
5616     }
5617   DONE;
5618 })
5619
5620 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5621 ;;
5622 ;; Parallel single-precision floating point element swizzling
5623 ;;
5624 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5625
5626 (define_expand "sse_movhlps_exp"
5627   [(set (match_operand:V4SF 0 "nonimmediate_operand")
5628         (vec_select:V4SF
5629           (vec_concat:V8SF
5630             (match_operand:V4SF 1 "nonimmediate_operand")
5631             (match_operand:V4SF 2 "nonimmediate_operand"))
5632           (parallel [(const_int 6)
5633                      (const_int 7)
5634                      (const_int 2)
5635                      (const_int 3)])))]
5636   "TARGET_SSE"
5637 {
5638   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
5639
5640   emit_insn (gen_sse_movhlps (dst, operands[1], operands[2]));
5641
5642   /* Fix up the destination if needed.  */
5643   if (dst != operands[0])
5644     emit_move_insn (operands[0], dst);
5645
5646   DONE;
5647 })
5648
5649 (define_insn "sse_movhlps"
5650   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
5651         (vec_select:V4SF
5652           (vec_concat:V8SF
5653             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
5654             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,o,o,x"))
5655           (parallel [(const_int 6)
5656                      (const_int 7)
5657                      (const_int 2)
5658                      (const_int 3)])))]
5659   "TARGET_SSE && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
5660   "@
5661    movhlps\t{%2, %0|%0, %2}
5662    vmovhlps\t{%2, %1, %0|%0, %1, %2}
5663    movlps\t{%H2, %0|%0, %H2}
5664    vmovlps\t{%H2, %1, %0|%0, %1, %H2}
5665    %vmovhps\t{%2, %0|%q0, %2}"
5666   [(set_attr "isa" "noavx,avx,noavx,avx,*")
5667    (set_attr "type" "ssemov")
5668    (set_attr "ssememalign" "64")
5669    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
5670    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
5671
5672 (define_expand "sse_movlhps_exp"
5673   [(set (match_operand:V4SF 0 "nonimmediate_operand")
5674         (vec_select:V4SF
5675           (vec_concat:V8SF
5676             (match_operand:V4SF 1 "nonimmediate_operand")
5677             (match_operand:V4SF 2 "nonimmediate_operand"))
5678           (parallel [(const_int 0)
5679                      (const_int 1)
5680                      (const_int 4)
5681                      (const_int 5)])))]
5682   "TARGET_SSE"
5683 {
5684   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
5685
5686   emit_insn (gen_sse_movlhps (dst, operands[1], operands[2]));
5687
5688   /* Fix up the destination if needed.  */
5689   if (dst != operands[0])
5690     emit_move_insn (operands[0], dst);
5691
5692   DONE;
5693 })
5694
5695 (define_insn "sse_movlhps"
5696   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
5697         (vec_select:V4SF
5698           (vec_concat:V8SF
5699             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
5700             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,m,m,x"))
5701           (parallel [(const_int 0)
5702                      (const_int 1)
5703                      (const_int 4)
5704                      (const_int 5)])))]
5705   "TARGET_SSE && ix86_binary_operator_ok (UNKNOWN, V4SFmode, operands)"
5706   "@
5707    movlhps\t{%2, %0|%0, %2}
5708    vmovlhps\t{%2, %1, %0|%0, %1, %2}
5709    movhps\t{%2, %0|%0, %q2}
5710    vmovhps\t{%2, %1, %0|%0, %1, %q2}
5711    %vmovlps\t{%2, %H0|%H0, %2}"
5712   [(set_attr "isa" "noavx,avx,noavx,avx,*")
5713    (set_attr "type" "ssemov")
5714    (set_attr "ssememalign" "64")
5715    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
5716    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
5717
5718 (define_insn "<mask_codefor>avx512f_unpckhps512<mask_name>"
5719   [(set (match_operand:V16SF 0 "register_operand" "=v")
5720         (vec_select:V16SF
5721           (vec_concat:V32SF
5722             (match_operand:V16SF 1 "register_operand" "v")
5723             (match_operand:V16SF 2 "nonimmediate_operand" "vm"))
5724           (parallel [(const_int 2) (const_int 18)
5725                      (const_int 3) (const_int 19)
5726                      (const_int 6) (const_int 22)
5727                      (const_int 7) (const_int 23)
5728                      (const_int 10) (const_int 26)
5729                      (const_int 11) (const_int 27)
5730                      (const_int 14) (const_int 30)
5731                      (const_int 15) (const_int 31)])))]
5732   "TARGET_AVX512F"
5733   "vunpckhps\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
5734   [(set_attr "type" "sselog")
5735    (set_attr "prefix" "evex")
5736    (set_attr "mode" "V16SF")])
5737
5738 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
5739 (define_insn "avx_unpckhps256<mask_name>"
5740   [(set (match_operand:V8SF 0 "register_operand" "=v")
5741         (vec_select:V8SF
5742           (vec_concat:V16SF
5743             (match_operand:V8SF 1 "register_operand" "v")
5744             (match_operand:V8SF 2 "nonimmediate_operand" "vm"))
5745           (parallel [(const_int 2) (const_int 10)
5746                      (const_int 3) (const_int 11)
5747                      (const_int 6) (const_int 14)
5748                      (const_int 7) (const_int 15)])))]
5749   "TARGET_AVX && <mask_avx512vl_condition>"
5750   "vunpckhps\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
5751   [(set_attr "type" "sselog")
5752    (set_attr "prefix" "vex")
5753    (set_attr "mode" "V8SF")])
5754
5755 (define_expand "vec_interleave_highv8sf"
5756   [(set (match_dup 3)
5757         (vec_select:V8SF
5758           (vec_concat:V16SF
5759             (match_operand:V8SF 1 "register_operand" "x")
5760             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
5761           (parallel [(const_int 0) (const_int 8)
5762                      (const_int 1) (const_int 9)
5763                      (const_int 4) (const_int 12)
5764                      (const_int 5) (const_int 13)])))
5765    (set (match_dup 4)
5766         (vec_select:V8SF
5767           (vec_concat:V16SF
5768             (match_dup 1)
5769             (match_dup 2))
5770           (parallel [(const_int 2) (const_int 10)
5771                      (const_int 3) (const_int 11)
5772                      (const_int 6) (const_int 14)
5773                      (const_int 7) (const_int 15)])))
5774    (set (match_operand:V8SF 0 "register_operand")
5775         (vec_select:V8SF
5776           (vec_concat:V16SF
5777             (match_dup 3)
5778             (match_dup 4))
5779           (parallel [(const_int 4) (const_int 5)
5780                      (const_int 6) (const_int 7)
5781                      (const_int 12) (const_int 13)
5782                      (const_int 14) (const_int 15)])))]
5783  "TARGET_AVX"
5784 {
5785   operands[3] = gen_reg_rtx (V8SFmode);
5786   operands[4] = gen_reg_rtx (V8SFmode);
5787 })
5788
5789 (define_insn "vec_interleave_highv4sf<mask_name>"
5790   [(set (match_operand:V4SF 0 "register_operand" "=x,v")
5791         (vec_select:V4SF
5792           (vec_concat:V8SF
5793             (match_operand:V4SF 1 "register_operand" "0,v")
5794             (match_operand:V4SF 2 "nonimmediate_operand" "xm,vm"))
5795           (parallel [(const_int 2) (const_int 6)
5796                      (const_int 3) (const_int 7)])))]
5797   "TARGET_SSE && <mask_avx512vl_condition>"
5798   "@
5799    unpckhps\t{%2, %0|%0, %2}
5800    vunpckhps\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
5801   [(set_attr "isa" "noavx,avx")
5802    (set_attr "type" "sselog")
5803    (set_attr "prefix" "orig,vex")
5804    (set_attr "mode" "V4SF")])
5805
5806 (define_insn "<mask_codefor>avx512f_unpcklps512<mask_name>"
5807   [(set (match_operand:V16SF 0 "register_operand" "=v")
5808         (vec_select:V16SF
5809           (vec_concat:V32SF
5810             (match_operand:V16SF 1 "register_operand" "v")
5811             (match_operand:V16SF 2 "nonimmediate_operand" "vm"))
5812           (parallel [(const_int 0) (const_int 16)
5813                      (const_int 1) (const_int 17)
5814                      (const_int 4) (const_int 20)
5815                      (const_int 5) (const_int 21)
5816                      (const_int 8) (const_int 24)
5817                      (const_int 9) (const_int 25)
5818                      (const_int 12) (const_int 28)
5819                      (const_int 13) (const_int 29)])))]
5820   "TARGET_AVX512F"
5821   "vunpcklps\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
5822   [(set_attr "type" "sselog")
5823    (set_attr "prefix" "evex")
5824    (set_attr "mode" "V16SF")])
5825
5826 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
5827 (define_insn "avx_unpcklps256<mask_name>"
5828   [(set (match_operand:V8SF 0 "register_operand" "=v")
5829         (vec_select:V8SF
5830           (vec_concat:V16SF
5831             (match_operand:V8SF 1 "register_operand" "v")
5832             (match_operand:V8SF 2 "nonimmediate_operand" "vm"))
5833           (parallel [(const_int 0) (const_int 8)
5834                      (const_int 1) (const_int 9)
5835                      (const_int 4) (const_int 12)
5836                      (const_int 5) (const_int 13)])))]
5837   "TARGET_AVX && <mask_avx512vl_condition>"
5838   "vunpcklps\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
5839   [(set_attr "type" "sselog")
5840    (set_attr "prefix" "vex")
5841    (set_attr "mode" "V8SF")])
5842
5843 (define_insn "unpcklps128_mask"
5844   [(set (match_operand:V4SF 0 "register_operand" "=v")
5845         (vec_merge:V4SF
5846           (vec_select:V4SF
5847             (vec_concat:V8SF
5848               (match_operand:V4SF 1 "register_operand" "v")
5849               (match_operand:V4SF 2 "nonimmediate_operand" "vm"))
5850             (parallel [(const_int 0) (const_int 4)
5851                       (const_int 1) (const_int 5)]))
5852           (match_operand:V4SF 3 "vector_move_operand" "0C")
5853           (match_operand:QI 4 "register_operand" "Yk")))]
5854   "TARGET_AVX512VL"
5855   "vunpcklps\t{%2, %1, %0%{%4%}%N3|%0%{%4%}%N3, %1, %2}"
5856   [(set_attr "type" "sselog")
5857    (set_attr "prefix" "evex")
5858    (set_attr "mode" "V4SF")])
5859
5860 (define_expand "vec_interleave_lowv8sf"
5861   [(set (match_dup 3)
5862         (vec_select:V8SF
5863           (vec_concat:V16SF
5864             (match_operand:V8SF 1 "register_operand" "x")
5865             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
5866           (parallel [(const_int 0) (const_int 8)
5867                      (const_int 1) (const_int 9)
5868                      (const_int 4) (const_int 12)
5869                      (const_int 5) (const_int 13)])))
5870    (set (match_dup 4)
5871         (vec_select:V8SF
5872           (vec_concat:V16SF
5873             (match_dup 1)
5874             (match_dup 2))
5875           (parallel [(const_int 2) (const_int 10)
5876                      (const_int 3) (const_int 11)
5877                      (const_int 6) (const_int 14)
5878                      (const_int 7) (const_int 15)])))
5879    (set (match_operand:V8SF 0 "register_operand")
5880         (vec_select:V8SF
5881           (vec_concat:V16SF
5882             (match_dup 3)
5883             (match_dup 4))
5884           (parallel [(const_int 0) (const_int 1)
5885                      (const_int 2) (const_int 3)
5886                      (const_int 8) (const_int 9)
5887                      (const_int 10) (const_int 11)])))]
5888  "TARGET_AVX"
5889 {
5890   operands[3] = gen_reg_rtx (V8SFmode);
5891   operands[4] = gen_reg_rtx (V8SFmode);
5892 })
5893
5894 (define_insn "vec_interleave_lowv4sf"
5895   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
5896         (vec_select:V4SF
5897           (vec_concat:V8SF
5898             (match_operand:V4SF 1 "register_operand" "0,x")
5899             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
5900           (parallel [(const_int 0) (const_int 4)
5901                      (const_int 1) (const_int 5)])))]
5902   "TARGET_SSE"
5903   "@
5904    unpcklps\t{%2, %0|%0, %2}
5905    vunpcklps\t{%2, %1, %0|%0, %1, %2}"
5906   [(set_attr "isa" "noavx,avx")
5907    (set_attr "type" "sselog")
5908    (set_attr "prefix" "orig,vex")
5909    (set_attr "mode" "V4SF")])
5910
5911 ;; These are modeled with the same vec_concat as the others so that we
5912 ;; capture users of shufps that can use the new instructions
5913 (define_insn "avx_movshdup256<mask_name>"
5914   [(set (match_operand:V8SF 0 "register_operand" "=v")
5915         (vec_select:V8SF
5916           (vec_concat:V16SF
5917             (match_operand:V8SF 1 "nonimmediate_operand" "vm")
5918             (match_dup 1))
5919           (parallel [(const_int 1) (const_int 1)
5920                      (const_int 3) (const_int 3)
5921                      (const_int 5) (const_int 5)
5922                      (const_int 7) (const_int 7)])))]
5923   "TARGET_AVX && <mask_avx512vl_condition>"
5924   "vmovshdup\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
5925   [(set_attr "type" "sse")
5926    (set_attr "prefix" "vex")
5927    (set_attr "mode" "V8SF")])
5928
5929 (define_insn "sse3_movshdup<mask_name>"
5930   [(set (match_operand:V4SF 0 "register_operand" "=v")
5931         (vec_select:V4SF
5932           (vec_concat:V8SF
5933             (match_operand:V4SF 1 "nonimmediate_operand" "vm")
5934             (match_dup 1))
5935           (parallel [(const_int 1)
5936                      (const_int 1)
5937                      (const_int 7)
5938                      (const_int 7)])))]
5939   "TARGET_SSE3 && <mask_avx512vl_condition>"
5940   "%vmovshdup\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
5941   [(set_attr "type" "sse")
5942    (set_attr "prefix_rep" "1")
5943    (set_attr "prefix" "maybe_vex")
5944    (set_attr "mode" "V4SF")])
5945
5946 (define_insn "<mask_codefor>avx512f_movshdup512<mask_name>"
5947   [(set (match_operand:V16SF 0 "register_operand" "=v")
5948         (vec_select:V16SF
5949           (vec_concat:V32SF
5950             (match_operand:V16SF 1 "nonimmediate_operand" "vm")
5951             (match_dup 1))
5952           (parallel [(const_int 1) (const_int 1)
5953                      (const_int 3) (const_int 3)
5954                      (const_int 5) (const_int 5)
5955                      (const_int 7) (const_int 7)
5956                      (const_int 9) (const_int 9)
5957                      (const_int 11) (const_int 11)
5958                      (const_int 13) (const_int 13)
5959                      (const_int 15) (const_int 15)])))]
5960   "TARGET_AVX512F"
5961   "vmovshdup\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
5962   [(set_attr "type" "sse")
5963    (set_attr "prefix" "evex")
5964    (set_attr "mode" "V16SF")])
5965
5966 (define_insn "avx_movsldup256<mask_name>"
5967   [(set (match_operand:V8SF 0 "register_operand" "=v")
5968         (vec_select:V8SF
5969           (vec_concat:V16SF
5970             (match_operand:V8SF 1 "nonimmediate_operand" "vm")
5971             (match_dup 1))
5972           (parallel [(const_int 0) (const_int 0)
5973                      (const_int 2) (const_int 2)
5974                      (const_int 4) (const_int 4)
5975                      (const_int 6) (const_int 6)])))]
5976   "TARGET_AVX && <mask_avx512vl_condition>"
5977   "vmovsldup\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
5978   [(set_attr "type" "sse")
5979    (set_attr "prefix" "vex")
5980    (set_attr "mode" "V8SF")])
5981
5982 (define_insn "sse3_movsldup<mask_name>"
5983   [(set (match_operand:V4SF 0 "register_operand" "=v")
5984         (vec_select:V4SF
5985           (vec_concat:V8SF
5986             (match_operand:V4SF 1 "nonimmediate_operand" "vm")
5987             (match_dup 1))
5988           (parallel [(const_int 0)
5989                      (const_int 0)
5990                      (const_int 6)
5991                      (const_int 6)])))]
5992   "TARGET_SSE3 && <mask_avx512vl_condition>"
5993   "%vmovsldup\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
5994   [(set_attr "type" "sse")
5995    (set_attr "prefix_rep" "1")
5996    (set_attr "prefix" "maybe_vex")
5997    (set_attr "mode" "V4SF")])
5998
5999 (define_insn "<mask_codefor>avx512f_movsldup512<mask_name>"
6000   [(set (match_operand:V16SF 0 "register_operand" "=v")
6001         (vec_select:V16SF
6002           (vec_concat:V32SF
6003             (match_operand:V16SF 1 "nonimmediate_operand" "vm")
6004             (match_dup 1))
6005           (parallel [(const_int 0) (const_int 0)
6006                      (const_int 2) (const_int 2)
6007                      (const_int 4) (const_int 4)
6008                      (const_int 6) (const_int 6)
6009                      (const_int 8) (const_int 8)
6010                      (const_int 10) (const_int 10)
6011                      (const_int 12) (const_int 12)
6012                      (const_int 14) (const_int 14)])))]
6013   "TARGET_AVX512F"
6014   "vmovsldup\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
6015   [(set_attr "type" "sse")
6016    (set_attr "prefix" "evex")
6017    (set_attr "mode" "V16SF")])
6018
6019 (define_expand "avx_shufps256<mask_expand4_name>"
6020   [(match_operand:V8SF 0 "register_operand")
6021    (match_operand:V8SF 1 "register_operand")
6022    (match_operand:V8SF 2 "nonimmediate_operand")
6023    (match_operand:SI 3 "const_int_operand")]
6024   "TARGET_AVX"
6025 {
6026   int mask = INTVAL (operands[3]);
6027   emit_insn (gen_avx_shufps256_1<mask_expand4_name> (operands[0],
6028                                                      operands[1],
6029                                                      operands[2],
6030                                                      GEN_INT ((mask >> 0) & 3),
6031                                                      GEN_INT ((mask >> 2) & 3),
6032                                                      GEN_INT (((mask >> 4) & 3) + 8),
6033                                                      GEN_INT (((mask >> 6) & 3) + 8),
6034                                                      GEN_INT (((mask >> 0) & 3) + 4),
6035                                                      GEN_INT (((mask >> 2) & 3) + 4),
6036                                                      GEN_INT (((mask >> 4) & 3) + 12),
6037                                                      GEN_INT (((mask >> 6) & 3) + 12)
6038                                                      <mask_expand4_args>));
6039   DONE;
6040 })
6041
6042 ;; One bit in mask selects 2 elements.
6043 (define_insn "avx_shufps256_1<mask_name>"
6044   [(set (match_operand:V8SF 0 "register_operand" "=v")
6045         (vec_select:V8SF
6046           (vec_concat:V16SF
6047             (match_operand:V8SF 1 "register_operand" "v")
6048             (match_operand:V8SF 2 "nonimmediate_operand" "vm"))
6049           (parallel [(match_operand 3  "const_0_to_3_operand"  )
6050                      (match_operand 4  "const_0_to_3_operand"  )
6051                      (match_operand 5  "const_8_to_11_operand" )
6052                      (match_operand 6  "const_8_to_11_operand" )
6053                      (match_operand 7  "const_4_to_7_operand"  )
6054                      (match_operand 8  "const_4_to_7_operand"  )
6055                      (match_operand 9  "const_12_to_15_operand")
6056                      (match_operand 10 "const_12_to_15_operand")])))]
6057   "TARGET_AVX
6058    && <mask_avx512vl_condition>
6059    && (INTVAL (operands[3]) == (INTVAL (operands[7]) - 4)
6060        && INTVAL (operands[4]) == (INTVAL (operands[8]) - 4)
6061        && INTVAL (operands[5]) == (INTVAL (operands[9]) - 4)
6062        && INTVAL (operands[6]) == (INTVAL (operands[10]) - 4))"
6063 {
6064   int mask;
6065   mask = INTVAL (operands[3]);
6066   mask |= INTVAL (operands[4]) << 2;
6067   mask |= (INTVAL (operands[5]) - 8) << 4;
6068   mask |= (INTVAL (operands[6]) - 8) << 6;
6069   operands[3] = GEN_INT (mask);
6070
6071   return "vshufps\t{%3, %2, %1, %0<mask_operand11>|%0<mask_operand11>, %1, %2, %3}";
6072 }
6073   [(set_attr "type" "sseshuf")
6074    (set_attr "length_immediate" "1")
6075    (set_attr "prefix" "<mask_prefix>")
6076    (set_attr "mode" "V8SF")])
6077
6078 (define_expand "sse_shufps<mask_expand4_name>"
6079   [(match_operand:V4SF 0 "register_operand")
6080    (match_operand:V4SF 1 "register_operand")
6081    (match_operand:V4SF 2 "nonimmediate_operand")
6082    (match_operand:SI 3 "const_int_operand")]
6083   "TARGET_SSE"
6084 {
6085   int mask = INTVAL (operands[3]);
6086   emit_insn (gen_sse_shufps_v4sf<mask_expand4_name> (operands[0],
6087                                                      operands[1],
6088                                                      operands[2],
6089                                                      GEN_INT ((mask >> 0) & 3),
6090                                                      GEN_INT ((mask >> 2) & 3),
6091                                                      GEN_INT (((mask >> 4) & 3) + 4),
6092                                                      GEN_INT (((mask >> 6) & 3) + 4)
6093                                                      <mask_expand4_args>));
6094   DONE;
6095 })
6096
6097 (define_insn "sse_shufps_v4sf_mask"
6098   [(set (match_operand:V4SF 0 "register_operand" "=v")
6099     (vec_merge:V4SF
6100           (vec_select:V4SF
6101             (vec_concat:V8SF
6102               (match_operand:V4SF 1 "register_operand" "v")
6103               (match_operand:V4SF 2 "nonimmediate_operand" "vm"))
6104             (parallel [(match_operand 3 "const_0_to_3_operand")
6105                        (match_operand 4 "const_0_to_3_operand")
6106                        (match_operand 5 "const_4_to_7_operand")
6107                        (match_operand 6 "const_4_to_7_operand")]))
6108       (match_operand:V4SF 7 "vector_move_operand" "0C")
6109       (match_operand:QI 8 "register_operand" "Yk")))]
6110   "TARGET_AVX512VL"
6111 {
6112   int mask = 0;
6113   mask |= INTVAL (operands[3]) << 0;
6114   mask |= INTVAL (operands[4]) << 2;
6115   mask |= (INTVAL (operands[5]) - 4) << 4;
6116   mask |= (INTVAL (operands[6]) - 4) << 6;
6117   operands[3] = GEN_INT (mask);
6118
6119   return "vshufps\t{%3, %2, %1, %0%{%8%}%N7|%0%{%8%}%N7, %1, %2, %3}";
6120 }
6121   [(set_attr "type" "sseshuf")
6122    (set_attr "length_immediate" "1")
6123    (set_attr "prefix" "evex")
6124    (set_attr "mode" "V4SF")])
6125
6126 (define_insn "sse_shufps_<mode>"
6127   [(set (match_operand:VI4F_128 0 "register_operand" "=x,x")
6128         (vec_select:VI4F_128
6129           (vec_concat:<ssedoublevecmode>
6130             (match_operand:VI4F_128 1 "register_operand" "0,x")
6131             (match_operand:VI4F_128 2 "nonimmediate_operand" "xm,xm"))
6132           (parallel [(match_operand 3 "const_0_to_3_operand")
6133                      (match_operand 4 "const_0_to_3_operand")
6134                      (match_operand 5 "const_4_to_7_operand")
6135                      (match_operand 6 "const_4_to_7_operand")])))]
6136   "TARGET_SSE"
6137 {
6138   int mask = 0;
6139   mask |= INTVAL (operands[3]) << 0;
6140   mask |= INTVAL (operands[4]) << 2;
6141   mask |= (INTVAL (operands[5]) - 4) << 4;
6142   mask |= (INTVAL (operands[6]) - 4) << 6;
6143   operands[3] = GEN_INT (mask);
6144
6145   switch (which_alternative)
6146     {
6147     case 0:
6148       return "shufps\t{%3, %2, %0|%0, %2, %3}";
6149     case 1:
6150       return "vshufps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
6151     default:
6152       gcc_unreachable ();
6153     }
6154 }
6155   [(set_attr "isa" "noavx,avx")
6156    (set_attr "type" "sseshuf")
6157    (set_attr "length_immediate" "1")
6158    (set_attr "prefix" "orig,vex")
6159    (set_attr "mode" "V4SF")])
6160
6161 (define_insn "sse_storehps"
6162   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=m,x,x")
6163         (vec_select:V2SF
6164           (match_operand:V4SF 1 "nonimmediate_operand" "x,x,o")
6165           (parallel [(const_int 2) (const_int 3)])))]
6166   "TARGET_SSE"
6167   "@
6168    %vmovhps\t{%1, %0|%q0, %1}
6169    %vmovhlps\t{%1, %d0|%d0, %1}
6170    %vmovlps\t{%H1, %d0|%d0, %H1}"
6171   [(set_attr "type" "ssemov")
6172    (set_attr "ssememalign" "64")
6173    (set_attr "prefix" "maybe_vex")
6174    (set_attr "mode" "V2SF,V4SF,V2SF")])
6175
6176 (define_expand "sse_loadhps_exp"
6177   [(set (match_operand:V4SF 0 "nonimmediate_operand")
6178         (vec_concat:V4SF
6179           (vec_select:V2SF
6180             (match_operand:V4SF 1 "nonimmediate_operand")
6181             (parallel [(const_int 0) (const_int 1)]))
6182           (match_operand:V2SF 2 "nonimmediate_operand")))]
6183   "TARGET_SSE"
6184 {
6185   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
6186
6187   emit_insn (gen_sse_loadhps (dst, operands[1], operands[2]));
6188
6189   /* Fix up the destination if needed.  */
6190   if (dst != operands[0])
6191     emit_move_insn (operands[0], dst);
6192
6193   DONE;
6194 })
6195
6196 (define_insn "sse_loadhps"
6197   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
6198         (vec_concat:V4SF
6199           (vec_select:V2SF
6200             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
6201             (parallel [(const_int 0) (const_int 1)]))
6202           (match_operand:V2SF 2 "nonimmediate_operand"   " m,m,x,x,x")))]
6203   "TARGET_SSE"
6204   "@
6205    movhps\t{%2, %0|%0, %q2}
6206    vmovhps\t{%2, %1, %0|%0, %1, %q2}
6207    movlhps\t{%2, %0|%0, %2}
6208    vmovlhps\t{%2, %1, %0|%0, %1, %2}
6209    %vmovlps\t{%2, %H0|%H0, %2}"
6210   [(set_attr "isa" "noavx,avx,noavx,avx,*")
6211    (set_attr "type" "ssemov")
6212    (set_attr "ssememalign" "64")
6213    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
6214    (set_attr "mode" "V2SF,V2SF,V4SF,V4SF,V2SF")])
6215
6216 (define_insn "sse_storelps"
6217   [(set (match_operand:V2SF 0 "nonimmediate_operand"   "=m,x,x")
6218         (vec_select:V2SF
6219           (match_operand:V4SF 1 "nonimmediate_operand" " x,x,m")
6220           (parallel [(const_int 0) (const_int 1)])))]
6221   "TARGET_SSE"
6222   "@
6223    %vmovlps\t{%1, %0|%q0, %1}
6224    %vmovaps\t{%1, %0|%0, %1}
6225    %vmovlps\t{%1, %d0|%d0, %q1}"
6226   [(set_attr "type" "ssemov")
6227    (set_attr "prefix" "maybe_vex")
6228    (set_attr "mode" "V2SF,V4SF,V2SF")])
6229
6230 (define_expand "sse_loadlps_exp"
6231   [(set (match_operand:V4SF 0 "nonimmediate_operand")
6232         (vec_concat:V4SF
6233           (match_operand:V2SF 2 "nonimmediate_operand")
6234           (vec_select:V2SF
6235             (match_operand:V4SF 1 "nonimmediate_operand")
6236             (parallel [(const_int 2) (const_int 3)]))))]
6237   "TARGET_SSE"
6238 {
6239   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
6240
6241   emit_insn (gen_sse_loadlps (dst, operands[1], operands[2]));
6242
6243   /* Fix up the destination if needed.  */
6244   if (dst != operands[0])
6245     emit_move_insn (operands[0], dst);
6246
6247   DONE;
6248 })
6249
6250 (define_insn "sse_loadlps"
6251   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
6252         (vec_concat:V4SF
6253           (match_operand:V2SF 2 "nonimmediate_operand"   " 0,x,m,m,x")
6254           (vec_select:V2SF
6255             (match_operand:V4SF 1 "nonimmediate_operand" " x,x,0,x,0")
6256             (parallel [(const_int 2) (const_int 3)]))))]
6257   "TARGET_SSE"
6258   "@
6259    shufps\t{$0xe4, %1, %0|%0, %1, 0xe4}
6260    vshufps\t{$0xe4, %1, %2, %0|%0, %2, %1, 0xe4}
6261    movlps\t{%2, %0|%0, %q2}
6262    vmovlps\t{%2, %1, %0|%0, %1, %q2}
6263    %vmovlps\t{%2, %0|%q0, %2}"
6264   [(set_attr "isa" "noavx,avx,noavx,avx,*")
6265    (set_attr "type" "sseshuf,sseshuf,ssemov,ssemov,ssemov")
6266    (set_attr "ssememalign" "64")
6267    (set_attr "length_immediate" "1,1,*,*,*")
6268    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
6269    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
6270
6271 (define_insn "sse_movss"
6272   [(set (match_operand:V4SF 0 "register_operand"   "=x,x")
6273         (vec_merge:V4SF
6274           (match_operand:V4SF 2 "register_operand" " x,x")
6275           (match_operand:V4SF 1 "register_operand" " 0,x")
6276           (const_int 1)))]
6277   "TARGET_SSE"
6278   "@
6279    movss\t{%2, %0|%0, %2}
6280    vmovss\t{%2, %1, %0|%0, %1, %2}"
6281   [(set_attr "isa" "noavx,avx")
6282    (set_attr "type" "ssemov")
6283    (set_attr "prefix" "orig,vex")
6284    (set_attr "mode" "SF")])
6285
6286 (define_insn "avx2_vec_dup<mode>"
6287   [(set (match_operand:VF1_128_256 0 "register_operand" "=x")
6288         (vec_duplicate:VF1_128_256
6289           (vec_select:SF
6290             (match_operand:V4SF 1 "register_operand" "x")
6291             (parallel [(const_int 0)]))))]
6292   "TARGET_AVX2"
6293   "vbroadcastss\t{%1, %0|%0, %1}"
6294   [(set_attr "type" "sselog1")
6295     (set_attr "prefix" "vex")
6296     (set_attr "mode" "<MODE>")])
6297
6298 (define_insn "avx2_vec_dupv8sf_1"
6299   [(set (match_operand:V8SF 0 "register_operand" "=x")
6300         (vec_duplicate:V8SF
6301           (vec_select:SF
6302             (match_operand:V8SF 1 "register_operand" "x")
6303             (parallel [(const_int 0)]))))]
6304   "TARGET_AVX2"
6305   "vbroadcastss\t{%x1, %0|%0, %x1}"
6306   [(set_attr "type" "sselog1")
6307     (set_attr "prefix" "vex")
6308     (set_attr "mode" "V8SF")])
6309
6310 (define_insn "avx512f_vec_dup<mode>_1"
6311   [(set (match_operand:VF_512 0 "register_operand" "=v")
6312         (vec_duplicate:VF_512
6313           (vec_select:<ssescalarmode>
6314             (match_operand:VF_512 1 "register_operand" "v")
6315             (parallel [(const_int 0)]))))]
6316   "TARGET_AVX512F"
6317   "vbroadcast<bcstscalarsuff>\t{%x1, %0|%0, %x1}"
6318   [(set_attr "type" "sselog1")
6319     (set_attr "prefix" "evex")
6320     (set_attr "mode" "<MODE>")])
6321
6322 ;; Although insertps takes register source, we prefer
6323 ;; unpcklps with register source since it is shorter.
6324 (define_insn "*vec_concatv2sf_sse4_1"
6325   [(set (match_operand:V2SF 0 "register_operand"     "=Yr,*x,x,Yr,*x,x,x,*y ,*y")
6326         (vec_concat:V2SF
6327           (match_operand:SF 1 "nonimmediate_operand" "  0, 0,x, 0,0, x,m, 0 , m")
6328           (match_operand:SF 2 "vector_move_operand"  " Yr,*x,x, m,m, m,C,*ym, C")))]
6329   "TARGET_SSE4_1"
6330   "@
6331    unpcklps\t{%2, %0|%0, %2}
6332    unpcklps\t{%2, %0|%0, %2}
6333    vunpcklps\t{%2, %1, %0|%0, %1, %2}
6334    insertps\t{$0x10, %2, %0|%0, %2, 0x10}
6335    insertps\t{$0x10, %2, %0|%0, %2, 0x10}
6336    vinsertps\t{$0x10, %2, %1, %0|%0, %1, %2, 0x10}
6337    %vmovss\t{%1, %0|%0, %1}
6338    punpckldq\t{%2, %0|%0, %2}
6339    movd\t{%1, %0|%0, %1}"
6340   [(set_attr "isa" "noavx,noavx,avx,noavx,noavx,avx,*,*,*")
6341    (set_attr "type" "sselog,sselog,sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
6342    (set_attr "prefix_data16" "*,*,*,1,1,*,*,*,*")
6343    (set_attr "prefix_extra" "*,*,*,1,1,1,*,*,*")
6344    (set_attr "length_immediate" "*,*,*,1,1,1,*,*,*")
6345    (set_attr "prefix" "orig,orig,vex,orig,orig,vex,maybe_vex,orig,orig")
6346    (set_attr "mode" "V4SF,V4SF,V4SF,V4SF,V4SF,V4SF,SF,DI,DI")])
6347
6348 ;; ??? In theory we can match memory for the MMX alternative, but allowing
6349 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
6350 ;; alternatives pretty much forces the MMX alternative to be chosen.
6351 (define_insn "*vec_concatv2sf_sse"
6352   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,*y,*y")
6353         (vec_concat:V2SF
6354           (match_operand:SF 1 "nonimmediate_operand" " 0,m, 0, m")
6355           (match_operand:SF 2 "reg_or_0_operand"     " x,C,*y, C")))]
6356   "TARGET_SSE"
6357   "@
6358    unpcklps\t{%2, %0|%0, %2}
6359    movss\t{%1, %0|%0, %1}
6360    punpckldq\t{%2, %0|%0, %2}
6361    movd\t{%1, %0|%0, %1}"
6362   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
6363    (set_attr "mode" "V4SF,SF,DI,DI")])
6364
6365 (define_insn "*vec_concatv4sf"
6366   [(set (match_operand:V4SF 0 "register_operand"       "=x,x,x,x")
6367         (vec_concat:V4SF
6368           (match_operand:V2SF 1 "register_operand"     " 0,x,0,x")
6369           (match_operand:V2SF 2 "nonimmediate_operand" " x,x,m,m")))]
6370   "TARGET_SSE"
6371   "@
6372    movlhps\t{%2, %0|%0, %2}
6373    vmovlhps\t{%2, %1, %0|%0, %1, %2}
6374    movhps\t{%2, %0|%0, %q2}
6375    vmovhps\t{%2, %1, %0|%0, %1, %q2}"
6376   [(set_attr "isa" "noavx,avx,noavx,avx")
6377    (set_attr "type" "ssemov")
6378    (set_attr "prefix" "orig,vex,orig,vex")
6379    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF")])
6380
6381 (define_expand "vec_init<mode>"
6382   [(match_operand:V_128 0 "register_operand")
6383    (match_operand 1)]
6384   "TARGET_SSE"
6385 {
6386   ix86_expand_vector_init (false, operands[0], operands[1]);
6387   DONE;
6388 })
6389
6390 ;; Avoid combining registers from different units in a single alternative,
6391 ;; see comment above inline_secondary_memory_needed function in i386.c
6392 (define_insn "vec_set<mode>_0"
6393   [(set (match_operand:VI4F_128 0 "nonimmediate_operand"
6394           "=Yr,*v,v,Yi,x,x,v,Yr ,*x ,x  ,m ,m   ,m")
6395         (vec_merge:VI4F_128
6396           (vec_duplicate:VI4F_128
6397             (match_operand:<ssescalarmode> 2 "general_operand"
6398           " Yr,*v,m,r ,m,x,v,*rm,*rm,*rm,!x,!*re,!*fF"))
6399           (match_operand:VI4F_128 1 "vector_move_operand"
6400           " C , C,C,C ,C,0,v,0  ,0  ,x  ,0 ,0   ,0")
6401           (const_int 1)))]
6402   "TARGET_SSE"
6403   "@
6404    %vinsertps\t{$0xe, %d2, %0|%0, %d2, 0xe}
6405    %vinsertps\t{$0xe, %d2, %0|%0, %d2, 0xe}
6406    %vmov<ssescalarmodesuffix>\t{%2, %0|%0, %2}
6407    %vmovd\t{%2, %0|%0, %2}
6408    movss\t{%2, %0|%0, %2}
6409    movss\t{%2, %0|%0, %2}
6410    vmovss\t{%2, %1, %0|%0, %1, %2}
6411    pinsrd\t{$0, %2, %0|%0, %2, 0}
6412    pinsrd\t{$0, %2, %0|%0, %2, 0}
6413    vpinsrd\t{$0, %2, %1, %0|%0, %1, %2, 0}
6414    #
6415    #
6416    #"
6417   [(set_attr "isa" "sse4,sse4,sse2,sse2,noavx,noavx,avx,sse4_noavx,sse4_noavx,avx,*,*,*")
6418    (set (attr "type")
6419      (cond [(eq_attr "alternative" "0,1,7,8,9")
6420               (const_string "sselog")
6421             (eq_attr "alternative" "11")
6422               (const_string "imov")
6423             (eq_attr "alternative" "12")
6424               (const_string "fmov")
6425            ]
6426            (const_string "ssemov")))
6427    (set_attr "prefix_extra" "*,*,*,*,*,*,*,1,1,1,*,*,*")
6428    (set_attr "length_immediate" "*,*,*,*,*,*,*,1,1,1,*,*,*")
6429    (set_attr "prefix" "maybe_vex,maybe_vex,maybe_vex,maybe_vex,orig,orig,vex,orig,orig,vex,*,*,*")
6430    (set_attr "mode" "SF,SF,<ssescalarmode>,SI,SF,SF,SF,TI,TI,TI,*,*,*")])
6431
6432 ;; A subset is vec_setv4sf.
6433 (define_insn "*vec_setv4sf_sse4_1"
6434   [(set (match_operand:V4SF 0 "register_operand" "=Yr,*x,x")
6435         (vec_merge:V4SF
6436           (vec_duplicate:V4SF
6437             (match_operand:SF 2 "nonimmediate_operand" "Yrm,*xm,xm"))
6438           (match_operand:V4SF 1 "register_operand" "0,0,x")
6439           (match_operand:SI 3 "const_int_operand")))]
6440   "TARGET_SSE4_1
6441    && ((unsigned) exact_log2 (INTVAL (operands[3]))
6442        < GET_MODE_NUNITS (V4SFmode))"
6443 {
6444   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])) << 4);
6445   switch (which_alternative)
6446     {
6447     case 0:
6448     case 1:
6449       return "insertps\t{%3, %2, %0|%0, %2, %3}";
6450     case 2:
6451       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
6452     default:
6453       gcc_unreachable ();
6454     }
6455 }
6456   [(set_attr "isa" "noavx,noavx,avx")
6457    (set_attr "type" "sselog")
6458    (set_attr "prefix_data16" "1,1,*")
6459    (set_attr "prefix_extra" "1")
6460    (set_attr "length_immediate" "1")
6461    (set_attr "prefix" "orig,orig,vex")
6462    (set_attr "mode" "V4SF")])
6463
6464 (define_insn "sse4_1_insertps"
6465   [(set (match_operand:V4SF 0 "register_operand" "=Yr,*x,x")
6466         (unspec:V4SF [(match_operand:V4SF 2 "nonimmediate_operand" "Yrm,*xm,xm")
6467                       (match_operand:V4SF 1 "register_operand" "0,0,x")
6468                       (match_operand:SI 3 "const_0_to_255_operand" "n,n,n")]
6469                      UNSPEC_INSERTPS))]
6470   "TARGET_SSE4_1"
6471 {
6472   if (MEM_P (operands[2]))
6473     {
6474       unsigned count_s = INTVAL (operands[3]) >> 6;
6475       if (count_s)
6476         operands[3] = GEN_INT (INTVAL (operands[3]) & 0x3f);
6477       operands[2] = adjust_address_nv (operands[2], SFmode, count_s * 4);
6478     }
6479   switch (which_alternative)
6480     {
6481     case 0:
6482     case 1:
6483       return "insertps\t{%3, %2, %0|%0, %2, %3}";
6484     case 2:
6485       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
6486     default:
6487       gcc_unreachable ();
6488     }
6489 }
6490   [(set_attr "isa" "noavx,noavx,avx")
6491    (set_attr "type" "sselog")
6492    (set_attr "prefix_data16" "1,1,*")
6493    (set_attr "prefix_extra" "1")
6494    (set_attr "length_immediate" "1")
6495    (set_attr "prefix" "orig,orig,vex")
6496    (set_attr "mode" "V4SF")])
6497
6498 (define_split
6499   [(set (match_operand:VI4F_128 0 "memory_operand")
6500         (vec_merge:VI4F_128
6501           (vec_duplicate:VI4F_128
6502             (match_operand:<ssescalarmode> 1 "nonmemory_operand"))
6503           (match_dup 0)
6504           (const_int 1)))]
6505   "TARGET_SSE && reload_completed"
6506   [(set (match_dup 0) (match_dup 1))]
6507   "operands[0] = adjust_address (operands[0], <ssescalarmode>mode, 0);")
6508
6509 (define_expand "vec_set<mode>"
6510   [(match_operand:V 0 "register_operand")
6511    (match_operand:<ssescalarmode> 1 "register_operand")
6512    (match_operand 2 "const_int_operand")]
6513   "TARGET_SSE"
6514 {
6515   ix86_expand_vector_set (false, operands[0], operands[1],
6516                           INTVAL (operands[2]));
6517   DONE;
6518 })
6519
6520 (define_insn_and_split "*vec_extractv4sf_0"
6521   [(set (match_operand:SF 0 "nonimmediate_operand" "=x,m,f,r")
6522         (vec_select:SF
6523           (match_operand:V4SF 1 "nonimmediate_operand" "xm,x,m,m")
6524           (parallel [(const_int 0)])))]
6525   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
6526   "#"
6527   "&& reload_completed"
6528   [(set (match_dup 0) (match_dup 1))]
6529 {
6530   if (REG_P (operands[1]))
6531     operands[1] = gen_rtx_REG (SFmode, REGNO (operands[1]));
6532   else
6533     operands[1] = adjust_address (operands[1], SFmode, 0);
6534 })
6535
6536 (define_insn_and_split "*sse4_1_extractps"
6537   [(set (match_operand:SF 0 "nonimmediate_operand" "=rm,rm,x,x")
6538         (vec_select:SF
6539           (match_operand:V4SF 1 "register_operand" "Yr,*x,0,x")
6540           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n,n,n,n")])))]
6541   "TARGET_SSE4_1"
6542   "@
6543    %vextractps\t{%2, %1, %0|%0, %1, %2}
6544    %vextractps\t{%2, %1, %0|%0, %1, %2}
6545    #
6546    #"
6547   "&& reload_completed && SSE_REG_P (operands[0])"
6548   [(const_int 0)]
6549 {
6550   rtx dest = gen_rtx_REG (V4SFmode, REGNO (operands[0]));
6551   switch (INTVAL (operands[2]))
6552     {
6553     case 1:
6554     case 3:
6555       emit_insn (gen_sse_shufps_v4sf (dest, operands[1], operands[1],
6556                                       operands[2], operands[2],
6557                                       GEN_INT (INTVAL (operands[2]) + 4),
6558                                       GEN_INT (INTVAL (operands[2]) + 4)));
6559       break;
6560     case 2:
6561       emit_insn (gen_vec_interleave_highv4sf (dest, operands[1], operands[1]));
6562       break;
6563     default:
6564       /* 0 should be handled by the *vec_extractv4sf_0 pattern above.  */
6565       gcc_unreachable ();
6566     }
6567   DONE;
6568 }
6569   [(set_attr "isa" "*,*,noavx,avx")
6570    (set_attr "type" "sselog,sselog,*,*")
6571    (set_attr "prefix_data16" "1,1,*,*")
6572    (set_attr "prefix_extra" "1,1,*,*")
6573    (set_attr "length_immediate" "1,1,*,*")
6574    (set_attr "prefix" "maybe_vex,maybe_vex,*,*")
6575    (set_attr "mode" "V4SF,V4SF,*,*")])
6576
6577 (define_insn_and_split "*vec_extractv4sf_mem"
6578   [(set (match_operand:SF 0 "register_operand" "=x,*r,f")
6579         (vec_select:SF
6580           (match_operand:V4SF 1 "memory_operand" "o,o,o")
6581           (parallel [(match_operand 2 "const_0_to_3_operand" "n,n,n")])))]
6582   "TARGET_SSE"
6583   "#"
6584   "&& reload_completed"
6585   [(set (match_dup 0) (match_dup 1))]
6586 {
6587   operands[1] = adjust_address (operands[1], SFmode, INTVAL (operands[2]) * 4);
6588 })
6589
6590 (define_mode_attr extract_type
6591   [(V16SF "avx512f") (V16SI "avx512f") (V8DF "avx512dq") (V8DI "avx512dq")])
6592
6593 (define_mode_attr extract_suf
6594   [(V16SF "32x4") (V16SI "32x4") (V8DF "64x2") (V8DI "64x2")])
6595
6596 (define_mode_iterator AVX512_VEC
6597   [(V8DF "TARGET_AVX512DQ") (V8DI "TARGET_AVX512DQ") V16SF V16SI])
6598
6599 (define_expand "<extract_type>_vextract<shuffletype><extract_suf>_mask"
6600   [(match_operand:<ssequartermode> 0 "nonimmediate_operand")
6601    (match_operand:AVX512_VEC 1 "register_operand")
6602    (match_operand:SI 2 "const_0_to_3_operand")
6603    (match_operand:<ssequartermode> 3 "nonimmediate_operand")
6604    (match_operand:QI 4 "register_operand")]
6605   "TARGET_AVX512F"
6606 {
6607   int mask;
6608   mask = INTVAL (operands[2]);
6609
6610   if (MEM_P (operands[0]) && GET_CODE (operands[3]) == CONST_VECTOR)
6611     operands[0] = force_reg (<ssequartermode>mode, operands[0]);
6612
6613   if (<MODE>mode == V16SImode || <MODE>mode == V16SFmode)
6614     emit_insn (gen_avx512f_vextract<shuffletype>32x4_1_mask (operands[0],
6615         operands[1], GEN_INT (mask * 4), GEN_INT (mask * 4 + 1),
6616         GEN_INT (mask * 4 + 2), GEN_INT (mask * 4 + 3), operands[3],
6617         operands[4]));
6618   else
6619     emit_insn (gen_avx512dq_vextract<shuffletype>64x2_1_mask (operands[0],
6620         operands[1], GEN_INT (mask * 2), GEN_INT (mask * 2 + 1), operands[3],
6621         operands[4]));
6622   DONE;
6623 })
6624
6625 (define_insn "avx512dq_vextract<shuffletype>64x2_1_maskm"
6626   [(set (match_operand:<ssequartermode> 0 "memory_operand" "=m")
6627         (vec_merge:<ssequartermode>
6628           (vec_select:<ssequartermode>
6629             (match_operand:V8FI 1 "register_operand" "v")
6630             (parallel [(match_operand 2  "const_0_to_7_operand")
6631               (match_operand 3  "const_0_to_7_operand")]))
6632           (match_operand:<ssequartermode> 4 "memory_operand" "0")
6633           (match_operand:QI 5 "register_operand" "k")))]
6634   "TARGET_AVX512DQ
6635    && (INTVAL (operands[2]) % 2 == 0)
6636    && (INTVAL (operands[2]) == INTVAL (operands[3]) - 1 )"
6637 {
6638   operands[2] = GEN_INT ((INTVAL (operands[2])) >> 1);
6639   return "vextract<shuffletype>64x2\t{%2, %1, %0%{%5%}|%0%{%5%}, %1, %2}";
6640 }
6641   [(set_attr "type" "sselog")
6642    (set_attr "prefix_extra" "1")
6643    (set_attr "length_immediate" "1")
6644    (set_attr "memory" "store")
6645    (set_attr "prefix" "evex")
6646    (set_attr "mode" "<sseinsnmode>")])
6647
6648 (define_insn "avx512f_vextract<shuffletype>32x4_1_maskm"
6649   [(set (match_operand:<ssequartermode> 0 "memory_operand" "=m")
6650         (vec_merge:<ssequartermode>
6651           (vec_select:<ssequartermode>
6652             (match_operand:V16FI 1 "register_operand" "v")
6653             (parallel [(match_operand 2  "const_0_to_15_operand")
6654               (match_operand 3  "const_0_to_15_operand")
6655               (match_operand 4  "const_0_to_15_operand")
6656               (match_operand 5  "const_0_to_15_operand")]))
6657           (match_operand:<ssequartermode> 6 "memory_operand" "0")
6658           (match_operand:QI 7 "register_operand" "Yk")))]
6659   "TARGET_AVX512F
6660    && ((INTVAL (operands[2]) % 4 == 0)
6661        && INTVAL (operands[2]) == (INTVAL (operands[3]) - 1)
6662        && INTVAL (operands[3]) == (INTVAL (operands[4]) - 1)
6663        && INTVAL (operands[4]) == (INTVAL (operands[5]) - 1))"
6664 {
6665   operands[2] = GEN_INT ((INTVAL (operands[2])) >> 2);
6666   return "vextract<shuffletype>32x4\t{%2, %1, %0%{%7%}|%0%{%7%}, %1, %2}";
6667 }
6668   [(set_attr "type" "sselog")
6669    (set_attr "prefix_extra" "1")
6670    (set_attr "length_immediate" "1")
6671    (set_attr "memory" "store")
6672    (set_attr "prefix" "evex")
6673    (set_attr "mode" "<sseinsnmode>")])
6674
6675 (define_insn "<mask_codefor>avx512dq_vextract<shuffletype>64x2_1<mask_name>"
6676   [(set (match_operand:<ssequartermode> 0 "<store_mask_predicate>" "=<store_mask_constraint>")
6677         (vec_select:<ssequartermode>
6678           (match_operand:V8FI 1 "register_operand" "v")
6679           (parallel [(match_operand 2  "const_0_to_7_operand")
6680             (match_operand 3  "const_0_to_7_operand")])))]
6681   "TARGET_AVX512DQ && (INTVAL (operands[2]) == INTVAL (operands[3]) - 1)"
6682 {
6683   operands[2] = GEN_INT ((INTVAL (operands[2])) >> 1);
6684   return "vextract<shuffletype>64x2\t{%2, %1, %0<mask_operand4>|%0<mask_operand4>, %1, %2}";
6685 }
6686   [(set_attr "type" "sselog1")
6687    (set_attr "prefix_extra" "1")
6688    (set_attr "length_immediate" "1")
6689    (set_attr "prefix" "evex")
6690    (set_attr "mode" "<sseinsnmode>")])
6691
6692 (define_insn "<mask_codefor>avx512f_vextract<shuffletype>32x4_1<mask_name>"
6693   [(set (match_operand:<ssequartermode> 0 "<store_mask_predicate>" "=<store_mask_constraint>")
6694         (vec_select:<ssequartermode>
6695           (match_operand:V16FI 1 "register_operand" "v")
6696           (parallel [(match_operand 2  "const_0_to_15_operand")
6697             (match_operand 3  "const_0_to_15_operand")
6698             (match_operand 4  "const_0_to_15_operand")
6699             (match_operand 5  "const_0_to_15_operand")])))]
6700   "TARGET_AVX512F
6701    && (INTVAL (operands[2]) == (INTVAL (operands[3]) - 1)
6702        && INTVAL (operands[3]) == (INTVAL (operands[4]) - 1)
6703        && INTVAL (operands[4]) == (INTVAL (operands[5]) - 1))"
6704 {
6705   operands[2] = GEN_INT ((INTVAL (operands[2])) >> 2);
6706   return "vextract<shuffletype>32x4\t{%2, %1, %0<mask_operand6>|%0<mask_operand6>, %1, %2}";
6707 }
6708   [(set_attr "type" "sselog1")
6709    (set_attr "prefix_extra" "1")
6710    (set_attr "length_immediate" "1")
6711    (set_attr "prefix" "evex")
6712    (set_attr "mode" "<sseinsnmode>")])
6713
6714 (define_mode_attr extract_type_2
6715   [(V16SF "avx512dq") (V16SI "avx512dq") (V8DF "avx512f") (V8DI "avx512f")])
6716
6717 (define_mode_attr extract_suf_2
6718   [(V16SF "32x8") (V16SI "32x8") (V8DF "64x4") (V8DI "64x4")])
6719
6720 (define_mode_iterator AVX512_VEC_2
6721   [(V16SF "TARGET_AVX512DQ") (V16SI "TARGET_AVX512DQ") V8DF V8DI])
6722
6723 (define_expand "<extract_type_2>_vextract<shuffletype><extract_suf_2>_mask"
6724   [(match_operand:<ssehalfvecmode> 0 "nonimmediate_operand")
6725    (match_operand:AVX512_VEC_2 1 "register_operand")
6726    (match_operand:SI 2 "const_0_to_1_operand")
6727    (match_operand:<ssehalfvecmode> 3 "nonimmediate_operand")
6728    (match_operand:QI 4 "register_operand")]
6729   "TARGET_AVX512F"
6730 {
6731   rtx (*insn)(rtx, rtx, rtx, rtx);
6732
6733   if (MEM_P (operands[0]) && GET_CODE (operands[3]) == CONST_VECTOR)
6734     operands[0] = force_reg (<ssequartermode>mode, operands[0]);
6735
6736   switch (INTVAL (operands[2]))
6737     {
6738     case 0:
6739       insn = gen_vec_extract_lo_<mode>_mask;
6740       break;
6741     case 1:
6742       insn = gen_vec_extract_hi_<mode>_mask;
6743       break;
6744     default:
6745       gcc_unreachable ();
6746     }
6747
6748   emit_insn (insn (operands[0], operands[1], operands[3], operands[4]));
6749   DONE;
6750 })
6751
6752 (define_split
6753   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand")
6754         (vec_select:<ssehalfvecmode>
6755           (match_operand:V8FI 1 "nonimmediate_operand")
6756           (parallel [(const_int 0) (const_int 1)
6757             (const_int 2) (const_int 3)])))]
6758   "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))
6759   && reload_completed"
6760   [(const_int 0)]
6761 {
6762   rtx op1 = operands[1];
6763   if (REG_P (op1))
6764     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
6765   else
6766     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
6767   emit_move_insn (operands[0], op1);
6768   DONE;
6769 })
6770
6771 (define_insn "vec_extract_lo_<mode>_maskm"
6772   [(set (match_operand:<ssehalfvecmode> 0 "memory_operand" "=m")
6773         (vec_merge:<ssehalfvecmode>
6774           (vec_select:<ssehalfvecmode>
6775             (match_operand:V8FI 1 "register_operand" "v")
6776             (parallel [(const_int 0) (const_int 1)
6777               (const_int 2) (const_int 3)]))
6778           (match_operand:<ssehalfvecmode> 2 "memory_operand" "0")
6779           (match_operand:QI 3 "register_operand" "Yk")))]
6780   "TARGET_AVX512F"
6781   "vextract<shuffletype>64x4\t{$0x0, %1, %0%{%3%}|%0%{%3%}, %1, 0x0}"
6782   [(set_attr "type" "sselog1")
6783    (set_attr "prefix_extra" "1")
6784    (set_attr "length_immediate" "1")
6785    (set_attr "prefix" "evex")
6786    (set_attr "mode" "<sseinsnmode>")])
6787
6788 (define_insn "vec_extract_lo_<mode><mask_name>"
6789   [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=<store_mask_constraint>,v")
6790         (vec_select:<ssehalfvecmode>
6791           (match_operand:V8FI 1 "nonimmediate_operand" "v,m")
6792           (parallel [(const_int 0) (const_int 1)
6793             (const_int 2) (const_int 3)])))]
6794   "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
6795 {
6796   if (<mask_applied>)
6797     return "vextract<shuffletype>64x4\t{$0x0, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x0}";
6798   else
6799     return "#";
6800 }
6801   [(set_attr "type" "sselog1")
6802    (set_attr "prefix_extra" "1")
6803    (set_attr "length_immediate" "1")
6804    (set_attr "prefix" "evex")
6805    (set_attr "mode" "<sseinsnmode>")])
6806
6807 (define_insn "vec_extract_hi_<mode>_maskm"
6808   [(set (match_operand:<ssehalfvecmode> 0 "memory_operand" "=m")
6809         (vec_merge:<ssehalfvecmode>
6810           (vec_select:<ssehalfvecmode>
6811             (match_operand:V8FI 1 "register_operand" "v")
6812             (parallel [(const_int 4) (const_int 5)
6813               (const_int 6) (const_int 7)]))
6814           (match_operand:<ssehalfvecmode> 2 "memory_operand" "0")
6815           (match_operand:QI 3 "register_operand" "Yk")))]
6816   "TARGET_AVX512F"
6817   "vextract<shuffletype>64x4\t{$0x1, %1, %0%{%3%}|%0%{%3%}, %1, 0x1}"
6818   [(set_attr "type" "sselog")
6819    (set_attr "prefix_extra" "1")
6820    (set_attr "length_immediate" "1")
6821    (set_attr "memory" "store")
6822    (set_attr "prefix" "evex")
6823    (set_attr "mode" "<sseinsnmode>")])
6824
6825 (define_insn "vec_extract_hi_<mode><mask_name>"
6826   [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=<store_mask_constraint>")
6827         (vec_select:<ssehalfvecmode>
6828           (match_operand:V8FI 1 "register_operand" "v")
6829           (parallel [(const_int 4) (const_int 5)
6830             (const_int 6) (const_int 7)])))]
6831   "TARGET_AVX512F"
6832   "vextract<shuffletype>64x4\t{$0x1, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x1}"
6833   [(set_attr "type" "sselog1")
6834    (set_attr "prefix_extra" "1")
6835    (set_attr "length_immediate" "1")
6836    (set_attr "prefix" "evex")
6837    (set_attr "mode" "<sseinsnmode>")])
6838
6839 (define_insn "vec_extract_hi_<mode>_maskm"
6840    [(set (match_operand:<ssehalfvecmode> 0 "memory_operand" "=m")
6841         (vec_merge:<ssehalfvecmode>
6842           (vec_select:<ssehalfvecmode>
6843             (match_operand:V16FI 1 "register_operand" "v")
6844             (parallel [(const_int 8) (const_int 9)
6845               (const_int 10) (const_int 11)
6846               (const_int 12) (const_int 13)
6847               (const_int 14) (const_int 15)]))
6848           (match_operand:<ssehalfvecmode> 2 "memory_operand" "0")
6849           (match_operand:QI 3 "register_operand" "k")))]
6850   "TARGET_AVX512DQ"
6851   "vextract<shuffletype>32x8\t{$0x1, %1, %0%{%3%}|%0%{%3%}, %1, 0x1}"
6852   [(set_attr "type" "sselog1")
6853    (set_attr "prefix_extra" "1")
6854    (set_attr "length_immediate" "1")
6855    (set_attr "prefix" "evex")
6856    (set_attr "mode" "<sseinsnmode>")])
6857
6858 (define_insn "vec_extract_hi_<mode><mask_name>"
6859   [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=<store_mask_constraint>,vm")
6860         (vec_select:<ssehalfvecmode>
6861           (match_operand:V16FI 1 "register_operand" "v,v")
6862           (parallel [(const_int 8) (const_int 9)
6863             (const_int 10) (const_int 11)
6864             (const_int 12) (const_int 13)
6865             (const_int 14) (const_int 15)])))]
6866   "TARGET_AVX512F && <mask_avx512dq_condition>"
6867   "@
6868    vextract<shuffletype>32x8\t{$0x1, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x1}
6869    vextracti64x4\t{$0x1, %1, %0|%0, %1, 0x1}"
6870   [(set_attr "type" "sselog1")
6871    (set_attr "prefix_extra" "1")
6872    (set_attr "isa" "avx512dq,noavx512dq")
6873    (set_attr "length_immediate" "1")
6874    (set_attr "prefix" "evex")
6875    (set_attr "mode" "<sseinsnmode>")])
6876
6877 (define_expand "avx512vl_vextractf128<mode>"
6878   [(match_operand:<ssehalfvecmode> 0 "nonimmediate_operand")
6879    (match_operand:VI48F_256 1 "register_operand")
6880    (match_operand:SI 2 "const_0_to_1_operand")
6881    (match_operand:<ssehalfvecmode> 3 "vector_move_operand")
6882    (match_operand:QI 4 "register_operand")]
6883   "TARGET_AVX512DQ && TARGET_AVX512VL"
6884 {
6885   rtx (*insn)(rtx, rtx, rtx, rtx);
6886
6887   if (MEM_P (operands[0]) && GET_CODE (operands[3]) == CONST_VECTOR)
6888     operands[0] = force_reg (<ssehalfvecmode>mode, operands[0]);
6889
6890   switch (INTVAL (operands[2]))
6891     {
6892     case 0:
6893       insn = gen_vec_extract_lo_<mode>_mask;
6894       break;
6895     case 1:
6896       insn = gen_vec_extract_hi_<mode>_mask;
6897       break;
6898     default:
6899       gcc_unreachable ();
6900     }
6901
6902   emit_insn (insn (operands[0], operands[1], operands[3], operands[4]));
6903   DONE;
6904 })
6905
6906 (define_expand "avx_vextractf128<mode>"
6907   [(match_operand:<ssehalfvecmode> 0 "nonimmediate_operand")
6908    (match_operand:V_256 1 "register_operand")
6909    (match_operand:SI 2 "const_0_to_1_operand")]
6910   "TARGET_AVX"
6911 {
6912   rtx (*insn)(rtx, rtx);
6913
6914   switch (INTVAL (operands[2]))
6915     {
6916     case 0:
6917       insn = gen_vec_extract_lo_<mode>;
6918       break;
6919     case 1:
6920       insn = gen_vec_extract_hi_<mode>;
6921       break;
6922     default:
6923       gcc_unreachable ();
6924     }
6925
6926   emit_insn (insn (operands[0], operands[1]));
6927   DONE;
6928 })
6929
6930 (define_insn "vec_extract_lo_<mode><mask_name>"
6931   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=v,m")
6932         (vec_select:<ssehalfvecmode>
6933           (match_operand:V16FI 1 "nonimmediate_operand" "vm,v")
6934           (parallel [(const_int 0) (const_int 1)
6935                      (const_int 2) (const_int 3)
6936                      (const_int 4) (const_int 5)
6937                      (const_int 6) (const_int 7)])))]
6938   "TARGET_AVX512F
6939    && <mask_mode512bit_condition>
6940    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
6941 {
6942   if (<mask_applied>)
6943     return "vextract<shuffletype>32x8\t{$0x0, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x0}";
6944   else
6945     return "#";
6946 })
6947
6948 (define_split
6949   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand")
6950         (vec_select:<ssehalfvecmode>
6951           (match_operand:V16FI 1 "nonimmediate_operand")
6952           (parallel [(const_int 0) (const_int 1)
6953             (const_int 2) (const_int 3)
6954             (const_int 4) (const_int 5)
6955             (const_int 6) (const_int 7)])))]
6956   "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))
6957    && reload_completed"
6958    [(const_int 0)]
6959  {
6960   rtx op1 = operands[1];
6961   if (REG_P (op1))
6962     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
6963   else
6964     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
6965   emit_move_insn (operands[0], op1);
6966   DONE;
6967 })
6968
6969 (define_insn "vec_extract_lo_<mode><mask_name>"
6970   [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=v,m")
6971         (vec_select:<ssehalfvecmode>
6972           (match_operand:VI8F_256 1 "nonimmediate_operand" "vm,v")
6973           (parallel [(const_int 0) (const_int 1)])))]
6974   "TARGET_AVX
6975    && <mask_avx512vl_condition> && <mask_avx512dq_condition>
6976    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
6977 {
6978   if (<mask_applied>)
6979     return "vextract<shuffletype>64x2\t{$0x0, %1, %0%{%3%}|%0%{%3%}, %1, 0x0}";
6980   else
6981     return "#";
6982 }
6983    [(set_attr "type" "sselog")
6984     (set_attr "prefix_extra" "1")
6985     (set_attr "length_immediate" "1")
6986     (set_attr "memory" "none,store")
6987     (set_attr "prefix" "evex")
6988     (set_attr "mode" "XI")])
6989
6990 (define_split
6991   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand")
6992         (vec_select:<ssehalfvecmode>
6993           (match_operand:VI8F_256 1 "nonimmediate_operand")
6994           (parallel [(const_int 0) (const_int 1)])))]
6995   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))
6996   && reload_completed"
6997    [(const_int 0)]
6998 {
6999   rtx op1 = operands[1];
7000   if (REG_P (op1))
7001     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
7002   else
7003     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
7004   emit_move_insn (operands[0], op1);
7005   DONE;
7006 })
7007
7008 (define_insn "vec_extract_hi_<mode><mask_name>"
7009   [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=v,<store_mask_constraint>")
7010         (vec_select:<ssehalfvecmode>
7011           (match_operand:VI8F_256 1 "register_operand" "v,v")
7012           (parallel [(const_int 2) (const_int 3)])))]
7013   "TARGET_AVX"
7014 {
7015   if (TARGET_AVX512DQ && TARGET_AVX512VL)
7016     return "vextract<shuffletype>64x2\t{$0x1, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x1}";
7017   else
7018     return "vextract<i128>\t{$0x1, %1, %0|%0, %1, 0x1}";
7019 }
7020   [(set_attr "type" "sselog")
7021    (set_attr "prefix_extra" "1")
7022    (set_attr "length_immediate" "1")
7023    (set_attr "memory" "none,store")
7024    (set_attr "prefix" "vex")
7025    (set_attr "mode" "<sseinsnmode>")])
7026
7027 (define_split
7028   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand")
7029         (vec_select:<ssehalfvecmode>
7030           (match_operand:VI4F_256 1 "nonimmediate_operand")
7031           (parallel [(const_int 0) (const_int 1)
7032                      (const_int 2) (const_int 3)])))]
7033   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1])) && reload_completed"
7034    [(const_int 0)]
7035 {
7036   rtx op1 = operands[1];
7037   if (REG_P (op1))
7038     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
7039   else
7040     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
7041   emit_move_insn (operands[0], op1);
7042   DONE;
7043 })
7044
7045
7046 (define_insn "vec_extract_lo_<mode><mask_name>"
7047   [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=<store_mask_constraint>")
7048         (vec_select:<ssehalfvecmode>
7049           (match_operand:VI4F_256 1 "nonimmediate_operand" "v")
7050           (parallel [(const_int 0) (const_int 1)
7051                      (const_int 2) (const_int 3)])))]
7052   "TARGET_AVX && <mask_avx512vl_condition> && <mask_avx512dq_condition>"
7053 {
7054   if (<mask_applied>)
7055     return "vextract<shuffletype>32x4\t{$0x0, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x0}";
7056   else
7057     return "#";
7058 }
7059   [(set_attr "type" "sselog1")
7060    (set_attr "prefix_extra" "1")
7061    (set_attr "length_immediate" "1")
7062    (set_attr "prefix" "evex")
7063    (set_attr "mode" "<sseinsnmode>")])
7064
7065 (define_insn "vec_extract_lo_<mode>_maskm"
7066   [(set (match_operand:<ssehalfvecmode> 0 "memory_operand" "=m")
7067         (vec_merge:<ssehalfvecmode>
7068           (vec_select:<ssehalfvecmode>
7069             (match_operand:VI4F_256 1 "register_operand" "v")
7070             (parallel [(const_int 0) (const_int 1)
7071                       (const_int 2) (const_int 3)]))
7072           (match_operand:<ssehalfvecmode> 2 "memory_operand" "0")
7073           (match_operand:QI 3 "register_operand" "k")))]
7074   "TARGET_AVX512VL && TARGET_AVX512F"
7075   "vextract<shuffletype>32x4\t{$0x0, %1, %0%{3%}|%0%{%3%}, %1, 0x0}"
7076   [(set_attr "type" "sselog1")
7077    (set_attr "prefix_extra" "1")
7078    (set_attr "length_immediate" "1")
7079    (set_attr "prefix" "evex")
7080    (set_attr "mode" "<sseinsnmode>")])
7081
7082 (define_insn "vec_extract_hi_<mode>_maskm"
7083   [(set (match_operand:<ssehalfvecmode> 0 "memory_operand" "=m")
7084         (vec_merge:<ssehalfvecmode>
7085           (vec_select:<ssehalfvecmode>
7086             (match_operand:VI4F_256 1 "register_operand" "v")
7087             (parallel [(const_int 4) (const_int 5)
7088                       (const_int 6) (const_int 7)]))
7089           (match_operand:<ssehalfvecmode> 2 "memory_operand" "0")
7090           (match_operand:<ssehalfvecmode> 3 "register_operand" "k")))]
7091   "TARGET_AVX512F && TARGET_AVX512VL"
7092 {
7093   return "vextract<shuffletype>32x4\t{$0x1, %1, %0%{%3%}|%0%{%3%}, %1, 0x1}";
7094 }
7095   [(set_attr "type" "sselog1")
7096    (set_attr "prefix_extra" "1")
7097    (set_attr "length_immediate" "1")
7098    (set_attr "prefix" "evex")
7099    (set_attr "mode" "<sseinsnmode>")])
7100
7101 (define_insn "vec_extract_hi_<mode><mask_name>"
7102   [(set (match_operand:<ssehalfvecmode> 0 "<store_mask_predicate>" "=<store_mask_constraint>")
7103         (vec_select:<ssehalfvecmode>
7104           (match_operand:VI4F_256 1 "register_operand" "v")
7105           (parallel [(const_int 4) (const_int 5)
7106                      (const_int 6) (const_int 7)])))]
7107   "TARGET_AVX && <mask_avx512vl_condition>"
7108 {
7109   if (TARGET_AVX512VL)
7110     return "vextract<shuffletype>32x4\t{$0x1, %1, %0<mask_operand2>|%0<mask_operand2>, %1, 0x1}";
7111   else
7112     return "vextract<i128>\t{$0x1, %1, %0|%0, %1, 0x1}";
7113 }
7114   [(set_attr "type" "sselog1")
7115    (set_attr "prefix_extra" "1")
7116    (set_attr "length_immediate" "1")
7117    (set (attr "prefix")
7118      (if_then_else
7119        (match_test "TARGET_AVX512VL")
7120      (const_string "evex")
7121      (const_string "vex")))
7122    (set_attr "mode" "<sseinsnmode>")])
7123
7124 (define_insn_and_split "vec_extract_lo_v32hi"
7125   [(set (match_operand:V16HI 0 "nonimmediate_operand" "=v,m")
7126         (vec_select:V16HI
7127           (match_operand:V32HI 1 "nonimmediate_operand" "vm,v")
7128           (parallel [(const_int 0) (const_int 1)
7129                      (const_int 2) (const_int 3)
7130                      (const_int 4) (const_int 5)
7131                      (const_int 6) (const_int 7)
7132                      (const_int 8) (const_int 9)
7133                      (const_int 10) (const_int 11)
7134                      (const_int 12) (const_int 13)
7135                      (const_int 14) (const_int 15)])))]
7136   "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7137   "#"
7138   "&& reload_completed"
7139   [(set (match_dup 0) (match_dup 1))]
7140 {
7141   if (REG_P (operands[1]))
7142     operands[1] = gen_rtx_REG (V16HImode, REGNO (operands[1]));
7143   else
7144     operands[1] = adjust_address (operands[1], V16HImode, 0);
7145 })
7146
7147 (define_insn "vec_extract_hi_v32hi"
7148   [(set (match_operand:V16HI 0 "nonimmediate_operand" "=v,m")
7149         (vec_select:V16HI
7150           (match_operand:V32HI 1 "nonimmediate_operand" "v,v")
7151           (parallel [(const_int 16) (const_int 17)
7152                      (const_int 18) (const_int 19)
7153                      (const_int 20) (const_int 21)
7154                      (const_int 22) (const_int 23)
7155                      (const_int 24) (const_int 25)
7156                      (const_int 26) (const_int 27)
7157                      (const_int 28) (const_int 29)
7158                      (const_int 30) (const_int 31)])))]
7159   "TARGET_AVX512F"
7160   "vextracti64x4\t{$0x1, %1, %0|%0, %1, 0x1}"
7161   [(set_attr "type" "sselog")
7162    (set_attr "prefix_extra" "1")
7163    (set_attr "length_immediate" "1")
7164    (set_attr "memory" "none,store")
7165    (set_attr "prefix" "evex")
7166    (set_attr "mode" "XI")])
7167
7168 (define_insn_and_split "vec_extract_lo_v16hi"
7169   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
7170         (vec_select:V8HI
7171           (match_operand:V16HI 1 "nonimmediate_operand" "xm,x")
7172           (parallel [(const_int 0) (const_int 1)
7173                      (const_int 2) (const_int 3)
7174                      (const_int 4) (const_int 5)
7175                      (const_int 6) (const_int 7)])))]
7176   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7177   "#"
7178   "&& reload_completed"
7179   [(set (match_dup 0) (match_dup 1))]
7180 {
7181   if (REG_P (operands[1]))
7182     operands[1] = gen_rtx_REG (V8HImode, REGNO (operands[1]));
7183   else
7184     operands[1] = adjust_address (operands[1], V8HImode, 0);
7185 })
7186
7187 (define_insn "vec_extract_hi_v16hi"
7188   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
7189         (vec_select:V8HI
7190           (match_operand:V16HI 1 "register_operand" "x,x")
7191           (parallel [(const_int 8) (const_int 9)
7192                      (const_int 10) (const_int 11)
7193                      (const_int 12) (const_int 13)
7194                      (const_int 14) (const_int 15)])))]
7195   "TARGET_AVX"
7196   "vextract%~128\t{$0x1, %1, %0|%0, %1, 0x1}"
7197   [(set_attr "type" "sselog")
7198    (set_attr "prefix_extra" "1")
7199    (set_attr "length_immediate" "1")
7200    (set_attr "memory" "none,store")
7201    (set_attr "prefix" "vex")
7202    (set_attr "mode" "OI")])
7203
7204 (define_insn_and_split "vec_extract_lo_v64qi"
7205   [(set (match_operand:V32QI 0 "nonimmediate_operand" "=v,m")
7206         (vec_select:V32QI
7207           (match_operand:V64QI 1 "nonimmediate_operand" "vm,v")
7208           (parallel [(const_int 0) (const_int 1)
7209                      (const_int 2) (const_int 3)
7210                      (const_int 4) (const_int 5)
7211                      (const_int 6) (const_int 7)
7212                      (const_int 8) (const_int 9)
7213                      (const_int 10) (const_int 11)
7214                      (const_int 12) (const_int 13)
7215                      (const_int 14) (const_int 15)
7216                      (const_int 16) (const_int 17)
7217                      (const_int 18) (const_int 19)
7218                      (const_int 20) (const_int 21)
7219                      (const_int 22) (const_int 23)
7220                      (const_int 24) (const_int 25)
7221                      (const_int 26) (const_int 27)
7222                      (const_int 28) (const_int 29)
7223                      (const_int 30) (const_int 31)])))]
7224   "TARGET_AVX512F && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7225   "#"
7226   "&& reload_completed"
7227   [(set (match_dup 0) (match_dup 1))]
7228 {
7229   if (REG_P (operands[1]))
7230     operands[1] = gen_rtx_REG (V32QImode, REGNO (operands[1]));
7231   else
7232     operands[1] = adjust_address (operands[1], V32QImode, 0);
7233 })
7234
7235 (define_insn "vec_extract_hi_v64qi"
7236   [(set (match_operand:V32QI 0 "nonimmediate_operand" "=v,m")
7237         (vec_select:V32QI
7238           (match_operand:V64QI 1 "nonimmediate_operand" "v,v")
7239           (parallel [(const_int 32) (const_int 33)
7240                      (const_int 34) (const_int 35)
7241                      (const_int 36) (const_int 37)
7242                      (const_int 38) (const_int 39)
7243                      (const_int 40) (const_int 41)
7244                      (const_int 42) (const_int 43)
7245                      (const_int 44) (const_int 45)
7246                      (const_int 46) (const_int 47)
7247                      (const_int 48) (const_int 49)
7248                      (const_int 50) (const_int 51)
7249                      (const_int 52) (const_int 53)
7250                      (const_int 54) (const_int 55)
7251                      (const_int 56) (const_int 57)
7252                      (const_int 58) (const_int 59)
7253                      (const_int 60) (const_int 61)
7254                      (const_int 62) (const_int 63)])))]
7255   "TARGET_AVX512F"
7256   "vextracti64x4\t{$0x1, %1, %0|%0, %1, 0x1}"
7257   [(set_attr "type" "sselog")
7258    (set_attr "prefix_extra" "1")
7259    (set_attr "length_immediate" "1")
7260    (set_attr "memory" "none,store")
7261    (set_attr "prefix" "evex")
7262    (set_attr "mode" "XI")])
7263
7264 (define_insn_and_split "vec_extract_lo_v32qi"
7265   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
7266         (vec_select:V16QI
7267           (match_operand:V32QI 1 "nonimmediate_operand" "xm,x")
7268           (parallel [(const_int 0) (const_int 1)
7269                      (const_int 2) (const_int 3)
7270                      (const_int 4) (const_int 5)
7271                      (const_int 6) (const_int 7)
7272                      (const_int 8) (const_int 9)
7273                      (const_int 10) (const_int 11)
7274                      (const_int 12) (const_int 13)
7275                      (const_int 14) (const_int 15)])))]
7276   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7277   "#"
7278   "&& reload_completed"
7279   [(set (match_dup 0) (match_dup 1))]
7280 {
7281   if (REG_P (operands[1]))
7282     operands[1] = gen_rtx_REG (V16QImode, REGNO (operands[1]));
7283   else
7284     operands[1] = adjust_address (operands[1], V16QImode, 0);
7285 })
7286
7287 (define_insn "vec_extract_hi_v32qi"
7288   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
7289         (vec_select:V16QI
7290           (match_operand:V32QI 1 "register_operand" "x,x")
7291           (parallel [(const_int 16) (const_int 17)
7292                      (const_int 18) (const_int 19)
7293                      (const_int 20) (const_int 21)
7294                      (const_int 22) (const_int 23)
7295                      (const_int 24) (const_int 25)
7296                      (const_int 26) (const_int 27)
7297                      (const_int 28) (const_int 29)
7298                      (const_int 30) (const_int 31)])))]
7299   "TARGET_AVX"
7300   "vextract%~128\t{$0x1, %1, %0|%0, %1, 0x1}"
7301   [(set_attr "type" "sselog")
7302    (set_attr "prefix_extra" "1")
7303    (set_attr "length_immediate" "1")
7304    (set_attr "memory" "none,store")
7305    (set_attr "prefix" "vex")
7306    (set_attr "mode" "OI")])
7307
7308 ;; Modes handled by vec_extract patterns.
7309 (define_mode_iterator VEC_EXTRACT_MODE
7310   [(V64QI "TARGET_AVX512BW") (V32QI "TARGET_AVX") V16QI
7311    (V32HI "TARGET_AVX512BW") (V16HI "TARGET_AVX") V8HI
7312    (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX") V4SI
7313    (V8DI "TARGET_AVX512F") (V4DI "TARGET_AVX") V2DI
7314    (V16SF "TARGET_AVX512F") (V8SF "TARGET_AVX") V4SF
7315    (V8DF "TARGET_AVX512F") (V4DF "TARGET_AVX") V2DF])
7316
7317 (define_expand "vec_extract<mode>"
7318   [(match_operand:<ssescalarmode> 0 "register_operand")
7319    (match_operand:VEC_EXTRACT_MODE 1 "register_operand")
7320    (match_operand 2 "const_int_operand")]
7321   "TARGET_SSE"
7322 {
7323   ix86_expand_vector_extract (false, operands[0], operands[1],
7324                               INTVAL (operands[2]));
7325   DONE;
7326 })
7327
7328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7329 ;;
7330 ;; Parallel double-precision floating point element swizzling
7331 ;;
7332 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7333
7334 (define_insn "<mask_codefor>avx512f_unpckhpd512<mask_name>"
7335   [(set (match_operand:V8DF 0 "register_operand" "=v")
7336         (vec_select:V8DF
7337           (vec_concat:V16DF
7338             (match_operand:V8DF 1 "nonimmediate_operand" "v")
7339             (match_operand:V8DF 2 "nonimmediate_operand" "vm"))
7340           (parallel [(const_int 1) (const_int 9)
7341                      (const_int 3) (const_int 11)
7342                      (const_int 5) (const_int 13)
7343                      (const_int 7) (const_int 15)])))]
7344   "TARGET_AVX512F"
7345   "vunpckhpd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
7346   [(set_attr "type" "sselog")
7347    (set_attr "prefix" "evex")
7348    (set_attr "mode" "V8DF")])
7349
7350 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
7351 (define_insn "avx_unpckhpd256<mask_name>"
7352   [(set (match_operand:V4DF 0 "register_operand" "=v")
7353         (vec_select:V4DF
7354           (vec_concat:V8DF
7355             (match_operand:V4DF 1 "register_operand" "v")
7356             (match_operand:V4DF 2 "nonimmediate_operand" "vm"))
7357           (parallel [(const_int 1) (const_int 5)
7358                      (const_int 3) (const_int 7)])))]
7359   "TARGET_AVX && <mask_avx512vl_condition>"
7360   "vunpckhpd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
7361   [(set_attr "type" "sselog")
7362    (set_attr "prefix" "vex")
7363    (set_attr "mode" "V4DF")])
7364
7365 (define_expand "vec_interleave_highv4df"
7366   [(set (match_dup 3)
7367         (vec_select:V4DF
7368           (vec_concat:V8DF
7369             (match_operand:V4DF 1 "register_operand" "x")
7370             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
7371           (parallel [(const_int 0) (const_int 4)
7372                      (const_int 2) (const_int 6)])))
7373    (set (match_dup 4)
7374         (vec_select:V4DF
7375           (vec_concat:V8DF
7376             (match_dup 1)
7377             (match_dup 2))
7378           (parallel [(const_int 1) (const_int 5)
7379                      (const_int 3) (const_int 7)])))
7380    (set (match_operand:V4DF 0 "register_operand")
7381         (vec_select:V4DF
7382           (vec_concat:V8DF
7383             (match_dup 3)
7384             (match_dup 4))
7385           (parallel [(const_int 2) (const_int 3)
7386                      (const_int 6) (const_int 7)])))]
7387  "TARGET_AVX"
7388 {
7389   operands[3] = gen_reg_rtx (V4DFmode);
7390   operands[4] = gen_reg_rtx (V4DFmode);
7391 })
7392
7393
7394 (define_insn "avx512vl_unpckhpd128_mask"
7395   [(set (match_operand:V2DF 0 "register_operand" "=v")
7396         (vec_merge:V2DF
7397           (vec_select:V2DF
7398             (vec_concat:V4DF
7399               (match_operand:V2DF 1 "register_operand" "v")
7400               (match_operand:V2DF 2 "nonimmediate_operand" "vm"))
7401             (parallel [(const_int 1) (const_int 3)]))
7402           (match_operand:V2DF 3 "vector_move_operand" "0C")
7403           (match_operand:QI 4 "register_operand" "Yk")))]
7404   "TARGET_AVX512VL"
7405   "vunpckhpd\t{%2, %1, %0%{%4%}%N3|%0%{%4%}%N3, %1, %2}"
7406   [(set_attr "type" "sselog")
7407    (set_attr "prefix" "evex")
7408    (set_attr "mode" "V2DF")])
7409
7410 (define_expand "vec_interleave_highv2df"
7411   [(set (match_operand:V2DF 0 "register_operand")
7412         (vec_select:V2DF
7413           (vec_concat:V4DF
7414             (match_operand:V2DF 1 "nonimmediate_operand")
7415             (match_operand:V2DF 2 "nonimmediate_operand"))
7416           (parallel [(const_int 1)
7417                      (const_int 3)])))]
7418   "TARGET_SSE2"
7419 {
7420   if (!ix86_vec_interleave_v2df_operator_ok (operands, 1))
7421     operands[2] = force_reg (V2DFmode, operands[2]);
7422 })
7423
7424 (define_insn "*vec_interleave_highv2df"
7425   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,m")
7426         (vec_select:V2DF
7427           (vec_concat:V4DF
7428             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,o,o,o,x")
7429             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,0,x,0"))
7430           (parallel [(const_int 1)
7431                      (const_int 3)])))]
7432   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 1)"
7433   "@
7434    unpckhpd\t{%2, %0|%0, %2}
7435    vunpckhpd\t{%2, %1, %0|%0, %1, %2}
7436    %vmovddup\t{%H1, %0|%0, %H1}
7437    movlpd\t{%H1, %0|%0, %H1}
7438    vmovlpd\t{%H1, %2, %0|%0, %2, %H1}
7439    %vmovhpd\t{%1, %0|%q0, %1}"
7440   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
7441    (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
7442    (set_attr "ssememalign" "64")
7443    (set_attr "prefix_data16" "*,*,*,1,*,1")
7444    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
7445    (set_attr "mode" "V2DF,V2DF,DF,V1DF,V1DF,V1DF")])
7446
7447 (define_expand "avx512f_movddup512<mask_name>"
7448   [(set (match_operand:V8DF 0 "register_operand")
7449         (vec_select:V8DF
7450           (vec_concat:V16DF
7451             (match_operand:V8DF 1 "nonimmediate_operand")
7452             (match_dup 1))
7453           (parallel [(const_int 0) (const_int 8)
7454                      (const_int 2) (const_int 10)
7455                      (const_int 4) (const_int 12)
7456                      (const_int 6) (const_int 14)])))]
7457   "TARGET_AVX512F")
7458
7459 (define_expand "avx512f_unpcklpd512<mask_name>"
7460   [(set (match_operand:V8DF 0 "register_operand")
7461         (vec_select:V8DF
7462           (vec_concat:V16DF
7463             (match_operand:V8DF 1 "register_operand")
7464             (match_operand:V8DF 2 "nonimmediate_operand"))
7465           (parallel [(const_int 0) (const_int 8)
7466                      (const_int 2) (const_int 10)
7467                      (const_int 4) (const_int 12)
7468                      (const_int 6) (const_int 14)])))]
7469   "TARGET_AVX512F")
7470
7471 (define_insn "*avx512f_unpcklpd512<mask_name>"
7472   [(set (match_operand:V8DF 0 "register_operand" "=v,v")
7473         (vec_select:V8DF
7474           (vec_concat:V16DF
7475             (match_operand:V8DF 1 "nonimmediate_operand" "vm, v")
7476             (match_operand:V8DF 2 "nonimmediate_operand" "1 ,vm"))
7477           (parallel [(const_int 0) (const_int 8)
7478                      (const_int 2) (const_int 10)
7479                      (const_int 4) (const_int 12)
7480                      (const_int 6) (const_int 14)])))]
7481   "TARGET_AVX512F"
7482   "@
7483    vmovddup\t{%1, %0<mask_operand3>|%0<mask_operand3>, %1}
7484    vunpcklpd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
7485   [(set_attr "type" "sselog")
7486    (set_attr "prefix" "evex")
7487    (set_attr "mode" "V8DF")])
7488
7489 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
7490 (define_expand "avx_movddup256<mask_name>"
7491   [(set (match_operand:V4DF 0 "register_operand")
7492         (vec_select:V4DF
7493           (vec_concat:V8DF
7494             (match_operand:V4DF 1 "nonimmediate_operand")
7495             (match_dup 1))
7496           (parallel [(const_int 0) (const_int 4)
7497                      (const_int 2) (const_int 6)])))]
7498   "TARGET_AVX && <mask_avx512vl_condition>")
7499
7500 (define_expand "avx_unpcklpd256<mask_name>"
7501   [(set (match_operand:V4DF 0 "register_operand")
7502         (vec_select:V4DF
7503           (vec_concat:V8DF
7504             (match_operand:V4DF 1 "register_operand")
7505             (match_operand:V4DF 2 "nonimmediate_operand"))
7506           (parallel [(const_int 0) (const_int 4)
7507                      (const_int 2) (const_int 6)])))]
7508   "TARGET_AVX && <mask_avx512vl_condition>")
7509
7510 (define_insn "*avx_unpcklpd256<mask_name>"
7511   [(set (match_operand:V4DF 0 "register_operand"         "=v,v")
7512         (vec_select:V4DF
7513           (vec_concat:V8DF
7514             (match_operand:V4DF 1 "nonimmediate_operand" " v,m")
7515             (match_operand:V4DF 2 "nonimmediate_operand" "vm,1"))
7516           (parallel [(const_int 0) (const_int 4)
7517                      (const_int 2) (const_int 6)])))]
7518   "TARGET_AVX && <mask_avx512vl_condition>"
7519   "@
7520    vunpcklpd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}
7521    vmovddup\t{%1, %0<mask_operand3>|%0<mask_operand3>, %1}"
7522   [(set_attr "type" "sselog")
7523    (set_attr "prefix" "vex")
7524    (set_attr "mode" "V4DF")])
7525
7526 (define_expand "vec_interleave_lowv4df"
7527   [(set (match_dup 3)
7528         (vec_select:V4DF
7529           (vec_concat:V8DF
7530             (match_operand:V4DF 1 "register_operand" "x")
7531             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
7532           (parallel [(const_int 0) (const_int 4)
7533                      (const_int 2) (const_int 6)])))
7534    (set (match_dup 4)
7535         (vec_select:V4DF
7536           (vec_concat:V8DF
7537             (match_dup 1)
7538             (match_dup 2))
7539           (parallel [(const_int 1) (const_int 5)
7540                      (const_int 3) (const_int 7)])))
7541    (set (match_operand:V4DF 0 "register_operand")
7542         (vec_select:V4DF
7543           (vec_concat:V8DF
7544             (match_dup 3)
7545             (match_dup 4))
7546           (parallel [(const_int 0) (const_int 1)
7547                      (const_int 4) (const_int 5)])))]
7548  "TARGET_AVX"
7549 {
7550   operands[3] = gen_reg_rtx (V4DFmode);
7551   operands[4] = gen_reg_rtx (V4DFmode);
7552 })
7553
7554 (define_insn "avx512vl_unpcklpd128_mask"
7555   [(set (match_operand:V2DF 0 "register_operand" "=v")
7556         (vec_merge:V2DF
7557           (vec_select:V2DF
7558             (vec_concat:V4DF
7559               (match_operand:V2DF 1 "register_operand" "v")
7560               (match_operand:V2DF 2 "nonimmediate_operand" "vm"))
7561             (parallel [(const_int 0) (const_int 2)]))
7562           (match_operand:V2DF 3 "vector_move_operand" "0C")
7563           (match_operand:QI 4 "register_operand" "Yk")))]
7564   "TARGET_AVX512VL"
7565   "vunpcklpd\t{%2, %1, %0%{%4%}%N3|%0%{%4%}%N3, %1, %2}"
7566   [(set_attr "type" "sselog")
7567    (set_attr "prefix" "evex")
7568    (set_attr "mode" "V2DF")])
7569
7570 (define_expand "vec_interleave_lowv2df"
7571   [(set (match_operand:V2DF 0 "register_operand")
7572         (vec_select:V2DF
7573           (vec_concat:V4DF
7574             (match_operand:V2DF 1 "nonimmediate_operand")
7575             (match_operand:V2DF 2 "nonimmediate_operand"))
7576           (parallel [(const_int 0)
7577                      (const_int 2)])))]
7578   "TARGET_SSE2"
7579 {
7580   if (!ix86_vec_interleave_v2df_operator_ok (operands, 0))
7581     operands[1] = force_reg (V2DFmode, operands[1]);
7582 })
7583
7584 (define_insn "*vec_interleave_lowv2df"
7585   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,o")
7586         (vec_select:V2DF
7587           (vec_concat:V4DF
7588             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,m,0,x,0")
7589             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,m,m,x"))
7590           (parallel [(const_int 0)
7591                      (const_int 2)])))]
7592   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 0)"
7593   "@
7594    unpcklpd\t{%2, %0|%0, %2}
7595    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
7596    %vmovddup\t{%1, %0|%0, %q1}
7597    movhpd\t{%2, %0|%0, %q2}
7598    vmovhpd\t{%2, %1, %0|%0, %1, %q2}
7599    %vmovlpd\t{%2, %H0|%H0, %2}"
7600   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
7601    (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
7602    (set_attr "ssememalign" "64")
7603    (set_attr "prefix_data16" "*,*,*,1,*,1")
7604    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
7605    (set_attr "mode" "V2DF,V2DF,DF,V1DF,V1DF,V1DF")])
7606
7607 (define_split
7608   [(set (match_operand:V2DF 0 "memory_operand")
7609         (vec_select:V2DF
7610           (vec_concat:V4DF
7611             (match_operand:V2DF 1 "register_operand")
7612             (match_dup 1))
7613           (parallel [(const_int 0)
7614                      (const_int 2)])))]
7615   "TARGET_SSE3 && reload_completed"
7616   [(const_int 0)]
7617 {
7618   rtx low = gen_rtx_REG (DFmode, REGNO (operands[1]));
7619   emit_move_insn (adjust_address (operands[0], DFmode, 0), low);
7620   emit_move_insn (adjust_address (operands[0], DFmode, 8), low);
7621   DONE;
7622 })
7623
7624 (define_split
7625   [(set (match_operand:V2DF 0 "register_operand")
7626         (vec_select:V2DF
7627           (vec_concat:V4DF
7628             (match_operand:V2DF 1 "memory_operand")
7629             (match_dup 1))
7630           (parallel [(match_operand:SI 2 "const_0_to_1_operand")
7631                      (match_operand:SI 3 "const_int_operand")])))]
7632   "TARGET_SSE3 && INTVAL (operands[2]) + 2 == INTVAL (operands[3])"
7633   [(set (match_dup 0) (vec_duplicate:V2DF (match_dup 1)))]
7634 {
7635   operands[1] = adjust_address (operands[1], DFmode, INTVAL (operands[2]) * 8);
7636 })
7637
7638 (define_insn "avx512f_vmscalef<mode><round_name>"
7639   [(set (match_operand:VF_128 0 "register_operand" "=v")
7640         (vec_merge:VF_128
7641           (unspec:VF_128
7642             [(match_operand:VF_128 1 "register_operand" "v")
7643              (match_operand:VF_128 2 "<round_nimm_predicate>" "<round_constraint>")]
7644             UNSPEC_SCALEF)
7645           (match_dup 1)
7646           (const_int 1)))]
7647   "TARGET_AVX512F"
7648   "vscalef<ssescalarmodesuffix>\t{<round_op3>%2, %1, %0|%0, %1, %2<round_op3>}"
7649   [(set_attr "prefix" "evex")
7650    (set_attr "mode"  "<ssescalarmode>")])
7651
7652 (define_insn "<avx512>_scalef<mode><mask_name><round_name>"
7653   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
7654         (unspec:VF_AVX512VL
7655           [(match_operand:VF_AVX512VL 1 "register_operand" "v")
7656            (match_operand:VF_AVX512VL 2 "nonimmediate_operand" "<round_constraint>")]
7657           UNSPEC_SCALEF))]
7658   "TARGET_AVX512F"
7659   "vscalef<ssemodesuffix>\t{<round_mask_op3>%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2<round_mask_op3>}"
7660   [(set_attr "prefix" "evex")
7661    (set_attr "mode"  "<MODE>")])
7662
7663 (define_expand "<avx512>_vternlog<mode>_maskz"
7664   [(match_operand:VI48_AVX512VL 0 "register_operand")
7665    (match_operand:VI48_AVX512VL 1 "register_operand")
7666    (match_operand:VI48_AVX512VL 2 "register_operand")
7667    (match_operand:VI48_AVX512VL 3 "nonimmediate_operand")
7668    (match_operand:SI 4 "const_0_to_255_operand")
7669    (match_operand:<avx512fmaskmode> 5 "register_operand")]
7670   "TARGET_AVX512F"
7671 {
7672   emit_insn (gen_<avx512>_vternlog<mode>_maskz_1 (
7673     operands[0], operands[1], operands[2], operands[3],
7674     operands[4], CONST0_RTX (<MODE>mode), operands[5]));
7675   DONE;
7676 })
7677
7678 (define_insn "<avx512>_vternlog<mode><sd_maskz_name>"
7679   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
7680         (unspec:VI48_AVX512VL
7681           [(match_operand:VI48_AVX512VL 1 "register_operand" "0")
7682            (match_operand:VI48_AVX512VL 2 "register_operand" "v")
7683            (match_operand:VI48_AVX512VL 3 "nonimmediate_operand" "vm")
7684            (match_operand:SI 4 "const_0_to_255_operand")]
7685           UNSPEC_VTERNLOG))]
7686   "TARGET_AVX512F"
7687   "vpternlog<ssemodesuffix>\t{%4, %3, %2, %0<sd_mask_op5>|%0<sd_mask_op5>, %2, %3, %4}"
7688   [(set_attr "type" "sselog")
7689    (set_attr "prefix" "evex")
7690    (set_attr "mode" "<sseinsnmode>")])
7691
7692 (define_insn "<avx512>_vternlog<mode>_mask"
7693   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
7694         (vec_merge:VI48_AVX512VL
7695           (unspec:VI48_AVX512VL
7696             [(match_operand:VI48_AVX512VL 1 "register_operand" "0")
7697              (match_operand:VI48_AVX512VL 2 "register_operand" "v")
7698              (match_operand:VI48_AVX512VL 3 "nonimmediate_operand" "vm")
7699              (match_operand:SI 4 "const_0_to_255_operand")]
7700             UNSPEC_VTERNLOG)
7701           (match_dup 1)
7702           (match_operand:<avx512fmaskmode> 5 "register_operand" "Yk")))]
7703   "TARGET_AVX512F"
7704   "vpternlog<ssemodesuffix>\t{%4, %3, %2, %0%{%5%}|%0%{%5%}, %2, %3, %4}"
7705   [(set_attr "type" "sselog")
7706    (set_attr "prefix" "evex")
7707    (set_attr "mode" "<sseinsnmode>")])
7708
7709 (define_insn "<avx512>_getexp<mode><mask_name><round_saeonly_name>"
7710   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
7711         (unspec:VF_AVX512VL [(match_operand:VF_AVX512VL 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")]
7712                         UNSPEC_GETEXP))]
7713    "TARGET_AVX512F"
7714    "vgetexp<ssemodesuffix>\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}";
7715     [(set_attr "prefix" "evex")
7716      (set_attr "mode" "<MODE>")])
7717
7718 (define_insn "avx512f_sgetexp<mode><round_saeonly_name>"
7719   [(set (match_operand:VF_128 0 "register_operand" "=v")
7720         (vec_merge:VF_128
7721           (unspec:VF_128
7722             [(match_operand:VF_128 1 "register_operand" "v")
7723              (match_operand:VF_128 2 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")]
7724             UNSPEC_GETEXP)
7725           (match_dup 1)
7726           (const_int 1)))]
7727    "TARGET_AVX512F"
7728    "vgetexp<ssescalarmodesuffix>\t{<round_saeonly_op3>%2, %1, %0|%0, %1, %2<round_saeonly_op3>}";
7729     [(set_attr "prefix" "evex")
7730      (set_attr "mode" "<ssescalarmode>")])
7731
7732 (define_insn "<mask_codefor><avx512>_align<mode><mask_name>"
7733   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
7734         (unspec:VI48_AVX512VL [(match_operand:VI48_AVX512VL 1 "register_operand" "v")
7735                                (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm")
7736                                (match_operand:SI 3 "const_0_to_255_operand")]
7737                               UNSPEC_ALIGN))]
7738   "TARGET_AVX512F"
7739   "valign<ssemodesuffix>\t{%3, %2, %1, %0<mask_operand4>|%0<mask_operand4>, %1, %2, %3}";
7740   [(set_attr "prefix" "evex")
7741    (set_attr "mode" "<sseinsnmode>")])
7742
7743 (define_expand "avx512f_shufps512_mask"
7744   [(match_operand:V16SF 0 "register_operand")
7745    (match_operand:V16SF 1 "register_operand")
7746    (match_operand:V16SF 2 "nonimmediate_operand")
7747    (match_operand:SI 3 "const_0_to_255_operand")
7748    (match_operand:V16SF 4 "register_operand")
7749    (match_operand:HI 5 "register_operand")]
7750   "TARGET_AVX512F"
7751 {
7752   int mask = INTVAL (operands[3]);
7753   emit_insn (gen_avx512f_shufps512_1_mask (operands[0], operands[1], operands[2],
7754                                           GEN_INT ((mask >> 0) & 3),
7755                                           GEN_INT ((mask >> 2) & 3),
7756                                           GEN_INT (((mask >> 4) & 3) + 16),
7757                                           GEN_INT (((mask >> 6) & 3) + 16),
7758                                           GEN_INT (((mask >> 0) & 3) + 4),
7759                                           GEN_INT (((mask >> 2) & 3) + 4),
7760                                           GEN_INT (((mask >> 4) & 3) + 20),
7761                                           GEN_INT (((mask >> 6) & 3) + 20),
7762                                           GEN_INT (((mask >> 0) & 3) + 8),
7763                                           GEN_INT (((mask >> 2) & 3) + 8),
7764                                           GEN_INT (((mask >> 4) & 3) + 24),
7765                                           GEN_INT (((mask >> 6) & 3) + 24),
7766                                           GEN_INT (((mask >> 0) & 3) + 12),
7767                                           GEN_INT (((mask >> 2) & 3) + 12),
7768                                           GEN_INT (((mask >> 4) & 3) + 28),
7769                                           GEN_INT (((mask >> 6) & 3) + 28),
7770                                           operands[4], operands[5]));
7771   DONE;
7772 })
7773
7774
7775 (define_expand "<avx512>_fixupimm<mode>_maskz<round_saeonly_expand_name>"
7776   [(match_operand:VF_AVX512VL 0 "register_operand")
7777    (match_operand:VF_AVX512VL 1 "register_operand")
7778    (match_operand:VF_AVX512VL 2 "register_operand")
7779    (match_operand:<sseintvecmode> 3 "<round_saeonly_expand_nimm_predicate>")
7780    (match_operand:SI 4 "const_0_to_255_operand")
7781    (match_operand:<avx512fmaskmode> 5 "register_operand")]
7782   "TARGET_AVX512F"
7783 {
7784   emit_insn (gen_<avx512>_fixupimm<mode>_maskz_1<round_saeonly_expand_name> (
7785         operands[0], operands[1], operands[2], operands[3],
7786         operands[4], CONST0_RTX (<MODE>mode), operands[5]
7787         <round_saeonly_expand_operand6>));
7788   DONE;
7789 })
7790
7791 (define_insn "<avx512>_fixupimm<mode><sd_maskz_name><round_saeonly_name>"
7792   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
7793         (unspec:VF_AVX512VL
7794           [(match_operand:VF_AVX512VL 1 "register_operand" "0")
7795            (match_operand:VF_AVX512VL 2 "register_operand" "v")
7796            (match_operand:<sseintvecmode> 3 "nonimmediate_operand" "<round_saeonly_constraint>")
7797            (match_operand:SI 4 "const_0_to_255_operand")]
7798            UNSPEC_FIXUPIMM))]
7799   "TARGET_AVX512F"
7800   "vfixupimm<ssemodesuffix>\t{%4, <round_saeonly_sd_mask_op5>%3, %2, %0<sd_mask_op5>|%0<sd_mask_op5>, %2, %3<round_saeonly_sd_mask_op5>, %4}";
7801   [(set_attr "prefix" "evex")
7802    (set_attr "mode" "<MODE>")])
7803
7804 (define_insn "<avx512>_fixupimm<mode>_mask<round_saeonly_name>"
7805   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
7806         (vec_merge:VF_AVX512VL
7807           (unspec:VF_AVX512VL
7808             [(match_operand:VF_AVX512VL 1 "register_operand" "0")
7809              (match_operand:VF_AVX512VL 2 "register_operand" "v")
7810              (match_operand:<sseintvecmode> 3 "nonimmediate_operand" "<round_saeonly_constraint>")
7811              (match_operand:SI 4 "const_0_to_255_operand")]
7812              UNSPEC_FIXUPIMM)
7813           (match_dup 1)
7814           (match_operand:<avx512fmaskmode> 5 "register_operand" "Yk")))]
7815   "TARGET_AVX512F"
7816   "vfixupimm<ssemodesuffix>\t{%4, <round_saeonly_op6>%3, %2, %0%{%5%}|%0%{%5%}, %2, %3<round_saeonly_op6>, %4}";
7817   [(set_attr "prefix" "evex")
7818    (set_attr "mode" "<MODE>")])
7819
7820 (define_expand "avx512f_sfixupimm<mode>_maskz<round_saeonly_expand_name>"
7821   [(match_operand:VF_128 0 "register_operand")
7822    (match_operand:VF_128 1 "register_operand")
7823    (match_operand:VF_128 2 "register_operand")
7824    (match_operand:<sseintvecmode> 3 "<round_saeonly_expand_nimm_predicate>")
7825    (match_operand:SI 4 "const_0_to_255_operand")
7826    (match_operand:<avx512fmaskmode> 5 "register_operand")]
7827   "TARGET_AVX512F"
7828 {
7829   emit_insn (gen_avx512f_sfixupimm<mode>_maskz_1<round_saeonly_expand_name> (
7830         operands[0], operands[1], operands[2], operands[3],
7831         operands[4], CONST0_RTX (<MODE>mode), operands[5]
7832         <round_saeonly_expand_operand6>));
7833   DONE;
7834 })
7835
7836 (define_insn "avx512f_sfixupimm<mode><sd_maskz_name><round_saeonly_name>"
7837   [(set (match_operand:VF_128 0 "register_operand" "=v")
7838         (vec_merge:VF_128
7839           (unspec:VF_128
7840             [(match_operand:VF_128 1 "register_operand" "0")
7841              (match_operand:VF_128 2 "register_operand" "v")
7842              (match_operand:<sseintvecmode> 3 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
7843              (match_operand:SI 4 "const_0_to_255_operand")]
7844             UNSPEC_FIXUPIMM)
7845           (match_dup 1)
7846           (const_int 1)))]
7847    "TARGET_AVX512F"
7848    "vfixupimm<ssescalarmodesuffix>\t{%4, <round_saeonly_sd_mask_op5>%3, %2, %0<sd_mask_op5>|%0<sd_mask_op5>, %2, %3<round_saeonly_sd_mask_op5>, %4}";
7849    [(set_attr "prefix" "evex")
7850    (set_attr "mode" "<ssescalarmode>")])
7851
7852 (define_insn "avx512f_sfixupimm<mode>_mask<round_saeonly_name>"
7853   [(set (match_operand:VF_128 0 "register_operand" "=v")
7854         (vec_merge:VF_128
7855           (vec_merge:VF_128
7856             (unspec:VF_128
7857                [(match_operand:VF_128 1 "register_operand" "0")
7858                 (match_operand:VF_128 2 "register_operand" "v")
7859                 (match_operand:<sseintvecmode> 3 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
7860                 (match_operand:SI 4 "const_0_to_255_operand")]
7861                UNSPEC_FIXUPIMM)
7862             (match_dup 1)
7863             (const_int 1))
7864           (match_dup 1)
7865           (match_operand:<avx512fmaskmode> 5 "register_operand" "Yk")))]
7866   "TARGET_AVX512F"
7867   "vfixupimm<ssescalarmodesuffix>\t{%4, <round_saeonly_op6>%3, %2, %0%{%5%}|%0%{%5%}, %2, %3<round_saeonly_op6>, %4}";
7868   [(set_attr "prefix" "evex")
7869    (set_attr "mode" "<ssescalarmode>")])
7870
7871 (define_insn "<avx512>_rndscale<mode><mask_name><round_saeonly_name>"
7872   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
7873         (unspec:VF_AVX512VL
7874           [(match_operand:VF_AVX512VL 1 "nonimmediate_operand" "<round_saeonly_constraint>")
7875            (match_operand:SI 2 "const_0_to_255_operand")]
7876           UNSPEC_ROUND))]
7877   "TARGET_AVX512F"
7878   "vrndscale<ssemodesuffix>\t{%2, <round_saeonly_mask_op3>%1, %0<mask_operand3>|%0<mask_operand3>, %1<round_saeonly_mask_op3>, %2}"
7879   [(set_attr "length_immediate" "1")
7880    (set_attr "prefix" "evex")
7881    (set_attr "mode" "<MODE>")])
7882
7883 (define_insn "avx512f_rndscale<mode><round_saeonly_name>"
7884   [(set (match_operand:VF_128 0 "register_operand" "=v")
7885         (vec_merge:VF_128
7886           (unspec:VF_128
7887             [(match_operand:VF_128 1 "register_operand" "v")
7888              (match_operand:VF_128 2 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
7889              (match_operand:SI 3 "const_0_to_255_operand")]
7890             UNSPEC_ROUND)
7891           (match_dup 1)
7892           (const_int 1)))]
7893   "TARGET_AVX512F"
7894   "vrndscale<ssescalarmodesuffix>\t{%3, <round_saeonly_op4>%2, %1, %0|%0, %1, %2<round_saeonly_op4>, %3}"
7895   [(set_attr "length_immediate" "1")
7896    (set_attr "prefix" "evex")
7897    (set_attr "mode" "<MODE>")])
7898
7899 ;; One bit in mask selects 2 elements.
7900 (define_insn "avx512f_shufps512_1<mask_name>"
7901   [(set (match_operand:V16SF 0 "register_operand" "=v")
7902         (vec_select:V16SF
7903           (vec_concat:V32SF
7904             (match_operand:V16SF 1 "register_operand" "v")
7905             (match_operand:V16SF 2 "nonimmediate_operand" "vm"))
7906           (parallel [(match_operand 3  "const_0_to_3_operand")
7907                      (match_operand 4  "const_0_to_3_operand")
7908                      (match_operand 5  "const_16_to_19_operand")
7909                      (match_operand 6  "const_16_to_19_operand")
7910                      (match_operand 7  "const_4_to_7_operand")
7911                      (match_operand 8  "const_4_to_7_operand")
7912                      (match_operand 9  "const_20_to_23_operand")
7913                      (match_operand 10  "const_20_to_23_operand")
7914                      (match_operand 11  "const_8_to_11_operand")
7915                      (match_operand 12  "const_8_to_11_operand")
7916                      (match_operand 13  "const_24_to_27_operand")
7917                      (match_operand 14  "const_24_to_27_operand")
7918                      (match_operand 15  "const_12_to_15_operand")
7919                      (match_operand 16  "const_12_to_15_operand")
7920                      (match_operand 17  "const_28_to_31_operand")
7921                      (match_operand 18  "const_28_to_31_operand")])))]
7922   "TARGET_AVX512F
7923    && (INTVAL (operands[3]) == (INTVAL (operands[7]) - 4)
7924        && INTVAL (operands[4]) == (INTVAL (operands[8]) - 4)
7925        && INTVAL (operands[5]) == (INTVAL (operands[9]) - 4)
7926        && INTVAL (operands[6]) == (INTVAL (operands[10]) - 4)
7927        && INTVAL (operands[3]) == (INTVAL (operands[11]) - 8)
7928        && INTVAL (operands[4]) == (INTVAL (operands[12]) - 8)
7929        && INTVAL (operands[5]) == (INTVAL (operands[13]) - 8)
7930        && INTVAL (operands[6]) == (INTVAL (operands[14]) - 8)
7931        && INTVAL (operands[3]) == (INTVAL (operands[15]) - 12)
7932        && INTVAL (operands[4]) == (INTVAL (operands[16]) - 12)
7933        && INTVAL (operands[5]) == (INTVAL (operands[17]) - 12)
7934        && INTVAL (operands[6]) == (INTVAL (operands[18]) - 12))"
7935 {
7936   int mask;
7937   mask = INTVAL (operands[3]);
7938   mask |= INTVAL (operands[4]) << 2;
7939   mask |= (INTVAL (operands[5]) - 16) << 4;
7940   mask |= (INTVAL (operands[6]) - 16) << 6;
7941   operands[3] = GEN_INT (mask);
7942
7943   return "vshufps\t{%3, %2, %1, %0<mask_operand19>|%0<mask_operand19>, %1, %2, %3}";
7944 }
7945   [(set_attr "type" "sselog")
7946    (set_attr "length_immediate" "1")
7947    (set_attr "prefix" "evex")
7948    (set_attr "mode" "V16SF")])
7949
7950 (define_expand "avx512f_shufpd512_mask"
7951   [(match_operand:V8DF 0 "register_operand")
7952    (match_operand:V8DF 1 "register_operand")
7953    (match_operand:V8DF 2 "nonimmediate_operand")
7954    (match_operand:SI 3 "const_0_to_255_operand")
7955    (match_operand:V8DF 4 "register_operand")
7956    (match_operand:QI 5 "register_operand")]
7957   "TARGET_AVX512F"
7958 {
7959   int mask = INTVAL (operands[3]);
7960   emit_insn (gen_avx512f_shufpd512_1_mask (operands[0], operands[1], operands[2],
7961                                         GEN_INT (mask & 1),
7962                                         GEN_INT (mask & 2 ? 9 : 8),
7963                                         GEN_INT (mask & 4 ? 3 : 2),
7964                                         GEN_INT (mask & 8 ? 11 : 10),
7965                                         GEN_INT (mask & 16 ? 5 : 4),
7966                                         GEN_INT (mask & 32 ? 13 : 12),
7967                                         GEN_INT (mask & 64 ? 7 : 6),
7968                                         GEN_INT (mask & 128 ? 15 : 14),
7969                                         operands[4], operands[5]));
7970   DONE;
7971 })
7972
7973 (define_insn "avx512f_shufpd512_1<mask_name>"
7974   [(set (match_operand:V8DF 0 "register_operand" "=v")
7975         (vec_select:V8DF
7976           (vec_concat:V16DF
7977             (match_operand:V8DF 1 "register_operand" "v")
7978             (match_operand:V8DF 2 "nonimmediate_operand" "vm"))
7979           (parallel [(match_operand 3 "const_0_to_1_operand")
7980                      (match_operand 4 "const_8_to_9_operand")
7981                      (match_operand 5 "const_2_to_3_operand")
7982                      (match_operand 6 "const_10_to_11_operand")
7983                      (match_operand 7 "const_4_to_5_operand")
7984                      (match_operand 8 "const_12_to_13_operand")
7985                      (match_operand 9 "const_6_to_7_operand")
7986                      (match_operand 10 "const_14_to_15_operand")])))]
7987   "TARGET_AVX512F"
7988 {
7989   int mask;
7990   mask = INTVAL (operands[3]);
7991   mask |= (INTVAL (operands[4]) - 8) << 1;
7992   mask |= (INTVAL (operands[5]) - 2) << 2;
7993   mask |= (INTVAL (operands[6]) - 10) << 3;
7994   mask |= (INTVAL (operands[7]) - 4) << 4;
7995   mask |= (INTVAL (operands[8]) - 12) << 5;
7996   mask |= (INTVAL (operands[9]) - 6) << 6;
7997   mask |= (INTVAL (operands[10]) - 14) << 7;
7998   operands[3] = GEN_INT (mask);
7999
8000   return "vshufpd\t{%3, %2, %1, %0<mask_operand11>|%0<mask_operand11>, %1, %2, %3}";
8001 }
8002   [(set_attr "type" "sselog")
8003    (set_attr "length_immediate" "1")
8004    (set_attr "prefix" "evex")
8005    (set_attr "mode" "V8DF")])
8006
8007 (define_expand "avx_shufpd256<mask_expand4_name>"
8008   [(match_operand:V4DF 0 "register_operand")
8009    (match_operand:V4DF 1 "register_operand")
8010    (match_operand:V4DF 2 "nonimmediate_operand")
8011    (match_operand:SI 3 "const_int_operand")]
8012   "TARGET_AVX"
8013 {
8014   int mask = INTVAL (operands[3]);
8015   emit_insn (gen_avx_shufpd256_1<mask_expand4_name> (operands[0],
8016                                                      operands[1],
8017                                                      operands[2],
8018                                                      GEN_INT (mask & 1),
8019                                                      GEN_INT (mask & 2 ? 5 : 4),
8020                                                      GEN_INT (mask & 4 ? 3 : 2),
8021                                                      GEN_INT (mask & 8 ? 7 : 6)
8022                                                      <mask_expand4_args>));
8023   DONE;
8024 })
8025
8026 (define_insn "avx_shufpd256_1<mask_name>"
8027   [(set (match_operand:V4DF 0 "register_operand" "=v")
8028         (vec_select:V4DF
8029           (vec_concat:V8DF
8030             (match_operand:V4DF 1 "register_operand" "v")
8031             (match_operand:V4DF 2 "nonimmediate_operand" "vm"))
8032           (parallel [(match_operand 3 "const_0_to_1_operand")
8033                      (match_operand 4 "const_4_to_5_operand")
8034                      (match_operand 5 "const_2_to_3_operand")
8035                      (match_operand 6 "const_6_to_7_operand")])))]
8036   "TARGET_AVX && <mask_avx512vl_condition>"
8037 {
8038   int mask;
8039   mask = INTVAL (operands[3]);
8040   mask |= (INTVAL (operands[4]) - 4) << 1;
8041   mask |= (INTVAL (operands[5]) - 2) << 2;
8042   mask |= (INTVAL (operands[6]) - 6) << 3;
8043   operands[3] = GEN_INT (mask);
8044
8045   return "vshufpd\t{%3, %2, %1, %0<mask_operand7>|%0<mask_operand7>, %1, %2, %3}";
8046 }
8047   [(set_attr "type" "sseshuf")
8048    (set_attr "length_immediate" "1")
8049    (set_attr "prefix" "vex")
8050    (set_attr "mode" "V4DF")])
8051
8052 (define_expand "sse2_shufpd<mask_expand4_name>"
8053   [(match_operand:V2DF 0 "register_operand")
8054    (match_operand:V2DF 1 "register_operand")
8055    (match_operand:V2DF 2 "nonimmediate_operand")
8056    (match_operand:SI 3 "const_int_operand")]
8057   "TARGET_SSE2"
8058 {
8059   int mask = INTVAL (operands[3]);
8060   emit_insn (gen_sse2_shufpd_v2df<mask_expand4_name> (operands[0], operands[1],
8061                                                       operands[2], GEN_INT (mask & 1),
8062                                                       GEN_INT (mask & 2 ? 3 : 2)
8063                                                       <mask_expand4_args>));
8064   DONE;
8065 })
8066
8067 (define_insn "sse2_shufpd_v2df_mask"
8068   [(set (match_operand:V2DF 0 "register_operand" "=v")
8069     (vec_merge:V2DF
8070           (vec_select:V2DF
8071             (vec_concat:V4DF
8072               (match_operand:V2DF 1 "register_operand" "v")
8073               (match_operand:V2DF 2 "nonimmediate_operand" "vm"))
8074             (parallel [(match_operand 3 "const_0_to_1_operand")
8075                            (match_operand 4 "const_2_to_3_operand")]))
8076       (match_operand:V2DF 5 "vector_move_operand" "0C")
8077       (match_operand:QI 6 "register_operand" "Yk")))]
8078   "TARGET_AVX512VL"
8079 {
8080   int mask;
8081   mask = INTVAL (operands[3]);
8082   mask |= (INTVAL (operands[4]) - 2) << 1;
8083   operands[3] = GEN_INT (mask);
8084
8085   return "vshufpd\t{%3, %2, %1, %0%{%6%}%N5|%0%{6%}%N5, %1, %2, %3}";
8086 }
8087   [(set_attr "type" "sseshuf")
8088    (set_attr "length_immediate" "1")
8089    (set_attr "prefix" "evex")
8090    (set_attr "mode" "V2DF")])
8091
8092 ;; punpcklqdq and punpckhqdq are shorter than shufpd.
8093 (define_insn "avx2_interleave_highv4di<mask_name>"
8094   [(set (match_operand:V4DI 0 "register_operand" "=v")
8095         (vec_select:V4DI
8096           (vec_concat:V8DI
8097             (match_operand:V4DI 1 "register_operand" "v")
8098             (match_operand:V4DI 2 "nonimmediate_operand" "vm"))
8099           (parallel [(const_int 1)
8100                      (const_int 5)
8101                      (const_int 3)
8102                      (const_int 7)])))]
8103   "TARGET_AVX2 && <mask_avx512vl_condition>"
8104   "vpunpckhqdq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
8105   [(set_attr "type" "sselog")
8106    (set_attr "prefix" "vex")
8107    (set_attr "mode" "OI")])
8108
8109 (define_insn "<mask_codefor>avx512f_interleave_highv8di<mask_name>"
8110   [(set (match_operand:V8DI 0 "register_operand" "=v")
8111         (vec_select:V8DI
8112           (vec_concat:V16DI
8113             (match_operand:V8DI 1 "register_operand" "v")
8114             (match_operand:V8DI 2 "nonimmediate_operand" "vm"))
8115           (parallel [(const_int 1) (const_int 9)
8116                      (const_int 3) (const_int 11)
8117                      (const_int 5) (const_int 13)
8118                      (const_int 7) (const_int 15)])))]
8119   "TARGET_AVX512F"
8120   "vpunpckhqdq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
8121   [(set_attr "type" "sselog")
8122    (set_attr "prefix" "evex")
8123    (set_attr "mode" "XI")])
8124
8125 (define_insn "vec_interleave_highv2di<mask_name>"
8126   [(set (match_operand:V2DI 0 "register_operand" "=x,v")
8127         (vec_select:V2DI
8128           (vec_concat:V4DI
8129             (match_operand:V2DI 1 "register_operand" "0,v")
8130             (match_operand:V2DI 2 "nonimmediate_operand" "xm,vm"))
8131           (parallel [(const_int 1)
8132                      (const_int 3)])))]
8133   "TARGET_SSE2 && <mask_avx512vl_condition>"
8134   "@
8135    punpckhqdq\t{%2, %0|%0, %2}
8136    vpunpckhqdq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
8137   [(set_attr "isa" "noavx,avx")
8138    (set_attr "type" "sselog")
8139    (set_attr "prefix_data16" "1,*")
8140    (set_attr "prefix" "orig,<mask_prefix>")
8141    (set_attr "mode" "TI")])
8142
8143 (define_insn "avx2_interleave_lowv4di<mask_name>"
8144   [(set (match_operand:V4DI 0 "register_operand" "=v")
8145         (vec_select:V4DI
8146           (vec_concat:V8DI
8147             (match_operand:V4DI 1 "register_operand" "v")
8148             (match_operand:V4DI 2 "nonimmediate_operand" "vm"))
8149           (parallel [(const_int 0)
8150                      (const_int 4)
8151                      (const_int 2)
8152                      (const_int 6)])))]
8153   "TARGET_AVX2 && <mask_avx512vl_condition>"
8154   "vpunpcklqdq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
8155   [(set_attr "type" "sselog")
8156    (set_attr "prefix" "vex")
8157    (set_attr "mode" "OI")])
8158
8159 (define_insn "<mask_codefor>avx512f_interleave_lowv8di<mask_name>"
8160   [(set (match_operand:V8DI 0 "register_operand" "=v")
8161         (vec_select:V8DI
8162           (vec_concat:V16DI
8163             (match_operand:V8DI 1 "register_operand" "v")
8164             (match_operand:V8DI 2 "nonimmediate_operand" "vm"))
8165           (parallel [(const_int 0) (const_int 8)
8166                      (const_int 2) (const_int 10)
8167                      (const_int 4) (const_int 12)
8168                      (const_int 6) (const_int 14)])))]
8169   "TARGET_AVX512F"
8170   "vpunpcklqdq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
8171   [(set_attr "type" "sselog")
8172    (set_attr "prefix" "evex")
8173    (set_attr "mode" "XI")])
8174
8175 (define_insn "vec_interleave_lowv2di<mask_name>"
8176   [(set (match_operand:V2DI 0 "register_operand" "=x,v")
8177         (vec_select:V2DI
8178           (vec_concat:V4DI
8179             (match_operand:V2DI 1 "register_operand" "0,v")
8180             (match_operand:V2DI 2 "nonimmediate_operand" "xm,vm"))
8181           (parallel [(const_int 0)
8182                      (const_int 2)])))]
8183   "TARGET_SSE2 && <mask_avx512vl_condition>"
8184   "@
8185    punpcklqdq\t{%2, %0|%0, %2}
8186    vpunpcklqdq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
8187   [(set_attr "isa" "noavx,avx")
8188    (set_attr "type" "sselog")
8189    (set_attr "prefix_data16" "1,*")
8190    (set_attr "prefix" "orig,vex")
8191    (set_attr "mode" "TI")])
8192
8193 (define_insn "sse2_shufpd_<mode>"
8194   [(set (match_operand:VI8F_128 0 "register_operand" "=x,x")
8195         (vec_select:VI8F_128
8196           (vec_concat:<ssedoublevecmode>
8197             (match_operand:VI8F_128 1 "register_operand" "0,x")
8198             (match_operand:VI8F_128 2 "nonimmediate_operand" "xm,xm"))
8199           (parallel [(match_operand 3 "const_0_to_1_operand")
8200                      (match_operand 4 "const_2_to_3_operand")])))]
8201   "TARGET_SSE2"
8202 {
8203   int mask;
8204   mask = INTVAL (operands[3]);
8205   mask |= (INTVAL (operands[4]) - 2) << 1;
8206   operands[3] = GEN_INT (mask);
8207
8208   switch (which_alternative)
8209     {
8210     case 0:
8211       return "shufpd\t{%3, %2, %0|%0, %2, %3}";
8212     case 1:
8213       return "vshufpd\t{%3, %2, %1, %0|%0, %1, %2, %3}";
8214     default:
8215       gcc_unreachable ();
8216     }
8217 }
8218   [(set_attr "isa" "noavx,avx")
8219    (set_attr "type" "sseshuf")
8220    (set_attr "length_immediate" "1")
8221    (set_attr "prefix" "orig,vex")
8222    (set_attr "mode" "V2DF")])
8223
8224 ;; Avoid combining registers from different units in a single alternative,
8225 ;; see comment above inline_secondary_memory_needed function in i386.c
8226 (define_insn "sse2_storehpd"
8227   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,x,*f,r")
8228         (vec_select:DF
8229           (match_operand:V2DF 1 "nonimmediate_operand" " x,0,x,o,o,o")
8230           (parallel [(const_int 1)])))]
8231   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8232   "@
8233    %vmovhpd\t{%1, %0|%0, %1}
8234    unpckhpd\t%0, %0
8235    vunpckhpd\t{%d1, %0|%0, %d1}
8236    #
8237    #
8238    #"
8239   [(set_attr "isa" "*,noavx,avx,*,*,*")
8240    (set_attr "type" "ssemov,sselog1,sselog1,ssemov,fmov,imov")
8241    (set (attr "prefix_data16")
8242      (if_then_else
8243        (and (eq_attr "alternative" "0")
8244             (not (match_test "TARGET_AVX")))
8245        (const_string "1")
8246        (const_string "*")))
8247    (set_attr "prefix" "maybe_vex,orig,vex,*,*,*")
8248    (set_attr "mode" "V1DF,V1DF,V2DF,DF,DF,DF")])
8249
8250 (define_split
8251   [(set (match_operand:DF 0 "register_operand")
8252         (vec_select:DF
8253           (match_operand:V2DF 1 "memory_operand")
8254           (parallel [(const_int 1)])))]
8255   "TARGET_SSE2 && reload_completed"
8256   [(set (match_dup 0) (match_dup 1))]
8257   "operands[1] = adjust_address (operands[1], DFmode, 8);")
8258
8259 (define_insn "*vec_extractv2df_1_sse"
8260   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
8261         (vec_select:DF
8262           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,o")
8263           (parallel [(const_int 1)])))]
8264   "!TARGET_SSE2 && TARGET_SSE
8265    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8266   "@
8267    movhps\t{%1, %0|%q0, %1}
8268    movhlps\t{%1, %0|%0, %1}
8269    movlps\t{%H1, %0|%0, %H1}"
8270   [(set_attr "type" "ssemov")
8271    (set_attr "ssememalign" "64")
8272    (set_attr "mode" "V2SF,V4SF,V2SF")])
8273
8274 ;; Avoid combining registers from different units in a single alternative,
8275 ;; see comment above inline_secondary_memory_needed function in i386.c
8276 (define_insn "sse2_storelpd"
8277   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,*f,r")
8278         (vec_select:DF
8279           (match_operand:V2DF 1 "nonimmediate_operand" " x,x,m,m,m")
8280           (parallel [(const_int 0)])))]
8281   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8282   "@
8283    %vmovlpd\t{%1, %0|%0, %1}
8284    #
8285    #
8286    #
8287    #"
8288   [(set_attr "type" "ssemov,ssemov,ssemov,fmov,imov")
8289    (set_attr "prefix_data16" "1,*,*,*,*")
8290    (set_attr "prefix" "maybe_vex")
8291    (set_attr "mode" "V1DF,DF,DF,DF,DF")])
8292
8293 (define_split
8294   [(set (match_operand:DF 0 "register_operand")
8295         (vec_select:DF
8296           (match_operand:V2DF 1 "nonimmediate_operand")
8297           (parallel [(const_int 0)])))]
8298   "TARGET_SSE2 && reload_completed"
8299   [(set (match_dup 0) (match_dup 1))]
8300 {
8301   if (REG_P (operands[1]))
8302     operands[1] = gen_rtx_REG (DFmode, REGNO (operands[1]));
8303   else
8304     operands[1] = adjust_address (operands[1], DFmode, 0);
8305 })
8306
8307 (define_insn "*vec_extractv2df_0_sse"
8308   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
8309         (vec_select:DF
8310           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,m")
8311           (parallel [(const_int 0)])))]
8312   "!TARGET_SSE2 && TARGET_SSE
8313    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
8314   "@
8315    movlps\t{%1, %0|%0, %1}
8316    movaps\t{%1, %0|%0, %1}
8317    movlps\t{%1, %0|%0, %q1}"
8318   [(set_attr "type" "ssemov")
8319    (set_attr "mode" "V2SF,V4SF,V2SF")])
8320
8321 (define_expand "sse2_loadhpd_exp"
8322   [(set (match_operand:V2DF 0 "nonimmediate_operand")
8323         (vec_concat:V2DF
8324           (vec_select:DF
8325             (match_operand:V2DF 1 "nonimmediate_operand")
8326             (parallel [(const_int 0)]))
8327           (match_operand:DF 2 "nonimmediate_operand")))]
8328   "TARGET_SSE2"
8329 {
8330   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
8331
8332   emit_insn (gen_sse2_loadhpd (dst, operands[1], operands[2]));
8333
8334   /* Fix up the destination if needed.  */
8335   if (dst != operands[0])
8336     emit_move_insn (operands[0], dst);
8337
8338   DONE;
8339 })
8340
8341 ;; Avoid combining registers from different units in a single alternative,
8342 ;; see comment above inline_secondary_memory_needed function in i386.c
8343 (define_insn "sse2_loadhpd"
8344   [(set (match_operand:V2DF 0 "nonimmediate_operand"
8345           "=x,x,x,x,o,o ,o")
8346         (vec_concat:V2DF
8347           (vec_select:DF
8348             (match_operand:V2DF 1 "nonimmediate_operand"
8349           " 0,x,0,x,0,0 ,0")
8350             (parallel [(const_int 0)]))
8351           (match_operand:DF 2 "nonimmediate_operand"
8352           " m,m,x,x,x,*f,r")))]
8353   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
8354   "@
8355    movhpd\t{%2, %0|%0, %2}
8356    vmovhpd\t{%2, %1, %0|%0, %1, %2}
8357    unpcklpd\t{%2, %0|%0, %2}
8358    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
8359    #
8360    #
8361    #"
8362   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
8363    (set_attr "type" "ssemov,ssemov,sselog,sselog,ssemov,fmov,imov")
8364    (set_attr "ssememalign" "64")
8365    (set_attr "prefix_data16" "1,*,*,*,*,*,*")
8366    (set_attr "prefix" "orig,vex,orig,vex,*,*,*")
8367    (set_attr "mode" "V1DF,V1DF,V2DF,V2DF,DF,DF,DF")])
8368
8369 (define_split
8370   [(set (match_operand:V2DF 0 "memory_operand")
8371         (vec_concat:V2DF
8372           (vec_select:DF (match_dup 0) (parallel [(const_int 0)]))
8373           (match_operand:DF 1 "register_operand")))]
8374   "TARGET_SSE2 && reload_completed"
8375   [(set (match_dup 0) (match_dup 1))]
8376   "operands[0] = adjust_address (operands[0], DFmode, 8);")
8377
8378 (define_expand "sse2_loadlpd_exp"
8379   [(set (match_operand:V2DF 0 "nonimmediate_operand")
8380         (vec_concat:V2DF
8381           (match_operand:DF 2 "nonimmediate_operand")
8382           (vec_select:DF
8383             (match_operand:V2DF 1 "nonimmediate_operand")
8384             (parallel [(const_int 1)]))))]
8385   "TARGET_SSE2"
8386 {
8387   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
8388
8389   emit_insn (gen_sse2_loadlpd (dst, operands[1], operands[2]));
8390
8391   /* Fix up the destination if needed.  */
8392   if (dst != operands[0])
8393     emit_move_insn (operands[0], dst);
8394
8395   DONE;
8396 })
8397
8398 ;; Avoid combining registers from different units in a single alternative,
8399 ;; see comment above inline_secondary_memory_needed function in i386.c
8400 (define_insn "sse2_loadlpd"
8401   [(set (match_operand:V2DF 0 "nonimmediate_operand"
8402           "=x,x,x,x,x,x,x,x,m,m ,m")
8403         (vec_concat:V2DF
8404           (match_operand:DF 2 "nonimmediate_operand"
8405           " m,m,m,x,x,0,0,x,x,*f,r")
8406           (vec_select:DF
8407             (match_operand:V2DF 1 "vector_move_operand"
8408           " C,0,x,0,x,x,o,o,0,0 ,0")
8409             (parallel [(const_int 1)]))))]
8410   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
8411   "@
8412    %vmovsd\t{%2, %0|%0, %2}
8413    movlpd\t{%2, %0|%0, %2}
8414    vmovlpd\t{%2, %1, %0|%0, %1, %2}
8415    movsd\t{%2, %0|%0, %2}
8416    vmovsd\t{%2, %1, %0|%0, %1, %2}
8417    shufpd\t{$2, %1, %0|%0, %1, 2}
8418    movhpd\t{%H1, %0|%0, %H1}
8419    vmovhpd\t{%H1, %2, %0|%0, %2, %H1}
8420    #
8421    #
8422    #"
8423   [(set_attr "isa" "*,noavx,avx,noavx,avx,noavx,noavx,avx,*,*,*")
8424    (set (attr "type")
8425      (cond [(eq_attr "alternative" "5")
8426               (const_string "sselog")
8427             (eq_attr "alternative" "9")
8428               (const_string "fmov")
8429             (eq_attr "alternative" "10")
8430               (const_string "imov")
8431            ]
8432            (const_string "ssemov")))
8433    (set_attr "ssememalign" "64")
8434    (set_attr "prefix_data16" "*,1,*,*,*,*,1,*,*,*,*")
8435    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*,*,*")
8436    (set_attr "prefix" "maybe_vex,orig,vex,orig,vex,orig,orig,vex,*,*,*")
8437    (set_attr "mode" "DF,V1DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,DF,DF,DF")])
8438
8439 (define_split
8440   [(set (match_operand:V2DF 0 "memory_operand")
8441         (vec_concat:V2DF
8442           (match_operand:DF 1 "register_operand")
8443           (vec_select:DF (match_dup 0) (parallel [(const_int 1)]))))]
8444   "TARGET_SSE2 && reload_completed"
8445   [(set (match_dup 0) (match_dup 1))]
8446   "operands[0] = adjust_address (operands[0], DFmode, 0);")
8447
8448 (define_insn "sse2_movsd"
8449   [(set (match_operand:V2DF 0 "nonimmediate_operand"   "=x,x,x,x,m,x,x,x,o")
8450         (vec_merge:V2DF
8451           (match_operand:V2DF 2 "nonimmediate_operand" " x,x,m,m,x,0,0,x,0")
8452           (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,0,x,0,x,o,o,x")
8453           (const_int 1)))]
8454   "TARGET_SSE2"
8455   "@
8456    movsd\t{%2, %0|%0, %2}
8457    vmovsd\t{%2, %1, %0|%0, %1, %2}
8458    movlpd\t{%2, %0|%0, %q2}
8459    vmovlpd\t{%2, %1, %0|%0, %1, %q2}
8460    %vmovlpd\t{%2, %0|%q0, %2}
8461    shufpd\t{$2, %1, %0|%0, %1, 2}
8462    movhps\t{%H1, %0|%0, %H1}
8463    vmovhps\t{%H1, %2, %0|%0, %2, %H1}
8464    %vmovhps\t{%1, %H0|%H0, %1}"
8465   [(set_attr "isa" "noavx,avx,noavx,avx,*,noavx,noavx,avx,*")
8466    (set (attr "type")
8467      (if_then_else
8468        (eq_attr "alternative" "5")
8469        (const_string "sselog")
8470        (const_string "ssemov")))
8471    (set (attr "prefix_data16")
8472      (if_then_else
8473        (and (eq_attr "alternative" "2,4")
8474             (not (match_test "TARGET_AVX")))
8475        (const_string "1")
8476        (const_string "*")))
8477    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*")
8478    (set_attr "ssememalign" "64")
8479    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig,vex,maybe_vex")
8480    (set_attr "mode" "DF,DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,V1DF")])
8481
8482 (define_insn "vec_dupv2df<mask_name>"
8483   [(set (match_operand:V2DF 0 "register_operand"     "=x,v")
8484         (vec_duplicate:V2DF
8485           (match_operand:DF 1 "nonimmediate_operand" " 0,vm")))]
8486   "TARGET_SSE2 && <mask_avx512vl_condition>"
8487   "@
8488    unpcklpd\t%0, %0
8489    %vmovddup\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
8490   [(set_attr "isa" "noavx,sse3")
8491    (set_attr "type" "sselog1")
8492    (set_attr "prefix" "orig,maybe_vex")
8493    (set_attr "mode" "V2DF,DF")])
8494
8495 (define_insn "*vec_concatv2df"
8496   [(set (match_operand:V2DF 0 "register_operand"     "=x,v,v,x,x,v,x,x")
8497         (vec_concat:V2DF
8498           (match_operand:DF 1 "nonimmediate_operand" " 0,v,m,0,x,m,0,0")
8499           (match_operand:DF 2 "vector_move_operand"  " x,v,1,m,m,C,x,m")))]
8500   "TARGET_SSE"
8501   "@
8502    unpcklpd\t{%2, %0|%0, %2}
8503    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
8504    %vmovddup\t{%1, %0|%0, %1}
8505    movhpd\t{%2, %0|%0, %2}
8506    vmovhpd\t{%2, %1, %0|%0, %1, %2}
8507    %vmovsd\t{%1, %0|%0, %1}
8508    movlhps\t{%2, %0|%0, %2}
8509    movhps\t{%2, %0|%0, %2}"
8510   [(set_attr "isa" "sse2_noavx,avx,sse3,sse2_noavx,avx,sse2,noavx,noavx")
8511    (set (attr "type")
8512      (if_then_else
8513        (eq_attr "alternative" "0,1,2")
8514        (const_string "sselog")
8515        (const_string "ssemov")))
8516    (set_attr "prefix_data16" "*,*,*,1,*,*,*,*")
8517    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex,orig,orig")
8518    (set_attr "mode" "V2DF,V2DF,DF,V1DF,V1DF,DF,V4SF,V2SF")])
8519
8520 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8521 ;;
8522 ;; Parallel integer down-conversion operations
8523 ;;
8524 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8525
8526 (define_mode_iterator PMOV_DST_MODE_1 [V16QI V16HI V8SI V8HI])
8527 (define_mode_attr pmov_src_mode
8528   [(V16QI "V16SI") (V16HI "V16SI") (V8SI "V8DI") (V8HI "V8DI")])
8529 (define_mode_attr pmov_src_lower
8530   [(V16QI "v16si") (V16HI "v16si") (V8SI "v8di") (V8HI "v8di")])
8531 (define_mode_attr pmov_suff_1
8532   [(V16QI "db") (V16HI "dw") (V8SI "qd") (V8HI "qw")])
8533
8534 (define_insn "*avx512f_<code><pmov_src_lower><mode>2"
8535   [(set (match_operand:PMOV_DST_MODE_1 0 "nonimmediate_operand" "=v,m")
8536         (any_truncate:PMOV_DST_MODE_1
8537           (match_operand:<pmov_src_mode> 1 "register_operand" "v,v")))]
8538   "TARGET_AVX512F"
8539   "vpmov<trunsuffix><pmov_suff_1>\t{%1, %0|%0, %1}"
8540   [(set_attr "type" "ssemov")
8541    (set_attr "memory" "none,store")
8542    (set_attr "prefix" "evex")
8543    (set_attr "mode" "<sseinsnmode>")])
8544
8545 (define_insn "avx512f_<code><pmov_src_lower><mode>2_mask"
8546   [(set (match_operand:PMOV_DST_MODE_1 0 "nonimmediate_operand" "=v,m")
8547     (vec_merge:PMOV_DST_MODE_1
8548       (any_truncate:PMOV_DST_MODE_1
8549         (match_operand:<pmov_src_mode> 1 "register_operand" "v,v"))
8550       (match_operand:PMOV_DST_MODE_1 2 "vector_move_operand" "0C,0")
8551       (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk,Yk")))]
8552   "TARGET_AVX512F"
8553   "vpmov<trunsuffix><pmov_suff_1>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
8554   [(set_attr "type" "ssemov")
8555    (set_attr "memory" "none,store")
8556    (set_attr "prefix" "evex")
8557    (set_attr "mode" "<sseinsnmode>")])
8558
8559 (define_expand "avx512f_<code><pmov_src_lower><mode>2_mask_store"
8560   [(set (match_operand:PMOV_DST_MODE_1 0 "memory_operand")
8561     (vec_merge:PMOV_DST_MODE_1
8562       (any_truncate:PMOV_DST_MODE_1
8563         (match_operand:<pmov_src_mode> 1 "register_operand"))
8564       (match_dup 0)
8565       (match_operand:<avx512fmaskmode> 2 "register_operand")))]
8566   "TARGET_AVX512F")
8567
8568 (define_insn "*avx512bw_<code>v32hiv32qi2"
8569   [(set (match_operand:V32QI 0 "nonimmediate_operand" "=v,m")
8570         (any_truncate:V32QI
8571             (match_operand:V32HI 1 "register_operand" "v,v")))]
8572   "TARGET_AVX512BW"
8573   "vpmov<trunsuffix>wb\t{%1, %0|%0, %1}"
8574   [(set_attr "type" "ssemov")
8575    (set_attr "memory" "none,store")
8576    (set_attr "prefix" "evex")
8577    (set_attr "mode" "XI")])
8578
8579 (define_insn "avx512bw_<code>v32hiv32qi2_mask"
8580   [(set (match_operand:V32QI 0 "nonimmediate_operand" "=v,m")
8581     (vec_merge:V32QI
8582       (any_truncate:V32QI
8583         (match_operand:V32HI 1 "register_operand" "v,v"))
8584       (match_operand:V32QI 2 "vector_move_operand" "0C,0")
8585       (match_operand:SI 3 "register_operand" "Yk,Yk")))]
8586   "TARGET_AVX512BW"
8587   "vpmov<trunsuffix>wb\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
8588   [(set_attr "type" "ssemov")
8589    (set_attr "memory" "none,store")
8590    (set_attr "prefix" "evex")
8591    (set_attr "mode" "XI")])
8592
8593 (define_expand "avx512bw_<code>v32hiv32qi2_mask_store"
8594   [(set (match_operand:V32QI 0 "nonimmediate_operand")
8595     (vec_merge:V32QI
8596       (any_truncate:V32QI
8597         (match_operand:V32HI 1 "register_operand"))
8598       (match_dup 0)
8599       (match_operand:SI 2 "register_operand")))]
8600   "TARGET_AVX512BW")
8601
8602 (define_mode_iterator PMOV_DST_MODE_2
8603   [V4SI V8HI (V16QI "TARGET_AVX512BW")])
8604 (define_mode_attr pmov_suff_2
8605   [(V16QI "wb") (V8HI "dw") (V4SI "qd")])
8606
8607 (define_insn "*avx512vl_<code><ssedoublemodelower><mode>2"
8608   [(set (match_operand:PMOV_DST_MODE_2 0 "nonimmediate_operand" "=v,m")
8609         (any_truncate:PMOV_DST_MODE_2
8610             (match_operand:<ssedoublemode> 1 "register_operand" "v,v")))]
8611   "TARGET_AVX512VL"
8612   "vpmov<trunsuffix><pmov_suff_2>\t{%1, %0|%0, %1}"
8613   [(set_attr "type" "ssemov")
8614    (set_attr "memory" "none,store")
8615    (set_attr "prefix" "evex")
8616    (set_attr "mode" "<sseinsnmode>")])
8617
8618 (define_insn "<avx512>_<code><ssedoublemodelower><mode>2_mask"
8619   [(set (match_operand:PMOV_DST_MODE_2 0 "nonimmediate_operand" "=v,m")
8620     (vec_merge:PMOV_DST_MODE_2
8621       (any_truncate:PMOV_DST_MODE_2
8622         (match_operand:<ssedoublemode> 1 "register_operand" "v,v"))
8623       (match_operand:PMOV_DST_MODE_2 2 "vector_move_operand" "0C,0")
8624       (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk,Yk")))]
8625   "TARGET_AVX512VL"
8626   "vpmov<trunsuffix><pmov_suff_2>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
8627   [(set_attr "type" "ssemov")
8628    (set_attr "memory" "none,store")
8629    (set_attr "prefix" "evex")
8630    (set_attr "mode" "<sseinsnmode>")])
8631
8632 (define_expand "<avx512>_<code><ssedoublemodelower><mode>2_mask_store"
8633   [(set (match_operand:PMOV_DST_MODE_2 0 "nonimmediate_operand")
8634     (vec_merge:PMOV_DST_MODE_2
8635       (any_truncate:PMOV_DST_MODE_2
8636         (match_operand:<ssedoublemode> 1 "register_operand"))
8637       (match_dup 0)
8638       (match_operand:<avx512fmaskmode> 2 "register_operand")))]
8639   "TARGET_AVX512VL")
8640
8641 (define_mode_iterator PMOV_SRC_MODE_3 [V4DI V2DI V8SI V4SI (V8HI "TARGET_AVX512BW")])
8642 (define_mode_attr pmov_dst_3
8643   [(V4DI "V4QI") (V2DI "V2QI") (V8SI "V8QI") (V4SI "V4QI") (V8HI "V8QI")])
8644 (define_mode_attr pmov_dst_zeroed_3
8645   [(V4DI "V12QI") (V2DI "V14QI") (V8SI "V8QI") (V4SI "V12QI") (V8HI "V8QI")])
8646 (define_mode_attr pmov_suff_3
8647   [(V4DI "qb") (V2DI "qb") (V8SI "db") (V4SI "db") (V8HI "wb")])
8648
8649 (define_insn "*avx512vl_<code><mode>v<ssescalarnum>qi2"
8650   [(set (match_operand:V16QI 0 "register_operand" "=v")
8651     (vec_concat:V16QI
8652       (any_truncate:<pmov_dst_3>
8653               (match_operand:PMOV_SRC_MODE_3 1 "register_operand" "v"))
8654       (match_operand:<pmov_dst_zeroed_3> 2 "const0_operand")))]
8655   "TARGET_AVX512VL"
8656   "vpmov<trunsuffix><pmov_suff_3>\t{%1, %0|%0, %1}"
8657   [(set_attr "type" "ssemov")
8658    (set_attr "prefix" "evex")
8659    (set_attr "mode" "TI")])
8660
8661 (define_insn "*avx512vl_<code>v2div2qi2_store"
8662   [(set (match_operand:V16QI 0 "memory_operand" "=m")
8663     (vec_concat:V16QI
8664       (any_truncate:V2QI
8665               (match_operand:V2DI 1 "register_operand" "v"))
8666       (vec_select:V14QI
8667         (match_dup 0)
8668         (parallel [(const_int 2) (const_int 3)
8669                    (const_int 4) (const_int 5)
8670                    (const_int 6) (const_int 7)
8671                    (const_int 8) (const_int 9)
8672                    (const_int 10) (const_int 11)
8673                    (const_int 12) (const_int 13)
8674                    (const_int 14) (const_int 15)]))))]
8675   "TARGET_AVX512VL"
8676   "vpmov<trunsuffix>qb\t{%1, %0|%0, %1}"
8677   [(set_attr "type" "ssemov")
8678    (set_attr "memory" "store")
8679    (set_attr "prefix" "evex")
8680    (set_attr "mode" "TI")])
8681
8682 (define_insn "avx512vl_<code>v2div2qi2_mask"
8683   [(set (match_operand:V16QI 0 "register_operand" "=v")
8684     (vec_concat:V16QI
8685       (vec_merge:V2QI
8686         (any_truncate:V2QI
8687           (match_operand:V2DI 1 "register_operand" "v"))
8688         (vec_select:V2QI
8689           (match_operand:V16QI 2 "vector_move_operand" "0C")
8690           (parallel [(const_int 0) (const_int 1)]))
8691         (match_operand:QI 3 "register_operand" "Yk"))
8692       (const_vector:V14QI [(const_int 0) (const_int 0)
8693                            (const_int 0) (const_int 0)
8694                            (const_int 0) (const_int 0)
8695                            (const_int 0) (const_int 0)
8696                            (const_int 0) (const_int 0)
8697                            (const_int 0) (const_int 0)
8698                            (const_int 0) (const_int 0)])))]
8699   "TARGET_AVX512VL"
8700   "vpmov<trunsuffix>qb\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
8701   [(set_attr "type" "ssemov")
8702    (set_attr "prefix" "evex")
8703    (set_attr "mode" "TI")])
8704
8705 (define_insn "avx512vl_<code>v2div2qi2_mask_store"
8706   [(set (match_operand:V16QI 0 "memory_operand" "=m")
8707     (vec_concat:V16QI
8708       (vec_merge:V2QI
8709         (any_truncate:V2QI
8710           (match_operand:V2DI 1 "register_operand" "v"))
8711         (vec_select:V2QI
8712           (match_dup 0)
8713           (parallel [(const_int 0) (const_int 1)]))
8714         (match_operand:QI 2 "register_operand" "Yk"))
8715       (vec_select:V14QI
8716         (match_dup 0)
8717         (parallel [(const_int 2) (const_int 3)
8718                    (const_int 4) (const_int 5)
8719                    (const_int 6) (const_int 7)
8720                    (const_int 8) (const_int 9)
8721                    (const_int 10) (const_int 11)
8722                    (const_int 12) (const_int 13)
8723                    (const_int 14) (const_int 15)]))))]
8724   "TARGET_AVX512VL"
8725   "vpmov<trunsuffix>qb\t{%1, %0%{%2%}|%0%{%2%}, %1}"
8726   [(set_attr "type" "ssemov")
8727    (set_attr "memory" "store")
8728    (set_attr "prefix" "evex")
8729    (set_attr "mode" "TI")])
8730
8731 (define_insn "*avx512vl_<code><mode>v4qi2_store"
8732   [(set (match_operand:V16QI 0 "memory_operand" "=m")
8733     (vec_concat:V16QI
8734       (any_truncate:V4QI
8735               (match_operand:VI4_128_8_256 1 "register_operand" "v"))
8736       (vec_select:V12QI
8737         (match_dup 0)
8738         (parallel [(const_int 4) (const_int 5)
8739                    (const_int 6) (const_int 7)
8740                    (const_int 8) (const_int 9)
8741                    (const_int 10) (const_int 11)
8742                    (const_int 12) (const_int 13)
8743                    (const_int 14) (const_int 15)]))))]
8744   "TARGET_AVX512VL"
8745   "vpmov<trunsuffix><pmov_suff_3>\t{%1, %0|%0, %1}"
8746   [(set_attr "type" "ssemov")
8747    (set_attr "memory" "store")
8748    (set_attr "prefix" "evex")
8749    (set_attr "mode" "TI")])
8750
8751 (define_insn "avx512vl_<code><mode>v4qi2_mask"
8752   [(set (match_operand:V16QI 0 "register_operand" "=v")
8753     (vec_concat:V16QI
8754       (vec_merge:V4QI
8755         (any_truncate:V4QI
8756           (match_operand:VI4_128_8_256 1 "register_operand" "v"))
8757         (vec_select:V4QI
8758           (match_operand:V16QI 2 "vector_move_operand" "0C")
8759           (parallel [(const_int 0) (const_int 1)
8760                      (const_int 2) (const_int 3)]))
8761         (match_operand:QI 3 "register_operand" "Yk"))
8762       (const_vector:V12QI [(const_int 0) (const_int 0)
8763                            (const_int 0) (const_int 0)
8764                            (const_int 0) (const_int 0)
8765                            (const_int 0) (const_int 0)
8766                            (const_int 0) (const_int 0)
8767                            (const_int 0) (const_int 0)])))]
8768   "TARGET_AVX512VL"
8769   "vpmov<trunsuffix><pmov_suff_3>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
8770   [(set_attr "type" "ssemov")
8771    (set_attr "prefix" "evex")
8772    (set_attr "mode" "TI")])
8773
8774 (define_insn "avx512vl_<code><mode>v4qi2_mask_store"
8775   [(set (match_operand:V16QI 0 "memory_operand" "=m")
8776     (vec_concat:V16QI
8777       (vec_merge:V4QI
8778         (any_truncate:V4QI
8779           (match_operand:VI4_128_8_256 1 "register_operand" "v"))
8780         (vec_select:V4QI
8781           (match_dup 0)
8782           (parallel [(const_int 0) (const_int 1)
8783                      (const_int 2) (const_int 3)]))
8784         (match_operand:QI 2 "register_operand" "Yk"))
8785       (vec_select:V12QI
8786         (match_dup 0)
8787         (parallel [(const_int 4) (const_int 5)
8788                    (const_int 6) (const_int 7)
8789                    (const_int 8) (const_int 9)
8790                    (const_int 10) (const_int 11)
8791                    (const_int 12) (const_int 13)
8792                    (const_int 14) (const_int 15)]))))]
8793   "TARGET_AVX512VL"
8794   "vpmov<trunsuffix><pmov_suff_3>\t{%1, %0%{%2%}|%0%{%2%}, %1}"
8795   [(set_attr "type" "ssemov")
8796    (set_attr "memory" "store")
8797    (set_attr "prefix" "evex")
8798    (set_attr "mode" "TI")])
8799
8800 (define_mode_iterator VI2_128_BW_4_256
8801   [(V8HI "TARGET_AVX512BW") V8SI])
8802
8803 (define_insn "*avx512vl_<code><mode>v8qi2_store"
8804   [(set (match_operand:V16QI 0 "memory_operand" "=m")
8805     (vec_concat:V16QI
8806       (any_truncate:V8QI
8807               (match_operand:VI2_128_BW_4_256 1 "register_operand" "v"))
8808       (vec_select:V8QI
8809         (match_dup 0)
8810         (parallel [(const_int 8) (const_int 9)
8811                    (const_int 10) (const_int 11)
8812                    (const_int 12) (const_int 13)
8813                    (const_int 14) (const_int 15)]))))]
8814   "TARGET_AVX512VL"
8815   "vpmov<trunsuffix><pmov_suff_3>\t{%1, %0|%0, %1}"
8816   [(set_attr "type" "ssemov")
8817    (set_attr "memory" "store")
8818    (set_attr "prefix" "evex")
8819    (set_attr "mode" "TI")])
8820
8821 (define_insn "avx512vl_<code><mode>v8qi2_mask"
8822   [(set (match_operand:V16QI 0 "register_operand" "=v")
8823     (vec_concat:V16QI
8824       (vec_merge:V8QI
8825         (any_truncate:V8QI
8826           (match_operand:VI2_128_BW_4_256 1 "register_operand" "v"))
8827         (vec_select:V8QI
8828           (match_operand:V16QI 2 "vector_move_operand" "0C")
8829           (parallel [(const_int 0) (const_int 1)
8830                      (const_int 2) (const_int 3)
8831                      (const_int 4) (const_int 5)
8832                      (const_int 6) (const_int 7)]))
8833         (match_operand:QI 3 "register_operand" "Yk"))
8834       (const_vector:V8QI [(const_int 0) (const_int 0)
8835                           (const_int 0) (const_int 0)
8836                           (const_int 0) (const_int 0)
8837                           (const_int 0) (const_int 0)])))]
8838   "TARGET_AVX512VL"
8839   "vpmov<trunsuffix><pmov_suff_3>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
8840   [(set_attr "type" "ssemov")
8841    (set_attr "prefix" "evex")
8842    (set_attr "mode" "TI")])
8843
8844 (define_insn "avx512vl_<code><mode>v8qi2_mask_store"
8845   [(set (match_operand:V16QI 0 "memory_operand" "=m")
8846     (vec_concat:V16QI
8847       (vec_merge:V8QI
8848         (any_truncate:V8QI
8849           (match_operand:VI2_128_BW_4_256 1 "register_operand" "v"))
8850         (vec_select:V8QI
8851           (match_dup 0)
8852           (parallel [(const_int 0) (const_int 1)
8853                      (const_int 2) (const_int 3)
8854                      (const_int 4) (const_int 5)
8855                      (const_int 6) (const_int 7)]))
8856         (match_operand:QI 2 "register_operand" "Yk"))
8857       (vec_select:V8QI
8858         (match_dup 0)
8859         (parallel [(const_int 8) (const_int 9)
8860                    (const_int 10) (const_int 11)
8861                    (const_int 12) (const_int 13)
8862                    (const_int 14) (const_int 15)]))))]
8863   "TARGET_AVX512VL"
8864   "vpmov<trunsuffix><pmov_suff_3>\t{%1, %0%{%2%}|%0%{%2%}, %1}"
8865   [(set_attr "type" "ssemov")
8866    (set_attr "memory" "store")
8867    (set_attr "prefix" "evex")
8868    (set_attr "mode" "TI")])
8869
8870 (define_mode_iterator PMOV_SRC_MODE_4 [V4DI V2DI V4SI])
8871 (define_mode_attr pmov_dst_4
8872   [(V4DI "V4HI") (V2DI "V2HI") (V4SI "V4HI")])
8873 (define_mode_attr pmov_dst_zeroed_4
8874   [(V4DI "V4HI") (V2DI "V6HI") (V4SI "V4HI")])
8875 (define_mode_attr pmov_suff_4
8876   [(V4DI "qw") (V2DI "qw") (V4SI "dw")])
8877
8878 (define_insn "*avx512vl_<code><mode>v<ssescalarnum>hi2"
8879   [(set (match_operand:V8HI 0 "register_operand" "=v")
8880     (vec_concat:V8HI
8881       (any_truncate:<pmov_dst_4>
8882               (match_operand:PMOV_SRC_MODE_4 1 "register_operand" "v"))
8883       (match_operand:<pmov_dst_zeroed_4> 2 "const0_operand")))]
8884   "TARGET_AVX512VL"
8885   "vpmov<trunsuffix><pmov_suff_4>\t{%1, %0|%0, %1}"
8886   [(set_attr "type" "ssemov")
8887    (set_attr "prefix" "evex")
8888    (set_attr "mode" "TI")])
8889
8890 (define_insn "*avx512vl_<code><mode>v4hi2_store"
8891   [(set (match_operand:V8HI 0 "memory_operand" "=m")
8892     (vec_concat:V8HI
8893       (any_truncate:V4HI
8894               (match_operand:VI4_128_8_256 1 "register_operand" "v"))
8895       (vec_select:V4HI
8896         (match_dup 0)
8897         (parallel [(const_int 4) (const_int 5)
8898                    (const_int 6) (const_int 7)]))))]
8899   "TARGET_AVX512VL"
8900   "vpmov<trunsuffix><pmov_suff_4>\t{%1, %0|%0, %1}"
8901   [(set_attr "type" "ssemov")
8902    (set_attr "memory" "store")
8903    (set_attr "prefix" "evex")
8904    (set_attr "mode" "TI")])
8905
8906 (define_insn "avx512vl_<code><mode>v4hi2_mask"
8907   [(set (match_operand:V8HI 0 "register_operand" "=v")
8908     (vec_concat:V8HI
8909       (vec_merge:V4HI
8910         (any_truncate:V4HI
8911           (match_operand:VI4_128_8_256 1 "register_operand" "v"))
8912         (vec_select:V4HI
8913           (match_operand:V8HI 2 "vector_move_operand" "0C")
8914           (parallel [(const_int 0) (const_int 1)
8915                      (const_int 2) (const_int 3)]))
8916         (match_operand:QI 3 "register_operand" "Yk"))
8917       (const_vector:V4HI [(const_int 0) (const_int 0)
8918                           (const_int 0) (const_int 0)])))]
8919   "TARGET_AVX512VL"
8920   "vpmov<trunsuffix><pmov_suff_4>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
8921   [(set_attr "type" "ssemov")
8922    (set_attr "prefix" "evex")
8923    (set_attr "mode" "TI")])
8924
8925 (define_insn "avx512vl_<code><mode>v4hi2_mask_store"
8926   [(set (match_operand:V8HI 0 "memory_operand" "=m")
8927     (vec_concat:V8HI
8928       (vec_merge:V4HI
8929         (any_truncate:V4HI
8930           (match_operand:VI4_128_8_256 1 "register_operand" "v"))
8931         (vec_select:V4HI
8932           (match_dup 0)
8933           (parallel [(const_int 0) (const_int 1)
8934                      (const_int 2) (const_int 3)]))
8935         (match_operand:QI 2 "register_operand" "Yk"))
8936       (vec_select:V4HI
8937         (match_dup 0)
8938         (parallel [(const_int 4) (const_int 5)
8939                    (const_int 6) (const_int 7)]))))]
8940   "TARGET_AVX512VL"
8941   "vpmov<trunsuffix><pmov_suff_4>\t{%1, %0%{%2%}|%0%{%2%}, %1}"
8942   [(set_attr "type" "ssemov")
8943    (set_attr "memory" "store")
8944    (set_attr "prefix" "evex")
8945    (set_attr "mode" "TI")])
8946
8947 (define_insn "*avx512vl_<code>v2div2hi2_store"
8948   [(set (match_operand:V8HI 0 "memory_operand" "=m")
8949     (vec_concat:V8HI
8950       (any_truncate:V2HI
8951               (match_operand:V2DI 1 "register_operand" "v"))
8952       (vec_select:V6HI
8953         (match_dup 0)
8954         (parallel [(const_int 2) (const_int 3)
8955                    (const_int 4) (const_int 5)
8956                    (const_int 6) (const_int 7)]))))]
8957   "TARGET_AVX512VL"
8958   "vpmov<trunsuffix>qw\t{%1, %0|%0, %1}"
8959   [(set_attr "type" "ssemov")
8960    (set_attr "memory" "store")
8961    (set_attr "prefix" "evex")
8962    (set_attr "mode" "TI")])
8963
8964 (define_insn "avx512vl_<code>v2div2hi2_mask"
8965   [(set (match_operand:V8HI 0 "register_operand" "=v")
8966     (vec_concat:V8HI
8967       (vec_merge:V2HI
8968         (any_truncate:V2HI
8969           (match_operand:V2DI 1 "register_operand" "v"))
8970         (vec_select:V2HI
8971           (match_operand:V8HI 2 "vector_move_operand" "0C")
8972           (parallel [(const_int 0) (const_int 1)]))
8973         (match_operand:QI 3 "register_operand" "Yk"))
8974       (const_vector:V6HI [(const_int 0) (const_int 0)
8975                           (const_int 0) (const_int 0)
8976                           (const_int 0) (const_int 0)])))]
8977   "TARGET_AVX512VL"
8978   "vpmov<trunsuffix>qw\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
8979   [(set_attr "type" "ssemov")
8980    (set_attr "prefix" "evex")
8981    (set_attr "mode" "TI")])
8982
8983 (define_insn "avx512vl_<code>v2div2hi2_mask_store"
8984   [(set (match_operand:V8HI 0 "memory_operand" "=m")
8985     (vec_concat:V8HI
8986       (vec_merge:V2HI
8987         (any_truncate:V2HI
8988           (match_operand:V2DI 1 "register_operand" "v"))
8989         (vec_select:V2HI
8990           (match_dup 0)
8991           (parallel [(const_int 0) (const_int 1)]))
8992         (match_operand:QI 2 "register_operand" "Yk"))
8993       (vec_select:V6HI
8994         (match_dup 0)
8995         (parallel [(const_int 2) (const_int 3)
8996                    (const_int 4) (const_int 5)
8997                    (const_int 6) (const_int 7)]))))]
8998   "TARGET_AVX512VL"
8999   "vpmov<trunsuffix>qw\t{%1, %0%{%2%}|%0%{%2%}, %1}"
9000   [(set_attr "type" "ssemov")
9001    (set_attr "memory" "store")
9002    (set_attr "prefix" "evex")
9003    (set_attr "mode" "TI")])
9004
9005 (define_insn "*avx512vl_<code>v2div2si2"
9006   [(set (match_operand:V4SI 0 "register_operand" "=v")
9007     (vec_concat:V4SI
9008       (any_truncate:V2SI
9009               (match_operand:V2DI 1 "register_operand" "v"))
9010       (match_operand:V2SI 2 "const0_operand")))]
9011   "TARGET_AVX512VL"
9012   "vpmov<trunsuffix>qd\t{%1, %0|%0, %1}"
9013   [(set_attr "type" "ssemov")
9014    (set_attr "prefix" "evex")
9015    (set_attr "mode" "TI")])
9016
9017 (define_insn "*avx512vl_<code>v2div2si2_store"
9018   [(set (match_operand:V4SI 0 "memory_operand" "=m")
9019     (vec_concat:V4SI
9020       (any_truncate:V2SI
9021               (match_operand:V2DI 1 "register_operand" "v"))
9022       (vec_select:V2SI
9023         (match_dup 0)
9024         (parallel [(const_int 2) (const_int 3)]))))]
9025   "TARGET_AVX512VL"
9026   "vpmov<trunsuffix>qd\t{%1, %0|%0, %1}"
9027   [(set_attr "type" "ssemov")
9028    (set_attr "memory" "store")
9029    (set_attr "prefix" "evex")
9030    (set_attr "mode" "TI")])
9031
9032 (define_insn "avx512vl_<code>v2div2si2_mask"
9033   [(set (match_operand:V4SI 0 "register_operand" "=v")
9034     (vec_concat:V4SI
9035       (vec_merge:V2SI
9036         (any_truncate:V2SI
9037           (match_operand:V2DI 1 "register_operand" "v"))
9038         (vec_select:V2SI
9039           (match_operand:V4SI 2 "vector_move_operand" "0C")
9040           (parallel [(const_int 0) (const_int 1)]))
9041         (match_operand:QI 3 "register_operand" "Yk"))
9042       (const_vector:V2SI [(const_int 0) (const_int 0)])))]
9043   "TARGET_AVX512VL"
9044   "vpmov<trunsuffix>qd\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
9045   [(set_attr "type" "ssemov")
9046    (set_attr "prefix" "evex")
9047    (set_attr "mode" "TI")])
9048
9049 (define_insn "avx512vl_<code>v2div2si2_mask_store"
9050   [(set (match_operand:V4SI 0 "memory_operand" "=m")
9051     (vec_concat:V4SI
9052       (vec_merge:V2SI
9053         (any_truncate:V2SI
9054           (match_operand:V2DI 1 "register_operand" "v"))
9055         (vec_select:V2SI
9056           (match_dup 0)
9057           (parallel [(const_int 0) (const_int 1)]))
9058         (match_operand:QI 2 "register_operand" "Yk"))
9059       (vec_select:V2SI
9060         (match_dup 0)
9061         (parallel [(const_int 2) (const_int 3)]))))]
9062   "TARGET_AVX512VL"
9063   "vpmov<trunsuffix>qd\t{%1, %0%{%2%}|%0%{%2%}, %1}"
9064   [(set_attr "type" "ssemov")
9065    (set_attr "memory" "store")
9066    (set_attr "prefix" "evex")
9067    (set_attr "mode" "TI")])
9068
9069 (define_insn "*avx512f_<code>v8div16qi2"
9070   [(set (match_operand:V16QI 0 "register_operand" "=v")
9071         (vec_concat:V16QI
9072           (any_truncate:V8QI
9073             (match_operand:V8DI 1 "register_operand" "v"))
9074           (const_vector:V8QI [(const_int 0) (const_int 0)
9075                               (const_int 0) (const_int 0)
9076                               (const_int 0) (const_int 0)
9077                               (const_int 0) (const_int 0)])))]
9078   "TARGET_AVX512F"
9079   "vpmov<trunsuffix>qb\t{%1, %0|%0, %1}"
9080   [(set_attr "type" "ssemov")
9081    (set_attr "prefix" "evex")
9082    (set_attr "mode" "TI")])
9083
9084 (define_insn "*avx512f_<code>v8div16qi2_store"
9085   [(set (match_operand:V16QI 0 "memory_operand" "=m")
9086         (vec_concat:V16QI
9087           (any_truncate:V8QI
9088             (match_operand:V8DI 1 "register_operand" "v"))
9089           (vec_select:V8QI
9090             (match_dup 0)
9091             (parallel [(const_int 8) (const_int 9)
9092                        (const_int 10) (const_int 11)
9093                        (const_int 12) (const_int 13)
9094                        (const_int 14) (const_int 15)]))))]
9095   "TARGET_AVX512F"
9096   "vpmov<trunsuffix>qb\t{%1, %0|%0, %1}"
9097   [(set_attr "type" "ssemov")
9098    (set_attr "memory" "store")
9099    (set_attr "prefix" "evex")
9100    (set_attr "mode" "TI")])
9101
9102 (define_insn "avx512f_<code>v8div16qi2_mask"
9103   [(set (match_operand:V16QI 0 "register_operand" "=v")
9104     (vec_concat:V16QI
9105       (vec_merge:V8QI
9106         (any_truncate:V8QI
9107           (match_operand:V8DI 1 "register_operand" "v"))
9108         (vec_select:V8QI
9109           (match_operand:V16QI 2 "vector_move_operand" "0C")
9110           (parallel [(const_int 0) (const_int 1)
9111                      (const_int 2) (const_int 3)
9112                      (const_int 4) (const_int 5)
9113                      (const_int 6) (const_int 7)]))
9114         (match_operand:QI 3 "register_operand" "Yk"))
9115       (const_vector:V8QI [(const_int 0) (const_int 0)
9116                           (const_int 0) (const_int 0)
9117                           (const_int 0) (const_int 0)
9118                           (const_int 0) (const_int 0)])))]
9119   "TARGET_AVX512F"
9120   "vpmov<trunsuffix>qb\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
9121   [(set_attr "type" "ssemov")
9122    (set_attr "prefix" "evex")
9123    (set_attr "mode" "TI")])
9124
9125 (define_insn "avx512f_<code>v8div16qi2_mask_store"
9126   [(set (match_operand:V16QI 0 "memory_operand" "=m")
9127     (vec_concat:V16QI
9128       (vec_merge:V8QI
9129         (any_truncate:V8QI
9130           (match_operand:V8DI 1 "register_operand" "v"))
9131         (vec_select:V8QI
9132           (match_dup 0)
9133           (parallel [(const_int 0) (const_int 1)
9134                      (const_int 2) (const_int 3)
9135                      (const_int 4) (const_int 5)
9136                      (const_int 6) (const_int 7)]))
9137         (match_operand:QI 2 "register_operand" "Yk"))
9138       (vec_select:V8QI
9139         (match_dup 0)
9140         (parallel [(const_int 8) (const_int 9)
9141                    (const_int 10) (const_int 11)
9142                    (const_int 12) (const_int 13)
9143                    (const_int 14) (const_int 15)]))))]
9144   "TARGET_AVX512F"
9145   "vpmov<trunsuffix>qb\t{%1, %0%{%2%}|%0%{%2%}, %1}"
9146   [(set_attr "type" "ssemov")
9147    (set_attr "memory" "store")
9148    (set_attr "prefix" "evex")
9149    (set_attr "mode" "TI")])
9150
9151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9152 ;;
9153 ;; Parallel integral arithmetic
9154 ;;
9155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9156
9157 (define_expand "neg<mode>2"
9158   [(set (match_operand:VI_AVX2 0 "register_operand")
9159         (minus:VI_AVX2
9160           (match_dup 2)
9161           (match_operand:VI_AVX2 1 "nonimmediate_operand")))]
9162   "TARGET_SSE2"
9163   "operands[2] = force_reg (<MODE>mode, CONST0_RTX (<MODE>mode));")
9164
9165 (define_expand "<plusminus_insn><mode>3"
9166   [(set (match_operand:VI_AVX2 0 "register_operand")
9167         (plusminus:VI_AVX2
9168           (match_operand:VI_AVX2 1 "nonimmediate_operand")
9169           (match_operand:VI_AVX2 2 "nonimmediate_operand")))]
9170   "TARGET_SSE2"
9171   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
9172
9173 (define_expand "<plusminus_insn><mode>3_mask"
9174   [(set (match_operand:VI48_AVX512VL 0 "register_operand")
9175         (vec_merge:VI48_AVX512VL
9176           (plusminus:VI48_AVX512VL
9177             (match_operand:VI48_AVX512VL 1 "nonimmediate_operand")
9178             (match_operand:VI48_AVX512VL 2 "nonimmediate_operand"))
9179           (match_operand:VI48_AVX512VL 3 "vector_move_operand")
9180           (match_operand:<avx512fmaskmode> 4 "register_operand")))]
9181   "TARGET_AVX512F"
9182   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
9183
9184 (define_expand "<plusminus_insn><mode>3_mask"
9185   [(set (match_operand:VI12_AVX512VL 0 "register_operand")
9186         (vec_merge:VI12_AVX512VL
9187           (plusminus:VI12_AVX512VL
9188             (match_operand:VI12_AVX512VL 1 "nonimmediate_operand")
9189             (match_operand:VI12_AVX512VL 2 "nonimmediate_operand"))
9190           (match_operand:VI12_AVX512VL 3 "vector_move_operand")
9191           (match_operand:<avx512fmaskmode> 4 "register_operand")))]
9192   "TARGET_AVX512BW"
9193   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
9194
9195 (define_insn "*<plusminus_insn><mode>3"
9196   [(set (match_operand:VI_AVX2 0 "register_operand" "=x,v")
9197         (plusminus:VI_AVX2
9198           (match_operand:VI_AVX2 1 "nonimmediate_operand" "<comm>0,v")
9199           (match_operand:VI_AVX2 2 "nonimmediate_operand" "xm,vm")))]
9200   "TARGET_SSE2
9201    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
9202   "@
9203    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
9204    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9205   [(set_attr "isa" "noavx,avx")
9206    (set_attr "type" "sseiadd")
9207    (set_attr "prefix_data16" "1,*")
9208    (set_attr "prefix" "<mask_prefix3>")
9209    (set_attr "mode" "<sseinsnmode>")])
9210
9211 (define_insn "*<plusminus_insn><mode>3_mask"
9212   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
9213         (vec_merge:VI48_AVX512VL
9214           (plusminus:VI48_AVX512VL
9215             (match_operand:VI48_AVX512VL 1 "nonimmediate_operand" "<comm>v")
9216             (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm"))
9217           (match_operand:VI48_AVX512VL 3 "vector_move_operand" "0C")
9218           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
9219   "TARGET_AVX512F
9220    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
9221   "vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0%{%4%}%N3|%0%{%4%}%N3, %1, %2}"
9222   [(set_attr "type" "sseiadd")
9223    (set_attr "prefix" "evex")
9224    (set_attr "mode" "<sseinsnmode>")])
9225
9226 (define_insn "*<plusminus_insn><mode>3_mask"
9227   [(set (match_operand:VI12_AVX512VL 0 "register_operand" "=v")
9228         (vec_merge:VI12_AVX512VL
9229           (plusminus:VI12_AVX512VL
9230             (match_operand:VI12_AVX512VL 1 "nonimmediate_operand" "<comm>v")
9231             (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm"))
9232           (match_operand:VI12_AVX512VL 3 "vector_move_operand" "0C")
9233           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
9234   "TARGET_AVX512BW && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
9235   "vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0%{%4%}%N3|%0%{%4%}%N3, %1, %2}"
9236   [(set_attr "type" "sseiadd")
9237    (set_attr "prefix" "evex")
9238    (set_attr "mode" "<sseinsnmode>")])
9239
9240 (define_expand "<sse2_avx2>_<plusminus_insn><mode>3<mask_name>"
9241   [(set (match_operand:VI12_AVX2 0 "register_operand")
9242         (sat_plusminus:VI12_AVX2
9243           (match_operand:VI12_AVX2 1 "nonimmediate_operand")
9244           (match_operand:VI12_AVX2 2 "nonimmediate_operand")))]
9245   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
9246   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
9247
9248 (define_insn "*<sse2_avx2>_<plusminus_insn><mode>3<mask_name>"
9249   [(set (match_operand:VI12_AVX2 0 "register_operand" "=x,v")
9250         (sat_plusminus:VI12_AVX2
9251           (match_operand:VI12_AVX2 1 "nonimmediate_operand" "<comm>0,v")
9252           (match_operand:VI12_AVX2 2 "nonimmediate_operand" "xm,vm")))]
9253   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>
9254    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
9255   "@
9256    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
9257    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9258   [(set_attr "isa" "noavx,avx")
9259    (set_attr "type" "sseiadd")
9260    (set_attr "prefix_data16" "1,*")
9261    (set_attr "prefix" "orig,maybe_evex")
9262    (set_attr "mode" "TI")])
9263
9264 (define_expand "mul<mode>3<mask_name>"
9265   [(set (match_operand:VI1_AVX512 0 "register_operand")
9266         (mult:VI1_AVX512 (match_operand:VI1_AVX512 1 "register_operand")
9267                        (match_operand:VI1_AVX512 2 "register_operand")))]
9268   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
9269 {
9270   ix86_expand_vecop_qihi (MULT, operands[0], operands[1], operands[2]);
9271   DONE;
9272 })
9273
9274 (define_expand "mul<mode>3<mask_name>"
9275   [(set (match_operand:VI2_AVX2 0 "register_operand")
9276         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand")
9277                        (match_operand:VI2_AVX2 2 "nonimmediate_operand")))]
9278   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
9279   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
9280
9281 (define_insn "*mul<mode>3<mask_name>"
9282   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,v")
9283         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,v")
9284                        (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,vm")))]
9285   "TARGET_SSE2
9286    && ix86_binary_operator_ok (MULT, <MODE>mode, operands)
9287    && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
9288   "@
9289    pmullw\t{%2, %0|%0, %2}
9290    vpmullw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9291   [(set_attr "isa" "noavx,avx")
9292    (set_attr "type" "sseimul")
9293    (set_attr "prefix_data16" "1,*")
9294    (set_attr "prefix" "orig,vex")
9295    (set_attr "mode" "<sseinsnmode>")])
9296
9297 (define_expand "<s>mul<mode>3_highpart<mask_name>"
9298   [(set (match_operand:VI2_AVX2 0 "register_operand")
9299         (truncate:VI2_AVX2
9300           (lshiftrt:<ssedoublemode>
9301             (mult:<ssedoublemode>
9302               (any_extend:<ssedoublemode>
9303                 (match_operand:VI2_AVX2 1 "nonimmediate_operand"))
9304               (any_extend:<ssedoublemode>
9305                 (match_operand:VI2_AVX2 2 "nonimmediate_operand")))
9306             (const_int 16))))]
9307   "TARGET_SSE2
9308    && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
9309   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
9310
9311 (define_insn "*<s>mul<mode>3_highpart<mask_name>"
9312   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,v")
9313         (truncate:VI2_AVX2
9314           (lshiftrt:<ssedoublemode>
9315             (mult:<ssedoublemode>
9316               (any_extend:<ssedoublemode>
9317                 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,v"))
9318               (any_extend:<ssedoublemode>
9319                 (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,vm")))
9320             (const_int 16))))]
9321   "TARGET_SSE2
9322    && ix86_binary_operator_ok (MULT, <MODE>mode, operands)
9323    && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
9324   "@
9325    pmulh<u>w\t{%2, %0|%0, %2}
9326    vpmulh<u>w\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9327   [(set_attr "isa" "noavx,avx")
9328    (set_attr "type" "sseimul")
9329    (set_attr "prefix_data16" "1,*")
9330    (set_attr "prefix" "orig,vex")
9331    (set_attr "mode" "<sseinsnmode>")])
9332
9333 (define_expand "vec_widen_umult_even_v16si<mask_name>"
9334   [(set (match_operand:V8DI 0 "register_operand")
9335         (mult:V8DI
9336           (zero_extend:V8DI
9337             (vec_select:V8SI
9338               (match_operand:V16SI 1 "nonimmediate_operand")
9339               (parallel [(const_int 0) (const_int 2)
9340                          (const_int 4) (const_int 6)
9341                          (const_int 8) (const_int 10)
9342                          (const_int 12) (const_int 14)])))
9343           (zero_extend:V8DI
9344             (vec_select:V8SI
9345               (match_operand:V16SI 2 "nonimmediate_operand")
9346               (parallel [(const_int 0) (const_int 2)
9347                          (const_int 4) (const_int 6)
9348                          (const_int 8) (const_int 10)
9349                          (const_int 12) (const_int 14)])))))]
9350   "TARGET_AVX512F"
9351   "ix86_fixup_binary_operands_no_copy (MULT, V16SImode, operands);")
9352
9353 (define_insn "*vec_widen_umult_even_v16si<mask_name>"
9354   [(set (match_operand:V8DI 0 "register_operand" "=v")
9355         (mult:V8DI
9356           (zero_extend:V8DI
9357             (vec_select:V8SI
9358               (match_operand:V16SI 1 "nonimmediate_operand" "%v")
9359               (parallel [(const_int 0) (const_int 2)
9360                          (const_int 4) (const_int 6)
9361                          (const_int 8) (const_int 10)
9362                          (const_int 12) (const_int 14)])))
9363           (zero_extend:V8DI
9364             (vec_select:V8SI
9365               (match_operand:V16SI 2 "nonimmediate_operand" "vm")
9366               (parallel [(const_int 0) (const_int 2)
9367                          (const_int 4) (const_int 6)
9368                          (const_int 8) (const_int 10)
9369                          (const_int 12) (const_int 14)])))))]
9370   "TARGET_AVX512F && ix86_binary_operator_ok (MULT, V16SImode, operands)"
9371   "vpmuludq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9372   [(set_attr "isa" "avx512f")
9373    (set_attr "type" "sseimul")
9374    (set_attr "prefix_extra" "1")
9375    (set_attr "prefix" "evex")
9376    (set_attr "mode" "XI")])
9377
9378 (define_expand "vec_widen_umult_even_v8si<mask_name>"
9379   [(set (match_operand:V4DI 0 "register_operand")
9380         (mult:V4DI
9381           (zero_extend:V4DI
9382             (vec_select:V4SI
9383               (match_operand:V8SI 1 "nonimmediate_operand")
9384               (parallel [(const_int 0) (const_int 2)
9385                          (const_int 4) (const_int 6)])))
9386           (zero_extend:V4DI
9387             (vec_select:V4SI
9388               (match_operand:V8SI 2 "nonimmediate_operand")
9389               (parallel [(const_int 0) (const_int 2)
9390                          (const_int 4) (const_int 6)])))))]
9391   "TARGET_AVX2 && <mask_avx512vl_condition>"
9392   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
9393
9394 (define_insn "*vec_widen_umult_even_v8si<mask_name>"
9395   [(set (match_operand:V4DI 0 "register_operand" "=v")
9396         (mult:V4DI
9397           (zero_extend:V4DI
9398             (vec_select:V4SI
9399               (match_operand:V8SI 1 "nonimmediate_operand" "%v")
9400               (parallel [(const_int 0) (const_int 2)
9401                          (const_int 4) (const_int 6)])))
9402           (zero_extend:V4DI
9403             (vec_select:V4SI
9404               (match_operand:V8SI 2 "nonimmediate_operand" "vm")
9405               (parallel [(const_int 0) (const_int 2)
9406                          (const_int 4) (const_int 6)])))))]
9407   "TARGET_AVX2 && <mask_avx512vl_condition>
9408    && ix86_binary_operator_ok (MULT, V8SImode, operands)"
9409   "vpmuludq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9410   [(set_attr "type" "sseimul")
9411    (set_attr "prefix" "maybe_evex")
9412    (set_attr "mode" "OI")])
9413
9414 (define_expand "vec_widen_umult_even_v4si<mask_name>"
9415   [(set (match_operand:V2DI 0 "register_operand")
9416         (mult:V2DI
9417           (zero_extend:V2DI
9418             (vec_select:V2SI
9419               (match_operand:V4SI 1 "nonimmediate_operand")
9420               (parallel [(const_int 0) (const_int 2)])))
9421           (zero_extend:V2DI
9422             (vec_select:V2SI
9423               (match_operand:V4SI 2 "nonimmediate_operand")
9424               (parallel [(const_int 0) (const_int 2)])))))]
9425   "TARGET_SSE2 && <mask_avx512vl_condition>"
9426   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
9427
9428 (define_insn "*vec_widen_umult_even_v4si<mask_name>"
9429   [(set (match_operand:V2DI 0 "register_operand" "=x,v")
9430         (mult:V2DI
9431           (zero_extend:V2DI
9432             (vec_select:V2SI
9433               (match_operand:V4SI 1 "nonimmediate_operand" "%0,v")
9434               (parallel [(const_int 0) (const_int 2)])))
9435           (zero_extend:V2DI
9436             (vec_select:V2SI
9437               (match_operand:V4SI 2 "nonimmediate_operand" "xm,vm")
9438               (parallel [(const_int 0) (const_int 2)])))))]
9439   "TARGET_SSE2 && <mask_avx512vl_condition>
9440    && ix86_binary_operator_ok (MULT, V4SImode, operands)"
9441   "@
9442    pmuludq\t{%2, %0|%0, %2}
9443    vpmuludq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9444   [(set_attr "isa" "noavx,avx")
9445    (set_attr "type" "sseimul")
9446    (set_attr "prefix_data16" "1,*")
9447    (set_attr "prefix" "orig,maybe_evex")
9448    (set_attr "mode" "TI")])
9449
9450 (define_expand "vec_widen_smult_even_v16si<mask_name>"
9451   [(set (match_operand:V8DI 0 "register_operand")
9452         (mult:V8DI
9453           (sign_extend:V8DI
9454             (vec_select:V8SI
9455               (match_operand:V16SI 1 "nonimmediate_operand")
9456               (parallel [(const_int 0) (const_int 2)
9457                          (const_int 4) (const_int 6)
9458                          (const_int 8) (const_int 10)
9459                          (const_int 12) (const_int 14)])))
9460           (sign_extend:V8DI
9461             (vec_select:V8SI
9462               (match_operand:V16SI 2 "nonimmediate_operand")
9463               (parallel [(const_int 0) (const_int 2)
9464                          (const_int 4) (const_int 6)
9465                          (const_int 8) (const_int 10)
9466                          (const_int 12) (const_int 14)])))))]
9467   "TARGET_AVX512F"
9468   "ix86_fixup_binary_operands_no_copy (MULT, V16SImode, operands);")
9469
9470 (define_insn "*vec_widen_smult_even_v16si<mask_name>"
9471   [(set (match_operand:V8DI 0 "register_operand" "=v")
9472         (mult:V8DI
9473           (sign_extend:V8DI
9474             (vec_select:V8SI
9475               (match_operand:V16SI 1 "nonimmediate_operand" "%v")
9476               (parallel [(const_int 0) (const_int 2)
9477                          (const_int 4) (const_int 6)
9478                          (const_int 8) (const_int 10)
9479                          (const_int 12) (const_int 14)])))
9480           (sign_extend:V8DI
9481             (vec_select:V8SI
9482               (match_operand:V16SI 2 "nonimmediate_operand" "vm")
9483               (parallel [(const_int 0) (const_int 2)
9484                          (const_int 4) (const_int 6)
9485                          (const_int 8) (const_int 10)
9486                          (const_int 12) (const_int 14)])))))]
9487   "TARGET_AVX512F && ix86_binary_operator_ok (MULT, V16SImode, operands)"
9488   "vpmuldq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9489   [(set_attr "isa" "avx512f")
9490    (set_attr "type" "sseimul")
9491    (set_attr "prefix_extra" "1")
9492    (set_attr "prefix" "evex")
9493    (set_attr "mode" "XI")])
9494
9495 (define_expand "vec_widen_smult_even_v8si<mask_name>"
9496   [(set (match_operand:V4DI 0 "register_operand")
9497         (mult:V4DI
9498           (sign_extend:V4DI
9499             (vec_select:V4SI
9500               (match_operand:V8SI 1 "nonimmediate_operand")
9501               (parallel [(const_int 0) (const_int 2)
9502                          (const_int 4) (const_int 6)])))
9503           (sign_extend:V4DI
9504             (vec_select:V4SI
9505               (match_operand:V8SI 2 "nonimmediate_operand")
9506               (parallel [(const_int 0) (const_int 2)
9507                          (const_int 4) (const_int 6)])))))]
9508   "TARGET_AVX2 && <mask_avx512vl_condition>"
9509   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
9510
9511 (define_insn "*vec_widen_smult_even_v8si<mask_name>"
9512   [(set (match_operand:V4DI 0 "register_operand" "=v")
9513         (mult:V4DI
9514           (sign_extend:V4DI
9515             (vec_select:V4SI
9516               (match_operand:V8SI 1 "nonimmediate_operand" "v")
9517               (parallel [(const_int 0) (const_int 2)
9518                          (const_int 4) (const_int 6)])))
9519           (sign_extend:V4DI
9520             (vec_select:V4SI
9521               (match_operand:V8SI 2 "nonimmediate_operand" "vm")
9522               (parallel [(const_int 0) (const_int 2)
9523                          (const_int 4) (const_int 6)])))))]
9524   "TARGET_AVX2
9525    && ix86_binary_operator_ok (MULT, V8SImode, operands)"
9526   "vpmuldq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9527   [(set_attr "type" "sseimul")
9528    (set_attr "prefix_extra" "1")
9529    (set_attr "prefix" "vex")
9530    (set_attr "mode" "OI")])
9531
9532 (define_expand "sse4_1_mulv2siv2di3<mask_name>"
9533   [(set (match_operand:V2DI 0 "register_operand")
9534         (mult:V2DI
9535           (sign_extend:V2DI
9536             (vec_select:V2SI
9537               (match_operand:V4SI 1 "nonimmediate_operand")
9538               (parallel [(const_int 0) (const_int 2)])))
9539           (sign_extend:V2DI
9540             (vec_select:V2SI
9541               (match_operand:V4SI 2 "nonimmediate_operand")
9542               (parallel [(const_int 0) (const_int 2)])))))]
9543   "TARGET_SSE4_1 && <mask_avx512vl_condition>"
9544   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
9545
9546 (define_insn "*sse4_1_mulv2siv2di3<mask_name>"
9547   [(set (match_operand:V2DI 0 "register_operand" "=Yr,*x,v")
9548         (mult:V2DI
9549           (sign_extend:V2DI
9550             (vec_select:V2SI
9551               (match_operand:V4SI 1 "nonimmediate_operand" "%0,0,v")
9552               (parallel [(const_int 0) (const_int 2)])))
9553           (sign_extend:V2DI
9554             (vec_select:V2SI
9555               (match_operand:V4SI 2 "nonimmediate_operand" "Yrm,*xm,vm")
9556               (parallel [(const_int 0) (const_int 2)])))))]
9557   "TARGET_SSE4_1 && <mask_avx512vl_condition>
9558    && ix86_binary_operator_ok (MULT, V4SImode, operands)"
9559   "@
9560    pmuldq\t{%2, %0|%0, %2}
9561    pmuldq\t{%2, %0|%0, %2}
9562    vpmuldq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9563   [(set_attr "isa" "noavx,noavx,avx")
9564    (set_attr "type" "sseimul")
9565    (set_attr "prefix_data16" "1,1,*")
9566    (set_attr "prefix_extra" "1")
9567    (set_attr "prefix" "orig,orig,vex")
9568    (set_attr "mode" "TI")])
9569
9570 (define_insn "avx512bw_pmaddwd512<mode><mask_name>"
9571   [(set (match_operand:<sseunpackmode> 0 "register_operand" "=v")
9572           (unspec:<sseunpackmode>
9573             [(match_operand:VI2_AVX2 1 "register_operand" "v")
9574              (match_operand:VI2_AVX2 2 "nonimmediate_operand" "vm")]
9575              UNSPEC_PMADDWD512))]
9576    "TARGET_AVX512BW && <mask_mode512bit_condition>"
9577    "vpmaddwd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}";
9578   [(set_attr "type" "sseiadd")
9579    (set_attr "prefix" "evex")
9580    (set_attr "mode" "XI")])
9581
9582 (define_expand "avx2_pmaddwd"
9583   [(set (match_operand:V8SI 0 "register_operand")
9584         (plus:V8SI
9585           (mult:V8SI
9586             (sign_extend:V8SI
9587               (vec_select:V8HI
9588                 (match_operand:V16HI 1 "nonimmediate_operand")
9589                 (parallel [(const_int 0) (const_int 2)
9590                            (const_int 4) (const_int 6)
9591                            (const_int 8) (const_int 10)
9592                            (const_int 12) (const_int 14)])))
9593             (sign_extend:V8SI
9594               (vec_select:V8HI
9595                 (match_operand:V16HI 2 "nonimmediate_operand")
9596                 (parallel [(const_int 0) (const_int 2)
9597                            (const_int 4) (const_int 6)
9598                            (const_int 8) (const_int 10)
9599                            (const_int 12) (const_int 14)]))))
9600           (mult:V8SI
9601             (sign_extend:V8SI
9602               (vec_select:V8HI (match_dup 1)
9603                 (parallel [(const_int 1) (const_int 3)
9604                            (const_int 5) (const_int 7)
9605                            (const_int 9) (const_int 11)
9606                            (const_int 13) (const_int 15)])))
9607             (sign_extend:V8SI
9608               (vec_select:V8HI (match_dup 2)
9609                 (parallel [(const_int 1) (const_int 3)
9610                            (const_int 5) (const_int 7)
9611                            (const_int 9) (const_int 11)
9612                            (const_int 13) (const_int 15)]))))))]
9613   "TARGET_AVX2"
9614   "ix86_fixup_binary_operands_no_copy (MULT, V16HImode, operands);")
9615
9616 (define_insn "*avx2_pmaddwd"
9617   [(set (match_operand:V8SI 0 "register_operand" "=x")
9618         (plus:V8SI
9619           (mult:V8SI
9620             (sign_extend:V8SI
9621               (vec_select:V8HI
9622                 (match_operand:V16HI 1 "nonimmediate_operand" "%x")
9623                 (parallel [(const_int 0) (const_int 2)
9624                            (const_int 4) (const_int 6)
9625                            (const_int 8) (const_int 10)
9626                            (const_int 12) (const_int 14)])))
9627             (sign_extend:V8SI
9628               (vec_select:V8HI
9629                 (match_operand:V16HI 2 "nonimmediate_operand" "xm")
9630                 (parallel [(const_int 0) (const_int 2)
9631                            (const_int 4) (const_int 6)
9632                            (const_int 8) (const_int 10)
9633                            (const_int 12) (const_int 14)]))))
9634           (mult:V8SI
9635             (sign_extend:V8SI
9636               (vec_select:V8HI (match_dup 1)
9637                 (parallel [(const_int 1) (const_int 3)
9638                            (const_int 5) (const_int 7)
9639                            (const_int 9) (const_int 11)
9640                            (const_int 13) (const_int 15)])))
9641             (sign_extend:V8SI
9642               (vec_select:V8HI (match_dup 2)
9643                 (parallel [(const_int 1) (const_int 3)
9644                            (const_int 5) (const_int 7)
9645                            (const_int 9) (const_int 11)
9646                            (const_int 13) (const_int 15)]))))))]
9647   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V16HImode, operands)"
9648   "vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
9649   [(set_attr "type" "sseiadd")
9650    (set_attr "prefix" "vex")
9651    (set_attr "mode" "OI")])
9652
9653 (define_expand "sse2_pmaddwd"
9654   [(set (match_operand:V4SI 0 "register_operand")
9655         (plus:V4SI
9656           (mult:V4SI
9657             (sign_extend:V4SI
9658               (vec_select:V4HI
9659                 (match_operand:V8HI 1 "nonimmediate_operand")
9660                 (parallel [(const_int 0) (const_int 2)
9661                            (const_int 4) (const_int 6)])))
9662             (sign_extend:V4SI
9663               (vec_select:V4HI
9664                 (match_operand:V8HI 2 "nonimmediate_operand")
9665                 (parallel [(const_int 0) (const_int 2)
9666                            (const_int 4) (const_int 6)]))))
9667           (mult:V4SI
9668             (sign_extend:V4SI
9669               (vec_select:V4HI (match_dup 1)
9670                 (parallel [(const_int 1) (const_int 3)
9671                            (const_int 5) (const_int 7)])))
9672             (sign_extend:V4SI
9673               (vec_select:V4HI (match_dup 2)
9674                 (parallel [(const_int 1) (const_int 3)
9675                            (const_int 5) (const_int 7)]))))))]
9676   "TARGET_SSE2"
9677   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
9678
9679 (define_insn "*sse2_pmaddwd"
9680   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
9681         (plus:V4SI
9682           (mult:V4SI
9683             (sign_extend:V4SI
9684               (vec_select:V4HI
9685                 (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
9686                 (parallel [(const_int 0) (const_int 2)
9687                            (const_int 4) (const_int 6)])))
9688             (sign_extend:V4SI
9689               (vec_select:V4HI
9690                 (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
9691                 (parallel [(const_int 0) (const_int 2)
9692                            (const_int 4) (const_int 6)]))))
9693           (mult:V4SI
9694             (sign_extend:V4SI
9695               (vec_select:V4HI (match_dup 1)
9696                 (parallel [(const_int 1) (const_int 3)
9697                            (const_int 5) (const_int 7)])))
9698             (sign_extend:V4SI
9699               (vec_select:V4HI (match_dup 2)
9700                 (parallel [(const_int 1) (const_int 3)
9701                            (const_int 5) (const_int 7)]))))))]
9702   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
9703   "@
9704    pmaddwd\t{%2, %0|%0, %2}
9705    vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
9706   [(set_attr "isa" "noavx,avx")
9707    (set_attr "type" "sseiadd")
9708    (set_attr "atom_unit" "simul")
9709    (set_attr "prefix_data16" "1,*")
9710    (set_attr "prefix" "orig,vex")
9711    (set_attr "mode" "TI")])
9712
9713 (define_insn "avx512dq_mul<mode>3<mask_name>"
9714   [(set (match_operand:VI8 0 "register_operand" "=v")
9715         (mult:VI8
9716           (match_operand:VI8 1 "register_operand" "v")
9717           (match_operand:VI8 2 "nonimmediate_operand" "vm")))]
9718   "TARGET_AVX512DQ && <mask_mode512bit_condition>"
9719   "vpmullq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9720   [(set_attr "type" "sseimul")
9721    (set_attr "prefix" "evex")
9722    (set_attr "mode" "<sseinsnmode>")])
9723
9724 (define_expand "mul<mode>3<mask_name>"
9725   [(set (match_operand:VI4_AVX512F 0 "register_operand")
9726         (mult:VI4_AVX512F
9727           (match_operand:VI4_AVX512F 1 "general_vector_operand")
9728           (match_operand:VI4_AVX512F 2 "general_vector_operand")))]
9729   "TARGET_SSE2 && <mask_mode512bit_condition>"
9730 {
9731   if (TARGET_SSE4_1)
9732     {
9733       if (!nonimmediate_operand (operands[1], <MODE>mode))
9734         operands[1] = force_reg (<MODE>mode, operands[1]);
9735       if (!nonimmediate_operand (operands[2], <MODE>mode))
9736         operands[2] = force_reg (<MODE>mode, operands[2]);
9737       ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);
9738     }
9739   else
9740     {
9741       ix86_expand_sse2_mulv4si3 (operands[0], operands[1], operands[2]);
9742       DONE;
9743     }
9744 })
9745
9746 (define_insn "*<sse4_1_avx2>_mul<mode>3<mask_name>"
9747   [(set (match_operand:VI4_AVX512F 0 "register_operand" "=Yr,*x,v")
9748         (mult:VI4_AVX512F
9749           (match_operand:VI4_AVX512F 1 "nonimmediate_operand" "%0,0,v")
9750           (match_operand:VI4_AVX512F 2 "nonimmediate_operand" "Yrm,*xm,vm")))]
9751   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, <MODE>mode, operands) && <mask_mode512bit_condition>"
9752   "@
9753    pmulld\t{%2, %0|%0, %2}
9754    pmulld\t{%2, %0|%0, %2}
9755    vpmulld\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9756   [(set_attr "isa" "noavx,noavx,avx")
9757    (set_attr "type" "sseimul")
9758    (set_attr "prefix_extra" "1")
9759    (set_attr "prefix" "<mask_prefix4>")
9760    (set_attr "btver2_decode" "vector,vector,vector")
9761    (set_attr "mode" "<sseinsnmode>")])
9762
9763 (define_expand "mul<mode>3"
9764   [(set (match_operand:VI8_AVX2_AVX512F 0 "register_operand")
9765         (mult:VI8_AVX2_AVX512F
9766           (match_operand:VI8_AVX2_AVX512F 1 "register_operand")
9767           (match_operand:VI8_AVX2_AVX512F 2 "register_operand")))]
9768   "TARGET_SSE2"
9769 {
9770   ix86_expand_sse2_mulvxdi3 (operands[0], operands[1], operands[2]);
9771   DONE;
9772 })
9773
9774 (define_expand "vec_widen_<s>mult_hi_<mode>"
9775   [(match_operand:<sseunpackmode> 0 "register_operand")
9776    (any_extend:<sseunpackmode>
9777      (match_operand:VI124_AVX2 1 "register_operand"))
9778    (match_operand:VI124_AVX2 2 "register_operand")]
9779   "TARGET_SSE2"
9780 {
9781   ix86_expand_mul_widen_hilo (operands[0], operands[1], operands[2],
9782                               <u_bool>, true);
9783   DONE;
9784 })
9785
9786 (define_expand "vec_widen_<s>mult_lo_<mode>"
9787   [(match_operand:<sseunpackmode> 0 "register_operand")
9788    (any_extend:<sseunpackmode>
9789      (match_operand:VI124_AVX2 1 "register_operand"))
9790    (match_operand:VI124_AVX2 2 "register_operand")]
9791   "TARGET_SSE2"
9792 {
9793   ix86_expand_mul_widen_hilo (operands[0], operands[1], operands[2],
9794                               <u_bool>, false);
9795   DONE;
9796 })
9797
9798 ;; Most widen_<s>mult_even_<mode> can be handled directly from other
9799 ;; named patterns, but signed V4SI needs special help for plain SSE2.
9800 (define_expand "vec_widen_smult_even_v4si"
9801   [(match_operand:V2DI 0 "register_operand")
9802    (match_operand:V4SI 1 "nonimmediate_operand")
9803    (match_operand:V4SI 2 "nonimmediate_operand")]
9804   "TARGET_SSE2"
9805 {
9806   ix86_expand_mul_widen_evenodd (operands[0], operands[1], operands[2],
9807                                  false, false);
9808   DONE;
9809 })
9810
9811 (define_expand "vec_widen_<s>mult_odd_<mode>"
9812   [(match_operand:<sseunpackmode> 0 "register_operand")
9813    (any_extend:<sseunpackmode>
9814      (match_operand:VI4_AVX512F 1 "general_vector_operand"))
9815    (match_operand:VI4_AVX512F 2 "general_vector_operand")]
9816   "TARGET_SSE2"
9817 {
9818   ix86_expand_mul_widen_evenodd (operands[0], operands[1], operands[2],
9819                                  <u_bool>, true);
9820   DONE;
9821 })
9822
9823 (define_mode_attr SDOT_PMADD_SUF
9824   [(V32HI "512v32hi") (V16HI "") (V8HI "")])
9825
9826 (define_expand "sdot_prod<mode>"
9827   [(match_operand:<sseunpackmode> 0 "register_operand")
9828    (match_operand:VI2_AVX2 1 "register_operand")
9829    (match_operand:VI2_AVX2 2 "register_operand")
9830    (match_operand:<sseunpackmode> 3 "register_operand")]
9831   "TARGET_SSE2"
9832 {
9833   rtx t = gen_reg_rtx (<sseunpackmode>mode);
9834   emit_insn (gen_<sse2_avx2>_pmaddwd<SDOT_PMADD_SUF> (t, operands[1], operands[2]));
9835   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
9836                           gen_rtx_PLUS (<sseunpackmode>mode,
9837                                         operands[3], t)));
9838   DONE;
9839 })
9840
9841 ;; Normally we use widen_mul_even/odd, but combine can't quite get it all
9842 ;; back together when madd is available.
9843 (define_expand "sdot_prodv4si"
9844   [(match_operand:V2DI 0 "register_operand")
9845    (match_operand:V4SI 1 "register_operand")
9846    (match_operand:V4SI 2 "register_operand")
9847    (match_operand:V2DI 3 "register_operand")]
9848   "TARGET_XOP"
9849 {
9850   rtx t = gen_reg_rtx (V2DImode);
9851   emit_insn (gen_xop_pmacsdqh (t, operands[1], operands[2], operands[3]));
9852   emit_insn (gen_xop_pmacsdql (operands[0], operands[1], operands[2], t));
9853   DONE;
9854 })
9855
9856 (define_expand "usadv16qi"
9857   [(match_operand:V4SI 0 "register_operand")
9858    (match_operand:V16QI 1 "register_operand")
9859    (match_operand:V16QI 2 "nonimmediate_operand")
9860    (match_operand:V4SI 3 "nonimmediate_operand")]
9861   "TARGET_SSE2"
9862 {
9863   rtx t1 = gen_reg_rtx (V2DImode);
9864   rtx t2 = gen_reg_rtx (V4SImode);
9865   emit_insn (gen_sse2_psadbw (t1, operands[1], operands[2]));
9866   convert_move (t2, t1, 0);
9867   emit_insn (gen_addv4si3 (operands[0], t2, operands[3]));
9868   DONE;
9869 })
9870
9871 (define_expand "usadv32qi"
9872   [(match_operand:V8SI 0 "register_operand")
9873    (match_operand:V32QI 1 "register_operand")
9874    (match_operand:V32QI 2 "nonimmediate_operand")
9875    (match_operand:V8SI 3 "nonimmediate_operand")]
9876   "TARGET_AVX2"
9877 {
9878   rtx t1 = gen_reg_rtx (V4DImode);
9879   rtx t2 = gen_reg_rtx (V8SImode);
9880   emit_insn (gen_avx2_psadbw (t1, operands[1], operands[2]));
9881   convert_move (t2, t1, 0);
9882   emit_insn (gen_addv8si3 (operands[0], t2, operands[3]));
9883   DONE;
9884 })
9885
9886 (define_insn "ashr<mode>3"
9887   [(set (match_operand:VI24_AVX2 0 "register_operand" "=x,x")
9888         (ashiftrt:VI24_AVX2
9889           (match_operand:VI24_AVX2 1 "register_operand" "0,x")
9890           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
9891   "TARGET_SSE2"
9892   "@
9893    psra<ssemodesuffix>\t{%2, %0|%0, %2}
9894    vpsra<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
9895   [(set_attr "isa" "noavx,avx")
9896    (set_attr "type" "sseishft")
9897    (set (attr "length_immediate")
9898      (if_then_else (match_operand 2 "const_int_operand")
9899        (const_string "1")
9900        (const_string "0")))
9901    (set_attr "prefix_data16" "1,*")
9902    (set_attr "prefix" "orig,vex")
9903    (set_attr "mode" "<sseinsnmode>")])
9904
9905 (define_insn "<mask_codefor>ashr<mode>3<mask_name>"
9906   [(set (match_operand:VI24_AVX512BW_1 0 "register_operand" "=v,v")
9907         (ashiftrt:VI24_AVX512BW_1
9908           (match_operand:VI24_AVX512BW_1 1 "nonimmediate_operand" "v,vm")
9909           (match_operand:SI 2 "nonmemory_operand" "v,N")))]
9910   "TARGET_AVX512VL"
9911   "vpsra<ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9912   [(set_attr "type" "sseishft")
9913    (set (attr "length_immediate")
9914      (if_then_else (match_operand 2 "const_int_operand")
9915        (const_string "1")
9916        (const_string "0")))
9917    (set_attr "mode" "<sseinsnmode>")])
9918
9919 (define_insn "<mask_codefor>ashrv2di3<mask_name>"
9920   [(set (match_operand:V2DI 0 "register_operand" "=v,v")
9921         (ashiftrt:V2DI
9922           (match_operand:V2DI 1 "nonimmediate_operand" "v,vm")
9923           (match_operand:DI 2 "nonmemory_operand" "v,N")))]
9924   "TARGET_AVX512VL"
9925   "vpsraq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9926   [(set_attr "type" "sseishft")
9927    (set (attr "length_immediate")
9928      (if_then_else (match_operand 2 "const_int_operand")
9929        (const_string "1")
9930        (const_string "0")))
9931    (set_attr "mode" "TI")])
9932
9933 (define_insn "ashr<mode>3<mask_name>"
9934   [(set (match_operand:VI248_AVX512BW_AVX512VL 0 "register_operand" "=v,v")
9935         (ashiftrt:VI248_AVX512BW_AVX512VL
9936           (match_operand:VI248_AVX512BW_AVX512VL 1 "nonimmediate_operand" "v,vm")
9937           (match_operand:SI 2 "nonmemory_operand" "v,N")))]
9938   "TARGET_AVX512F"
9939   "vpsra<ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9940   [(set_attr "type" "sseishft")
9941    (set (attr "length_immediate")
9942      (if_then_else (match_operand 2 "const_int_operand")
9943        (const_string "1")
9944        (const_string "0")))
9945    (set_attr "mode" "<sseinsnmode>")])
9946
9947 (define_insn "<shift_insn><mode>3<mask_name>"
9948   [(set (match_operand:VI2_AVX2_AVX512BW 0 "register_operand" "=x,v")
9949         (any_lshift:VI2_AVX2_AVX512BW
9950           (match_operand:VI2_AVX2_AVX512BW 1 "register_operand" "0,v")
9951           (match_operand:SI 2 "nonmemory_operand" "xN,vN")))]
9952   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
9953   "@
9954    p<vshift><ssemodesuffix>\t{%2, %0|%0, %2}
9955    vp<vshift><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9956   [(set_attr "isa" "noavx,avx")
9957    (set_attr "type" "sseishft")
9958    (set (attr "length_immediate")
9959      (if_then_else (match_operand 2 "const_int_operand")
9960        (const_string "1")
9961        (const_string "0")))
9962    (set_attr "prefix_data16" "1,*")
9963    (set_attr "prefix" "orig,vex")
9964    (set_attr "mode" "<sseinsnmode>")])
9965
9966 (define_insn "<shift_insn><mode>3<mask_name>"
9967   [(set (match_operand:VI48_AVX2 0 "register_operand" "=x,v")
9968         (any_lshift:VI48_AVX2
9969           (match_operand:VI48_AVX2 1 "register_operand" "0,v")
9970           (match_operand:SI 2 "nonmemory_operand" "xN,vN")))]
9971   "TARGET_SSE2 && <mask_mode512bit_condition>"
9972   "@
9973    p<vshift><ssemodesuffix>\t{%2, %0|%0, %2}
9974    vp<vshift><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9975   [(set_attr "isa" "noavx,avx")
9976    (set_attr "type" "sseishft")
9977    (set (attr "length_immediate")
9978      (if_then_else (match_operand 2 "const_int_operand")
9979        (const_string "1")
9980        (const_string "0")))
9981    (set_attr "prefix_data16" "1,*")
9982    (set_attr "prefix" "orig,vex")
9983    (set_attr "mode" "<sseinsnmode>")])
9984
9985 (define_insn "<shift_insn><mode>3<mask_name>"
9986   [(set (match_operand:VI48_512 0 "register_operand" "=v,v")
9987         (any_lshift:VI48_512
9988           (match_operand:VI48_512 1 "nonimmediate_operand" "v,m")
9989           (match_operand:SI 2 "nonmemory_operand" "vN,N")))]
9990   "TARGET_AVX512F && <mask_mode512bit_condition>"
9991   "vp<vshift><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
9992   [(set_attr "isa" "avx512f")
9993    (set_attr "type" "sseishft")
9994    (set (attr "length_immediate")
9995      (if_then_else (match_operand 2 "const_int_operand")
9996        (const_string "1")
9997        (const_string "0")))
9998    (set_attr "prefix" "evex")
9999    (set_attr "mode" "<sseinsnmode>")])
10000
10001
10002 (define_expand "vec_shl_<mode>"
10003   [(set (match_dup 3)
10004         (ashift:V1TI
10005          (match_operand:VI_128 1 "register_operand")
10006          (match_operand:SI 2 "const_0_to_255_mul_8_operand")))
10007    (set (match_operand:VI_128 0 "register_operand") (match_dup 4))]
10008   "TARGET_SSE2"
10009 {
10010   operands[1] = gen_lowpart (V1TImode, operands[1]);
10011   operands[3] = gen_reg_rtx (V1TImode);
10012   operands[4] = gen_lowpart (<MODE>mode, operands[3]);
10013 })
10014
10015 (define_insn "<sse2_avx2>_ashl<mode>3"
10016   [(set (match_operand:VIMAX_AVX2 0 "register_operand" "=x,v")
10017         (ashift:VIMAX_AVX2
10018          (match_operand:VIMAX_AVX2 1 "register_operand" "0,v")
10019          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
10020   "TARGET_SSE2"
10021 {
10022   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
10023
10024   switch (which_alternative)
10025     {
10026     case 0:
10027       return "pslldq\t{%2, %0|%0, %2}";
10028     case 1:
10029       return "vpslldq\t{%2, %1, %0|%0, %1, %2}";
10030     default:
10031       gcc_unreachable ();
10032     }
10033 }
10034   [(set_attr "isa" "noavx,avx")
10035    (set_attr "type" "sseishft")
10036    (set_attr "length_immediate" "1")
10037    (set_attr "prefix_data16" "1,*")
10038    (set_attr "prefix" "orig,vex")
10039    (set_attr "mode" "<sseinsnmode>")])
10040
10041 (define_expand "vec_shr_<mode>"
10042   [(set (match_dup 3)
10043         (lshiftrt:V1TI
10044          (match_operand:VI_128 1 "register_operand")
10045          (match_operand:SI 2 "const_0_to_255_mul_8_operand")))
10046    (set (match_operand:VI_128 0 "register_operand") (match_dup 4))]
10047   "TARGET_SSE2"
10048 {
10049   operands[1] = gen_lowpart (V1TImode, operands[1]);
10050   operands[3] = gen_reg_rtx (V1TImode);
10051   operands[4] = gen_lowpart (<MODE>mode, operands[3]);
10052 })
10053
10054 (define_insn "<sse2_avx2>_lshr<mode>3"
10055   [(set (match_operand:VIMAX_AVX2 0 "register_operand" "=x,v")
10056         (lshiftrt:VIMAX_AVX2
10057          (match_operand:VIMAX_AVX2 1 "register_operand" "0,v")
10058          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
10059   "TARGET_SSE2"
10060 {
10061   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
10062
10063   switch (which_alternative)
10064     {
10065     case 0:
10066       return "psrldq\t{%2, %0|%0, %2}";
10067     case 1:
10068       return "vpsrldq\t{%2, %1, %0|%0, %1, %2}";
10069     default:
10070       gcc_unreachable ();
10071     }
10072 }
10073   [(set_attr "isa" "noavx,avx")
10074    (set_attr "type" "sseishft")
10075    (set_attr "length_immediate" "1")
10076    (set_attr "atom_unit" "sishuf")
10077    (set_attr "prefix_data16" "1,*")
10078    (set_attr "prefix" "orig,vex")
10079    (set_attr "mode" "<sseinsnmode>")])
10080
10081 (define_insn "<avx512>_<rotate>v<mode><mask_name>"
10082   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
10083         (any_rotate:VI48_AVX512VL
10084           (match_operand:VI48_AVX512VL 1 "register_operand" "v")
10085           (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm")))]
10086   "TARGET_AVX512F"
10087   "vp<rotate>v<ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
10088   [(set_attr "prefix" "evex")
10089    (set_attr "mode" "<sseinsnmode>")])
10090
10091 (define_insn "<avx512>_<rotate><mode><mask_name>"
10092   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
10093         (any_rotate:VI48_AVX512VL
10094           (match_operand:VI48_AVX512VL 1 "nonimmediate_operand" "vm")
10095           (match_operand:SI 2 "const_0_to_255_operand")))]
10096   "TARGET_AVX512F"
10097   "vp<rotate><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
10098   [(set_attr "prefix" "evex")
10099    (set_attr "mode" "<sseinsnmode>")])
10100
10101 (define_expand "<code><mode>3"
10102   [(set (match_operand:VI124_256_AVX512F_AVX512BW 0 "register_operand")
10103         (maxmin:VI124_256_AVX512F_AVX512BW
10104           (match_operand:VI124_256_AVX512F_AVX512BW 1 "nonimmediate_operand")
10105           (match_operand:VI124_256_AVX512F_AVX512BW 2 "nonimmediate_operand")))]
10106   "TARGET_AVX2"
10107   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
10108
10109 (define_insn "*avx2_<code><mode>3"
10110   [(set (match_operand:VI124_256 0 "register_operand" "=v")
10111         (maxmin:VI124_256
10112           (match_operand:VI124_256 1 "nonimmediate_operand" "%v")
10113           (match_operand:VI124_256 2 "nonimmediate_operand" "vm")))]
10114   "TARGET_AVX2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10115   "vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10116   [(set_attr "type" "sseiadd")
10117    (set_attr "prefix_extra" "1")
10118    (set_attr "prefix" "vex")
10119    (set_attr "mode" "OI")])
10120
10121 (define_expand "<code><mode>3_mask"
10122   [(set (match_operand:VI48_AVX512VL 0 "register_operand")
10123         (vec_merge:VI48_AVX512VL
10124           (maxmin:VI48_AVX512VL
10125             (match_operand:VI48_AVX512VL 1 "nonimmediate_operand")
10126             (match_operand:VI48_AVX512VL 2 "nonimmediate_operand"))
10127           (match_operand:VI48_AVX512VL 3 "vector_move_operand")
10128           (match_operand:<avx512fmaskmode> 4 "register_operand")))]
10129   "TARGET_AVX512F"
10130   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
10131
10132 (define_insn "*avx512bw_<code><mode>3<mask_name>"
10133   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
10134         (maxmin:VI48_AVX512VL
10135           (match_operand:VI48_AVX512VL 1 "nonimmediate_operand" "%v")
10136           (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm")))]
10137   "TARGET_AVX512F && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10138   "vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
10139   [(set_attr "type" "sseiadd")
10140    (set_attr "prefix_extra" "1")
10141    (set_attr "prefix" "maybe_evex")
10142    (set_attr "mode" "<sseinsnmode>")])
10143
10144 (define_insn "<mask_codefor><code><mode>3<mask_name>"
10145   [(set (match_operand:VI12_AVX512VL 0 "register_operand" "=v")
10146         (maxmin:VI12_AVX512VL
10147           (match_operand:VI12_AVX512VL 1 "register_operand" "v")
10148           (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm")))]
10149   "TARGET_AVX512BW"
10150   "vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
10151   [(set_attr "type" "sseiadd")
10152    (set_attr "prefix" "evex")
10153    (set_attr "mode" "<sseinsnmode>")])
10154
10155 (define_expand "<code><mode>3"
10156   [(set (match_operand:VI8_AVX2_AVX512BW 0 "register_operand")
10157         (maxmin:VI8_AVX2_AVX512BW
10158           (match_operand:VI8_AVX2_AVX512BW 1 "register_operand")
10159           (match_operand:VI8_AVX2_AVX512BW 2 "register_operand")))]
10160   "TARGET_SSE4_2"
10161 {
10162   if (TARGET_AVX512F
10163       && (<MODE>mode == V8DImode || TARGET_AVX512VL))
10164     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
10165   else 
10166     {
10167       enum rtx_code code;
10168       rtx xops[6];
10169       bool ok;
10170
10171
10172       xops[0] = operands[0];
10173
10174       if (<CODE> == SMAX || <CODE> == UMAX)
10175         {
10176           xops[1] = operands[1];
10177           xops[2] = operands[2];
10178         }
10179       else
10180         {
10181           xops[1] = operands[2];
10182           xops[2] = operands[1];
10183         }
10184
10185       code = (<CODE> == UMAX || <CODE> == UMIN) ? GTU : GT;
10186
10187       xops[3] = gen_rtx_fmt_ee (code, VOIDmode, operands[1], operands[2]);
10188       xops[4] = operands[1];
10189       xops[5] = operands[2];
10190
10191       ok = ix86_expand_int_vcond (xops);
10192       gcc_assert (ok);
10193       DONE;
10194     }
10195 })
10196
10197 (define_expand "<code><mode>3"
10198   [(set (match_operand:VI124_128 0 "register_operand")
10199         (smaxmin:VI124_128
10200           (match_operand:VI124_128 1 "nonimmediate_operand")
10201           (match_operand:VI124_128 2 "nonimmediate_operand")))]
10202   "TARGET_SSE2"
10203 {
10204   if (TARGET_SSE4_1 || <MODE>mode == V8HImode)
10205     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
10206   else
10207     {
10208       rtx xops[6];
10209       bool ok;
10210
10211       xops[0] = operands[0];
10212       operands[1] = force_reg (<MODE>mode, operands[1]);
10213       operands[2] = force_reg (<MODE>mode, operands[2]);
10214
10215       if (<CODE> == SMAX)
10216         {
10217           xops[1] = operands[1];
10218           xops[2] = operands[2];
10219         }
10220       else
10221         {
10222           xops[1] = operands[2];
10223           xops[2] = operands[1];
10224         }
10225
10226       xops[3] = gen_rtx_GT (VOIDmode, operands[1], operands[2]);
10227       xops[4] = operands[1];
10228       xops[5] = operands[2];
10229
10230       ok = ix86_expand_int_vcond (xops);
10231       gcc_assert (ok);
10232       DONE;
10233     }
10234 })
10235
10236 (define_insn "*sse4_1_<code><mode>3<mask_name>"
10237   [(set (match_operand:VI14_128 0 "register_operand" "=Yr,*x,v")
10238         (smaxmin:VI14_128
10239           (match_operand:VI14_128 1 "nonimmediate_operand" "%0,0,v")
10240           (match_operand:VI14_128 2 "nonimmediate_operand" "Yrm,*xm,vm")))]
10241   "TARGET_SSE4_1
10242    && <mask_mode512bit_condition>
10243    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10244   "@
10245    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
10246    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
10247    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
10248   [(set_attr "isa" "noavx,noavx,avx")
10249    (set_attr "type" "sseiadd")
10250    (set_attr "prefix_extra" "1,1,*")
10251    (set_attr "prefix" "orig,orig,vex")
10252    (set_attr "mode" "TI")])
10253
10254 (define_insn "*<code>v8hi3"
10255   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
10256         (smaxmin:V8HI
10257           (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
10258           (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))]
10259   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V8HImode, operands)"
10260   "@
10261    p<maxmin_int>w\t{%2, %0|%0, %2}
10262    vp<maxmin_int>w\t{%2, %1, %0|%0, %1, %2}"
10263   [(set_attr "isa" "noavx,avx")
10264    (set_attr "type" "sseiadd")
10265    (set_attr "prefix_data16" "1,*")
10266    (set_attr "prefix_extra" "*,1")
10267    (set_attr "prefix" "orig,vex")
10268    (set_attr "mode" "TI")])
10269
10270 (define_expand "<code><mode>3"
10271   [(set (match_operand:VI124_128 0 "register_operand")
10272         (umaxmin:VI124_128
10273           (match_operand:VI124_128 1 "nonimmediate_operand")
10274           (match_operand:VI124_128 2 "nonimmediate_operand")))]
10275   "TARGET_SSE2"
10276 {
10277   if (TARGET_SSE4_1 || <MODE>mode == V16QImode)
10278     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
10279   else if (<CODE> == UMAX && <MODE>mode == V8HImode)
10280     {
10281       rtx op0 = operands[0], op2 = operands[2], op3 = op0;
10282       operands[1] = force_reg (<MODE>mode, operands[1]);
10283       if (rtx_equal_p (op3, op2))
10284         op3 = gen_reg_rtx (V8HImode);
10285       emit_insn (gen_sse2_ussubv8hi3 (op3, operands[1], op2));
10286       emit_insn (gen_addv8hi3 (op0, op3, op2));
10287       DONE;
10288     }
10289   else
10290     {
10291       rtx xops[6];
10292       bool ok;
10293
10294       operands[1] = force_reg (<MODE>mode, operands[1]);
10295       operands[2] = force_reg (<MODE>mode, operands[2]);
10296
10297       xops[0] = operands[0];
10298
10299       if (<CODE> == UMAX)
10300         {
10301           xops[1] = operands[1];
10302           xops[2] = operands[2];
10303         }
10304       else
10305         {
10306           xops[1] = operands[2];
10307           xops[2] = operands[1];
10308         }
10309
10310       xops[3] = gen_rtx_GTU (VOIDmode, operands[1], operands[2]);
10311       xops[4] = operands[1];
10312       xops[5] = operands[2];
10313
10314       ok = ix86_expand_int_vcond (xops);
10315       gcc_assert (ok);
10316       DONE;
10317     }
10318 })
10319
10320 (define_insn "*sse4_1_<code><mode>3<mask_name>"
10321   [(set (match_operand:VI24_128 0 "register_operand" "=Yr,*x,v")
10322         (umaxmin:VI24_128
10323           (match_operand:VI24_128 1 "nonimmediate_operand" "%0,0,v")
10324           (match_operand:VI24_128 2 "nonimmediate_operand" "Yrm,*xm,vm")))]
10325   "TARGET_SSE4_1
10326    && <mask_mode512bit_condition>
10327    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10328   "@
10329    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
10330    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
10331    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
10332   [(set_attr "isa" "noavx,noavx,avx")
10333    (set_attr "type" "sseiadd")
10334    (set_attr "prefix_extra" "1,1,*")
10335    (set_attr "prefix" "orig,orig,vex")
10336    (set_attr "mode" "TI")])
10337
10338 (define_insn "*<code>v16qi3"
10339   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
10340         (umaxmin:V16QI
10341           (match_operand:V16QI 1 "nonimmediate_operand" "%0,x")
10342           (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")))]
10343   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V16QImode, operands)"
10344   "@
10345    p<maxmin_int>b\t{%2, %0|%0, %2}
10346    vp<maxmin_int>b\t{%2, %1, %0|%0, %1, %2}"
10347   [(set_attr "isa" "noavx,avx")
10348    (set_attr "type" "sseiadd")
10349    (set_attr "prefix_data16" "1,*")
10350    (set_attr "prefix_extra" "*,1")
10351    (set_attr "prefix" "orig,vex")
10352    (set_attr "mode" "TI")])
10353
10354 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10355 ;;
10356 ;; Parallel integral comparisons
10357 ;;
10358 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10359
10360 (define_expand "avx2_eq<mode>3"
10361   [(set (match_operand:VI_256 0 "register_operand")
10362         (eq:VI_256
10363           (match_operand:VI_256 1 "nonimmediate_operand")
10364           (match_operand:VI_256 2 "nonimmediate_operand")))]
10365   "TARGET_AVX2"
10366   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
10367
10368 (define_insn "*avx2_eq<mode>3"
10369   [(set (match_operand:VI_256 0 "register_operand" "=x")
10370         (eq:VI_256
10371           (match_operand:VI_256 1 "nonimmediate_operand" "%x")
10372           (match_operand:VI_256 2 "nonimmediate_operand" "xm")))]
10373   "TARGET_AVX2 && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
10374   "vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10375   [(set_attr "type" "ssecmp")
10376    (set_attr "prefix_extra" "1")
10377    (set_attr "prefix" "vex")
10378    (set_attr "mode" "OI")])
10379
10380 (define_expand "<avx512>_eq<mode>3<mask_scalar_merge_name>"
10381   [(set (match_operand:<avx512fmaskmode> 0 "register_operand")
10382         (unspec:<avx512fmaskmode>
10383           [(match_operand:VI12_AVX512VL 1 "register_operand")
10384            (match_operand:VI12_AVX512VL 2 "nonimmediate_operand")]
10385           UNSPEC_MASKED_EQ))]
10386   "TARGET_AVX512BW"
10387   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
10388
10389 (define_expand "<avx512>_eq<mode>3<mask_scalar_merge_name>"
10390   [(set (match_operand:<avx512fmaskmode> 0 "register_operand")
10391         (unspec:<avx512fmaskmode>
10392           [(match_operand:VI48_AVX512VL 1 "register_operand")
10393            (match_operand:VI48_AVX512VL 2 "nonimmediate_operand")]
10394           UNSPEC_MASKED_EQ))]
10395   "TARGET_AVX512F"
10396   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
10397
10398 (define_insn "<avx512>_eq<mode>3<mask_scalar_merge_name>_1"
10399   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
10400         (unspec:<avx512fmaskmode>
10401           [(match_operand:VI12_AVX512VL 1 "register_operand" "%v")
10402            (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm")]
10403           UNSPEC_MASKED_EQ))]
10404   "TARGET_AVX512F && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
10405   "vpcmpeq<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}"
10406   [(set_attr "type" "ssecmp")
10407    (set_attr "prefix_extra" "1")
10408    (set_attr "prefix" "evex")
10409    (set_attr "mode" "<sseinsnmode>")])
10410
10411 (define_insn "<avx512>_eq<mode>3<mask_scalar_merge_name>_1"
10412   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
10413         (unspec:<avx512fmaskmode>
10414           [(match_operand:VI48_AVX512VL 1 "register_operand" "%v")
10415            (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm")]
10416           UNSPEC_MASKED_EQ))]
10417   "TARGET_AVX512F && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
10418   "vpcmpeq<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}"
10419   [(set_attr "type" "ssecmp")
10420    (set_attr "prefix_extra" "1")
10421    (set_attr "prefix" "evex")
10422    (set_attr "mode" "<sseinsnmode>")])
10423
10424 (define_insn "*sse4_1_eqv2di3"
10425   [(set (match_operand:V2DI 0 "register_operand" "=Yr,*x,x")
10426         (eq:V2DI
10427           (match_operand:V2DI 1 "nonimmediate_operand" "%0,0,x")
10428           (match_operand:V2DI 2 "nonimmediate_operand" "Yrm,*xm,xm")))]
10429   "TARGET_SSE4_1 && ix86_binary_operator_ok (EQ, V2DImode, operands)"
10430   "@
10431    pcmpeqq\t{%2, %0|%0, %2}
10432    pcmpeqq\t{%2, %0|%0, %2}
10433    vpcmpeqq\t{%2, %1, %0|%0, %1, %2}"
10434   [(set_attr "isa" "noavx,noavx,avx")
10435    (set_attr "type" "ssecmp")
10436    (set_attr "prefix_extra" "1")
10437    (set_attr "prefix" "orig,orig,vex")
10438    (set_attr "mode" "TI")])
10439
10440 (define_insn "*sse2_eq<mode>3"
10441   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
10442         (eq:VI124_128
10443           (match_operand:VI124_128 1 "nonimmediate_operand" "%0,x")
10444           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
10445   "TARGET_SSE2 && !TARGET_XOP
10446    && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
10447   "@
10448    pcmpeq<ssemodesuffix>\t{%2, %0|%0, %2}
10449    vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10450   [(set_attr "isa" "noavx,avx")
10451    (set_attr "type" "ssecmp")
10452    (set_attr "prefix_data16" "1,*")
10453    (set_attr "prefix" "orig,vex")
10454    (set_attr "mode" "TI")])
10455
10456 (define_expand "sse2_eq<mode>3"
10457   [(set (match_operand:VI124_128 0 "register_operand")
10458         (eq:VI124_128
10459           (match_operand:VI124_128 1 "nonimmediate_operand")
10460           (match_operand:VI124_128 2 "nonimmediate_operand")))]
10461   "TARGET_SSE2 && !TARGET_XOP "
10462   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
10463
10464 (define_expand "sse4_1_eqv2di3"
10465   [(set (match_operand:V2DI 0 "register_operand")
10466         (eq:V2DI
10467           (match_operand:V2DI 1 "nonimmediate_operand")
10468           (match_operand:V2DI 2 "nonimmediate_operand")))]
10469   "TARGET_SSE4_1"
10470   "ix86_fixup_binary_operands_no_copy (EQ, V2DImode, operands);")
10471
10472 (define_insn "sse4_2_gtv2di3"
10473   [(set (match_operand:V2DI 0 "register_operand" "=Yr,*x,x")
10474         (gt:V2DI
10475           (match_operand:V2DI 1 "register_operand" "0,0,x")
10476           (match_operand:V2DI 2 "nonimmediate_operand" "Yrm,*xm,xm")))]
10477   "TARGET_SSE4_2"
10478   "@
10479    pcmpgtq\t{%2, %0|%0, %2}
10480    pcmpgtq\t{%2, %0|%0, %2}
10481    vpcmpgtq\t{%2, %1, %0|%0, %1, %2}"
10482   [(set_attr "isa" "noavx,noavx,avx")
10483    (set_attr "type" "ssecmp")
10484    (set_attr "prefix_extra" "1")
10485    (set_attr "prefix" "orig,orig,vex")
10486    (set_attr "mode" "TI")])
10487
10488 (define_insn "avx2_gt<mode>3"
10489   [(set (match_operand:VI_256 0 "register_operand" "=x")
10490         (gt:VI_256
10491           (match_operand:VI_256 1 "register_operand" "x")
10492           (match_operand:VI_256 2 "nonimmediate_operand" "xm")))]
10493   "TARGET_AVX2"
10494   "vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10495   [(set_attr "type" "ssecmp")
10496    (set_attr "prefix_extra" "1")
10497    (set_attr "prefix" "vex")
10498    (set_attr "mode" "OI")])
10499
10500 (define_insn "<avx512>_gt<mode>3<mask_scalar_merge_name>"
10501   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
10502         (unspec:<avx512fmaskmode>
10503           [(match_operand:VI48_AVX512VL 1 "register_operand" "v")
10504            (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm")] UNSPEC_MASKED_GT))]
10505   "TARGET_AVX512F"
10506   "vpcmpgt<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}"
10507   [(set_attr "type" "ssecmp")
10508    (set_attr "prefix_extra" "1")
10509    (set_attr "prefix" "evex")
10510    (set_attr "mode" "<sseinsnmode>")])
10511
10512 (define_insn "<avx512>_gt<mode>3<mask_scalar_merge_name>"
10513   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
10514         (unspec:<avx512fmaskmode>
10515           [(match_operand:VI12_AVX512VL 1 "register_operand" "v")
10516            (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm")] UNSPEC_MASKED_GT))]
10517   "TARGET_AVX512BW"
10518   "vpcmpgt<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}"
10519   [(set_attr "type" "ssecmp")
10520    (set_attr "prefix_extra" "1")
10521    (set_attr "prefix" "evex")
10522    (set_attr "mode" "<sseinsnmode>")])
10523
10524 (define_insn "sse2_gt<mode>3"
10525   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
10526         (gt:VI124_128
10527           (match_operand:VI124_128 1 "register_operand" "0,x")
10528           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
10529   "TARGET_SSE2 && !TARGET_XOP"
10530   "@
10531    pcmpgt<ssemodesuffix>\t{%2, %0|%0, %2}
10532    vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
10533   [(set_attr "isa" "noavx,avx")
10534    (set_attr "type" "ssecmp")
10535    (set_attr "prefix_data16" "1,*")
10536    (set_attr "prefix" "orig,vex")
10537    (set_attr "mode" "TI")])
10538
10539 (define_expand "vcond<V_512:mode><VI_512:mode>"
10540   [(set (match_operand:V_512 0 "register_operand")
10541         (if_then_else:V_512
10542           (match_operator 3 ""
10543             [(match_operand:VI_512 4 "nonimmediate_operand")
10544              (match_operand:VI_512 5 "general_operand")])
10545           (match_operand:V_512 1)
10546           (match_operand:V_512 2)))]
10547   "TARGET_AVX512F
10548    && (GET_MODE_NUNITS (<V_512:MODE>mode)
10549        == GET_MODE_NUNITS (<VI_512:MODE>mode))"
10550 {
10551   bool ok = ix86_expand_int_vcond (operands);
10552   gcc_assert (ok);
10553   DONE;
10554 })
10555
10556 (define_expand "vcond<V_256:mode><VI_256:mode>"
10557   [(set (match_operand:V_256 0 "register_operand")
10558         (if_then_else:V_256
10559           (match_operator 3 ""
10560             [(match_operand:VI_256 4 "nonimmediate_operand")
10561              (match_operand:VI_256 5 "general_operand")])
10562           (match_operand:V_256 1)
10563           (match_operand:V_256 2)))]
10564   "TARGET_AVX2
10565    && (GET_MODE_NUNITS (<V_256:MODE>mode)
10566        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
10567 {
10568   bool ok = ix86_expand_int_vcond (operands);
10569   gcc_assert (ok);
10570   DONE;
10571 })
10572
10573 (define_expand "vcond<V_128:mode><VI124_128:mode>"
10574   [(set (match_operand:V_128 0 "register_operand")
10575         (if_then_else:V_128
10576           (match_operator 3 ""
10577             [(match_operand:VI124_128 4 "nonimmediate_operand")
10578              (match_operand:VI124_128 5 "general_operand")])
10579           (match_operand:V_128 1)
10580           (match_operand:V_128 2)))]
10581   "TARGET_SSE2
10582    && (GET_MODE_NUNITS (<V_128:MODE>mode)
10583        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
10584 {
10585   bool ok = ix86_expand_int_vcond (operands);
10586   gcc_assert (ok);
10587   DONE;
10588 })
10589
10590 (define_expand "vcond<VI8F_128:mode>v2di"
10591   [(set (match_operand:VI8F_128 0 "register_operand")
10592         (if_then_else:VI8F_128
10593           (match_operator 3 ""
10594             [(match_operand:V2DI 4 "nonimmediate_operand")
10595              (match_operand:V2DI 5 "general_operand")])
10596           (match_operand:VI8F_128 1)
10597           (match_operand:VI8F_128 2)))]
10598   "TARGET_SSE4_2"
10599 {
10600   bool ok = ix86_expand_int_vcond (operands);
10601   gcc_assert (ok);
10602   DONE;
10603 })
10604
10605 (define_expand "vcondu<V_512:mode><VI_512:mode>"
10606   [(set (match_operand:V_512 0 "register_operand")
10607         (if_then_else:V_512
10608           (match_operator 3 ""
10609             [(match_operand:VI_512 4 "nonimmediate_operand")
10610              (match_operand:VI_512 5 "nonimmediate_operand")])
10611           (match_operand:V_512 1 "general_operand")
10612           (match_operand:V_512 2 "general_operand")))]
10613   "TARGET_AVX512F
10614    && (GET_MODE_NUNITS (<V_512:MODE>mode)
10615        == GET_MODE_NUNITS (<VI_512:MODE>mode))"
10616 {
10617   bool ok = ix86_expand_int_vcond (operands);
10618   gcc_assert (ok);
10619   DONE;
10620 })
10621
10622 (define_expand "vcondu<V_256:mode><VI_256:mode>"
10623   [(set (match_operand:V_256 0 "register_operand")
10624         (if_then_else:V_256
10625           (match_operator 3 ""
10626             [(match_operand:VI_256 4 "nonimmediate_operand")
10627              (match_operand:VI_256 5 "nonimmediate_operand")])
10628           (match_operand:V_256 1 "general_operand")
10629           (match_operand:V_256 2 "general_operand")))]
10630   "TARGET_AVX2
10631    && (GET_MODE_NUNITS (<V_256:MODE>mode)
10632        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
10633 {
10634   bool ok = ix86_expand_int_vcond (operands);
10635   gcc_assert (ok);
10636   DONE;
10637 })
10638
10639 (define_expand "vcondu<V_128:mode><VI124_128:mode>"
10640   [(set (match_operand:V_128 0 "register_operand")
10641         (if_then_else:V_128
10642           (match_operator 3 ""
10643             [(match_operand:VI124_128 4 "nonimmediate_operand")
10644              (match_operand:VI124_128 5 "nonimmediate_operand")])
10645           (match_operand:V_128 1 "general_operand")
10646           (match_operand:V_128 2 "general_operand")))]
10647   "TARGET_SSE2
10648    && (GET_MODE_NUNITS (<V_128:MODE>mode)
10649        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
10650 {
10651   bool ok = ix86_expand_int_vcond (operands);
10652   gcc_assert (ok);
10653   DONE;
10654 })
10655
10656 (define_expand "vcondu<VI8F_128:mode>v2di"
10657   [(set (match_operand:VI8F_128 0 "register_operand")
10658         (if_then_else:VI8F_128
10659           (match_operator 3 ""
10660             [(match_operand:V2DI 4 "nonimmediate_operand")
10661              (match_operand:V2DI 5 "nonimmediate_operand")])
10662           (match_operand:VI8F_128 1 "general_operand")
10663           (match_operand:VI8F_128 2 "general_operand")))]
10664   "TARGET_SSE4_2"
10665 {
10666   bool ok = ix86_expand_int_vcond (operands);
10667   gcc_assert (ok);
10668   DONE;
10669 })
10670
10671 (define_mode_iterator VEC_PERM_AVX2
10672   [V16QI V8HI V4SI V2DI V4SF V2DF
10673    (V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
10674    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")
10675    (V8SF "TARGET_AVX2") (V4DF "TARGET_AVX2")
10676    (V16SF "TARGET_AVX512F") (V8DF "TARGET_AVX512F")
10677    (V16SI "TARGET_AVX512F") (V8DI "TARGET_AVX512F")
10678    (V32HI "TARGET_AVX512BW") (V64QI "TARGET_AVX512VBMI")])
10679
10680 (define_expand "vec_perm<mode>"
10681   [(match_operand:VEC_PERM_AVX2 0 "register_operand")
10682    (match_operand:VEC_PERM_AVX2 1 "register_operand")
10683    (match_operand:VEC_PERM_AVX2 2 "register_operand")
10684    (match_operand:<sseintvecmode> 3 "register_operand")]
10685   "TARGET_SSSE3 || TARGET_AVX || TARGET_XOP"
10686 {
10687   ix86_expand_vec_perm (operands);
10688   DONE;
10689 })
10690
10691 (define_mode_iterator VEC_PERM_CONST
10692   [(V4SF "TARGET_SSE") (V4SI "TARGET_SSE")
10693    (V2DF "TARGET_SSE") (V2DI "TARGET_SSE")
10694    (V16QI "TARGET_SSE2") (V8HI "TARGET_SSE2")
10695    (V8SF "TARGET_AVX") (V4DF "TARGET_AVX")
10696    (V8SI "TARGET_AVX") (V4DI "TARGET_AVX")
10697    (V32QI "TARGET_AVX2") (V16HI "TARGET_AVX2")
10698    (V16SI "TARGET_AVX512F") (V8DI "TARGET_AVX512F")
10699    (V16SF "TARGET_AVX512F") (V8DF "TARGET_AVX512F")
10700    (V32HI "TARGET_AVX512BW") (V64QI "TARGET_AVX512BW")])
10701
10702 (define_expand "vec_perm_const<mode>"
10703   [(match_operand:VEC_PERM_CONST 0 "register_operand")
10704    (match_operand:VEC_PERM_CONST 1 "register_operand")
10705    (match_operand:VEC_PERM_CONST 2 "register_operand")
10706    (match_operand:<sseintvecmode> 3)]
10707   ""
10708 {
10709   if (ix86_expand_vec_perm_const (operands))
10710     DONE;
10711   else
10712     FAIL;
10713 })
10714
10715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10716 ;;
10717 ;; Parallel bitwise logical operations
10718 ;;
10719 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10720
10721 (define_expand "one_cmpl<mode>2"
10722   [(set (match_operand:VI 0 "register_operand")
10723         (xor:VI (match_operand:VI 1 "nonimmediate_operand")
10724                 (match_dup 2)))]
10725   "TARGET_SSE"
10726 {
10727   int i, n = GET_MODE_NUNITS (<MODE>mode);
10728   rtvec v = rtvec_alloc (n);
10729
10730   for (i = 0; i < n; ++i)
10731     RTVEC_ELT (v, i) = constm1_rtx;
10732
10733   operands[2] = force_reg (<MODE>mode, gen_rtx_CONST_VECTOR (<MODE>mode, v));
10734 })
10735
10736 (define_expand "<sse2_avx2>_andnot<mode>3"
10737   [(set (match_operand:VI_AVX2 0 "register_operand")
10738         (and:VI_AVX2
10739           (not:VI_AVX2 (match_operand:VI_AVX2 1 "register_operand"))
10740           (match_operand:VI_AVX2 2 "nonimmediate_operand")))]
10741   "TARGET_SSE2")
10742
10743 (define_expand "<sse2_avx2>_andnot<mode>3_mask"
10744   [(set (match_operand:VI48_AVX512VL 0 "register_operand")
10745         (vec_merge:VI48_AVX512VL
10746           (and:VI48_AVX512VL
10747             (not:VI48_AVX512VL
10748               (match_operand:VI48_AVX512VL 1 "register_operand"))
10749             (match_operand:VI48_AVX512VL 2 "nonimmediate_operand"))
10750           (match_operand:VI48_AVX512VL 3 "vector_move_operand")
10751           (match_operand:<avx512fmaskmode> 4 "register_operand")))]
10752   "TARGET_AVX512F")
10753
10754 (define_expand "<sse2_avx2>_andnot<mode>3_mask"
10755   [(set (match_operand:VI12_AVX512VL 0 "register_operand")
10756         (vec_merge:VI12_AVX512VL
10757           (and:VI12_AVX512VL
10758             (not:VI12_AVX512VL
10759               (match_operand:VI12_AVX512VL 1 "register_operand"))
10760             (match_operand:VI12_AVX512VL 2 "nonimmediate_operand"))
10761           (match_operand:VI12_AVX512VL 3 "vector_move_operand")
10762           (match_operand:<avx512fmaskmode> 4 "register_operand")))]
10763   "TARGET_AVX512BW")
10764
10765 (define_insn "*andnot<mode>3"
10766   [(set (match_operand:VI 0 "register_operand" "=x,v")
10767         (and:VI
10768           (not:VI (match_operand:VI 1 "register_operand" "0,v"))
10769           (match_operand:VI 2 "nonimmediate_operand" "xm,vm")))]
10770   "TARGET_SSE"
10771 {
10772   static char buf[64];
10773   const char *ops;
10774   const char *tmp;
10775
10776   switch (get_attr_mode (insn))
10777     {
10778     case MODE_XI:
10779       gcc_assert (TARGET_AVX512F);
10780     case MODE_OI:
10781       gcc_assert (TARGET_AVX2 || TARGET_AVX512VL);
10782     case MODE_TI:
10783       gcc_assert (TARGET_SSE2 || TARGET_AVX512VL);
10784       switch (<MODE>mode)
10785       {
10786         case V16SImode:
10787         case V8DImode:
10788           if (TARGET_AVX512F)
10789           {
10790             tmp = "pandn<ssemodesuffix>";
10791             break;
10792           }
10793         case V8SImode:
10794         case V4DImode:
10795         case V4SImode:
10796         case V2DImode:
10797           if (TARGET_AVX512VL)
10798           {
10799             tmp = "pandn<ssemodesuffix>";
10800             break;
10801           }
10802         default:
10803           tmp = TARGET_AVX512VL ? "pandnq" : "pandn";
10804       }
10805       break;
10806
10807    case MODE_V16SF:
10808       gcc_assert (TARGET_AVX512F);
10809    case MODE_V8SF:
10810       gcc_assert (TARGET_AVX);
10811    case MODE_V4SF:
10812       gcc_assert (TARGET_SSE);
10813
10814       tmp = "andnps";
10815       break;
10816
10817    default:
10818       gcc_unreachable ();
10819    }
10820
10821   switch (which_alternative)
10822     {
10823     case 0:
10824       ops = "%s\t{%%2, %%0|%%0, %%2}";
10825       break;
10826     case 1:
10827       ops = "v%s\t{%%2, %%1, %%0<mask_operand3_1>|%%0<mask_operand3_1>, %%1, %%2}";
10828       break;
10829     default:
10830       gcc_unreachable ();
10831     }
10832
10833   snprintf (buf, sizeof (buf), ops, tmp);
10834   return buf;
10835 }
10836   [(set_attr "isa" "noavx,avx")
10837    (set_attr "type" "sselog")
10838    (set (attr "prefix_data16")
10839      (if_then_else
10840        (and (eq_attr "alternative" "0")
10841             (eq_attr "mode" "TI"))
10842        (const_string "1")
10843        (const_string "*")))
10844    (set_attr "prefix" "orig,vex")
10845    (set (attr "mode")
10846         (cond [(and (match_test "<MODE_SIZE> == 16")
10847                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
10848                  (const_string "<ssePSmode>")
10849                (match_test "TARGET_AVX2")
10850                  (const_string "<sseinsnmode>")
10851                (match_test "TARGET_AVX")
10852                  (if_then_else
10853                    (match_test "<MODE_SIZE> > 16")
10854                    (const_string "V8SF")
10855                    (const_string "<sseinsnmode>"))
10856                (ior (not (match_test "TARGET_SSE2"))
10857                     (match_test "optimize_function_for_size_p (cfun)"))
10858                  (const_string "V4SF")
10859               ]
10860               (const_string "<sseinsnmode>")))])
10861
10862 (define_insn "*andnot<mode>3_mask"
10863   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
10864         (vec_merge:VI48_AVX512VL
10865           (and:VI48_AVX512VL
10866             (not:VI48_AVX512VL
10867               (match_operand:VI48_AVX512VL 1 "register_operand" "v"))
10868             (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm"))
10869           (match_operand:VI48_AVX512VL 3 "vector_move_operand" "0C")
10870           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
10871   "TARGET_AVX512F"
10872   "vpandn<ssemodesuffix>\t{%2, %1, %0%{%4%}%N3|%0%{%4%}%N3, %1, %2}";
10873   [(set_attr "type" "sselog")
10874    (set_attr "prefix" "evex")
10875    (set_attr "mode" "<sseinsnmode>")])
10876
10877 (define_insn "*andnot<mode>3_mask"
10878   [(set (match_operand:VI12_AVX512VL 0 "register_operand" "=v")
10879         (vec_merge:VI12_AVX512VL
10880           (and:VI12_AVX512VL
10881             (not:VI12_AVX512VL
10882               (match_operand:VI12_AVX512VL 1 "register_operand" "v"))
10883             (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm"))
10884           (match_operand:VI12_AVX512VL 3 "vector_move_operand" "0C")
10885           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
10886   "TARGET_AVX512BW"
10887   "vpandn<ssemodesuffix>\t{%2, %1, %0%{%4%}%N3|%0%{%4%}%N3, %1, %2}";
10888   [(set_attr "type" "sselog")
10889    (set_attr "prefix" "evex")
10890    (set_attr "mode" "<sseinsnmode>")])
10891
10892 (define_expand "<code><mode>3"
10893   [(set (match_operand:VI 0 "register_operand")
10894         (any_logic:VI
10895           (match_operand:VI 1 "nonimmediate_or_const_vector_operand")
10896           (match_operand:VI 2 "nonimmediate_or_const_vector_operand")))]
10897   "TARGET_SSE"
10898 {
10899   ix86_expand_vector_logical_operator (<CODE>, <MODE>mode, operands);
10900   DONE;
10901 })
10902
10903 (define_insn "<mask_codefor><code><mode>3<mask_name>"
10904   [(set (match_operand:VI 0 "register_operand" "=x,v")
10905         (any_logic:VI
10906           (match_operand:VI 1 "nonimmediate_operand" "%0,v")
10907           (match_operand:VI 2 "nonimmediate_operand" "xm,vm")))]
10908   "TARGET_SSE && <mask_mode512bit_condition>
10909    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
10910 {
10911   static char buf[64];
10912   const char *ops;
10913   const char *tmp;
10914
10915   switch (get_attr_mode (insn))
10916     {
10917     case MODE_XI:
10918       gcc_assert (TARGET_AVX512F);
10919     case MODE_OI:
10920       gcc_assert (TARGET_AVX2 || TARGET_AVX512VL);
10921     case MODE_TI:
10922       gcc_assert (TARGET_SSE2 || TARGET_AVX512VL);
10923       switch (<MODE>mode)
10924       {
10925         case V16SImode:
10926         case V8DImode:
10927           if (TARGET_AVX512F)
10928           {
10929             tmp = "p<logic><ssemodesuffix>";
10930             break;
10931           }
10932         case V8SImode:
10933         case V4DImode:
10934         case V4SImode:
10935         case V2DImode:
10936           if (TARGET_AVX512VL)
10937           {
10938             tmp = "p<logic><ssemodesuffix>";
10939             break;
10940           }
10941         default:
10942           tmp = TARGET_AVX512VL ? "p<logic>q" : "p<logic>";
10943       }
10944       break;
10945
10946    case MODE_V16SF:
10947       gcc_assert (TARGET_AVX512F);
10948    case MODE_V8SF:
10949       gcc_assert (TARGET_AVX);
10950    case MODE_V4SF:
10951       gcc_assert (TARGET_SSE);
10952
10953       tmp = "<logic>ps";
10954       break;
10955
10956    default:
10957       gcc_unreachable ();
10958    }
10959
10960   switch (which_alternative)
10961     {
10962     case 0:
10963       ops = "%s\t{%%2, %%0|%%0, %%2}";
10964       break;
10965     case 1:
10966       ops = "v%s\t{%%2, %%1, %%0<mask_operand3_1>|%%0<mask_operand3_1>, %%1, %%2}";
10967       break;
10968     default:
10969       gcc_unreachable ();
10970     }
10971
10972   snprintf (buf, sizeof (buf), ops, tmp);
10973   return buf;
10974 }
10975   [(set_attr "isa" "noavx,avx")
10976    (set_attr "type" "sselog")
10977    (set (attr "prefix_data16")
10978      (if_then_else
10979        (and (eq_attr "alternative" "0")
10980             (eq_attr "mode" "TI"))
10981        (const_string "1")
10982        (const_string "*")))
10983    (set_attr "prefix" "<mask_prefix3>")
10984    (set (attr "mode")
10985         (cond [(and (match_test "<MODE_SIZE> == 16")
10986                     (match_test "TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL"))
10987                  (const_string "<ssePSmode>")
10988                (match_test "TARGET_AVX2")
10989                  (const_string "<sseinsnmode>")
10990                (match_test "TARGET_AVX")
10991                  (if_then_else
10992                    (match_test "<MODE_SIZE> > 16")
10993                    (const_string "V8SF")
10994                    (const_string "<sseinsnmode>"))
10995                (ior (not (match_test "TARGET_SSE2"))
10996                     (match_test "optimize_function_for_size_p (cfun)"))
10997                  (const_string "V4SF")
10998               ]
10999               (const_string "<sseinsnmode>")))])
11000
11001 (define_insn "<avx512>_testm<mode>3<mask_scalar_merge_name>"
11002   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
11003         (unspec:<avx512fmaskmode>
11004          [(match_operand:VI12_AVX512VL 1 "register_operand" "v")
11005           (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm")]
11006          UNSPEC_TESTM))]
11007   "TARGET_AVX512BW"
11008   "vptestm<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}"
11009   [(set_attr "prefix" "evex")
11010    (set_attr "mode"  "<sseinsnmode>")])
11011
11012 (define_insn "<avx512>_testm<mode>3<mask_scalar_merge_name>"
11013   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
11014         (unspec:<avx512fmaskmode>
11015          [(match_operand:VI48_AVX512VL 1 "register_operand" "v")
11016           (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm")]
11017          UNSPEC_TESTM))]
11018   "TARGET_AVX512F"
11019   "vptestm<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}"
11020   [(set_attr "prefix" "evex")
11021    (set_attr "mode"  "<sseinsnmode>")])
11022
11023 (define_insn "<avx512>_testnm<mode>3<mask_scalar_merge_name>"
11024   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
11025         (unspec:<avx512fmaskmode>
11026          [(match_operand:VI12_AVX512VL 1 "register_operand" "v")
11027           (match_operand:VI12_AVX512VL 2 "nonimmediate_operand" "vm")]
11028          UNSPEC_TESTNM))]
11029   "TARGET_AVX512BW"
11030   "vptestnm<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}"
11031   [(set_attr "prefix" "evex")
11032    (set_attr "mode"  "<sseinsnmode>")])
11033
11034 (define_insn "<avx512>_testnm<mode>3<mask_scalar_merge_name>"
11035   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
11036         (unspec:<avx512fmaskmode>
11037          [(match_operand:VI48_AVX512VL 1 "register_operand" "v")
11038           (match_operand:VI48_AVX512VL 2 "nonimmediate_operand" "vm")]
11039          UNSPEC_TESTNM))]
11040   "TARGET_AVX512F"
11041   "vptestnm<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}"
11042   [(set_attr "prefix" "evex")
11043    (set_attr "mode"  "<sseinsnmode>")])
11044
11045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11046 ;;
11047 ;; Parallel integral element swizzling
11048 ;;
11049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11050
11051 (define_expand "vec_pack_trunc_<mode>"
11052   [(match_operand:<ssepackmode> 0 "register_operand")
11053    (match_operand:VI248_AVX2_8_AVX512F 1 "register_operand")
11054    (match_operand:VI248_AVX2_8_AVX512F 2 "register_operand")]
11055   "TARGET_SSE2"
11056 {
11057   rtx op1 = gen_lowpart (<ssepackmode>mode, operands[1]);
11058   rtx op2 = gen_lowpart (<ssepackmode>mode, operands[2]);
11059   ix86_expand_vec_extract_even_odd (operands[0], op1, op2, 0);
11060   DONE;
11061 })
11062
11063 (define_insn "<sse2_avx2>_packsswb<mask_name>"
11064   [(set (match_operand:VI1_AVX512 0 "register_operand" "=x,x")
11065         (vec_concat:VI1_AVX512
11066           (ss_truncate:<ssehalfvecmode>
11067             (match_operand:<sseunpackmode> 1 "register_operand" "0,v"))
11068           (ss_truncate:<ssehalfvecmode>
11069             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,vm"))))]
11070   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
11071   "@
11072    packsswb\t{%2, %0|%0, %2}
11073    vpacksswb\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11074   [(set_attr "isa" "noavx,avx")
11075    (set_attr "type" "sselog")
11076    (set_attr "prefix_data16" "1,*")
11077    (set_attr "prefix" "orig,maybe_evex")
11078    (set_attr "mode" "<sseinsnmode>")])
11079
11080 (define_insn "<sse2_avx2>_packssdw<mask_name>"
11081   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,v")
11082         (vec_concat:VI2_AVX2
11083           (ss_truncate:<ssehalfvecmode>
11084             (match_operand:<sseunpackmode> 1 "register_operand" "0,v"))
11085           (ss_truncate:<ssehalfvecmode>
11086             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,vm"))))]
11087   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
11088   "@
11089    packssdw\t{%2, %0|%0, %2}
11090    vpackssdw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11091   [(set_attr "isa" "noavx,avx")
11092    (set_attr "type" "sselog")
11093    (set_attr "prefix_data16" "1,*")
11094    (set_attr "prefix" "orig,vex")
11095    (set_attr "mode" "<sseinsnmode>")])
11096
11097 (define_insn "<sse2_avx2>_packuswb<mask_name>"
11098   [(set (match_operand:VI1_AVX512 0 "register_operand" "=x,x")
11099         (vec_concat:VI1_AVX512
11100           (us_truncate:<ssehalfvecmode>
11101             (match_operand:<sseunpackmode> 1 "register_operand" "0,v"))
11102           (us_truncate:<ssehalfvecmode>
11103             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,vm"))))]
11104   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
11105   "@
11106    packuswb\t{%2, %0|%0, %2}
11107    vpackuswb\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11108   [(set_attr "isa" "noavx,avx")
11109    (set_attr "type" "sselog")
11110    (set_attr "prefix_data16" "1,*")
11111    (set_attr "prefix" "orig,vex")
11112    (set_attr "mode" "<sseinsnmode>")])
11113
11114 (define_insn "avx512bw_interleave_highv64qi<mask_name>"
11115   [(set (match_operand:V64QI 0 "register_operand" "=v")
11116         (vec_select:V64QI
11117           (vec_concat:V128QI
11118             (match_operand:V64QI 1 "register_operand" "v")
11119             (match_operand:V64QI 2 "nonimmediate_operand" "vm"))
11120           (parallel [(const_int 8)  (const_int 72)
11121                      (const_int 9)  (const_int 73)
11122                      (const_int 10) (const_int 74)
11123                      (const_int 11) (const_int 75)
11124                      (const_int 12) (const_int 76)
11125                      (const_int 13) (const_int 77)
11126                      (const_int 14) (const_int 78)
11127                      (const_int 15) (const_int 79)
11128                      (const_int 24) (const_int 88)
11129                      (const_int 25) (const_int 89)
11130                      (const_int 26) (const_int 90)
11131                      (const_int 27) (const_int 91)
11132                      (const_int 28) (const_int 92)
11133                      (const_int 29) (const_int 93)
11134                      (const_int 30) (const_int 94)
11135                      (const_int 31) (const_int 95)
11136                      (const_int 40) (const_int 104)
11137                      (const_int 41) (const_int 105)
11138                      (const_int 42) (const_int 106)
11139                      (const_int 43) (const_int 107)
11140                      (const_int 44) (const_int 108)
11141                      (const_int 45) (const_int 109)
11142                      (const_int 46) (const_int 110)
11143                      (const_int 47) (const_int 111)
11144                      (const_int 56) (const_int 120)
11145                      (const_int 57) (const_int 121)
11146                      (const_int 58) (const_int 122)
11147                      (const_int 59) (const_int 123)
11148                      (const_int 60) (const_int 124)
11149                      (const_int 61) (const_int 125)
11150                      (const_int 62) (const_int 126)
11151                      (const_int 63) (const_int 127)])))]
11152   "TARGET_AVX512BW"
11153   "vpunpckhbw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11154   [(set_attr "type" "sselog")
11155    (set_attr "prefix" "evex")
11156    (set_attr "mode" "XI")])
11157
11158 (define_insn "avx2_interleave_highv32qi<mask_name>"
11159   [(set (match_operand:V32QI 0 "register_operand" "=v")
11160         (vec_select:V32QI
11161           (vec_concat:V64QI
11162             (match_operand:V32QI 1 "register_operand" "v")
11163             (match_operand:V32QI 2 "nonimmediate_operand" "vm"))
11164           (parallel [(const_int 8)  (const_int 40)
11165                      (const_int 9)  (const_int 41)
11166                      (const_int 10) (const_int 42)
11167                      (const_int 11) (const_int 43)
11168                      (const_int 12) (const_int 44)
11169                      (const_int 13) (const_int 45)
11170                      (const_int 14) (const_int 46)
11171                      (const_int 15) (const_int 47)
11172                      (const_int 24) (const_int 56)
11173                      (const_int 25) (const_int 57)
11174                      (const_int 26) (const_int 58)
11175                      (const_int 27) (const_int 59)
11176                      (const_int 28) (const_int 60)
11177                      (const_int 29) (const_int 61)
11178                      (const_int 30) (const_int 62)
11179                      (const_int 31) (const_int 63)])))]
11180   "TARGET_AVX2 && <mask_avx512vl_condition>"
11181   "vpunpckhbw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11182   [(set_attr "type" "sselog")
11183    (set_attr "prefix" "<mask_prefix>")
11184    (set_attr "mode" "OI")])
11185
11186 (define_insn "vec_interleave_highv16qi<mask_name>"
11187   [(set (match_operand:V16QI 0 "register_operand" "=x,v")
11188         (vec_select:V16QI
11189           (vec_concat:V32QI
11190             (match_operand:V16QI 1 "register_operand" "0,v")
11191             (match_operand:V16QI 2 "nonimmediate_operand" "xm,vm"))
11192           (parallel [(const_int 8)  (const_int 24)
11193                      (const_int 9)  (const_int 25)
11194                      (const_int 10) (const_int 26)
11195                      (const_int 11) (const_int 27)
11196                      (const_int 12) (const_int 28)
11197                      (const_int 13) (const_int 29)
11198                      (const_int 14) (const_int 30)
11199                      (const_int 15) (const_int 31)])))]
11200   "TARGET_SSE2 && <mask_avx512vl_condition>"
11201   "@
11202    punpckhbw\t{%2, %0|%0, %2}
11203    vpunpckhbw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11204   [(set_attr "isa" "noavx,avx")
11205    (set_attr "type" "sselog")
11206    (set_attr "prefix_data16" "1,*")
11207    (set_attr "prefix" "orig,<mask_prefix>")
11208    (set_attr "mode" "TI")])
11209
11210 (define_insn "avx512bw_interleave_lowv64qi<mask_name>"
11211   [(set (match_operand:V64QI 0 "register_operand" "=v")
11212         (vec_select:V64QI
11213           (vec_concat:V128QI
11214             (match_operand:V64QI 1 "register_operand" "v")
11215             (match_operand:V64QI 2 "nonimmediate_operand" "vm"))
11216           (parallel [(const_int 0) (const_int 64)
11217                      (const_int 1) (const_int 65)
11218                      (const_int 2) (const_int 66)
11219                      (const_int 3) (const_int 67)
11220                      (const_int 4) (const_int 68)
11221                      (const_int 5) (const_int 69)
11222                      (const_int 6) (const_int 70)
11223                      (const_int 7) (const_int 71)
11224                      (const_int 16) (const_int 80)
11225                      (const_int 17) (const_int 81)
11226                      (const_int 18) (const_int 82)
11227                      (const_int 19) (const_int 83)
11228                      (const_int 20) (const_int 84)
11229                      (const_int 21) (const_int 85)
11230                      (const_int 22) (const_int 86)
11231                      (const_int 23) (const_int 87)
11232                      (const_int 32) (const_int 96)
11233                      (const_int 33) (const_int 97)
11234                      (const_int 34) (const_int 98)
11235                      (const_int 35) (const_int 99)
11236                      (const_int 36) (const_int 100)
11237                      (const_int 37) (const_int 101)
11238                      (const_int 38) (const_int 102)
11239                      (const_int 39) (const_int 103)
11240                      (const_int 48) (const_int 112)
11241                      (const_int 49) (const_int 113)
11242                      (const_int 50) (const_int 114)
11243                      (const_int 51) (const_int 115)
11244                      (const_int 52) (const_int 116)
11245                      (const_int 53) (const_int 117)
11246                      (const_int 54) (const_int 118)
11247                      (const_int 55) (const_int 119)])))]
11248   "TARGET_AVX512BW"
11249   "vpunpcklbw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11250   [(set_attr "type" "sselog")
11251    (set_attr "prefix" "evex")
11252    (set_attr "mode" "XI")])
11253
11254 (define_insn "avx2_interleave_lowv32qi<mask_name>"
11255   [(set (match_operand:V32QI 0 "register_operand" "=v")
11256         (vec_select:V32QI
11257           (vec_concat:V64QI
11258             (match_operand:V32QI 1 "register_operand" "v")
11259             (match_operand:V32QI 2 "nonimmediate_operand" "vm"))
11260           (parallel [(const_int 0) (const_int 32)
11261                      (const_int 1) (const_int 33)
11262                      (const_int 2) (const_int 34)
11263                      (const_int 3) (const_int 35)
11264                      (const_int 4) (const_int 36)
11265                      (const_int 5) (const_int 37)
11266                      (const_int 6) (const_int 38)
11267                      (const_int 7) (const_int 39)
11268                      (const_int 16) (const_int 48)
11269                      (const_int 17) (const_int 49)
11270                      (const_int 18) (const_int 50)
11271                      (const_int 19) (const_int 51)
11272                      (const_int 20) (const_int 52)
11273                      (const_int 21) (const_int 53)
11274                      (const_int 22) (const_int 54)
11275                      (const_int 23) (const_int 55)])))]
11276   "TARGET_AVX2 && <mask_avx512vl_condition> && <mask_avx512bw_condition>"
11277   "vpunpcklbw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11278   [(set_attr "type" "sselog")
11279    (set_attr "prefix" "maybe_vex")
11280    (set_attr "mode" "OI")])
11281
11282 (define_insn "vec_interleave_lowv16qi<mask_name>"
11283   [(set (match_operand:V16QI 0 "register_operand" "=x,v")
11284         (vec_select:V16QI
11285           (vec_concat:V32QI
11286             (match_operand:V16QI 1 "register_operand" "0,v")
11287             (match_operand:V16QI 2 "nonimmediate_operand" "xm,vm"))
11288           (parallel [(const_int 0) (const_int 16)
11289                      (const_int 1) (const_int 17)
11290                      (const_int 2) (const_int 18)
11291                      (const_int 3) (const_int 19)
11292                      (const_int 4) (const_int 20)
11293                      (const_int 5) (const_int 21)
11294                      (const_int 6) (const_int 22)
11295                      (const_int 7) (const_int 23)])))]
11296   "TARGET_SSE2 && <mask_avx512vl_condition> && <mask_avx512bw_condition>"
11297   "@
11298    punpcklbw\t{%2, %0|%0, %2}
11299    vpunpcklbw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11300   [(set_attr "isa" "noavx,avx")
11301    (set_attr "type" "sselog")
11302    (set_attr "prefix_data16" "1,*")
11303    (set_attr "prefix" "orig,vex")
11304    (set_attr "mode" "TI")])
11305
11306 (define_insn "avx512bw_interleave_highv32hi<mask_name>"
11307   [(set (match_operand:V32HI 0 "register_operand" "=v")
11308         (vec_select:V32HI
11309           (vec_concat:V64HI
11310             (match_operand:V32HI 1 "register_operand" "v")
11311             (match_operand:V32HI 2 "nonimmediate_operand" "vm"))
11312           (parallel [(const_int 4) (const_int 36)
11313                      (const_int 5) (const_int 37)
11314                      (const_int 6) (const_int 38)
11315                      (const_int 7) (const_int 39)
11316                      (const_int 12) (const_int 44)
11317                      (const_int 13) (const_int 45)
11318                      (const_int 14) (const_int 46)
11319                      (const_int 15) (const_int 47)
11320                      (const_int 20) (const_int 52)
11321                      (const_int 21) (const_int 53)
11322                      (const_int 22) (const_int 54)
11323                      (const_int 23) (const_int 55)
11324                      (const_int 28) (const_int 60)
11325                      (const_int 29) (const_int 61)
11326                      (const_int 30) (const_int 62)
11327                      (const_int 31) (const_int 63)])))]
11328   "TARGET_AVX512BW"
11329   "vpunpckhwd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11330   [(set_attr "type" "sselog")
11331    (set_attr "prefix" "evex")
11332    (set_attr "mode" "XI")])
11333
11334 (define_insn "avx2_interleave_highv16hi<mask_name>"
11335   [(set (match_operand:V16HI 0 "register_operand" "=v")
11336         (vec_select:V16HI
11337           (vec_concat:V32HI
11338             (match_operand:V16HI 1 "register_operand" "v")
11339             (match_operand:V16HI 2 "nonimmediate_operand" "vm"))
11340           (parallel [(const_int 4) (const_int 20)
11341                      (const_int 5) (const_int 21)
11342                      (const_int 6) (const_int 22)
11343                      (const_int 7) (const_int 23)
11344                      (const_int 12) (const_int 28)
11345                      (const_int 13) (const_int 29)
11346                      (const_int 14) (const_int 30)
11347                      (const_int 15) (const_int 31)])))]
11348   "TARGET_AVX2 && <mask_avx512vl_condition> && <mask_avx512bw_condition>"
11349   "vpunpckhwd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11350   [(set_attr "type" "sselog")
11351    (set_attr "prefix" "maybe_evex")
11352    (set_attr "mode" "OI")])
11353
11354 (define_insn "vec_interleave_highv8hi<mask_name>"
11355   [(set (match_operand:V8HI 0 "register_operand" "=x,v")
11356         (vec_select:V8HI
11357           (vec_concat:V16HI
11358             (match_operand:V8HI 1 "register_operand" "0,v")
11359             (match_operand:V8HI 2 "nonimmediate_operand" "xm,vm"))
11360           (parallel [(const_int 4) (const_int 12)
11361                      (const_int 5) (const_int 13)
11362                      (const_int 6) (const_int 14)
11363                      (const_int 7) (const_int 15)])))]
11364   "TARGET_SSE2 && <mask_avx512vl_condition> && <mask_avx512bw_condition>"
11365   "@
11366    punpckhwd\t{%2, %0|%0, %2}
11367    vpunpckhwd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11368   [(set_attr "isa" "noavx,avx")
11369    (set_attr "type" "sselog")
11370    (set_attr "prefix_data16" "1,*")
11371    (set_attr "prefix" "orig,maybe_vex")
11372    (set_attr "mode" "TI")])
11373
11374 (define_insn "<mask_codefor>avx512bw_interleave_lowv32hi<mask_name>"
11375   [(set (match_operand:V32HI 0 "register_operand" "=v")
11376         (vec_select:V32HI
11377           (vec_concat:V64HI
11378             (match_operand:V32HI 1 "register_operand" "v")
11379             (match_operand:V32HI 2 "nonimmediate_operand" "vm"))
11380           (parallel [(const_int 0) (const_int 32)
11381                      (const_int 1) (const_int 33)
11382                      (const_int 2) (const_int 34)
11383                      (const_int 3) (const_int 35)
11384                      (const_int 8) (const_int 40)
11385                      (const_int 9) (const_int 41)
11386                      (const_int 10) (const_int 42)
11387                      (const_int 11) (const_int 43)
11388                      (const_int 16) (const_int 48)
11389                      (const_int 17) (const_int 49)
11390                      (const_int 18) (const_int 50)
11391                      (const_int 19) (const_int 51)
11392                      (const_int 24) (const_int 56)
11393                      (const_int 25) (const_int 57)
11394                      (const_int 26) (const_int 58)
11395                      (const_int 27) (const_int 59)])))]
11396   "TARGET_AVX512BW"
11397   "vpunpcklwd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11398   [(set_attr "type" "sselog")
11399    (set_attr "prefix" "evex")
11400    (set_attr "mode" "XI")])
11401
11402 (define_insn "avx2_interleave_lowv16hi<mask_name>"
11403   [(set (match_operand:V16HI 0 "register_operand" "=v")
11404         (vec_select:V16HI
11405           (vec_concat:V32HI
11406             (match_operand:V16HI 1 "register_operand" "v")
11407             (match_operand:V16HI 2 "nonimmediate_operand" "vm"))
11408           (parallel [(const_int 0) (const_int 16)
11409                      (const_int 1) (const_int 17)
11410                      (const_int 2) (const_int 18)
11411                      (const_int 3) (const_int 19)
11412                      (const_int 8) (const_int 24)
11413                      (const_int 9) (const_int 25)
11414                      (const_int 10) (const_int 26)
11415                      (const_int 11) (const_int 27)])))]
11416   "TARGET_AVX2 && <mask_avx512vl_condition> && <mask_avx512bw_condition>"
11417   "vpunpcklwd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11418   [(set_attr "type" "sselog")
11419    (set_attr "prefix" "maybe_evex")
11420    (set_attr "mode" "OI")])
11421
11422 (define_insn "vec_interleave_lowv8hi<mask_name>"
11423   [(set (match_operand:V8HI 0 "register_operand" "=x,v")
11424         (vec_select:V8HI
11425           (vec_concat:V16HI
11426             (match_operand:V8HI 1 "register_operand" "0,v")
11427             (match_operand:V8HI 2 "nonimmediate_operand" "xm,vm"))
11428           (parallel [(const_int 0) (const_int 8)
11429                      (const_int 1) (const_int 9)
11430                      (const_int 2) (const_int 10)
11431                      (const_int 3) (const_int 11)])))]
11432   "TARGET_SSE2 && <mask_avx512vl_condition> && <mask_avx512bw_condition>"
11433   "@
11434    punpcklwd\t{%2, %0|%0, %2}
11435    vpunpcklwd\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11436   [(set_attr "isa" "noavx,avx")
11437    (set_attr "type" "sselog")
11438    (set_attr "prefix_data16" "1,*")
11439    (set_attr "prefix" "orig,maybe_evex")
11440    (set_attr "mode" "TI")])
11441
11442 (define_insn "avx2_interleave_highv8si<mask_name>"
11443   [(set (match_operand:V8SI 0 "register_operand" "=v")
11444         (vec_select:V8SI
11445           (vec_concat:V16SI
11446             (match_operand:V8SI 1 "register_operand" "v")
11447             (match_operand:V8SI 2 "nonimmediate_operand" "vm"))
11448           (parallel [(const_int 2) (const_int 10)
11449                      (const_int 3) (const_int 11)
11450                      (const_int 6) (const_int 14)
11451                      (const_int 7) (const_int 15)])))]
11452   "TARGET_AVX2 && <mask_avx512vl_condition>"
11453   "vpunpckhdq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11454   [(set_attr "type" "sselog")
11455    (set_attr "prefix" "maybe_evex")
11456    (set_attr "mode" "OI")])
11457
11458 (define_insn "<mask_codefor>avx512f_interleave_highv16si<mask_name>"
11459   [(set (match_operand:V16SI 0 "register_operand" "=v")
11460         (vec_select:V16SI
11461           (vec_concat:V32SI
11462             (match_operand:V16SI 1 "register_operand" "v")
11463             (match_operand:V16SI 2 "nonimmediate_operand" "vm"))
11464           (parallel [(const_int 2) (const_int 18)
11465                      (const_int 3) (const_int 19)
11466                      (const_int 6) (const_int 22)
11467                      (const_int 7) (const_int 23)
11468                      (const_int 10) (const_int 26)
11469                      (const_int 11) (const_int 27)
11470                      (const_int 14) (const_int 30)
11471                      (const_int 15) (const_int 31)])))]
11472   "TARGET_AVX512F"
11473   "vpunpckhdq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11474   [(set_attr "type" "sselog")
11475    (set_attr "prefix" "evex")
11476    (set_attr "mode" "XI")])
11477
11478
11479 (define_insn "vec_interleave_highv4si<mask_name>"
11480   [(set (match_operand:V4SI 0 "register_operand" "=x,v")
11481         (vec_select:V4SI
11482           (vec_concat:V8SI
11483             (match_operand:V4SI 1 "register_operand" "0,v")
11484             (match_operand:V4SI 2 "nonimmediate_operand" "xm,vm"))
11485           (parallel [(const_int 2) (const_int 6)
11486                      (const_int 3) (const_int 7)])))]
11487   "TARGET_SSE2 && <mask_avx512vl_condition>"
11488   "@
11489    punpckhdq\t{%2, %0|%0, %2}
11490    vpunpckhdq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11491   [(set_attr "isa" "noavx,avx")
11492    (set_attr "type" "sselog")
11493    (set_attr "prefix_data16" "1,*")
11494    (set_attr "prefix" "orig,maybe_vex")
11495    (set_attr "mode" "TI")])
11496
11497 (define_insn "avx2_interleave_lowv8si<mask_name>"
11498   [(set (match_operand:V8SI 0 "register_operand" "=v")
11499         (vec_select:V8SI
11500           (vec_concat:V16SI
11501             (match_operand:V8SI 1 "register_operand" "v")
11502             (match_operand:V8SI 2 "nonimmediate_operand" "vm"))
11503           (parallel [(const_int 0) (const_int 8)
11504                      (const_int 1) (const_int 9)
11505                      (const_int 4) (const_int 12)
11506                      (const_int 5) (const_int 13)])))]
11507   "TARGET_AVX2 && <mask_avx512vl_condition>"
11508   "vpunpckldq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11509   [(set_attr "type" "sselog")
11510    (set_attr "prefix" "maybe_evex")
11511    (set_attr "mode" "OI")])
11512
11513 (define_insn "<mask_codefor>avx512f_interleave_lowv16si<mask_name>"
11514   [(set (match_operand:V16SI 0 "register_operand" "=v")
11515         (vec_select:V16SI
11516           (vec_concat:V32SI
11517             (match_operand:V16SI 1 "register_operand" "v")
11518             (match_operand:V16SI 2 "nonimmediate_operand" "vm"))
11519           (parallel [(const_int 0) (const_int 16)
11520                      (const_int 1) (const_int 17)
11521                      (const_int 4) (const_int 20)
11522                      (const_int 5) (const_int 21)
11523                      (const_int 8) (const_int 24)
11524                      (const_int 9) (const_int 25)
11525                      (const_int 12) (const_int 28)
11526                      (const_int 13) (const_int 29)])))]
11527   "TARGET_AVX512F"
11528   "vpunpckldq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11529   [(set_attr "type" "sselog")
11530    (set_attr "prefix" "evex")
11531    (set_attr "mode" "XI")])
11532
11533 (define_insn "vec_interleave_lowv4si<mask_name>"
11534   [(set (match_operand:V4SI 0 "register_operand" "=x,v")
11535         (vec_select:V4SI
11536           (vec_concat:V8SI
11537             (match_operand:V4SI 1 "register_operand" "0,v")
11538             (match_operand:V4SI 2 "nonimmediate_operand" "xm,vm"))
11539           (parallel [(const_int 0) (const_int 4)
11540                      (const_int 1) (const_int 5)])))]
11541   "TARGET_SSE2 && <mask_avx512vl_condition>"
11542   "@
11543    punpckldq\t{%2, %0|%0, %2}
11544    vpunpckldq\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
11545   [(set_attr "isa" "noavx,avx")
11546    (set_attr "type" "sselog")
11547    (set_attr "prefix_data16" "1,*")
11548    (set_attr "prefix" "orig,vex")
11549    (set_attr "mode" "TI")])
11550
11551 (define_expand "vec_interleave_high<mode>"
11552   [(match_operand:VI_256 0 "register_operand" "=x")
11553    (match_operand:VI_256 1 "register_operand" "x")
11554    (match_operand:VI_256 2 "nonimmediate_operand" "xm")]
11555  "TARGET_AVX2"
11556 {
11557   rtx t1 = gen_reg_rtx (<MODE>mode);
11558   rtx t2 = gen_reg_rtx (<MODE>mode);
11559   rtx t3 = gen_reg_rtx (V4DImode);
11560   emit_insn (gen_avx2_interleave_low<mode> (t1, operands[1], operands[2]));
11561   emit_insn (gen_avx2_interleave_high<mode> (t2,  operands[1], operands[2]));
11562   emit_insn (gen_avx2_permv2ti (t3, gen_lowpart (V4DImode, t1),
11563                                 gen_lowpart (V4DImode, t2),
11564                                 GEN_INT (1 + (3 << 4))));
11565   emit_move_insn (operands[0], gen_lowpart (<MODE>mode, t3));
11566   DONE;
11567 })
11568
11569 (define_expand "vec_interleave_low<mode>"
11570   [(match_operand:VI_256 0 "register_operand" "=x")
11571    (match_operand:VI_256 1 "register_operand" "x")
11572    (match_operand:VI_256 2 "nonimmediate_operand" "xm")]
11573  "TARGET_AVX2"
11574 {
11575   rtx t1 = gen_reg_rtx (<MODE>mode);
11576   rtx t2 = gen_reg_rtx (<MODE>mode);
11577   rtx t3 = gen_reg_rtx (V4DImode);
11578   emit_insn (gen_avx2_interleave_low<mode> (t1, operands[1], operands[2]));
11579   emit_insn (gen_avx2_interleave_high<mode> (t2, operands[1], operands[2]));
11580   emit_insn (gen_avx2_permv2ti (t3, gen_lowpart (V4DImode, t1),
11581                                 gen_lowpart (V4DImode, t2),
11582                                 GEN_INT (0 + (2 << 4))));
11583   emit_move_insn (operands[0], gen_lowpart (<MODE>mode, t3));
11584   DONE;
11585 })
11586
11587 ;; Modes handled by pinsr patterns.
11588 (define_mode_iterator PINSR_MODE
11589   [(V16QI "TARGET_SSE4_1") V8HI
11590    (V4SI "TARGET_SSE4_1")
11591    (V2DI "TARGET_SSE4_1 && TARGET_64BIT")])
11592
11593 (define_mode_attr sse2p4_1
11594   [(V16QI "sse4_1") (V8HI "sse2")
11595    (V4SI "sse4_1") (V2DI "sse4_1")])
11596
11597 ;; sse4_1_pinsrd must come before sse2_loadld since it is preferred.
11598 (define_insn "<sse2p4_1>_pinsr<ssemodesuffix>"
11599   [(set (match_operand:PINSR_MODE 0 "register_operand" "=x,x,x,x")
11600         (vec_merge:PINSR_MODE
11601           (vec_duplicate:PINSR_MODE
11602             (match_operand:<ssescalarmode> 2 "nonimmediate_operand" "r,m,r,m"))
11603           (match_operand:PINSR_MODE 1 "register_operand" "0,0,x,x")
11604           (match_operand:SI 3 "const_int_operand")))]
11605   "TARGET_SSE2
11606    && ((unsigned) exact_log2 (INTVAL (operands[3]))
11607        < GET_MODE_NUNITS (<MODE>mode))"
11608 {
11609   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
11610
11611   switch (which_alternative)
11612     {
11613     case 0:
11614       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
11615         return "pinsr<ssemodesuffix>\t{%3, %k2, %0|%0, %k2, %3}";
11616       /* FALLTHRU */
11617     case 1:
11618       return "pinsr<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}";
11619     case 2:
11620       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
11621         return "vpinsr<ssemodesuffix>\t{%3, %k2, %1, %0|%0, %1, %k2, %3}";
11622       /* FALLTHRU */
11623     case 3:
11624       return "vpinsr<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}";
11625     default:
11626       gcc_unreachable ();
11627     }
11628 }
11629   [(set_attr "isa" "noavx,noavx,avx,avx")
11630    (set_attr "type" "sselog")
11631    (set (attr "prefix_rex")
11632      (if_then_else
11633        (and (not (match_test "TARGET_AVX"))
11634             (eq (const_string "<MODE>mode") (const_string "V2DImode")))
11635        (const_string "1")
11636        (const_string "*")))
11637    (set (attr "prefix_data16")
11638      (if_then_else
11639        (and (not (match_test "TARGET_AVX"))
11640             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
11641        (const_string "1")
11642        (const_string "*")))
11643    (set (attr "prefix_extra")
11644      (if_then_else
11645        (and (not (match_test "TARGET_AVX"))
11646             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
11647        (const_string "*")
11648        (const_string "1")))
11649    (set_attr "length_immediate" "1")
11650    (set_attr "prefix" "orig,orig,vex,vex")
11651    (set_attr "mode" "TI")])
11652
11653 (define_expand "<extract_type>_vinsert<shuffletype><extract_suf>_mask"
11654   [(match_operand:AVX512_VEC 0 "register_operand")
11655    (match_operand:AVX512_VEC 1 "register_operand")
11656    (match_operand:<ssequartermode> 2 "nonimmediate_operand")
11657    (match_operand:SI 3 "const_0_to_3_operand")
11658    (match_operand:AVX512_VEC 4 "register_operand")
11659    (match_operand:<avx512fmaskmode> 5 "register_operand")]
11660   "TARGET_AVX512F"
11661 {
11662   int mask,selector;
11663   mask = INTVAL (operands[3]);
11664   selector = GET_MODE_SIZE (GET_MODE_INNER (<MODE>mode)) == 4 ?
11665     0xFFFF ^ (0xF000 >> mask * 4)
11666     : 0xFF ^ (0xC0 >> mask * 2);
11667   emit_insn (gen_<extract_type>_vinsert<shuffletype><extract_suf>_1_mask
11668     (operands[0], operands[1], operands[2], GEN_INT (selector),
11669      operands[4], operands[5]));
11670   DONE;
11671 })
11672
11673 (define_insn "<mask_codefor><extract_type>_vinsert<shuffletype><extract_suf>_1<mask_name>"
11674   [(set (match_operand:AVX512_VEC 0 "register_operand" "=v")
11675         (vec_merge:AVX512_VEC
11676           (match_operand:AVX512_VEC 1 "register_operand" "v")
11677           (vec_duplicate:AVX512_VEC
11678                 (match_operand:<ssequartermode> 2 "nonimmediate_operand" "vm"))
11679           (match_operand:SI 3 "const_int_operand" "n")))]
11680   "TARGET_AVX512F"
11681 {
11682   int mask;
11683   int selector = INTVAL (operands[3]);
11684
11685   if (selector == 0xFFF || selector == 0x3F)
11686     mask = 0;
11687   else if ( selector == 0xF0FF || selector == 0xCF)
11688     mask = 1;
11689   else if ( selector == 0xFF0F || selector == 0xF3)
11690     mask = 2;
11691   else if ( selector == 0xFFF0 || selector == 0xFC)
11692     mask = 3;
11693   else
11694       gcc_unreachable ();
11695
11696   operands[3] = GEN_INT (mask);
11697
11698   return "vinsert<shuffletype><extract_suf>\t{%3, %2, %1, %0<mask_operand4>|%0<mask_operand4>, %1, %2, %3}";
11699 }
11700   [(set_attr "type" "sselog")
11701    (set_attr "length_immediate" "1")
11702    (set_attr "prefix" "evex")
11703    (set_attr "mode" "<sseinsnmode>")])
11704
11705 (define_expand "<extract_type_2>_vinsert<shuffletype><extract_suf_2>_mask"
11706   [(match_operand:AVX512_VEC_2 0 "register_operand")
11707    (match_operand:AVX512_VEC_2 1 "register_operand")
11708    (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand")
11709    (match_operand:SI 3 "const_0_to_1_operand")
11710    (match_operand:AVX512_VEC_2 4 "register_operand")
11711    (match_operand:<avx512fmaskmode> 5 "register_operand")]
11712   "TARGET_AVX512F"
11713 {
11714   int mask = INTVAL (operands[3]);
11715   if (mask == 0)
11716     emit_insn (gen_vec_set_lo_<mode>_mask
11717       (operands[0], operands[1], operands[2],
11718        operands[4], operands[5]));
11719   else
11720     emit_insn (gen_vec_set_hi_<mode>_mask
11721       (operands[0], operands[1], operands[2],
11722        operands[4], operands[5]));
11723   DONE;
11724 })
11725
11726 (define_insn "vec_set_lo_<mode><mask_name>"
11727   [(set (match_operand:V16FI 0 "register_operand" "=v")
11728         (vec_concat:V16FI
11729           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "vm")
11730           (vec_select:<ssehalfvecmode>
11731             (match_operand:V16FI 1 "register_operand" "v")
11732             (parallel [(const_int 8) (const_int 9)
11733               (const_int 10) (const_int 11)
11734               (const_int 12) (const_int 13)
11735               (const_int 14) (const_int 15)]))))]
11736   "TARGET_AVX512DQ"
11737   "vinsert<shuffletype>32x8\t{$0x0, %2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2, $0x0}"
11738   [(set_attr "type" "sselog")
11739    (set_attr "length_immediate" "1")
11740    (set_attr "prefix" "evex")
11741    (set_attr "mode" "<sseinsnmode>")])
11742
11743 (define_insn "vec_set_hi_<mode><mask_name>"
11744   [(set (match_operand:V16FI 0 "register_operand" "=v")
11745         (vec_concat:V16FI
11746           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "vm")
11747           (vec_select:<ssehalfvecmode>
11748             (match_operand:V16FI 1 "register_operand" "v")
11749             (parallel [(const_int 0) (const_int 1)
11750               (const_int 2) (const_int 3)
11751               (const_int 4) (const_int 5)
11752               (const_int 6) (const_int 7)]))))]
11753   "TARGET_AVX512DQ"
11754   "vinsert<shuffletype>32x8\t{$0x1, %2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2, $0x1}"
11755   [(set_attr "type" "sselog")
11756    (set_attr "length_immediate" "1")
11757    (set_attr "prefix" "evex")
11758    (set_attr "mode" "<sseinsnmode>")])
11759
11760 (define_insn "vec_set_lo_<mode><mask_name>"
11761   [(set (match_operand:V8FI 0 "register_operand" "=v")
11762         (vec_concat:V8FI
11763           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "vm")
11764           (vec_select:<ssehalfvecmode>
11765             (match_operand:V8FI 1 "register_operand" "v")
11766             (parallel [(const_int 4) (const_int 5)
11767               (const_int 6) (const_int 7)]))))]
11768   "TARGET_AVX512F"
11769   "vinsert<shuffletype>64x4\t{$0x0, %2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2, $0x0}"
11770   [(set_attr "type" "sselog")
11771    (set_attr "length_immediate" "1")
11772    (set_attr "prefix" "evex")
11773    (set_attr "mode" "XI")])
11774
11775 (define_insn "vec_set_hi_<mode><mask_name>"
11776   [(set (match_operand:V8FI 0 "register_operand" "=v")
11777         (vec_concat:V8FI
11778           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "vm")
11779           (vec_select:<ssehalfvecmode>
11780             (match_operand:V8FI 1 "register_operand" "v")
11781             (parallel [(const_int 0) (const_int 1)
11782               (const_int 2) (const_int 3)]))))]
11783   "TARGET_AVX512F"
11784   "vinsert<shuffletype>64x4\t{$0x1, %2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2, $0x1}"
11785   [(set_attr "type" "sselog")
11786    (set_attr "length_immediate" "1")
11787    (set_attr "prefix" "evex")
11788    (set_attr "mode" "XI")])
11789
11790 (define_expand "avx512dq_shuf_<shuffletype>64x2_mask"
11791   [(match_operand:VI8F_256 0 "register_operand")
11792    (match_operand:VI8F_256 1 "register_operand")
11793    (match_operand:VI8F_256 2 "nonimmediate_operand")
11794    (match_operand:SI 3 "const_0_to_3_operand")
11795    (match_operand:VI8F_256 4 "register_operand")
11796    (match_operand:QI 5 "register_operand")]
11797   "TARGET_AVX512DQ"
11798 {
11799   int mask = INTVAL (operands[3]);
11800   emit_insn (gen_avx512dq_shuf_<shuffletype>64x2_1_mask
11801       (operands[0], operands[1], operands[2],
11802        GEN_INT (((mask >> 0) & 1) * 2 + 0),
11803        GEN_INT (((mask >> 0) & 1) * 2 + 1),
11804        GEN_INT (((mask >> 1) & 1) * 2 + 4),
11805        GEN_INT (((mask >> 1) & 1) * 2 + 5),
11806        operands[4], operands[5]));
11807   DONE;
11808 })
11809
11810 (define_insn "<mask_codefor>avx512dq_shuf_<shuffletype>64x2_1<mask_name>"
11811   [(set (match_operand:VI8F_256 0 "register_operand" "=v")
11812         (vec_select:VI8F_256
11813           (vec_concat:<ssedoublemode>
11814             (match_operand:VI8F_256 1 "register_operand" "v")
11815             (match_operand:VI8F_256 2 "nonimmediate_operand" "vm"))
11816           (parallel [(match_operand 3  "const_0_to_3_operand")
11817                      (match_operand 4  "const_0_to_3_operand")
11818                      (match_operand 5  "const_4_to_7_operand")
11819                      (match_operand 6  "const_4_to_7_operand")])))]
11820   "TARGET_AVX512VL
11821    && (INTVAL (operands[3]) == (INTVAL (operands[4]) - 1)
11822        && INTVAL (operands[5]) == (INTVAL (operands[6]) - 1))"
11823 {
11824   int mask;
11825   mask = INTVAL (operands[3]) / 2;
11826   mask |= (INTVAL (operands[5]) - 4) / 2 << 1;
11827   operands[3] = GEN_INT (mask);
11828   return "vshuf<shuffletype>64x2\t{%3, %2, %1, %0<mask_operand7>|%0<mask_operand7>, %1, %2, %3}";
11829 }
11830   [(set_attr "type" "sselog")
11831    (set_attr "length_immediate" "1")
11832    (set_attr "prefix" "evex")
11833    (set_attr "mode" "XI")])
11834
11835 (define_expand "avx512f_shuf_<shuffletype>64x2_mask"
11836   [(match_operand:V8FI 0 "register_operand")
11837    (match_operand:V8FI 1 "register_operand")
11838    (match_operand:V8FI 2 "nonimmediate_operand")
11839    (match_operand:SI 3 "const_0_to_255_operand")
11840    (match_operand:V8FI 4 "register_operand")
11841    (match_operand:QI 5 "register_operand")]
11842   "TARGET_AVX512F"
11843 {
11844   int mask = INTVAL (operands[3]);
11845   emit_insn (gen_avx512f_shuf_<shuffletype>64x2_1_mask
11846       (operands[0], operands[1], operands[2],
11847        GEN_INT (((mask >> 0) & 3) * 2),
11848        GEN_INT (((mask >> 0) & 3) * 2 + 1),
11849        GEN_INT (((mask >> 2) & 3) * 2),
11850        GEN_INT (((mask >> 2) & 3) * 2 + 1),
11851        GEN_INT (((mask >> 4) & 3) * 2 + 8),
11852        GEN_INT (((mask >> 4) & 3) * 2 + 9),
11853        GEN_INT (((mask >> 6) & 3) * 2 + 8),
11854        GEN_INT (((mask >> 6) & 3) * 2 + 9),
11855        operands[4], operands[5]));
11856   DONE;
11857 })
11858
11859 (define_insn "avx512f_shuf_<shuffletype>64x2_1<mask_name>"
11860   [(set (match_operand:V8FI 0 "register_operand" "=v")
11861         (vec_select:V8FI
11862           (vec_concat:<ssedoublemode>
11863             (match_operand:V8FI 1 "register_operand" "v")
11864             (match_operand:V8FI 2 "nonimmediate_operand" "vm"))
11865           (parallel [(match_operand 3  "const_0_to_7_operand")
11866                      (match_operand 4  "const_0_to_7_operand")
11867                      (match_operand 5  "const_0_to_7_operand")
11868                      (match_operand 6  "const_0_to_7_operand")
11869                      (match_operand 7  "const_8_to_15_operand")
11870                      (match_operand 8  "const_8_to_15_operand")
11871                      (match_operand 9  "const_8_to_15_operand")
11872                      (match_operand 10  "const_8_to_15_operand")])))]
11873   "TARGET_AVX512F
11874    && (INTVAL (operands[3]) == (INTVAL (operands[4]) - 1)
11875        && INTVAL (operands[5]) == (INTVAL (operands[6]) - 1)
11876        && INTVAL (operands[7]) == (INTVAL (operands[8]) - 1)
11877        && INTVAL (operands[9]) == (INTVAL (operands[10]) - 1))"
11878 {
11879   int mask;
11880   mask = INTVAL (operands[3]) / 2;
11881   mask |= INTVAL (operands[5]) / 2 << 2;
11882   mask |= (INTVAL (operands[7]) - 8) / 2 << 4;
11883   mask |= (INTVAL (operands[9]) - 8) / 2 << 6;
11884   operands[3] = GEN_INT (mask);
11885
11886   return "vshuf<shuffletype>64x2\t{%3, %2, %1, %0<mask_operand11>|%0<mask_operand11>, %1, %2, %3}";
11887 }
11888   [(set_attr "type" "sselog")
11889    (set_attr "length_immediate" "1")
11890    (set_attr "prefix" "evex")
11891    (set_attr "mode" "<sseinsnmode>")])
11892
11893 (define_expand "avx512vl_shuf_<shuffletype>32x4_mask"
11894   [(match_operand:VI4F_256 0 "register_operand")
11895    (match_operand:VI4F_256 1 "register_operand")
11896    (match_operand:VI4F_256 2 "nonimmediate_operand")
11897    (match_operand:SI 3 "const_0_to_3_operand")
11898    (match_operand:VI4F_256 4 "register_operand")
11899    (match_operand:QI 5 "register_operand")]
11900   "TARGET_AVX512VL"
11901 {
11902   int mask = INTVAL (operands[3]);
11903   emit_insn (gen_avx512vl_shuf_<shuffletype>32x4_1_mask
11904       (operands[0], operands[1], operands[2],
11905        GEN_INT (((mask >> 0) & 1) * 4 + 0),
11906        GEN_INT (((mask >> 0) & 1) * 4 + 1),
11907        GEN_INT (((mask >> 0) & 1) * 4 + 2),
11908        GEN_INT (((mask >> 0) & 1) * 4 + 3),
11909        GEN_INT (((mask >> 1) & 1) * 4 + 8),
11910        GEN_INT (((mask >> 1) & 1) * 4 + 9),
11911        GEN_INT (((mask >> 1) & 1) * 4 + 10),
11912        GEN_INT (((mask >> 1) & 1) * 4 + 11),
11913        operands[4], operands[5]));
11914   DONE;
11915 })
11916
11917 (define_insn "<mask_codefor>avx512vl_shuf_<shuffletype>32x4_1<mask_name>"
11918   [(set (match_operand:VI4F_256 0 "register_operand" "=v")
11919         (vec_select:VI4F_256
11920           (vec_concat:<ssedoublemode>
11921             (match_operand:VI4F_256 1 "register_operand" "v")
11922             (match_operand:VI4F_256 2 "nonimmediate_operand" "vm"))
11923           (parallel [(match_operand 3  "const_0_to_7_operand")
11924                      (match_operand 4  "const_0_to_7_operand")
11925                      (match_operand 5  "const_0_to_7_operand")
11926                      (match_operand 6  "const_0_to_7_operand")
11927                      (match_operand 7  "const_8_to_15_operand")
11928                      (match_operand 8  "const_8_to_15_operand")
11929                      (match_operand 9  "const_8_to_15_operand")
11930                      (match_operand 10 "const_8_to_15_operand")])))]
11931   "TARGET_AVX512VL
11932    && (INTVAL (operands[3]) == (INTVAL (operands[4]) - 1)
11933        && INTVAL (operands[3]) == (INTVAL (operands[5]) - 2)
11934        && INTVAL (operands[3]) == (INTVAL (operands[6]) - 3)
11935        && INTVAL (operands[7]) == (INTVAL (operands[8]) - 1)
11936        && INTVAL (operands[7]) == (INTVAL (operands[9]) - 2)
11937        && INTVAL (operands[7]) == (INTVAL (operands[10]) - 3))"
11938 {
11939   int mask;
11940   mask = INTVAL (operands[3]) / 4;
11941   mask |= (INTVAL (operands[7]) - 8) / 4 << 1;
11942   operands[3] = GEN_INT (mask);
11943
11944   return "vshuf<shuffletype>32x4\t{%3, %2, %1, %0<mask_operand11>|%0<mask_operand11>, %1, %2, %3}";
11945 }
11946   [(set_attr "type" "sselog")
11947    (set_attr "length_immediate" "1")
11948    (set_attr "prefix" "evex")
11949    (set_attr "mode" "<sseinsnmode>")])
11950
11951 (define_expand "avx512f_shuf_<shuffletype>32x4_mask"
11952   [(match_operand:V16FI 0 "register_operand")
11953    (match_operand:V16FI 1 "register_operand")
11954    (match_operand:V16FI 2 "nonimmediate_operand")
11955    (match_operand:SI 3 "const_0_to_255_operand")
11956    (match_operand:V16FI 4 "register_operand")
11957    (match_operand:HI 5 "register_operand")]
11958   "TARGET_AVX512F"
11959 {
11960   int mask = INTVAL (operands[3]);
11961   emit_insn (gen_avx512f_shuf_<shuffletype>32x4_1_mask
11962       (operands[0], operands[1], operands[2],
11963        GEN_INT (((mask >> 0) & 3) * 4),
11964        GEN_INT (((mask >> 0) & 3) * 4 + 1),
11965        GEN_INT (((mask >> 0) & 3) * 4 + 2),
11966        GEN_INT (((mask >> 0) & 3) * 4 + 3),
11967        GEN_INT (((mask >> 2) & 3) * 4),
11968        GEN_INT (((mask >> 2) & 3) * 4 + 1),
11969        GEN_INT (((mask >> 2) & 3) * 4 + 2),
11970        GEN_INT (((mask >> 2) & 3) * 4 + 3),
11971        GEN_INT (((mask >> 4) & 3) * 4 + 16),
11972        GEN_INT (((mask >> 4) & 3) * 4 + 17),
11973        GEN_INT (((mask >> 4) & 3) * 4 + 18),
11974        GEN_INT (((mask >> 4) & 3) * 4 + 19),
11975        GEN_INT (((mask >> 6) & 3) * 4 + 16),
11976        GEN_INT (((mask >> 6) & 3) * 4 + 17),
11977        GEN_INT (((mask >> 6) & 3) * 4 + 18),
11978        GEN_INT (((mask >> 6) & 3) * 4 + 19),
11979        operands[4], operands[5]));
11980   DONE;
11981 })
11982
11983 (define_insn "avx512f_shuf_<shuffletype>32x4_1<mask_name>"
11984   [(set (match_operand:V16FI 0 "register_operand" "=v")
11985         (vec_select:V16FI
11986           (vec_concat:<ssedoublemode>
11987             (match_operand:V16FI 1 "register_operand" "v")
11988             (match_operand:V16FI 2 "nonimmediate_operand" "vm"))
11989           (parallel [(match_operand 3  "const_0_to_15_operand")
11990                      (match_operand 4  "const_0_to_15_operand")
11991                      (match_operand 5  "const_0_to_15_operand")
11992                      (match_operand 6  "const_0_to_15_operand")
11993                      (match_operand 7  "const_0_to_15_operand")
11994                      (match_operand 8  "const_0_to_15_operand")
11995                      (match_operand 9  "const_0_to_15_operand")
11996                      (match_operand 10  "const_0_to_15_operand")
11997                      (match_operand 11  "const_16_to_31_operand")
11998                      (match_operand 12  "const_16_to_31_operand")
11999                      (match_operand 13  "const_16_to_31_operand")
12000                      (match_operand 14  "const_16_to_31_operand")
12001                      (match_operand 15  "const_16_to_31_operand")
12002                      (match_operand 16  "const_16_to_31_operand")
12003                      (match_operand 17  "const_16_to_31_operand")
12004                      (match_operand 18  "const_16_to_31_operand")])))]
12005   "TARGET_AVX512F
12006    && (INTVAL (operands[3]) == (INTVAL (operands[4]) - 1)
12007        && INTVAL (operands[3]) == (INTVAL (operands[5]) - 2)
12008        && INTVAL (operands[3]) == (INTVAL (operands[6]) - 3)
12009        && INTVAL (operands[7]) == (INTVAL (operands[8]) - 1)
12010        && INTVAL (operands[7]) == (INTVAL (operands[9]) - 2)
12011        && INTVAL (operands[7]) == (INTVAL (operands[10]) - 3)
12012        && INTVAL (operands[11]) == (INTVAL (operands[12]) - 1)
12013        && INTVAL (operands[11]) == (INTVAL (operands[13]) - 2)
12014        && INTVAL (operands[11]) == (INTVAL (operands[14]) - 3)
12015        && INTVAL (operands[15]) == (INTVAL (operands[16]) - 1)
12016        && INTVAL (operands[15]) == (INTVAL (operands[17]) - 2)
12017        && INTVAL (operands[15]) == (INTVAL (operands[18]) - 3))"
12018 {
12019   int mask;
12020   mask = INTVAL (operands[3]) / 4;
12021   mask |= INTVAL (operands[7]) / 4 << 2;
12022   mask |= (INTVAL (operands[11]) - 16) / 4 << 4;
12023   mask |= (INTVAL (operands[15]) - 16) / 4 << 6;
12024   operands[3] = GEN_INT (mask);
12025
12026   return "vshuf<shuffletype>32x4\t{%3, %2, %1, %0<mask_operand19>|%0<mask_operand19>, %1, %2, %3}";
12027 }
12028   [(set_attr "type" "sselog")
12029    (set_attr "length_immediate" "1")
12030    (set_attr "prefix" "evex")
12031    (set_attr "mode" "<sseinsnmode>")])
12032
12033 (define_expand "avx512f_pshufdv3_mask"
12034   [(match_operand:V16SI 0 "register_operand")
12035    (match_operand:V16SI 1 "nonimmediate_operand")
12036    (match_operand:SI 2 "const_0_to_255_operand")
12037    (match_operand:V16SI 3 "register_operand")
12038    (match_operand:HI 4 "register_operand")]
12039   "TARGET_AVX512F"
12040 {
12041   int mask = INTVAL (operands[2]);
12042   emit_insn (gen_avx512f_pshufd_1_mask (operands[0], operands[1],
12043                                        GEN_INT ((mask >> 0) & 3),
12044                                        GEN_INT ((mask >> 2) & 3),
12045                                        GEN_INT ((mask >> 4) & 3),
12046                                        GEN_INT ((mask >> 6) & 3),
12047                                        GEN_INT (((mask >> 0) & 3) + 4),
12048                                        GEN_INT (((mask >> 2) & 3) + 4),
12049                                        GEN_INT (((mask >> 4) & 3) + 4),
12050                                        GEN_INT (((mask >> 6) & 3) + 4),
12051                                        GEN_INT (((mask >> 0) & 3) + 8),
12052                                        GEN_INT (((mask >> 2) & 3) + 8),
12053                                        GEN_INT (((mask >> 4) & 3) + 8),
12054                                        GEN_INT (((mask >> 6) & 3) + 8),
12055                                        GEN_INT (((mask >> 0) & 3) + 12),
12056                                        GEN_INT (((mask >> 2) & 3) + 12),
12057                                        GEN_INT (((mask >> 4) & 3) + 12),
12058                                        GEN_INT (((mask >> 6) & 3) + 12),
12059                                        operands[3], operands[4]));
12060   DONE;
12061 })
12062
12063 (define_insn "avx512f_pshufd_1<mask_name>"
12064   [(set (match_operand:V16SI 0 "register_operand" "=v")
12065         (vec_select:V16SI
12066           (match_operand:V16SI 1 "nonimmediate_operand" "vm")
12067           (parallel [(match_operand 2 "const_0_to_3_operand")
12068                      (match_operand 3 "const_0_to_3_operand")
12069                      (match_operand 4 "const_0_to_3_operand")
12070                      (match_operand 5 "const_0_to_3_operand")
12071                      (match_operand 6 "const_4_to_7_operand")
12072                      (match_operand 7 "const_4_to_7_operand")
12073                      (match_operand 8 "const_4_to_7_operand")
12074                      (match_operand 9 "const_4_to_7_operand")
12075                      (match_operand 10 "const_8_to_11_operand")
12076                      (match_operand 11 "const_8_to_11_operand")
12077                      (match_operand 12 "const_8_to_11_operand")
12078                      (match_operand 13 "const_8_to_11_operand")
12079                      (match_operand 14 "const_12_to_15_operand")
12080                      (match_operand 15 "const_12_to_15_operand")
12081                      (match_operand 16 "const_12_to_15_operand")
12082                      (match_operand 17 "const_12_to_15_operand")])))]
12083   "TARGET_AVX512F
12084    && INTVAL (operands[2]) + 4 == INTVAL (operands[6])
12085    && INTVAL (operands[3]) + 4 == INTVAL (operands[7])
12086    && INTVAL (operands[4]) + 4 == INTVAL (operands[8])
12087    && INTVAL (operands[5]) + 4 == INTVAL (operands[9])
12088    && INTVAL (operands[2]) + 8 == INTVAL (operands[10])
12089    && INTVAL (operands[3]) + 8 == INTVAL (operands[11])
12090    && INTVAL (operands[4]) + 8 == INTVAL (operands[12])
12091    && INTVAL (operands[5]) + 8 == INTVAL (operands[13])
12092    && INTVAL (operands[2]) + 12 == INTVAL (operands[14])
12093    && INTVAL (operands[3]) + 12 == INTVAL (operands[15])
12094    && INTVAL (operands[4]) + 12 == INTVAL (operands[16])
12095    && INTVAL (operands[5]) + 12 == INTVAL (operands[17])"
12096 {
12097   int mask = 0;
12098   mask |= INTVAL (operands[2]) << 0;
12099   mask |= INTVAL (operands[3]) << 2;
12100   mask |= INTVAL (operands[4]) << 4;
12101   mask |= INTVAL (operands[5]) << 6;
12102   operands[2] = GEN_INT (mask);
12103
12104   return "vpshufd\t{%2, %1, %0<mask_operand18>|%0<mask_operand18>, %1, %2}";
12105 }
12106   [(set_attr "type" "sselog1")
12107    (set_attr "prefix" "evex")
12108    (set_attr "length_immediate" "1")
12109    (set_attr "mode" "XI")])
12110
12111 (define_expand "avx512vl_pshufdv3_mask"
12112   [(match_operand:V8SI 0 "register_operand")
12113    (match_operand:V8SI 1 "nonimmediate_operand")
12114    (match_operand:SI 2 "const_0_to_255_operand")
12115    (match_operand:V8SI 3 "register_operand")
12116    (match_operand:QI 4 "register_operand")]
12117   "TARGET_AVX512VL"
12118 {
12119   int mask = INTVAL (operands[2]);
12120   emit_insn (gen_avx2_pshufd_1_mask (operands[0], operands[1],
12121                                 GEN_INT ((mask >> 0) & 3),
12122                                 GEN_INT ((mask >> 2) & 3),
12123                                 GEN_INT ((mask >> 4) & 3),
12124                                 GEN_INT ((mask >> 6) & 3),
12125                                 GEN_INT (((mask >> 0) & 3) + 4),
12126                                 GEN_INT (((mask >> 2) & 3) + 4),
12127                                 GEN_INT (((mask >> 4) & 3) + 4),
12128                                 GEN_INT (((mask >> 6) & 3) + 4),
12129                 operands[3], operands[4]));
12130   DONE;
12131 })
12132
12133 (define_expand "avx2_pshufdv3"
12134   [(match_operand:V8SI 0 "register_operand")
12135    (match_operand:V8SI 1 "nonimmediate_operand")
12136    (match_operand:SI 2 "const_0_to_255_operand")]
12137   "TARGET_AVX2"
12138 {
12139   int mask = INTVAL (operands[2]);
12140   emit_insn (gen_avx2_pshufd_1 (operands[0], operands[1],
12141                                 GEN_INT ((mask >> 0) & 3),
12142                                 GEN_INT ((mask >> 2) & 3),
12143                                 GEN_INT ((mask >> 4) & 3),
12144                                 GEN_INT ((mask >> 6) & 3),
12145                                 GEN_INT (((mask >> 0) & 3) + 4),
12146                                 GEN_INT (((mask >> 2) & 3) + 4),
12147                                 GEN_INT (((mask >> 4) & 3) + 4),
12148                                 GEN_INT (((mask >> 6) & 3) + 4)));
12149   DONE;
12150 })
12151
12152 (define_insn "avx2_pshufd_1<mask_name>"
12153   [(set (match_operand:V8SI 0 "register_operand" "=v")
12154         (vec_select:V8SI
12155           (match_operand:V8SI 1 "nonimmediate_operand" "vm")
12156           (parallel [(match_operand 2 "const_0_to_3_operand")
12157                      (match_operand 3 "const_0_to_3_operand")
12158                      (match_operand 4 "const_0_to_3_operand")
12159                      (match_operand 5 "const_0_to_3_operand")
12160                      (match_operand 6 "const_4_to_7_operand")
12161                      (match_operand 7 "const_4_to_7_operand")
12162                      (match_operand 8 "const_4_to_7_operand")
12163                      (match_operand 9 "const_4_to_7_operand")])))]
12164   "TARGET_AVX2
12165    && <mask_avx512vl_condition>
12166    && INTVAL (operands[2]) + 4 == INTVAL (operands[6])
12167    && INTVAL (operands[3]) + 4 == INTVAL (operands[7])
12168    && INTVAL (operands[4]) + 4 == INTVAL (operands[8])
12169    && INTVAL (operands[5]) + 4 == INTVAL (operands[9])"
12170 {
12171   int mask = 0;
12172   mask |= INTVAL (operands[2]) << 0;
12173   mask |= INTVAL (operands[3]) << 2;
12174   mask |= INTVAL (operands[4]) << 4;
12175   mask |= INTVAL (operands[5]) << 6;
12176   operands[2] = GEN_INT (mask);
12177
12178   return "vpshufd\t{%2, %1, %0<mask_operand10>|%0<mask_operand10>, %1, %2}";
12179 }
12180   [(set_attr "type" "sselog1")
12181    (set_attr "prefix" "maybe_evex")
12182    (set_attr "length_immediate" "1")
12183    (set_attr "mode" "OI")])
12184
12185 (define_expand "avx512vl_pshufd_mask"
12186   [(match_operand:V4SI 0 "register_operand")
12187    (match_operand:V4SI 1 "nonimmediate_operand")
12188    (match_operand:SI 2 "const_0_to_255_operand")
12189    (match_operand:V4SI 3 "register_operand")
12190    (match_operand:QI 4 "register_operand")]
12191   "TARGET_AVX512VL"
12192 {
12193   int mask = INTVAL (operands[2]);
12194   emit_insn (gen_sse2_pshufd_1_mask (operands[0], operands[1],
12195                                 GEN_INT ((mask >> 0) & 3),
12196                                 GEN_INT ((mask >> 2) & 3),
12197                                 GEN_INT ((mask >> 4) & 3),
12198                                 GEN_INT ((mask >> 6) & 3),
12199                 operands[3], operands[4]));
12200   DONE;
12201 })
12202
12203 (define_expand "sse2_pshufd"
12204   [(match_operand:V4SI 0 "register_operand")
12205    (match_operand:V4SI 1 "nonimmediate_operand")
12206    (match_operand:SI 2 "const_int_operand")]
12207   "TARGET_SSE2"
12208 {
12209   int mask = INTVAL (operands[2]);
12210   emit_insn (gen_sse2_pshufd_1 (operands[0], operands[1],
12211                                 GEN_INT ((mask >> 0) & 3),
12212                                 GEN_INT ((mask >> 2) & 3),
12213                                 GEN_INT ((mask >> 4) & 3),
12214                                 GEN_INT ((mask >> 6) & 3)));
12215   DONE;
12216 })
12217
12218 (define_insn "sse2_pshufd_1<mask_name>"
12219   [(set (match_operand:V4SI 0 "register_operand" "=v")
12220         (vec_select:V4SI
12221           (match_operand:V4SI 1 "nonimmediate_operand" "vm")
12222           (parallel [(match_operand 2 "const_0_to_3_operand")
12223                      (match_operand 3 "const_0_to_3_operand")
12224                      (match_operand 4 "const_0_to_3_operand")
12225                      (match_operand 5 "const_0_to_3_operand")])))]
12226   "TARGET_SSE2 && <mask_avx512vl_condition>"
12227 {
12228   int mask = 0;
12229   mask |= INTVAL (operands[2]) << 0;
12230   mask |= INTVAL (operands[3]) << 2;
12231   mask |= INTVAL (operands[4]) << 4;
12232   mask |= INTVAL (operands[5]) << 6;
12233   operands[2] = GEN_INT (mask);
12234
12235   return "%vpshufd\t{%2, %1, %0<mask_operand6>|%0<mask_operand6>, %1, %2}";
12236 }
12237   [(set_attr "type" "sselog1")
12238    (set_attr "prefix_data16" "1")
12239    (set_attr "prefix" "<mask_prefix2>")
12240    (set_attr "length_immediate" "1")
12241    (set_attr "mode" "TI")])
12242
12243 (define_insn "<mask_codefor>avx512bw_pshuflwv32hi<mask_name>"
12244   [(set (match_operand:V32HI 0 "register_operand" "=v")
12245         (unspec:V32HI
12246           [(match_operand:V32HI 1 "nonimmediate_operand" "vm")
12247            (match_operand:SI 2 "const_0_to_255_operand" "n")]
12248           UNSPEC_PSHUFLW))]
12249   "TARGET_AVX512BW"
12250   "vpshuflw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
12251   [(set_attr "type" "sselog")
12252    (set_attr "prefix" "evex")
12253    (set_attr "mode" "XI")])
12254
12255 (define_expand "avx512vl_pshuflwv3_mask"
12256   [(match_operand:V16HI 0 "register_operand")
12257    (match_operand:V16HI 1 "nonimmediate_operand")
12258    (match_operand:SI 2 "const_0_to_255_operand")
12259    (match_operand:V16HI 3 "register_operand")
12260    (match_operand:HI 4 "register_operand")]
12261   "TARGET_AVX512VL && TARGET_AVX512BW"
12262 {
12263   int mask = INTVAL (operands[2]);
12264   emit_insn (gen_avx2_pshuflw_1_mask (operands[0], operands[1],
12265                                  GEN_INT ((mask >> 0) & 3),
12266                                  GEN_INT ((mask >> 2) & 3),
12267                                  GEN_INT ((mask >> 4) & 3),
12268                                  GEN_INT ((mask >> 6) & 3),
12269                                  GEN_INT (((mask >> 0) & 3) + 8),
12270                                  GEN_INT (((mask >> 2) & 3) + 8),
12271                                  GEN_INT (((mask >> 4) & 3) + 8),
12272                                  GEN_INT (((mask >> 6) & 3) + 8),
12273                  operands[3], operands[4]));
12274   DONE;
12275 })
12276
12277 (define_expand "avx2_pshuflwv3"
12278   [(match_operand:V16HI 0 "register_operand")
12279    (match_operand:V16HI 1 "nonimmediate_operand")
12280    (match_operand:SI 2 "const_0_to_255_operand")]
12281   "TARGET_AVX2"
12282 {
12283   int mask = INTVAL (operands[2]);
12284   emit_insn (gen_avx2_pshuflw_1 (operands[0], operands[1],
12285                                  GEN_INT ((mask >> 0) & 3),
12286                                  GEN_INT ((mask >> 2) & 3),
12287                                  GEN_INT ((mask >> 4) & 3),
12288                                  GEN_INT ((mask >> 6) & 3),
12289                                  GEN_INT (((mask >> 0) & 3) + 8),
12290                                  GEN_INT (((mask >> 2) & 3) + 8),
12291                                  GEN_INT (((mask >> 4) & 3) + 8),
12292                                  GEN_INT (((mask >> 6) & 3) + 8)));
12293   DONE;
12294 })
12295
12296 (define_insn "avx2_pshuflw_1<mask_name>"
12297   [(set (match_operand:V16HI 0 "register_operand" "=v")
12298         (vec_select:V16HI
12299           (match_operand:V16HI 1 "nonimmediate_operand" "vm")
12300           (parallel [(match_operand 2 "const_0_to_3_operand")
12301                      (match_operand 3 "const_0_to_3_operand")
12302                      (match_operand 4 "const_0_to_3_operand")
12303                      (match_operand 5 "const_0_to_3_operand")
12304                      (const_int 4)
12305                      (const_int 5)
12306                      (const_int 6)
12307                      (const_int 7)
12308                      (match_operand 6 "const_8_to_11_operand")
12309                      (match_operand 7 "const_8_to_11_operand")
12310                      (match_operand 8 "const_8_to_11_operand")
12311                      (match_operand 9 "const_8_to_11_operand")
12312                      (const_int 12)
12313                      (const_int 13)
12314                      (const_int 14)
12315                      (const_int 15)])))]
12316   "TARGET_AVX2
12317    && <mask_avx512bw_condition> && <mask_avx512vl_condition>
12318    && INTVAL (operands[2]) + 8 == INTVAL (operands[6])
12319    && INTVAL (operands[3]) + 8 == INTVAL (operands[7])
12320    && INTVAL (operands[4]) + 8 == INTVAL (operands[8])
12321    && INTVAL (operands[5]) + 8 == INTVAL (operands[9])"
12322 {
12323   int mask = 0;
12324   mask |= INTVAL (operands[2]) << 0;
12325   mask |= INTVAL (operands[3]) << 2;
12326   mask |= INTVAL (operands[4]) << 4;
12327   mask |= INTVAL (operands[5]) << 6;
12328   operands[2] = GEN_INT (mask);
12329
12330   return "vpshuflw\t{%2, %1, %0<mask_operand10>|%0<mask_operand10>, %1, %2}";
12331 }
12332   [(set_attr "type" "sselog")
12333    (set_attr "prefix" "maybe_evex")
12334    (set_attr "length_immediate" "1")
12335    (set_attr "mode" "OI")])
12336
12337 (define_expand "avx512vl_pshuflw_mask"
12338   [(match_operand:V8HI 0 "register_operand")
12339    (match_operand:V8HI 1 "nonimmediate_operand")
12340    (match_operand:SI 2 "const_0_to_255_operand")
12341    (match_operand:V8HI 3 "register_operand")
12342    (match_operand:QI 4 "register_operand")]
12343   "TARGET_AVX512VL && TARGET_AVX512BW"
12344 {
12345   int mask = INTVAL (operands[2]);
12346   emit_insn (gen_sse2_pshuflw_1_mask (operands[0], operands[1],
12347                                  GEN_INT ((mask >> 0) & 3),
12348                                  GEN_INT ((mask >> 2) & 3),
12349                                  GEN_INT ((mask >> 4) & 3),
12350                                  GEN_INT ((mask >> 6) & 3),
12351                  operands[3], operands[4]));
12352   DONE;
12353 })
12354
12355 (define_expand "sse2_pshuflw"
12356   [(match_operand:V8HI 0 "register_operand")
12357    (match_operand:V8HI 1 "nonimmediate_operand")
12358    (match_operand:SI 2 "const_int_operand")]
12359   "TARGET_SSE2"
12360 {
12361   int mask = INTVAL (operands[2]);
12362   emit_insn (gen_sse2_pshuflw_1 (operands[0], operands[1],
12363                                  GEN_INT ((mask >> 0) & 3),
12364                                  GEN_INT ((mask >> 2) & 3),
12365                                  GEN_INT ((mask >> 4) & 3),
12366                                  GEN_INT ((mask >> 6) & 3)));
12367   DONE;
12368 })
12369
12370 (define_insn "sse2_pshuflw_1<mask_name>"
12371   [(set (match_operand:V8HI 0 "register_operand" "=v")
12372         (vec_select:V8HI
12373           (match_operand:V8HI 1 "nonimmediate_operand" "vm")
12374           (parallel [(match_operand 2 "const_0_to_3_operand")
12375                      (match_operand 3 "const_0_to_3_operand")
12376                      (match_operand 4 "const_0_to_3_operand")
12377                      (match_operand 5 "const_0_to_3_operand")
12378                      (const_int 4)
12379                      (const_int 5)
12380                      (const_int 6)
12381                      (const_int 7)])))]
12382   "TARGET_SSE2 && <mask_avx512bw_condition> && <mask_avx512vl_condition>"
12383 {
12384   int mask = 0;
12385   mask |= INTVAL (operands[2]) << 0;
12386   mask |= INTVAL (operands[3]) << 2;
12387   mask |= INTVAL (operands[4]) << 4;
12388   mask |= INTVAL (operands[5]) << 6;
12389   operands[2] = GEN_INT (mask);
12390
12391   return "%vpshuflw\t{%2, %1, %0<mask_operand6>|%0<mask_operand6>, %1, %2}";
12392 }
12393   [(set_attr "type" "sselog")
12394    (set_attr "prefix_data16" "0")
12395    (set_attr "prefix_rep" "1")
12396    (set_attr "prefix" "maybe_vex")
12397    (set_attr "length_immediate" "1")
12398    (set_attr "mode" "TI")])
12399
12400 (define_expand "avx2_pshufhwv3"
12401   [(match_operand:V16HI 0 "register_operand")
12402    (match_operand:V16HI 1 "nonimmediate_operand")
12403    (match_operand:SI 2 "const_0_to_255_operand")]
12404   "TARGET_AVX2"
12405 {
12406   int mask = INTVAL (operands[2]);
12407   emit_insn (gen_avx2_pshufhw_1 (operands[0], operands[1],
12408                                  GEN_INT (((mask >> 0) & 3) + 4),
12409                                  GEN_INT (((mask >> 2) & 3) + 4),
12410                                  GEN_INT (((mask >> 4) & 3) + 4),
12411                                  GEN_INT (((mask >> 6) & 3) + 4),
12412                                  GEN_INT (((mask >> 0) & 3) + 12),
12413                                  GEN_INT (((mask >> 2) & 3) + 12),
12414                                  GEN_INT (((mask >> 4) & 3) + 12),
12415                                  GEN_INT (((mask >> 6) & 3) + 12)));
12416   DONE;
12417 })
12418
12419 (define_insn "<mask_codefor>avx512bw_pshufhwv32hi<mask_name>"
12420   [(set (match_operand:V32HI 0 "register_operand" "=v")
12421         (unspec:V32HI
12422           [(match_operand:V32HI 1 "nonimmediate_operand" "vm")
12423            (match_operand:SI 2 "const_0_to_255_operand" "n")]
12424           UNSPEC_PSHUFHW))]
12425   "TARGET_AVX512BW"
12426   "vpshufhw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
12427   [(set_attr "type" "sselog")
12428    (set_attr "prefix" "evex")
12429    (set_attr "mode" "XI")])
12430
12431 (define_expand "avx512vl_pshufhwv3_mask"
12432   [(match_operand:V16HI 0 "register_operand")
12433    (match_operand:V16HI 1 "nonimmediate_operand")
12434    (match_operand:SI 2 "const_0_to_255_operand")
12435    (match_operand:V16HI 3 "register_operand")
12436    (match_operand:HI 4 "register_operand")]
12437   "TARGET_AVX512VL && TARGET_AVX512BW"
12438 {
12439   int mask = INTVAL (operands[2]);
12440   emit_insn (gen_avx2_pshufhw_1_mask (operands[0], operands[1],
12441                                  GEN_INT (((mask >> 0) & 3) + 4),
12442                                  GEN_INT (((mask >> 2) & 3) + 4),
12443                                  GEN_INT (((mask >> 4) & 3) + 4),
12444                                  GEN_INT (((mask >> 6) & 3) + 4),
12445                                  GEN_INT (((mask >> 0) & 3) + 12),
12446                                  GEN_INT (((mask >> 2) & 3) + 12),
12447                                  GEN_INT (((mask >> 4) & 3) + 12),
12448                                  GEN_INT (((mask >> 6) & 3) + 12),
12449                  operands[3], operands[4]));
12450   DONE;
12451 })
12452
12453 (define_insn "avx2_pshufhw_1<mask_name>"
12454   [(set (match_operand:V16HI 0 "register_operand" "=v")
12455         (vec_select:V16HI
12456           (match_operand:V16HI 1 "nonimmediate_operand" "vm")
12457           (parallel [(const_int 0)
12458                      (const_int 1)
12459                      (const_int 2)
12460                      (const_int 3)
12461                      (match_operand 2 "const_4_to_7_operand")
12462                      (match_operand 3 "const_4_to_7_operand")
12463                      (match_operand 4 "const_4_to_7_operand")
12464                      (match_operand 5 "const_4_to_7_operand")
12465                      (const_int 8)
12466                      (const_int 9)
12467                      (const_int 10)
12468                      (const_int 11)
12469                      (match_operand 6 "const_12_to_15_operand")
12470                      (match_operand 7 "const_12_to_15_operand")
12471                      (match_operand 8 "const_12_to_15_operand")
12472                      (match_operand 9 "const_12_to_15_operand")])))]
12473   "TARGET_AVX2
12474    && <mask_avx512bw_condition> && <mask_avx512vl_condition>
12475    && INTVAL (operands[2]) + 8 == INTVAL (operands[6])
12476    && INTVAL (operands[3]) + 8 == INTVAL (operands[7])
12477    && INTVAL (operands[4]) + 8 == INTVAL (operands[8])
12478    && INTVAL (operands[5]) + 8 == INTVAL (operands[9])"
12479 {
12480   int mask = 0;
12481   mask |= (INTVAL (operands[2]) - 4) << 0;
12482   mask |= (INTVAL (operands[3]) - 4) << 2;
12483   mask |= (INTVAL (operands[4]) - 4) << 4;
12484   mask |= (INTVAL (operands[5]) - 4) << 6;
12485   operands[2] = GEN_INT (mask);
12486
12487   return "vpshufhw\t{%2, %1, %0<mask_operand10>|%0<mask_operand10>, %1, %2}";
12488 }
12489   [(set_attr "type" "sselog")
12490    (set_attr "prefix" "maybe_evex")
12491    (set_attr "length_immediate" "1")
12492    (set_attr "mode" "OI")])
12493
12494 (define_expand "avx512vl_pshufhw_mask"
12495   [(match_operand:V8HI 0 "register_operand")
12496    (match_operand:V8HI 1 "nonimmediate_operand")
12497    (match_operand:SI 2 "const_0_to_255_operand")
12498    (match_operand:V8HI 3 "register_operand")
12499    (match_operand:QI 4 "register_operand")]
12500   "TARGET_AVX512VL && TARGET_AVX512BW"
12501 {
12502   int mask = INTVAL (operands[2]);
12503   emit_insn (gen_sse2_pshufhw_1_mask (operands[0], operands[1],
12504                                  GEN_INT (((mask >> 0) & 3) + 4),
12505                                  GEN_INT (((mask >> 2) & 3) + 4),
12506                                  GEN_INT (((mask >> 4) & 3) + 4),
12507                                  GEN_INT (((mask >> 6) & 3) + 4),
12508                  operands[3], operands[4]));
12509   DONE;
12510 })
12511
12512 (define_expand "sse2_pshufhw"
12513   [(match_operand:V8HI 0 "register_operand")
12514    (match_operand:V8HI 1 "nonimmediate_operand")
12515    (match_operand:SI 2 "const_int_operand")]
12516   "TARGET_SSE2"
12517 {
12518   int mask = INTVAL (operands[2]);
12519   emit_insn (gen_sse2_pshufhw_1 (operands[0], operands[1],
12520                                  GEN_INT (((mask >> 0) & 3) + 4),
12521                                  GEN_INT (((mask >> 2) & 3) + 4),
12522                                  GEN_INT (((mask >> 4) & 3) + 4),
12523                                  GEN_INT (((mask >> 6) & 3) + 4)));
12524   DONE;
12525 })
12526
12527 (define_insn "sse2_pshufhw_1<mask_name>"
12528   [(set (match_operand:V8HI 0 "register_operand" "=v")
12529         (vec_select:V8HI
12530           (match_operand:V8HI 1 "nonimmediate_operand" "vm")
12531           (parallel [(const_int 0)
12532                      (const_int 1)
12533                      (const_int 2)
12534                      (const_int 3)
12535                      (match_operand 2 "const_4_to_7_operand")
12536                      (match_operand 3 "const_4_to_7_operand")
12537                      (match_operand 4 "const_4_to_7_operand")
12538                      (match_operand 5 "const_4_to_7_operand")])))]
12539   "TARGET_SSE2 && <mask_avx512bw_condition> && <mask_avx512vl_condition>"
12540 {
12541   int mask = 0;
12542   mask |= (INTVAL (operands[2]) - 4) << 0;
12543   mask |= (INTVAL (operands[3]) - 4) << 2;
12544   mask |= (INTVAL (operands[4]) - 4) << 4;
12545   mask |= (INTVAL (operands[5]) - 4) << 6;
12546   operands[2] = GEN_INT (mask);
12547
12548   return "%vpshufhw\t{%2, %1, %0<mask_operand6>|%0<mask_operand6>, %1, %2}";
12549 }
12550   [(set_attr "type" "sselog")
12551    (set_attr "prefix_rep" "1")
12552    (set_attr "prefix_data16" "0")
12553    (set_attr "prefix" "maybe_vex")
12554    (set_attr "length_immediate" "1")
12555    (set_attr "mode" "TI")])
12556
12557 (define_expand "sse2_loadd"
12558   [(set (match_operand:V4SI 0 "register_operand")
12559         (vec_merge:V4SI
12560           (vec_duplicate:V4SI
12561             (match_operand:SI 1 "nonimmediate_operand"))
12562           (match_dup 2)
12563           (const_int 1)))]
12564   "TARGET_SSE"
12565   "operands[2] = CONST0_RTX (V4SImode);")
12566
12567 (define_insn "sse2_loadld"
12568   [(set (match_operand:V4SI 0 "register_operand"       "=x,Yi,x,x,x")
12569         (vec_merge:V4SI
12570           (vec_duplicate:V4SI
12571             (match_operand:SI 2 "nonimmediate_operand" "m ,r ,m,x,x"))
12572           (match_operand:V4SI 1 "reg_or_0_operand"     "C ,C ,C,0,x")
12573           (const_int 1)))]
12574   "TARGET_SSE"
12575   "@
12576    %vmovd\t{%2, %0|%0, %2}
12577    %vmovd\t{%2, %0|%0, %2}
12578    movss\t{%2, %0|%0, %2}
12579    movss\t{%2, %0|%0, %2}
12580    vmovss\t{%2, %1, %0|%0, %1, %2}"
12581   [(set_attr "isa" "sse2,sse2,noavx,noavx,avx")
12582    (set_attr "type" "ssemov")
12583    (set_attr "prefix" "maybe_vex,maybe_vex,orig,orig,vex")
12584    (set_attr "mode" "TI,TI,V4SF,SF,SF")])
12585
12586 (define_insn "*vec_extract<mode>"
12587   [(set (match_operand:<ssescalarmode> 0 "nonimmediate_operand" "=r,m")
12588         (vec_select:<ssescalarmode>
12589           (match_operand:VI12_128 1 "register_operand" "x,x")
12590           (parallel
12591             [(match_operand:SI 2 "const_0_to_<ssescalarnummask>_operand")])))]
12592   "TARGET_SSE4_1"
12593   "@
12594    %vpextr<ssemodesuffix>\t{%2, %1, %k0|%k0, %1, %2}
12595    %vpextr<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12596   [(set_attr "type" "sselog1")
12597    (set (attr "prefix_data16")
12598      (if_then_else
12599        (and (eq_attr "alternative" "0")
12600             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
12601        (const_string "1")
12602        (const_string "*")))
12603    (set (attr "prefix_extra")
12604      (if_then_else
12605        (and (eq_attr "alternative" "0")
12606             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
12607        (const_string "*")
12608        (const_string "1")))
12609    (set_attr "length_immediate" "1")
12610    (set_attr "prefix" "maybe_vex")
12611    (set_attr "mode" "TI")])
12612
12613 (define_insn "*vec_extractv8hi_sse2"
12614   [(set (match_operand:HI 0 "register_operand" "=r")
12615         (vec_select:HI
12616           (match_operand:V8HI 1 "register_operand" "x")
12617           (parallel
12618             [(match_operand:SI 2 "const_0_to_7_operand")])))]
12619   "TARGET_SSE2 && !TARGET_SSE4_1"
12620   "pextrw\t{%2, %1, %k0|%k0, %1, %2}"
12621   [(set_attr "type" "sselog1")
12622    (set_attr "prefix_data16" "1")
12623    (set_attr "length_immediate" "1")
12624    (set_attr "mode" "TI")])
12625
12626 (define_insn "*vec_extractv16qi_zext"
12627   [(set (match_operand:SWI48 0 "register_operand" "=r")
12628         (zero_extend:SWI48
12629           (vec_select:QI
12630             (match_operand:V16QI 1 "register_operand" "x")
12631             (parallel
12632               [(match_operand:SI 2 "const_0_to_15_operand")]))))]
12633   "TARGET_SSE4_1"
12634   "%vpextrb\t{%2, %1, %k0|%k0, %1, %2}"
12635   [(set_attr "type" "sselog1")
12636    (set_attr "prefix_extra" "1")
12637    (set_attr "length_immediate" "1")
12638    (set_attr "prefix" "maybe_vex")
12639    (set_attr "mode" "TI")])
12640
12641 (define_insn "*vec_extractv8hi_zext"
12642   [(set (match_operand:SWI48 0 "register_operand" "=r")
12643         (zero_extend:SWI48
12644           (vec_select:HI
12645             (match_operand:V8HI 1 "register_operand" "x")
12646             (parallel
12647               [(match_operand:SI 2 "const_0_to_7_operand")]))))]
12648   "TARGET_SSE2"
12649   "%vpextrw\t{%2, %1, %k0|%k0, %1, %2}"
12650   [(set_attr "type" "sselog1")
12651    (set_attr "prefix_data16" "1")
12652    (set_attr "length_immediate" "1")
12653    (set_attr "prefix" "maybe_vex")
12654    (set_attr "mode" "TI")])
12655
12656 (define_insn "*vec_extract<mode>_mem"
12657   [(set (match_operand:<ssescalarmode> 0 "register_operand" "=r")
12658         (vec_select:<ssescalarmode>
12659           (match_operand:VI12_128 1 "memory_operand" "o")
12660           (parallel
12661             [(match_operand 2 "const_0_to_<ssescalarnummask>_operand")])))]
12662   "TARGET_SSE"
12663   "#")
12664
12665 (define_insn "*vec_extract<ssevecmodelower>_0"
12666   [(set (match_operand:SWI48 0 "nonimmediate_operand"          "=r ,r,x ,m")
12667         (vec_select:SWI48
12668           (match_operand:<ssevecmode> 1 "nonimmediate_operand" "mYj,x,xm,x")
12669           (parallel [(const_int 0)])))]
12670   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
12671   "#"
12672   [(set_attr "isa" "*,sse4,*,*")])
12673
12674 (define_insn_and_split "*vec_extractv4si_0_zext"
12675   [(set (match_operand:DI 0 "register_operand" "=r")
12676         (zero_extend:DI
12677           (vec_select:SI
12678             (match_operand:V4SI 1 "register_operand" "x")
12679             (parallel [(const_int 0)]))))]
12680   "TARGET_64BIT && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_FROM_VEC"
12681   "#"
12682   "&& reload_completed"
12683   [(set (match_dup 0) (zero_extend:DI (match_dup 1)))]
12684   "operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]));")
12685
12686 (define_insn "*vec_extractv2di_0_sse"
12687   [(set (match_operand:DI 0 "nonimmediate_operand"     "=x,m")
12688         (vec_select:DI
12689           (match_operand:V2DI 1 "nonimmediate_operand" "xm,x")
12690           (parallel [(const_int 0)])))]
12691   "TARGET_SSE && !TARGET_64BIT
12692    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
12693   "#")
12694
12695 (define_split
12696   [(set (match_operand:SWI48x 0 "nonimmediate_operand")
12697         (vec_select:SWI48x
12698           (match_operand:<ssevecmode> 1 "register_operand")
12699           (parallel [(const_int 0)])))]
12700   "TARGET_SSE && reload_completed"
12701   [(set (match_dup 0) (match_dup 1))]
12702   "operands[1] = gen_rtx_REG (<MODE>mode, REGNO (operands[1]));")
12703
12704 (define_insn "*vec_extractv4si"
12705   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm,Yr,*x,x")
12706         (vec_select:SI
12707           (match_operand:V4SI 1 "register_operand" "x,0,0,x")
12708           (parallel [(match_operand:SI 2 "const_0_to_3_operand")])))]
12709   "TARGET_SSE4_1"
12710 {
12711   switch (which_alternative)
12712     {
12713     case 0:
12714       return "%vpextrd\t{%2, %1, %0|%0, %1, %2}";
12715
12716     case 1:
12717     case 2:
12718       operands [2] = GEN_INT (INTVAL (operands[2]) * 4);
12719       return "psrldq\t{%2, %0|%0, %2}";
12720
12721     case 3:
12722       operands [2] = GEN_INT (INTVAL (operands[2]) * 4);
12723       return "vpsrldq\t{%2, %1, %0|%0, %1, %2}";
12724
12725     default:
12726       gcc_unreachable ();
12727     }
12728 }
12729   [(set_attr "isa" "*,noavx,noavx,avx")
12730    (set_attr "type" "sselog1,sseishft1,sseishft1,sseishft1")
12731    (set_attr "prefix_extra" "1,*,*,*")
12732    (set_attr "length_immediate" "1")
12733    (set_attr "prefix" "maybe_vex,orig,orig,vex")
12734    (set_attr "mode" "TI")])
12735
12736 (define_insn "*vec_extractv4si_zext"
12737   [(set (match_operand:DI 0 "register_operand" "=r")
12738         (zero_extend:DI
12739           (vec_select:SI
12740             (match_operand:V4SI 1 "register_operand" "x")
12741             (parallel [(match_operand:SI 2 "const_0_to_3_operand")]))))]
12742   "TARGET_64BIT && TARGET_SSE4_1"
12743   "%vpextrd\t{%2, %1, %k0|%k0, %1, %2}"
12744   [(set_attr "type" "sselog1")
12745    (set_attr "prefix_extra" "1")
12746    (set_attr "length_immediate" "1")
12747    (set_attr "prefix" "maybe_vex")
12748    (set_attr "mode" "TI")])
12749
12750 (define_insn "*vec_extractv4si_mem"
12751   [(set (match_operand:SI 0 "register_operand" "=x,r")
12752         (vec_select:SI
12753           (match_operand:V4SI 1 "memory_operand" "o,o")
12754           (parallel [(match_operand 2 "const_0_to_3_operand")])))]
12755   "TARGET_SSE"
12756   "#")
12757
12758 (define_insn_and_split "*vec_extractv4si_zext_mem"
12759   [(set (match_operand:DI 0 "register_operand" "=x,r")
12760         (zero_extend:DI
12761           (vec_select:SI
12762             (match_operand:V4SI 1 "memory_operand" "o,o")
12763             (parallel [(match_operand:SI 2 "const_0_to_3_operand")]))))]
12764   "TARGET_64BIT && TARGET_SSE"
12765   "#"
12766   "&& reload_completed"
12767   [(set (match_dup 0) (zero_extend:DI (match_dup 1)))]
12768 {
12769   operands[1] = adjust_address (operands[1], SImode, INTVAL (operands[2]) * 4);
12770 })
12771
12772 (define_insn "*vec_extractv2di_1"
12773   [(set (match_operand:DI 0 "nonimmediate_operand"     "=rm,m,x,x,x,x,r")
12774         (vec_select:DI
12775           (match_operand:V2DI 1 "nonimmediate_operand"  "x ,x,0,x,x,o,o")
12776           (parallel [(const_int 1)])))]
12777   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
12778   "@
12779    %vpextrq\t{$1, %1, %0|%0, %1, 1}
12780    %vmovhps\t{%1, %0|%0, %1}
12781    psrldq\t{$8, %0|%0, 8}
12782    vpsrldq\t{$8, %1, %0|%0, %1, 8}
12783    movhlps\t{%1, %0|%0, %1}
12784    #
12785    #"
12786   [(set_attr "isa" "x64_sse4,*,sse2_noavx,avx,noavx,*,x64")
12787    (set_attr "type" "sselog1,ssemov,sseishft1,sseishft1,ssemov,ssemov,imov")
12788    (set_attr "length_immediate" "1,*,1,1,*,*,*")
12789    (set_attr "prefix_rex" "1,*,*,*,*,*,*")
12790    (set_attr "prefix_extra" "1,*,*,*,*,*,*")
12791    (set_attr "prefix" "maybe_vex,maybe_vex,orig,vex,orig,*,*")
12792    (set_attr "mode" "TI,V2SF,TI,TI,V4SF,DI,DI")])
12793
12794 (define_split
12795   [(set (match_operand:<ssescalarmode> 0 "register_operand")
12796         (vec_select:<ssescalarmode>
12797           (match_operand:VI_128 1 "memory_operand")
12798           (parallel
12799             [(match_operand 2 "const_0_to_<ssescalarnummask>_operand")])))]
12800   "TARGET_SSE && reload_completed"
12801   [(set (match_dup 0) (match_dup 1))]
12802 {
12803   int offs = INTVAL (operands[2]) * GET_MODE_SIZE (<ssescalarmode>mode);
12804
12805   operands[1] = adjust_address (operands[1], <ssescalarmode>mode, offs);
12806 })
12807
12808 (define_insn "*vec_concatv2si_sse4_1"
12809   [(set (match_operand:V2SI 0 "register_operand"     "=Yr,*x,x, Yr,*x,x, x, *y,*y")
12810         (vec_concat:V2SI
12811           (match_operand:SI 1 "nonimmediate_operand" "  0, 0,x,  0,0, x,rm,  0,rm")
12812           (match_operand:SI 2 "vector_move_operand"  " rm,rm,rm,Yr,*x,x, C,*ym, C")))]
12813   "TARGET_SSE4_1"
12814   "@
12815    pinsrd\t{$1, %2, %0|%0, %2, 1}
12816    pinsrd\t{$1, %2, %0|%0, %2, 1}
12817    vpinsrd\t{$1, %2, %1, %0|%0, %1, %2, 1}
12818    punpckldq\t{%2, %0|%0, %2}
12819    punpckldq\t{%2, %0|%0, %2}
12820    vpunpckldq\t{%2, %1, %0|%0, %1, %2}
12821    %vmovd\t{%1, %0|%0, %1}
12822    punpckldq\t{%2, %0|%0, %2}
12823    movd\t{%1, %0|%0, %1}"
12824   [(set_attr "isa" "noavx,noavx,avx,noavx,noavx,avx,*,*,*")
12825    (set_attr "type" "sselog,sselog,sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
12826    (set_attr "prefix_extra" "1,1,1,*,*,*,*,*,*")
12827    (set_attr "length_immediate" "1,1,1,*,*,*,*,*,*")
12828    (set_attr "prefix" "orig,orig,vex,orig,orig,vex,maybe_vex,orig,orig")
12829    (set_attr "mode" "TI,TI,TI,TI,TI,TI,TI,DI,DI")])
12830
12831 ;; ??? In theory we can match memory for the MMX alternative, but allowing
12832 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
12833 ;; alternatives pretty much forces the MMX alternative to be chosen.
12834 (define_insn "*vec_concatv2si"
12835   [(set (match_operand:V2SI 0 "register_operand"     "=x,x ,*y,x,x,*y,*y")
12836         (vec_concat:V2SI
12837           (match_operand:SI 1 "nonimmediate_operand" " 0,rm,rm,0,m, 0,*rm")
12838           (match_operand:SI 2 "reg_or_0_operand"     " x,C ,C, x,C,*y,C")))]
12839   "TARGET_SSE && !TARGET_SSE4_1"
12840   "@
12841    punpckldq\t{%2, %0|%0, %2}
12842    movd\t{%1, %0|%0, %1}
12843    movd\t{%1, %0|%0, %1}
12844    unpcklps\t{%2, %0|%0, %2}
12845    movss\t{%1, %0|%0, %1}
12846    punpckldq\t{%2, %0|%0, %2}
12847    movd\t{%1, %0|%0, %1}"
12848   [(set_attr "isa" "sse2,sse2,sse2,*,*,*,*")
12849    (set_attr "type" "sselog,ssemov,mmxmov,sselog,ssemov,mmxcvt,mmxmov")
12850    (set_attr "mode" "TI,TI,DI,V4SF,SF,DI,DI")])
12851
12852 (define_insn "*vec_concatv4si"
12853   [(set (match_operand:V4SI 0 "register_operand"       "=x,x,x,x,x")
12854         (vec_concat:V4SI
12855           (match_operand:V2SI 1 "register_operand"     " 0,x,0,0,x")
12856           (match_operand:V2SI 2 "nonimmediate_operand" " x,x,x,m,m")))]
12857   "TARGET_SSE"
12858   "@
12859    punpcklqdq\t{%2, %0|%0, %2}
12860    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
12861    movlhps\t{%2, %0|%0, %2}
12862    movhps\t{%2, %0|%0, %q2}
12863    vmovhps\t{%2, %1, %0|%0, %1, %q2}"
12864   [(set_attr "isa" "sse2_noavx,avx,noavx,noavx,avx")
12865    (set_attr "type" "sselog,sselog,ssemov,ssemov,ssemov")
12866    (set_attr "prefix" "orig,vex,orig,orig,vex")
12867    (set_attr "mode" "TI,TI,V4SF,V2SF,V2SF")])
12868
12869 ;; movd instead of movq is required to handle broken assemblers.
12870 (define_insn "vec_concatv2di"
12871   [(set (match_operand:V2DI 0 "register_operand"
12872           "=Yr,*x,x ,Yi,x ,!x,x,x,x,x,x")
12873         (vec_concat:V2DI
12874           (match_operand:DI 1 "nonimmediate_operand"
12875           "  0, 0,x ,r ,xm,*y,0,x,0,0,x")
12876           (match_operand:DI 2 "vector_move_operand"
12877           "*rm,rm,rm,C ,C ,C ,x,x,x,m,m")))]
12878   "TARGET_SSE"
12879   "@
12880    pinsrq\t{$1, %2, %0|%0, %2, 1}
12881    pinsrq\t{$1, %2, %0|%0, %2, 1}
12882    vpinsrq\t{$1, %2, %1, %0|%0, %1, %2, 1}
12883    * return HAVE_AS_IX86_INTERUNIT_MOVQ ? \"%vmovq\t{%1, %0|%0, %1}\" : \"%vmovd\t{%1, %0|%0, %1}\";
12884    %vmovq\t{%1, %0|%0, %1}
12885    movq2dq\t{%1, %0|%0, %1}
12886    punpcklqdq\t{%2, %0|%0, %2}
12887    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
12888    movlhps\t{%2, %0|%0, %2}
12889    movhps\t{%2, %0|%0, %2}
12890    vmovhps\t{%2, %1, %0|%0, %1, %2}"
12891   [(set_attr "isa" "x64_sse4_noavx,x64_sse4_noavx,x64_avx,x64,sse2,sse2,sse2_noavx,avx,noavx,noavx,avx")
12892    (set (attr "type")
12893      (if_then_else
12894        (eq_attr "alternative" "0,1,2,6,7")
12895        (const_string "sselog")
12896        (const_string "ssemov")))
12897    (set_attr "prefix_rex" "1,1,1,1,*,*,*,*,*,*,*")
12898    (set_attr "prefix_extra" "1,1,1,*,*,*,*,*,*,*,*")
12899    (set_attr "length_immediate" "1,1,1,*,*,*,*,*,*,*,*")
12900    (set_attr "prefix" "orig,orig,vex,maybe_vex,maybe_vex,orig,orig,vex,orig,orig,vex")
12901    (set_attr "mode" "TI,TI,TI,TI,TI,TI,TI,TI,V4SF,V2SF,V2SF")])
12902
12903 (define_expand "vec_unpacks_lo_<mode>"
12904   [(match_operand:<sseunpackmode> 0 "register_operand")
12905    (match_operand:VI124_AVX512F 1 "register_operand")]
12906   "TARGET_SSE2"
12907   "ix86_expand_sse_unpack (operands[0], operands[1], false, false); DONE;")
12908
12909 (define_expand "vec_unpacks_hi_<mode>"
12910   [(match_operand:<sseunpackmode> 0 "register_operand")
12911    (match_operand:VI124_AVX512F 1 "register_operand")]
12912   "TARGET_SSE2"
12913   "ix86_expand_sse_unpack (operands[0], operands[1], false, true); DONE;")
12914
12915 (define_expand "vec_unpacku_lo_<mode>"
12916   [(match_operand:<sseunpackmode> 0 "register_operand")
12917    (match_operand:VI124_AVX512F 1 "register_operand")]
12918   "TARGET_SSE2"
12919   "ix86_expand_sse_unpack (operands[0], operands[1], true, false); DONE;")
12920
12921 (define_expand "vec_unpacku_hi_<mode>"
12922   [(match_operand:<sseunpackmode> 0 "register_operand")
12923    (match_operand:VI124_AVX512F 1 "register_operand")]
12924   "TARGET_SSE2"
12925   "ix86_expand_sse_unpack (operands[0], operands[1], true, true); DONE;")
12926
12927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12928 ;;
12929 ;; Miscellaneous
12930 ;;
12931 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12932
12933 (define_expand "<sse2_avx2>_uavg<mode>3<mask_name>"
12934   [(set (match_operand:VI12_AVX2 0 "register_operand")
12935         (truncate:VI12_AVX2
12936           (lshiftrt:<ssedoublemode>
12937             (plus:<ssedoublemode>
12938               (plus:<ssedoublemode>
12939                 (zero_extend:<ssedoublemode>
12940                   (match_operand:VI12_AVX2 1 "nonimmediate_operand"))
12941                 (zero_extend:<ssedoublemode>
12942                   (match_operand:VI12_AVX2 2 "nonimmediate_operand")))
12943               (match_dup <mask_expand_op3>))
12944             (const_int 1))))]
12945   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
12946 {
12947   rtx tmp;
12948   if (<mask_applied>)
12949     tmp = operands[3];
12950   operands[3] = CONST1_RTX(<MODE>mode);
12951   ix86_fixup_binary_operands_no_copy (PLUS, <MODE>mode, operands);
12952
12953   if (<mask_applied>)
12954     {
12955       operands[5] = operands[3];
12956       operands[3] = tmp;
12957     }
12958 })
12959
12960 (define_insn "*<sse2_avx2>_uavg<mode>3<mask_name>"
12961   [(set (match_operand:VI12_AVX2 0 "register_operand" "=x,v")
12962         (truncate:VI12_AVX2
12963           (lshiftrt:<ssedoublemode>
12964             (plus:<ssedoublemode>
12965               (plus:<ssedoublemode>
12966                 (zero_extend:<ssedoublemode>
12967                   (match_operand:VI12_AVX2 1 "nonimmediate_operand" "%0,v"))
12968                 (zero_extend:<ssedoublemode>
12969                   (match_operand:VI12_AVX2 2 "nonimmediate_operand" "xm,vm")))
12970               (match_operand:VI12_AVX2 <mask_expand_op3> "const1_operand"))
12971             (const_int 1))))]
12972   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>
12973    && ix86_binary_operator_ok (PLUS, <MODE>mode, operands)"
12974   "@
12975    pavg<ssemodesuffix>\t{%2, %0|%0, %2}
12976    vpavg<ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
12977   [(set_attr "isa" "noavx,avx")
12978    (set_attr "type" "sseiadd")
12979    (set_attr "prefix_data16" "1,*")
12980    (set_attr "prefix" "orig,<mask_prefix>")
12981    (set_attr "mode" "<sseinsnmode>")])
12982
12983 ;; The correct representation for this is absolutely enormous, and
12984 ;; surely not generally useful.
12985 (define_insn "<sse2_avx2>_psadbw"
12986   [(set (match_operand:VI8_AVX2_AVX512BW 0 "register_operand" "=x,v")
12987         (unspec:VI8_AVX2_AVX512BW
12988           [(match_operand:<ssebytemode> 1 "register_operand" "0,v")
12989            (match_operand:<ssebytemode> 2 "nonimmediate_operand" "xm,vm")]
12990           UNSPEC_PSADBW))]
12991   "TARGET_SSE2"
12992   "@
12993    psadbw\t{%2, %0|%0, %2}
12994    vpsadbw\t{%2, %1, %0|%0, %1, %2}"
12995   [(set_attr "isa" "noavx,avx")
12996    (set_attr "type" "sseiadd")
12997    (set_attr "atom_unit" "simul")
12998    (set_attr "prefix_data16" "1,*")
12999    (set_attr "prefix" "orig,maybe_evex")
13000    (set_attr "mode" "<sseinsnmode>")])
13001
13002 (define_insn "<sse>_movmsk<ssemodesuffix><avxsizesuffix>"
13003   [(set (match_operand:SI 0 "register_operand" "=r")
13004         (unspec:SI
13005           [(match_operand:VF_128_256 1 "register_operand" "x")]
13006           UNSPEC_MOVMSK))]
13007   "TARGET_SSE"
13008   "%vmovmsk<ssemodesuffix>\t{%1, %0|%0, %1}"
13009   [(set_attr "type" "ssemov")
13010    (set_attr "prefix" "maybe_vex")
13011    (set_attr "mode" "<MODE>")])
13012
13013 (define_insn "avx2_pmovmskb"
13014   [(set (match_operand:SI 0 "register_operand" "=r")
13015         (unspec:SI [(match_operand:V32QI 1 "register_operand" "x")]
13016                    UNSPEC_MOVMSK))]
13017   "TARGET_AVX2"
13018   "vpmovmskb\t{%1, %0|%0, %1}"
13019   [(set_attr "type" "ssemov")
13020    (set_attr "prefix" "vex")
13021    (set_attr "mode" "DI")])
13022
13023 (define_insn "sse2_pmovmskb"
13024   [(set (match_operand:SI 0 "register_operand" "=r")
13025         (unspec:SI [(match_operand:V16QI 1 "register_operand" "x")]
13026                    UNSPEC_MOVMSK))]
13027   "TARGET_SSE2"
13028   "%vpmovmskb\t{%1, %0|%0, %1}"
13029   [(set_attr "type" "ssemov")
13030    (set_attr "prefix_data16" "1")
13031    (set_attr "prefix" "maybe_vex")
13032    (set_attr "mode" "SI")])
13033
13034 (define_expand "sse2_maskmovdqu"
13035   [(set (match_operand:V16QI 0 "memory_operand")
13036         (unspec:V16QI [(match_operand:V16QI 1 "register_operand")
13037                        (match_operand:V16QI 2 "register_operand")
13038                        (match_dup 0)]
13039                       UNSPEC_MASKMOV))]
13040   "TARGET_SSE2")
13041
13042 (define_insn "*sse2_maskmovdqu"
13043   [(set (mem:V16QI (match_operand:P 0 "register_operand" "D"))
13044         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
13045                        (match_operand:V16QI 2 "register_operand" "x")
13046                        (mem:V16QI (match_dup 0))]
13047                       UNSPEC_MASKMOV))]
13048   "TARGET_SSE2"
13049 {
13050   /* We can't use %^ here due to ASM_OUTPUT_OPCODE processing
13051      that requires %v to be at the beginning of the opcode name.  */
13052   if (Pmode != word_mode)
13053     fputs ("\taddr32", asm_out_file);
13054   return "%vmaskmovdqu\t{%2, %1|%1, %2}";
13055 }
13056   [(set_attr "type" "ssemov")
13057    (set_attr "prefix_data16" "1")
13058    (set (attr "length_address")
13059      (symbol_ref ("Pmode != word_mode")))
13060    ;; The implicit %rdi operand confuses default length_vex computation.
13061    (set (attr "length_vex")
13062      (symbol_ref ("3 + REX_SSE_REGNO_P (REGNO (operands[2]))")))
13063    (set_attr "prefix" "maybe_vex")
13064    (set_attr "mode" "TI")])
13065
13066 (define_insn "sse_ldmxcsr"
13067   [(unspec_volatile [(match_operand:SI 0 "memory_operand" "m")]
13068                     UNSPECV_LDMXCSR)]
13069   "TARGET_SSE"
13070   "%vldmxcsr\t%0"
13071   [(set_attr "type" "sse")
13072    (set_attr "atom_sse_attr" "mxcsr")
13073    (set_attr "prefix" "maybe_vex")
13074    (set_attr "memory" "load")])
13075
13076 (define_insn "sse_stmxcsr"
13077   [(set (match_operand:SI 0 "memory_operand" "=m")
13078         (unspec_volatile:SI [(const_int 0)] UNSPECV_STMXCSR))]
13079   "TARGET_SSE"
13080   "%vstmxcsr\t%0"
13081   [(set_attr "type" "sse")
13082    (set_attr "atom_sse_attr" "mxcsr")
13083    (set_attr "prefix" "maybe_vex")
13084    (set_attr "memory" "store")])
13085
13086 (define_insn "sse2_clflush"
13087   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
13088                     UNSPECV_CLFLUSH)]
13089   "TARGET_SSE2"
13090   "clflush\t%a0"
13091   [(set_attr "type" "sse")
13092    (set_attr "atom_sse_attr" "fence")
13093    (set_attr "memory" "unknown")])
13094
13095
13096 (define_insn "sse3_mwait"
13097   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
13098                      (match_operand:SI 1 "register_operand" "c")]
13099                     UNSPECV_MWAIT)]
13100   "TARGET_SSE3"
13101 ;; 64bit version is "mwait %rax,%rcx". But only lower 32bits are used.
13102 ;; Since 32bit register operands are implicitly zero extended to 64bit,
13103 ;; we only need to set up 32bit registers.
13104   "mwait"
13105   [(set_attr "length" "3")])
13106
13107 (define_insn "sse3_monitor_<mode>"
13108   [(unspec_volatile [(match_operand:P 0 "register_operand" "a")
13109                      (match_operand:SI 1 "register_operand" "c")
13110                      (match_operand:SI 2 "register_operand" "d")]
13111                     UNSPECV_MONITOR)]
13112   "TARGET_SSE3"
13113 ;; 64bit version is "monitor %rax,%rcx,%rdx". But only lower 32bits in
13114 ;; RCX and RDX are used.  Since 32bit register operands are implicitly
13115 ;; zero extended to 64bit, we only need to set up 32bit registers.
13116   "%^monitor"
13117   [(set (attr "length")
13118      (symbol_ref ("(Pmode != word_mode) + 3")))])
13119
13120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13121 ;;
13122 ;; SSSE3 instructions
13123 ;;
13124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13125
13126 (define_code_iterator ssse3_plusminus [plus ss_plus minus ss_minus])
13127
13128 (define_insn "avx2_ph<plusminus_mnemonic>wv16hi3"
13129   [(set (match_operand:V16HI 0 "register_operand" "=x")
13130         (vec_concat:V16HI
13131           (vec_concat:V8HI
13132             (vec_concat:V4HI
13133               (vec_concat:V2HI
13134                 (ssse3_plusminus:HI
13135                   (vec_select:HI
13136                     (match_operand:V16HI 1 "register_operand" "x")
13137                     (parallel [(const_int 0)]))
13138                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
13139                 (ssse3_plusminus:HI
13140                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
13141                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
13142               (vec_concat:V2HI
13143                 (ssse3_plusminus:HI
13144                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
13145                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
13146                 (ssse3_plusminus:HI
13147                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
13148                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
13149             (vec_concat:V4HI
13150               (vec_concat:V2HI
13151                 (ssse3_plusminus:HI
13152                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
13153                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
13154                 (ssse3_plusminus:HI
13155                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
13156                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
13157               (vec_concat:V2HI
13158                 (ssse3_plusminus:HI
13159                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
13160                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
13161                 (ssse3_plusminus:HI
13162                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
13163                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
13164           (vec_concat:V8HI
13165             (vec_concat:V4HI
13166               (vec_concat:V2HI
13167                 (ssse3_plusminus:HI
13168                   (vec_select:HI
13169                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
13170                     (parallel [(const_int 0)]))
13171                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
13172                 (ssse3_plusminus:HI
13173                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
13174                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
13175               (vec_concat:V2HI
13176                 (ssse3_plusminus:HI
13177                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
13178                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
13179                 (ssse3_plusminus:HI
13180                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
13181                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
13182             (vec_concat:V4HI
13183               (vec_concat:V2HI
13184                 (ssse3_plusminus:HI
13185                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
13186                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
13187                 (ssse3_plusminus:HI
13188                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
13189                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
13190               (vec_concat:V2HI
13191                 (ssse3_plusminus:HI
13192                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
13193                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
13194                 (ssse3_plusminus:HI
13195                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
13196                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
13197   "TARGET_AVX2"
13198   "vph<plusminus_mnemonic>w\t{%2, %1, %0|%0, %1, %2}"
13199   [(set_attr "type" "sseiadd")
13200    (set_attr "prefix_extra" "1")
13201    (set_attr "prefix" "vex")
13202    (set_attr "mode" "OI")])
13203
13204 (define_insn "ssse3_ph<plusminus_mnemonic>wv8hi3"
13205   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
13206         (vec_concat:V8HI
13207           (vec_concat:V4HI
13208             (vec_concat:V2HI
13209               (ssse3_plusminus:HI
13210                 (vec_select:HI
13211                   (match_operand:V8HI 1 "register_operand" "0,x")
13212                   (parallel [(const_int 0)]))
13213                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
13214               (ssse3_plusminus:HI
13215                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
13216                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
13217             (vec_concat:V2HI
13218               (ssse3_plusminus:HI
13219                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
13220                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
13221               (ssse3_plusminus:HI
13222                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
13223                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
13224           (vec_concat:V4HI
13225             (vec_concat:V2HI
13226               (ssse3_plusminus:HI
13227                 (vec_select:HI
13228                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
13229                   (parallel [(const_int 0)]))
13230                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
13231               (ssse3_plusminus:HI
13232                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
13233                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
13234             (vec_concat:V2HI
13235               (ssse3_plusminus:HI
13236                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
13237                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
13238               (ssse3_plusminus:HI
13239                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
13240                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
13241   "TARGET_SSSE3"
13242   "@
13243    ph<plusminus_mnemonic>w\t{%2, %0|%0, %2}
13244    vph<plusminus_mnemonic>w\t{%2, %1, %0|%0, %1, %2}"
13245   [(set_attr "isa" "noavx,avx")
13246    (set_attr "type" "sseiadd")
13247    (set_attr "atom_unit" "complex")
13248    (set_attr "prefix_data16" "1,*")
13249    (set_attr "prefix_extra" "1")
13250    (set_attr "prefix" "orig,vex")
13251    (set_attr "mode" "TI")])
13252
13253 (define_insn "ssse3_ph<plusminus_mnemonic>wv4hi3"
13254   [(set (match_operand:V4HI 0 "register_operand" "=y")
13255         (vec_concat:V4HI
13256           (vec_concat:V2HI
13257             (ssse3_plusminus:HI
13258               (vec_select:HI
13259                 (match_operand:V4HI 1 "register_operand" "0")
13260                 (parallel [(const_int 0)]))
13261               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
13262             (ssse3_plusminus:HI
13263               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
13264               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
13265           (vec_concat:V2HI
13266             (ssse3_plusminus:HI
13267               (vec_select:HI
13268                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
13269                 (parallel [(const_int 0)]))
13270               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
13271             (ssse3_plusminus:HI
13272               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
13273               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
13274   "TARGET_SSSE3"
13275   "ph<plusminus_mnemonic>w\t{%2, %0|%0, %2}"
13276   [(set_attr "type" "sseiadd")
13277    (set_attr "atom_unit" "complex")
13278    (set_attr "prefix_extra" "1")
13279    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
13280    (set_attr "mode" "DI")])
13281
13282 (define_insn "avx2_ph<plusminus_mnemonic>dv8si3"
13283   [(set (match_operand:V8SI 0 "register_operand" "=x")
13284         (vec_concat:V8SI
13285           (vec_concat:V4SI
13286             (vec_concat:V2SI
13287               (plusminus:SI
13288                 (vec_select:SI
13289                   (match_operand:V8SI 1 "register_operand" "x")
13290                   (parallel [(const_int 0)]))
13291                 (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
13292               (plusminus:SI
13293                 (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
13294                 (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
13295             (vec_concat:V2SI
13296               (plusminus:SI
13297                 (vec_select:SI (match_dup 1) (parallel [(const_int 4)]))
13298                 (vec_select:SI (match_dup 1) (parallel [(const_int 5)])))
13299               (plusminus:SI
13300                 (vec_select:SI (match_dup 1) (parallel [(const_int 6)]))
13301                 (vec_select:SI (match_dup 1) (parallel [(const_int 7)])))))
13302           (vec_concat:V4SI
13303             (vec_concat:V2SI
13304               (plusminus:SI
13305                 (vec_select:SI
13306                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
13307                   (parallel [(const_int 0)]))
13308                 (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
13309               (plusminus:SI
13310                 (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
13311                 (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))
13312             (vec_concat:V2SI
13313               (plusminus:SI
13314                 (vec_select:SI (match_dup 2) (parallel [(const_int 4)]))
13315                 (vec_select:SI (match_dup 2) (parallel [(const_int 5)])))
13316               (plusminus:SI
13317                 (vec_select:SI (match_dup 2) (parallel [(const_int 6)]))
13318                 (vec_select:SI (match_dup 2) (parallel [(const_int 7)])))))))]
13319   "TARGET_AVX2"
13320   "vph<plusminus_mnemonic>d\t{%2, %1, %0|%0, %1, %2}"
13321   [(set_attr "type" "sseiadd")
13322    (set_attr "prefix_extra" "1")
13323    (set_attr "prefix" "vex")
13324    (set_attr "mode" "OI")])
13325
13326 (define_insn "ssse3_ph<plusminus_mnemonic>dv4si3"
13327   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
13328         (vec_concat:V4SI
13329           (vec_concat:V2SI
13330             (plusminus:SI
13331               (vec_select:SI
13332                 (match_operand:V4SI 1 "register_operand" "0,x")
13333                 (parallel [(const_int 0)]))
13334               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
13335             (plusminus:SI
13336               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
13337               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
13338           (vec_concat:V2SI
13339             (plusminus:SI
13340               (vec_select:SI
13341                 (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
13342                 (parallel [(const_int 0)]))
13343               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
13344             (plusminus:SI
13345               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
13346               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
13347   "TARGET_SSSE3"
13348   "@
13349    ph<plusminus_mnemonic>d\t{%2, %0|%0, %2}
13350    vph<plusminus_mnemonic>d\t{%2, %1, %0|%0, %1, %2}"
13351   [(set_attr "isa" "noavx,avx")
13352    (set_attr "type" "sseiadd")
13353    (set_attr "atom_unit" "complex")
13354    (set_attr "prefix_data16" "1,*")
13355    (set_attr "prefix_extra" "1")
13356    (set_attr "prefix" "orig,vex")
13357    (set_attr "mode" "TI")])
13358
13359 (define_insn "ssse3_ph<plusminus_mnemonic>dv2si3"
13360   [(set (match_operand:V2SI 0 "register_operand" "=y")
13361         (vec_concat:V2SI
13362           (plusminus:SI
13363             (vec_select:SI
13364               (match_operand:V2SI 1 "register_operand" "0")
13365               (parallel [(const_int 0)]))
13366             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
13367           (plusminus:SI
13368             (vec_select:SI
13369               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
13370               (parallel [(const_int 0)]))
13371             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
13372   "TARGET_SSSE3"
13373   "ph<plusminus_mnemonic>d\t{%2, %0|%0, %2}"
13374   [(set_attr "type" "sseiadd")
13375    (set_attr "atom_unit" "complex")
13376    (set_attr "prefix_extra" "1")
13377    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
13378    (set_attr "mode" "DI")])
13379
13380 (define_insn "avx2_pmaddubsw256"
13381   [(set (match_operand:V16HI 0 "register_operand" "=x")
13382         (ss_plus:V16HI
13383           (mult:V16HI
13384             (zero_extend:V16HI
13385               (vec_select:V16QI
13386                 (match_operand:V32QI 1 "register_operand" "x")
13387                 (parallel [(const_int 0) (const_int 2)
13388                            (const_int 4) (const_int 6)
13389                            (const_int 8) (const_int 10)
13390                            (const_int 12) (const_int 14)
13391                            (const_int 16) (const_int 18)
13392                            (const_int 20) (const_int 22)
13393                            (const_int 24) (const_int 26)
13394                            (const_int 28) (const_int 30)])))
13395             (sign_extend:V16HI
13396               (vec_select:V16QI
13397                 (match_operand:V32QI 2 "nonimmediate_operand" "xm")
13398                 (parallel [(const_int 0) (const_int 2)
13399                            (const_int 4) (const_int 6)
13400                            (const_int 8) (const_int 10)
13401                            (const_int 12) (const_int 14)
13402                            (const_int 16) (const_int 18)
13403                            (const_int 20) (const_int 22)
13404                            (const_int 24) (const_int 26)
13405                            (const_int 28) (const_int 30)]))))
13406           (mult:V16HI
13407             (zero_extend:V16HI
13408               (vec_select:V16QI (match_dup 1)
13409                 (parallel [(const_int 1) (const_int 3)
13410                            (const_int 5) (const_int 7)
13411                            (const_int 9) (const_int 11)
13412                            (const_int 13) (const_int 15)
13413                            (const_int 17) (const_int 19)
13414                            (const_int 21) (const_int 23)
13415                            (const_int 25) (const_int 27)
13416                            (const_int 29) (const_int 31)])))
13417             (sign_extend:V16HI
13418               (vec_select:V16QI (match_dup 2)
13419                 (parallel [(const_int 1) (const_int 3)
13420                            (const_int 5) (const_int 7)
13421                            (const_int 9) (const_int 11)
13422                            (const_int 13) (const_int 15)
13423                            (const_int 17) (const_int 19)
13424                            (const_int 21) (const_int 23)
13425                            (const_int 25) (const_int 27)
13426                            (const_int 29) (const_int 31)]))))))]
13427   "TARGET_AVX2"
13428   "vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
13429   [(set_attr "type" "sseiadd")
13430    (set_attr "prefix_extra" "1")
13431    (set_attr "prefix" "vex")
13432    (set_attr "mode" "OI")])
13433
13434 ;; The correct representation for this is absolutely enormous, and
13435 ;; surely not generally useful.
13436 (define_insn "avx512bw_pmaddubsw512<mode><mask_name>"
13437   [(set (match_operand:VI2_AVX512VL 0 "register_operand" "=v")
13438           (unspec:VI2_AVX512VL
13439             [(match_operand:<dbpsadbwmode> 1 "register_operand" "v")
13440              (match_operand:<dbpsadbwmode> 2 "nonimmediate_operand" "vm")]
13441              UNSPEC_PMADDUBSW512))]
13442    "TARGET_AVX512BW"
13443    "vpmaddubsw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}";
13444   [(set_attr "type" "sseiadd")
13445    (set_attr "prefix" "evex")
13446    (set_attr "mode" "XI")])
13447
13448 (define_insn "avx512bw_umulhrswv32hi3<mask_name>"
13449   [(set (match_operand:V32HI 0 "register_operand" "=v")
13450         (truncate:V32HI
13451           (lshiftrt:V32SI
13452             (plus:V32SI
13453               (lshiftrt:V32SI
13454                 (mult:V32SI
13455                   (sign_extend:V32SI
13456                     (match_operand:V32HI 1 "nonimmediate_operand" "%v"))
13457                   (sign_extend:V32SI
13458                     (match_operand:V32HI 2 "nonimmediate_operand" "vm")))
13459                 (const_int 14))
13460               (const_vector:V32HI [(const_int 1) (const_int 1)
13461                                    (const_int 1) (const_int 1)
13462                                    (const_int 1) (const_int 1)
13463                                    (const_int 1) (const_int 1)
13464                                    (const_int 1) (const_int 1)
13465                                    (const_int 1) (const_int 1)
13466                                    (const_int 1) (const_int 1)
13467                                    (const_int 1) (const_int 1)
13468                                    (const_int 1) (const_int 1)
13469                                    (const_int 1) (const_int 1)
13470                                    (const_int 1) (const_int 1)
13471                                    (const_int 1) (const_int 1)
13472                                    (const_int 1) (const_int 1)
13473                                    (const_int 1) (const_int 1)
13474                                    (const_int 1) (const_int 1)
13475                                    (const_int 1) (const_int 1)]))
13476             (const_int 1))))]
13477   "TARGET_AVX512BW"
13478   "vpmulhrsw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
13479   [(set_attr "type" "sseimul")
13480    (set_attr "prefix" "evex")
13481    (set_attr "mode" "XI")])
13482
13483 (define_insn "ssse3_pmaddubsw128"
13484   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
13485         (ss_plus:V8HI
13486           (mult:V8HI
13487             (zero_extend:V8HI
13488               (vec_select:V8QI
13489                 (match_operand:V16QI 1 "register_operand" "0,x")
13490                 (parallel [(const_int 0) (const_int 2)
13491                            (const_int 4) (const_int 6)
13492                            (const_int 8) (const_int 10)
13493                            (const_int 12) (const_int 14)])))
13494             (sign_extend:V8HI
13495               (vec_select:V8QI
13496                 (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")
13497                 (parallel [(const_int 0) (const_int 2)
13498                            (const_int 4) (const_int 6)
13499                            (const_int 8) (const_int 10)
13500                            (const_int 12) (const_int 14)]))))
13501           (mult:V8HI
13502             (zero_extend:V8HI
13503               (vec_select:V8QI (match_dup 1)
13504                 (parallel [(const_int 1) (const_int 3)
13505                            (const_int 5) (const_int 7)
13506                            (const_int 9) (const_int 11)
13507                            (const_int 13) (const_int 15)])))
13508             (sign_extend:V8HI
13509               (vec_select:V8QI (match_dup 2)
13510                 (parallel [(const_int 1) (const_int 3)
13511                            (const_int 5) (const_int 7)
13512                            (const_int 9) (const_int 11)
13513                            (const_int 13) (const_int 15)]))))))]
13514   "TARGET_SSSE3"
13515   "@
13516    pmaddubsw\t{%2, %0|%0, %2}
13517    vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
13518   [(set_attr "isa" "noavx,avx")
13519    (set_attr "type" "sseiadd")
13520    (set_attr "atom_unit" "simul")
13521    (set_attr "prefix_data16" "1,*")
13522    (set_attr "prefix_extra" "1")
13523    (set_attr "prefix" "orig,vex")
13524    (set_attr "mode" "TI")])
13525
13526 (define_insn "ssse3_pmaddubsw"
13527   [(set (match_operand:V4HI 0 "register_operand" "=y")
13528         (ss_plus:V4HI
13529           (mult:V4HI
13530             (zero_extend:V4HI
13531               (vec_select:V4QI
13532                 (match_operand:V8QI 1 "register_operand" "0")
13533                 (parallel [(const_int 0) (const_int 2)
13534                            (const_int 4) (const_int 6)])))
13535             (sign_extend:V4HI
13536               (vec_select:V4QI
13537                 (match_operand:V8QI 2 "nonimmediate_operand" "ym")
13538                 (parallel [(const_int 0) (const_int 2)
13539                            (const_int 4) (const_int 6)]))))
13540           (mult:V4HI
13541             (zero_extend:V4HI
13542               (vec_select:V4QI (match_dup 1)
13543                 (parallel [(const_int 1) (const_int 3)
13544                            (const_int 5) (const_int 7)])))
13545             (sign_extend:V4HI
13546               (vec_select:V4QI (match_dup 2)
13547                 (parallel [(const_int 1) (const_int 3)
13548                            (const_int 5) (const_int 7)]))))))]
13549   "TARGET_SSSE3"
13550   "pmaddubsw\t{%2, %0|%0, %2}"
13551   [(set_attr "type" "sseiadd")
13552    (set_attr "atom_unit" "simul")
13553    (set_attr "prefix_extra" "1")
13554    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
13555    (set_attr "mode" "DI")])
13556
13557 (define_mode_iterator PMULHRSW
13558   [V4HI V8HI (V16HI "TARGET_AVX2")])
13559
13560 (define_expand "<ssse3_avx2>_pmulhrsw<mode>3_mask"
13561   [(set (match_operand:PMULHRSW 0 "register_operand")
13562         (vec_merge:PMULHRSW
13563           (truncate:PMULHRSW
13564             (lshiftrt:<ssedoublemode>
13565               (plus:<ssedoublemode>
13566                 (lshiftrt:<ssedoublemode>
13567                   (mult:<ssedoublemode>
13568                     (sign_extend:<ssedoublemode>
13569                       (match_operand:PMULHRSW 1 "nonimmediate_operand"))
13570                     (sign_extend:<ssedoublemode>
13571                       (match_operand:PMULHRSW 2 "nonimmediate_operand")))
13572                   (const_int 14))
13573                 (match_dup 5))
13574               (const_int 1)))
13575           (match_operand:PMULHRSW 3 "register_operand")
13576           (match_operand:<avx512fmaskmode> 4 "register_operand")))]
13577   "TARGET_AVX512BW && TARGET_AVX512VL"
13578 {
13579   operands[5] = CONST1_RTX(<MODE>mode);
13580   ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);
13581 })
13582
13583 (define_expand "<ssse3_avx2>_pmulhrsw<mode>3"
13584   [(set (match_operand:PMULHRSW 0 "register_operand")
13585         (truncate:PMULHRSW
13586           (lshiftrt:<ssedoublemode>
13587             (plus:<ssedoublemode>
13588               (lshiftrt:<ssedoublemode>
13589                 (mult:<ssedoublemode>
13590                   (sign_extend:<ssedoublemode>
13591                     (match_operand:PMULHRSW 1 "nonimmediate_operand"))
13592                   (sign_extend:<ssedoublemode>
13593                     (match_operand:PMULHRSW 2 "nonimmediate_operand")))
13594                 (const_int 14))
13595               (match_dup 3))
13596             (const_int 1))))]
13597   "TARGET_AVX2"
13598 {
13599   operands[3] = CONST1_RTX(<MODE>mode);
13600   ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);
13601 })
13602
13603 (define_insn "*<ssse3_avx2>_pmulhrsw<mode>3<mask_name>"
13604   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,v")
13605         (truncate:VI2_AVX2
13606           (lshiftrt:<ssedoublemode>
13607             (plus:<ssedoublemode>
13608               (lshiftrt:<ssedoublemode>
13609                 (mult:<ssedoublemode>
13610                   (sign_extend:<ssedoublemode>
13611                     (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,v"))
13612                   (sign_extend:<ssedoublemode>
13613                     (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,vm")))
13614                 (const_int 14))
13615               (match_operand:VI2_AVX2 3 "const1_operand"))
13616             (const_int 1))))]
13617   "TARGET_SSSE3 && <mask_mode512bit_condition> && <mask_avx512bw_condition>
13618    && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
13619   "@
13620    pmulhrsw\t{%2, %0|%0, %2}
13621    vpmulhrsw\t{%2, %1, %0<mask_operand4>|%0<mask_operand4>, %1, %2}"
13622   [(set_attr "isa" "noavx,avx")
13623    (set_attr "type" "sseimul")
13624    (set_attr "prefix_data16" "1,*")
13625    (set_attr "prefix_extra" "1")
13626    (set_attr "prefix" "orig,maybe_evex")
13627    (set_attr "mode" "<sseinsnmode>")])
13628
13629 (define_insn "*ssse3_pmulhrswv4hi3"
13630   [(set (match_operand:V4HI 0 "register_operand" "=y")
13631         (truncate:V4HI
13632           (lshiftrt:V4SI
13633             (plus:V4SI
13634               (lshiftrt:V4SI
13635                 (mult:V4SI
13636                   (sign_extend:V4SI
13637                     (match_operand:V4HI 1 "nonimmediate_operand" "%0"))
13638                   (sign_extend:V4SI
13639                     (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
13640                 (const_int 14))
13641               (match_operand:V4HI 3 "const1_operand"))
13642             (const_int 1))))]
13643   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V4HImode, operands)"
13644   "pmulhrsw\t{%2, %0|%0, %2}"
13645   [(set_attr "type" "sseimul")
13646    (set_attr "prefix_extra" "1")
13647    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
13648    (set_attr "mode" "DI")])
13649
13650 (define_insn "<ssse3_avx2>_pshufb<mode>3<mask_name>"
13651   [(set (match_operand:VI1_AVX512 0 "register_operand" "=x,v")
13652         (unspec:VI1_AVX512
13653           [(match_operand:VI1_AVX512 1 "register_operand" "0,v")
13654            (match_operand:VI1_AVX512 2 "nonimmediate_operand" "xm,vm")]
13655           UNSPEC_PSHUFB))]
13656   "TARGET_SSSE3 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
13657   "@
13658    pshufb\t{%2, %0|%0, %2}
13659    vpshufb\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
13660   [(set_attr "isa" "noavx,avx")
13661    (set_attr "type" "sselog1")
13662    (set_attr "prefix_data16" "1,*")
13663    (set_attr "prefix_extra" "1")
13664    (set_attr "prefix" "orig,maybe_evex")
13665    (set_attr "btver2_decode" "vector,vector")
13666    (set_attr "mode" "<sseinsnmode>")])
13667
13668 (define_insn "ssse3_pshufbv8qi3"
13669   [(set (match_operand:V8QI 0 "register_operand" "=y")
13670         (unspec:V8QI [(match_operand:V8QI 1 "register_operand" "0")
13671                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")]
13672                      UNSPEC_PSHUFB))]
13673   "TARGET_SSSE3"
13674   "pshufb\t{%2, %0|%0, %2}";
13675   [(set_attr "type" "sselog1")
13676    (set_attr "prefix_extra" "1")
13677    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
13678    (set_attr "mode" "DI")])
13679
13680 (define_insn "<ssse3_avx2>_psign<mode>3"
13681   [(set (match_operand:VI124_AVX2 0 "register_operand" "=x,x")
13682         (unspec:VI124_AVX2
13683           [(match_operand:VI124_AVX2 1 "register_operand" "0,x")
13684            (match_operand:VI124_AVX2 2 "nonimmediate_operand" "xm,xm")]
13685           UNSPEC_PSIGN))]
13686   "TARGET_SSSE3"
13687   "@
13688    psign<ssemodesuffix>\t{%2, %0|%0, %2}
13689    vpsign<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
13690   [(set_attr "isa" "noavx,avx")
13691    (set_attr "type" "sselog1")
13692    (set_attr "prefix_data16" "1,*")
13693    (set_attr "prefix_extra" "1")
13694    (set_attr "prefix" "orig,vex")
13695    (set_attr "mode" "<sseinsnmode>")])
13696
13697 (define_insn "ssse3_psign<mode>3"
13698   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
13699         (unspec:MMXMODEI
13700           [(match_operand:MMXMODEI 1 "register_operand" "0")
13701            (match_operand:MMXMODEI 2 "nonimmediate_operand" "ym")]
13702           UNSPEC_PSIGN))]
13703   "TARGET_SSSE3"
13704   "psign<mmxvecsize>\t{%2, %0|%0, %2}";
13705   [(set_attr "type" "sselog1")
13706    (set_attr "prefix_extra" "1")
13707    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
13708    (set_attr "mode" "DI")])
13709
13710 (define_insn "<ssse3_avx2>_palignr<mode>_mask"
13711   [(set (match_operand:VI1_AVX512 0 "register_operand" "=v")
13712         (vec_merge:VI1_AVX512
13713           (unspec:VI1_AVX512
13714             [(match_operand:VI1_AVX512 1 "register_operand" "v")
13715              (match_operand:VI1_AVX512 2 "nonimmediate_operand" "vm")
13716              (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n")]
13717             UNSPEC_PALIGNR)
13718         (match_operand:VI1_AVX512 4 "vector_move_operand" "0C")
13719         (match_operand:<avx512fmaskmode> 5 "register_operand" "Yk")))]
13720   "TARGET_AVX512BW && (<MODE_SIZE> == 64 || TARGET_AVX512VL)"
13721 {
13722   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
13723   return "vpalignr\t{%3, %2, %1, %0%{%5%}%N4|%0%{%5%}%N4, %1, %2, %3}";
13724 }
13725   [(set_attr "type" "sseishft")
13726    (set_attr "atom_unit" "sishuf")
13727    (set_attr "prefix_extra" "1")
13728    (set_attr "length_immediate" "1")
13729    (set_attr "prefix" "evex")
13730    (set_attr "mode" "<sseinsnmode>")])
13731
13732 (define_insn "<ssse3_avx2>_palignr<mode>"
13733   [(set (match_operand:SSESCALARMODE 0 "register_operand" "=x,v")
13734         (unspec:SSESCALARMODE
13735           [(match_operand:SSESCALARMODE 1 "register_operand" "0,v")
13736            (match_operand:SSESCALARMODE 2 "nonimmediate_operand" "xm,vm")
13737            (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n,n")]
13738           UNSPEC_PALIGNR))]
13739   "TARGET_SSSE3"
13740 {
13741   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
13742
13743   switch (which_alternative)
13744     {
13745     case 0:
13746       return "palignr\t{%3, %2, %0|%0, %2, %3}";
13747     case 1:
13748       return "vpalignr\t{%3, %2, %1, %0|%0, %1, %2, %3}";
13749     default:
13750       gcc_unreachable ();
13751     }
13752 }
13753   [(set_attr "isa" "noavx,avx")
13754    (set_attr "type" "sseishft")
13755    (set_attr "atom_unit" "sishuf")
13756    (set_attr "prefix_data16" "1,*")
13757    (set_attr "prefix_extra" "1")
13758    (set_attr "length_immediate" "1")
13759    (set_attr "prefix" "orig,vex")
13760    (set_attr "mode" "<sseinsnmode>")])
13761
13762 (define_insn "ssse3_palignrdi"
13763   [(set (match_operand:DI 0 "register_operand" "=y")
13764         (unspec:DI [(match_operand:DI 1 "register_operand" "0")
13765                     (match_operand:DI 2 "nonimmediate_operand" "ym")
13766                     (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n")]
13767                    UNSPEC_PALIGNR))]
13768   "TARGET_SSSE3"
13769 {
13770   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
13771   return "palignr\t{%3, %2, %0|%0, %2, %3}";
13772 }
13773   [(set_attr "type" "sseishft")
13774    (set_attr "atom_unit" "sishuf")
13775    (set_attr "prefix_extra" "1")
13776    (set_attr "length_immediate" "1")
13777    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
13778    (set_attr "mode" "DI")])
13779
13780 ;; Mode iterator to handle singularity w/ absence of V2DI and V4DI
13781 ;; modes for abs instruction on pre AVX-512 targets.
13782 (define_mode_iterator VI1248_AVX512VL_AVX512BW
13783   [(V64QI "TARGET_AVX512BW") (V32QI "TARGET_AVX2") V16QI
13784    (V32HI "TARGET_AVX512BW") (V16HI "TARGET_AVX2") V8HI
13785    (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX2") V4SI
13786    (V8DI "TARGET_AVX512F") (V4DI "TARGET_AVX512VL") (V2DI "TARGET_AVX512VL")])
13787
13788 (define_insn "*abs<mode>2"
13789   [(set (match_operand:VI1248_AVX512VL_AVX512BW 0 "register_operand" "=v")
13790         (abs:VI1248_AVX512VL_AVX512BW
13791           (match_operand:VI1248_AVX512VL_AVX512BW 1 "nonimmediate_operand" "vm")))]
13792   "TARGET_SSSE3"
13793   "%vpabs<ssemodesuffix>\t{%1, %0|%0, %1}"
13794   [(set_attr "type" "sselog1")
13795    (set_attr "prefix_data16" "1")
13796    (set_attr "prefix_extra" "1")
13797    (set_attr "prefix" "maybe_vex")
13798    (set_attr "mode" "<sseinsnmode>")])
13799
13800 (define_insn "abs<mode>2_mask"
13801   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
13802         (vec_merge:VI48_AVX512VL
13803           (abs:VI48_AVX512VL
13804             (match_operand:VI48_AVX512VL 1 "nonimmediate_operand" "vm"))
13805           (match_operand:VI48_AVX512VL 2 "vector_move_operand" "0C")
13806           (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk")))]
13807   "TARGET_AVX512F"
13808   "vpabs<ssemodesuffix>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
13809   [(set_attr "type" "sselog1")
13810    (set_attr "prefix" "evex")
13811    (set_attr "mode" "<sseinsnmode>")])
13812
13813 (define_insn "abs<mode>2_mask"
13814   [(set (match_operand:VI12_AVX512VL 0 "register_operand" "=v")
13815         (vec_merge:VI12_AVX512VL
13816           (abs:VI12_AVX512VL
13817             (match_operand:VI12_AVX512VL 1 "nonimmediate_operand" "vm"))
13818           (match_operand:VI12_AVX512VL 2 "vector_move_operand" "0C")
13819           (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk")))]
13820   "TARGET_AVX512BW"
13821   "vpabs<ssemodesuffix>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
13822   [(set_attr "type" "sselog1")
13823    (set_attr "prefix" "evex")
13824    (set_attr "mode" "<sseinsnmode>")])
13825
13826 (define_expand "abs<mode>2"
13827   [(set (match_operand:VI1248_AVX512VL_AVX512BW 0 "register_operand")
13828         (abs:VI1248_AVX512VL_AVX512BW
13829           (match_operand:VI1248_AVX512VL_AVX512BW 1 "nonimmediate_operand")))]
13830   "TARGET_SSE2"
13831 {
13832   if (!TARGET_SSSE3)
13833     {
13834       ix86_expand_sse2_abs (operands[0], operands[1]);
13835       DONE;
13836     }
13837 })
13838
13839 (define_insn "abs<mode>2"
13840   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
13841         (abs:MMXMODEI
13842           (match_operand:MMXMODEI 1 "nonimmediate_operand" "ym")))]
13843   "TARGET_SSSE3"
13844   "pabs<mmxvecsize>\t{%1, %0|%0, %1}";
13845   [(set_attr "type" "sselog1")
13846    (set_attr "prefix_rep" "0")
13847    (set_attr "prefix_extra" "1")
13848    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
13849    (set_attr "mode" "DI")])
13850
13851 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13852 ;;
13853 ;; AMD SSE4A instructions
13854 ;;
13855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13856
13857 (define_insn "sse4a_movnt<mode>"
13858   [(set (match_operand:MODEF 0 "memory_operand" "=m")
13859         (unspec:MODEF
13860           [(match_operand:MODEF 1 "register_operand" "x")]
13861           UNSPEC_MOVNT))]
13862   "TARGET_SSE4A"
13863   "movnt<ssemodesuffix>\t{%1, %0|%0, %1}"
13864   [(set_attr "type" "ssemov")
13865    (set_attr "mode" "<MODE>")])
13866
13867 (define_insn "sse4a_vmmovnt<mode>"
13868   [(set (match_operand:<ssescalarmode> 0 "memory_operand" "=m")
13869         (unspec:<ssescalarmode>
13870           [(vec_select:<ssescalarmode>
13871              (match_operand:VF_128 1 "register_operand" "x")
13872              (parallel [(const_int 0)]))]
13873           UNSPEC_MOVNT))]
13874   "TARGET_SSE4A"
13875   "movnt<ssescalarmodesuffix>\t{%1, %0|%0, %1}"
13876   [(set_attr "type" "ssemov")
13877    (set_attr "mode" "<ssescalarmode>")])
13878
13879 (define_insn "sse4a_extrqi"
13880   [(set (match_operand:V2DI 0 "register_operand" "=x")
13881         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
13882                       (match_operand 2 "const_0_to_255_operand")
13883                       (match_operand 3 "const_0_to_255_operand")]
13884                      UNSPEC_EXTRQI))]
13885   "TARGET_SSE4A"
13886   "extrq\t{%3, %2, %0|%0, %2, %3}"
13887   [(set_attr "type" "sse")
13888    (set_attr "prefix_data16" "1")
13889    (set_attr "length_immediate" "2")
13890    (set_attr "mode" "TI")])
13891
13892 (define_insn "sse4a_extrq"
13893   [(set (match_operand:V2DI 0 "register_operand" "=x")
13894         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
13895                       (match_operand:V16QI 2 "register_operand" "x")]
13896                      UNSPEC_EXTRQ))]
13897   "TARGET_SSE4A"
13898   "extrq\t{%2, %0|%0, %2}"
13899   [(set_attr "type" "sse")
13900    (set_attr "prefix_data16" "1")
13901    (set_attr "mode" "TI")])
13902
13903 (define_insn "sse4a_insertqi"
13904   [(set (match_operand:V2DI 0 "register_operand" "=x")
13905         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
13906                       (match_operand:V2DI 2 "register_operand" "x")
13907                       (match_operand 3 "const_0_to_255_operand")
13908                       (match_operand 4 "const_0_to_255_operand")]
13909                      UNSPEC_INSERTQI))]
13910   "TARGET_SSE4A"
13911   "insertq\t{%4, %3, %2, %0|%0, %2, %3, %4}"
13912   [(set_attr "type" "sseins")
13913    (set_attr "prefix_data16" "0")
13914    (set_attr "prefix_rep" "1")
13915    (set_attr "length_immediate" "2")
13916    (set_attr "mode" "TI")])
13917
13918 (define_insn "sse4a_insertq"
13919   [(set (match_operand:V2DI 0 "register_operand" "=x")
13920         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
13921                       (match_operand:V2DI 2 "register_operand" "x")]
13922                      UNSPEC_INSERTQ))]
13923   "TARGET_SSE4A"
13924   "insertq\t{%2, %0|%0, %2}"
13925   [(set_attr "type" "sseins")
13926    (set_attr "prefix_data16" "0")
13927    (set_attr "prefix_rep" "1")
13928    (set_attr "mode" "TI")])
13929
13930 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13931 ;;
13932 ;; Intel SSE4.1 instructions
13933 ;;
13934 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13935
13936 ;; Mapping of immediate bits for blend instructions
13937 (define_mode_attr blendbits
13938   [(V8SF "255") (V4SF "15") (V4DF "15") (V2DF "3")])
13939
13940 (define_insn "<sse4_1>_blend<ssemodesuffix><avxsizesuffix>"
13941   [(set (match_operand:VF_128_256 0 "register_operand" "=Yr,*x,x")
13942         (vec_merge:VF_128_256
13943           (match_operand:VF_128_256 2 "nonimmediate_operand" "Yrm,*xm,xm")
13944           (match_operand:VF_128_256 1 "register_operand" "0,0,x")
13945           (match_operand:SI 3 "const_0_to_<blendbits>_operand")))]
13946   "TARGET_SSE4_1"
13947   "@
13948    blend<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
13949    blend<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
13950    vblend<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
13951   [(set_attr "isa" "noavx,noavx,avx")
13952    (set_attr "type" "ssemov")
13953    (set_attr "length_immediate" "1")
13954    (set_attr "prefix_data16" "1,1,*")
13955    (set_attr "prefix_extra" "1")
13956    (set_attr "prefix" "orig,orig,vex")
13957    (set_attr "mode" "<MODE>")])
13958
13959 (define_insn "<sse4_1>_blendv<ssemodesuffix><avxsizesuffix>"
13960   [(set (match_operand:VF_128_256 0 "register_operand" "=Yr,*x,x")
13961         (unspec:VF_128_256
13962           [(match_operand:VF_128_256 1 "register_operand" "0,0,x")
13963            (match_operand:VF_128_256 2 "nonimmediate_operand" "Yrm,*xm,xm")
13964            (match_operand:VF_128_256 3 "register_operand" "Yz,Yz,x")]
13965           UNSPEC_BLENDV))]
13966   "TARGET_SSE4_1"
13967   "@
13968    blendv<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
13969    blendv<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
13970    vblendv<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
13971   [(set_attr "isa" "noavx,noavx,avx")
13972    (set_attr "type" "ssemov")
13973    (set_attr "length_immediate" "1")
13974    (set_attr "prefix_data16" "1,1,*")
13975    (set_attr "prefix_extra" "1")
13976    (set_attr "prefix" "orig,orig,vex")
13977    (set_attr "btver2_decode" "vector,vector,vector") 
13978    (set_attr "mode" "<MODE>")])
13979
13980 (define_insn "<sse4_1>_dp<ssemodesuffix><avxsizesuffix>"
13981   [(set (match_operand:VF_128_256 0 "register_operand" "=Yr,*x,x")
13982         (unspec:VF_128_256
13983           [(match_operand:VF_128_256 1 "nonimmediate_operand" "%0,0,x")
13984            (match_operand:VF_128_256 2 "nonimmediate_operand" "Yrm,*xm,xm")
13985            (match_operand:SI 3 "const_0_to_255_operand" "n,n,n")]
13986           UNSPEC_DP))]
13987   "TARGET_SSE4_1"
13988   "@
13989    dp<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
13990    dp<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
13991    vdp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
13992   [(set_attr "isa" "noavx,noavx,avx")
13993    (set_attr "type" "ssemul")
13994    (set_attr "length_immediate" "1")
13995    (set_attr "prefix_data16" "1,1,*")
13996    (set_attr "prefix_extra" "1")
13997    (set_attr "prefix" "orig,orig,vex")
13998    (set_attr "btver2_decode" "vector,vector,vector")
13999    (set_attr "mode" "<MODE>")])
14000
14001 ;; Mode attribute used by `vmovntdqa' pattern
14002 (define_mode_attr vi8_sse4_1_avx2_avx512
14003    [(V2DI "sse4_1") (V4DI "avx2") (V8DI "avx512f")])
14004
14005 (define_insn "<vi8_sse4_1_avx2_avx512>_movntdqa"
14006   [(set (match_operand:VI8_AVX2_AVX512F 0 "register_operand" "=Yr,*x, v")
14007         (unspec:VI8_AVX2_AVX512F [(match_operand:VI8_AVX2_AVX512F 1 "memory_operand" "m, m, m")]
14008                      UNSPEC_MOVNTDQA))]
14009   "TARGET_SSE4_1"
14010   "%vmovntdqa\t{%1, %0|%0, %1}"
14011   [(set_attr "type" "ssemov")
14012    (set_attr "prefix_extra" "1,1,*")
14013    (set_attr "prefix" "maybe_vex,maybe_vex,evex")
14014    (set_attr "mode" "<sseinsnmode>")])
14015
14016 (define_insn "<sse4_1_avx2>_mpsadbw"
14017   [(set (match_operand:VI1_AVX2 0 "register_operand" "=Yr,*x,x")
14018         (unspec:VI1_AVX2
14019           [(match_operand:VI1_AVX2 1 "register_operand" "0,0,x")
14020            (match_operand:VI1_AVX2 2 "nonimmediate_operand" "Yrm,*xm,xm")
14021            (match_operand:SI 3 "const_0_to_255_operand" "n,n,n")]
14022           UNSPEC_MPSADBW))]
14023   "TARGET_SSE4_1"
14024   "@
14025    mpsadbw\t{%3, %2, %0|%0, %2, %3}
14026    mpsadbw\t{%3, %2, %0|%0, %2, %3}
14027    vmpsadbw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
14028   [(set_attr "isa" "noavx,noavx,avx")
14029    (set_attr "type" "sselog1")
14030    (set_attr "length_immediate" "1")
14031    (set_attr "prefix_extra" "1")
14032    (set_attr "prefix" "orig,orig,vex")
14033    (set_attr "btver2_decode" "vector,vector,vector")
14034    (set_attr "mode" "<sseinsnmode>")])
14035
14036 (define_insn "<sse4_1_avx2>_packusdw<mask_name>"
14037   [(set (match_operand:VI2_AVX2 0 "register_operand" "=Yr,*x,v")
14038         (vec_concat:VI2_AVX2
14039           (us_truncate:<ssehalfvecmode>
14040             (match_operand:<sseunpackmode> 1 "register_operand" "0,0,v"))
14041           (us_truncate:<ssehalfvecmode>
14042             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "Yrm,*xm,vm"))))]
14043   "TARGET_SSE4_1 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
14044   "@
14045    packusdw\t{%2, %0|%0, %2}
14046    packusdw\t{%2, %0|%0, %2}
14047    vpackusdw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
14048   [(set_attr "isa" "noavx,noavx,avx")
14049    (set_attr "type" "sselog")
14050    (set_attr "prefix_extra" "1")
14051    (set_attr "prefix" "orig,orig,maybe_evex")
14052    (set_attr "mode" "<sseinsnmode>")])
14053
14054 (define_insn "<sse4_1_avx2>_pblendvb"
14055   [(set (match_operand:VI1_AVX2 0 "register_operand" "=Yr,*x,x")
14056         (unspec:VI1_AVX2
14057           [(match_operand:VI1_AVX2 1 "register_operand"  "0,0,x")
14058            (match_operand:VI1_AVX2 2 "nonimmediate_operand" "Yrm,*xm,xm")
14059            (match_operand:VI1_AVX2 3 "register_operand" "Yz,Yz,x")]
14060           UNSPEC_BLENDV))]
14061   "TARGET_SSE4_1"
14062   "@
14063    pblendvb\t{%3, %2, %0|%0, %2, %3}
14064    pblendvb\t{%3, %2, %0|%0, %2, %3}
14065    vpblendvb\t{%3, %2, %1, %0|%0, %1, %2, %3}"
14066   [(set_attr "isa" "noavx,noavx,avx")
14067    (set_attr "type" "ssemov")
14068    (set_attr "prefix_extra" "1")
14069    (set_attr "length_immediate" "*,*,1")
14070    (set_attr "prefix" "orig,orig,vex")
14071    (set_attr "btver2_decode" "vector,vector,vector")
14072    (set_attr "mode" "<sseinsnmode>")])
14073
14074 (define_insn "sse4_1_pblendw"
14075   [(set (match_operand:V8HI 0 "register_operand" "=Yr,*x,x")
14076         (vec_merge:V8HI
14077           (match_operand:V8HI 2 "nonimmediate_operand" "Yrm,*xm,xm")
14078           (match_operand:V8HI 1 "register_operand" "0,0,x")
14079           (match_operand:SI 3 "const_0_to_255_operand" "n,n,n")))]
14080   "TARGET_SSE4_1"
14081   "@
14082    pblendw\t{%3, %2, %0|%0, %2, %3}
14083    pblendw\t{%3, %2, %0|%0, %2, %3}
14084    vpblendw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
14085   [(set_attr "isa" "noavx,noavx,avx")
14086    (set_attr "type" "ssemov")
14087    (set_attr "prefix_extra" "1")
14088    (set_attr "length_immediate" "1")
14089    (set_attr "prefix" "orig,orig,vex")
14090    (set_attr "mode" "TI")])
14091
14092 ;; The builtin uses an 8-bit immediate.  Expand that.
14093 (define_expand "avx2_pblendw"
14094   [(set (match_operand:V16HI 0 "register_operand")
14095         (vec_merge:V16HI
14096           (match_operand:V16HI 2 "nonimmediate_operand")
14097           (match_operand:V16HI 1 "register_operand")
14098           (match_operand:SI 3 "const_0_to_255_operand")))]
14099   "TARGET_AVX2"
14100 {
14101   HOST_WIDE_INT val = INTVAL (operands[3]) & 0xff;
14102   operands[3] = GEN_INT (val << 8 | val);
14103 })
14104
14105 (define_insn "*avx2_pblendw"
14106   [(set (match_operand:V16HI 0 "register_operand" "=x")
14107         (vec_merge:V16HI
14108           (match_operand:V16HI 2 "nonimmediate_operand" "xm")
14109           (match_operand:V16HI 1 "register_operand" "x")
14110           (match_operand:SI 3 "avx2_pblendw_operand" "n")))]
14111   "TARGET_AVX2"
14112 {
14113   operands[3] = GEN_INT (INTVAL (operands[3]) & 0xff);
14114   return "vpblendw\t{%3, %2, %1, %0|%0, %1, %2, %3}";
14115 }
14116   [(set_attr "type" "ssemov")
14117    (set_attr "prefix_extra" "1")
14118    (set_attr "length_immediate" "1")
14119    (set_attr "prefix" "vex")
14120    (set_attr "mode" "OI")])
14121
14122 (define_insn "avx2_pblendd<mode>"
14123   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x")
14124         (vec_merge:VI4_AVX2
14125           (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm")
14126           (match_operand:VI4_AVX2 1 "register_operand" "x")
14127           (match_operand:SI 3 "const_0_to_255_operand" "n")))]
14128   "TARGET_AVX2"
14129   "vpblendd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
14130   [(set_attr "type" "ssemov")
14131    (set_attr "prefix_extra" "1")
14132    (set_attr "length_immediate" "1")
14133    (set_attr "prefix" "vex")
14134    (set_attr "mode" "<sseinsnmode>")])
14135
14136 (define_insn "sse4_1_phminposuw"
14137   [(set (match_operand:V8HI 0 "register_operand" "=Yr,*x")
14138         (unspec:V8HI [(match_operand:V8HI 1 "nonimmediate_operand" "Yrm,*xm")]
14139                      UNSPEC_PHMINPOSUW))]
14140   "TARGET_SSE4_1"
14141   "%vphminposuw\t{%1, %0|%0, %1}"
14142   [(set_attr "type" "sselog1")
14143    (set_attr "prefix_extra" "1")
14144    (set_attr "prefix" "maybe_vex")
14145    (set_attr "mode" "TI")])
14146
14147 (define_insn "avx2_<code>v16qiv16hi2<mask_name>"
14148   [(set (match_operand:V16HI 0 "register_operand" "=v")
14149         (any_extend:V16HI
14150           (match_operand:V16QI 1 "nonimmediate_operand" "vm")))]
14151   "TARGET_AVX2 && <mask_avx512bw_condition> && <mask_avx512vl_condition>"
14152   "vpmov<extsuffix>bw\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
14153   [(set_attr "type" "ssemov")
14154    (set_attr "prefix_extra" "1")
14155    (set_attr "prefix" "maybe_evex")
14156    (set_attr "mode" "OI")])
14157
14158 (define_insn "avx512bw_<code>v32qiv32hi2<mask_name>"
14159   [(set (match_operand:V32HI 0 "register_operand" "=v")
14160         (any_extend:V32HI
14161           (match_operand:V32QI 1 "nonimmediate_operand" "vm")))]
14162   "TARGET_AVX512BW"
14163   "vpmov<extsuffix>bw\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
14164   [(set_attr "type" "ssemov")
14165    (set_attr "prefix_extra" "1")
14166    (set_attr "prefix" "evex")
14167    (set_attr "mode" "XI")])
14168
14169 (define_insn "sse4_1_<code>v8qiv8hi2<mask_name>"
14170   [(set (match_operand:V8HI 0 "register_operand" "=Yr,*v")
14171         (any_extend:V8HI
14172           (vec_select:V8QI
14173             (match_operand:V16QI 1 "nonimmediate_operand" "Yrm,*vm")
14174             (parallel [(const_int 0) (const_int 1)
14175                        (const_int 2) (const_int 3)
14176                        (const_int 4) (const_int 5)
14177                        (const_int 6) (const_int 7)]))))]
14178   "TARGET_SSE4_1 && <mask_avx512bw_condition> && <mask_avx512vl_condition>"
14179   "%vpmov<extsuffix>bw\t{%1, %0<mask_operand2>|%0<mask_operand2>, %q1}"
14180   [(set_attr "type" "ssemov")
14181    (set_attr "ssememalign" "64")
14182    (set_attr "prefix_extra" "1")
14183    (set_attr "prefix" "maybe_vex")
14184    (set_attr "mode" "TI")])
14185
14186 (define_insn "<mask_codefor>avx512f_<code>v16qiv16si2<mask_name>"
14187   [(set (match_operand:V16SI 0 "register_operand" "=v")
14188         (any_extend:V16SI
14189           (match_operand:V16QI 1 "nonimmediate_operand" "vm")))]
14190   "TARGET_AVX512F"
14191   "vpmov<extsuffix>bd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %q1}"
14192   [(set_attr "type" "ssemov")
14193    (set_attr "prefix" "evex")
14194    (set_attr "mode" "XI")])
14195
14196 (define_insn "avx2_<code>v8qiv8si2<mask_name>"
14197   [(set (match_operand:V8SI 0 "register_operand" "=v")
14198         (any_extend:V8SI
14199           (vec_select:V8QI
14200             (match_operand:V16QI 1 "nonimmediate_operand" "vm")
14201             (parallel [(const_int 0) (const_int 1)
14202                        (const_int 2) (const_int 3)
14203                        (const_int 4) (const_int 5)
14204                        (const_int 6) (const_int 7)]))))]
14205   "TARGET_AVX2 && <mask_avx512vl_condition>"
14206   "vpmov<extsuffix>bd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %q1}"
14207   [(set_attr "type" "ssemov")
14208    (set_attr "prefix_extra" "1")
14209    (set_attr "prefix" "maybe_evex")
14210    (set_attr "mode" "OI")])
14211
14212 (define_insn "sse4_1_<code>v4qiv4si2<mask_name>"
14213   [(set (match_operand:V4SI 0 "register_operand" "=Yr,*v")
14214         (any_extend:V4SI
14215           (vec_select:V4QI
14216             (match_operand:V16QI 1 "nonimmediate_operand" "Yrm,*vm")
14217             (parallel [(const_int 0) (const_int 1)
14218                        (const_int 2) (const_int 3)]))))]
14219   "TARGET_SSE4_1 && <mask_avx512vl_condition>"
14220   "%vpmov<extsuffix>bd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %k1}"
14221   [(set_attr "type" "ssemov")
14222    (set_attr "ssememalign" "32")
14223    (set_attr "prefix_extra" "1")
14224    (set_attr "prefix" "maybe_vex")
14225    (set_attr "mode" "TI")])
14226
14227 (define_insn "avx512f_<code>v16hiv16si2<mask_name>"
14228   [(set (match_operand:V16SI 0 "register_operand" "=v")
14229         (any_extend:V16SI
14230           (match_operand:V16HI 1 "nonimmediate_operand" "vm")))]
14231   "TARGET_AVX512F"
14232   "vpmov<extsuffix>wd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
14233   [(set_attr "type" "ssemov")
14234    (set_attr "prefix" "evex")
14235    (set_attr "mode" "XI")])
14236
14237 (define_insn "avx2_<code>v8hiv8si2<mask_name>"
14238   [(set (match_operand:V8SI 0 "register_operand" "=v")
14239         (any_extend:V8SI
14240             (match_operand:V8HI 1 "nonimmediate_operand" "vm")))]
14241   "TARGET_AVX2 && <mask_avx512vl_condition>"
14242   "vpmov<extsuffix>wd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
14243   [(set_attr "type" "ssemov")
14244    (set_attr "prefix_extra" "1")
14245    (set_attr "prefix" "maybe_evex")
14246    (set_attr "mode" "OI")])
14247
14248 (define_insn "sse4_1_<code>v4hiv4si2<mask_name>"
14249   [(set (match_operand:V4SI 0 "register_operand" "=Yr,*v")
14250         (any_extend:V4SI
14251           (vec_select:V4HI
14252             (match_operand:V8HI 1 "nonimmediate_operand" "Yrm,*vm")
14253             (parallel [(const_int 0) (const_int 1)
14254                        (const_int 2) (const_int 3)]))))]
14255   "TARGET_SSE4_1 && <mask_avx512vl_condition>"
14256   "%vpmov<extsuffix>wd\t{%1, %0<mask_operand2>|%0<mask_operand2>, %q1}"
14257   [(set_attr "type" "ssemov")
14258    (set_attr "ssememalign" "64")
14259    (set_attr "prefix_extra" "1")
14260    (set_attr "prefix" "maybe_vex")
14261    (set_attr "mode" "TI")])
14262
14263 (define_insn "avx512f_<code>v8qiv8di2<mask_name>"
14264   [(set (match_operand:V8DI 0 "register_operand" "=v")
14265         (any_extend:V8DI
14266           (vec_select:V8QI
14267             (match_operand:V16QI 1 "nonimmediate_operand" "vm")
14268             (parallel [(const_int 0) (const_int 1)
14269                        (const_int 2) (const_int 3)
14270                        (const_int 4) (const_int 5)
14271                        (const_int 6) (const_int 7)]))))]
14272   "TARGET_AVX512F"
14273   "vpmov<extsuffix>bq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %k1}"
14274   [(set_attr "type" "ssemov")
14275    (set_attr "prefix" "evex")
14276    (set_attr "mode" "XI")])
14277
14278 (define_insn "avx2_<code>v4qiv4di2<mask_name>"
14279   [(set (match_operand:V4DI 0 "register_operand" "=v")
14280         (any_extend:V4DI
14281           (vec_select:V4QI
14282             (match_operand:V16QI 1 "nonimmediate_operand" "vm")
14283             (parallel [(const_int 0) (const_int 1)
14284                        (const_int 2) (const_int 3)]))))]
14285   "TARGET_AVX2 && <mask_avx512vl_condition>"
14286   "vpmov<extsuffix>bq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %k1}"
14287   [(set_attr "type" "ssemov")
14288    (set_attr "prefix_extra" "1")
14289    (set_attr "prefix" "maybe_evex")
14290    (set_attr "mode" "OI")])
14291
14292 (define_insn "sse4_1_<code>v2qiv2di2<mask_name>"
14293   [(set (match_operand:V2DI 0 "register_operand" "=Yr,*v")
14294         (any_extend:V2DI
14295           (vec_select:V2QI
14296             (match_operand:V16QI 1 "nonimmediate_operand" "Yrm,*vm")
14297             (parallel [(const_int 0) (const_int 1)]))))]
14298   "TARGET_SSE4_1 && <mask_avx512vl_condition>"
14299   "%vpmov<extsuffix>bq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %w1}"
14300   [(set_attr "type" "ssemov")
14301    (set_attr "ssememalign" "16")
14302    (set_attr "prefix_extra" "1")
14303    (set_attr "prefix" "maybe_vex")
14304    (set_attr "mode" "TI")])
14305
14306 (define_insn "avx512f_<code>v8hiv8di2<mask_name>"
14307   [(set (match_operand:V8DI 0 "register_operand" "=v")
14308         (any_extend:V8DI
14309           (match_operand:V8HI 1 "nonimmediate_operand" "vm")))]
14310   "TARGET_AVX512F"
14311   "vpmov<extsuffix>wq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %q1}"
14312   [(set_attr "type" "ssemov")
14313    (set_attr "prefix" "evex")
14314    (set_attr "mode" "XI")])
14315
14316 (define_insn "avx2_<code>v4hiv4di2<mask_name>"
14317   [(set (match_operand:V4DI 0 "register_operand" "=v")
14318         (any_extend:V4DI
14319           (vec_select:V4HI
14320             (match_operand:V8HI 1 "nonimmediate_operand" "vm")
14321             (parallel [(const_int 0) (const_int 1)
14322                        (const_int 2) (const_int 3)]))))]
14323   "TARGET_AVX2 && <mask_avx512vl_condition>"
14324   "vpmov<extsuffix>wq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %q1}"
14325   [(set_attr "type" "ssemov")
14326    (set_attr "prefix_extra" "1")
14327    (set_attr "prefix" "maybe_evex")
14328    (set_attr "mode" "OI")])
14329
14330 (define_insn "sse4_1_<code>v2hiv2di2<mask_name>"
14331   [(set (match_operand:V2DI 0 "register_operand" "=Yr,*v")
14332         (any_extend:V2DI
14333           (vec_select:V2HI
14334             (match_operand:V8HI 1 "nonimmediate_operand" "Yrm,*vm")
14335             (parallel [(const_int 0) (const_int 1)]))))]
14336   "TARGET_SSE4_1 && <mask_avx512vl_condition>"
14337   "%vpmov<extsuffix>wq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %k1}"
14338   [(set_attr "type" "ssemov")
14339    (set_attr "ssememalign" "32")
14340    (set_attr "prefix_extra" "1")
14341    (set_attr "prefix" "maybe_vex")
14342    (set_attr "mode" "TI")])
14343
14344 (define_insn "avx512f_<code>v8siv8di2<mask_name>"
14345   [(set (match_operand:V8DI 0 "register_operand" "=v")
14346         (any_extend:V8DI
14347           (match_operand:V8SI 1 "nonimmediate_operand" "vm")))]
14348   "TARGET_AVX512F"
14349   "vpmov<extsuffix>dq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
14350   [(set_attr "type" "ssemov")
14351    (set_attr "prefix" "evex")
14352    (set_attr "mode" "XI")])
14353
14354 (define_insn "avx2_<code>v4siv4di2<mask_name>"
14355   [(set (match_operand:V4DI 0 "register_operand" "=v")
14356         (any_extend:V4DI
14357             (match_operand:V4SI 1 "nonimmediate_operand" "vm")))]
14358   "TARGET_AVX2 && <mask_avx512vl_condition>"
14359   "vpmov<extsuffix>dq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
14360   [(set_attr "type" "ssemov")
14361    (set_attr "prefix" "maybe_evex")
14362    (set_attr "prefix_extra" "1")
14363    (set_attr "mode" "OI")])
14364
14365 (define_insn "sse4_1_<code>v2siv2di2<mask_name>"
14366   [(set (match_operand:V2DI 0 "register_operand" "=Yr,*v")
14367         (any_extend:V2DI
14368           (vec_select:V2SI
14369             (match_operand:V4SI 1 "nonimmediate_operand" "Yrm,*vm")
14370             (parallel [(const_int 0) (const_int 1)]))))]
14371   "TARGET_SSE4_1 && <mask_avx512vl_condition>"
14372   "%vpmov<extsuffix>dq\t{%1, %0<mask_operand2>|%0<mask_operand2>, %q1}"
14373   [(set_attr "type" "ssemov")
14374    (set_attr "ssememalign" "64")
14375    (set_attr "prefix_extra" "1")
14376    (set_attr "prefix" "maybe_vex")
14377    (set_attr "mode" "TI")])
14378
14379 ;; ptestps/ptestpd are very similar to comiss and ucomiss when
14380 ;; setting FLAGS_REG. But it is not a really compare instruction.
14381 (define_insn "avx_vtest<ssemodesuffix><avxsizesuffix>"
14382   [(set (reg:CC FLAGS_REG)
14383         (unspec:CC [(match_operand:VF_128_256 0 "register_operand" "x")
14384                     (match_operand:VF_128_256 1 "nonimmediate_operand" "xm")]
14385                    UNSPEC_VTESTP))]
14386   "TARGET_AVX"
14387   "vtest<ssemodesuffix>\t{%1, %0|%0, %1}"
14388   [(set_attr "type" "ssecomi")
14389    (set_attr "prefix_extra" "1")
14390    (set_attr "prefix" "vex")
14391    (set_attr "mode" "<MODE>")])
14392
14393 ;; ptest is very similar to comiss and ucomiss when setting FLAGS_REG.
14394 ;; But it is not a really compare instruction.
14395 (define_insn "avx_ptest256"
14396   [(set (reg:CC FLAGS_REG)
14397         (unspec:CC [(match_operand:V4DI 0 "register_operand" "x")
14398                     (match_operand:V4DI 1 "nonimmediate_operand" "xm")]
14399                    UNSPEC_PTEST))]
14400   "TARGET_AVX"
14401   "vptest\t{%1, %0|%0, %1}"
14402   [(set_attr "type" "ssecomi")
14403    (set_attr "prefix_extra" "1")
14404    (set_attr "prefix" "vex")
14405    (set_attr "btver2_decode" "vector")
14406    (set_attr "mode" "OI")])
14407
14408 (define_insn "sse4_1_ptest"
14409   [(set (reg:CC FLAGS_REG)
14410         (unspec:CC [(match_operand:V2DI 0 "register_operand" "Yr,*x")
14411                     (match_operand:V2DI 1 "nonimmediate_operand" "Yrm,*xm")]
14412                    UNSPEC_PTEST))]
14413   "TARGET_SSE4_1"
14414   "%vptest\t{%1, %0|%0, %1}"
14415   [(set_attr "type" "ssecomi")
14416    (set_attr "prefix_extra" "1")
14417    (set_attr "prefix" "maybe_vex")
14418    (set_attr "mode" "TI")])
14419
14420 (define_insn "<sse4_1>_round<ssemodesuffix><avxsizesuffix>"
14421   [(set (match_operand:VF_128_256 0 "register_operand" "=Yr,*x")
14422         (unspec:VF_128_256
14423           [(match_operand:VF_128_256 1 "nonimmediate_operand" "Yrm,*xm")
14424            (match_operand:SI 2 "const_0_to_15_operand" "n,n")]
14425           UNSPEC_ROUND))]
14426   "TARGET_ROUND"
14427   "%vround<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
14428   [(set_attr "type" "ssecvt")
14429    (set (attr "prefix_data16")
14430      (if_then_else
14431        (match_test "TARGET_AVX")
14432      (const_string "*")
14433      (const_string "1")))
14434    (set_attr "prefix_extra" "1")
14435    (set_attr "length_immediate" "1")
14436    (set_attr "prefix" "maybe_vex")
14437    (set_attr "mode" "<MODE>")])
14438
14439 (define_expand "<sse4_1>_round<ssemodesuffix>_sfix<avxsizesuffix>"
14440   [(match_operand:<sseintvecmode> 0 "register_operand")
14441    (match_operand:VF1_128_256 1 "nonimmediate_operand")
14442    (match_operand:SI 2 "const_0_to_15_operand")]
14443   "TARGET_ROUND"
14444 {
14445   rtx tmp = gen_reg_rtx (<MODE>mode);
14446
14447   emit_insn
14448     (gen_<sse4_1>_round<ssemodesuffix><avxsizesuffix> (tmp, operands[1],
14449                                                        operands[2]));
14450   emit_insn
14451     (gen_fix_trunc<mode><sseintvecmodelower>2 (operands[0], tmp));
14452   DONE;
14453 })
14454
14455 (define_expand "avx512f_roundpd512"
14456   [(match_operand:V8DF 0 "register_operand")
14457    (match_operand:V8DF 1 "nonimmediate_operand")
14458    (match_operand:SI 2 "const_0_to_15_operand")]
14459   "TARGET_AVX512F"
14460 {
14461   emit_insn (gen_avx512f_rndscalev8df (operands[0], operands[1], operands[2]));
14462   DONE;
14463 })
14464
14465 (define_expand "<sse4_1>_round<ssemodesuffix>_vec_pack_sfix<avxsizesuffix>"
14466   [(match_operand:<ssepackfltmode> 0 "register_operand")
14467    (match_operand:VF2 1 "nonimmediate_operand")
14468    (match_operand:VF2 2 "nonimmediate_operand")
14469    (match_operand:SI 3 "const_0_to_15_operand")]
14470   "TARGET_ROUND"
14471 {
14472   rtx tmp0, tmp1;
14473
14474   if (<MODE>mode == V2DFmode
14475       && TARGET_AVX && !TARGET_PREFER_AVX128 && optimize_insn_for_speed_p ())
14476     {
14477       rtx tmp2 = gen_reg_rtx (V4DFmode);
14478
14479       tmp0 = gen_reg_rtx (V4DFmode);
14480       tmp1 = force_reg (V2DFmode, operands[1]);
14481
14482       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
14483       emit_insn (gen_avx_roundpd256 (tmp2, tmp0, operands[3]));
14484       emit_insn (gen_fix_truncv4dfv4si2 (operands[0], tmp2));
14485     }
14486   else
14487     {
14488       tmp0 = gen_reg_rtx (<MODE>mode);
14489       tmp1 = gen_reg_rtx (<MODE>mode);
14490
14491       emit_insn
14492        (gen_<sse4_1>_round<ssemodesuffix><avxsizesuffix> (tmp0, operands[1],
14493                                                           operands[3]));
14494       emit_insn
14495        (gen_<sse4_1>_round<ssemodesuffix><avxsizesuffix> (tmp1, operands[2],
14496                                                           operands[3]));
14497       emit_insn
14498        (gen_vec_pack_sfix_trunc_<mode> (operands[0], tmp0, tmp1));
14499     }
14500   DONE;
14501 })
14502
14503 (define_insn "sse4_1_round<ssescalarmodesuffix>"
14504   [(set (match_operand:VF_128 0 "register_operand" "=Yr,*x,x")
14505         (vec_merge:VF_128
14506           (unspec:VF_128
14507             [(match_operand:VF_128 2 "register_operand" "Yr,*x,x")
14508              (match_operand:SI 3 "const_0_to_15_operand" "n,n,n")]
14509             UNSPEC_ROUND)
14510           (match_operand:VF_128 1 "register_operand" "0,0,x")
14511           (const_int 1)))]
14512   "TARGET_ROUND"
14513   "@
14514    round<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
14515    round<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
14516    vround<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
14517   [(set_attr "isa" "noavx,noavx,avx")
14518    (set_attr "type" "ssecvt")
14519    (set_attr "length_immediate" "1")
14520    (set_attr "prefix_data16" "1,1,*")
14521    (set_attr "prefix_extra" "1")
14522    (set_attr "prefix" "orig,orig,vex")
14523    (set_attr "mode" "<MODE>")])
14524
14525 (define_expand "round<mode>2"
14526   [(set (match_dup 4)
14527         (plus:VF
14528           (match_operand:VF 1 "register_operand")
14529           (match_dup 3)))
14530    (set (match_operand:VF 0 "register_operand")
14531         (unspec:VF
14532           [(match_dup 4) (match_dup 5)]
14533           UNSPEC_ROUND))]
14534   "TARGET_ROUND && !flag_trapping_math"
14535 {
14536   machine_mode scalar_mode;
14537   const struct real_format *fmt;
14538   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
14539   rtx half, vec_half;
14540
14541   scalar_mode = GET_MODE_INNER (<MODE>mode);
14542
14543   /* load nextafter (0.5, 0.0) */
14544   fmt = REAL_MODE_FORMAT (scalar_mode);
14545   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, scalar_mode);
14546   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
14547   half = const_double_from_real_value (pred_half, scalar_mode);
14548
14549   vec_half = ix86_build_const_vector (<MODE>mode, true, half);
14550   vec_half = force_reg (<MODE>mode, vec_half);
14551
14552   operands[3] = gen_reg_rtx (<MODE>mode);
14553   emit_insn (gen_copysign<mode>3 (operands[3], vec_half, operands[1]));
14554
14555   operands[4] = gen_reg_rtx (<MODE>mode);
14556   operands[5] = GEN_INT (ROUND_TRUNC);
14557 })
14558
14559 (define_expand "round<mode>2_sfix"
14560   [(match_operand:<sseintvecmode> 0 "register_operand")
14561    (match_operand:VF1_128_256 1 "register_operand")]
14562   "TARGET_ROUND && !flag_trapping_math"
14563 {
14564   rtx tmp = gen_reg_rtx (<MODE>mode);
14565
14566   emit_insn (gen_round<mode>2 (tmp, operands[1]));
14567
14568   emit_insn
14569     (gen_fix_trunc<mode><sseintvecmodelower>2 (operands[0], tmp));
14570   DONE;
14571 })
14572
14573 (define_expand "round<mode>2_vec_pack_sfix"
14574   [(match_operand:<ssepackfltmode> 0 "register_operand")
14575    (match_operand:VF2 1 "register_operand")
14576    (match_operand:VF2 2 "register_operand")]
14577   "TARGET_ROUND && !flag_trapping_math"
14578 {
14579   rtx tmp0, tmp1;
14580
14581   if (<MODE>mode == V2DFmode
14582       && TARGET_AVX && !TARGET_PREFER_AVX128 && optimize_insn_for_speed_p ())
14583     {
14584       rtx tmp2 = gen_reg_rtx (V4DFmode);
14585
14586       tmp0 = gen_reg_rtx (V4DFmode);
14587       tmp1 = force_reg (V2DFmode, operands[1]);
14588
14589       emit_insn (gen_avx_vec_concatv4df (tmp0, tmp1, operands[2]));
14590       emit_insn (gen_roundv4df2 (tmp2, tmp0));
14591       emit_insn (gen_fix_truncv4dfv4si2 (operands[0], tmp2));
14592     }
14593   else
14594     {
14595       tmp0 = gen_reg_rtx (<MODE>mode);
14596       tmp1 = gen_reg_rtx (<MODE>mode);
14597
14598       emit_insn (gen_round<mode>2 (tmp0, operands[1]));
14599       emit_insn (gen_round<mode>2 (tmp1, operands[2]));
14600
14601       emit_insn
14602        (gen_vec_pack_sfix_trunc_<mode> (operands[0], tmp0, tmp1));
14603     }
14604   DONE;
14605 })
14606
14607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14608 ;;
14609 ;; Intel SSE4.2 string/text processing instructions
14610 ;;
14611 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14612
14613 (define_insn_and_split "sse4_2_pcmpestr"
14614   [(set (match_operand:SI 0 "register_operand" "=c,c")
14615         (unspec:SI
14616           [(match_operand:V16QI 2 "register_operand" "x,x")
14617            (match_operand:SI 3 "register_operand" "a,a")
14618            (match_operand:V16QI 4 "nonimmediate_operand" "x,m")
14619            (match_operand:SI 5 "register_operand" "d,d")
14620            (match_operand:SI 6 "const_0_to_255_operand" "n,n")]
14621           UNSPEC_PCMPESTR))
14622    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
14623         (unspec:V16QI
14624           [(match_dup 2)
14625            (match_dup 3)
14626            (match_dup 4)
14627            (match_dup 5)
14628            (match_dup 6)]
14629           UNSPEC_PCMPESTR))
14630    (set (reg:CC FLAGS_REG)
14631         (unspec:CC
14632           [(match_dup 2)
14633            (match_dup 3)
14634            (match_dup 4)
14635            (match_dup 5)
14636            (match_dup 6)]
14637           UNSPEC_PCMPESTR))]
14638   "TARGET_SSE4_2
14639    && can_create_pseudo_p ()"
14640   "#"
14641   "&& 1"
14642   [(const_int 0)]
14643 {
14644   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
14645   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
14646   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
14647
14648   if (ecx)
14649     emit_insn (gen_sse4_2_pcmpestri (operands[0], operands[2],
14650                                      operands[3], operands[4],
14651                                      operands[5], operands[6]));
14652   if (xmm0)
14653     emit_insn (gen_sse4_2_pcmpestrm (operands[1], operands[2],
14654                                      operands[3], operands[4],
14655                                      operands[5], operands[6]));
14656   if (flags && !(ecx || xmm0))
14657     emit_insn (gen_sse4_2_pcmpestr_cconly (NULL, NULL,
14658                                            operands[2], operands[3],
14659                                            operands[4], operands[5],
14660                                            operands[6]));
14661   if (!(flags || ecx || xmm0))
14662     emit_note (NOTE_INSN_DELETED);
14663
14664   DONE;
14665 }
14666   [(set_attr "type" "sselog")
14667    (set_attr "prefix_data16" "1")
14668    (set_attr "prefix_extra" "1")
14669    (set_attr "ssememalign" "8")
14670    (set_attr "length_immediate" "1")
14671    (set_attr "memory" "none,load")
14672    (set_attr "mode" "TI")])
14673
14674 (define_insn_and_split "*sse4_2_pcmpestr_unaligned"
14675   [(set (match_operand:SI 0 "register_operand" "=c")
14676         (unspec:SI
14677           [(match_operand:V16QI 2 "register_operand" "x")
14678            (match_operand:SI 3 "register_operand" "a")
14679            (unspec:V16QI
14680              [(match_operand:V16QI 4 "memory_operand" "m")]
14681              UNSPEC_LOADU)
14682            (match_operand:SI 5 "register_operand" "d")
14683            (match_operand:SI 6 "const_0_to_255_operand" "n")]
14684           UNSPEC_PCMPESTR))
14685    (set (match_operand:V16QI 1 "register_operand" "=Yz")
14686         (unspec:V16QI
14687           [(match_dup 2)
14688            (match_dup 3)
14689            (unspec:V16QI [(match_dup 4)] UNSPEC_LOADU)
14690            (match_dup 5)
14691            (match_dup 6)]
14692           UNSPEC_PCMPESTR))
14693    (set (reg:CC FLAGS_REG)
14694         (unspec:CC
14695           [(match_dup 2)
14696            (match_dup 3)
14697            (unspec:V16QI [(match_dup 4)] UNSPEC_LOADU)
14698            (match_dup 5)
14699            (match_dup 6)]
14700           UNSPEC_PCMPESTR))]
14701   "TARGET_SSE4_2
14702    && can_create_pseudo_p ()"
14703   "#"
14704   "&& 1"
14705   [(const_int 0)]
14706 {
14707   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
14708   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
14709   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
14710
14711   if (ecx)
14712     emit_insn (gen_sse4_2_pcmpestri (operands[0], operands[2],
14713                                      operands[3], operands[4],
14714                                      operands[5], operands[6]));
14715   if (xmm0)
14716     emit_insn (gen_sse4_2_pcmpestrm (operands[1], operands[2],
14717                                      operands[3], operands[4],
14718                                      operands[5], operands[6]));
14719   if (flags && !(ecx || xmm0))
14720     emit_insn (gen_sse4_2_pcmpestr_cconly (NULL, NULL,
14721                                            operands[2], operands[3],
14722                                            operands[4], operands[5],
14723                                            operands[6]));
14724   if (!(flags || ecx || xmm0))
14725     emit_note (NOTE_INSN_DELETED);
14726
14727   DONE;
14728 }
14729   [(set_attr "type" "sselog")
14730    (set_attr "prefix_data16" "1")
14731    (set_attr "prefix_extra" "1")
14732    (set_attr "ssememalign" "8")
14733    (set_attr "length_immediate" "1")
14734    (set_attr "memory" "load")
14735    (set_attr "mode" "TI")])
14736
14737 (define_insn "sse4_2_pcmpestri"
14738   [(set (match_operand:SI 0 "register_operand" "=c,c")
14739         (unspec:SI
14740           [(match_operand:V16QI 1 "register_operand" "x,x")
14741            (match_operand:SI 2 "register_operand" "a,a")
14742            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
14743            (match_operand:SI 4 "register_operand" "d,d")
14744            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
14745           UNSPEC_PCMPESTR))
14746    (set (reg:CC FLAGS_REG)
14747         (unspec:CC
14748           [(match_dup 1)
14749            (match_dup 2)
14750            (match_dup 3)
14751            (match_dup 4)
14752            (match_dup 5)]
14753           UNSPEC_PCMPESTR))]
14754   "TARGET_SSE4_2"
14755   "%vpcmpestri\t{%5, %3, %1|%1, %3, %5}"
14756   [(set_attr "type" "sselog")
14757    (set_attr "prefix_data16" "1")
14758    (set_attr "prefix_extra" "1")
14759    (set_attr "prefix" "maybe_vex")
14760    (set_attr "ssememalign" "8")
14761    (set_attr "length_immediate" "1")
14762    (set_attr "btver2_decode" "vector")
14763    (set_attr "memory" "none,load")
14764    (set_attr "mode" "TI")])
14765
14766 (define_insn "sse4_2_pcmpestrm"
14767   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
14768         (unspec:V16QI
14769           [(match_operand:V16QI 1 "register_operand" "x,x")
14770            (match_operand:SI 2 "register_operand" "a,a")
14771            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
14772            (match_operand:SI 4 "register_operand" "d,d")
14773            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
14774           UNSPEC_PCMPESTR))
14775    (set (reg:CC FLAGS_REG)
14776         (unspec:CC
14777           [(match_dup 1)
14778            (match_dup 2)
14779            (match_dup 3)
14780            (match_dup 4)
14781            (match_dup 5)]
14782           UNSPEC_PCMPESTR))]
14783   "TARGET_SSE4_2"
14784   "%vpcmpestrm\t{%5, %3, %1|%1, %3, %5}"
14785   [(set_attr "type" "sselog")
14786    (set_attr "prefix_data16" "1")
14787    (set_attr "prefix_extra" "1")
14788    (set_attr "ssememalign" "8")
14789    (set_attr "length_immediate" "1")
14790    (set_attr "prefix" "maybe_vex")
14791    (set_attr "btver2_decode" "vector")
14792    (set_attr "memory" "none,load")
14793    (set_attr "mode" "TI")])
14794
14795 (define_insn "sse4_2_pcmpestr_cconly"
14796   [(set (reg:CC FLAGS_REG)
14797         (unspec:CC
14798           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
14799            (match_operand:SI 3 "register_operand" "a,a,a,a")
14800            (match_operand:V16QI 4 "nonimmediate_operand" "x,m,x,m")
14801            (match_operand:SI 5 "register_operand" "d,d,d,d")
14802            (match_operand:SI 6 "const_0_to_255_operand" "n,n,n,n")]
14803           UNSPEC_PCMPESTR))
14804    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
14805    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
14806   "TARGET_SSE4_2"
14807   "@
14808    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
14809    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
14810    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}
14811    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}"
14812   [(set_attr "type" "sselog")
14813    (set_attr "prefix_data16" "1")
14814    (set_attr "prefix_extra" "1")
14815    (set_attr "ssememalign" "8")
14816    (set_attr "length_immediate" "1")
14817    (set_attr "memory" "none,load,none,load")
14818    (set_attr "btver2_decode" "vector,vector,vector,vector") 
14819    (set_attr "prefix" "maybe_vex")
14820    (set_attr "mode" "TI")])
14821
14822 (define_insn_and_split "sse4_2_pcmpistr"
14823   [(set (match_operand:SI 0 "register_operand" "=c,c")
14824         (unspec:SI
14825           [(match_operand:V16QI 2 "register_operand" "x,x")
14826            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
14827            (match_operand:SI 4 "const_0_to_255_operand" "n,n")]
14828           UNSPEC_PCMPISTR))
14829    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
14830         (unspec:V16QI
14831           [(match_dup 2)
14832            (match_dup 3)
14833            (match_dup 4)]
14834           UNSPEC_PCMPISTR))
14835    (set (reg:CC FLAGS_REG)
14836         (unspec:CC
14837           [(match_dup 2)
14838            (match_dup 3)
14839            (match_dup 4)]
14840           UNSPEC_PCMPISTR))]
14841   "TARGET_SSE4_2
14842    && can_create_pseudo_p ()"
14843   "#"
14844   "&& 1"
14845   [(const_int 0)]
14846 {
14847   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
14848   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
14849   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
14850
14851   if (ecx)
14852     emit_insn (gen_sse4_2_pcmpistri (operands[0], operands[2],
14853                                      operands[3], operands[4]));
14854   if (xmm0)
14855     emit_insn (gen_sse4_2_pcmpistrm (operands[1], operands[2],
14856                                      operands[3], operands[4]));
14857   if (flags && !(ecx || xmm0))
14858     emit_insn (gen_sse4_2_pcmpistr_cconly (NULL, NULL,
14859                                            operands[2], operands[3],
14860                                            operands[4]));
14861   if (!(flags || ecx || xmm0))
14862     emit_note (NOTE_INSN_DELETED);
14863
14864   DONE;
14865 }
14866   [(set_attr "type" "sselog")
14867    (set_attr "prefix_data16" "1")
14868    (set_attr "prefix_extra" "1")
14869    (set_attr "ssememalign" "8")
14870    (set_attr "length_immediate" "1")
14871    (set_attr "memory" "none,load")
14872    (set_attr "mode" "TI")])
14873
14874 (define_insn_and_split "*sse4_2_pcmpistr_unaligned"
14875   [(set (match_operand:SI 0 "register_operand" "=c")
14876         (unspec:SI
14877           [(match_operand:V16QI 2 "register_operand" "x")
14878            (unspec:V16QI
14879              [(match_operand:V16QI 3 "memory_operand" "m")]
14880              UNSPEC_LOADU)
14881            (match_operand:SI 4 "const_0_to_255_operand" "n")]
14882           UNSPEC_PCMPISTR))
14883    (set (match_operand:V16QI 1 "register_operand" "=Yz")
14884         (unspec:V16QI
14885           [(match_dup 2)
14886            (unspec:V16QI [(match_dup 3)] UNSPEC_LOADU)
14887            (match_dup 4)]
14888           UNSPEC_PCMPISTR))
14889    (set (reg:CC FLAGS_REG)
14890         (unspec:CC
14891           [(match_dup 2)
14892            (unspec:V16QI [(match_dup 3)] UNSPEC_LOADU)
14893            (match_dup 4)]
14894           UNSPEC_PCMPISTR))]
14895   "TARGET_SSE4_2
14896    && can_create_pseudo_p ()"
14897   "#"
14898   "&& 1"
14899   [(const_int 0)]
14900 {
14901   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
14902   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
14903   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
14904
14905   if (ecx)
14906     emit_insn (gen_sse4_2_pcmpistri (operands[0], operands[2],
14907                                      operands[3], operands[4]));
14908   if (xmm0)
14909     emit_insn (gen_sse4_2_pcmpistrm (operands[1], operands[2],
14910                                      operands[3], operands[4]));
14911   if (flags && !(ecx || xmm0))
14912     emit_insn (gen_sse4_2_pcmpistr_cconly (NULL, NULL,
14913                                            operands[2], operands[3],
14914                                            operands[4]));
14915   if (!(flags || ecx || xmm0))
14916     emit_note (NOTE_INSN_DELETED);
14917
14918   DONE;
14919 }
14920   [(set_attr "type" "sselog")
14921    (set_attr "prefix_data16" "1")
14922    (set_attr "prefix_extra" "1")
14923    (set_attr "ssememalign" "8")
14924    (set_attr "length_immediate" "1")
14925    (set_attr "memory" "load")
14926    (set_attr "mode" "TI")])
14927
14928 (define_insn "sse4_2_pcmpistri"
14929   [(set (match_operand:SI 0 "register_operand" "=c,c")
14930         (unspec:SI
14931           [(match_operand:V16QI 1 "register_operand" "x,x")
14932            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
14933            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
14934           UNSPEC_PCMPISTR))
14935    (set (reg:CC FLAGS_REG)
14936         (unspec:CC
14937           [(match_dup 1)
14938            (match_dup 2)
14939            (match_dup 3)]
14940           UNSPEC_PCMPISTR))]
14941   "TARGET_SSE4_2"
14942   "%vpcmpistri\t{%3, %2, %1|%1, %2, %3}"
14943   [(set_attr "type" "sselog")
14944    (set_attr "prefix_data16" "1")
14945    (set_attr "prefix_extra" "1")
14946    (set_attr "ssememalign" "8")
14947    (set_attr "length_immediate" "1")
14948    (set_attr "prefix" "maybe_vex")
14949    (set_attr "memory" "none,load")
14950    (set_attr "btver2_decode" "vector")
14951    (set_attr "mode" "TI")])
14952
14953 (define_insn "sse4_2_pcmpistrm"
14954   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
14955         (unspec:V16QI
14956           [(match_operand:V16QI 1 "register_operand" "x,x")
14957            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
14958            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
14959           UNSPEC_PCMPISTR))
14960    (set (reg:CC FLAGS_REG)
14961         (unspec:CC
14962           [(match_dup 1)
14963            (match_dup 2)
14964            (match_dup 3)]
14965           UNSPEC_PCMPISTR))]
14966   "TARGET_SSE4_2"
14967   "%vpcmpistrm\t{%3, %2, %1|%1, %2, %3}"
14968   [(set_attr "type" "sselog")
14969    (set_attr "prefix_data16" "1")
14970    (set_attr "prefix_extra" "1")
14971    (set_attr "ssememalign" "8")
14972    (set_attr "length_immediate" "1")
14973    (set_attr "prefix" "maybe_vex")
14974    (set_attr "memory" "none,load")
14975    (set_attr "btver2_decode" "vector")
14976    (set_attr "mode" "TI")])
14977
14978 (define_insn "sse4_2_pcmpistr_cconly"
14979   [(set (reg:CC FLAGS_REG)
14980         (unspec:CC
14981           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
14982            (match_operand:V16QI 3 "nonimmediate_operand" "x,m,x,m")
14983            (match_operand:SI 4 "const_0_to_255_operand" "n,n,n,n")]
14984           UNSPEC_PCMPISTR))
14985    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
14986    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
14987   "TARGET_SSE4_2"
14988   "@
14989    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
14990    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
14991    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}
14992    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}"
14993   [(set_attr "type" "sselog")
14994    (set_attr "prefix_data16" "1")
14995    (set_attr "prefix_extra" "1")
14996    (set_attr "ssememalign" "8")
14997    (set_attr "length_immediate" "1")
14998    (set_attr "memory" "none,load,none,load")
14999    (set_attr "prefix" "maybe_vex")
15000    (set_attr "btver2_decode" "vector,vector,vector,vector")
15001    (set_attr "mode" "TI")])
15002
15003 ;; Packed float variants
15004 (define_mode_attr GATHER_SCATTER_SF_MEM_MODE
15005                       [(V8DI "V8SF") (V16SI "V16SF")])
15006
15007 (define_expand "avx512pf_gatherpf<mode>sf"
15008   [(unspec
15009      [(match_operand:<avx512fmaskmode> 0 "register_or_constm1_operand")
15010       (mem:<GATHER_SCATTER_SF_MEM_MODE>
15011         (match_par_dup 5
15012           [(match_operand 2 "vsib_address_operand")
15013            (match_operand:VI48_512 1 "register_operand")
15014            (match_operand:SI 3 "const1248_operand")]))
15015       (match_operand:SI 4 "const_2_to_3_operand")]
15016      UNSPEC_GATHER_PREFETCH)]
15017   "TARGET_AVX512PF"
15018 {
15019   operands[5]
15020     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[1],
15021                                         operands[3]), UNSPEC_VSIBADDR);
15022 })
15023
15024 (define_insn "*avx512pf_gatherpf<mode>sf_mask"
15025   [(unspec
15026      [(match_operand:<avx512fmaskmode> 0 "register_operand" "Yk")
15027       (match_operator:<GATHER_SCATTER_SF_MEM_MODE> 5 "vsib_mem_operator"
15028         [(unspec:P
15029            [(match_operand:P 2 "vsib_address_operand" "Tv")
15030             (match_operand:VI48_512 1 "register_operand" "v")
15031             (match_operand:SI 3 "const1248_operand" "n")]
15032            UNSPEC_VSIBADDR)])
15033       (match_operand:SI 4 "const_2_to_3_operand" "n")]
15034      UNSPEC_GATHER_PREFETCH)]
15035   "TARGET_AVX512PF"
15036 {
15037   switch (INTVAL (operands[4]))
15038     {
15039     case 3:
15040       return "vgatherpf0<ssemodesuffix>ps\t{%5%{%0%}|%5%{%0%}}";
15041     case 2:
15042       return "vgatherpf1<ssemodesuffix>ps\t{%5%{%0%}|%5%{%0%}}";
15043     default:
15044       gcc_unreachable ();
15045     }
15046 }
15047   [(set_attr "type" "sse")
15048    (set_attr "prefix" "evex")
15049    (set_attr "mode" "XI")])
15050
15051 (define_insn "*avx512pf_gatherpf<mode>sf"
15052   [(unspec
15053      [(const_int -1)
15054       (match_operator:<GATHER_SCATTER_SF_MEM_MODE> 4 "vsib_mem_operator"
15055         [(unspec:P
15056            [(match_operand:P 1 "vsib_address_operand" "Tv")
15057             (match_operand:VI48_512 0 "register_operand" "v")
15058             (match_operand:SI 2 "const1248_operand" "n")]
15059            UNSPEC_VSIBADDR)])
15060       (match_operand:SI 3 "const_2_to_3_operand" "n")]
15061      UNSPEC_GATHER_PREFETCH)]
15062   "TARGET_AVX512PF"
15063 {
15064   switch (INTVAL (operands[3]))
15065     {
15066     case 3:
15067       return "vgatherpf0<ssemodesuffix>ps\t{%4|%4}";
15068     case 2:
15069       return "vgatherpf1<ssemodesuffix>ps\t{%4|%4}";
15070     default:
15071       gcc_unreachable ();
15072     }
15073 }
15074   [(set_attr "type" "sse")
15075    (set_attr "prefix" "evex")
15076    (set_attr "mode" "XI")])
15077
15078 ;; Packed double variants
15079 (define_expand "avx512pf_gatherpf<mode>df"
15080   [(unspec
15081      [(match_operand:<avx512fmaskmode> 0 "register_or_constm1_operand")
15082       (mem:V8DF
15083         (match_par_dup 5
15084           [(match_operand 2 "vsib_address_operand")
15085            (match_operand:VI4_256_8_512 1 "register_operand")
15086            (match_operand:SI 3 "const1248_operand")]))
15087       (match_operand:SI 4 "const_2_to_3_operand")]
15088      UNSPEC_GATHER_PREFETCH)]
15089   "TARGET_AVX512PF"
15090 {
15091   operands[5]
15092     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[1],
15093                                         operands[3]), UNSPEC_VSIBADDR);
15094 })
15095
15096 (define_insn "*avx512pf_gatherpf<mode>df_mask"
15097   [(unspec
15098      [(match_operand:<avx512fmaskmode> 0 "register_operand" "Yk")
15099       (match_operator:V8DF 5 "vsib_mem_operator"
15100         [(unspec:P
15101            [(match_operand:P 2 "vsib_address_operand" "Tv")
15102             (match_operand:VI4_256_8_512 1 "register_operand" "v")
15103             (match_operand:SI 3 "const1248_operand" "n")]
15104            UNSPEC_VSIBADDR)])
15105       (match_operand:SI 4 "const_2_to_3_operand" "n")]
15106      UNSPEC_GATHER_PREFETCH)]
15107   "TARGET_AVX512PF"
15108 {
15109   switch (INTVAL (operands[4]))
15110     {
15111     case 3:
15112       return "vgatherpf0<ssemodesuffix>pd\t{%5%{%0%}|%5%{%0%}}";
15113     case 2:
15114       return "vgatherpf1<ssemodesuffix>pd\t{%5%{%0%}|%5%{%0%}}";
15115     default:
15116       gcc_unreachable ();
15117     }
15118 }
15119   [(set_attr "type" "sse")
15120    (set_attr "prefix" "evex")
15121    (set_attr "mode" "XI")])
15122
15123 (define_insn "*avx512pf_gatherpf<mode>df"
15124   [(unspec
15125      [(const_int -1)
15126       (match_operator:V8DF 4 "vsib_mem_operator"
15127         [(unspec:P
15128            [(match_operand:P 1 "vsib_address_operand" "Tv")
15129             (match_operand:VI4_256_8_512 0 "register_operand" "v")
15130             (match_operand:SI 2 "const1248_operand" "n")]
15131            UNSPEC_VSIBADDR)])
15132       (match_operand:SI 3 "const_2_to_3_operand" "n")]
15133      UNSPEC_GATHER_PREFETCH)]
15134   "TARGET_AVX512PF"
15135 {
15136   switch (INTVAL (operands[3]))
15137     {
15138     case 3:
15139       return "vgatherpf0<ssemodesuffix>pd\t{%4|%4}";
15140     case 2:
15141       return "vgatherpf1<ssemodesuffix>pd\t{%4|%4}";
15142     default:
15143       gcc_unreachable ();
15144     }
15145 }
15146   [(set_attr "type" "sse")
15147    (set_attr "prefix" "evex")
15148    (set_attr "mode" "XI")])
15149
15150 ;; Packed float variants
15151 (define_expand "avx512pf_scatterpf<mode>sf"
15152   [(unspec
15153      [(match_operand:<avx512fmaskmode> 0 "register_or_constm1_operand")
15154       (mem:<GATHER_SCATTER_SF_MEM_MODE>
15155         (match_par_dup 5
15156           [(match_operand 2 "vsib_address_operand")
15157            (match_operand:VI48_512 1 "register_operand")
15158            (match_operand:SI 3 "const1248_operand")]))
15159       (match_operand:SI 4 "const2367_operand")]
15160      UNSPEC_SCATTER_PREFETCH)]
15161   "TARGET_AVX512PF"
15162 {
15163   operands[5]
15164     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[1],
15165                                         operands[3]), UNSPEC_VSIBADDR);
15166 })
15167
15168 (define_insn "*avx512pf_scatterpf<mode>sf_mask"
15169   [(unspec
15170      [(match_operand:<avx512fmaskmode> 0 "register_operand" "Yk")
15171       (match_operator:<GATHER_SCATTER_SF_MEM_MODE> 5 "vsib_mem_operator"
15172         [(unspec:P
15173            [(match_operand:P 2 "vsib_address_operand" "Tv")
15174             (match_operand:VI48_512 1 "register_operand" "v")
15175             (match_operand:SI 3 "const1248_operand" "n")]
15176            UNSPEC_VSIBADDR)])
15177       (match_operand:SI 4 "const2367_operand" "n")]
15178      UNSPEC_SCATTER_PREFETCH)]
15179   "TARGET_AVX512PF"
15180 {
15181   switch (INTVAL (operands[4]))
15182     {
15183     case 3:
15184     case 7:
15185       return "vscatterpf0<ssemodesuffix>ps\t{%5%{%0%}|%5%{%0%}}";
15186     case 2:
15187     case 6:
15188       return "vscatterpf1<ssemodesuffix>ps\t{%5%{%0%}|%5%{%0%}}";
15189     default:
15190       gcc_unreachable ();
15191     }
15192 }
15193   [(set_attr "type" "sse")
15194    (set_attr "prefix" "evex")
15195    (set_attr "mode" "XI")])
15196
15197 (define_insn "*avx512pf_scatterpf<mode>sf"
15198   [(unspec
15199      [(const_int -1)
15200       (match_operator:<GATHER_SCATTER_SF_MEM_MODE> 4 "vsib_mem_operator"
15201         [(unspec:P
15202            [(match_operand:P 1 "vsib_address_operand" "Tv")
15203             (match_operand:VI48_512 0 "register_operand" "v")
15204             (match_operand:SI 2 "const1248_operand" "n")]
15205            UNSPEC_VSIBADDR)])
15206       (match_operand:SI 3 "const2367_operand" "n")]
15207      UNSPEC_SCATTER_PREFETCH)]
15208   "TARGET_AVX512PF"
15209 {
15210   switch (INTVAL (operands[3]))
15211     {
15212     case 3:
15213     case 7:
15214       return "vscatterpf0<ssemodesuffix>ps\t{%4|%4}";
15215     case 2:
15216     case 6:
15217       return "vscatterpf1<ssemodesuffix>ps\t{%4|%4}";
15218     default:
15219       gcc_unreachable ();
15220     }
15221 }
15222   [(set_attr "type" "sse")
15223    (set_attr "prefix" "evex")
15224    (set_attr "mode" "XI")])
15225
15226 ;; Packed double variants
15227 (define_expand "avx512pf_scatterpf<mode>df"
15228   [(unspec
15229      [(match_operand:<avx512fmaskmode> 0 "register_or_constm1_operand")
15230       (mem:V8DF
15231         (match_par_dup 5
15232           [(match_operand 2 "vsib_address_operand")
15233            (match_operand:VI4_256_8_512 1 "register_operand")
15234            (match_operand:SI 3 "const1248_operand")]))
15235       (match_operand:SI 4 "const2367_operand")]
15236      UNSPEC_SCATTER_PREFETCH)]
15237   "TARGET_AVX512PF"
15238 {
15239   operands[5]
15240     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[1],
15241                                         operands[3]), UNSPEC_VSIBADDR);
15242 })
15243
15244 (define_insn "*avx512pf_scatterpf<mode>df_mask"
15245   [(unspec
15246      [(match_operand:<avx512fmaskmode> 0 "register_operand" "Yk")
15247       (match_operator:V8DF 5 "vsib_mem_operator"
15248         [(unspec:P
15249            [(match_operand:P 2 "vsib_address_operand" "Tv")
15250             (match_operand:VI4_256_8_512 1 "register_operand" "v")
15251             (match_operand:SI 3 "const1248_operand" "n")]
15252            UNSPEC_VSIBADDR)])
15253       (match_operand:SI 4 "const2367_operand" "n")]
15254      UNSPEC_SCATTER_PREFETCH)]
15255   "TARGET_AVX512PF"
15256 {
15257   switch (INTVAL (operands[4]))
15258     {
15259     case 3:
15260     case 7:
15261       return "vscatterpf0<ssemodesuffix>pd\t{%5%{%0%}|%5%{%0%}}";
15262     case 2:
15263     case 6:
15264       return "vscatterpf1<ssemodesuffix>pd\t{%5%{%0%}|%5%{%0%}}";
15265     default:
15266       gcc_unreachable ();
15267     }
15268 }
15269   [(set_attr "type" "sse")
15270    (set_attr "prefix" "evex")
15271    (set_attr "mode" "XI")])
15272
15273 (define_insn "*avx512pf_scatterpf<mode>df"
15274   [(unspec
15275      [(const_int -1)
15276       (match_operator:V8DF 4 "vsib_mem_operator"
15277         [(unspec:P
15278            [(match_operand:P 1 "vsib_address_operand" "Tv")
15279             (match_operand:VI4_256_8_512 0 "register_operand" "v")
15280             (match_operand:SI 2 "const1248_operand" "n")]
15281            UNSPEC_VSIBADDR)])
15282       (match_operand:SI 3 "const2367_operand" "n")]
15283      UNSPEC_SCATTER_PREFETCH)]
15284   "TARGET_AVX512PF"
15285 {
15286   switch (INTVAL (operands[3]))
15287     {
15288     case 3:
15289     case 7:
15290       return "vscatterpf0<ssemodesuffix>pd\t{%4|%4}";
15291     case 2:
15292     case 6:
15293       return "vscatterpf1<ssemodesuffix>pd\t{%4|%4}";
15294     default:
15295       gcc_unreachable ();
15296     }
15297 }
15298   [(set_attr "type" "sse")
15299    (set_attr "prefix" "evex")
15300    (set_attr "mode" "XI")])
15301
15302 (define_insn "avx512er_exp2<mode><mask_name><round_saeonly_name>"
15303   [(set (match_operand:VF_512 0 "register_operand" "=v")
15304         (unspec:VF_512
15305           [(match_operand:VF_512 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")]
15306           UNSPEC_EXP2))]
15307   "TARGET_AVX512ER"
15308   "vexp2<ssemodesuffix>\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}"
15309   [(set_attr "prefix" "evex")
15310    (set_attr "type" "sse")
15311    (set_attr "mode" "<MODE>")])
15312
15313 (define_insn "<mask_codefor>avx512er_rcp28<mode><mask_name><round_saeonly_name>"
15314   [(set (match_operand:VF_512 0 "register_operand" "=v")
15315         (unspec:VF_512
15316           [(match_operand:VF_512 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")]
15317           UNSPEC_RCP28))]
15318   "TARGET_AVX512ER"
15319   "vrcp28<ssemodesuffix>\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}"
15320   [(set_attr "prefix" "evex")
15321    (set_attr "type" "sse")
15322    (set_attr "mode" "<MODE>")])
15323
15324 (define_insn "avx512er_vmrcp28<mode><round_saeonly_name>"
15325   [(set (match_operand:VF_128 0 "register_operand" "=v")
15326         (vec_merge:VF_128
15327           (unspec:VF_128
15328             [(match_operand:VF_128 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")]
15329             UNSPEC_RCP28)
15330           (match_operand:VF_128 2 "register_operand" "v")
15331           (const_int 1)))]
15332   "TARGET_AVX512ER"
15333   "vrcp28<ssescalarmodesuffix>\t{<round_saeonly_op3>%1, %2, %0|%0, %2, %1<round_saeonly_op3>}"
15334   [(set_attr "length_immediate" "1")
15335    (set_attr "prefix" "evex")
15336    (set_attr "type" "sse")
15337    (set_attr "mode" "<MODE>")])
15338
15339 (define_insn "<mask_codefor>avx512er_rsqrt28<mode><mask_name><round_saeonly_name>"
15340   [(set (match_operand:VF_512 0 "register_operand" "=v")
15341         (unspec:VF_512
15342           [(match_operand:VF_512 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")]
15343           UNSPEC_RSQRT28))]
15344   "TARGET_AVX512ER"
15345   "vrsqrt28<ssemodesuffix>\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}"
15346   [(set_attr "prefix" "evex")
15347    (set_attr "type" "sse")
15348    (set_attr "mode" "<MODE>")])
15349
15350 (define_insn "avx512er_vmrsqrt28<mode><round_saeonly_name>"
15351   [(set (match_operand:VF_128 0 "register_operand" "=v")
15352         (vec_merge:VF_128
15353           (unspec:VF_128
15354             [(match_operand:VF_128 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")]
15355             UNSPEC_RSQRT28)
15356           (match_operand:VF_128 2 "register_operand" "v")
15357           (const_int 1)))]
15358   "TARGET_AVX512ER"
15359   "vrsqrt28<ssescalarmodesuffix>\t{<round_saeonly_op3>%1, %2, %0|%0, %2, %1<round_saeonly_op3>}"
15360   [(set_attr "length_immediate" "1")
15361    (set_attr "type" "sse")
15362    (set_attr "prefix" "evex")
15363    (set_attr "mode" "<MODE>")])
15364
15365 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15366 ;;
15367 ;; XOP instructions
15368 ;;
15369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15370
15371 (define_code_iterator xop_plus [plus ss_plus])
15372
15373 (define_code_attr macs [(plus "macs") (ss_plus "macss")])
15374 (define_code_attr madcs [(plus "madcs") (ss_plus "madcss")])
15375
15376 ;; XOP parallel integer multiply/add instructions.
15377
15378 (define_insn "xop_p<macs><ssemodesuffix><ssemodesuffix>"
15379   [(set (match_operand:VI24_128 0 "register_operand" "=x")
15380         (xop_plus:VI24_128
15381          (mult:VI24_128
15382           (match_operand:VI24_128 1 "nonimmediate_operand" "%x")
15383           (match_operand:VI24_128 2 "nonimmediate_operand" "xm"))
15384          (match_operand:VI24_128 3 "register_operand" "x")))]
15385   "TARGET_XOP"
15386   "vp<macs><ssemodesuffix><ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15387   [(set_attr "type" "ssemuladd")
15388    (set_attr "mode" "TI")])
15389
15390 (define_insn "xop_p<macs>dql"
15391   [(set (match_operand:V2DI 0 "register_operand" "=x")
15392         (xop_plus:V2DI
15393          (mult:V2DI
15394           (sign_extend:V2DI
15395            (vec_select:V2SI
15396             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
15397             (parallel [(const_int 0) (const_int 2)])))
15398           (sign_extend:V2DI
15399            (vec_select:V2SI
15400             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
15401             (parallel [(const_int 0) (const_int 2)]))))
15402          (match_operand:V2DI 3 "register_operand" "x")))]
15403   "TARGET_XOP"
15404   "vp<macs>dql\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15405   [(set_attr "type" "ssemuladd")
15406    (set_attr "mode" "TI")])
15407
15408 (define_insn "xop_p<macs>dqh"
15409   [(set (match_operand:V2DI 0 "register_operand" "=x")
15410         (xop_plus:V2DI
15411          (mult:V2DI
15412           (sign_extend:V2DI
15413            (vec_select:V2SI
15414             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
15415             (parallel [(const_int 1) (const_int 3)])))
15416           (sign_extend:V2DI
15417            (vec_select:V2SI
15418             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
15419             (parallel [(const_int 1) (const_int 3)]))))
15420          (match_operand:V2DI 3 "register_operand" "x")))]
15421   "TARGET_XOP"
15422   "vp<macs>dqh\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15423   [(set_attr "type" "ssemuladd")
15424    (set_attr "mode" "TI")])
15425
15426 ;; XOP parallel integer multiply/add instructions for the intrinisics
15427 (define_insn "xop_p<macs>wd"
15428   [(set (match_operand:V4SI 0 "register_operand" "=x")
15429         (xop_plus:V4SI
15430          (mult:V4SI
15431           (sign_extend:V4SI
15432            (vec_select:V4HI
15433             (match_operand:V8HI 1 "nonimmediate_operand" "%x")
15434             (parallel [(const_int 1) (const_int 3)
15435                        (const_int 5) (const_int 7)])))
15436           (sign_extend:V4SI
15437            (vec_select:V4HI
15438             (match_operand:V8HI 2 "nonimmediate_operand" "xm")
15439             (parallel [(const_int 1) (const_int 3)
15440                        (const_int 5) (const_int 7)]))))
15441          (match_operand:V4SI 3 "register_operand" "x")))]
15442   "TARGET_XOP"
15443   "vp<macs>wd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15444   [(set_attr "type" "ssemuladd")
15445    (set_attr "mode" "TI")])
15446
15447 (define_insn "xop_p<madcs>wd"
15448   [(set (match_operand:V4SI 0 "register_operand" "=x")
15449         (xop_plus:V4SI
15450          (plus:V4SI
15451           (mult:V4SI
15452            (sign_extend:V4SI
15453             (vec_select:V4HI
15454              (match_operand:V8HI 1 "nonimmediate_operand" "%x")
15455              (parallel [(const_int 0) (const_int 2)
15456                         (const_int 4) (const_int 6)])))
15457            (sign_extend:V4SI
15458             (vec_select:V4HI
15459              (match_operand:V8HI 2 "nonimmediate_operand" "xm")
15460              (parallel [(const_int 0) (const_int 2)
15461                         (const_int 4) (const_int 6)]))))
15462           (mult:V4SI
15463            (sign_extend:V4SI
15464             (vec_select:V4HI
15465              (match_dup 1)
15466              (parallel [(const_int 1) (const_int 3)
15467                         (const_int 5) (const_int 7)])))
15468            (sign_extend:V4SI
15469             (vec_select:V4HI
15470              (match_dup 2)
15471              (parallel [(const_int 1) (const_int 3)
15472                         (const_int 5) (const_int 7)])))))
15473          (match_operand:V4SI 3 "register_operand" "x")))]
15474   "TARGET_XOP"
15475   "vp<madcs>wd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15476   [(set_attr "type" "ssemuladd")
15477    (set_attr "mode" "TI")])
15478
15479 ;; XOP parallel XMM conditional moves
15480 (define_insn "xop_pcmov_<mode><avxsizesuffix>"
15481   [(set (match_operand:V 0 "register_operand" "=x,x")
15482         (if_then_else:V
15483           (match_operand:V 3 "nonimmediate_operand" "x,m")
15484           (match_operand:V 1 "register_operand" "x,x")
15485           (match_operand:V 2 "nonimmediate_operand" "xm,x")))]
15486   "TARGET_XOP"
15487   "vpcmov\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15488   [(set_attr "type" "sse4arg")])
15489
15490 ;; XOP horizontal add/subtract instructions
15491 (define_insn "xop_phadd<u>bw"
15492   [(set (match_operand:V8HI 0 "register_operand" "=x")
15493         (plus:V8HI
15494          (any_extend:V8HI
15495           (vec_select:V8QI
15496            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
15497            (parallel [(const_int 0) (const_int 2)
15498                       (const_int 4) (const_int 6)
15499                       (const_int 8) (const_int 10)
15500                       (const_int 12) (const_int 14)])))
15501          (any_extend:V8HI
15502           (vec_select:V8QI
15503            (match_dup 1)
15504            (parallel [(const_int 1) (const_int 3)
15505                       (const_int 5) (const_int 7)
15506                       (const_int 9) (const_int 11)
15507                       (const_int 13) (const_int 15)])))))]
15508   "TARGET_XOP"
15509   "vphadd<u>bw\t{%1, %0|%0, %1}"
15510   [(set_attr "type" "sseiadd1")])
15511
15512 (define_insn "xop_phadd<u>bd"
15513   [(set (match_operand:V4SI 0 "register_operand" "=x")
15514         (plus:V4SI
15515          (plus:V4SI
15516           (any_extend:V4SI
15517            (vec_select:V4QI
15518             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
15519             (parallel [(const_int 0) (const_int 4)
15520                        (const_int 8) (const_int 12)])))
15521           (any_extend:V4SI
15522            (vec_select:V4QI
15523             (match_dup 1)
15524             (parallel [(const_int 1) (const_int 5)
15525                        (const_int 9) (const_int 13)]))))
15526          (plus:V4SI
15527           (any_extend:V4SI
15528            (vec_select:V4QI
15529             (match_dup 1)
15530             (parallel [(const_int 2) (const_int 6)
15531                        (const_int 10) (const_int 14)])))
15532           (any_extend:V4SI
15533            (vec_select:V4QI
15534             (match_dup 1)
15535             (parallel [(const_int 3) (const_int 7)
15536                        (const_int 11) (const_int 15)]))))))]
15537   "TARGET_XOP"
15538   "vphadd<u>bd\t{%1, %0|%0, %1}"
15539   [(set_attr "type" "sseiadd1")])
15540
15541 (define_insn "xop_phadd<u>bq"
15542   [(set (match_operand:V2DI 0 "register_operand" "=x")
15543         (plus:V2DI
15544          (plus:V2DI
15545           (plus:V2DI
15546            (any_extend:V2DI
15547             (vec_select:V2QI
15548              (match_operand:V16QI 1 "nonimmediate_operand" "xm")
15549              (parallel [(const_int 0) (const_int 8)])))
15550            (any_extend:V2DI
15551             (vec_select:V2QI
15552              (match_dup 1)
15553              (parallel [(const_int 1) (const_int 9)]))))
15554           (plus:V2DI
15555            (any_extend:V2DI
15556             (vec_select:V2QI
15557              (match_dup 1)
15558              (parallel [(const_int 2) (const_int 10)])))
15559            (any_extend:V2DI
15560             (vec_select:V2QI
15561              (match_dup 1)
15562              (parallel [(const_int 3) (const_int 11)])))))
15563          (plus:V2DI
15564           (plus:V2DI
15565            (any_extend:V2DI
15566             (vec_select:V2QI
15567              (match_dup 1)
15568              (parallel [(const_int 4) (const_int 12)])))
15569            (any_extend:V2DI
15570             (vec_select:V2QI
15571              (match_dup 1)
15572              (parallel [(const_int 5) (const_int 13)]))))
15573           (plus:V2DI
15574            (any_extend:V2DI
15575             (vec_select:V2QI
15576              (match_dup 1)
15577              (parallel [(const_int 6) (const_int 14)])))
15578            (any_extend:V2DI
15579             (vec_select:V2QI
15580              (match_dup 1)
15581              (parallel [(const_int 7) (const_int 15)])))))))]
15582   "TARGET_XOP"
15583   "vphadd<u>bq\t{%1, %0|%0, %1}"
15584   [(set_attr "type" "sseiadd1")])
15585
15586 (define_insn "xop_phadd<u>wd"
15587   [(set (match_operand:V4SI 0 "register_operand" "=x")
15588         (plus:V4SI
15589          (any_extend:V4SI
15590           (vec_select:V4HI
15591            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
15592            (parallel [(const_int 0) (const_int 2)
15593                       (const_int 4) (const_int 6)])))
15594          (any_extend:V4SI
15595           (vec_select:V4HI
15596            (match_dup 1)
15597            (parallel [(const_int 1) (const_int 3)
15598                       (const_int 5) (const_int 7)])))))]
15599   "TARGET_XOP"
15600   "vphadd<u>wd\t{%1, %0|%0, %1}"
15601   [(set_attr "type" "sseiadd1")])
15602
15603 (define_insn "xop_phadd<u>wq"
15604   [(set (match_operand:V2DI 0 "register_operand" "=x")
15605         (plus:V2DI
15606          (plus:V2DI
15607           (any_extend:V2DI
15608            (vec_select:V2HI
15609             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
15610             (parallel [(const_int 0) (const_int 4)])))
15611           (any_extend:V2DI
15612            (vec_select:V2HI
15613             (match_dup 1)
15614             (parallel [(const_int 1) (const_int 5)]))))
15615          (plus:V2DI
15616           (any_extend:V2DI
15617            (vec_select:V2HI
15618             (match_dup 1)
15619             (parallel [(const_int 2) (const_int 6)])))
15620           (any_extend:V2DI
15621            (vec_select:V2HI
15622             (match_dup 1)
15623             (parallel [(const_int 3) (const_int 7)]))))))]
15624   "TARGET_XOP"
15625   "vphadd<u>wq\t{%1, %0|%0, %1}"
15626   [(set_attr "type" "sseiadd1")])
15627
15628 (define_insn "xop_phadd<u>dq"
15629   [(set (match_operand:V2DI 0 "register_operand" "=x")
15630         (plus:V2DI
15631          (any_extend:V2DI
15632           (vec_select:V2SI
15633            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
15634            (parallel [(const_int 0) (const_int 2)])))
15635          (any_extend:V2DI
15636           (vec_select:V2SI
15637            (match_dup 1)
15638            (parallel [(const_int 1) (const_int 3)])))))]
15639   "TARGET_XOP"
15640   "vphadd<u>dq\t{%1, %0|%0, %1}"
15641   [(set_attr "type" "sseiadd1")])
15642
15643 (define_insn "xop_phsubbw"
15644   [(set (match_operand:V8HI 0 "register_operand" "=x")
15645         (minus:V8HI
15646          (sign_extend:V8HI
15647           (vec_select:V8QI
15648            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
15649            (parallel [(const_int 0) (const_int 2)
15650                       (const_int 4) (const_int 6)
15651                       (const_int 8) (const_int 10)
15652                       (const_int 12) (const_int 14)])))
15653          (sign_extend:V8HI
15654           (vec_select:V8QI
15655            (match_dup 1)
15656            (parallel [(const_int 1) (const_int 3)
15657                       (const_int 5) (const_int 7)
15658                       (const_int 9) (const_int 11)
15659                       (const_int 13) (const_int 15)])))))]
15660   "TARGET_XOP"
15661   "vphsubbw\t{%1, %0|%0, %1}"
15662   [(set_attr "type" "sseiadd1")])
15663
15664 (define_insn "xop_phsubwd"
15665   [(set (match_operand:V4SI 0 "register_operand" "=x")
15666         (minus:V4SI
15667          (sign_extend:V4SI
15668           (vec_select:V4HI
15669            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
15670            (parallel [(const_int 0) (const_int 2)
15671                       (const_int 4) (const_int 6)])))
15672          (sign_extend:V4SI
15673           (vec_select:V4HI
15674            (match_dup 1)
15675            (parallel [(const_int 1) (const_int 3)
15676                       (const_int 5) (const_int 7)])))))]
15677   "TARGET_XOP"
15678   "vphsubwd\t{%1, %0|%0, %1}"
15679   [(set_attr "type" "sseiadd1")])
15680
15681 (define_insn "xop_phsubdq"
15682   [(set (match_operand:V2DI 0 "register_operand" "=x")
15683         (minus:V2DI
15684          (sign_extend:V2DI
15685           (vec_select:V2SI
15686            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
15687            (parallel [(const_int 0) (const_int 2)])))
15688          (sign_extend:V2DI
15689           (vec_select:V2SI
15690            (match_dup 1)
15691            (parallel [(const_int 1) (const_int 3)])))))]
15692   "TARGET_XOP"
15693   "vphsubdq\t{%1, %0|%0, %1}"
15694   [(set_attr "type" "sseiadd1")])
15695
15696 ;; XOP permute instructions
15697 (define_insn "xop_pperm"
15698   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
15699         (unspec:V16QI
15700           [(match_operand:V16QI 1 "register_operand" "x,x")
15701            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
15702            (match_operand:V16QI 3 "nonimmediate_operand" "xm,x")]
15703           UNSPEC_XOP_PERMUTE))]
15704   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
15705   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15706   [(set_attr "type" "sse4arg")
15707    (set_attr "mode" "TI")])
15708
15709 ;; XOP pack instructions that combine two vectors into a smaller vector
15710 (define_insn "xop_pperm_pack_v2di_v4si"
15711   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
15712         (vec_concat:V4SI
15713          (truncate:V2SI
15714           (match_operand:V2DI 1 "register_operand" "x,x"))
15715          (truncate:V2SI
15716           (match_operand:V2DI 2 "nonimmediate_operand" "x,m"))))
15717    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
15718   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
15719   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15720   [(set_attr "type" "sse4arg")
15721    (set_attr "mode" "TI")])
15722
15723 (define_insn "xop_pperm_pack_v4si_v8hi"
15724   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
15725         (vec_concat:V8HI
15726          (truncate:V4HI
15727           (match_operand:V4SI 1 "register_operand" "x,x"))
15728          (truncate:V4HI
15729           (match_operand:V4SI 2 "nonimmediate_operand" "x,m"))))
15730    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
15731   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
15732   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15733   [(set_attr "type" "sse4arg")
15734    (set_attr "mode" "TI")])
15735
15736 (define_insn "xop_pperm_pack_v8hi_v16qi"
15737   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
15738         (vec_concat:V16QI
15739          (truncate:V8QI
15740           (match_operand:V8HI 1 "register_operand" "x,x"))
15741          (truncate:V8QI
15742           (match_operand:V8HI 2 "nonimmediate_operand" "x,m"))))
15743    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
15744   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
15745   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
15746   [(set_attr "type" "sse4arg")
15747    (set_attr "mode" "TI")])
15748
15749 ;; XOP packed rotate instructions
15750 (define_expand "rotl<mode>3"
15751   [(set (match_operand:VI_128 0 "register_operand")
15752         (rotate:VI_128
15753          (match_operand:VI_128 1 "nonimmediate_operand")
15754          (match_operand:SI 2 "general_operand")))]
15755   "TARGET_XOP"
15756 {
15757   /* If we were given a scalar, convert it to parallel */
15758   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
15759     {
15760       rtvec vs = rtvec_alloc (<ssescalarnum>);
15761       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
15762       rtx reg = gen_reg_rtx (<MODE>mode);
15763       rtx op2 = operands[2];
15764       int i;
15765
15766       if (GET_MODE (op2) != <ssescalarmode>mode)
15767         {
15768           op2 = gen_reg_rtx (<ssescalarmode>mode);
15769           convert_move (op2, operands[2], false);
15770         }
15771
15772       for (i = 0; i < <ssescalarnum>; i++)
15773         RTVEC_ELT (vs, i) = op2;
15774
15775       emit_insn (gen_vec_init<mode> (reg, par));
15776       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
15777       DONE;
15778     }
15779 })
15780
15781 (define_expand "rotr<mode>3"
15782   [(set (match_operand:VI_128 0 "register_operand")
15783         (rotatert:VI_128
15784          (match_operand:VI_128 1 "nonimmediate_operand")
15785          (match_operand:SI 2 "general_operand")))]
15786   "TARGET_XOP"
15787 {
15788   /* If we were given a scalar, convert it to parallel */
15789   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
15790     {
15791       rtvec vs = rtvec_alloc (<ssescalarnum>);
15792       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
15793       rtx neg = gen_reg_rtx (<MODE>mode);
15794       rtx reg = gen_reg_rtx (<MODE>mode);
15795       rtx op2 = operands[2];
15796       int i;
15797
15798       if (GET_MODE (op2) != <ssescalarmode>mode)
15799         {
15800           op2 = gen_reg_rtx (<ssescalarmode>mode);
15801           convert_move (op2, operands[2], false);
15802         }
15803
15804       for (i = 0; i < <ssescalarnum>; i++)
15805         RTVEC_ELT (vs, i) = op2;
15806
15807       emit_insn (gen_vec_init<mode> (reg, par));
15808       emit_insn (gen_neg<mode>2 (neg, reg));
15809       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], neg));
15810       DONE;
15811     }
15812 })
15813
15814 (define_insn "xop_rotl<mode>3"
15815   [(set (match_operand:VI_128 0 "register_operand" "=x")
15816         (rotate:VI_128
15817          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
15818          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
15819   "TARGET_XOP"
15820   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
15821   [(set_attr "type" "sseishft")
15822    (set_attr "length_immediate" "1")
15823    (set_attr "mode" "TI")])
15824
15825 (define_insn "xop_rotr<mode>3"
15826   [(set (match_operand:VI_128 0 "register_operand" "=x")
15827         (rotatert:VI_128
15828          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
15829          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
15830   "TARGET_XOP"
15831 {
15832   operands[3]
15833     = GEN_INT (GET_MODE_BITSIZE (<ssescalarmode>mode) - INTVAL (operands[2]));
15834   return \"vprot<ssemodesuffix>\t{%3, %1, %0|%0, %1, %3}\";
15835 }
15836   [(set_attr "type" "sseishft")
15837    (set_attr "length_immediate" "1")
15838    (set_attr "mode" "TI")])
15839
15840 (define_expand "vrotr<mode>3"
15841   [(match_operand:VI_128 0 "register_operand")
15842    (match_operand:VI_128 1 "register_operand")
15843    (match_operand:VI_128 2 "register_operand")]
15844   "TARGET_XOP"
15845 {
15846   rtx reg = gen_reg_rtx (<MODE>mode);
15847   emit_insn (gen_neg<mode>2 (reg, operands[2]));
15848   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
15849   DONE;
15850 })
15851
15852 (define_expand "vrotl<mode>3"
15853   [(match_operand:VI_128 0 "register_operand")
15854    (match_operand:VI_128 1 "register_operand")
15855    (match_operand:VI_128 2 "register_operand")]
15856   "TARGET_XOP"
15857 {
15858   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], operands[2]));
15859   DONE;
15860 })
15861
15862 (define_insn "xop_vrotl<mode>3"
15863   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
15864         (if_then_else:VI_128
15865          (ge:VI_128
15866           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
15867           (const_int 0))
15868          (rotate:VI_128
15869           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
15870           (match_dup 2))
15871          (rotatert:VI_128
15872           (match_dup 1)
15873           (neg:VI_128 (match_dup 2)))))]
15874   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
15875   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
15876   [(set_attr "type" "sseishft")
15877    (set_attr "prefix_data16" "0")
15878    (set_attr "prefix_extra" "2")
15879    (set_attr "mode" "TI")])
15880
15881 ;; XOP packed shift instructions.
15882 (define_expand "vlshr<mode>3"
15883   [(set (match_operand:VI12_128 0 "register_operand")
15884         (lshiftrt:VI12_128
15885           (match_operand:VI12_128 1 "register_operand")
15886           (match_operand:VI12_128 2 "nonimmediate_operand")))]
15887   "TARGET_XOP"
15888 {
15889   rtx neg = gen_reg_rtx (<MODE>mode);
15890   emit_insn (gen_neg<mode>2 (neg, operands[2]));
15891   emit_insn (gen_xop_shl<mode>3 (operands[0], operands[1], neg));
15892   DONE;
15893 })
15894
15895 (define_expand "vlshr<mode>3"
15896   [(set (match_operand:VI48_128 0 "register_operand")
15897         (lshiftrt:VI48_128
15898           (match_operand:VI48_128 1 "register_operand")
15899           (match_operand:VI48_128 2 "nonimmediate_operand")))]
15900   "TARGET_AVX2 || TARGET_XOP"
15901 {
15902   if (!TARGET_AVX2)
15903     {
15904       rtx neg = gen_reg_rtx (<MODE>mode);
15905       emit_insn (gen_neg<mode>2 (neg, operands[2]));
15906       emit_insn (gen_xop_shl<mode>3 (operands[0], operands[1], neg));
15907       DONE;
15908     }
15909 })
15910
15911 (define_expand "vlshr<mode>3"
15912   [(set (match_operand:VI48_512 0 "register_operand")
15913         (lshiftrt:VI48_512
15914           (match_operand:VI48_512 1 "register_operand")
15915           (match_operand:VI48_512 2 "nonimmediate_operand")))]
15916   "TARGET_AVX512F")
15917
15918 (define_expand "vlshr<mode>3"
15919   [(set (match_operand:VI48_256 0 "register_operand")
15920         (lshiftrt:VI48_256
15921           (match_operand:VI48_256 1 "register_operand")
15922           (match_operand:VI48_256 2 "nonimmediate_operand")))]
15923   "TARGET_AVX2")
15924
15925 (define_expand "vashrv8hi3<mask_name>"
15926   [(set (match_operand:V8HI 0 "register_operand")
15927         (ashiftrt:V8HI
15928           (match_operand:V8HI 1 "register_operand")
15929           (match_operand:V8HI 2 "nonimmediate_operand")))]
15930   "TARGET_XOP || (TARGET_AVX512BW && TARGET_AVX512VL)"
15931 {
15932   if (TARGET_XOP)
15933     {
15934       rtx neg = gen_reg_rtx (V8HImode);
15935       emit_insn (gen_negv8hi2 (neg, operands[2]));
15936       emit_insn (gen_xop_shav8hi3 (operands[0], operands[1], neg));
15937       DONE;
15938     }
15939 })
15940
15941 (define_expand "vashrv16qi3"
15942   [(set (match_operand:V16QI 0 "register_operand")
15943         (ashiftrt:V16QI
15944           (match_operand:V16QI 1 "register_operand")
15945           (match_operand:V16QI 2 "nonimmediate_operand")))]
15946   "TARGET_XOP"
15947 {
15948    rtx neg = gen_reg_rtx (V16QImode);
15949    emit_insn (gen_negv16qi2 (neg, operands[2]));
15950    emit_insn (gen_xop_shav16qi3 (operands[0], operands[1], neg));
15951    DONE;
15952 })
15953
15954 (define_expand "vashrv2di3<mask_name>"
15955   [(set (match_operand:V2DI 0 "register_operand")
15956         (ashiftrt:V2DI
15957           (match_operand:V2DI 1 "register_operand")
15958           (match_operand:V2DI 2 "nonimmediate_operand")))]
15959   "TARGET_XOP || TARGET_AVX512VL"
15960 {
15961   if (TARGET_XOP)
15962     {
15963       rtx neg = gen_reg_rtx (V2DImode);
15964       emit_insn (gen_negv2di2 (neg, operands[2]));
15965       emit_insn (gen_xop_shav2di3 (operands[0], operands[1], neg));
15966       DONE;
15967     }
15968 })
15969
15970 (define_expand "vashrv4si3"
15971   [(set (match_operand:V4SI 0 "register_operand")
15972         (ashiftrt:V4SI (match_operand:V4SI 1 "register_operand")
15973                        (match_operand:V4SI 2 "nonimmediate_operand")))]
15974   "TARGET_AVX2 || TARGET_XOP"
15975 {
15976   if (!TARGET_AVX2)
15977     {
15978       rtx neg = gen_reg_rtx (V4SImode);
15979       emit_insn (gen_negv4si2 (neg, operands[2]));
15980       emit_insn (gen_xop_shav4si3 (operands[0], operands[1], neg));
15981       DONE;
15982     }
15983 })
15984
15985 (define_expand "vashrv16si3"
15986   [(set (match_operand:V16SI 0 "register_operand")
15987         (ashiftrt:V16SI (match_operand:V16SI 1 "register_operand")
15988                         (match_operand:V16SI 2 "nonimmediate_operand")))]
15989   "TARGET_AVX512F")
15990
15991 (define_expand "vashrv8si3"
15992   [(set (match_operand:V8SI 0 "register_operand")
15993         (ashiftrt:V8SI (match_operand:V8SI 1 "register_operand")
15994                        (match_operand:V8SI 2 "nonimmediate_operand")))]
15995   "TARGET_AVX2")
15996
15997 (define_expand "vashl<mode>3"
15998   [(set (match_operand:VI12_128 0 "register_operand")
15999         (ashift:VI12_128
16000           (match_operand:VI12_128 1 "register_operand")
16001           (match_operand:VI12_128 2 "nonimmediate_operand")))]
16002   "TARGET_XOP"
16003 {
16004   emit_insn (gen_xop_sha<mode>3 (operands[0], operands[1], operands[2]));
16005   DONE;
16006 })
16007
16008 (define_expand "vashl<mode>3"
16009   [(set (match_operand:VI48_128 0 "register_operand")
16010         (ashift:VI48_128
16011           (match_operand:VI48_128 1 "register_operand")
16012           (match_operand:VI48_128 2 "nonimmediate_operand")))]
16013   "TARGET_AVX2 || TARGET_XOP"
16014 {
16015   if (!TARGET_AVX2)
16016     {
16017       operands[2] = force_reg (<MODE>mode, operands[2]);
16018       emit_insn (gen_xop_sha<mode>3 (operands[0], operands[1], operands[2]));
16019       DONE;
16020     }
16021 })
16022
16023 (define_expand "vashl<mode>3"
16024   [(set (match_operand:VI48_512 0 "register_operand")
16025         (ashift:VI48_512
16026           (match_operand:VI48_512 1 "register_operand")
16027           (match_operand:VI48_512 2 "nonimmediate_operand")))]
16028   "TARGET_AVX512F")
16029
16030 (define_expand "vashl<mode>3"
16031   [(set (match_operand:VI48_256 0 "register_operand")
16032         (ashift:VI48_256
16033           (match_operand:VI48_256 1 "register_operand")
16034           (match_operand:VI48_256 2 "nonimmediate_operand")))]
16035   "TARGET_AVX2")
16036
16037 (define_insn "xop_sha<mode>3"
16038   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
16039         (if_then_else:VI_128
16040          (ge:VI_128
16041           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
16042           (const_int 0))
16043          (ashift:VI_128
16044           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
16045           (match_dup 2))
16046          (ashiftrt:VI_128
16047           (match_dup 1)
16048           (neg:VI_128 (match_dup 2)))))]
16049   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
16050   "vpsha<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
16051   [(set_attr "type" "sseishft")
16052    (set_attr "prefix_data16" "0")
16053    (set_attr "prefix_extra" "2")
16054    (set_attr "mode" "TI")])
16055
16056 (define_insn "xop_shl<mode>3"
16057   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
16058         (if_then_else:VI_128
16059          (ge:VI_128
16060           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
16061           (const_int 0))
16062          (ashift:VI_128
16063           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
16064           (match_dup 2))
16065          (lshiftrt:VI_128
16066           (match_dup 1)
16067           (neg:VI_128 (match_dup 2)))))]
16068   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
16069   "vpshl<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
16070   [(set_attr "type" "sseishft")
16071    (set_attr "prefix_data16" "0")
16072    (set_attr "prefix_extra" "2")
16073    (set_attr "mode" "TI")])
16074
16075 (define_expand "<shift_insn><mode>3"
16076   [(set (match_operand:VI1_AVX512 0 "register_operand")
16077         (any_shift:VI1_AVX512
16078           (match_operand:VI1_AVX512 1 "register_operand")
16079           (match_operand:SI 2 "nonmemory_operand")))]
16080   "TARGET_SSE2"
16081 {
16082   if (TARGET_XOP && <MODE>mode == V16QImode)
16083     {
16084       bool negate = false;
16085       rtx (*gen) (rtx, rtx, rtx);
16086       rtx tmp, par;
16087       int i;
16088
16089       if (<CODE> != ASHIFT)
16090         {
16091           if (CONST_INT_P (operands[2]))
16092             operands[2] = GEN_INT (-INTVAL (operands[2]));
16093           else
16094             negate = true;
16095         }
16096       par = gen_rtx_PARALLEL (V16QImode, rtvec_alloc (16));
16097       for (i = 0; i < 16; i++)
16098         XVECEXP (par, 0, i) = operands[2];
16099
16100       tmp = gen_reg_rtx (V16QImode);
16101       emit_insn (gen_vec_initv16qi (tmp, par));
16102
16103       if (negate)
16104         emit_insn (gen_negv16qi2 (tmp, tmp));
16105
16106       gen = (<CODE> == LSHIFTRT ? gen_xop_shlv16qi3 : gen_xop_shav16qi3);
16107       emit_insn (gen (operands[0], operands[1], tmp));
16108     }
16109   else
16110     ix86_expand_vecop_qihi (<CODE>, operands[0], operands[1], operands[2]);
16111   DONE;
16112 })
16113
16114 (define_expand "ashrv2di3"
16115   [(set (match_operand:V2DI 0 "register_operand")
16116         (ashiftrt:V2DI
16117           (match_operand:V2DI 1 "register_operand")
16118           (match_operand:DI 2 "nonmemory_operand")))]
16119   "TARGET_XOP || TARGET_AVX512VL"
16120 {
16121   if (!TARGET_AVX512VL)
16122     {
16123       rtx reg = gen_reg_rtx (V2DImode);
16124       rtx par;
16125       bool negate = false;
16126       int i;
16127
16128       if (CONST_INT_P (operands[2]))
16129         operands[2] = GEN_INT (-INTVAL (operands[2]));
16130       else
16131         negate = true;
16132
16133       par = gen_rtx_PARALLEL (V2DImode, rtvec_alloc (2));
16134       for (i = 0; i < 2; i++)
16135         XVECEXP (par, 0, i) = operands[2];
16136
16137       emit_insn (gen_vec_initv2di (reg, par));
16138
16139       if (negate)
16140         emit_insn (gen_negv2di2 (reg, reg));
16141
16142       emit_insn (gen_xop_shav2di3 (operands[0], operands[1], reg));
16143       DONE;
16144     }
16145 })
16146
16147 ;; XOP FRCZ support
16148 (define_insn "xop_frcz<mode>2"
16149   [(set (match_operand:FMAMODE 0 "register_operand" "=x")
16150         (unspec:FMAMODE
16151          [(match_operand:FMAMODE 1 "nonimmediate_operand" "xm")]
16152          UNSPEC_FRCZ))]
16153   "TARGET_XOP"
16154   "vfrcz<ssemodesuffix>\t{%1, %0|%0, %1}"
16155   [(set_attr "type" "ssecvt1")
16156    (set_attr "mode" "<MODE>")])
16157
16158 (define_expand "xop_vmfrcz<mode>2"
16159   [(set (match_operand:VF_128 0 "register_operand")
16160         (vec_merge:VF_128
16161           (unspec:VF_128
16162            [(match_operand:VF_128 1 "nonimmediate_operand")]
16163            UNSPEC_FRCZ)
16164           (match_dup 2)
16165           (const_int 1)))]
16166   "TARGET_XOP"
16167   "operands[2] = CONST0_RTX (<MODE>mode);")
16168
16169 (define_insn "*xop_vmfrcz<mode>2"
16170   [(set (match_operand:VF_128 0 "register_operand" "=x")
16171         (vec_merge:VF_128
16172           (unspec:VF_128
16173            [(match_operand:VF_128 1 "nonimmediate_operand" "xm")]
16174            UNSPEC_FRCZ)
16175           (match_operand:VF_128 2 "const0_operand")
16176           (const_int 1)))]
16177   "TARGET_XOP"
16178   "vfrcz<ssescalarmodesuffix>\t{%1, %0|%0, %<iptr>1}"
16179   [(set_attr "type" "ssecvt1")
16180    (set_attr "mode" "<MODE>")])
16181
16182 (define_insn "xop_maskcmp<mode>3"
16183   [(set (match_operand:VI_128 0 "register_operand" "=x")
16184         (match_operator:VI_128 1 "ix86_comparison_int_operator"
16185          [(match_operand:VI_128 2 "register_operand" "x")
16186           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
16187   "TARGET_XOP"
16188   "vpcom%Y1<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
16189   [(set_attr "type" "sse4arg")
16190    (set_attr "prefix_data16" "0")
16191    (set_attr "prefix_rep" "0")
16192    (set_attr "prefix_extra" "2")
16193    (set_attr "length_immediate" "1")
16194    (set_attr "mode" "TI")])
16195
16196 (define_insn "xop_maskcmp_uns<mode>3"
16197   [(set (match_operand:VI_128 0 "register_operand" "=x")
16198         (match_operator:VI_128 1 "ix86_comparison_uns_operator"
16199          [(match_operand:VI_128 2 "register_operand" "x")
16200           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
16201   "TARGET_XOP"
16202   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
16203   [(set_attr "type" "ssecmp")
16204    (set_attr "prefix_data16" "0")
16205    (set_attr "prefix_rep" "0")
16206    (set_attr "prefix_extra" "2")
16207    (set_attr "length_immediate" "1")
16208    (set_attr "mode" "TI")])
16209
16210 ;; Version of pcom*u* that is called from the intrinsics that allows pcomequ*
16211 ;; and pcomneu* not to be converted to the signed ones in case somebody needs
16212 ;; the exact instruction generated for the intrinsic.
16213 (define_insn "xop_maskcmp_uns2<mode>3"
16214   [(set (match_operand:VI_128 0 "register_operand" "=x")
16215         (unspec:VI_128
16216          [(match_operator:VI_128 1 "ix86_comparison_uns_operator"
16217           [(match_operand:VI_128 2 "register_operand" "x")
16218            (match_operand:VI_128 3 "nonimmediate_operand" "xm")])]
16219          UNSPEC_XOP_UNSIGNED_CMP))]
16220   "TARGET_XOP"
16221   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
16222   [(set_attr "type" "ssecmp")
16223    (set_attr "prefix_data16" "0")
16224    (set_attr "prefix_extra" "2")
16225    (set_attr "length_immediate" "1")
16226    (set_attr "mode" "TI")])
16227
16228 ;; Pcomtrue and pcomfalse support.  These are useless instructions, but are
16229 ;; being added here to be complete.
16230 (define_insn "xop_pcom_tf<mode>3"
16231   [(set (match_operand:VI_128 0 "register_operand" "=x")
16232         (unspec:VI_128
16233           [(match_operand:VI_128 1 "register_operand" "x")
16234            (match_operand:VI_128 2 "nonimmediate_operand" "xm")
16235            (match_operand:SI 3 "const_int_operand" "n")]
16236           UNSPEC_XOP_TRUEFALSE))]
16237   "TARGET_XOP"
16238 {
16239   return ((INTVAL (operands[3]) != 0)
16240           ? "vpcomtrue<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
16241           : "vpcomfalse<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}");
16242 }
16243   [(set_attr "type" "ssecmp")
16244    (set_attr "prefix_data16" "0")
16245    (set_attr "prefix_extra" "2")
16246    (set_attr "length_immediate" "1")
16247    (set_attr "mode" "TI")])
16248
16249 (define_insn "xop_vpermil2<mode>3"
16250   [(set (match_operand:VF_128_256 0 "register_operand" "=x")
16251         (unspec:VF_128_256
16252           [(match_operand:VF_128_256 1 "register_operand" "x")
16253            (match_operand:VF_128_256 2 "nonimmediate_operand" "%x")
16254            (match_operand:<sseintvecmode> 3 "nonimmediate_operand" "xm")
16255            (match_operand:SI 4 "const_0_to_3_operand" "n")]
16256           UNSPEC_VPERMIL2))]
16257   "TARGET_XOP"
16258   "vpermil2<ssemodesuffix>\t{%4, %3, %2, %1, %0|%0, %1, %2, %3, %4}"
16259   [(set_attr "type" "sse4arg")
16260    (set_attr "length_immediate" "1")
16261    (set_attr "mode" "<MODE>")])
16262
16263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16264
16265 (define_insn "aesenc"
16266   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
16267         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
16268                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
16269                       UNSPEC_AESENC))]
16270   "TARGET_AES"
16271   "@
16272    aesenc\t{%2, %0|%0, %2}
16273    vaesenc\t{%2, %1, %0|%0, %1, %2}"
16274   [(set_attr "isa" "noavx,avx")
16275    (set_attr "type" "sselog1")
16276    (set_attr "prefix_extra" "1")
16277    (set_attr "prefix" "orig,vex")
16278    (set_attr "btver2_decode" "double,double")
16279    (set_attr "mode" "TI")])
16280
16281 (define_insn "aesenclast"
16282   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
16283         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
16284                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
16285                       UNSPEC_AESENCLAST))]
16286   "TARGET_AES"
16287   "@
16288    aesenclast\t{%2, %0|%0, %2}
16289    vaesenclast\t{%2, %1, %0|%0, %1, %2}"
16290   [(set_attr "isa" "noavx,avx")
16291    (set_attr "type" "sselog1")
16292    (set_attr "prefix_extra" "1")
16293    (set_attr "prefix" "orig,vex")
16294    (set_attr "btver2_decode" "double,double") 
16295    (set_attr "mode" "TI")])
16296
16297 (define_insn "aesdec"
16298   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
16299         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
16300                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
16301                       UNSPEC_AESDEC))]
16302   "TARGET_AES"
16303   "@
16304    aesdec\t{%2, %0|%0, %2}
16305    vaesdec\t{%2, %1, %0|%0, %1, %2}"
16306   [(set_attr "isa" "noavx,avx")
16307    (set_attr "type" "sselog1")
16308    (set_attr "prefix_extra" "1")
16309    (set_attr "prefix" "orig,vex")
16310    (set_attr "btver2_decode" "double,double") 
16311    (set_attr "mode" "TI")])
16312
16313 (define_insn "aesdeclast"
16314   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
16315         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
16316                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
16317                       UNSPEC_AESDECLAST))]
16318   "TARGET_AES"
16319   "@
16320    aesdeclast\t{%2, %0|%0, %2}
16321    vaesdeclast\t{%2, %1, %0|%0, %1, %2}"
16322   [(set_attr "isa" "noavx,avx")
16323    (set_attr "type" "sselog1")
16324    (set_attr "prefix_extra" "1")
16325    (set_attr "prefix" "orig,vex")
16326    (set_attr "btver2_decode" "double,double")
16327    (set_attr "mode" "TI")])
16328
16329 (define_insn "aesimc"
16330   [(set (match_operand:V2DI 0 "register_operand" "=x")
16331         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")]
16332                       UNSPEC_AESIMC))]
16333   "TARGET_AES"
16334   "%vaesimc\t{%1, %0|%0, %1}"
16335   [(set_attr "type" "sselog1")
16336    (set_attr "prefix_extra" "1")
16337    (set_attr "prefix" "maybe_vex")
16338    (set_attr "mode" "TI")])
16339
16340 (define_insn "aeskeygenassist"
16341   [(set (match_operand:V2DI 0 "register_operand" "=x")
16342         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")
16343                       (match_operand:SI 2 "const_0_to_255_operand" "n")]
16344                      UNSPEC_AESKEYGENASSIST))]
16345   "TARGET_AES"
16346   "%vaeskeygenassist\t{%2, %1, %0|%0, %1, %2}"
16347   [(set_attr "type" "sselog1")
16348    (set_attr "prefix_extra" "1")
16349    (set_attr "length_immediate" "1")
16350    (set_attr "prefix" "maybe_vex")
16351    (set_attr "mode" "TI")])
16352
16353 (define_insn "pclmulqdq"
16354   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
16355         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
16356                       (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")
16357                       (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
16358                      UNSPEC_PCLMUL))]
16359   "TARGET_PCLMUL"
16360   "@
16361    pclmulqdq\t{%3, %2, %0|%0, %2, %3}
16362    vpclmulqdq\t{%3, %2, %1, %0|%0, %1, %2, %3}"
16363   [(set_attr "isa" "noavx,avx")
16364    (set_attr "type" "sselog1")
16365    (set_attr "prefix_extra" "1")
16366    (set_attr "length_immediate" "1")
16367    (set_attr "prefix" "orig,vex")
16368    (set_attr "mode" "TI")])
16369
16370 (define_expand "avx_vzeroall"
16371   [(match_par_dup 0 [(const_int 0)])]
16372   "TARGET_AVX"
16373 {
16374   int nregs = TARGET_64BIT ? 16 : 8;
16375   int regno;
16376
16377   operands[0] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs + 1));
16378
16379   XVECEXP (operands[0], 0, 0)
16380     = gen_rtx_UNSPEC_VOLATILE (VOIDmode, gen_rtvec (1, const0_rtx),
16381                                UNSPECV_VZEROALL);
16382
16383   for (regno = 0; regno < nregs; regno++)
16384     XVECEXP (operands[0], 0, regno + 1)
16385       = gen_rtx_SET (VOIDmode,
16386                      gen_rtx_REG (V8SImode, SSE_REGNO (regno)),
16387                      CONST0_RTX (V8SImode));
16388 })
16389
16390 (define_insn "*avx_vzeroall"
16391   [(match_parallel 0 "vzeroall_operation"
16392     [(unspec_volatile [(const_int 0)] UNSPECV_VZEROALL)])]
16393   "TARGET_AVX"
16394   "vzeroall"
16395   [(set_attr "type" "sse")
16396    (set_attr "modrm" "0")
16397    (set_attr "memory" "none")
16398    (set_attr "prefix" "vex")
16399    (set_attr "btver2_decode" "vector")
16400    (set_attr "mode" "OI")])
16401
16402 ;; Clear the upper 128bits of AVX registers, equivalent to a NOP
16403 ;; if the upper 128bits are unused.
16404 (define_insn "avx_vzeroupper"
16405   [(unspec_volatile [(const_int 0)] UNSPECV_VZEROUPPER)]
16406   "TARGET_AVX"
16407   "vzeroupper"
16408   [(set_attr "type" "sse")
16409    (set_attr "modrm" "0")
16410    (set_attr "memory" "none")
16411    (set_attr "prefix" "vex")
16412    (set_attr "btver2_decode" "vector")
16413    (set_attr "mode" "OI")])
16414
16415 (define_insn "avx2_pbroadcast<mode>"
16416   [(set (match_operand:VI 0 "register_operand" "=x")
16417         (vec_duplicate:VI
16418           (vec_select:<ssescalarmode>
16419             (match_operand:<ssexmmmode> 1 "nonimmediate_operand" "xm")
16420             (parallel [(const_int 0)]))))]
16421   "TARGET_AVX2"
16422   "vpbroadcast<ssemodesuffix>\t{%1, %0|%0, %<iptr>1}"
16423   [(set_attr "type" "ssemov")
16424    (set_attr "prefix_extra" "1")
16425    (set_attr "prefix" "vex")
16426    (set_attr "mode" "<sseinsnmode>")])
16427
16428 (define_insn "avx2_pbroadcast<mode>_1"
16429   [(set (match_operand:VI_256 0 "register_operand" "=x,x")
16430         (vec_duplicate:VI_256
16431           (vec_select:<ssescalarmode>
16432             (match_operand:VI_256 1 "nonimmediate_operand" "m,x")
16433             (parallel [(const_int 0)]))))]
16434   "TARGET_AVX2"
16435   "@
16436    vpbroadcast<ssemodesuffix>\t{%1, %0|%0, %<iptr>1}
16437    vpbroadcast<ssemodesuffix>\t{%x1, %0|%0, %x1}"
16438   [(set_attr "type" "ssemov")
16439    (set_attr "prefix_extra" "1")
16440    (set_attr "prefix" "vex")
16441    (set_attr "mode" "<sseinsnmode>")])
16442
16443 (define_insn "<avx2_avx512>_permvar<mode><mask_name>"
16444   [(set (match_operand:VI48F_256_512 0 "register_operand" "=v")
16445         (unspec:VI48F_256_512
16446           [(match_operand:VI48F_256_512 1 "nonimmediate_operand" "vm")
16447            (match_operand:<sseintvecmode> 2 "register_operand" "v")]
16448           UNSPEC_VPERMVAR))]
16449   "TARGET_AVX2 && <mask_mode512bit_condition>"
16450   "vperm<ssemodesuffix>\t{%1, %2, %0<mask_operand3>|%0<mask_operand3>, %2, %1}"
16451   [(set_attr "type" "sselog")
16452    (set_attr "prefix" "<mask_prefix2>")
16453    (set_attr "mode" "<sseinsnmode>")])
16454
16455 (define_insn "<avx512>_permvar<mode><mask_name>"
16456   [(set (match_operand:VI1_AVX512VL 0 "register_operand" "=v")
16457         (unspec:VI1_AVX512VL
16458           [(match_operand:VI1_AVX512VL 1 "nonimmediate_operand" "vm")
16459            (match_operand:<sseintvecmode> 2 "register_operand" "v")]
16460           UNSPEC_VPERMVAR))]
16461   "TARGET_AVX512VBMI && <mask_mode512bit_condition>"
16462   "vperm<ssemodesuffix>\t{%1, %2, %0<mask_operand3>|%0<mask_operand3>, %2, %1}"
16463   [(set_attr "type" "sselog")
16464    (set_attr "prefix" "<mask_prefix2>")
16465    (set_attr "mode" "<sseinsnmode>")])
16466
16467 (define_insn "<avx512>_permvar<mode><mask_name>"
16468   [(set (match_operand:VI2_AVX512VL 0 "register_operand" "=v")
16469         (unspec:VI2_AVX512VL
16470           [(match_operand:VI2_AVX512VL 1 "nonimmediate_operand" "vm")
16471            (match_operand:<sseintvecmode> 2 "register_operand" "v")]
16472           UNSPEC_VPERMVAR))]
16473   "TARGET_AVX512BW && <mask_mode512bit_condition>"
16474   "vperm<ssemodesuffix>\t{%1, %2, %0<mask_operand3>|%0<mask_operand3>, %2, %1}"
16475   [(set_attr "type" "sselog")
16476    (set_attr "prefix" "<mask_prefix2>")
16477    (set_attr "mode" "<sseinsnmode>")])
16478
16479 (define_expand "<avx2_avx512>_perm<mode>"
16480   [(match_operand:VI8F_256_512 0 "register_operand")
16481    (match_operand:VI8F_256_512 1 "nonimmediate_operand")
16482    (match_operand:SI 2 "const_0_to_255_operand")]
16483   "TARGET_AVX2"
16484 {
16485   int mask = INTVAL (operands[2]);
16486   emit_insn (gen_<avx2_avx512>_perm<mode>_1 (operands[0], operands[1],
16487                                               GEN_INT ((mask >> 0) & 3),
16488                                               GEN_INT ((mask >> 2) & 3),
16489                                               GEN_INT ((mask >> 4) & 3),
16490                                               GEN_INT ((mask >> 6) & 3)));
16491   DONE;
16492 })
16493
16494 (define_expand "<avx512>_perm<mode>_mask"
16495   [(match_operand:VI8F_256_512 0 "register_operand")
16496    (match_operand:VI8F_256_512 1 "nonimmediate_operand")
16497    (match_operand:SI 2 "const_0_to_255_operand")
16498    (match_operand:VI8F_256_512 3 "vector_move_operand")
16499    (match_operand:<avx512fmaskmode> 4 "register_operand")]
16500   "TARGET_AVX512F"
16501 {
16502   int mask = INTVAL (operands[2]);
16503   emit_insn (gen_<avx2_avx512>_perm<mode>_1_mask (operands[0], operands[1],
16504                                                    GEN_INT ((mask >> 0) & 3),
16505                                                    GEN_INT ((mask >> 2) & 3),
16506                                                    GEN_INT ((mask >> 4) & 3),
16507                                                    GEN_INT ((mask >> 6) & 3),
16508                                                    operands[3], operands[4]));
16509   DONE;
16510 })
16511
16512 (define_insn "<avx2_avx512>_perm<mode>_1<mask_name>"
16513   [(set (match_operand:VI8F_256_512 0 "register_operand" "=v")
16514         (vec_select:VI8F_256_512
16515           (match_operand:VI8F_256_512 1 "nonimmediate_operand" "vm")
16516           (parallel [(match_operand 2 "const_0_to_3_operand")
16517                      (match_operand 3 "const_0_to_3_operand")
16518                      (match_operand 4 "const_0_to_3_operand")
16519                      (match_operand 5 "const_0_to_3_operand")])))]
16520   "TARGET_AVX2 && <mask_mode512bit_condition>"
16521 {
16522   int mask = 0;
16523   mask |= INTVAL (operands[2]) << 0;
16524   mask |= INTVAL (operands[3]) << 2;
16525   mask |= INTVAL (operands[4]) << 4;
16526   mask |= INTVAL (operands[5]) << 6;
16527   operands[2] = GEN_INT (mask);
16528   return "vperm<ssemodesuffix>\t{%2, %1, %0<mask_operand6>|%0<mask_operand6>, %1, %2}";
16529 }
16530   [(set_attr "type" "sselog")
16531    (set_attr "prefix" "<mask_prefix2>")
16532    (set_attr "mode" "<sseinsnmode>")])
16533
16534 (define_insn "avx2_permv2ti"
16535   [(set (match_operand:V4DI 0 "register_operand" "=x")
16536         (unspec:V4DI
16537           [(match_operand:V4DI 1 "register_operand" "x")
16538            (match_operand:V4DI 2 "nonimmediate_operand" "xm")
16539            (match_operand:SI 3 "const_0_to_255_operand" "n")]
16540           UNSPEC_VPERMTI))]
16541   "TARGET_AVX2"
16542   "vperm2i128\t{%3, %2, %1, %0|%0, %1, %2, %3}"
16543   [(set_attr "type" "sselog")
16544    (set_attr "prefix" "vex")
16545    (set_attr "mode" "OI")])
16546
16547 (define_insn "avx2_vec_dupv4df"
16548   [(set (match_operand:V4DF 0 "register_operand" "=x")
16549         (vec_duplicate:V4DF
16550           (vec_select:DF
16551             (match_operand:V2DF 1 "register_operand" "x")
16552             (parallel [(const_int 0)]))))]
16553   "TARGET_AVX2"
16554   "vbroadcastsd\t{%1, %0|%0, %1}"
16555   [(set_attr "type" "sselog1")
16556    (set_attr "prefix" "vex")
16557    (set_attr "mode" "V4DF")])
16558
16559 (define_insn "<avx512>_vec_dup<mode>_1"
16560   [(set (match_operand:VI_AVX512BW 0 "register_operand" "=v,v")
16561         (vec_duplicate:VI_AVX512BW
16562           (vec_select:VI_AVX512BW
16563             (match_operand:VI_AVX512BW 1 "nonimmediate_operand" "v,m")
16564             (parallel [(const_int 0)]))))]
16565   "TARGET_AVX512F"
16566   "vpbroadcast<ssemodesuffix>\t{%1, %0|%0, %<iptr>1}
16567    vpbroadcast<ssemodesuffix>\t{%x1, %0|%0, %x1}"
16568   [(set_attr "type" "ssemov")
16569    (set_attr "prefix" "evex")
16570    (set_attr "mode" "<sseinsnmode>")])
16571
16572 (define_insn "<avx512>_vec_dup<mode><mask_name>"
16573   [(set (match_operand:V48_AVX512VL 0 "register_operand" "=v")
16574         (vec_duplicate:V48_AVX512VL
16575           (vec_select:<ssescalarmode>
16576             (match_operand:<ssexmmmode> 1 "nonimmediate_operand" "vm")
16577             (parallel [(const_int 0)]))))]
16578   "TARGET_AVX512F"
16579   "v<sseintprefix>broadcast<bcstscalarsuff>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
16580   [(set_attr "type" "ssemov")
16581    (set_attr "prefix" "evex")
16582    (set_attr "mode" "<sseinsnmode>")])
16583
16584 (define_insn "<avx512>_vec_dup<mode><mask_name>"
16585   [(set (match_operand:VI12_AVX512VL 0 "register_operand" "=v")
16586         (vec_duplicate:VI12_AVX512VL
16587           (vec_select:<ssescalarmode>
16588             (match_operand:<ssexmmmode> 1 "nonimmediate_operand" "vm")
16589             (parallel [(const_int 0)]))))]
16590   "TARGET_AVX512BW"
16591   "vpbroadcast<bcstscalarsuff>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
16592   [(set_attr "type" "ssemov")
16593    (set_attr "prefix" "evex")
16594    (set_attr "mode" "<sseinsnmode>")])
16595
16596 (define_insn "<mask_codefor>avx512f_broadcast<mode><mask_name>"
16597   [(set (match_operand:V16FI 0 "register_operand" "=v,v")
16598         (vec_duplicate:V16FI
16599           (match_operand:<ssexmmmode> 1 "nonimmediate_operand" "v,m")))]
16600   "TARGET_AVX512F"
16601   "@
16602    vshuf<shuffletype>32x4\t{$0x0, %g1, %g1, %0<mask_operand2>|%0<mask_operand2>, %g1, %g1, 0x0}
16603    vbroadcast<shuffletype>32x4\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
16604   [(set_attr "type" "ssemov")
16605    (set_attr "prefix" "evex")
16606    (set_attr "mode" "<sseinsnmode>")])
16607
16608 (define_insn "<mask_codefor>avx512f_broadcast<mode><mask_name>"
16609   [(set (match_operand:V8FI 0 "register_operand" "=v,v")
16610         (vec_duplicate:V8FI
16611           (match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "v,m")))]
16612   "TARGET_AVX512F"
16613   "@
16614    vshuf<shuffletype>64x2\t{$0x44, %g1, %g1, %0<mask_operand2>|%0<mask_operand2>, %g1, %g1, 0x44}
16615    vbroadcast<shuffletype>64x4\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
16616   [(set_attr "type" "ssemov")
16617    (set_attr "prefix" "evex")
16618    (set_attr "mode" "<sseinsnmode>")])
16619
16620 (define_insn "<mask_codefor><avx512>_vec_dup_gpr<mode><mask_name>"
16621   [(set (match_operand:VI12_AVX512VL 0 "register_operand" "=v,v")
16622         (vec_duplicate:VI12_AVX512VL
16623           (match_operand:<ssescalarmode> 1 "nonimmediate_operand" "vm,r")))]
16624   "TARGET_AVX512BW"
16625   "@
16626    vpbroadcast<bcstscalarsuff>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}
16627    vpbroadcast<bcstscalarsuff>\t{%k1, %0<mask_operand2>|%0<mask_operand2>, %k1}"
16628   [(set_attr "type" "ssemov")
16629    (set_attr "prefix" "evex")
16630    (set_attr "mode" "<sseinsnmode>")])
16631
16632 (define_insn "<mask_codefor><avx512>_vec_dup_gpr<mode><mask_name>"
16633   [(set (match_operand:V48_AVX512VL 0 "register_operand" "=v,v")
16634         (vec_duplicate:V48_AVX512VL
16635           (match_operand:<ssescalarmode> 1 "nonimmediate_operand" "vm,r")))]
16636   "TARGET_AVX512F"
16637   "v<sseintprefix>broadcast<bcstscalarsuff>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
16638   [(set_attr "type" "ssemov")
16639    (set_attr "prefix" "evex")
16640    (set_attr "mode" "<sseinsnmode>")
16641    (set (attr "enabled")
16642      (if_then_else (eq_attr "alternative" "1")
16643         (symbol_ref "GET_MODE_CLASS (<ssescalarmode>mode) == MODE_INT
16644                      && (<ssescalarmode>mode != DImode || TARGET_64BIT)")
16645         (const_int 1)))])
16646
16647 (define_insn "vec_dupv4sf"
16648   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
16649         (vec_duplicate:V4SF
16650           (match_operand:SF 1 "nonimmediate_operand" "x,m,0")))]
16651   "TARGET_SSE"
16652   "@
16653    vshufps\t{$0, %1, %1, %0|%0, %1, %1, 0}
16654    vbroadcastss\t{%1, %0|%0, %1}
16655    shufps\t{$0, %0, %0|%0, %0, 0}"
16656   [(set_attr "isa" "avx,avx,noavx")
16657    (set_attr "type" "sseshuf1,ssemov,sseshuf1")
16658    (set_attr "length_immediate" "1,0,1")
16659    (set_attr "prefix_extra" "0,1,*")
16660    (set_attr "prefix" "vex,vex,orig")
16661    (set_attr "mode" "V4SF")])
16662
16663 (define_insn "*vec_dupv4si"
16664   [(set (match_operand:V4SI 0 "register_operand"     "=x,x,x")
16665         (vec_duplicate:V4SI
16666           (match_operand:SI 1 "nonimmediate_operand" " x,m,0")))]
16667   "TARGET_SSE"
16668   "@
16669    %vpshufd\t{$0, %1, %0|%0, %1, 0}
16670    vbroadcastss\t{%1, %0|%0, %1}
16671    shufps\t{$0, %0, %0|%0, %0, 0}"
16672   [(set_attr "isa" "sse2,avx,noavx")
16673    (set_attr "type" "sselog1,ssemov,sselog1")
16674    (set_attr "length_immediate" "1,0,1")
16675    (set_attr "prefix_extra" "0,1,*")
16676    (set_attr "prefix" "maybe_vex,vex,orig")
16677    (set_attr "mode" "TI,V4SF,V4SF")])
16678
16679 (define_insn "*vec_dupv2di"
16680   [(set (match_operand:V2DI 0 "register_operand"     "=x,x,x,x")
16681         (vec_duplicate:V2DI
16682           (match_operand:DI 1 "nonimmediate_operand" " 0,x,m,0")))]
16683   "TARGET_SSE"
16684   "@
16685    punpcklqdq\t%0, %0
16686    vpunpcklqdq\t{%d1, %0|%0, %d1}
16687    %vmovddup\t{%1, %0|%0, %1}
16688    movlhps\t%0, %0"
16689   [(set_attr "isa" "sse2_noavx,avx,sse3,noavx")
16690    (set_attr "type" "sselog1,sselog1,sselog1,ssemov")
16691    (set_attr "prefix" "orig,vex,maybe_vex,orig")
16692    (set_attr "mode" "TI,TI,DF,V4SF")])
16693
16694 (define_insn "avx2_vbroadcasti128_<mode>"
16695   [(set (match_operand:VI_256 0 "register_operand" "=x")
16696         (vec_concat:VI_256
16697           (match_operand:<ssehalfvecmode> 1 "memory_operand" "m")
16698           (match_dup 1)))]
16699   "TARGET_AVX2"
16700   "vbroadcasti128\t{%1, %0|%0, %1}"
16701   [(set_attr "type" "ssemov")
16702    (set_attr "prefix_extra" "1")
16703    (set_attr "prefix" "vex")
16704    (set_attr "mode" "OI")])
16705
16706 ;; Modes handled by AVX vec_dup patterns.
16707 (define_mode_iterator AVX_VEC_DUP_MODE
16708   [V8SI V8SF V4DI V4DF])
16709 ;; Modes handled by AVX2 vec_dup patterns.
16710 (define_mode_iterator AVX2_VEC_DUP_MODE
16711   [V32QI V16QI V16HI V8HI V8SI V4SI])
16712
16713 (define_insn "*vec_dup<mode>"
16714   [(set (match_operand:AVX2_VEC_DUP_MODE 0 "register_operand" "=x,x,Yi")
16715         (vec_duplicate:AVX2_VEC_DUP_MODE
16716           (match_operand:<ssescalarmode> 1 "nonimmediate_operand" "m,x,$r")))]
16717   "TARGET_AVX2"
16718   "@
16719    v<sseintprefix>broadcast<bcstscalarsuff>\t{%1, %0|%0, %1}
16720    v<sseintprefix>broadcast<bcstscalarsuff>\t{%x1, %0|%0, %x1}
16721    #"
16722   [(set_attr "type" "ssemov")
16723    (set_attr "prefix_extra" "1")
16724    (set_attr "prefix" "maybe_evex")
16725    (set_attr "mode" "<sseinsnmode>")])
16726
16727 (define_insn "vec_dup<mode>"
16728   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "=x,x,v,x")
16729         (vec_duplicate:AVX_VEC_DUP_MODE
16730           (match_operand:<ssescalarmode> 1 "nonimmediate_operand" "m,m,v,?x")))]
16731   "TARGET_AVX"
16732   "@
16733    v<sseintprefix>broadcast<bcstscalarsuff>\t{%1, %0|%0, %1}
16734    vbroadcast<ssescalarmodesuffix>\t{%1, %0|%0, %1}
16735    v<sseintprefix>broadcast<bcstscalarsuff>\t{%x1, %0|%0, %x1}
16736    #"
16737   [(set_attr "type" "ssemov")
16738    (set_attr "prefix_extra" "1")
16739    (set_attr "prefix" "maybe_evex")
16740    (set_attr "isa" "avx2,noavx2,avx2,noavx2")
16741    (set_attr "mode" "<sseinsnmode>,V8SF,<sseinsnmode>,V8SF")])
16742
16743 (define_split
16744   [(set (match_operand:AVX2_VEC_DUP_MODE 0 "register_operand")
16745         (vec_duplicate:AVX2_VEC_DUP_MODE
16746           (match_operand:<ssescalarmode> 1 "register_operand")))]
16747   "TARGET_AVX2
16748    /* Disable this splitter if avx512vl_vec_dup_gprv*[qhs]i insn is
16749       available, because then we can broadcast from GPRs directly.
16750       For V*[QH]I modes it requires both -mavx512vl and -mavx512bw,
16751       for V*SI mode it requires just -mavx512vl.  */
16752    && !(TARGET_AVX512VL
16753         && (TARGET_AVX512BW || <ssescalarmode>mode == SImode))
16754    && reload_completed && GENERAL_REG_P (operands[1])"
16755   [(const_int 0)]
16756 {
16757   emit_insn (gen_vec_setv4si_0 (gen_lowpart (V4SImode, operands[0]),
16758                                 CONST0_RTX (V4SImode),
16759                                 gen_lowpart (SImode, operands[1])));
16760   emit_insn (gen_avx2_pbroadcast<mode> (operands[0],
16761                                         gen_lowpart (<ssexmmmode>mode,
16762                                                      operands[0])));
16763   DONE;
16764 })
16765
16766 (define_split
16767   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand")
16768         (vec_duplicate:AVX_VEC_DUP_MODE
16769           (match_operand:<ssescalarmode> 1 "register_operand")))]
16770   "TARGET_AVX && !TARGET_AVX2 && reload_completed"
16771   [(set (match_dup 2)
16772         (vec_duplicate:<ssehalfvecmode> (match_dup 1)))
16773    (set (match_dup 0)
16774         (vec_concat:AVX_VEC_DUP_MODE (match_dup 2) (match_dup 2)))]
16775   "operands[2] = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (operands[0]));")
16776
16777 (define_insn "avx_vbroadcastf128_<mode>"
16778   [(set (match_operand:V_256 0 "register_operand" "=x,x,x")
16779         (vec_concat:V_256
16780           (match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "m,0,?x")
16781           (match_dup 1)))]
16782   "TARGET_AVX"
16783   "@
16784    vbroadcast<i128>\t{%1, %0|%0, %1}
16785    vinsert<i128>\t{$1, %1, %0, %0|%0, %0, %1, 1}
16786    vperm2<i128>\t{$0, %t1, %t1, %0|%0, %t1, %t1, 0}"
16787   [(set_attr "type" "ssemov,sselog1,sselog1")
16788    (set_attr "prefix_extra" "1")
16789    (set_attr "length_immediate" "0,1,1")
16790    (set_attr "prefix" "vex")
16791    (set_attr "mode" "<sseinsnmode>")])
16792
16793 ;; For broadcast[i|f]32x2.  Yes there is no v4sf version, only v4si.
16794 (define_mode_iterator VI4F_BRCST32x2
16795   [V16SI (V8SI "TARGET_AVX512VL") (V4SI "TARGET_AVX512VL")
16796    V16SF (V8SF "TARGET_AVX512VL")])
16797
16798 (define_mode_attr 64x2mode
16799   [(V8DF "V2DF") (V8DI "V2DI") (V4DI "V2DI") (V4DF "V2DF")])
16800
16801 (define_mode_attr 32x2mode
16802   [(V16SF "V2SF") (V16SI "V2SI") (V8SI "V2SI")
16803   (V8SF "V2SF") (V4SI "V2SI")])
16804
16805 (define_insn "<mask_codefor>avx512dq_broadcast<mode><mask_name>"
16806   [(set (match_operand:VI4F_BRCST32x2 0 "register_operand" "=v")
16807         (vec_duplicate:VI4F_BRCST32x2
16808           (vec_select:<32x2mode>
16809             (match_operand:<ssexmmmode> 1 "nonimmediate_operand" "vm")
16810             (parallel [(const_int 0) (const_int 1)]))))]
16811   "TARGET_AVX512DQ"
16812   "vbroadcast<shuffletype>32x2\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
16813   [(set_attr "type" "ssemov")
16814    (set_attr "prefix_extra" "1")
16815    (set_attr "prefix" "evex")
16816    (set_attr "mode" "<sseinsnmode>")])
16817
16818 (define_insn "<mask_codefor>avx512vl_broadcast<mode><mask_name>_1"
16819   [(set (match_operand:VI4F_256 0 "register_operand" "=v,v")
16820         (vec_duplicate:VI4F_256
16821          (match_operand:<ssexmmmode> 1 "nonimmediate_operand" "v,m")))]
16822   "TARGET_AVX512VL"
16823   "@
16824    vshuf<shuffletype>32x4\t{$0x0, %t1, %t1, %0<mask_operand2>|%0<mask_operand2>, %t1, %t1, 0x0}
16825    vbroadcast<shuffletype>32x4\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
16826   [(set_attr "type" "ssemov")
16827    (set_attr "prefix_extra" "1")
16828    (set_attr "prefix" "evex")
16829    (set_attr "mode" "<sseinsnmode>")])
16830
16831 (define_insn "<mask_codefor>avx512dq_broadcast<mode><mask_name>_1"
16832   [(set (match_operand:V16FI 0 "register_operand" "=v,v")
16833        (vec_duplicate:V16FI
16834          (match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "v,m")))]
16835   "TARGET_AVX512DQ"
16836   "@
16837    vshuf<shuffletype>32x4\t{$0x44, %g1, %g1, %0<mask_operand2>|%0<mask_operand2>, %g1, %g1, 0x44}
16838    vbroadcast<shuffletype>32x8\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
16839   [(set_attr "type" "ssemov")
16840    (set_attr "prefix_extra" "1")
16841    (set_attr "prefix" "evex")
16842    (set_attr "mode" "<sseinsnmode>")])
16843
16844 ;; For broadcast[i|f]64x2
16845 (define_mode_iterator VI8F_BRCST64x2
16846   [V8DI V8DF (V4DI "TARGET_AVX512VL") (V4DF "TARGET_AVX512VL")])
16847
16848 (define_insn "<mask_codefor>avx512dq_broadcast<mode><mask_name>_1"
16849   [(set (match_operand:VI8F_BRCST64x2 0 "register_operand" "=v,v")
16850        (vec_duplicate:VI8F_BRCST64x2
16851          (match_operand:<64x2mode> 1 "nonimmediate_operand" "v,m")))]
16852   "TARGET_AVX512DQ"
16853   "@
16854    vshuf<shuffletype>64x2\t{$0x0, %<concat_tg_mode>1, %<concat_tg_mode>1, %0<mask_operand2>|%0<mask_operand2>, %<concat_tg_mode>1, %<concat_tg_mode>1, 0x0}
16855    vbroadcast<shuffletype>64x2\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
16856   [(set_attr "type" "ssemov")
16857    (set_attr "prefix_extra" "1")
16858    (set_attr "prefix" "evex")
16859    (set_attr "mode" "<sseinsnmode>")])
16860
16861 (define_insn "avx512cd_maskb_vec_dup<mode>"
16862   [(set (match_operand:VI8_AVX512VL 0 "register_operand" "=v")
16863         (vec_duplicate:VI8_AVX512VL
16864           (zero_extend:DI
16865             (match_operand:QI 1 "register_operand" "Yk"))))]
16866   "TARGET_AVX512CD"
16867   "vpbroadcastmb2q\t{%1, %0|%0, %1}"
16868   [(set_attr "type" "mskmov")
16869    (set_attr "prefix" "evex")
16870    (set_attr "mode" "XI")])
16871
16872 (define_insn "avx512cd_maskw_vec_dup<mode>"
16873   [(set (match_operand:VI4_AVX512VL 0 "register_operand" "=v")
16874         (vec_duplicate:VI4_AVX512VL
16875           (zero_extend:SI
16876             (match_operand:HI 1 "register_operand" "Yk"))))]
16877   "TARGET_AVX512CD"
16878   "vpbroadcastmw2d\t{%1, %0|%0, %1}"
16879   [(set_attr "type" "mskmov")
16880    (set_attr "prefix" "evex")
16881    (set_attr "mode" "XI")])
16882
16883 ;; Recognize broadcast as a vec_select as produced by builtin_vec_perm.
16884 ;; If it so happens that the input is in memory, use vbroadcast.
16885 ;; Otherwise use vpermilp (and in the case of 256-bit modes, vperm2f128).
16886 (define_insn "*avx_vperm_broadcast_v4sf"
16887   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
16888         (vec_select:V4SF
16889           (match_operand:V4SF 1 "nonimmediate_operand" "m,o,x")
16890           (match_parallel 2 "avx_vbroadcast_operand"
16891             [(match_operand 3 "const_int_operand" "C,n,n")])))]
16892   "TARGET_AVX"
16893 {
16894   int elt = INTVAL (operands[3]);
16895   switch (which_alternative)
16896     {
16897     case 0:
16898     case 1:
16899       operands[1] = adjust_address_nv (operands[1], SFmode, elt * 4);
16900       return "vbroadcastss\t{%1, %0|%0, %k1}";
16901     case 2:
16902       operands[2] = GEN_INT (elt * 0x55);
16903       return "vpermilps\t{%2, %1, %0|%0, %1, %2}";
16904     default:
16905       gcc_unreachable ();
16906     }
16907 }
16908   [(set_attr "type" "ssemov,ssemov,sselog1")
16909    (set_attr "prefix_extra" "1")
16910    (set_attr "length_immediate" "0,0,1")
16911    (set_attr "prefix" "vex")
16912    (set_attr "mode" "SF,SF,V4SF")])
16913
16914 (define_insn_and_split "*avx_vperm_broadcast_<mode>"
16915   [(set (match_operand:VF_256 0 "register_operand" "=x,x,x")
16916         (vec_select:VF_256
16917           (match_operand:VF_256 1 "nonimmediate_operand" "m,o,?x")
16918           (match_parallel 2 "avx_vbroadcast_operand"
16919             [(match_operand 3 "const_int_operand" "C,n,n")])))]
16920   "TARGET_AVX"
16921   "#"
16922   "&& reload_completed && (<MODE>mode != V4DFmode || !TARGET_AVX2)"
16923   [(set (match_dup 0) (vec_duplicate:VF_256 (match_dup 1)))]
16924 {
16925   rtx op0 = operands[0], op1 = operands[1];
16926   int elt = INTVAL (operands[3]);
16927
16928   if (REG_P (op1))
16929     {
16930       int mask;
16931
16932       if (TARGET_AVX2 && elt == 0)
16933         {
16934           emit_insn (gen_vec_dup<mode> (op0, gen_lowpart (<ssescalarmode>mode,
16935                                                           op1)));
16936           DONE;
16937         }
16938
16939       /* Shuffle element we care about into all elements of the 128-bit lane.
16940          The other lane gets shuffled too, but we don't care.  */
16941       if (<MODE>mode == V4DFmode)
16942         mask = (elt & 1 ? 15 : 0);
16943       else
16944         mask = (elt & 3) * 0x55;
16945       emit_insn (gen_avx_vpermil<mode> (op0, op1, GEN_INT (mask)));
16946
16947       /* Shuffle the lane we care about into both lanes of the dest.  */
16948       mask = (elt / (<ssescalarnum> / 2)) * 0x11;
16949       emit_insn (gen_avx_vperm2f128<mode>3 (op0, op0, op0, GEN_INT (mask)));
16950       DONE;
16951     }
16952
16953   operands[1] = adjust_address (op1, <ssescalarmode>mode,
16954                                 elt * GET_MODE_SIZE (<ssescalarmode>mode));
16955 })
16956
16957 (define_expand "<sse2_avx_avx512f>_vpermil<mode><mask_name>"
16958   [(set (match_operand:VF2 0 "register_operand")
16959         (vec_select:VF2
16960           (match_operand:VF2 1 "nonimmediate_operand")
16961           (match_operand:SI 2 "const_0_to_255_operand")))]
16962   "TARGET_AVX && <mask_mode512bit_condition>"
16963 {
16964   int mask = INTVAL (operands[2]);
16965   rtx perm[<ssescalarnum>];
16966
16967   int i;
16968   for (i = 0; i < <ssescalarnum>; i = i + 2)
16969     {
16970       perm[i]     = GEN_INT (((mask >> i)       & 1) + i);
16971       perm[i + 1] = GEN_INT (((mask >> (i + 1)) & 1) + i);
16972     }
16973
16974   operands[2]
16975     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
16976 })
16977
16978 (define_expand "<sse2_avx_avx512f>_vpermil<mode><mask_name>"
16979   [(set (match_operand:VF1 0 "register_operand")
16980         (vec_select:VF1
16981           (match_operand:VF1 1 "nonimmediate_operand")
16982           (match_operand:SI 2 "const_0_to_255_operand")))]
16983   "TARGET_AVX && <mask_mode512bit_condition>"
16984 {
16985   int mask = INTVAL (operands[2]);
16986   rtx perm[<ssescalarnum>];
16987
16988   int i;
16989   for (i = 0; i < <ssescalarnum>; i = i + 4)
16990     {
16991       perm[i]     = GEN_INT (((mask >> 0) & 3) + i);
16992       perm[i + 1] = GEN_INT (((mask >> 2) & 3) + i);
16993       perm[i + 2] = GEN_INT (((mask >> 4) & 3) + i);
16994       perm[i + 3] = GEN_INT (((mask >> 6) & 3) + i);
16995     }
16996
16997   operands[2]
16998     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
16999 })
17000
17001 (define_insn "*<sse2_avx_avx512f>_vpermilp<mode><mask_name>"
17002   [(set (match_operand:VF 0 "register_operand" "=v")
17003         (vec_select:VF
17004           (match_operand:VF 1 "nonimmediate_operand" "vm")
17005           (match_parallel 2 ""
17006             [(match_operand 3 "const_int_operand")])))]
17007   "TARGET_AVX && <mask_mode512bit_condition>
17008    && avx_vpermilp_parallel (operands[2], <MODE>mode)"
17009 {
17010   int mask = avx_vpermilp_parallel (operands[2], <MODE>mode) - 1;
17011   operands[2] = GEN_INT (mask);
17012   return "vpermil<ssemodesuffix>\t{%2, %1, %0<mask_operand4>|%0<mask_operand4>, %1, %2}";
17013 }
17014   [(set_attr "type" "sselog")
17015    (set_attr "prefix_extra" "1")
17016    (set_attr "length_immediate" "1")
17017    (set_attr "prefix" "<mask_prefix>")
17018    (set_attr "mode" "<sseinsnmode>")])
17019
17020 (define_insn "<sse2_avx_avx512f>_vpermilvar<mode>3<mask_name>"
17021   [(set (match_operand:VF 0 "register_operand" "=v")
17022         (unspec:VF
17023           [(match_operand:VF 1 "register_operand" "v")
17024            (match_operand:<sseintvecmode> 2 "nonimmediate_operand" "vm")]
17025           UNSPEC_VPERMIL))]
17026   "TARGET_AVX && <mask_mode512bit_condition>"
17027   "vpermil<ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
17028   [(set_attr "type" "sselog")
17029    (set_attr "prefix_extra" "1")
17030    (set_attr "btver2_decode" "vector")
17031    (set_attr "prefix" "<mask_prefix>")
17032    (set_attr "mode" "<sseinsnmode>")])
17033
17034 (define_expand "<avx512>_vpermi2var<mode>3_maskz"
17035   [(match_operand:VI48F 0 "register_operand" "=v")
17036    (match_operand:VI48F 1 "register_operand" "v")
17037    (match_operand:<sseintvecmode> 2 "register_operand" "0")
17038    (match_operand:VI48F 3 "nonimmediate_operand" "vm")
17039    (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")]
17040   "TARGET_AVX512F"
17041 {
17042   emit_insn (gen_<avx512>_vpermi2var<mode>3_maskz_1 (
17043         operands[0], operands[1], operands[2], operands[3],
17044         CONST0_RTX (<MODE>mode), operands[4]));
17045   DONE;
17046 })
17047
17048 (define_expand "<avx512>_vpermi2var<mode>3_maskz"
17049   [(match_operand:VI1_AVX512VL 0 "register_operand")
17050    (match_operand:VI1_AVX512VL 1 "register_operand")
17051    (match_operand:<sseintvecmode> 2 "register_operand")
17052    (match_operand:VI1_AVX512VL 3 "nonimmediate_operand")
17053    (match_operand:<avx512fmaskmode> 4 "register_operand")]
17054   "TARGET_AVX512VBMI"
17055 {
17056   emit_insn (gen_<avx512>_vpermi2var<mode>3_maskz_1 (
17057         operands[0], operands[1], operands[2], operands[3],
17058         CONST0_RTX (<MODE>mode), operands[4]));
17059   DONE;
17060 })
17061
17062 (define_expand "<avx512>_vpermi2var<mode>3_maskz"
17063   [(match_operand:VI2_AVX512VL 0 "register_operand" "=v")
17064    (match_operand:VI2_AVX512VL 1 "register_operand" "v")
17065    (match_operand:<sseintvecmode> 2 "register_operand" "0")
17066    (match_operand:VI2_AVX512VL 3 "nonimmediate_operand" "vm")
17067    (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")]
17068   "TARGET_AVX512BW"
17069 {
17070   emit_insn (gen_<avx512>_vpermi2var<mode>3_maskz_1 (
17071         operands[0], operands[1], operands[2], operands[3],
17072         CONST0_RTX (<MODE>mode), operands[4]));
17073   DONE;
17074 })
17075
17076 (define_insn "<avx512>_vpermi2var<mode>3<sd_maskz_name>"
17077   [(set (match_operand:VI48F 0 "register_operand" "=v")
17078         (unspec:VI48F
17079           [(match_operand:VI48F 1 "register_operand" "v")
17080            (match_operand:<sseintvecmode> 2 "register_operand" "0")
17081            (match_operand:VI48F 3 "nonimmediate_operand" "vm")]
17082           UNSPEC_VPERMI2))]
17083   "TARGET_AVX512F"
17084   "vpermi2<ssemodesuffix>\t{%3, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %3}"
17085   [(set_attr "type" "sselog")
17086    (set_attr "prefix" "evex")
17087    (set_attr "mode" "<sseinsnmode>")])
17088
17089 (define_insn "<avx512>_vpermi2var<mode>3<sd_maskz_name>"
17090   [(set (match_operand:VI1_AVX512VL 0 "register_operand" "=v")
17091         (unspec:VI1_AVX512VL
17092           [(match_operand:VI1_AVX512VL 1 "register_operand" "v")
17093            (match_operand:<sseintvecmode> 2 "register_operand" "0")
17094            (match_operand:VI1_AVX512VL 3 "nonimmediate_operand" "vm")]
17095           UNSPEC_VPERMI2))]
17096   "TARGET_AVX512VBMI"
17097   "vpermi2<ssemodesuffix>\t{%3, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %3}"
17098   [(set_attr "type" "sselog")
17099    (set_attr "prefix" "evex")
17100    (set_attr "mode" "<sseinsnmode>")])
17101
17102 (define_insn "<avx512>_vpermi2var<mode>3<sd_maskz_name>"
17103   [(set (match_operand:VI2_AVX512VL 0 "register_operand" "=v")
17104         (unspec:VI2_AVX512VL
17105           [(match_operand:VI2_AVX512VL 1 "register_operand" "v")
17106            (match_operand:<sseintvecmode> 2 "register_operand" "0")
17107            (match_operand:VI2_AVX512VL 3 "nonimmediate_operand" "vm")]
17108           UNSPEC_VPERMI2))]
17109   "TARGET_AVX512BW"
17110   "vpermi2<ssemodesuffix>\t{%3, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %3}"
17111   [(set_attr "type" "sselog")
17112    (set_attr "prefix" "evex")
17113    (set_attr "mode" "<sseinsnmode>")])
17114
17115 (define_insn "<avx512>_vpermi2var<mode>3_mask"
17116   [(set (match_operand:VI48F 0 "register_operand" "=v")
17117         (vec_merge:VI48F
17118           (unspec:VI48F
17119             [(match_operand:VI48F 1 "register_operand" "v")
17120             (match_operand:<sseintvecmode> 2 "register_operand" "0")
17121             (match_operand:VI48F 3 "nonimmediate_operand" "vm")]
17122             UNSPEC_VPERMI2_MASK)
17123           (match_dup 0)
17124           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
17125   "TARGET_AVX512F"
17126   "vpermi2<ssemodesuffix>\t{%3, %1, %0%{%4%}|%0%{%4%}, %1, %3}"
17127   [(set_attr "type" "sselog")
17128    (set_attr "prefix" "evex")
17129    (set_attr "mode" "<sseinsnmode>")])
17130
17131 (define_insn "<avx512>_vpermi2var<mode>3_mask"
17132   [(set (match_operand:VI1_AVX512VL 0 "register_operand" "=v")
17133         (vec_merge:VI1_AVX512VL
17134           (unspec:VI1_AVX512VL
17135             [(match_operand:VI1_AVX512VL 1 "register_operand" "v")
17136             (match_operand:<sseintvecmode> 2 "register_operand" "0")
17137             (match_operand:VI1_AVX512VL 3 "nonimmediate_operand" "vm")]
17138             UNSPEC_VPERMI2_MASK)
17139           (match_dup 0)
17140           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
17141   "TARGET_AVX512VBMI"
17142   "vpermi2<ssemodesuffix>\t{%3, %1, %0%{%4%}|%0%{%4%}, %1, %3}"
17143   [(set_attr "type" "sselog")
17144    (set_attr "prefix" "evex")
17145    (set_attr "mode" "<sseinsnmode>")])
17146
17147 (define_insn "<avx512>_vpermi2var<mode>3_mask"
17148   [(set (match_operand:VI2_AVX512VL 0 "register_operand" "=v")
17149         (vec_merge:VI2_AVX512VL
17150           (unspec:VI2_AVX512VL
17151             [(match_operand:VI2_AVX512VL 1 "register_operand" "v")
17152             (match_operand:<sseintvecmode> 2 "register_operand" "0")
17153             (match_operand:VI2_AVX512VL 3 "nonimmediate_operand" "vm")]
17154             UNSPEC_VPERMI2_MASK)
17155           (match_dup 0)
17156           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
17157   "TARGET_AVX512BW"
17158   "vpermi2<ssemodesuffix>\t{%3, %1, %0%{%4%}|%0%{%4%}, %1, %3}"
17159   [(set_attr "type" "sselog")
17160    (set_attr "prefix" "evex")
17161    (set_attr "mode" "<sseinsnmode>")])
17162
17163 (define_expand "<avx512>_vpermt2var<mode>3_maskz"
17164   [(match_operand:VI48F 0 "register_operand" "=v")
17165    (match_operand:<sseintvecmode> 1 "register_operand" "v")
17166    (match_operand:VI48F 2 "register_operand" "0")
17167    (match_operand:VI48F 3 "nonimmediate_operand" "vm")
17168    (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")]
17169   "TARGET_AVX512F"
17170 {
17171   emit_insn (gen_<avx512>_vpermt2var<mode>3_maskz_1 (
17172         operands[0], operands[1], operands[2], operands[3],
17173         CONST0_RTX (<MODE>mode), operands[4]));
17174   DONE;
17175 })
17176
17177 (define_expand "<avx512>_vpermt2var<mode>3_maskz"
17178   [(match_operand:VI1_AVX512VL 0 "register_operand" "=v")
17179    (match_operand:<sseintvecmode> 1 "register_operand" "v")
17180    (match_operand:VI1_AVX512VL 2 "register_operand" "0")
17181    (match_operand:VI1_AVX512VL 3 "nonimmediate_operand" "vm")
17182    (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")]
17183   "TARGET_AVX512VBMI"
17184 {
17185   emit_insn (gen_<avx512>_vpermt2var<mode>3_maskz_1 (
17186         operands[0], operands[1], operands[2], operands[3],
17187         CONST0_RTX (<MODE>mode), operands[4]));
17188   DONE;
17189 })
17190
17191 (define_expand "<avx512>_vpermt2var<mode>3_maskz"
17192   [(match_operand:VI2_AVX512VL 0 "register_operand" "=v")
17193    (match_operand:<sseintvecmode> 1 "register_operand" "v")
17194    (match_operand:VI2_AVX512VL 2 "register_operand" "0")
17195    (match_operand:VI2_AVX512VL 3 "nonimmediate_operand" "vm")
17196    (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")]
17197   "TARGET_AVX512BW"
17198 {
17199   emit_insn (gen_<avx512>_vpermt2var<mode>3_maskz_1 (
17200         operands[0], operands[1], operands[2], operands[3],
17201         CONST0_RTX (<MODE>mode), operands[4]));
17202   DONE;
17203 })
17204
17205 (define_insn "<avx512>_vpermt2var<mode>3<sd_maskz_name>"
17206   [(set (match_operand:VI48F 0 "register_operand" "=v")
17207         (unspec:VI48F
17208           [(match_operand:<sseintvecmode> 1 "register_operand" "v")
17209            (match_operand:VI48F 2 "register_operand" "0")
17210            (match_operand:VI48F 3 "nonimmediate_operand" "vm")]
17211           UNSPEC_VPERMT2))]
17212   "TARGET_AVX512F"
17213   "vpermt2<ssemodesuffix>\t{%3, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %3}"
17214   [(set_attr "type" "sselog")
17215    (set_attr "prefix" "evex")
17216    (set_attr "mode" "<sseinsnmode>")])
17217
17218 (define_insn "<avx512>_vpermt2var<mode>3<sd_maskz_name>"
17219   [(set (match_operand:VI1_AVX512VL 0 "register_operand" "=v")
17220         (unspec:VI1_AVX512VL
17221           [(match_operand:<sseintvecmode> 1 "register_operand" "v")
17222            (match_operand:VI1_AVX512VL 2 "register_operand" "0")
17223            (match_operand:VI1_AVX512VL 3 "nonimmediate_operand" "vm")]
17224           UNSPEC_VPERMT2))]
17225   "TARGET_AVX512VBMI"
17226   "vpermt2<ssemodesuffix>\t{%3, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %3}"
17227   [(set_attr "type" "sselog")
17228    (set_attr "prefix" "evex")
17229    (set_attr "mode" "<sseinsnmode>")])
17230
17231 (define_insn "<avx512>_vpermt2var<mode>3<sd_maskz_name>"
17232   [(set (match_operand:VI2_AVX512VL 0 "register_operand" "=v")
17233         (unspec:VI2_AVX512VL
17234           [(match_operand:<sseintvecmode> 1 "register_operand" "v")
17235            (match_operand:VI2_AVX512VL 2 "register_operand" "0")
17236            (match_operand:VI2_AVX512VL 3 "nonimmediate_operand" "vm")]
17237           UNSPEC_VPERMT2))]
17238   "TARGET_AVX512BW"
17239   "vpermt2<ssemodesuffix>\t{%3, %1, %0<sd_mask_op4>|%0<sd_mask_op4>, %1, %3}"
17240   [(set_attr "type" "sselog")
17241    (set_attr "prefix" "evex")
17242    (set_attr "mode" "<sseinsnmode>")])
17243
17244 (define_insn "<avx512>_vpermt2var<mode>3_mask"
17245   [(set (match_operand:VI48F 0 "register_operand" "=v")
17246         (vec_merge:VI48F
17247           (unspec:VI48F
17248             [(match_operand:<sseintvecmode> 1 "register_operand" "v")
17249             (match_operand:VI48F 2 "register_operand" "0")
17250             (match_operand:VI48F 3 "nonimmediate_operand" "vm")]
17251             UNSPEC_VPERMT2)
17252           (match_dup 2)
17253           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
17254   "TARGET_AVX512F"
17255   "vpermt2<ssemodesuffix>\t{%3, %1, %0%{%4%}|%0%{%4%}, %1, %3}"
17256   [(set_attr "type" "sselog")
17257    (set_attr "prefix" "evex")
17258    (set_attr "mode" "<sseinsnmode>")])
17259
17260 (define_insn "<avx512>_vpermt2var<mode>3_mask"
17261   [(set (match_operand:VI1_AVX512VL 0 "register_operand" "=v")
17262         (vec_merge:VI1_AVX512VL
17263           (unspec:VI1_AVX512VL
17264             [(match_operand:<sseintvecmode> 1 "register_operand" "v")
17265             (match_operand:VI1_AVX512VL 2 "register_operand" "0")
17266             (match_operand:VI1_AVX512VL 3 "nonimmediate_operand" "vm")]
17267             UNSPEC_VPERMT2)
17268           (match_dup 2)
17269           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
17270   "TARGET_AVX512VBMI"
17271   "vpermt2<ssemodesuffix>\t{%3, %1, %0%{%4%}|%0%{%4%}, %1, %3}"
17272   [(set_attr "type" "sselog")
17273    (set_attr "prefix" "evex")
17274    (set_attr "mode" "<sseinsnmode>")])
17275
17276 (define_insn "<avx512>_vpermt2var<mode>3_mask"
17277   [(set (match_operand:VI2_AVX512VL 0 "register_operand" "=v")
17278         (vec_merge:VI2_AVX512VL
17279           (unspec:VI2_AVX512VL
17280             [(match_operand:<sseintvecmode> 1 "register_operand" "v")
17281             (match_operand:VI2_AVX512VL 2 "register_operand" "0")
17282             (match_operand:VI2_AVX512VL 3 "nonimmediate_operand" "vm")]
17283             UNSPEC_VPERMT2)
17284           (match_dup 2)
17285           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
17286   "TARGET_AVX512BW"
17287   "vpermt2<ssemodesuffix>\t{%3, %1, %0%{%4%}|%0%{%4%}, %1, %3}"
17288   [(set_attr "type" "sselog")
17289    (set_attr "prefix" "evex")
17290    (set_attr "mode" "<sseinsnmode>")])
17291
17292 (define_expand "avx_vperm2f128<mode>3"
17293   [(set (match_operand:AVX256MODE2P 0 "register_operand")
17294         (unspec:AVX256MODE2P
17295           [(match_operand:AVX256MODE2P 1 "register_operand")
17296            (match_operand:AVX256MODE2P 2 "nonimmediate_operand")
17297            (match_operand:SI 3 "const_0_to_255_operand")]
17298           UNSPEC_VPERMIL2F128))]
17299   "TARGET_AVX"
17300 {
17301   int mask = INTVAL (operands[3]);
17302   if ((mask & 0x88) == 0)
17303     {
17304       rtx perm[<ssescalarnum>], t1, t2;
17305       int i, base, nelt = <ssescalarnum>, nelt2 = nelt / 2;
17306
17307       base = (mask & 3) * nelt2;
17308       for (i = 0; i < nelt2; ++i)
17309         perm[i] = GEN_INT (base + i);
17310
17311       base = ((mask >> 4) & 3) * nelt2;
17312       for (i = 0; i < nelt2; ++i)
17313         perm[i + nelt2] = GEN_INT (base + i);
17314
17315       t2 = gen_rtx_VEC_CONCAT (<ssedoublevecmode>mode,
17316                                operands[1], operands[2]);
17317       t1 = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelt, perm));
17318       t2 = gen_rtx_VEC_SELECT (<MODE>mode, t2, t1);
17319       t2 = gen_rtx_SET (VOIDmode, operands[0], t2);
17320       emit_insn (t2);
17321       DONE;
17322     }
17323 })
17324
17325 ;; Note that bits 7 and 3 of the imm8 allow lanes to be zeroed, which
17326 ;; means that in order to represent this properly in rtl we'd have to
17327 ;; nest *another* vec_concat with a zero operand and do the select from
17328 ;; a 4x wide vector.  That doesn't seem very nice.
17329 (define_insn "*avx_vperm2f128<mode>_full"
17330   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
17331         (unspec:AVX256MODE2P
17332           [(match_operand:AVX256MODE2P 1 "register_operand" "x")
17333            (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm")
17334            (match_operand:SI 3 "const_0_to_255_operand" "n")]
17335           UNSPEC_VPERMIL2F128))]
17336   "TARGET_AVX"
17337   "vperm2<i128>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
17338   [(set_attr "type" "sselog")
17339    (set_attr "prefix_extra" "1")
17340    (set_attr "length_immediate" "1")
17341    (set_attr "prefix" "vex")
17342    (set_attr "mode" "<sseinsnmode>")])
17343
17344 (define_insn "*avx_vperm2f128<mode>_nozero"
17345   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
17346         (vec_select:AVX256MODE2P
17347           (vec_concat:<ssedoublevecmode>
17348             (match_operand:AVX256MODE2P 1 "register_operand" "x")
17349             (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm"))
17350           (match_parallel 3 ""
17351             [(match_operand 4 "const_int_operand")])))]
17352   "TARGET_AVX
17353    && avx_vperm2f128_parallel (operands[3], <MODE>mode)"
17354 {
17355   int mask = avx_vperm2f128_parallel (operands[3], <MODE>mode) - 1;
17356   if (mask == 0x12)
17357     return "vinsert<i128>\t{$0, %x2, %1, %0|%0, %1, %x2, 0}";
17358   if (mask == 0x20)
17359     return "vinsert<i128>\t{$1, %x2, %1, %0|%0, %1, %x2, 1}";
17360   operands[3] = GEN_INT (mask);
17361   return "vperm2<i128>\t{%3, %2, %1, %0|%0, %1, %2, %3}";
17362 }
17363   [(set_attr "type" "sselog")
17364    (set_attr "prefix_extra" "1")
17365    (set_attr "length_immediate" "1")
17366    (set_attr "prefix" "vex")
17367    (set_attr "mode" "<sseinsnmode>")])
17368
17369 (define_insn "*ssse3_palignr<mode>_perm"
17370   [(set (match_operand:V_128 0 "register_operand" "=x,x")
17371       (vec_select:V_128
17372         (match_operand:V_128 1 "register_operand" "0,x")
17373         (match_parallel 2 "palignr_operand"
17374           [(match_operand 3 "const_int_operand" "n, n")])))]
17375   "TARGET_SSSE3"
17376 {
17377   machine_mode imode = GET_MODE_INNER (GET_MODE (operands[0]));
17378   operands[2] = GEN_INT (INTVAL (operands[3]) * GET_MODE_SIZE (imode));
17379
17380   switch (which_alternative)
17381     {
17382     case 0:
17383       return "palignr\t{%2, %1, %0|%0, %1, %2}";
17384     case 1:
17385       return "vpalignr\t{%2, %1, %1, %0|%0, %1, %1, %2}";
17386     default:
17387       gcc_unreachable ();
17388     }
17389 }
17390   [(set_attr "isa" "noavx,avx")
17391    (set_attr "type" "sseishft")
17392    (set_attr "atom_unit" "sishuf")
17393    (set_attr "prefix_data16" "1,*")
17394    (set_attr "prefix_extra" "1")
17395    (set_attr "length_immediate" "1")
17396    (set_attr "prefix" "orig,vex")])
17397
17398 (define_expand "avx512vl_vinsert<mode>"
17399   [(match_operand:VI48F_256 0 "register_operand")
17400    (match_operand:VI48F_256 1 "register_operand")
17401    (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand")
17402    (match_operand:SI 3 "const_0_to_1_operand")
17403    (match_operand:VI48F_256 4 "register_operand")
17404    (match_operand:<avx512fmaskmode> 5 "register_operand")]
17405   "TARGET_AVX512VL"
17406 {
17407   rtx (*insn)(rtx, rtx, rtx, rtx, rtx);
17408
17409   switch (INTVAL (operands[3]))
17410     {
17411     case 0:
17412       insn = gen_vec_set_lo_<mode>_mask;
17413       break;
17414     case 1:
17415       insn = gen_vec_set_hi_<mode>_mask;
17416       break;
17417     default:
17418       gcc_unreachable ();
17419     }
17420
17421   emit_insn (insn (operands[0], operands[1], operands[2], operands[4],
17422                    operands[5]));
17423   DONE;
17424 })
17425
17426 (define_expand "avx_vinsertf128<mode>"
17427   [(match_operand:V_256 0 "register_operand")
17428    (match_operand:V_256 1 "register_operand")
17429    (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand")
17430    (match_operand:SI 3 "const_0_to_1_operand")]
17431   "TARGET_AVX"
17432 {
17433   rtx (*insn)(rtx, rtx, rtx);
17434
17435   switch (INTVAL (operands[3]))
17436     {
17437     case 0:
17438       insn = gen_vec_set_lo_<mode>;
17439       break;
17440     case 1:
17441       insn = gen_vec_set_hi_<mode>;
17442       break;
17443     default:
17444       gcc_unreachable ();
17445     }
17446
17447   emit_insn (insn (operands[0], operands[1], operands[2]));
17448   DONE;
17449 })
17450
17451 (define_insn "vec_set_lo_<mode><mask_name>"
17452   [(set (match_operand:VI8F_256 0 "register_operand" "=v")
17453         (vec_concat:VI8F_256
17454           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "vm")
17455           (vec_select:<ssehalfvecmode>
17456             (match_operand:VI8F_256 1 "register_operand" "v")
17457             (parallel [(const_int 2) (const_int 3)]))))]
17458   "TARGET_AVX"
17459 {
17460   if (TARGET_AVX512VL)
17461     return "vinsert<shuffletype>64x2\t{$0x0, %2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2, 0x0}";
17462   else
17463     return "vinsert<i128>\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}";
17464 }
17465   [(set_attr "type" "sselog")
17466    (set_attr "prefix_extra" "1")
17467    (set_attr "length_immediate" "1")
17468    (set_attr "prefix" "vex")
17469    (set_attr "mode" "<sseinsnmode>")])
17470
17471 (define_insn "vec_set_hi_<mode><mask_name>"
17472   [(set (match_operand:VI8F_256 0 "register_operand" "=v")
17473         (vec_concat:VI8F_256
17474           (vec_select:<ssehalfvecmode>
17475             (match_operand:VI8F_256 1 "register_operand" "v")
17476             (parallel [(const_int 0) (const_int 1)]))
17477           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "vm")))]
17478   "TARGET_AVX"
17479 {
17480   if (TARGET_AVX512VL)
17481     return "vinsert<shuffletype>64x2\t{$0x1, %2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2, 0x1}";
17482   else
17483     return "vinsert<i128>\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}";
17484 }
17485   [(set_attr "type" "sselog")
17486    (set_attr "prefix_extra" "1")
17487    (set_attr "length_immediate" "1")
17488    (set_attr "prefix" "vex")
17489    (set_attr "mode" "<sseinsnmode>")])
17490
17491 (define_insn "vec_set_lo_<mode><mask_name>"
17492   [(set (match_operand:VI4F_256 0 "register_operand" "=v")
17493         (vec_concat:VI4F_256
17494           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "vm")
17495           (vec_select:<ssehalfvecmode>
17496             (match_operand:VI4F_256 1 "register_operand" "v")
17497             (parallel [(const_int 4) (const_int 5)
17498                        (const_int 6) (const_int 7)]))))]
17499   "TARGET_AVX"
17500 {
17501   if (TARGET_AVX512VL)
17502     return "vinsert<shuffletype>32x4\t{$0x0, %2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2, 0x0}";
17503   else
17504     return "vinsert<i128>\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}";
17505 }
17506   [(set_attr "type" "sselog")
17507    (set_attr "prefix_extra" "1")
17508    (set_attr "length_immediate" "1")
17509    (set_attr "prefix" "vex")
17510    (set_attr "mode" "<sseinsnmode>")])
17511
17512 (define_insn "vec_set_hi_<mode><mask_name>"
17513   [(set (match_operand:VI4F_256 0 "register_operand" "=v")
17514         (vec_concat:VI4F_256
17515           (vec_select:<ssehalfvecmode>
17516             (match_operand:VI4F_256 1 "register_operand" "v")
17517             (parallel [(const_int 0) (const_int 1)
17518                        (const_int 2) (const_int 3)]))
17519           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "vm")))]
17520   "TARGET_AVX"
17521 {
17522   if (TARGET_AVX512VL)
17523     return "vinsert<shuffletype>32x4\t{$0x1, %2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2, 0x1}";
17524   else
17525     return "vinsert<i128>\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}";
17526 }
17527   [(set_attr "type" "sselog")
17528    (set_attr "prefix_extra" "1")
17529    (set_attr "length_immediate" "1")
17530    (set_attr "prefix" "vex")
17531    (set_attr "mode" "<sseinsnmode>")])
17532
17533 (define_insn "vec_set_lo_v16hi"
17534   [(set (match_operand:V16HI 0 "register_operand" "=x")
17535         (vec_concat:V16HI
17536           (match_operand:V8HI 2 "nonimmediate_operand" "xm")
17537           (vec_select:V8HI
17538             (match_operand:V16HI 1 "register_operand" "x")
17539             (parallel [(const_int 8) (const_int 9)
17540                        (const_int 10) (const_int 11)
17541                        (const_int 12) (const_int 13)
17542                        (const_int 14) (const_int 15)]))))]
17543   "TARGET_AVX"
17544   "vinsert%~128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
17545   [(set_attr "type" "sselog")
17546    (set_attr "prefix_extra" "1")
17547    (set_attr "length_immediate" "1")
17548    (set_attr "prefix" "vex")
17549    (set_attr "mode" "OI")])
17550
17551 (define_insn "vec_set_hi_v16hi"
17552   [(set (match_operand:V16HI 0 "register_operand" "=x")
17553         (vec_concat:V16HI
17554           (vec_select:V8HI
17555             (match_operand:V16HI 1 "register_operand" "x")
17556             (parallel [(const_int 0) (const_int 1)
17557                        (const_int 2) (const_int 3)
17558                        (const_int 4) (const_int 5)
17559                        (const_int 6) (const_int 7)]))
17560           (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
17561   "TARGET_AVX"
17562   "vinsert%~128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
17563   [(set_attr "type" "sselog")
17564    (set_attr "prefix_extra" "1")
17565    (set_attr "length_immediate" "1")
17566    (set_attr "prefix" "vex")
17567    (set_attr "mode" "OI")])
17568
17569 (define_insn "vec_set_lo_v32qi"
17570   [(set (match_operand:V32QI 0 "register_operand" "=x")
17571         (vec_concat:V32QI
17572           (match_operand:V16QI 2 "nonimmediate_operand" "xm")
17573           (vec_select:V16QI
17574             (match_operand:V32QI 1 "register_operand" "x")
17575             (parallel [(const_int 16) (const_int 17)
17576                        (const_int 18) (const_int 19)
17577                        (const_int 20) (const_int 21)
17578                        (const_int 22) (const_int 23)
17579                        (const_int 24) (const_int 25)
17580                        (const_int 26) (const_int 27)
17581                        (const_int 28) (const_int 29)
17582                        (const_int 30) (const_int 31)]))))]
17583   "TARGET_AVX"
17584   "vinsert%~128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
17585   [(set_attr "type" "sselog")
17586    (set_attr "prefix_extra" "1")
17587    (set_attr "length_immediate" "1")
17588    (set_attr "prefix" "vex")
17589    (set_attr "mode" "OI")])
17590
17591 (define_insn "vec_set_hi_v32qi"
17592   [(set (match_operand:V32QI 0 "register_operand" "=x")
17593         (vec_concat:V32QI
17594           (vec_select:V16QI
17595             (match_operand:V32QI 1 "register_operand" "x")
17596             (parallel [(const_int 0) (const_int 1)
17597                        (const_int 2) (const_int 3)
17598                        (const_int 4) (const_int 5)
17599                        (const_int 6) (const_int 7)
17600                        (const_int 8) (const_int 9)
17601                        (const_int 10) (const_int 11)
17602                        (const_int 12) (const_int 13)
17603                        (const_int 14) (const_int 15)]))
17604           (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
17605   "TARGET_AVX"
17606   "vinsert%~128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
17607   [(set_attr "type" "sselog")
17608    (set_attr "prefix_extra" "1")
17609    (set_attr "length_immediate" "1")
17610    (set_attr "prefix" "vex")
17611    (set_attr "mode" "OI")])
17612
17613 (define_insn "<avx_avx2>_maskload<ssemodesuffix><avxsizesuffix>"
17614   [(set (match_operand:V48_AVX2 0 "register_operand" "=x")
17615         (unspec:V48_AVX2
17616           [(match_operand:<sseintvecmode> 2 "register_operand" "x")
17617            (match_operand:V48_AVX2 1 "memory_operand" "m")]
17618           UNSPEC_MASKMOV))]
17619   "TARGET_AVX"
17620   "v<sseintprefix>maskmov<ssemodesuffix>\t{%1, %2, %0|%0, %2, %1}"
17621   [(set_attr "type" "sselog1")
17622    (set_attr "prefix_extra" "1")
17623    (set_attr "prefix" "vex")
17624    (set_attr "btver2_decode" "vector")
17625    (set_attr "mode" "<sseinsnmode>")])
17626
17627 (define_insn "<avx_avx2>_maskstore<ssemodesuffix><avxsizesuffix>"
17628   [(set (match_operand:V48_AVX2 0 "memory_operand" "+m")
17629         (unspec:V48_AVX2
17630           [(match_operand:<sseintvecmode> 1 "register_operand" "x")
17631            (match_operand:V48_AVX2 2 "register_operand" "x")
17632            (match_dup 0)]
17633           UNSPEC_MASKMOV))]
17634   "TARGET_AVX"
17635   "v<sseintprefix>maskmov<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
17636   [(set_attr "type" "sselog1")
17637    (set_attr "prefix_extra" "1")
17638    (set_attr "prefix" "vex")
17639    (set_attr "btver2_decode" "vector") 
17640    (set_attr "mode" "<sseinsnmode>")])
17641
17642 (define_expand "maskload<mode>"
17643   [(set (match_operand:V48_AVX2 0 "register_operand")
17644         (unspec:V48_AVX2
17645           [(match_operand:<sseintvecmode> 2 "register_operand")
17646            (match_operand:V48_AVX2 1 "memory_operand")]
17647           UNSPEC_MASKMOV))]
17648   "TARGET_AVX")
17649
17650 (define_expand "maskstore<mode>"
17651   [(set (match_operand:V48_AVX2 0 "memory_operand")
17652         (unspec:V48_AVX2
17653           [(match_operand:<sseintvecmode> 2 "register_operand")
17654            (match_operand:V48_AVX2 1 "register_operand")
17655            (match_dup 0)]
17656           UNSPEC_MASKMOV))]
17657   "TARGET_AVX")
17658
17659 (define_insn_and_split "avx_<castmode><avxsizesuffix>_<castmode>"
17660   [(set (match_operand:AVX256MODE2P 0 "nonimmediate_operand" "=x,m")
17661         (unspec:AVX256MODE2P
17662           [(match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "xm,x")]
17663           UNSPEC_CAST))]
17664   "TARGET_AVX"
17665   "#"
17666   "&& reload_completed"
17667   [(const_int 0)]
17668 {
17669   rtx op0 = operands[0];
17670   rtx op1 = operands[1];
17671   if (REG_P (op0))
17672     op0 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op0));
17673   else
17674     op1 = gen_rtx_REG (<MODE>mode, REGNO (op1));
17675   emit_move_insn (op0, op1);
17676   DONE;
17677 })
17678
17679 (define_expand "vec_init<mode>"
17680   [(match_operand:V_256 0 "register_operand")
17681    (match_operand 1)]
17682   "TARGET_AVX"
17683 {
17684   ix86_expand_vector_init (false, operands[0], operands[1]);
17685   DONE;
17686 })
17687
17688 (define_expand "vec_init<mode>"
17689   [(match_operand:VF48_I1248 0 "register_operand")
17690    (match_operand 1)]
17691   "TARGET_AVX512F"
17692 {
17693   ix86_expand_vector_init (false, operands[0], operands[1]);
17694   DONE;
17695 })
17696
17697 (define_insn "<avx2_avx512>_ashrv<mode><mask_name>"
17698   [(set (match_operand:VI48_AVX512F_AVX512VL 0 "register_operand" "=v")
17699         (ashiftrt:VI48_AVX512F_AVX512VL
17700           (match_operand:VI48_AVX512F_AVX512VL 1 "register_operand" "v")
17701           (match_operand:VI48_AVX512F_AVX512VL 2 "nonimmediate_operand" "vm")))]
17702   "TARGET_AVX2 && <mask_mode512bit_condition>"
17703   "vpsrav<ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
17704   [(set_attr "type" "sseishft")
17705    (set_attr "prefix" "maybe_evex")
17706    (set_attr "mode" "<sseinsnmode>")])
17707
17708 (define_insn "<avx2_avx512>_ashrv<mode><mask_name>"
17709   [(set (match_operand:VI2_AVX512VL 0 "register_operand" "=v")
17710         (ashiftrt:VI2_AVX512VL
17711           (match_operand:VI2_AVX512VL 1 "register_operand" "v")
17712           (match_operand:VI2_AVX512VL 2 "nonimmediate_operand" "vm")))]
17713   "TARGET_AVX512BW"
17714   "vpsravw\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
17715   [(set_attr "type" "sseishft")
17716    (set_attr "prefix" "maybe_evex")
17717    (set_attr "mode" "<sseinsnmode>")])
17718
17719 (define_insn "<avx2_avx512>_<shift_insn>v<mode><mask_name>"
17720   [(set (match_operand:VI48_AVX512F 0 "register_operand" "=v")
17721         (any_lshift:VI48_AVX512F
17722           (match_operand:VI48_AVX512F 1 "register_operand" "v")
17723           (match_operand:VI48_AVX512F 2 "nonimmediate_operand" "vm")))]
17724   "TARGET_AVX2 && <mask_mode512bit_condition>"
17725   "vp<vshift>v<ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
17726   [(set_attr "type" "sseishft")
17727    (set_attr "prefix" "maybe_evex")
17728    (set_attr "mode" "<sseinsnmode>")])
17729
17730 (define_insn "<avx2_avx512>_<shift_insn>v<mode><mask_name>"
17731   [(set (match_operand:VI2_AVX512VL 0 "register_operand" "=v")
17732         (any_lshift:VI2_AVX512VL
17733           (match_operand:VI2_AVX512VL 1 "register_operand" "v")
17734           (match_operand:VI2_AVX512VL 2 "nonimmediate_operand" "vm")))]
17735   "TARGET_AVX512BW"
17736   "vp<vshift>v<ssemodesuffix>\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
17737   [(set_attr "type" "sseishft")
17738    (set_attr "prefix" "maybe_evex")
17739    (set_attr "mode" "<sseinsnmode>")])
17740
17741 (define_insn "avx_vec_concat<mode>"
17742   [(set (match_operand:V_256_512 0 "register_operand" "=x,x")
17743         (vec_concat:V_256_512
17744           (match_operand:<ssehalfvecmode> 1 "register_operand" "x,x")
17745           (match_operand:<ssehalfvecmode> 2 "vector_move_operand" "xm,C")))]
17746   "TARGET_AVX"
17747 {
17748   switch (which_alternative)
17749     {
17750     case 0:
17751       return "vinsert<i128>\t{$0x1, %2, %<concat_tg_mode>1, %0|%0, %<concat_tg_mode>1, %2, 0x1}";
17752     case 1:
17753       switch (get_attr_mode (insn))
17754         {
17755         case MODE_V16SF:
17756           return "vmovaps\t{%1, %t0|%t0, %1}";
17757         case MODE_V8DF:
17758           return "vmovapd\t{%1, %t0|%t0, %1}";
17759         case MODE_V8SF:
17760           return "vmovaps\t{%1, %x0|%x0, %1}";
17761         case MODE_V4DF:
17762           return "vmovapd\t{%1, %x0|%x0, %1}";
17763         case MODE_XI:
17764           return "vmovdqa\t{%1, %t0|%t0, %1}";
17765         case MODE_OI:
17766           return "vmovdqa\t{%1, %x0|%x0, %1}";
17767         default:
17768           gcc_unreachable ();
17769         }
17770     default:
17771       gcc_unreachable ();
17772     }
17773 }
17774   [(set_attr "type" "sselog,ssemov")
17775    (set_attr "prefix_extra" "1,*")
17776    (set_attr "length_immediate" "1,*")
17777    (set_attr "prefix" "maybe_evex")
17778    (set_attr "mode" "<sseinsnmode>")])
17779
17780 (define_insn "vcvtph2ps<mask_name>"
17781   [(set (match_operand:V4SF 0 "register_operand" "=v")
17782         (vec_select:V4SF
17783           (unspec:V8SF [(match_operand:V8HI 1 "register_operand" "v")]
17784                        UNSPEC_VCVTPH2PS)
17785           (parallel [(const_int 0) (const_int 1)
17786                      (const_int 2) (const_int 3)])))]
17787   "TARGET_F16C || TARGET_AVX512VL"
17788   "vcvtph2ps\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
17789   [(set_attr "type" "ssecvt")
17790    (set_attr "prefix" "maybe_evex")
17791    (set_attr "mode" "V4SF")])
17792
17793 (define_insn "*vcvtph2ps_load<mask_name>"
17794   [(set (match_operand:V4SF 0 "register_operand" "=v")
17795         (unspec:V4SF [(match_operand:V4HI 1 "memory_operand" "m")]
17796                      UNSPEC_VCVTPH2PS))]
17797   "TARGET_F16C || TARGET_AVX512VL"
17798   "vcvtph2ps\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
17799   [(set_attr "type" "ssecvt")
17800    (set_attr "prefix" "vex")
17801    (set_attr "mode" "V8SF")])
17802
17803 (define_insn "vcvtph2ps256<mask_name>"
17804   [(set (match_operand:V8SF 0 "register_operand" "=v")
17805         (unspec:V8SF [(match_operand:V8HI 1 "nonimmediate_operand" "vm")]
17806                      UNSPEC_VCVTPH2PS))]
17807   "TARGET_F16C || TARGET_AVX512VL"
17808   "vcvtph2ps\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
17809   [(set_attr "type" "ssecvt")
17810    (set_attr "prefix" "vex")
17811    (set_attr "btver2_decode" "double")
17812    (set_attr "mode" "V8SF")])
17813
17814 (define_insn "<mask_codefor>avx512f_vcvtph2ps512<mask_name><round_saeonly_name>"
17815   [(set (match_operand:V16SF 0 "register_operand" "=v")
17816         (unspec:V16SF
17817           [(match_operand:V16HI 1 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")]
17818           UNSPEC_VCVTPH2PS))]
17819   "TARGET_AVX512F"
17820   "vcvtph2ps\t{<round_saeonly_mask_op2>%1, %0<mask_operand2>|%0<mask_operand2>, %1<round_saeonly_mask_op2>}"
17821   [(set_attr "type" "ssecvt")
17822    (set_attr "prefix" "evex")
17823    (set_attr "mode" "V16SF")])
17824
17825 (define_expand "vcvtps2ph_mask"
17826   [(set (match_operand:V8HI 0 "register_operand")
17827         (vec_merge:V8HI
17828           (vec_concat:V8HI
17829             (unspec:V4HI [(match_operand:V4SF 1 "register_operand")
17830                           (match_operand:SI 2 "const_0_to_255_operand")]
17831                           UNSPEC_VCVTPS2PH)
17832             (match_dup 5))
17833            (match_operand:V8HI 3 "vector_move_operand")
17834            (match_operand:QI 4 "register_operand")))]
17835   "TARGET_AVX512VL"
17836   "operands[5] = CONST0_RTX (V4HImode);")
17837
17838 (define_expand "vcvtps2ph"
17839   [(set (match_operand:V8HI 0 "register_operand")
17840         (vec_concat:V8HI
17841           (unspec:V4HI [(match_operand:V4SF 1 "register_operand")
17842                         (match_operand:SI 2 "const_0_to_255_operand")]
17843                        UNSPEC_VCVTPS2PH)
17844           (match_dup 3)))]
17845   "TARGET_F16C"
17846   "operands[3] = CONST0_RTX (V4HImode);")
17847
17848 (define_insn "*vcvtps2ph<mask_name>"
17849   [(set (match_operand:V8HI 0 "register_operand" "=v")
17850         (vec_concat:V8HI
17851           (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "v")
17852                         (match_operand:SI 2 "const_0_to_255_operand" "N")]
17853                        UNSPEC_VCVTPS2PH)
17854           (match_operand:V4HI 3 "const0_operand")))]
17855   "(TARGET_F16C || TARGET_AVX512VL) && <mask_avx512vl_condition>"
17856   "vcvtps2ph\t{%2, %1, %0<mask_operand4>|%0<mask_operand4>, %1, %2}"
17857   [(set_attr "type" "ssecvt")
17858    (set_attr "prefix" "maybe_evex")
17859    (set_attr "mode" "V4SF")])
17860
17861 (define_insn "*vcvtps2ph_store<mask_name>"
17862   [(set (match_operand:V4HI 0 "memory_operand" "=m")
17863         (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "x")
17864                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
17865                      UNSPEC_VCVTPS2PH))]
17866   "TARGET_F16C || TARGET_AVX512VL"
17867   "vcvtps2ph\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
17868   [(set_attr "type" "ssecvt")
17869    (set_attr "prefix" "maybe_evex")
17870    (set_attr "mode" "V4SF")])
17871
17872 (define_insn "vcvtps2ph256<mask_name>"
17873   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=xm")
17874         (unspec:V8HI [(match_operand:V8SF 1 "register_operand" "x")
17875                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
17876                      UNSPEC_VCVTPS2PH))]
17877   "TARGET_F16C || TARGET_AVX512VL"
17878   "vcvtps2ph\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
17879   [(set_attr "type" "ssecvt")
17880    (set_attr "prefix" "maybe_evex")
17881    (set_attr "btver2_decode" "vector")
17882    (set_attr "mode" "V8SF")])
17883
17884 (define_insn "<mask_codefor>avx512f_vcvtps2ph512<mask_name>"
17885   [(set (match_operand:V16HI 0 "nonimmediate_operand" "=vm")
17886         (unspec:V16HI
17887           [(match_operand:V16SF 1 "register_operand" "v")
17888            (match_operand:SI 2 "const_0_to_255_operand" "N")]
17889           UNSPEC_VCVTPS2PH))]
17890   "TARGET_AVX512F"
17891   "vcvtps2ph\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
17892   [(set_attr "type" "ssecvt")
17893    (set_attr "prefix" "evex")
17894    (set_attr "mode" "V16SF")])
17895
17896 ;; For gather* insn patterns
17897 (define_mode_iterator VEC_GATHER_MODE
17898                       [V2DI V2DF V4DI V4DF V4SI V4SF V8SI V8SF])
17899 (define_mode_attr VEC_GATHER_IDXSI
17900                       [(V2DI "V4SI") (V4DI "V4SI") (V8DI "V8SI")
17901                        (V2DF "V4SI") (V4DF "V4SI") (V8DF "V8SI")
17902                        (V4SI "V4SI") (V8SI "V8SI") (V16SI "V16SI")
17903                        (V4SF "V4SI") (V8SF "V8SI") (V16SF "V16SI")])
17904
17905 (define_mode_attr VEC_GATHER_IDXDI
17906                       [(V2DI "V2DI") (V4DI "V4DI") (V8DI "V8DI")
17907                        (V2DF "V2DI") (V4DF "V4DI") (V8DF "V8DI")
17908                        (V4SI "V2DI") (V8SI "V4DI") (V16SI "V8DI")
17909                        (V4SF "V2DI") (V8SF "V4DI") (V16SF "V8DI")])
17910
17911 (define_mode_attr VEC_GATHER_SRCDI
17912                       [(V2DI "V2DI") (V4DI "V4DI") (V8DI "V8DI")
17913                        (V2DF "V2DF") (V4DF "V4DF") (V8DF "V8DF")
17914                        (V4SI "V4SI") (V8SI "V4SI") (V16SI "V8SI")
17915                        (V4SF "V4SF") (V8SF "V4SF") (V16SF "V8SF")])
17916
17917 (define_expand "avx2_gathersi<mode>"
17918   [(parallel [(set (match_operand:VEC_GATHER_MODE 0 "register_operand")
17919                    (unspec:VEC_GATHER_MODE
17920                      [(match_operand:VEC_GATHER_MODE 1 "register_operand")
17921                       (mem:<ssescalarmode>
17922                         (match_par_dup 7
17923                           [(match_operand 2 "vsib_address_operand")
17924                            (match_operand:<VEC_GATHER_IDXSI>
17925                               3 "register_operand")
17926                            (match_operand:SI 5 "const1248_operand ")]))
17927                       (mem:BLK (scratch))
17928                       (match_operand:VEC_GATHER_MODE 4 "register_operand")]
17929                      UNSPEC_GATHER))
17930               (clobber (match_scratch:VEC_GATHER_MODE 6))])]
17931   "TARGET_AVX2"
17932 {
17933   operands[7]
17934     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[3],
17935                                         operands[5]), UNSPEC_VSIBADDR);
17936 })
17937
17938 (define_insn "*avx2_gathersi<mode>"
17939   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
17940         (unspec:VEC_GATHER_MODE
17941           [(match_operand:VEC_GATHER_MODE 2 "register_operand" "0")
17942            (match_operator:<ssescalarmode> 7 "vsib_mem_operator"
17943              [(unspec:P
17944                 [(match_operand:P 3 "vsib_address_operand" "Tv")
17945                  (match_operand:<VEC_GATHER_IDXSI> 4 "register_operand" "x")
17946                  (match_operand:SI 6 "const1248_operand" "n")]
17947                 UNSPEC_VSIBADDR)])
17948            (mem:BLK (scratch))
17949            (match_operand:VEC_GATHER_MODE 5 "register_operand" "1")]
17950           UNSPEC_GATHER))
17951    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
17952   "TARGET_AVX2"
17953   "v<sseintprefix>gatherd<ssemodesuffix>\t{%1, %7, %0|%0, %7, %1}"
17954   [(set_attr "type" "ssemov")
17955    (set_attr "prefix" "vex")
17956    (set_attr "mode" "<sseinsnmode>")])
17957
17958 (define_insn "*avx2_gathersi<mode>_2"
17959   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
17960         (unspec:VEC_GATHER_MODE
17961           [(pc)
17962            (match_operator:<ssescalarmode> 6 "vsib_mem_operator"
17963              [(unspec:P
17964                 [(match_operand:P 2 "vsib_address_operand" "Tv")
17965                  (match_operand:<VEC_GATHER_IDXSI> 3 "register_operand" "x")
17966                  (match_operand:SI 5 "const1248_operand" "n")]
17967                 UNSPEC_VSIBADDR)])
17968            (mem:BLK (scratch))
17969            (match_operand:VEC_GATHER_MODE 4 "register_operand" "1")]
17970           UNSPEC_GATHER))
17971    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
17972   "TARGET_AVX2"
17973   "v<sseintprefix>gatherd<ssemodesuffix>\t{%1, %6, %0|%0, %6, %1}"
17974   [(set_attr "type" "ssemov")
17975    (set_attr "prefix" "vex")
17976    (set_attr "mode" "<sseinsnmode>")])
17977
17978 (define_expand "avx2_gatherdi<mode>"
17979   [(parallel [(set (match_operand:VEC_GATHER_MODE 0 "register_operand")
17980                    (unspec:VEC_GATHER_MODE
17981                      [(match_operand:<VEC_GATHER_SRCDI> 1 "register_operand")
17982                       (mem:<ssescalarmode>
17983                         (match_par_dup 7
17984                           [(match_operand 2 "vsib_address_operand")
17985                            (match_operand:<VEC_GATHER_IDXDI>
17986                               3 "register_operand")
17987                            (match_operand:SI 5 "const1248_operand ")]))
17988                       (mem:BLK (scratch))
17989                       (match_operand:<VEC_GATHER_SRCDI>
17990                         4 "register_operand")]
17991                      UNSPEC_GATHER))
17992               (clobber (match_scratch:VEC_GATHER_MODE 6))])]
17993   "TARGET_AVX2"
17994 {
17995   operands[7]
17996     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[3],
17997                                         operands[5]), UNSPEC_VSIBADDR);
17998 })
17999
18000 (define_insn "*avx2_gatherdi<mode>"
18001   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
18002         (unspec:VEC_GATHER_MODE
18003           [(match_operand:<VEC_GATHER_SRCDI> 2 "register_operand" "0")
18004            (match_operator:<ssescalarmode> 7 "vsib_mem_operator"
18005              [(unspec:P
18006                 [(match_operand:P 3 "vsib_address_operand" "Tv")
18007                  (match_operand:<VEC_GATHER_IDXDI> 4 "register_operand" "x")
18008                  (match_operand:SI 6 "const1248_operand" "n")]
18009                 UNSPEC_VSIBADDR)])
18010            (mem:BLK (scratch))
18011            (match_operand:<VEC_GATHER_SRCDI> 5 "register_operand" "1")]
18012           UNSPEC_GATHER))
18013    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
18014   "TARGET_AVX2"
18015   "v<sseintprefix>gatherq<ssemodesuffix>\t{%5, %7, %2|%2, %7, %5}"
18016   [(set_attr "type" "ssemov")
18017    (set_attr "prefix" "vex")
18018    (set_attr "mode" "<sseinsnmode>")])
18019
18020 (define_insn "*avx2_gatherdi<mode>_2"
18021   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=&x")
18022         (unspec:VEC_GATHER_MODE
18023           [(pc)
18024            (match_operator:<ssescalarmode> 6 "vsib_mem_operator"
18025              [(unspec:P
18026                 [(match_operand:P 2 "vsib_address_operand" "Tv")
18027                  (match_operand:<VEC_GATHER_IDXDI> 3 "register_operand" "x")
18028                  (match_operand:SI 5 "const1248_operand" "n")]
18029                 UNSPEC_VSIBADDR)])
18030            (mem:BLK (scratch))
18031            (match_operand:<VEC_GATHER_SRCDI> 4 "register_operand" "1")]
18032           UNSPEC_GATHER))
18033    (clobber (match_scratch:VEC_GATHER_MODE 1 "=&x"))]
18034   "TARGET_AVX2"
18035 {
18036   if (<MODE>mode != <VEC_GATHER_SRCDI>mode)
18037     return "v<sseintprefix>gatherq<ssemodesuffix>\t{%4, %6, %x0|%x0, %6, %4}";
18038   return "v<sseintprefix>gatherq<ssemodesuffix>\t{%4, %6, %0|%0, %6, %4}";
18039 }
18040   [(set_attr "type" "ssemov")
18041    (set_attr "prefix" "vex")
18042    (set_attr "mode" "<sseinsnmode>")])
18043
18044 (define_insn "*avx2_gatherdi<mode>_3"
18045   [(set (match_operand:<VEC_GATHER_SRCDI> 0 "register_operand" "=&x")
18046         (vec_select:<VEC_GATHER_SRCDI>
18047           (unspec:VI4F_256
18048             [(match_operand:<VEC_GATHER_SRCDI> 2 "register_operand" "0")
18049              (match_operator:<ssescalarmode> 7 "vsib_mem_operator"
18050                [(unspec:P
18051                   [(match_operand:P 3 "vsib_address_operand" "Tv")
18052                    (match_operand:<VEC_GATHER_IDXDI> 4 "register_operand" "x")
18053                    (match_operand:SI 6 "const1248_operand" "n")]
18054                   UNSPEC_VSIBADDR)])
18055              (mem:BLK (scratch))
18056              (match_operand:<VEC_GATHER_SRCDI> 5 "register_operand" "1")]
18057              UNSPEC_GATHER)
18058           (parallel [(const_int 0) (const_int 1)
18059                      (const_int 2) (const_int 3)])))
18060    (clobber (match_scratch:VI4F_256 1 "=&x"))]
18061   "TARGET_AVX2"
18062   "v<sseintprefix>gatherq<ssemodesuffix>\t{%5, %7, %0|%0, %7, %5}"
18063   [(set_attr "type" "ssemov")
18064    (set_attr "prefix" "vex")
18065    (set_attr "mode" "<sseinsnmode>")])
18066
18067 (define_insn "*avx2_gatherdi<mode>_4"
18068   [(set (match_operand:<VEC_GATHER_SRCDI> 0 "register_operand" "=&x")
18069         (vec_select:<VEC_GATHER_SRCDI>
18070           (unspec:VI4F_256
18071             [(pc)
18072              (match_operator:<ssescalarmode> 6 "vsib_mem_operator"
18073                [(unspec:P
18074                   [(match_operand:P 2 "vsib_address_operand" "Tv")
18075                    (match_operand:<VEC_GATHER_IDXDI> 3 "register_operand" "x")
18076                    (match_operand:SI 5 "const1248_operand" "n")]
18077                   UNSPEC_VSIBADDR)])
18078              (mem:BLK (scratch))
18079              (match_operand:<VEC_GATHER_SRCDI> 4 "register_operand" "1")]
18080             UNSPEC_GATHER)
18081           (parallel [(const_int 0) (const_int 1)
18082                      (const_int 2) (const_int 3)])))
18083    (clobber (match_scratch:VI4F_256 1 "=&x"))]
18084   "TARGET_AVX2"
18085   "v<sseintprefix>gatherq<ssemodesuffix>\t{%4, %6, %0|%0, %6, %4}"
18086   [(set_attr "type" "ssemov")
18087    (set_attr "prefix" "vex")
18088    (set_attr "mode" "<sseinsnmode>")])
18089
18090 (define_expand "<avx512>_gathersi<mode>"
18091   [(parallel [(set (match_operand:VI48F 0 "register_operand")
18092                    (unspec:VI48F
18093                      [(match_operand:VI48F 1 "register_operand")
18094                       (match_operand:<avx512fmaskmode> 4 "register_operand")
18095                       (mem:<ssescalarmode>
18096                         (match_par_dup 6
18097                           [(match_operand 2 "vsib_address_operand")
18098                            (match_operand:<VEC_GATHER_IDXSI> 3 "register_operand")
18099                            (match_operand:SI 5 "const1248_operand")]))]
18100                      UNSPEC_GATHER))
18101               (clobber (match_scratch:<avx512fmaskmode> 7))])]
18102   "TARGET_AVX512F"
18103 {
18104   operands[6]
18105     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[3],
18106                                         operands[5]), UNSPEC_VSIBADDR);
18107 })
18108
18109 (define_insn "*avx512f_gathersi<mode>"
18110   [(set (match_operand:VI48F 0 "register_operand" "=&v")
18111         (unspec:VI48F
18112           [(match_operand:VI48F 1 "register_operand" "0")
18113            (match_operand:<avx512fmaskmode> 7 "register_operand" "2")
18114            (match_operator:<ssescalarmode> 6 "vsib_mem_operator"
18115              [(unspec:P
18116                 [(match_operand:P 4 "vsib_address_operand" "Tv")
18117                  (match_operand:<VEC_GATHER_IDXSI> 3 "register_operand" "v")
18118                  (match_operand:SI 5 "const1248_operand" "n")]
18119                 UNSPEC_VSIBADDR)])]
18120           UNSPEC_GATHER))
18121    (clobber (match_scratch:<avx512fmaskmode> 2 "=&Yk"))]
18122   "TARGET_AVX512F"
18123   "v<sseintprefix>gatherd<ssemodesuffix>\t{%6, %0%{%2%}|%0%{%2%}, %g6}"
18124   [(set_attr "type" "ssemov")
18125    (set_attr "prefix" "evex")
18126    (set_attr "mode" "<sseinsnmode>")])
18127
18128 (define_insn "*avx512f_gathersi<mode>_2"
18129   [(set (match_operand:VI48F 0 "register_operand" "=&v")
18130         (unspec:VI48F
18131           [(pc)
18132            (match_operand:<avx512fmaskmode> 6 "register_operand" "1")
18133            (match_operator:<ssescalarmode> 5 "vsib_mem_operator"
18134              [(unspec:P
18135                 [(match_operand:P 3 "vsib_address_operand" "Tv")
18136                  (match_operand:<VEC_GATHER_IDXSI> 2 "register_operand" "v")
18137                  (match_operand:SI 4 "const1248_operand" "n")]
18138                 UNSPEC_VSIBADDR)])]
18139           UNSPEC_GATHER))
18140    (clobber (match_scratch:<avx512fmaskmode> 1 "=&Yk"))]
18141   "TARGET_AVX512F"
18142   "v<sseintprefix>gatherd<ssemodesuffix>\t{%5, %0%{%1%}|%0%{%1%}, %g5}"
18143   [(set_attr "type" "ssemov")
18144    (set_attr "prefix" "evex")
18145    (set_attr "mode" "<sseinsnmode>")])
18146
18147
18148 (define_expand "<avx512>_gatherdi<mode>"
18149   [(parallel [(set (match_operand:VI48F 0 "register_operand")
18150                    (unspec:VI48F
18151                      [(match_operand:<VEC_GATHER_SRCDI> 1 "register_operand")
18152                       (match_operand:QI 4 "register_operand")
18153                       (mem:<ssescalarmode>
18154                         (match_par_dup 6
18155                           [(match_operand 2 "vsib_address_operand")
18156                            (match_operand:<VEC_GATHER_IDXDI> 3 "register_operand")
18157                            (match_operand:SI 5 "const1248_operand")]))]
18158                      UNSPEC_GATHER))
18159               (clobber (match_scratch:QI 7))])]
18160   "TARGET_AVX512F"
18161 {
18162   operands[6]
18163     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[2], operands[3],
18164                                         operands[5]), UNSPEC_VSIBADDR);
18165 })
18166
18167 (define_insn "*avx512f_gatherdi<mode>"
18168   [(set (match_operand:VI48F 0 "register_operand" "=&v")
18169         (unspec:VI48F
18170           [(match_operand:<VEC_GATHER_SRCDI> 1 "register_operand" "0")
18171            (match_operand:QI 7 "register_operand" "2")
18172            (match_operator:<ssescalarmode> 6 "vsib_mem_operator"
18173              [(unspec:P
18174                 [(match_operand:P 4 "vsib_address_operand" "Tv")
18175                  (match_operand:<VEC_GATHER_IDXDI> 3 "register_operand" "v")
18176                  (match_operand:SI 5 "const1248_operand" "n")]
18177                 UNSPEC_VSIBADDR)])]
18178           UNSPEC_GATHER))
18179    (clobber (match_scratch:QI 2 "=&Yk"))]
18180   "TARGET_AVX512F"
18181   "v<sseintprefix>gatherq<ssemodesuffix>\t{%6, %1%{%2%}|%1%{%2%}, %g6}"
18182   [(set_attr "type" "ssemov")
18183    (set_attr "prefix" "evex")
18184    (set_attr "mode" "<sseinsnmode>")])
18185
18186 (define_insn "*avx512f_gatherdi<mode>_2"
18187   [(set (match_operand:VI48F 0 "register_operand" "=&v")
18188         (unspec:VI48F
18189           [(pc)
18190            (match_operand:QI 6 "register_operand" "1")
18191            (match_operator:<ssescalarmode> 5 "vsib_mem_operator"
18192              [(unspec:P
18193                 [(match_operand:P 3 "vsib_address_operand" "Tv")
18194                  (match_operand:<VEC_GATHER_IDXDI> 2 "register_operand" "v")
18195                  (match_operand:SI 4 "const1248_operand" "n")]
18196                 UNSPEC_VSIBADDR)])]
18197           UNSPEC_GATHER))
18198    (clobber (match_scratch:QI 1 "=&Yk"))]
18199   "TARGET_AVX512F"
18200 {
18201   if (<MODE>mode != <VEC_GATHER_SRCDI>mode)
18202     {
18203       if (<MODE_SIZE> != 64)
18204         return "v<sseintprefix>gatherq<ssemodesuffix>\t{%5, %x0%{%1%}|%t0%{%1%}, %g5}";
18205       else
18206         return "v<sseintprefix>gatherq<ssemodesuffix>\t{%5, %t0%{%1%}|%t0%{%1%}, %g5}";
18207     }
18208   return "v<sseintprefix>gatherq<ssemodesuffix>\t{%5, %0%{%1%}|%0%{%1%}, %g5}";
18209 }
18210   [(set_attr "type" "ssemov")
18211    (set_attr "prefix" "evex")
18212    (set_attr "mode" "<sseinsnmode>")])
18213
18214 (define_expand "<avx512>_scattersi<mode>"
18215   [(parallel [(set (mem:VI48F
18216                      (match_par_dup 5
18217                        [(match_operand 0 "vsib_address_operand")
18218                         (match_operand:<VEC_GATHER_IDXSI> 2 "register_operand")
18219                         (match_operand:SI 4 "const1248_operand")]))
18220                    (unspec:VI48F
18221                      [(match_operand:<avx512fmaskmode> 1 "register_operand")
18222                       (match_operand:VI48F 3 "register_operand")]
18223                      UNSPEC_SCATTER))
18224               (clobber (match_scratch:<avx512fmaskmode> 6))])]
18225   "TARGET_AVX512F"
18226 {
18227   operands[5]
18228     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[0], operands[2],
18229                                         operands[4]), UNSPEC_VSIBADDR);
18230 })
18231
18232 (define_insn "*avx512f_scattersi<mode>"
18233   [(set (match_operator:VI48F 5 "vsib_mem_operator"
18234           [(unspec:P
18235              [(match_operand:P 0 "vsib_address_operand" "Tv")
18236               (match_operand:<VEC_GATHER_IDXSI> 2 "register_operand" "v")
18237               (match_operand:SI 4 "const1248_operand" "n")]
18238              UNSPEC_VSIBADDR)])
18239         (unspec:VI48F
18240           [(match_operand:<avx512fmaskmode> 6 "register_operand" "1")
18241            (match_operand:VI48F 3 "register_operand" "v")]
18242           UNSPEC_SCATTER))
18243    (clobber (match_scratch:<avx512fmaskmode> 1 "=&Yk"))]
18244   "TARGET_AVX512F"
18245   "v<sseintprefix>scatterd<ssemodesuffix>\t{%3, %5%{%1%}|%5%{%1%}, %3}"
18246   [(set_attr "type" "ssemov")
18247    (set_attr "prefix" "evex")
18248    (set_attr "mode" "<sseinsnmode>")])
18249
18250 (define_expand "<avx512>_scatterdi<mode>"
18251   [(parallel [(set (mem:VI48F
18252                      (match_par_dup 5
18253                        [(match_operand 0 "vsib_address_operand")
18254                         (match_operand:<VEC_GATHER_IDXDI> 2 "register_operand")
18255                         (match_operand:SI 4 "const1248_operand")]))
18256                    (unspec:VI48F
18257                      [(match_operand:QI 1 "register_operand")
18258                       (match_operand:<VEC_GATHER_SRCDI> 3 "register_operand")]
18259                      UNSPEC_SCATTER))
18260               (clobber (match_scratch:QI 6))])]
18261   "TARGET_AVX512F"
18262 {
18263   operands[5]
18264     = gen_rtx_UNSPEC (Pmode, gen_rtvec (3, operands[0], operands[2],
18265                                         operands[4]), UNSPEC_VSIBADDR);
18266 })
18267
18268 (define_insn "*avx512f_scatterdi<mode>"
18269   [(set (match_operator:VI48F 5 "vsib_mem_operator"
18270           [(unspec:P
18271              [(match_operand:P 0 "vsib_address_operand" "Tv")
18272               (match_operand:<VEC_GATHER_IDXDI> 2 "register_operand" "v")
18273               (match_operand:SI 4 "const1248_operand" "n")]
18274              UNSPEC_VSIBADDR)])
18275         (unspec:VI48F
18276           [(match_operand:QI 6 "register_operand" "1")
18277            (match_operand:<VEC_GATHER_SRCDI> 3 "register_operand" "v")]
18278           UNSPEC_SCATTER))
18279    (clobber (match_scratch:QI 1 "=&Yk"))]
18280   "TARGET_AVX512F"
18281   "v<sseintprefix>scatterq<ssemodesuffix>\t{%3, %5%{%1%}|%5%{%1%}, %3}"
18282   [(set_attr "type" "ssemov")
18283    (set_attr "prefix" "evex")
18284    (set_attr "mode" "<sseinsnmode>")])
18285
18286 (define_insn "<avx512>_compress<mode>_mask"
18287   [(set (match_operand:VI48F 0 "register_operand" "=v")
18288         (unspec:VI48F
18289           [(match_operand:VI48F 1 "register_operand" "v")
18290            (match_operand:VI48F 2 "vector_move_operand" "0C")
18291            (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk")]
18292           UNSPEC_COMPRESS))]
18293   "TARGET_AVX512F"
18294   "v<sseintprefix>compress<ssemodesuffix>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
18295   [(set_attr "type" "ssemov")
18296    (set_attr "prefix" "evex")
18297    (set_attr "mode" "<sseinsnmode>")])
18298
18299 (define_insn "<avx512>_compressstore<mode>_mask"
18300   [(set (match_operand:VI48F 0 "memory_operand" "=m")
18301         (unspec:VI48F
18302           [(match_operand:VI48F 1 "register_operand" "x")
18303            (match_dup 0)
18304            (match_operand:<avx512fmaskmode> 2 "register_operand" "Yk")]
18305           UNSPEC_COMPRESS_STORE))]
18306   "TARGET_AVX512F"
18307   "v<sseintprefix>compress<ssemodesuffix>\t{%1, %0%{%2%}|%0%{%2%}, %1}"
18308   [(set_attr "type" "ssemov")
18309    (set_attr "prefix" "evex")
18310    (set_attr "memory" "store")
18311    (set_attr "mode" "<sseinsnmode>")])
18312
18313 (define_expand "<avx512>_expand<mode>_maskz"
18314   [(set (match_operand:VI48F 0 "register_operand")
18315         (unspec:VI48F
18316           [(match_operand:VI48F 1 "nonimmediate_operand")
18317            (match_operand:VI48F 2 "vector_move_operand")
18318            (match_operand:<avx512fmaskmode> 3 "register_operand")]
18319           UNSPEC_EXPAND))]
18320   "TARGET_AVX512F"
18321   "operands[2] = CONST0_RTX (<MODE>mode);")
18322
18323 (define_insn "<avx512>_expand<mode>_mask"
18324   [(set (match_operand:VI48F 0 "register_operand" "=v,v")
18325         (unspec:VI48F
18326           [(match_operand:VI48F 1 "nonimmediate_operand" "v,m")
18327            (match_operand:VI48F 2 "vector_move_operand" "0C,0C")
18328            (match_operand:<avx512fmaskmode> 3 "register_operand" "Yk,Yk")]
18329           UNSPEC_EXPAND))]
18330   "TARGET_AVX512F"
18331   "v<sseintprefix>expand<ssemodesuffix>\t{%1, %0%{%3%}%N2|%0%{%3%}%N2, %1}"
18332   [(set_attr "type" "ssemov")
18333    (set_attr "prefix" "evex")
18334    (set_attr "memory" "none,load")
18335    (set_attr "mode" "<sseinsnmode>")])
18336
18337 (define_insn "avx512dq_rangep<mode><mask_name><round_saeonly_name>"
18338   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
18339         (unspec:VF_AVX512VL
18340           [(match_operand:VF_AVX512VL 1 "register_operand" "v")
18341            (match_operand:VF_AVX512VL 2 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
18342            (match_operand:SI 3 "const_0_to_15_operand")]
18343           UNSPEC_RANGE))]
18344   "TARGET_AVX512DQ && <round_saeonly_mode512bit_condition>"
18345   "vrange<ssemodesuffix>\t{<round_saeonly_mask_op4>%3, %2, %1, %0<mask_operand4>|%0<mask_operand4>, %1, %2, %3<round_saeonly_mask_op4>}"
18346   [(set_attr "type" "sse")
18347    (set_attr "prefix" "evex")
18348    (set_attr "mode" "<MODE>")])
18349
18350 (define_insn "avx512dq_ranges<mode><round_saeonly_name>"
18351   [(set (match_operand:VF_128 0 "register_operand" "=v")
18352         (vec_merge:VF_128
18353           (unspec:VF_128
18354             [(match_operand:VF_128 1 "register_operand" "v")
18355              (match_operand:VF_128 2 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
18356              (match_operand:SI 3 "const_0_to_15_operand")]
18357             UNSPEC_RANGE)
18358           (match_dup 1)
18359           (const_int 1)))]
18360   "TARGET_AVX512DQ"
18361   "vrange<ssescalarmodesuffix>\t{<round_saeonly_op4>%3, %2, %1, %0|%0, %1, %2, %3<round_saeonly_op4>}"
18362   [(set_attr "type" "sse")
18363    (set_attr "prefix" "evex")
18364    (set_attr "mode" "<MODE>")])
18365
18366 (define_insn "avx512dq_fpclass<mode><mask_scalar_merge_name>"
18367   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
18368           (unspec:<avx512fmaskmode>
18369             [(match_operand:VF_AVX512VL 1 "register_operand" "v")
18370              (match_operand:QI 2 "const_0_to_255_operand" "n")]
18371              UNSPEC_FPCLASS))]
18372    "TARGET_AVX512DQ"
18373    "vfpclass<ssemodesuffix>\t{%2, %1, %0<mask_scalar_merge_operand3>|%0<mask_scalar_merge_operand3>, %1, %2}";
18374   [(set_attr "type" "sse")
18375    (set_attr "length_immediate" "1")
18376    (set_attr "prefix" "evex")
18377    (set_attr "mode" "<MODE>")])
18378
18379 (define_insn "avx512dq_vmfpclass<mode>"
18380   [(set (match_operand:<avx512fmaskmode> 0 "register_operand" "=Yk")
18381         (and:<avx512fmaskmode>
18382           (unspec:<avx512fmaskmode>
18383             [(match_operand:VF_128 1 "register_operand" "v")
18384              (match_operand:QI 2 "const_0_to_255_operand" "n")]
18385             UNSPEC_FPCLASS)
18386           (const_int 1)))]
18387    "TARGET_AVX512DQ"
18388    "vfpclass<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}";
18389   [(set_attr "type" "sse")
18390    (set_attr "length_immediate" "1")
18391    (set_attr "prefix" "evex")
18392    (set_attr "mode" "<MODE>")])
18393
18394 (define_insn "<avx512>_getmant<mode><mask_name><round_saeonly_name>"
18395   [(set (match_operand:VF_AVX512VL 0 "register_operand" "=v")
18396         (unspec:VF_AVX512VL
18397           [(match_operand:VF_AVX512VL 1 "nonimmediate_operand" "<round_saeonly_constraint>")
18398            (match_operand:SI 2 "const_0_to_15_operand")]
18399           UNSPEC_GETMANT))]
18400   "TARGET_AVX512F"
18401   "vgetmant<ssemodesuffix>\t{%2, <round_saeonly_mask_op3>%1, %0<mask_operand3>|%0<mask_operand3>, %1<round_saeonly_mask_op3>, %2}";
18402   [(set_attr "prefix" "evex")
18403    (set_attr "mode" "<MODE>")])
18404
18405 (define_insn "avx512f_vgetmant<mode><round_saeonly_name>"
18406   [(set (match_operand:VF_128 0 "register_operand" "=v")
18407         (vec_merge:VF_128
18408           (unspec:VF_128
18409             [(match_operand:VF_128 1 "register_operand" "v")
18410              (match_operand:VF_128 2 "<round_saeonly_nimm_predicate>" "<round_saeonly_constraint>")
18411              (match_operand:SI 3 "const_0_to_15_operand")]
18412             UNSPEC_GETMANT)
18413           (match_dup 1)
18414           (const_int 1)))]
18415    "TARGET_AVX512F"
18416    "vgetmant<ssescalarmodesuffix>\t{%3, <round_saeonly_op4>%2, %1, %0|%0, %1, %2<round_saeonly_op4>, %3}";
18417    [(set_attr "prefix" "evex")
18418    (set_attr "mode" "<ssescalarmode>")])
18419
18420 ;; The correct representation for this is absolutely enormous, and
18421 ;; surely not generally useful.
18422 (define_insn "<mask_codefor>avx512bw_dbpsadbw<mode><mask_name>"
18423   [(set (match_operand:VI2_AVX512VL 0 "register_operand" "=v")
18424         (unspec:VI2_AVX512VL
18425           [(match_operand:<dbpsadbwmode> 1 "register_operand" "v")
18426            (match_operand:<dbpsadbwmode> 2 "nonimmediate_operand" "vm")
18427            (match_operand:SI 3 "const_0_to_255_operand")]
18428           UNSPEC_DBPSADBW))]
18429    "TARGET_AVX512BW"
18430   "vdbpsadbw\t{%3, %2, %1, %0<mask_operand4>|%0<mask_operand4>, %1, %2, %3}"
18431   [(set_attr "isa" "avx")
18432    (set_attr "type" "sselog1")
18433    (set_attr "length_immediate" "1")
18434    (set_attr "prefix" "evex")
18435    (set_attr "mode" "<sseinsnmode>")])
18436
18437 (define_insn "clz<mode>2<mask_name>"
18438   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
18439         (clz:VI48_AVX512VL
18440           (match_operand:VI48_AVX512VL 1 "nonimmediate_operand" "vm")))]
18441   "TARGET_AVX512CD"
18442   "vplzcnt<ssemodesuffix>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
18443   [(set_attr "type" "sse")
18444    (set_attr "prefix" "evex")
18445    (set_attr "mode" "<sseinsnmode>")])
18446
18447 (define_insn "<mask_codefor>conflict<mode><mask_name>"
18448   [(set (match_operand:VI48_AVX512VL 0 "register_operand" "=v")
18449         (unspec:VI48_AVX512VL
18450           [(match_operand:VI48_AVX512VL 1 "nonimmediate_operand" "vm")]
18451           UNSPEC_CONFLICT))]
18452   "TARGET_AVX512CD"
18453   "vpconflict<ssemodesuffix>\t{%1, %0<mask_operand2>|%0<mask_operand2>, %1}"
18454   [(set_attr "type" "sse")
18455    (set_attr "prefix" "evex")
18456    (set_attr "mode" "<sseinsnmode>")])
18457
18458 (define_insn "sha1msg1"
18459   [(set (match_operand:V4SI 0 "register_operand" "=x")
18460         (unspec:V4SI
18461           [(match_operand:V4SI 1 "register_operand" "0")
18462            (match_operand:V4SI 2 "nonimmediate_operand" "xm")]
18463           UNSPEC_SHA1MSG1))]
18464   "TARGET_SHA"
18465   "sha1msg1\t{%2, %0|%0, %2}"
18466   [(set_attr "type" "sselog1")
18467    (set_attr "mode" "TI")])
18468
18469 (define_insn "sha1msg2"
18470   [(set (match_operand:V4SI 0 "register_operand" "=x")
18471         (unspec:V4SI
18472           [(match_operand:V4SI 1 "register_operand" "0")
18473            (match_operand:V4SI 2 "nonimmediate_operand" "xm")]
18474           UNSPEC_SHA1MSG2))]
18475   "TARGET_SHA"
18476   "sha1msg2\t{%2, %0|%0, %2}"
18477   [(set_attr "type" "sselog1")
18478    (set_attr "mode" "TI")])
18479
18480 (define_insn "sha1nexte"
18481   [(set (match_operand:V4SI 0 "register_operand" "=x")
18482         (unspec:V4SI
18483           [(match_operand:V4SI 1 "register_operand" "0")
18484            (match_operand:V4SI 2 "nonimmediate_operand" "xm")]
18485           UNSPEC_SHA1NEXTE))]
18486   "TARGET_SHA"
18487   "sha1nexte\t{%2, %0|%0, %2}"
18488   [(set_attr "type" "sselog1")
18489    (set_attr "mode" "TI")])
18490
18491 (define_insn "sha1rnds4"
18492   [(set (match_operand:V4SI 0 "register_operand" "=x")
18493         (unspec:V4SI
18494           [(match_operand:V4SI 1 "register_operand" "0")
18495            (match_operand:V4SI 2 "nonimmediate_operand" "xm")
18496            (match_operand:SI 3 "const_0_to_3_operand" "n")]
18497           UNSPEC_SHA1RNDS4))]
18498   "TARGET_SHA"
18499   "sha1rnds4\t{%3, %2, %0|%0, %2, %3}"
18500   [(set_attr "type" "sselog1")
18501    (set_attr "length_immediate" "1")
18502    (set_attr "mode" "TI")])
18503
18504 (define_insn "sha256msg1"
18505   [(set (match_operand:V4SI 0 "register_operand" "=x")
18506         (unspec:V4SI
18507           [(match_operand:V4SI 1 "register_operand" "0")
18508            (match_operand:V4SI 2 "nonimmediate_operand" "xm")]
18509           UNSPEC_SHA256MSG1))]
18510   "TARGET_SHA"
18511   "sha256msg1\t{%2, %0|%0, %2}"
18512   [(set_attr "type" "sselog1")
18513    (set_attr "mode" "TI")])
18514
18515 (define_insn "sha256msg2"
18516   [(set (match_operand:V4SI 0 "register_operand" "=x")
18517         (unspec:V4SI
18518           [(match_operand:V4SI 1 "register_operand" "0")
18519            (match_operand:V4SI 2 "nonimmediate_operand" "xm")]
18520           UNSPEC_SHA256MSG2))]
18521   "TARGET_SHA"
18522   "sha256msg2\t{%2, %0|%0, %2}"
18523   [(set_attr "type" "sselog1")
18524    (set_attr "mode" "TI")])
18525
18526 (define_insn "sha256rnds2"
18527   [(set (match_operand:V4SI 0 "register_operand" "=x")
18528         (unspec:V4SI
18529           [(match_operand:V4SI 1 "register_operand" "0")
18530            (match_operand:V4SI 2 "nonimmediate_operand" "xm")
18531            (match_operand:V4SI 3 "register_operand" "Yz")]
18532           UNSPEC_SHA256RNDS2))]
18533   "TARGET_SHA"
18534   "sha256rnds2\t{%3, %2, %0|%0, %2, %3}"
18535   [(set_attr "type" "sselog1")
18536    (set_attr "length_immediate" "1")
18537    (set_attr "mode" "TI")])
18538
18539 (define_insn_and_split "avx512f_<castmode><avxsizesuffix>_<castmode>"
18540   [(set (match_operand:AVX512MODE2P 0 "nonimmediate_operand" "=x,m")
18541         (unspec:AVX512MODE2P
18542           [(match_operand:<ssequartermode> 1 "nonimmediate_operand" "xm,x")]
18543           UNSPEC_CAST))]
18544   "TARGET_AVX512F"
18545   "#"
18546   "&& reload_completed"
18547   [(const_int 0)]
18548 {
18549   rtx op0 = operands[0];
18550   rtx op1 = operands[1];
18551   if (REG_P (op0))
18552     op0 = gen_rtx_REG (<ssequartermode>mode, REGNO (op0));
18553   else
18554     op1 = gen_rtx_REG (<MODE>mode, REGNO (op1));
18555   emit_move_insn (op0, op1);
18556   DONE;
18557 })
18558
18559 (define_insn_and_split "avx512f_<castmode><avxsizesuffix>_256<castmode>"
18560   [(set (match_operand:AVX512MODE2P 0 "nonimmediate_operand" "=x,m")
18561         (unspec:AVX512MODE2P
18562           [(match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "xm,x")]
18563           UNSPEC_CAST))]
18564   "TARGET_AVX512F"
18565   "#"
18566   "&& reload_completed"
18567   [(const_int 0)]
18568 {
18569   rtx op0 = operands[0];
18570   rtx op1 = operands[1];
18571   if (REG_P (op0))
18572     op0 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op0));
18573   else
18574     op1 = gen_rtx_REG (<MODE>mode, REGNO (op1));
18575   emit_move_insn (op0, op1);
18576   DONE;
18577 })
18578
18579 (define_int_iterator VPMADD52
18580         [UNSPEC_VPMADD52LUQ
18581          UNSPEC_VPMADD52HUQ])
18582
18583 (define_int_attr vpmadd52type
18584   [(UNSPEC_VPMADD52LUQ "luq") (UNSPEC_VPMADD52HUQ "huq")])
18585
18586 (define_expand "vpamdd52huq<mode>_maskz"
18587   [(match_operand:VI8_AVX512VL 0 "register_operand")
18588    (match_operand:VI8_AVX512VL 1 "register_operand")
18589    (match_operand:VI8_AVX512VL 2 "register_operand")
18590    (match_operand:VI8_AVX512VL 3 "nonimmediate_operand")
18591    (match_operand:<avx512fmaskmode> 4 "register_operand")]
18592   "TARGET_AVX512IFMA"
18593 {
18594   emit_insn (gen_vpamdd52huq<mode>_maskz_1 (
18595     operands[0], operands[1], operands[2], operands[3],
18596     CONST0_RTX (<MODE>mode), operands[4]));
18597   DONE;
18598 })
18599
18600 (define_expand "vpamdd52luq<mode>_maskz"
18601   [(match_operand:VI8_AVX512VL 0 "register_operand")
18602    (match_operand:VI8_AVX512VL 1 "register_operand")
18603    (match_operand:VI8_AVX512VL 2 "register_operand")
18604    (match_operand:VI8_AVX512VL 3 "nonimmediate_operand")
18605    (match_operand:<avx512fmaskmode> 4 "register_operand")]
18606   "TARGET_AVX512IFMA"
18607 {
18608   emit_insn (gen_vpamdd52luq<mode>_maskz_1 (
18609     operands[0], operands[1], operands[2], operands[3],
18610     CONST0_RTX (<MODE>mode), operands[4]));
18611   DONE;
18612 })
18613
18614 (define_insn "vpamdd52<vpmadd52type><mode><sd_maskz_name>"
18615   [(set (match_operand:VI8_AVX512VL 0 "register_operand" "=v")
18616         (unspec:VI8_AVX512VL
18617           [(match_operand:VI8_AVX512VL 1 "register_operand" "0")
18618            (match_operand:VI8_AVX512VL 2 "register_operand" "v")
18619            (match_operand:VI8_AVX512VL 3 "nonimmediate_operand" "vm")]
18620           VPMADD52))]
18621   "TARGET_AVX512IFMA"
18622   "vpmadd52<vpmadd52type>\t{%3, %2, %0<sd_mask_op4>|%0<sd_mask_op4>, %2, %3}"
18623   [(set_attr "type" "ssemuladd")
18624    (set_attr "prefix" "evex")
18625    (set_attr "mode" "<sseinsnmode>")])
18626
18627 (define_insn "vpamdd52<vpmadd52type><mode>_mask"
18628   [(set (match_operand:VI8_AVX512VL 0 "register_operand" "=v")
18629         (vec_merge:VI8_AVX512VL
18630           (unspec:VI8_AVX512VL
18631             [(match_operand:VI8_AVX512VL 1 "register_operand" "0")
18632              (match_operand:VI8_AVX512VL 2 "register_operand" "v")
18633              (match_operand:VI8_AVX512VL 3 "nonimmediate_operand" "vm")]
18634             VPMADD52)
18635           (match_dup 1)
18636           (match_operand:<avx512fmaskmode> 4 "register_operand" "Yk")))]
18637   "TARGET_AVX512IFMA"
18638   "vpmadd52<vpmadd52type>\t{%3, %2, %0%{%4%}|%0%{%4%}, %2, %3}"
18639   [(set_attr "type" "ssemuladd")
18640    (set_attr "prefix" "evex")
18641    (set_attr "mode" "<sseinsnmode>")])
18642
18643 (define_insn "vpmultishiftqb<mode><mask_name>"
18644   [(set (match_operand:VI1_AVX512VL 0 "register_operand" "=v")
18645         (unspec:VI1_AVX512VL
18646           [(match_operand:VI1_AVX512VL 1 "register_operand" "v")
18647            (match_operand:VI1_AVX512VL 2 "nonimmediate_operand" "vm")]
18648           UNSPEC_VPMULTISHIFT))]
18649   "TARGET_AVX512VBMI"
18650   "vpmultishiftqb\t{%2, %1, %0<mask_operand3>|%0<mask_operand3>, %1, %2}"
18651   [(set_attr "type" "sselog")
18652    (set_attr "prefix" "evex")
18653    (set_attr "mode" "<sseinsnmode>")])