OSDN Git Service

* config/i386/i386.c (ix86_build_const_vector): Handle V8SImode
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / sse.md
1 ;; GCC machine description for SSE instructions
2 ;; Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 ;; Free Software Foundation, Inc.
4 ;;
5 ;; This file is part of GCC.
6 ;;
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
10 ;; any later version.
11 ;;
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3.  If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;; All vector modes including V1TImode, used in move patterns.
22 (define_mode_iterator V16
23   [(V32QI "TARGET_AVX") V16QI
24    (V16HI "TARGET_AVX") V8HI
25    (V8SI "TARGET_AVX") V4SI
26    (V4DI "TARGET_AVX") V2DI
27    V1TI
28    (V8SF "TARGET_AVX") V4SF
29    (V4DF "TARGET_AVX") V2DF])
30
31 ;; All vector modes
32 (define_mode_iterator V
33   [(V32QI "TARGET_AVX") V16QI
34    (V16HI "TARGET_AVX") V8HI
35    (V8SI "TARGET_AVX") V4SI
36    (V4DI "TARGET_AVX") V2DI
37    (V8SF "TARGET_AVX") V4SF
38    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
39
40 ;; All 128bit vector modes
41 (define_mode_iterator V_128
42   [V16QI V8HI V4SI V2DI V4SF (V2DF "TARGET_SSE2")])
43
44 ;; All 256bit vector modes
45 (define_mode_iterator V_256
46   [V32QI V16HI V8SI V4DI V8SF V4DF])
47
48 ;; All vector float modes
49 (define_mode_iterator VF
50   [(V8SF "TARGET_AVX") V4SF
51    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
52
53 ;; All SFmode vector float modes
54 (define_mode_iterator VF1
55   [(V8SF "TARGET_AVX") V4SF])
56
57 ;; All DFmode vector float modes
58 (define_mode_iterator VF2
59   [(V4DF "TARGET_AVX") V2DF])
60
61 ;; All 128bit vector float modes
62 (define_mode_iterator VF_128
63   [V4SF (V2DF "TARGET_SSE2")])
64
65 ;; All 256bit vector float modes
66 (define_mode_iterator VF_256
67   [V8SF V4DF])
68
69 ;; All vector integer modes
70 (define_mode_iterator VI
71   [(V32QI "TARGET_AVX") V16QI
72    (V16HI "TARGET_AVX") V8HI
73    (V8SI "TARGET_AVX") V4SI
74    (V4DI "TARGET_AVX") V2DI])
75
76 (define_mode_iterator VI_AVX2
77   [(V32QI "TARGET_AVX2") V16QI
78    (V16HI "TARGET_AVX2") V8HI
79    (V8SI "TARGET_AVX2") V4SI
80    (V4DI "TARGET_AVX2") V2DI])
81
82 ;; All QImode vector integer modes
83 (define_mode_iterator VI1
84   [(V32QI "TARGET_AVX") V16QI])
85
86 ;; All DImode vector integer modes
87 (define_mode_iterator VI8
88   [(V4DI "TARGET_AVX") V2DI])
89
90 (define_mode_iterator VI1_AVX2
91   [(V32QI "TARGET_AVX2") V16QI])
92
93 (define_mode_iterator VI2_AVX2
94   [(V16HI "TARGET_AVX2") V8HI])
95
96 (define_mode_iterator VI4_AVX2
97   [(V8SI "TARGET_AVX2") V4SI])
98
99 (define_mode_iterator VI8_AVX2
100   [(V4DI "TARGET_AVX2") V2DI])
101
102 (define_mode_iterator VIMAX_AVX2
103   [(V4DI "TARGET_AVX2") V1TI])
104
105 (define_mode_iterator SSESCALARMODE
106   [(V4DI "TARGET_AVX2") TI])
107
108 (define_mode_iterator VI12_AVX2
109   [(V32QI "TARGET_AVX2") V16QI
110    (V16HI "TARGET_AVX2") V8HI])
111
112 (define_mode_iterator VI24_AVX2
113   [(V16HI "TARGET_AVX2") V8HI
114    (V8SI "TARGET_AVX2") V4SI])
115
116 (define_mode_iterator VI124_AVX2
117   [(V32QI "TARGET_AVX2") V16QI
118    (V16HI "TARGET_AVX2") V8HI
119    (V8SI "TARGET_AVX2") V4SI])
120
121 (define_mode_iterator VI248_AVX2
122   [(V16HI "TARGET_AVX2") V8HI
123    (V8SI "TARGET_AVX2") V4SI
124    (V4DI "TARGET_AVX2") V2DI])
125
126 (define_mode_iterator VI48_AVX2
127   [V8SI V4SI V4DI V2DI])
128
129 (define_mode_iterator VI4SD_AVX2
130   [V4SI V4DI])
131
132 (define_mode_iterator V48_AVX2
133   [V4SF V2DF
134    V8SF V4DF
135    (V4SI "TARGET_AVX2") (V2DI "TARGET_AVX2")
136    (V8SI "TARGET_AVX2") (V4DI "TARGET_AVX2")])
137
138 (define_mode_attr sse2_avx2
139   [(V16QI "sse2") (V32QI "avx2")
140    (V8HI "sse2") (V16HI "avx2")
141    (V4SI "sse2") (V8SI "avx2")
142    (V2DI "sse2") (V4DI "avx2")
143    (V1TI "sse2")])
144
145 (define_mode_attr ssse3_avx2
146    [(V16QI "ssse3") (V32QI "avx2")
147     (V8HI "ssse3") (V16HI "avx2")
148     (V4SI "ssse3") (V8SI "avx2")
149     (V2DI "ssse3") (V4DI "avx2")
150     (TI "ssse3")])
151
152 (define_mode_attr sse4_1_avx2
153    [(V16QI "sse4_1") (V32QI "avx2")
154     (V8HI "sse4_1") (V16HI "avx2")
155     (V4SI "sse4_1") (V8SI "avx2")
156     (V2DI "sse4_1") (V4DI "avx2")])
157
158 (define_mode_attr avx_avx2
159   [(V4SF "avx") (V2DF "avx")
160    (V8SF "avx") (V4DF "avx")
161    (V4SI "avx2") (V2DI "avx2")
162    (V8SI "avx2") (V4DI "avx2")])
163
164 ;; Mapping of logic-shift operators
165 (define_code_iterator lshift [lshiftrt ashift])
166
167 ;; Base name for define_insn
168 (define_code_attr lshift_insn [(lshiftrt "srl") (ashift "sll")])
169
170 ;; Base name for insn mnemonic
171 (define_code_attr lshift [(lshiftrt "lshr") (ashift "lshl")])
172
173 (define_mode_attr ssedoublemode
174   [(V16HI "V16SI") (V8HI "V8SI")])
175
176 (define_mode_attr ssebytemode
177   [(V4DI "V32QI") (V2DI "V16QI")])
178
179 ;; All 128bit vector integer modes
180 (define_mode_iterator VI_128 [V16QI V8HI V4SI V2DI])
181
182 ;; All 256bit vector integer modes
183 (define_mode_iterator VI_256 [V32QI V16HI V8SI V4DI])
184
185 ;; Random 128bit vector integer mode combinations
186 (define_mode_iterator VI12_128 [V16QI V8HI])
187 (define_mode_iterator VI14_128 [V16QI V4SI])
188 (define_mode_iterator VI124_128 [V16QI V8HI V4SI])
189 (define_mode_iterator VI24_128 [V8HI V4SI])
190 (define_mode_iterator VI248_128 [V8HI V4SI V2DI])
191
192 ;; Random 256bit vector integer mode combinations
193 (define_mode_iterator VI124_256 [V32QI V16HI V8SI])
194 (define_mode_iterator VI1248_256 [V32QI V16HI V8SI V4DI])
195 (define_mode_iterator VI248_256 [V16HI V8SI V4DI])
196
197 ;; Int-float size matches
198 (define_mode_iterator VI4F_128 [V4SI V4SF])
199 (define_mode_iterator VI8F_128 [V2DI V2DF])
200 (define_mode_iterator VI4F_256 [V8SI V8SF])
201 (define_mode_iterator VI8F_256 [V4DI V4DF])
202
203 ;; Mapping from float mode to required SSE level
204 (define_mode_attr sse
205   [(SF "sse") (DF "sse2")
206    (V4SF "sse") (V2DF "sse2")
207    (V8SF "avx") (V4DF "avx")])
208
209 (define_mode_attr sse2
210   [(V16QI "sse2") (V32QI "avx")
211    (V2DI "sse2") (V4DI "avx")])
212
213 (define_mode_attr sse3
214   [(V16QI "sse3") (V32QI "avx")])
215
216 (define_mode_attr sse4_1
217   [(V4SF "sse4_1") (V2DF "sse4_1")
218    (V8SF "avx") (V4DF "avx")])
219
220 (define_mode_attr avxsizesuffix
221   [(V32QI "256") (V16HI "256") (V8SI "256") (V4DI "256")
222    (V16QI "") (V8HI "") (V4SI "") (V2DI "")
223    (V8SF "256") (V4DF "256")
224    (V4SF "") (V2DF "")])
225
226 ;; SSE instruction mode
227 (define_mode_attr sseinsnmode
228   [(V32QI "OI") (V16HI "OI") (V8SI "OI") (V4DI "OI")
229    (V16QI "TI") (V8HI "TI") (V4SI "TI") (V2DI "TI") (V1TI "TI")
230    (V8SF "V8SF") (V4DF "V4DF")
231    (V4SF "V4SF") (V2DF "V2DF")
232    (TI "TI")])
233
234 ;; Mapping of vector float modes to an integer mode of the same size
235 (define_mode_attr sseintvecmode
236   [(V8SF "V8SI") (V4DF "V4DI")
237    (V4SF "V4SI") (V2DF "V2DI")
238    (V4DF "V4DI") (V8SF "V8SI")
239    (V8SI "V8SI") (V4DI "V4DI")
240    (V4SI "V4SI") (V2DI "V2DI")])
241
242 ;; Mapping of vector modes to a vector mode of double size
243 (define_mode_attr ssedoublevecmode
244   [(V32QI "V64QI") (V16HI "V32HI") (V8SI "V16SI") (V4DI "V8DI")
245    (V16QI "V32QI") (V8HI "V16HI") (V4SI "V8SI") (V2DI "V4DI")
246    (V8SF "V16SF") (V4DF "V8DF")
247    (V4SF "V8SF") (V2DF "V4DF")])
248
249 ;; Mapping of vector modes to a vector mode of half size
250 (define_mode_attr ssehalfvecmode
251   [(V32QI "V16QI") (V16HI "V8HI") (V8SI "V4SI") (V4DI "V2DI")
252    (V16QI  "V8QI") (V8HI  "V4HI") (V4SI "V2SI")
253    (V8SF "V4SF") (V4DF "V2DF")
254    (V4SF "V2SF")])
255
256 ;; Mapping of vector modes back to the scalar modes
257 (define_mode_attr ssescalarmode
258   [(V32QI "QI") (V16HI "HI") (V8SI "SI") (V4DI "DI")
259    (V16QI "QI") (V8HI "HI") (V4SI "SI") (V2DI "DI")
260    (V8SF "SF") (V4DF "DF")
261    (V4SF "SF") (V2DF "DF")])
262
263 ;; Number of scalar elements in each vector type
264 (define_mode_attr ssescalarnum
265   [(V32QI "32") (V16HI "16") (V8SI "8") (V4DI "4")
266    (V16QI "16") (V8HI "8") (V4SI "4") (V2DI "2")
267    (V8SF "8") (V4DF "4")
268    (V4SF "4") (V2DF "2")])
269
270 ;; SSE scalar suffix for vector modes
271 (define_mode_attr ssescalarmodesuffix
272   [(SF "ss") (DF "sd")
273    (V8SF "ss") (V4DF "sd")
274    (V4SF "ss") (V2DF "sd")
275    (V8SI "ss") (V4DI "sd")
276    (V4SI "d")])
277
278 ;; Pack/unpack vector modes
279 (define_mode_attr sseunpackmode
280   [(V16QI "V8HI") (V8HI "V4SI") (V4SI "V2DI")
281    (V32QI "V16HI") (V16HI "V8SI") (V8SI "V4DI")])
282
283 (define_mode_attr ssepackmode
284   [(V8HI "V16QI") (V4SI "V8HI") (V2DI "V4SI")
285    (V16HI "V32QI") (V8SI "V16HI") (V4DI "V8SI")])
286
287 ;; Mapping of the max integer size for xop rotate immediate constraint
288 (define_mode_attr sserotatemax
289   [(V16QI "7") (V8HI "15") (V4SI "31") (V2DI "63")])
290
291 ;; Mapping of mode to cast intrinsic name
292 (define_mode_attr castmode [(V8SI "si") (V8SF "ps") (V4DF "pd")])
293
294 ;; Instruction suffix for sign and zero extensions.
295 (define_code_attr extsuffix [(sign_extend "sx") (zero_extend "zx")])
296
297 ;; Mix-n-match
298 (define_mode_iterator AVX256MODE2P [V8SI V8SF V4DF])
299
300 (define_mode_iterator AVXMODE48P_DI
301                       [V2DI V2DF V4DI V4DF V4SF V4SI])
302 (define_mode_attr AVXMODE48P_DI
303                       [(V2DI "V2DI") (V2DF "V2DI")
304                        (V4DI "V4DI") (V4DF "V4DI")
305                        (V4SI "V2DI") (V4SF "V2DI")
306                        (V8SI "V4DI") (V8SF "V4DI")])
307 (define_mode_attr gthrfirstp
308                       [(V2DI "p") (V2DF "")
309                        (V4DI "p") (V4DF "")
310                        (V4SI "p") (V4SF "")
311                        (V8SI "p") (V8SF "")])
312 (define_mode_attr gthrlastp
313                       [(V2DI "q") (V2DF "pd")
314                        (V4DI "q") (V4DF "pd")
315                        (V4SI "d") (V4SF "ps")
316                        (V8SI "d") (V8SF "ps")])
317
318 (define_mode_iterator FMAMODE [SF DF V4SF V2DF V8SF V4DF])
319
320 ;; Mapping of immediate bits for blend instructions
321 (define_mode_attr blendbits
322   [(V8SF "255") (V4SF "15") (V4DF "15") (V2DF "3")])
323
324 ;; Patterns whose name begins with "sse{,2,3}_" are invoked by intrinsics.
325
326 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
327 ;;
328 ;; Move patterns
329 ;;
330 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
331
332 ;; All of these patterns are enabled for SSE1 as well as SSE2.
333 ;; This is essential for maintaining stable calling conventions.
334
335 (define_expand "mov<mode>"
336   [(set (match_operand:V16 0 "nonimmediate_operand" "")
337         (match_operand:V16 1 "nonimmediate_operand" ""))]
338   "TARGET_SSE"
339 {
340   ix86_expand_vector_move (<MODE>mode, operands);
341   DONE;
342 })
343
344 (define_insn "*mov<mode>_internal"
345   [(set (match_operand:V16 0 "nonimmediate_operand" "=x,x ,m")
346         (match_operand:V16 1 "nonimmediate_or_sse_const_operand"  "C ,xm,x"))]
347   "TARGET_SSE
348    && (register_operand (operands[0], <MODE>mode)
349        || register_operand (operands[1], <MODE>mode))"
350 {
351   switch (which_alternative)
352     {
353     case 0:
354       return standard_sse_constant_opcode (insn, operands[1]);
355     case 1:
356     case 2:
357       switch (get_attr_mode (insn))
358         {
359         case MODE_V8SF:
360         case MODE_V4SF:
361           if (TARGET_AVX
362               && (misaligned_operand (operands[0], <MODE>mode)
363                   || misaligned_operand (operands[1], <MODE>mode)))
364             return "vmovups\t{%1, %0|%0, %1}";
365           else
366             return "%vmovaps\t{%1, %0|%0, %1}";
367
368         case MODE_V4DF:
369         case MODE_V2DF:
370           if (TARGET_AVX
371               && (misaligned_operand (operands[0], <MODE>mode)
372                   || misaligned_operand (operands[1], <MODE>mode)))
373             return "vmovupd\t{%1, %0|%0, %1}";
374           else if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
375             return "%vmovaps\t{%1, %0|%0, %1}";
376           else
377             return "%vmovapd\t{%1, %0|%0, %1}";
378
379         case MODE_OI:
380         case MODE_TI:
381           if (TARGET_AVX
382               && (misaligned_operand (operands[0], <MODE>mode)
383                   || misaligned_operand (operands[1], <MODE>mode)))
384             return "vmovdqu\t{%1, %0|%0, %1}";
385           else if (TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL)
386             return "%vmovaps\t{%1, %0|%0, %1}";
387           else
388             return "%vmovdqa\t{%1, %0|%0, %1}";
389
390         default:
391           gcc_unreachable ();
392         }
393     default:
394       gcc_unreachable ();
395     }
396 }
397   [(set_attr "type" "sselog1,ssemov,ssemov")
398    (set_attr "prefix" "maybe_vex")
399    (set (attr "mode")
400         (cond [(match_test "TARGET_AVX")
401                  (const_string "<sseinsnmode>")
402                (ior (ior (match_test "optimize_function_for_size_p (cfun)")
403                          (not (match_test "TARGET_SSE2")))
404                     (and (eq_attr "alternative" "2")
405                          (match_test "TARGET_SSE_TYPELESS_STORES")))
406                  (const_string "V4SF")
407                (eq (const_string "<MODE>mode") (const_string "V4SFmode"))
408                  (const_string "V4SF")
409                (eq (const_string "<MODE>mode") (const_string "V2DFmode"))
410                  (const_string "V2DF")
411               ]
412           (const_string "TI")))])
413
414 (define_insn "sse2_movq128"
415   [(set (match_operand:V2DI 0 "register_operand" "=x")
416         (vec_concat:V2DI
417           (vec_select:DI
418             (match_operand:V2DI 1 "nonimmediate_operand" "xm")
419             (parallel [(const_int 0)]))
420           (const_int 0)))]
421   "TARGET_SSE2"
422   "%vmovq\t{%1, %0|%0, %1}"
423   [(set_attr "type" "ssemov")
424    (set_attr "prefix" "maybe_vex")
425    (set_attr "mode" "TI")])
426
427 ;; Move a DI from a 32-bit register pair (e.g. %edx:%eax) to an xmm.
428 ;; We'd rather avoid this entirely; if the 32-bit reg pair was loaded
429 ;; from memory, we'd prefer to load the memory directly into the %xmm
430 ;; register.  To facilitate this happy circumstance, this pattern won't
431 ;; split until after register allocation.  If the 64-bit value didn't
432 ;; come from memory, this is the best we can do.  This is much better
433 ;; than storing %edx:%eax into a stack temporary and loading an %xmm
434 ;; from there.
435
436 (define_insn_and_split "movdi_to_sse"
437   [(parallel
438     [(set (match_operand:V4SI 0 "register_operand" "=?x,x")
439           (subreg:V4SI (match_operand:DI 1 "nonimmediate_operand" "r,m") 0))
440      (clobber (match_scratch:V4SI 2 "=&x,X"))])]
441   "!TARGET_64BIT && TARGET_SSE2 && TARGET_INTER_UNIT_MOVES"
442   "#"
443   "&& reload_completed"
444   [(const_int 0)]
445 {
446  if (register_operand (operands[1], DImode))
447    {
448       /* The DImode arrived in a pair of integral registers (e.g. %edx:%eax).
449          Assemble the 64-bit DImode value in an xmm register.  */
450       emit_insn (gen_sse2_loadld (operands[0], CONST0_RTX (V4SImode),
451                                   gen_rtx_SUBREG (SImode, operands[1], 0)));
452       emit_insn (gen_sse2_loadld (operands[2], CONST0_RTX (V4SImode),
453                                   gen_rtx_SUBREG (SImode, operands[1], 4)));
454       emit_insn (gen_vec_interleave_lowv4si (operands[0], operands[0],
455                                              operands[2]));
456     }
457  else if (memory_operand (operands[1], DImode))
458    emit_insn (gen_vec_concatv2di (gen_lowpart (V2DImode, operands[0]),
459                                   operands[1], const0_rtx));
460  else
461    gcc_unreachable ();
462 })
463
464 (define_split
465   [(set (match_operand:V4SF 0 "register_operand" "")
466         (match_operand:V4SF 1 "zero_extended_scalar_load_operand" ""))]
467   "TARGET_SSE && reload_completed"
468   [(set (match_dup 0)
469         (vec_merge:V4SF
470           (vec_duplicate:V4SF (match_dup 1))
471           (match_dup 2)
472           (const_int 1)))]
473 {
474   operands[1] = simplify_gen_subreg (SFmode, operands[1], V4SFmode, 0);
475   operands[2] = CONST0_RTX (V4SFmode);
476 })
477
478 (define_split
479   [(set (match_operand:V2DF 0 "register_operand" "")
480         (match_operand:V2DF 1 "zero_extended_scalar_load_operand" ""))]
481   "TARGET_SSE2 && reload_completed"
482   [(set (match_dup 0) (vec_concat:V2DF (match_dup 1) (match_dup 2)))]
483 {
484   operands[1] = simplify_gen_subreg (DFmode, operands[1], V2DFmode, 0);
485   operands[2] = CONST0_RTX (DFmode);
486 })
487
488 (define_expand "push<mode>1"
489   [(match_operand:V16 0 "register_operand" "")]
490   "TARGET_SSE"
491 {
492   ix86_expand_push (<MODE>mode, operands[0]);
493   DONE;
494 })
495
496 (define_expand "movmisalign<mode>"
497   [(set (match_operand:V16 0 "nonimmediate_operand" "")
498         (match_operand:V16 1 "nonimmediate_operand" ""))]
499   "TARGET_SSE"
500 {
501   ix86_expand_vector_move_misalign (<MODE>mode, operands);
502   DONE;
503 })
504
505 (define_expand "<sse>_movu<ssemodesuffix><avxsizesuffix>"
506   [(set (match_operand:VF 0 "nonimmediate_operand" "")
507         (unspec:VF
508           [(match_operand:VF 1 "nonimmediate_operand" "")]
509           UNSPEC_MOVU))]
510   "TARGET_SSE"
511 {
512   if (MEM_P (operands[0]) && MEM_P (operands[1]))
513     operands[1] = force_reg (<MODE>mode, operands[1]);
514 })
515
516 (define_insn "*<sse>_movu<ssemodesuffix><avxsizesuffix>"
517   [(set (match_operand:VF 0 "nonimmediate_operand" "=x,m")
518         (unspec:VF
519           [(match_operand:VF 1 "nonimmediate_operand" "xm,x")]
520           UNSPEC_MOVU))]
521   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
522   "%vmovu<ssemodesuffix>\t{%1, %0|%0, %1}"
523   [(set_attr "type" "ssemov")
524    (set_attr "movu" "1")
525    (set_attr "prefix" "maybe_vex")
526    (set_attr "mode" "<MODE>")])
527
528 (define_expand "<sse2>_movdqu<avxsizesuffix>"
529   [(set (match_operand:VI1 0 "nonimmediate_operand" "")
530         (unspec:VI1 [(match_operand:VI1 1 "nonimmediate_operand" "")]
531                     UNSPEC_MOVU))]
532   "TARGET_SSE2"
533 {
534   if (MEM_P (operands[0]) && MEM_P (operands[1]))
535     operands[1] = force_reg (<MODE>mode, operands[1]);
536 })
537
538 (define_insn "*<sse2>_movdqu<avxsizesuffix>"
539   [(set (match_operand:VI1 0 "nonimmediate_operand" "=x,m")
540         (unspec:VI1 [(match_operand:VI1 1 "nonimmediate_operand" "xm,x")]
541                     UNSPEC_MOVU))]
542   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
543   "%vmovdqu\t{%1, %0|%0, %1}"
544   [(set_attr "type" "ssemov")
545    (set_attr "movu" "1")
546    (set (attr "prefix_data16")
547      (if_then_else
548        (match_test "TARGET_AVX")
549      (const_string "*")
550      (const_string "1")))
551    (set_attr "prefix" "maybe_vex")
552    (set_attr "mode" "<sseinsnmode>")])
553
554 (define_insn "<sse3>_lddqu<avxsizesuffix>"
555   [(set (match_operand:VI1 0 "register_operand" "=x")
556         (unspec:VI1 [(match_operand:VI1 1 "memory_operand" "m")]
557                     UNSPEC_LDDQU))]
558   "TARGET_SSE3"
559   "%vlddqu\t{%1, %0|%0, %1}"
560   [(set_attr "type" "ssemov")
561    (set_attr "movu" "1")
562    (set (attr "prefix_data16")
563      (if_then_else
564        (match_test "TARGET_AVX")
565      (const_string "*")
566      (const_string "0")))
567    (set (attr "prefix_rep")
568      (if_then_else
569        (match_test "TARGET_AVX")
570      (const_string "*")
571      (const_string "1")))
572    (set_attr "prefix" "maybe_vex")
573    (set_attr "mode" "<sseinsnmode>")])
574
575 (define_insn "sse2_movntsi"
576   [(set (match_operand:SI 0 "memory_operand" "=m")
577         (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
578                    UNSPEC_MOVNT))]
579   "TARGET_SSE2"
580   "movnti\t{%1, %0|%0, %1}"
581   [(set_attr "type" "ssemov")
582    (set_attr "prefix_data16" "0")
583    (set_attr "mode" "V2DF")])
584
585 (define_insn "<sse>_movnt<mode>"
586   [(set (match_operand:VF 0 "memory_operand" "=m")
587         (unspec:VF [(match_operand:VF 1 "register_operand" "x")]
588                    UNSPEC_MOVNT))]
589   "TARGET_SSE"
590   "%vmovnt<ssemodesuffix>\t{%1, %0|%0, %1}"
591   [(set_attr "type" "ssemov")
592    (set_attr "prefix" "maybe_vex")
593    (set_attr "mode" "<MODE>")])
594
595 (define_insn "<sse2>_movnt<mode>"
596   [(set (match_operand:VI8 0 "memory_operand" "=m")
597         (unspec:VI8 [(match_operand:VI8 1 "register_operand" "x")]
598                     UNSPEC_MOVNT))]
599   "TARGET_SSE2"
600   "%vmovntdq\t{%1, %0|%0, %1}"
601   [(set_attr "type" "ssecvt")
602    (set (attr "prefix_data16")
603      (if_then_else
604        (match_test "TARGET_AVX")
605      (const_string "*")
606      (const_string "1")))
607    (set_attr "prefix" "maybe_vex")
608    (set_attr "mode" "<sseinsnmode>")])
609
610 ; Expand patterns for non-temporal stores.  At the moment, only those
611 ; that directly map to insns are defined; it would be possible to
612 ; define patterns for other modes that would expand to several insns.
613
614 ;; Modes handled by storent patterns.
615 (define_mode_iterator STORENT_MODE
616   [(SI "TARGET_SSE2") (SF "TARGET_SSE4A") (DF "TARGET_SSE4A")
617    (V2DI "TARGET_SSE2")
618    (V8SF "TARGET_AVX") V4SF
619    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
620
621 (define_expand "storent<mode>"
622   [(set (match_operand:STORENT_MODE 0 "memory_operand" "")
623         (unspec:STORENT_MODE
624           [(match_operand:STORENT_MODE 1 "register_operand" "")]
625           UNSPEC_MOVNT))]
626   "TARGET_SSE")
627
628 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
629 ;;
630 ;; Parallel floating point arithmetic
631 ;;
632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
633
634 (define_expand "<code><mode>2"
635   [(set (match_operand:VF 0 "register_operand" "")
636         (absneg:VF
637           (match_operand:VF 1 "register_operand" "")))]
638   "TARGET_SSE"
639   "ix86_expand_fp_absneg_operator (<CODE>, <MODE>mode, operands); DONE;")
640
641 (define_insn_and_split "*absneg<mode>2"
642   [(set (match_operand:VF 0 "register_operand" "=x,x,x,x")
643         (match_operator:VF 3 "absneg_operator"
644           [(match_operand:VF 1 "nonimmediate_operand" "0, xm,x, m")]))
645    (use (match_operand:VF 2 "nonimmediate_operand"    "xm,0, xm,x"))]
646   "TARGET_SSE"
647   "#"
648   "&& reload_completed"
649   [(const_int 0)]
650 {
651   enum rtx_code absneg_op;
652   rtx op1, op2;
653   rtx t;
654
655   if (TARGET_AVX)
656     {
657       if (MEM_P (operands[1]))
658         op1 = operands[2], op2 = operands[1];
659       else
660         op1 = operands[1], op2 = operands[2];
661     }
662   else
663     {
664       op1 = operands[0];
665       if (rtx_equal_p (operands[0], operands[1]))
666         op2 = operands[2];
667       else
668         op2 = operands[1];
669     }
670
671   absneg_op = GET_CODE (operands[3]) == NEG ? XOR : AND;
672   t = gen_rtx_fmt_ee (absneg_op, <MODE>mode, op1, op2);
673   t = gen_rtx_SET (VOIDmode, operands[0], t);
674   emit_insn (t);
675   DONE;
676 }
677   [(set_attr "isa" "noavx,noavx,avx,avx")])
678
679 (define_expand "<plusminus_insn><mode>3"
680   [(set (match_operand:VF 0 "register_operand" "")
681         (plusminus:VF
682           (match_operand:VF 1 "nonimmediate_operand" "")
683           (match_operand:VF 2 "nonimmediate_operand" "")))]
684   "TARGET_SSE"
685   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
686
687 (define_insn "*<plusminus_insn><mode>3"
688   [(set (match_operand:VF 0 "register_operand" "=x,x")
689         (plusminus:VF
690           (match_operand:VF 1 "nonimmediate_operand" "<comm>0,x")
691           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
692   "TARGET_SSE && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
693   "@
694    <plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
695    v<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
696   [(set_attr "isa" "noavx,avx")
697    (set_attr "type" "sseadd")
698    (set_attr "prefix" "orig,vex")
699    (set_attr "mode" "<MODE>")])
700
701 (define_insn "<sse>_vm<plusminus_insn><mode>3"
702   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
703         (vec_merge:VF_128
704           (plusminus:VF_128
705             (match_operand:VF_128 1 "register_operand" "0,x")
706             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
707           (match_dup 1)
708           (const_int 1)))]
709   "TARGET_SSE"
710   "@
711    <plusminus_mnemonic><ssescalarmodesuffix>\t{%2, %0|%0, %2}
712    v<plusminus_mnemonic><ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
713   [(set_attr "isa" "noavx,avx")
714    (set_attr "type" "sseadd")
715    (set_attr "prefix" "orig,vex")
716    (set_attr "mode" "<ssescalarmode>")])
717
718 (define_expand "mul<mode>3"
719   [(set (match_operand:VF 0 "register_operand" "")
720         (mult:VF
721           (match_operand:VF 1 "nonimmediate_operand" "")
722           (match_operand:VF 2 "nonimmediate_operand" "")))]
723   "TARGET_SSE"
724   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
725
726 (define_insn "*mul<mode>3"
727   [(set (match_operand:VF 0 "register_operand" "=x,x")
728         (mult:VF
729           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
730           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
731   "TARGET_SSE && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
732   "@
733    mul<ssemodesuffix>\t{%2, %0|%0, %2}
734    vmul<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
735   [(set_attr "isa" "noavx,avx")
736    (set_attr "type" "ssemul")
737    (set_attr "prefix" "orig,vex")
738    (set_attr "mode" "<MODE>")])
739
740 (define_insn "<sse>_vmmul<mode>3"
741   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
742         (vec_merge:VF_128
743           (mult:VF_128
744             (match_operand:VF_128 1 "register_operand" "0,x")
745             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
746           (match_dup 1)
747           (const_int 1)))]
748   "TARGET_SSE"
749   "@
750    mul<ssescalarmodesuffix>\t{%2, %0|%0, %2}
751    vmul<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
752   [(set_attr "isa" "noavx,avx")
753    (set_attr "type" "ssemul")
754    (set_attr "prefix" "orig,vex")
755    (set_attr "mode" "<ssescalarmode>")])
756
757 (define_expand "div<mode>3"
758   [(set (match_operand:VF2 0 "register_operand" "")
759         (div:VF2 (match_operand:VF2 1 "register_operand" "")
760                  (match_operand:VF2 2 "nonimmediate_operand" "")))]
761   "TARGET_SSE2"
762   "ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);")
763
764 (define_expand "div<mode>3"
765   [(set (match_operand:VF1 0 "register_operand" "")
766         (div:VF1 (match_operand:VF1 1 "register_operand" "")
767                  (match_operand:VF1 2 "nonimmediate_operand" "")))]
768   "TARGET_SSE"
769 {
770   ix86_fixup_binary_operands_no_copy (DIV, <MODE>mode, operands);
771
772   if (TARGET_SSE_MATH && TARGET_RECIP && !optimize_insn_for_size_p ()
773       && flag_finite_math_only && !flag_trapping_math
774       && flag_unsafe_math_optimizations)
775     {
776       ix86_emit_swdivsf (operands[0], operands[1], operands[2], <MODE>mode);
777       DONE;
778     }
779 })
780
781 (define_insn "<sse>_div<mode>3"
782   [(set (match_operand:VF 0 "register_operand" "=x,x")
783         (div:VF
784           (match_operand:VF 1 "register_operand" "0,x")
785           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
786   "TARGET_SSE"
787   "@
788    div<ssemodesuffix>\t{%2, %0|%0, %2}
789    vdiv<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
790   [(set_attr "isa" "noavx,avx")
791    (set_attr "type" "ssediv")
792    (set_attr "prefix" "orig,vex")
793    (set_attr "mode" "<MODE>")])
794
795 (define_insn "<sse>_vmdiv<mode>3"
796   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
797         (vec_merge:VF_128
798           (div:VF_128
799             (match_operand:VF_128 1 "register_operand" "0,x")
800             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
801           (match_dup 1)
802           (const_int 1)))]
803   "TARGET_SSE"
804   "@
805    div<ssescalarmodesuffix>\t{%2, %0|%0, %2}
806    vdiv<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
807   [(set_attr "isa" "noavx,avx")
808    (set_attr "type" "ssediv")
809    (set_attr "prefix" "orig,vex")
810    (set_attr "mode" "<ssescalarmode>")])
811
812 (define_insn "<sse>_rcp<mode>2"
813   [(set (match_operand:VF1 0 "register_operand" "=x")
814         (unspec:VF1
815           [(match_operand:VF1 1 "nonimmediate_operand" "xm")] UNSPEC_RCP))]
816   "TARGET_SSE"
817   "%vrcpps\t{%1, %0|%0, %1}"
818   [(set_attr "type" "sse")
819    (set_attr "atom_sse_attr" "rcp")
820    (set_attr "prefix" "maybe_vex")
821    (set_attr "mode" "<MODE>")])
822
823 (define_insn "sse_vmrcpv4sf2"
824   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
825         (vec_merge:V4SF
826           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
827                        UNSPEC_RCP)
828           (match_operand:V4SF 2 "register_operand" "0,x")
829           (const_int 1)))]
830   "TARGET_SSE"
831   "@
832    rcpss\t{%1, %0|%0, %1}
833    vrcpss\t{%1, %2, %0|%0, %2, %1}"
834   [(set_attr "isa" "noavx,avx")
835    (set_attr "type" "sse")
836    (set_attr "atom_sse_attr" "rcp")
837    (set_attr "prefix" "orig,vex")
838    (set_attr "mode" "SF")])
839
840 (define_expand "sqrt<mode>2"
841   [(set (match_operand:VF2 0 "register_operand" "")
842         (sqrt:VF2 (match_operand:VF2 1 "nonimmediate_operand" "")))]
843   "TARGET_SSE2")
844
845 (define_expand "sqrt<mode>2"
846   [(set (match_operand:VF1 0 "register_operand" "")
847         (sqrt:VF1 (match_operand:VF1 1 "nonimmediate_operand" "")))]
848   "TARGET_SSE"
849 {
850   if (TARGET_SSE_MATH && TARGET_RECIP && !optimize_insn_for_size_p ()
851       && flag_finite_math_only && !flag_trapping_math
852       && flag_unsafe_math_optimizations)
853     {
854       ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, false);
855       DONE;
856     }
857 })
858
859 (define_insn "<sse>_sqrt<mode>2"
860   [(set (match_operand:VF 0 "register_operand" "=x")
861         (sqrt:VF (match_operand:VF 1 "nonimmediate_operand" "xm")))]
862   "TARGET_SSE"
863   "%vsqrt<ssemodesuffix>\t{%1, %0|%0, %1}"
864   [(set_attr "type" "sse")
865    (set_attr "atom_sse_attr" "sqrt")
866    (set_attr "prefix" "maybe_vex")
867    (set_attr "mode" "<MODE>")])
868
869 (define_insn "<sse>_vmsqrt<mode>2"
870   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
871         (vec_merge:VF_128
872           (sqrt:VF_128
873             (match_operand:VF_128 1 "nonimmediate_operand" "xm,xm"))
874           (match_operand:VF_128 2 "register_operand" "0,x")
875           (const_int 1)))]
876   "TARGET_SSE"
877   "@
878    sqrt<ssescalarmodesuffix>\t{%1, %0|%0, %1}
879    vsqrt<ssescalarmodesuffix>\t{%1, %2, %0|%0, %2, %1}"
880   [(set_attr "isa" "noavx,avx")
881    (set_attr "type" "sse")
882    (set_attr "atom_sse_attr" "sqrt")
883    (set_attr "prefix" "orig,vex")
884    (set_attr "mode" "<ssescalarmode>")])
885
886 (define_expand "rsqrt<mode>2"
887   [(set (match_operand:VF1 0 "register_operand" "")
888         (unspec:VF1
889           [(match_operand:VF1 1 "nonimmediate_operand" "")] UNSPEC_RSQRT))]
890   "TARGET_SSE_MATH"
891 {
892   ix86_emit_swsqrtsf (operands[0], operands[1], <MODE>mode, true);
893   DONE;
894 })
895
896 (define_insn "<sse>_rsqrt<mode>2"
897   [(set (match_operand:VF1 0 "register_operand" "=x")
898         (unspec:VF1
899           [(match_operand:VF1 1 "nonimmediate_operand" "xm")] UNSPEC_RSQRT))]
900   "TARGET_SSE"
901   "%vrsqrtps\t{%1, %0|%0, %1}"
902   [(set_attr "type" "sse")
903    (set_attr "prefix" "maybe_vex")
904    (set_attr "mode" "<MODE>")])
905
906 (define_insn "sse_vmrsqrtv4sf2"
907   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
908         (vec_merge:V4SF
909           (unspec:V4SF [(match_operand:V4SF 1 "nonimmediate_operand" "xm,xm")]
910                        UNSPEC_RSQRT)
911           (match_operand:V4SF 2 "register_operand" "0,x")
912           (const_int 1)))]
913   "TARGET_SSE"
914   "@
915    rsqrtss\t{%1, %0|%0, %1}
916    vrsqrtss\t{%1, %2, %0|%0, %2, %1}"
917   [(set_attr "isa" "noavx,avx")
918    (set_attr "type" "sse")
919    (set_attr "prefix" "orig,vex")
920    (set_attr "mode" "SF")])
921
922 ;; ??? For !flag_finite_math_only, the representation with SMIN/SMAX
923 ;; isn't really correct, as those rtl operators aren't defined when
924 ;; applied to NaNs.  Hopefully the optimizers won't get too smart on us.
925
926 (define_expand "<code><mode>3"
927   [(set (match_operand:VF 0 "register_operand" "")
928         (smaxmin:VF
929           (match_operand:VF 1 "nonimmediate_operand" "")
930           (match_operand:VF 2 "nonimmediate_operand" "")))]
931   "TARGET_SSE"
932 {
933   if (!flag_finite_math_only)
934     operands[1] = force_reg (<MODE>mode, operands[1]);
935   ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
936 })
937
938 (define_insn "*<code><mode>3_finite"
939   [(set (match_operand:VF 0 "register_operand" "=x,x")
940         (smaxmin:VF
941           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
942           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
943   "TARGET_SSE && flag_finite_math_only
944    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
945   "@
946    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
947    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
948   [(set_attr "isa" "noavx,avx")
949    (set_attr "type" "sseadd")
950    (set_attr "prefix" "orig,vex")
951    (set_attr "mode" "<MODE>")])
952
953 (define_insn "*<code><mode>3"
954   [(set (match_operand:VF 0 "register_operand" "=x,x")
955         (smaxmin:VF
956           (match_operand:VF 1 "register_operand" "0,x")
957           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
958   "TARGET_SSE && !flag_finite_math_only"
959   "@
960    <maxmin_float><ssemodesuffix>\t{%2, %0|%0, %2}
961    v<maxmin_float><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
962   [(set_attr "isa" "noavx,avx")
963    (set_attr "type" "sseadd")
964    (set_attr "prefix" "orig,vex")
965    (set_attr "mode" "<MODE>")])
966
967 (define_insn "<sse>_vm<code><mode>3"
968   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
969         (vec_merge:VF_128
970           (smaxmin:VF_128
971             (match_operand:VF_128 1 "register_operand" "0,x")
972             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm"))
973          (match_dup 1)
974          (const_int 1)))]
975   "TARGET_SSE"
976   "@
977    <maxmin_float><ssescalarmodesuffix>\t{%2, %0|%0, %2}
978    v<maxmin_float><ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
979   [(set_attr "isa" "noavx,avx")
980    (set_attr "type" "sse")
981    (set_attr "prefix" "orig,vex")
982    (set_attr "mode" "<ssescalarmode>")])
983
984 ;; These versions of the min/max patterns implement exactly the operations
985 ;;   min = (op1 < op2 ? op1 : op2)
986 ;;   max = (!(op1 < op2) ? op1 : op2)
987 ;; Their operands are not commutative, and thus they may be used in the
988 ;; presence of -0.0 and NaN.
989
990 (define_insn "*ieee_smin<mode>3"
991   [(set (match_operand:VF 0 "register_operand" "=x,x")
992         (unspec:VF
993           [(match_operand:VF 1 "register_operand" "0,x")
994            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]
995          UNSPEC_IEEE_MIN))]
996   "TARGET_SSE"
997   "@
998    min<ssemodesuffix>\t{%2, %0|%0, %2}
999    vmin<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1000   [(set_attr "isa" "noavx,avx")
1001    (set_attr "type" "sseadd")
1002    (set_attr "prefix" "orig,vex")
1003    (set_attr "mode" "<MODE>")])
1004
1005 (define_insn "*ieee_smax<mode>3"
1006   [(set (match_operand:VF 0 "register_operand" "=x,x")
1007         (unspec:VF
1008           [(match_operand:VF 1 "register_operand" "0,x")
1009            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]
1010          UNSPEC_IEEE_MAX))]
1011   "TARGET_SSE"
1012   "@
1013    max<ssemodesuffix>\t{%2, %0|%0, %2}
1014    vmax<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1015   [(set_attr "isa" "noavx,avx")
1016    (set_attr "type" "sseadd")
1017    (set_attr "prefix" "orig,vex")
1018    (set_attr "mode" "<MODE>")])
1019
1020 (define_insn "avx_addsubv4df3"
1021   [(set (match_operand:V4DF 0 "register_operand" "=x")
1022         (vec_merge:V4DF
1023           (plus:V4DF
1024             (match_operand:V4DF 1 "register_operand" "x")
1025             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
1026           (minus:V4DF (match_dup 1) (match_dup 2))
1027           (const_int 10)))]
1028   "TARGET_AVX"
1029   "vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
1030   [(set_attr "type" "sseadd")
1031    (set_attr "prefix" "vex")
1032    (set_attr "mode" "V4DF")])
1033
1034 (define_insn "sse3_addsubv2df3"
1035   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1036         (vec_merge:V2DF
1037           (plus:V2DF
1038             (match_operand:V2DF 1 "register_operand" "0,x")
1039             (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm"))
1040           (minus:V2DF (match_dup 1) (match_dup 2))
1041           (const_int 2)))]
1042   "TARGET_SSE3"
1043   "@
1044    addsubpd\t{%2, %0|%0, %2}
1045    vaddsubpd\t{%2, %1, %0|%0, %1, %2}"
1046   [(set_attr "isa" "noavx,avx")
1047    (set_attr "type" "sseadd")
1048    (set_attr "atom_unit" "complex")
1049    (set_attr "prefix" "orig,vex")
1050    (set_attr "mode" "V2DF")])
1051
1052 (define_insn "avx_addsubv8sf3"
1053   [(set (match_operand:V8SF 0 "register_operand" "=x")
1054         (vec_merge:V8SF
1055           (plus:V8SF
1056             (match_operand:V8SF 1 "register_operand" "x")
1057             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
1058           (minus:V8SF (match_dup 1) (match_dup 2))
1059           (const_int 170)))]
1060   "TARGET_AVX"
1061   "vaddsubps\t{%2, %1, %0|%0, %1, %2}"
1062   [(set_attr "type" "sseadd")
1063    (set_attr "prefix" "vex")
1064    (set_attr "mode" "V8SF")])
1065
1066 (define_insn "sse3_addsubv4sf3"
1067   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1068         (vec_merge:V4SF
1069           (plus:V4SF
1070             (match_operand:V4SF 1 "register_operand" "0,x")
1071             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
1072           (minus:V4SF (match_dup 1) (match_dup 2))
1073           (const_int 10)))]
1074   "TARGET_SSE3"
1075   "@
1076    addsubps\t{%2, %0|%0, %2}
1077    vaddsubps\t{%2, %1, %0|%0, %1, %2}"
1078   [(set_attr "isa" "noavx,avx")
1079    (set_attr "type" "sseadd")
1080    (set_attr "prefix" "orig,vex")
1081    (set_attr "prefix_rep" "1,*")
1082    (set_attr "mode" "V4SF")])
1083
1084 (define_insn "avx_h<plusminus_insn>v4df3"
1085   [(set (match_operand:V4DF 0 "register_operand" "=x")
1086         (vec_concat:V4DF
1087           (vec_concat:V2DF
1088             (plusminus:DF
1089               (vec_select:DF
1090                 (match_operand:V4DF 1 "register_operand" "x")
1091                 (parallel [(const_int 0)]))
1092               (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1093             (plusminus:DF
1094               (vec_select:DF (match_dup 1) (parallel [(const_int 2)]))
1095               (vec_select:DF (match_dup 1) (parallel [(const_int 3)]))))
1096           (vec_concat:V2DF
1097             (plusminus:DF
1098               (vec_select:DF
1099                 (match_operand:V4DF 2 "nonimmediate_operand" "xm")
1100                 (parallel [(const_int 0)]))
1101               (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))
1102             (plusminus:DF
1103               (vec_select:DF (match_dup 2) (parallel [(const_int 2)]))
1104               (vec_select:DF (match_dup 2) (parallel [(const_int 3)]))))))]
1105   "TARGET_AVX"
1106   "vh<plusminus_mnemonic>pd\t{%2, %1, %0|%0, %1, %2}"
1107   [(set_attr "type" "sseadd")
1108    (set_attr "prefix" "vex")
1109    (set_attr "mode" "V4DF")])
1110
1111 (define_insn "sse3_h<plusminus_insn>v2df3"
1112   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
1113         (vec_concat:V2DF
1114           (plusminus:DF
1115             (vec_select:DF
1116               (match_operand:V2DF 1 "register_operand" "0,x")
1117               (parallel [(const_int 0)]))
1118             (vec_select:DF (match_dup 1) (parallel [(const_int 1)])))
1119           (plusminus:DF
1120             (vec_select:DF
1121               (match_operand:V2DF 2 "nonimmediate_operand" "xm,xm")
1122               (parallel [(const_int 0)]))
1123             (vec_select:DF (match_dup 2) (parallel [(const_int 1)])))))]
1124   "TARGET_SSE3"
1125   "@
1126    h<plusminus_mnemonic>pd\t{%2, %0|%0, %2}
1127    vh<plusminus_mnemonic>pd\t{%2, %1, %0|%0, %1, %2}"
1128   [(set_attr "isa" "noavx,avx")
1129    (set_attr "type" "sseadd")
1130    (set_attr "prefix" "orig,vex")
1131    (set_attr "mode" "V2DF")])
1132
1133 (define_insn "avx_h<plusminus_insn>v8sf3"
1134   [(set (match_operand:V8SF 0 "register_operand" "=x")
1135         (vec_concat:V8SF
1136           (vec_concat:V4SF
1137             (vec_concat:V2SF
1138               (plusminus:SF
1139                 (vec_select:SF
1140                   (match_operand:V8SF 1 "register_operand" "x")
1141                   (parallel [(const_int 0)]))
1142                 (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
1143               (plusminus:SF
1144                 (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
1145                 (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
1146             (vec_concat:V2SF
1147               (plusminus:SF
1148                 (vec_select:SF
1149                   (match_operand:V8SF 2 "nonimmediate_operand" "xm")
1150                   (parallel [(const_int 0)]))
1151                 (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
1152               (plusminus:SF
1153                 (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
1154                 (vec_select:SF (match_dup 2) (parallel [(const_int 3)])))))
1155           (vec_concat:V4SF
1156             (vec_concat:V2SF
1157               (plusminus:SF
1158                 (vec_select:SF (match_dup 1) (parallel [(const_int 4)]))
1159                 (vec_select:SF (match_dup 1) (parallel [(const_int 5)])))
1160               (plusminus:SF
1161                 (vec_select:SF (match_dup 1) (parallel [(const_int 6)]))
1162                 (vec_select:SF (match_dup 1) (parallel [(const_int 7)]))))
1163             (vec_concat:V2SF
1164               (plusminus:SF
1165                 (vec_select:SF (match_dup 2) (parallel [(const_int 4)]))
1166                 (vec_select:SF (match_dup 2) (parallel [(const_int 5)])))
1167               (plusminus:SF
1168                 (vec_select:SF (match_dup 2) (parallel [(const_int 6)]))
1169                 (vec_select:SF (match_dup 2) (parallel [(const_int 7)])))))))]
1170   "TARGET_AVX"
1171   "vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
1172   [(set_attr "type" "sseadd")
1173    (set_attr "prefix" "vex")
1174    (set_attr "mode" "V8SF")])
1175
1176 (define_insn "sse3_h<plusminus_insn>v4sf3"
1177   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
1178         (vec_concat:V4SF
1179           (vec_concat:V2SF
1180             (plusminus:SF
1181               (vec_select:SF
1182                 (match_operand:V4SF 1 "register_operand" "0,x")
1183                 (parallel [(const_int 0)]))
1184               (vec_select:SF (match_dup 1) (parallel [(const_int 1)])))
1185             (plusminus:SF
1186               (vec_select:SF (match_dup 1) (parallel [(const_int 2)]))
1187               (vec_select:SF (match_dup 1) (parallel [(const_int 3)]))))
1188           (vec_concat:V2SF
1189             (plusminus:SF
1190               (vec_select:SF
1191                 (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm")
1192                 (parallel [(const_int 0)]))
1193               (vec_select:SF (match_dup 2) (parallel [(const_int 1)])))
1194             (plusminus:SF
1195               (vec_select:SF (match_dup 2) (parallel [(const_int 2)]))
1196               (vec_select:SF (match_dup 2) (parallel [(const_int 3)]))))))]
1197   "TARGET_SSE3"
1198   "@
1199    h<plusminus_mnemonic>ps\t{%2, %0|%0, %2}
1200    vh<plusminus_mnemonic>ps\t{%2, %1, %0|%0, %1, %2}"
1201   [(set_attr "isa" "noavx,avx")
1202    (set_attr "type" "sseadd")
1203    (set_attr "atom_unit" "complex")
1204    (set_attr "prefix" "orig,vex")
1205    (set_attr "prefix_rep" "1,*")
1206    (set_attr "mode" "V4SF")])
1207
1208 (define_expand "reduc_splus_v4df"
1209   [(match_operand:V4DF 0 "register_operand" "")
1210    (match_operand:V4DF 1 "register_operand" "")]
1211   "TARGET_AVX"
1212 {
1213   rtx tmp = gen_reg_rtx (V4DFmode);
1214   rtx tmp2 = gen_reg_rtx (V4DFmode);
1215   emit_insn (gen_avx_haddv4df3 (tmp, operands[1], operands[1]));
1216   emit_insn (gen_avx_vperm2f128v4df3 (tmp2, tmp, tmp, GEN_INT (1)));
1217   emit_insn (gen_addv4df3 (operands[0], tmp, tmp2));
1218   DONE;
1219 })
1220
1221 (define_expand "reduc_splus_v2df"
1222   [(match_operand:V2DF 0 "register_operand" "")
1223    (match_operand:V2DF 1 "register_operand" "")]
1224   "TARGET_SSE3"
1225 {
1226   emit_insn (gen_sse3_haddv2df3 (operands[0], operands[1], operands[1]));
1227   DONE;
1228 })
1229
1230 (define_expand "reduc_splus_v8sf"
1231   [(match_operand:V8SF 0 "register_operand" "")
1232    (match_operand:V8SF 1 "register_operand" "")]
1233   "TARGET_AVX"
1234 {
1235   rtx tmp = gen_reg_rtx (V8SFmode);
1236   rtx tmp2 = gen_reg_rtx (V8SFmode);
1237   emit_insn (gen_avx_haddv8sf3 (tmp, operands[1], operands[1]));
1238   emit_insn (gen_avx_haddv8sf3 (tmp2, tmp, tmp));
1239   emit_insn (gen_avx_vperm2f128v8sf3 (tmp, tmp2, tmp2, GEN_INT (1)));
1240   emit_insn (gen_addv8sf3 (operands[0], tmp, tmp2));
1241   DONE;
1242 })
1243
1244 (define_expand "reduc_splus_v4sf"
1245   [(match_operand:V4SF 0 "register_operand" "")
1246    (match_operand:V4SF 1 "register_operand" "")]
1247   "TARGET_SSE"
1248 {
1249   if (TARGET_SSE3)
1250     {
1251       rtx tmp = gen_reg_rtx (V4SFmode);
1252       emit_insn (gen_sse3_haddv4sf3 (tmp, operands[1], operands[1]));
1253       emit_insn (gen_sse3_haddv4sf3 (operands[0], tmp, tmp));
1254     }
1255   else
1256     ix86_expand_reduc (gen_addv4sf3, operands[0], operands[1]);
1257   DONE;
1258 })
1259
1260
1261 (define_expand "reduc_smax_v4sf"
1262   [(match_operand:V4SF 0 "register_operand" "")
1263    (match_operand:V4SF 1 "register_operand" "")]
1264   "TARGET_SSE"
1265 {
1266   ix86_expand_reduc (gen_smaxv4sf3, operands[0], operands[1]);
1267   DONE;
1268 })
1269
1270 (define_expand "reduc_smin_v4sf"
1271   [(match_operand:V4SF 0 "register_operand" "")
1272    (match_operand:V4SF 1 "register_operand" "")]
1273   "TARGET_SSE"
1274 {
1275   ix86_expand_reduc (gen_sminv4sf3, operands[0], operands[1]);
1276   DONE;
1277 })
1278
1279 (define_expand "reduc_smax_v8sf"
1280   [(match_operand:V8SF 0 "register_operand" "")
1281    (match_operand:V8SF 1 "register_operand" "")]
1282   "TARGET_AVX"
1283 {
1284   ix86_expand_reduc (gen_smaxv8sf3, operands[0], operands[1]);
1285   DONE;
1286 })
1287
1288 (define_expand "reduc_smin_v8sf"
1289   [(match_operand:V8SF 0 "register_operand" "")
1290    (match_operand:V8SF 1 "register_operand" "")]
1291   "TARGET_AVX"
1292 {
1293   ix86_expand_reduc (gen_sminv8sf3, operands[0], operands[1]);
1294   DONE;
1295 })
1296
1297 (define_expand "reduc_smax_v4df"
1298   [(match_operand:V4DF 0 "register_operand" "")
1299    (match_operand:V4DF 1 "register_operand" "")]
1300   "TARGET_AVX"
1301 {
1302   ix86_expand_reduc (gen_smaxv4df3, operands[0], operands[1]);
1303   DONE;
1304 })
1305
1306 (define_expand "reduc_smin_v4df"
1307   [(match_operand:V4DF 0 "register_operand" "")
1308    (match_operand:V4DF 1 "register_operand" "")]
1309   "TARGET_AVX"
1310 {
1311   ix86_expand_reduc (gen_sminv4df3, operands[0], operands[1]);
1312   DONE;
1313 })
1314
1315 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1316 ;;
1317 ;; Parallel floating point comparisons
1318 ;;
1319 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1320
1321 (define_insn "avx_cmp<mode>3"
1322   [(set (match_operand:VF 0 "register_operand" "=x")
1323         (unspec:VF
1324           [(match_operand:VF 1 "register_operand" "x")
1325            (match_operand:VF 2 "nonimmediate_operand" "xm")
1326            (match_operand:SI 3 "const_0_to_31_operand" "n")]
1327           UNSPEC_PCMP))]
1328   "TARGET_AVX"
1329   "vcmp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1330   [(set_attr "type" "ssecmp")
1331    (set_attr "length_immediate" "1")
1332    (set_attr "prefix" "vex")
1333    (set_attr "mode" "<MODE>")])
1334
1335 (define_insn "avx_vmcmp<mode>3"
1336   [(set (match_operand:VF_128 0 "register_operand" "=x")
1337         (vec_merge:VF_128
1338           (unspec:VF_128
1339             [(match_operand:VF_128 1 "register_operand" "x")
1340              (match_operand:VF_128 2 "nonimmediate_operand" "xm")
1341              (match_operand:SI 3 "const_0_to_31_operand" "n")]
1342             UNSPEC_PCMP)
1343          (match_dup 1)
1344          (const_int 1)))]
1345   "TARGET_AVX"
1346   "vcmp<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1347   [(set_attr "type" "ssecmp")
1348    (set_attr "length_immediate" "1")
1349    (set_attr "prefix" "vex")
1350    (set_attr "mode" "<ssescalarmode>")])
1351
1352 (define_insn "*<sse>_maskcmp<mode>3_comm"
1353   [(set (match_operand:VF 0 "register_operand" "=x,x")
1354         (match_operator:VF 3 "sse_comparison_operator"
1355           [(match_operand:VF 1 "register_operand" "%0,x")
1356            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]))]
1357   "TARGET_SSE
1358    && GET_RTX_CLASS (GET_CODE (operands[3])) == RTX_COMM_COMPARE"
1359   "@
1360    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
1361    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1362   [(set_attr "isa" "noavx,avx")
1363    (set_attr "type" "ssecmp")
1364    (set_attr "length_immediate" "1")
1365    (set_attr "prefix" "orig,vex")
1366    (set_attr "mode" "<MODE>")])
1367
1368 (define_insn "<sse>_maskcmp<mode>3"
1369   [(set (match_operand:VF 0 "register_operand" "=x,x")
1370         (match_operator:VF 3 "sse_comparison_operator"
1371           [(match_operand:VF 1 "register_operand" "0,x")
1372            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")]))]
1373   "TARGET_SSE"
1374   "@
1375    cmp%D3<ssemodesuffix>\t{%2, %0|%0, %2}
1376    vcmp%D3<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1377   [(set_attr "isa" "noavx,avx")
1378    (set_attr "type" "ssecmp")
1379    (set_attr "length_immediate" "1")
1380    (set_attr "prefix" "orig,vex")
1381    (set_attr "mode" "<MODE>")])
1382
1383 (define_insn "<sse>_vmmaskcmp<mode>3"
1384   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1385         (vec_merge:VF_128
1386          (match_operator:VF_128 3 "sse_comparison_operator"
1387            [(match_operand:VF_128 1 "register_operand" "0,x")
1388             (match_operand:VF_128 2 "nonimmediate_operand" "xm,xm")])
1389          (match_dup 1)
1390          (const_int 1)))]
1391   "TARGET_SSE"
1392   "@
1393    cmp%D3<ssescalarmodesuffix>\t{%2, %0|%0, %2}
1394    vcmp%D3<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1395   [(set_attr "isa" "noavx,avx")
1396    (set_attr "type" "ssecmp")
1397    (set_attr "length_immediate" "1,*")
1398    (set_attr "prefix" "orig,vex")
1399    (set_attr "mode" "<ssescalarmode>")])
1400
1401 (define_insn "<sse>_comi"
1402   [(set (reg:CCFP FLAGS_REG)
1403         (compare:CCFP
1404           (vec_select:MODEF
1405             (match_operand:<ssevecmode> 0 "register_operand" "x")
1406             (parallel [(const_int 0)]))
1407           (vec_select:MODEF
1408             (match_operand:<ssevecmode> 1 "nonimmediate_operand" "xm")
1409             (parallel [(const_int 0)]))))]
1410   "SSE_FLOAT_MODE_P (<MODE>mode)"
1411   "%vcomi<ssemodesuffix>\t{%1, %0|%0, %1}"
1412   [(set_attr "type" "ssecomi")
1413    (set_attr "prefix" "maybe_vex")
1414    (set_attr "prefix_rep" "0")
1415    (set (attr "prefix_data16")
1416         (if_then_else (eq_attr "mode" "DF")
1417                       (const_string "1")
1418                       (const_string "0")))
1419    (set_attr "mode" "<MODE>")])
1420
1421 (define_insn "<sse>_ucomi"
1422   [(set (reg:CCFPU FLAGS_REG)
1423         (compare:CCFPU
1424           (vec_select:MODEF
1425             (match_operand:<ssevecmode> 0 "register_operand" "x")
1426             (parallel [(const_int 0)]))
1427           (vec_select:MODEF
1428             (match_operand:<ssevecmode> 1 "nonimmediate_operand" "xm")
1429             (parallel [(const_int 0)]))))]
1430   "SSE_FLOAT_MODE_P (<MODE>mode)"
1431   "%vucomi<ssemodesuffix>\t{%1, %0|%0, %1}"
1432   [(set_attr "type" "ssecomi")
1433    (set_attr "prefix" "maybe_vex")
1434    (set_attr "prefix_rep" "0")
1435    (set (attr "prefix_data16")
1436         (if_then_else (eq_attr "mode" "DF")
1437                       (const_string "1")
1438                       (const_string "0")))
1439    (set_attr "mode" "<MODE>")])
1440
1441 (define_expand "vcond<V_256:mode><VF_256:mode>"
1442   [(set (match_operand:V_256 0 "register_operand" "")
1443         (if_then_else:V_256
1444           (match_operator 3 ""
1445             [(match_operand:VF_256 4 "nonimmediate_operand" "")
1446              (match_operand:VF_256 5 "nonimmediate_operand" "")])
1447           (match_operand:V_256 1 "general_operand" "")
1448           (match_operand:V_256 2 "general_operand" "")))]
1449   "TARGET_AVX
1450    && (GET_MODE_NUNITS (<V_256:MODE>mode)
1451        == GET_MODE_NUNITS (<VF_256:MODE>mode))"
1452 {
1453   bool ok = ix86_expand_fp_vcond (operands);
1454   gcc_assert (ok);
1455   DONE;
1456 })
1457
1458 (define_expand "vcond<V_128:mode><VF_128:mode>"
1459   [(set (match_operand:V_128 0 "register_operand" "")
1460         (if_then_else:V_128
1461           (match_operator 3 ""
1462             [(match_operand:VF_128 4 "nonimmediate_operand" "")
1463              (match_operand:VF_128 5 "nonimmediate_operand" "")])
1464           (match_operand:V_128 1 "general_operand" "")
1465           (match_operand:V_128 2 "general_operand" "")))]
1466   "TARGET_SSE
1467    && (GET_MODE_NUNITS (<V_128:MODE>mode)
1468        == GET_MODE_NUNITS (<VF_128:MODE>mode))"
1469 {
1470   bool ok = ix86_expand_fp_vcond (operands);
1471   gcc_assert (ok);
1472   DONE;
1473 })
1474
1475 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1476 ;;
1477 ;; Parallel floating point logical operations
1478 ;;
1479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1480
1481 (define_insn "<sse>_andnot<mode>3"
1482   [(set (match_operand:VF 0 "register_operand" "=x,x")
1483         (and:VF
1484           (not:VF
1485             (match_operand:VF 1 "register_operand" "0,x"))
1486           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1487   "TARGET_SSE"
1488 {
1489   static char buf[32];
1490   const char *insn;
1491   const char *suffix
1492     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssemodesuffix>";
1493
1494   switch (which_alternative)
1495     {
1496     case 0:
1497       insn = "andn%s\t{%%2, %%0|%%0, %%2}";
1498       break;
1499     case 1:
1500       insn = "vandn%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1501       break;
1502     default:
1503       gcc_unreachable ();
1504     }
1505
1506   snprintf (buf, sizeof (buf), insn, suffix);
1507   return buf;
1508 }
1509   [(set_attr "isa" "noavx,avx")
1510    (set_attr "type" "sselog")
1511    (set_attr "prefix" "orig,vex")
1512    (set_attr "mode" "<MODE>")])
1513
1514 (define_expand "<code><mode>3"
1515   [(set (match_operand:VF 0 "register_operand" "")
1516         (any_logic:VF
1517           (match_operand:VF 1 "nonimmediate_operand" "")
1518           (match_operand:VF 2 "nonimmediate_operand" "")))]
1519   "TARGET_SSE"
1520   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
1521
1522 (define_insn "*<code><mode>3"
1523   [(set (match_operand:VF 0 "register_operand" "=x,x")
1524         (any_logic:VF
1525           (match_operand:VF 1 "nonimmediate_operand" "%0,x")
1526           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")))]
1527   "TARGET_SSE && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
1528 {
1529   static char buf[32];
1530   const char *insn;
1531   const char *suffix
1532     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssemodesuffix>";
1533
1534   switch (which_alternative)
1535     {
1536     case 0:
1537       insn = "<logic>%s\t{%%2, %%0|%%0, %%2}";
1538       break;
1539     case 1:
1540       insn = "v<logic>%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1541       break;
1542     default:
1543       gcc_unreachable ();
1544     }
1545
1546   snprintf (buf, sizeof (buf), insn, suffix);
1547   return buf;
1548 }
1549   [(set_attr "isa" "noavx,avx")
1550    (set_attr "type" "sselog")
1551    (set_attr "prefix" "orig,vex")
1552    (set_attr "mode" "<MODE>")])
1553
1554 (define_expand "copysign<mode>3"
1555   [(set (match_dup 4)
1556         (and:VF
1557           (not:VF (match_dup 3))
1558           (match_operand:VF 1 "nonimmediate_operand" "")))
1559    (set (match_dup 5)
1560         (and:VF (match_dup 3)
1561                 (match_operand:VF 2 "nonimmediate_operand" "")))
1562    (set (match_operand:VF 0 "register_operand" "")
1563         (ior:VF (match_dup 4) (match_dup 5)))]
1564   "TARGET_SSE"
1565 {
1566   operands[3] = ix86_build_signbit_mask (<MODE>mode, 1, 0);
1567
1568   operands[4] = gen_reg_rtx (<MODE>mode);
1569   operands[5] = gen_reg_rtx (<MODE>mode);
1570 })
1571
1572 ;; Also define scalar versions.  These are used for abs, neg, and
1573 ;; conditional move.  Using subregs into vector modes causes register
1574 ;; allocation lossage.  These patterns do not allow memory operands
1575 ;; because the native instructions read the full 128-bits.
1576
1577 (define_insn "*andnot<mode>3"
1578   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
1579         (and:MODEF
1580           (not:MODEF
1581             (match_operand:MODEF 1 "register_operand" "0,x"))
1582             (match_operand:MODEF 2 "register_operand" "x,x")))]
1583   "SSE_FLOAT_MODE_P (<MODE>mode)"
1584 {
1585   static char buf[32];
1586   const char *insn;
1587   const char *suffix
1588     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssevecmodesuffix>";
1589
1590   switch (which_alternative)
1591     {
1592     case 0:
1593       insn = "andn%s\t{%%2, %%0|%%0, %%2}";
1594       break;
1595     case 1:
1596       insn = "vandn%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1597       break;
1598     default:
1599       gcc_unreachable ();
1600     }
1601
1602   snprintf (buf, sizeof (buf), insn, suffix);
1603   return buf;
1604 }
1605   [(set_attr "isa" "noavx,avx")
1606    (set_attr "type" "sselog")
1607    (set_attr "prefix" "orig,vex")
1608    (set_attr "mode" "<ssevecmode>")])
1609
1610 (define_insn "*<code><mode>3"
1611   [(set (match_operand:MODEF 0 "register_operand" "=x,x")
1612         (any_logic:MODEF
1613           (match_operand:MODEF 1 "register_operand" "%0,x")
1614           (match_operand:MODEF 2 "register_operand" "x,x")))]
1615   "SSE_FLOAT_MODE_P (<MODE>mode)"
1616 {
1617   static char buf[32];
1618   const char *insn;
1619   const char *suffix
1620     = TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL ? "ps" : "<ssevecmodesuffix>";
1621
1622   switch (which_alternative)
1623     {
1624     case 0:
1625       insn = "<logic>%s\t{%%2, %%0|%%0, %%2}";
1626       break;
1627     case 1:
1628       insn = "v<logic>%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
1629       break;
1630     default:
1631       gcc_unreachable ();
1632     }
1633
1634   snprintf (buf, sizeof (buf), insn, suffix);
1635   return buf;
1636 }
1637   [(set_attr "isa" "noavx,avx")
1638    (set_attr "type" "sselog")
1639    (set_attr "prefix" "orig,vex")
1640    (set_attr "mode" "<ssevecmode>")])
1641
1642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1643 ;;
1644 ;; FMA4 floating point multiply/accumulate instructions.  This
1645 ;; includes the scalar version of the instructions as well as the
1646 ;; vector.
1647 ;;
1648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1649
1650 ;; In order to match (*a * *b) + *c, particularly when vectorizing, allow
1651 ;; combine to generate a multiply/add with two memory references.  We then
1652 ;; split this insn, into loading up the destination register with one of the
1653 ;; memory operations.  If we don't manage to split the insn, reload will
1654 ;; generate the appropriate moves.  The reason this is needed, is that combine
1655 ;; has already folded one of the memory references into both the multiply and
1656 ;; add insns, and it can't generate a new pseudo.  I.e.:
1657 ;;      (set (reg1) (mem (addr1)))
1658 ;;      (set (reg2) (mult (reg1) (mem (addr2))))
1659 ;;      (set (reg3) (plus (reg2) (mem (addr3))))
1660 ;;
1661 ;; ??? This is historic, pre-dating the gimple fma transformation.
1662 ;; We could now properly represent that only one memory operand is
1663 ;; allowed and not be penalized during optimization.
1664
1665 ;; Intrinsic FMA operations.
1666
1667 ;; The standard names for fma is only available with SSE math enabled.
1668 (define_expand "fma<mode>4"
1669   [(set (match_operand:FMAMODE 0 "register_operand")
1670         (fma:FMAMODE
1671           (match_operand:FMAMODE 1 "nonimmediate_operand")
1672           (match_operand:FMAMODE 2 "nonimmediate_operand")
1673           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
1674   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1675
1676 (define_expand "fms<mode>4"
1677   [(set (match_operand:FMAMODE 0 "register_operand")
1678         (fma:FMAMODE
1679           (match_operand:FMAMODE 1 "nonimmediate_operand")
1680           (match_operand:FMAMODE 2 "nonimmediate_operand")
1681           (neg:FMAMODE (match_operand:FMAMODE 3 "nonimmediate_operand"))))]
1682   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1683
1684 (define_expand "fnma<mode>4"
1685   [(set (match_operand:FMAMODE 0 "register_operand")
1686         (fma:FMAMODE
1687           (neg:FMAMODE (match_operand:FMAMODE 1 "nonimmediate_operand"))
1688           (match_operand:FMAMODE 2 "nonimmediate_operand")
1689           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
1690   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1691
1692 (define_expand "fnms<mode>4"
1693   [(set (match_operand:FMAMODE 0 "register_operand")
1694         (fma:FMAMODE
1695           (neg:FMAMODE (match_operand:FMAMODE 1 "nonimmediate_operand"))
1696           (match_operand:FMAMODE 2 "nonimmediate_operand")
1697           (neg:FMAMODE (match_operand:FMAMODE 3 "nonimmediate_operand"))))]
1698   "(TARGET_FMA || TARGET_FMA4) && TARGET_SSE_MATH")
1699
1700 ;; The builtin for fma4intrin.h is not constrained by SSE math enabled.
1701 (define_expand "fma4i_fmadd_<mode>"
1702   [(set (match_operand:FMAMODE 0 "register_operand")
1703         (fma:FMAMODE
1704           (match_operand:FMAMODE 1 "nonimmediate_operand")
1705           (match_operand:FMAMODE 2 "nonimmediate_operand")
1706           (match_operand:FMAMODE 3 "nonimmediate_operand")))]
1707   "TARGET_FMA || TARGET_FMA4")
1708
1709 (define_insn "*fma4i_fmadd_<mode>"
1710   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1711         (fma:FMAMODE
1712           (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x")
1713           (match_operand:FMAMODE 2 "nonimmediate_operand" " x,m")
1714           (match_operand:FMAMODE 3 "nonimmediate_operand" "xm,x")))]
1715   "TARGET_FMA4"
1716   "vfmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1717   [(set_attr "type" "ssemuladd")
1718    (set_attr "mode" "<MODE>")])
1719
1720 (define_insn "*fma4i_fmsub_<mode>"
1721   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1722         (fma:FMAMODE
1723           (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x")
1724           (match_operand:FMAMODE 2 "nonimmediate_operand" " x,m")
1725           (neg:FMAMODE
1726             (match_operand:FMAMODE 3 "nonimmediate_operand" "xm,x"))))]
1727   "TARGET_FMA4"
1728   "vfmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1729   [(set_attr "type" "ssemuladd")
1730    (set_attr "mode" "<MODE>")])
1731
1732 (define_insn "*fma4i_fnmadd_<mode>"
1733   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1734         (fma:FMAMODE
1735           (neg:FMAMODE
1736             (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x"))
1737           (match_operand:FMAMODE   2 "nonimmediate_operand" " x,m")
1738           (match_operand:FMAMODE   3 "nonimmediate_operand" "xm,x")))]
1739   "TARGET_FMA4"
1740   "vfnmadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1741   [(set_attr "type" "ssemuladd")
1742    (set_attr "mode" "<MODE>")])
1743
1744 (define_insn "*fma4i_fnmsub_<mode>"
1745   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x")
1746         (fma:FMAMODE
1747           (neg:FMAMODE
1748             (match_operand:FMAMODE 1 "nonimmediate_operand" "%x,x"))
1749           (match_operand:FMAMODE   2 "nonimmediate_operand" " x,m")
1750           (neg:FMAMODE
1751             (match_operand:FMAMODE 3 "nonimmediate_operand" "xm,x"))))]
1752   "TARGET_FMA4"
1753   "vfnmsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1754   [(set_attr "type" "ssemuladd")
1755    (set_attr "mode" "<MODE>")])
1756
1757 ;; Scalar versions of the above.  Unlike ADDSS et al, these write the
1758 ;; entire destination register, with the high-order elements zeroed.
1759
1760 (define_expand "fma4i_vmfmadd_<mode>"
1761   [(set (match_operand:VF_128 0 "register_operand")
1762         (vec_merge:VF_128
1763           (fma:VF_128
1764             (match_operand:VF_128 1 "nonimmediate_operand")
1765             (match_operand:VF_128 2 "nonimmediate_operand")
1766             (match_operand:VF_128 3 "nonimmediate_operand"))
1767           (match_dup 4)
1768           (const_int 1)))]
1769   "TARGET_FMA4"
1770 {
1771   operands[4] = CONST0_RTX (<MODE>mode);
1772 })
1773
1774 (define_expand "fmai_vmfmadd_<mode>"
1775   [(set (match_operand:VF_128 0 "register_operand")
1776         (vec_merge:VF_128
1777           (fma:VF_128
1778             (match_operand:VF_128 1 "nonimmediate_operand")
1779             (match_operand:VF_128 2 "nonimmediate_operand")
1780             (match_operand:VF_128 3 "nonimmediate_operand"))
1781           (match_dup 0)
1782           (const_int 1)))]
1783   "TARGET_FMA")
1784
1785 (define_insn "*fmai_fmadd_<mode>"
1786   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1787         (vec_merge:VF_128
1788           (fma:VF_128
1789             (match_operand:VF_128 1 "nonimmediate_operand" "%0, 0,x")
1790             (match_operand:VF_128 2 "nonimmediate_operand" "xm, x,xm")
1791             (match_operand:VF_128 3 "nonimmediate_operand" " x,xm,0"))
1792           (match_dup 0)
1793           (const_int 1)))]
1794   "TARGET_FMA"
1795   "@
1796    vfmadd132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1797    vfmadd213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1798    vfmadd231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1799   [(set_attr "type" "ssemuladd")
1800    (set_attr "mode" "<MODE>")])
1801
1802 (define_insn "*fmai_fmsub_<mode>"
1803   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1804         (vec_merge:VF_128
1805           (fma:VF_128
1806             (match_operand:VF_128   1 "nonimmediate_operand" "%0, 0,x")
1807             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x,xm")
1808             (neg:VF_128
1809               (match_operand:VF_128 3 "nonimmediate_operand" " x,xm,0")))
1810           (match_dup 0)
1811           (const_int 1)))]
1812   "TARGET_FMA"
1813   "@
1814    vfmsub132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1815    vfmsub213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1816    vfmsub231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1817   [(set_attr "type" "ssemuladd")
1818    (set_attr "mode" "<MODE>")])
1819
1820 (define_insn "*fmai_fnmadd_<mode>"
1821   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1822         (vec_merge:VF_128
1823           (fma:VF_128
1824             (neg:VF_128
1825               (match_operand:VF_128 1 "nonimmediate_operand" "%0, 0,x"))
1826             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x,xm")
1827             (match_operand:VF_128   3 "nonimmediate_operand" " x,xm,0"))
1828           (match_dup 0)
1829           (const_int 1)))]
1830   "TARGET_FMA"
1831   "@
1832    vfnmadd132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1833    vfnmadd213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1834    vfnmadd231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1835   [(set_attr "type" "ssemuladd")
1836    (set_attr "mode" "<MODE>")])
1837
1838 (define_insn "*fmai_fnmsub_<mode>"
1839   [(set (match_operand:VF_128 0 "register_operand" "=x,x,x")
1840         (vec_merge:VF_128
1841           (fma:VF_128
1842             (neg:VF_128
1843               (match_operand:VF_128 1 "nonimmediate_operand" "%0, 0,x"))
1844             (match_operand:VF_128   2 "nonimmediate_operand" "xm, x,xm")
1845             (neg:VF_128
1846               (match_operand:VF_128 3 "nonimmediate_operand" " x,xm,0")))
1847           (match_dup 0)
1848           (const_int 1)))]
1849   "TARGET_FMA"
1850   "@
1851    vfnmsub132<ssescalarmodesuffix>\t{%2, %3, %0|%0, %3, %2}
1852    vfnmsub213<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
1853    vfnmsub231<ssescalarmodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1854   [(set_attr "type" "ssemuladd")
1855    (set_attr "mode" "<MODE>")])
1856
1857 (define_insn "*fma4i_vmfmadd_<mode>"
1858   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1859         (vec_merge:VF_128
1860           (fma:VF_128
1861             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
1862             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
1863             (match_operand:VF_128 3 "nonimmediate_operand" "xm,x"))
1864           (match_operand:VF_128 4 "const0_operand" "")
1865           (const_int 1)))]
1866   "TARGET_FMA4"
1867   "vfmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1868   [(set_attr "type" "ssemuladd")
1869    (set_attr "mode" "<MODE>")])
1870
1871 (define_insn "*fma4i_vmfmsub_<mode>"
1872   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1873         (vec_merge:VF_128
1874           (fma:VF_128
1875             (match_operand:VF_128 1 "nonimmediate_operand" "%x,x")
1876             (match_operand:VF_128 2 "nonimmediate_operand" " x,m")
1877             (neg:VF_128
1878               (match_operand:VF_128 3 "nonimmediate_operand" "xm,x")))
1879           (match_operand:VF_128 4 "const0_operand" "")
1880           (const_int 1)))]
1881   "TARGET_FMA4"
1882   "vfmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1883   [(set_attr "type" "ssemuladd")
1884    (set_attr "mode" "<MODE>")])
1885
1886 (define_insn "*fma4i_vmfnmadd_<mode>"
1887   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1888         (vec_merge:VF_128
1889           (fma:VF_128
1890             (neg:VF_128
1891               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
1892             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
1893             (match_operand:VF_128   3 "nonimmediate_operand" "xm,x"))
1894           (match_operand:VF_128 4 "const0_operand" "")
1895           (const_int 1)))]
1896   "TARGET_FMA4"
1897   "vfnmadd<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1898   [(set_attr "type" "ssemuladd")
1899    (set_attr "mode" "<MODE>")])
1900
1901 (define_insn "*fma4i_vmfnmsub_<mode>"
1902   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
1903         (vec_merge:VF_128
1904           (fma:VF_128
1905             (neg:VF_128
1906               (match_operand:VF_128 1 "nonimmediate_operand" "%x,x"))
1907             (match_operand:VF_128   2 "nonimmediate_operand" " x,m")
1908             (neg:VF_128
1909               (match_operand:VF_128   3 "nonimmediate_operand" "xm,x")))
1910           (match_operand:VF_128 4 "const0_operand" "")
1911           (const_int 1)))]
1912   "TARGET_FMA4"
1913   "vfnmsub<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1914   [(set_attr "type" "ssemuladd")
1915    (set_attr "mode" "<MODE>")])
1916
1917 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1918 ;;
1919 ;; FMA4 Parallel floating point multiply addsub and subadd operations.
1920 ;;
1921 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1922
1923 ;; It would be possible to represent these without the UNSPEC as
1924 ;;
1925 ;; (vec_merge
1926 ;;   (fma op1 op2 op3)
1927 ;;   (fma op1 op2 (neg op3))
1928 ;;   (merge-const))
1929 ;;
1930 ;; But this doesn't seem useful in practice.
1931
1932 (define_expand "fmaddsub_<mode>"
1933   [(set (match_operand:VF 0 "register_operand")
1934         (unspec:VF
1935           [(match_operand:VF 1 "nonimmediate_operand")
1936            (match_operand:VF 2 "nonimmediate_operand")
1937            (match_operand:VF 3 "nonimmediate_operand")]
1938           UNSPEC_FMADDSUB))]
1939   "TARGET_FMA || TARGET_FMA4")
1940
1941 (define_insn "*fma4_fmaddsub_<mode>"
1942   [(set (match_operand:VF 0 "register_operand" "=x,x")
1943         (unspec:VF
1944           [(match_operand:VF 1 "nonimmediate_operand" "%x,x")
1945            (match_operand:VF 2 "nonimmediate_operand" " x,m")
1946            (match_operand:VF 3 "nonimmediate_operand" "xm,x")]
1947           UNSPEC_FMADDSUB))]
1948   "TARGET_FMA4"
1949   "vfmaddsub<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1950   [(set_attr "type" "ssemuladd")
1951    (set_attr "mode" "<MODE>")])
1952
1953 (define_insn "*fma4_fmsubadd_<mode>"
1954   [(set (match_operand:VF 0 "register_operand" "=x,x")
1955         (unspec:VF
1956           [(match_operand:VF 1 "nonimmediate_operand" "%x,x")
1957            (match_operand:VF 2 "nonimmediate_operand" " x,m")
1958            (neg:VF
1959              (match_operand:VF 3 "nonimmediate_operand" "xm,x"))]
1960           UNSPEC_FMADDSUB))]
1961   "TARGET_FMA4"
1962   "vfmsubadd<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
1963   [(set_attr "type" "ssemuladd")
1964    (set_attr "mode" "<MODE>")])
1965
1966 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1967 ;;
1968 ;; FMA3 floating point multiply/accumulate instructions.
1969 ;;
1970 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1971
1972 (define_insn "*fma_fmadd_<mode>"
1973   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
1974         (fma:FMAMODE
1975           (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x")
1976           (match_operand:FMAMODE 2 "nonimmediate_operand" "xm, x,xm")
1977           (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0")))]
1978   "TARGET_FMA"
1979   "@
1980    vfmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
1981    vfmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
1982    vfmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1983   [(set_attr "type" "ssemuladd")
1984    (set_attr "mode" "<MODE>")])
1985
1986 (define_insn "*fma_fmsub_<mode>"
1987   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
1988         (fma:FMAMODE
1989           (match_operand:FMAMODE   1 "nonimmediate_operand" "%0, 0,x")
1990           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm")
1991           (neg:FMAMODE
1992             (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0"))))]
1993   "TARGET_FMA"
1994   "@
1995    vfmsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
1996    vfmsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
1997    vfmsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
1998   [(set_attr "type" "ssemuladd")
1999    (set_attr "mode" "<MODE>")])
2000
2001 (define_insn "*fma_fnmadd_<mode>"
2002   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
2003         (fma:FMAMODE
2004           (neg:FMAMODE
2005             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x"))
2006           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm")
2007           (match_operand:FMAMODE   3 "nonimmediate_operand" " x,xm,0")))]
2008   "TARGET_FMA"
2009   "@
2010    vfnmadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2011    vfnmadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2012    vfnmadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2013   [(set_attr "type" "ssemuladd")
2014    (set_attr "mode" "<MODE>")])
2015
2016 (define_insn "*fma_fnmsub_<mode>"
2017   [(set (match_operand:FMAMODE 0 "register_operand" "=x,x,x")
2018         (fma:FMAMODE
2019           (neg:FMAMODE
2020             (match_operand:FMAMODE 1 "nonimmediate_operand" "%0, 0,x"))
2021           (match_operand:FMAMODE   2 "nonimmediate_operand" "xm, x,xm")
2022           (neg:FMAMODE
2023             (match_operand:FMAMODE 3 "nonimmediate_operand" " x,xm,0"))))]
2024   "TARGET_FMA"
2025   "@
2026    vfnmsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2027    vfnmsub231<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2028    vfnmsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2029   [(set_attr "type" "ssemuladd")
2030    (set_attr "mode" "<MODE>")])
2031
2032 (define_insn "*fma_fmaddsub_<mode>"
2033   [(set (match_operand:VF 0 "register_operand" "=x,x,x")
2034         (unspec:VF
2035           [(match_operand:VF 1 "nonimmediate_operand" "%0, 0,x")
2036            (match_operand:VF 2 "nonimmediate_operand" "xm, x,xm")
2037            (match_operand:VF 3 "nonimmediate_operand" " x,xm,0")]
2038           UNSPEC_FMADDSUB))]
2039   "TARGET_FMA"
2040   "@
2041    vfmaddsub132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2042    vfmaddsub213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2043    vfmaddsub231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2044   [(set_attr "type" "ssemuladd")
2045    (set_attr "mode" "<MODE>")])
2046
2047 (define_insn "*fma_fmsubadd_<mode>"
2048   [(set (match_operand:VF 0 "register_operand" "=x,x,x")
2049         (unspec:VF
2050           [(match_operand:VF   1 "nonimmediate_operand" "%0, 0,x")
2051            (match_operand:VF   2 "nonimmediate_operand" "xm, x,xm")
2052            (neg:VF
2053              (match_operand:VF 3 "nonimmediate_operand" " x,xm,0"))]
2054           UNSPEC_FMADDSUB))]
2055   "TARGET_FMA"
2056   "@
2057    vfmsubadd132<ssemodesuffix>\t{%2, %3, %0|%0, %3, %2}
2058    vfmsubadd213<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
2059    vfmsubadd231<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
2060   [(set_attr "type" "ssemuladd")
2061    (set_attr "mode" "<MODE>")])
2062
2063 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2064 ;;
2065 ;; Parallel single-precision floating point conversion operations
2066 ;;
2067 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2068
2069 (define_insn "sse_cvtpi2ps"
2070   [(set (match_operand:V4SF 0 "register_operand" "=x")
2071         (vec_merge:V4SF
2072           (vec_duplicate:V4SF
2073             (float:V2SF (match_operand:V2SI 2 "nonimmediate_operand" "ym")))
2074           (match_operand:V4SF 1 "register_operand" "0")
2075           (const_int 3)))]
2076   "TARGET_SSE"
2077   "cvtpi2ps\t{%2, %0|%0, %2}"
2078   [(set_attr "type" "ssecvt")
2079    (set_attr "mode" "V4SF")])
2080
2081 (define_insn "sse_cvtps2pi"
2082   [(set (match_operand:V2SI 0 "register_operand" "=y")
2083         (vec_select:V2SI
2084           (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
2085                        UNSPEC_FIX_NOTRUNC)
2086           (parallel [(const_int 0) (const_int 1)])))]
2087   "TARGET_SSE"
2088   "cvtps2pi\t{%1, %0|%0, %1}"
2089   [(set_attr "type" "ssecvt")
2090    (set_attr "unit" "mmx")
2091    (set_attr "mode" "DI")])
2092
2093 (define_insn "sse_cvttps2pi"
2094   [(set (match_operand:V2SI 0 "register_operand" "=y")
2095         (vec_select:V2SI
2096           (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm"))
2097           (parallel [(const_int 0) (const_int 1)])))]
2098   "TARGET_SSE"
2099   "cvttps2pi\t{%1, %0|%0, %1}"
2100   [(set_attr "type" "ssecvt")
2101    (set_attr "unit" "mmx")
2102    (set_attr "prefix_rep" "0")
2103    (set_attr "mode" "SF")])
2104
2105 (define_insn "sse_cvtsi2ss"
2106   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2107         (vec_merge:V4SF
2108           (vec_duplicate:V4SF
2109             (float:SF (match_operand:SI 2 "nonimmediate_operand" "r,m,rm")))
2110           (match_operand:V4SF 1 "register_operand" "0,0,x")
2111           (const_int 1)))]
2112   "TARGET_SSE"
2113   "@
2114    cvtsi2ss\t{%2, %0|%0, %2}
2115    cvtsi2ss\t{%2, %0|%0, %2}
2116    vcvtsi2ss\t{%2, %1, %0|%0, %1, %2}"
2117   [(set_attr "isa" "noavx,noavx,avx")
2118    (set_attr "type" "sseicvt")
2119    (set_attr "athlon_decode" "vector,double,*")
2120    (set_attr "amdfam10_decode" "vector,double,*")
2121    (set_attr "bdver1_decode" "double,direct,*")
2122    (set_attr "prefix" "orig,orig,vex")
2123    (set_attr "mode" "SF")])
2124
2125 (define_insn "sse_cvtsi2ssq"
2126   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2127         (vec_merge:V4SF
2128           (vec_duplicate:V4SF
2129             (float:SF (match_operand:DI 2 "nonimmediate_operand" "r,m,rm")))
2130           (match_operand:V4SF 1 "register_operand" "0,0,x")
2131           (const_int 1)))]
2132   "TARGET_SSE && TARGET_64BIT"
2133   "@
2134    cvtsi2ssq\t{%2, %0|%0, %2}
2135    cvtsi2ssq\t{%2, %0|%0, %2}
2136    vcvtsi2ssq\t{%2, %1, %0|%0, %1, %2}"
2137   [(set_attr "isa" "noavx,noavx,avx")
2138    (set_attr "type" "sseicvt")
2139    (set_attr "athlon_decode" "vector,double,*")
2140    (set_attr "amdfam10_decode" "vector,double,*")
2141    (set_attr "bdver1_decode" "double,direct,*")
2142    (set_attr "length_vex" "*,*,4")
2143    (set_attr "prefix_rex" "1,1,*")
2144    (set_attr "prefix" "orig,orig,vex")
2145    (set_attr "mode" "SF")])
2146
2147 (define_insn "sse_cvtss2si"
2148   [(set (match_operand:SI 0 "register_operand" "=r,r")
2149         (unspec:SI
2150           [(vec_select:SF
2151              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2152              (parallel [(const_int 0)]))]
2153           UNSPEC_FIX_NOTRUNC))]
2154   "TARGET_SSE"
2155   "%vcvtss2si\t{%1, %0|%0, %1}"
2156   [(set_attr "type" "sseicvt")
2157    (set_attr "athlon_decode" "double,vector")
2158    (set_attr "bdver1_decode" "double,double")
2159    (set_attr "prefix_rep" "1")
2160    (set_attr "prefix" "maybe_vex")
2161    (set_attr "mode" "SI")])
2162
2163 (define_insn "sse_cvtss2si_2"
2164   [(set (match_operand:SI 0 "register_operand" "=r,r")
2165         (unspec:SI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
2166                    UNSPEC_FIX_NOTRUNC))]
2167   "TARGET_SSE"
2168   "%vcvtss2si\t{%1, %0|%0, %1}"
2169   [(set_attr "type" "sseicvt")
2170    (set_attr "athlon_decode" "double,vector")
2171    (set_attr "amdfam10_decode" "double,double")
2172    (set_attr "bdver1_decode" "double,double")
2173    (set_attr "prefix_rep" "1")
2174    (set_attr "prefix" "maybe_vex")
2175    (set_attr "mode" "SI")])
2176
2177 (define_insn "sse_cvtss2siq"
2178   [(set (match_operand:DI 0 "register_operand" "=r,r")
2179         (unspec:DI
2180           [(vec_select:SF
2181              (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2182              (parallel [(const_int 0)]))]
2183           UNSPEC_FIX_NOTRUNC))]
2184   "TARGET_SSE && TARGET_64BIT"
2185   "%vcvtss2si{q}\t{%1, %0|%0, %1}"
2186   [(set_attr "type" "sseicvt")
2187    (set_attr "athlon_decode" "double,vector")
2188    (set_attr "bdver1_decode" "double,double")
2189    (set_attr "prefix_rep" "1")
2190    (set_attr "prefix" "maybe_vex")
2191    (set_attr "mode" "DI")])
2192
2193 (define_insn "sse_cvtss2siq_2"
2194   [(set (match_operand:DI 0 "register_operand" "=r,r")
2195         (unspec:DI [(match_operand:SF 1 "nonimmediate_operand" "x,m")]
2196                    UNSPEC_FIX_NOTRUNC))]
2197   "TARGET_SSE && TARGET_64BIT"
2198   "%vcvtss2si{q}\t{%1, %0|%0, %1}"
2199   [(set_attr "type" "sseicvt")
2200    (set_attr "athlon_decode" "double,vector")
2201    (set_attr "amdfam10_decode" "double,double")
2202    (set_attr "bdver1_decode" "double,double")
2203    (set_attr "prefix_rep" "1")
2204    (set_attr "prefix" "maybe_vex")
2205    (set_attr "mode" "DI")])
2206
2207 (define_insn "sse_cvttss2si"
2208   [(set (match_operand:SI 0 "register_operand" "=r,r")
2209         (fix:SI
2210           (vec_select:SF
2211             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2212             (parallel [(const_int 0)]))))]
2213   "TARGET_SSE"
2214   "%vcvttss2si\t{%1, %0|%0, %1}"
2215   [(set_attr "type" "sseicvt")
2216    (set_attr "athlon_decode" "double,vector")
2217    (set_attr "amdfam10_decode" "double,double")
2218    (set_attr "bdver1_decode" "double,double")
2219    (set_attr "prefix_rep" "1")
2220    (set_attr "prefix" "maybe_vex")
2221    (set_attr "mode" "SI")])
2222
2223 (define_insn "sse_cvttss2siq"
2224   [(set (match_operand:DI 0 "register_operand" "=r,r")
2225         (fix:DI
2226           (vec_select:SF
2227             (match_operand:V4SF 1 "nonimmediate_operand" "x,m")
2228             (parallel [(const_int 0)]))))]
2229   "TARGET_SSE && TARGET_64BIT"
2230   "%vcvttss2si{q}\t{%1, %0|%0, %1}"
2231   [(set_attr "type" "sseicvt")
2232    (set_attr "athlon_decode" "double,vector")
2233    (set_attr "amdfam10_decode" "double,double")
2234    (set_attr "bdver1_decode" "double,double")
2235    (set_attr "prefix_rep" "1")
2236    (set_attr "prefix" "maybe_vex")
2237    (set_attr "mode" "DI")])
2238
2239 (define_insn "avx_cvtdq2ps256"
2240   [(set (match_operand:V8SF 0 "register_operand" "=x")
2241         (float:V8SF (match_operand:V8SI 1 "nonimmediate_operand" "xm")))]
2242   "TARGET_AVX"
2243   "vcvtdq2ps\t{%1, %0|%0, %1}"
2244   [(set_attr "type" "ssecvt")
2245    (set_attr "prefix" "vex")
2246    (set_attr "mode" "V8SF")])
2247
2248 (define_insn "sse2_cvtdq2ps"
2249   [(set (match_operand:V4SF 0 "register_operand" "=x")
2250         (float:V4SF (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
2251   "TARGET_SSE2"
2252   "%vcvtdq2ps\t{%1, %0|%0, %1}"
2253   [(set_attr "type" "ssecvt")
2254    (set_attr "prefix" "maybe_vex")
2255    (set_attr "mode" "V4SF")])
2256
2257 (define_expand "sse2_cvtudq2ps"
2258   [(set (match_dup 5)
2259         (float:V4SF (match_operand:V4SI 1 "nonimmediate_operand" "")))
2260    (set (match_dup 6)
2261         (lt:V4SF (match_dup 5) (match_dup 3)))
2262    (set (match_dup 7)
2263         (and:V4SF (match_dup 6) (match_dup 4)))
2264    (set (match_operand:V4SF 0 "register_operand" "")
2265         (plus:V4SF (match_dup 5) (match_dup 7)))]
2266   "TARGET_SSE2"
2267 {
2268   REAL_VALUE_TYPE TWO32r;
2269   rtx x;
2270   int i;
2271
2272   real_ldexp (&TWO32r, &dconst1, 32);
2273   x = const_double_from_real_value (TWO32r, SFmode);
2274
2275   operands[3] = force_reg (V4SFmode, CONST0_RTX (V4SFmode));
2276   operands[4] = force_reg (V4SFmode,
2277                            ix86_build_const_vector (V4SFmode, 1, x));
2278
2279   for (i = 5; i < 8; i++)
2280     operands[i] = gen_reg_rtx (V4SFmode);
2281 })
2282
2283 (define_insn "avx_cvtps2dq256"
2284   [(set (match_operand:V8SI 0 "register_operand" "=x")
2285         (unspec:V8SI [(match_operand:V8SF 1 "nonimmediate_operand" "xm")]
2286                      UNSPEC_FIX_NOTRUNC))]
2287   "TARGET_AVX"
2288   "vcvtps2dq\t{%1, %0|%0, %1}"
2289   [(set_attr "type" "ssecvt")
2290    (set_attr "prefix" "vex")
2291    (set_attr "mode" "OI")])
2292
2293 (define_insn "sse2_cvtps2dq"
2294   [(set (match_operand:V4SI 0 "register_operand" "=x")
2295         (unspec:V4SI [(match_operand:V4SF 1 "nonimmediate_operand" "xm")]
2296                      UNSPEC_FIX_NOTRUNC))]
2297   "TARGET_SSE2"
2298   "%vcvtps2dq\t{%1, %0|%0, %1}"
2299   [(set_attr "type" "ssecvt")
2300    (set (attr "prefix_data16")
2301      (if_then_else
2302        (match_test "TARGET_AVX")
2303      (const_string "*")
2304      (const_string "1")))
2305    (set_attr "prefix" "maybe_vex")
2306    (set_attr "mode" "TI")])
2307
2308 (define_insn "avx_cvttps2dq256"
2309   [(set (match_operand:V8SI 0 "register_operand" "=x")
2310         (fix:V8SI (match_operand:V8SF 1 "nonimmediate_operand" "xm")))]
2311   "TARGET_AVX"
2312   "vcvttps2dq\t{%1, %0|%0, %1}"
2313   [(set_attr "type" "ssecvt")
2314    (set_attr "prefix" "vex")
2315    (set_attr "mode" "OI")])
2316
2317 (define_insn "sse2_cvttps2dq"
2318   [(set (match_operand:V4SI 0 "register_operand" "=x")
2319         (fix:V4SI (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
2320   "TARGET_SSE2"
2321   "%vcvttps2dq\t{%1, %0|%0, %1}"
2322   [(set_attr "type" "ssecvt")
2323    (set (attr "prefix_rep")
2324      (if_then_else
2325        (match_test "TARGET_AVX")
2326      (const_string "*")
2327      (const_string "1")))
2328    (set (attr "prefix_data16")
2329      (if_then_else
2330        (match_test "TARGET_AVX")
2331      (const_string "*")
2332      (const_string "0")))
2333    (set_attr "prefix_data16" "0")
2334    (set_attr "prefix" "maybe_vex")
2335    (set_attr "mode" "TI")])
2336
2337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2338 ;;
2339 ;; Parallel double-precision floating point conversion operations
2340 ;;
2341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2342
2343 (define_insn "sse2_cvtpi2pd"
2344   [(set (match_operand:V2DF 0 "register_operand" "=x,x")
2345         (float:V2DF (match_operand:V2SI 1 "nonimmediate_operand" "y,m")))]
2346   "TARGET_SSE2"
2347   "cvtpi2pd\t{%1, %0|%0, %1}"
2348   [(set_attr "type" "ssecvt")
2349    (set_attr "unit" "mmx,*")
2350    (set_attr "prefix_data16" "1,*")
2351    (set_attr "mode" "V2DF")])
2352
2353 (define_insn "sse2_cvtpd2pi"
2354   [(set (match_operand:V2SI 0 "register_operand" "=y")
2355         (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
2356                      UNSPEC_FIX_NOTRUNC))]
2357   "TARGET_SSE2"
2358   "cvtpd2pi\t{%1, %0|%0, %1}"
2359   [(set_attr "type" "ssecvt")
2360    (set_attr "unit" "mmx")
2361    (set_attr "bdver1_decode" "double")
2362    (set_attr "prefix_data16" "1")
2363    (set_attr "mode" "DI")])
2364
2365 (define_insn "sse2_cvttpd2pi"
2366   [(set (match_operand:V2SI 0 "register_operand" "=y")
2367         (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm")))]
2368   "TARGET_SSE2"
2369   "cvttpd2pi\t{%1, %0|%0, %1}"
2370   [(set_attr "type" "ssecvt")
2371    (set_attr "unit" "mmx")
2372    (set_attr "bdver1_decode" "double")
2373    (set_attr "prefix_data16" "1")
2374    (set_attr "mode" "TI")])
2375
2376 (define_insn "sse2_cvtsi2sd"
2377   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2378         (vec_merge:V2DF
2379           (vec_duplicate:V2DF
2380             (float:DF (match_operand:SI 2 "nonimmediate_operand" "r,m,rm")))
2381           (match_operand:V2DF 1 "register_operand" "0,0,x")
2382           (const_int 1)))]
2383   "TARGET_SSE2"
2384   "@
2385    cvtsi2sd\t{%2, %0|%0, %2}
2386    cvtsi2sd\t{%2, %0|%0, %2}
2387    vcvtsi2sd\t{%2, %1, %0|%0, %1, %2}"
2388   [(set_attr "isa" "noavx,noavx,avx")
2389    (set_attr "type" "sseicvt")
2390    (set_attr "athlon_decode" "double,direct,*")
2391    (set_attr "amdfam10_decode" "vector,double,*")
2392    (set_attr "bdver1_decode" "double,direct,*")
2393    (set_attr "prefix" "orig,orig,vex")
2394    (set_attr "mode" "DF")])
2395
2396 (define_insn "sse2_cvtsi2sdq"
2397   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2398         (vec_merge:V2DF
2399           (vec_duplicate:V2DF
2400             (float:DF (match_operand:DI 2 "nonimmediate_operand" "r,m,rm")))
2401           (match_operand:V2DF 1 "register_operand" "0,0,x")
2402           (const_int 1)))]
2403   "TARGET_SSE2 && TARGET_64BIT"
2404   "@
2405    cvtsi2sdq\t{%2, %0|%0, %2}
2406    cvtsi2sdq\t{%2, %0|%0, %2}
2407    vcvtsi2sdq\t{%2, %1, %0|%0, %1, %2}"
2408   [(set_attr "isa" "noavx,noavx,avx")
2409    (set_attr "type" "sseicvt")
2410    (set_attr "athlon_decode" "double,direct,*")
2411    (set_attr "amdfam10_decode" "vector,double,*")
2412    (set_attr "bdver1_decode" "double,direct,*")
2413    (set_attr "length_vex" "*,*,4")
2414    (set_attr "prefix_rex" "1,1,*")
2415    (set_attr "prefix" "orig,orig,vex")
2416    (set_attr "mode" "DF")])
2417
2418 (define_insn "sse2_cvtsd2si"
2419   [(set (match_operand:SI 0 "register_operand" "=r,r")
2420         (unspec:SI
2421           [(vec_select:DF
2422              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2423              (parallel [(const_int 0)]))]
2424           UNSPEC_FIX_NOTRUNC))]
2425   "TARGET_SSE2"
2426   "%vcvtsd2si\t{%1, %0|%0, %1}"
2427   [(set_attr "type" "sseicvt")
2428    (set_attr "athlon_decode" "double,vector")
2429    (set_attr "bdver1_decode" "double,double")
2430    (set_attr "prefix_rep" "1")
2431    (set_attr "prefix" "maybe_vex")
2432    (set_attr "mode" "SI")])
2433
2434 (define_insn "sse2_cvtsd2si_2"
2435   [(set (match_operand:SI 0 "register_operand" "=r,r")
2436         (unspec:SI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2437                    UNSPEC_FIX_NOTRUNC))]
2438   "TARGET_SSE2"
2439   "%vcvtsd2si\t{%1, %0|%0, %1}"
2440   [(set_attr "type" "sseicvt")
2441    (set_attr "athlon_decode" "double,vector")
2442    (set_attr "amdfam10_decode" "double,double")
2443    (set_attr "bdver1_decode" "double,double")
2444    (set_attr "prefix_rep" "1")
2445    (set_attr "prefix" "maybe_vex")
2446    (set_attr "mode" "SI")])
2447
2448 (define_insn "sse2_cvtsd2siq"
2449   [(set (match_operand:DI 0 "register_operand" "=r,r")
2450         (unspec:DI
2451           [(vec_select:DF
2452              (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2453              (parallel [(const_int 0)]))]
2454           UNSPEC_FIX_NOTRUNC))]
2455   "TARGET_SSE2 && TARGET_64BIT"
2456   "%vcvtsd2si{q}\t{%1, %0|%0, %1}"
2457   [(set_attr "type" "sseicvt")
2458    (set_attr "athlon_decode" "double,vector")
2459    (set_attr "bdver1_decode" "double,double")
2460    (set_attr "prefix_rep" "1")
2461    (set_attr "prefix" "maybe_vex")
2462    (set_attr "mode" "DI")])
2463
2464 (define_insn "sse2_cvtsd2siq_2"
2465   [(set (match_operand:DI 0 "register_operand" "=r,r")
2466         (unspec:DI [(match_operand:DF 1 "nonimmediate_operand" "x,m")]
2467                    UNSPEC_FIX_NOTRUNC))]
2468   "TARGET_SSE2 && TARGET_64BIT"
2469   "%vcvtsd2si{q}\t{%1, %0|%0, %1}"
2470   [(set_attr "type" "sseicvt")
2471    (set_attr "athlon_decode" "double,vector")
2472    (set_attr "amdfam10_decode" "double,double")
2473    (set_attr "bdver1_decode" "double,double")
2474    (set_attr "prefix_rep" "1")
2475    (set_attr "prefix" "maybe_vex")
2476    (set_attr "mode" "DI")])
2477
2478 (define_insn "sse2_cvttsd2si"
2479   [(set (match_operand:SI 0 "register_operand" "=r,r")
2480         (fix:SI
2481           (vec_select:DF
2482             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2483             (parallel [(const_int 0)]))))]
2484   "TARGET_SSE2"
2485   "%vcvttsd2si\t{%1, %0|%0, %1}"
2486   [(set_attr "type" "sseicvt")
2487    (set_attr "athlon_decode" "double,vector")
2488    (set_attr "amdfam10_decode" "double,double")
2489    (set_attr "bdver1_decode" "double,double")
2490    (set_attr "prefix_rep" "1")
2491    (set_attr "prefix" "maybe_vex")
2492    (set_attr "mode" "SI")])
2493
2494 (define_insn "sse2_cvttsd2siq"
2495   [(set (match_operand:DI 0 "register_operand" "=r,r")
2496         (fix:DI
2497           (vec_select:DF
2498             (match_operand:V2DF 1 "nonimmediate_operand" "x,m")
2499             (parallel [(const_int 0)]))))]
2500   "TARGET_SSE2 && TARGET_64BIT"
2501   "%vcvttsd2si{q}\t{%1, %0|%0, %1}"
2502   [(set_attr "type" "sseicvt")
2503    (set_attr "athlon_decode" "double,vector")
2504    (set_attr "amdfam10_decode" "double,double")
2505    (set_attr "bdver1_decode" "double,double")
2506    (set_attr "prefix_rep" "1")
2507    (set_attr "prefix" "maybe_vex")
2508    (set_attr "mode" "DI")])
2509
2510 (define_insn "avx_cvtdq2pd256"
2511   [(set (match_operand:V4DF 0 "register_operand" "=x")
2512         (float:V4DF (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
2513   "TARGET_AVX"
2514   "vcvtdq2pd\t{%1, %0|%0, %1}"
2515   [(set_attr "type" "ssecvt")
2516    (set_attr "prefix" "vex")
2517    (set_attr "mode" "V4DF")])
2518
2519 (define_insn "*avx_cvtdq2pd256_2"
2520   [(set (match_operand:V4DF 0 "register_operand" "=x")
2521         (float:V4DF
2522           (vec_select:V4SI
2523             (match_operand:V8SI 1 "nonimmediate_operand" "xm")
2524             (parallel [(const_int 0) (const_int 1)
2525                        (const_int 2) (const_int 3)]))))]
2526   "TARGET_AVX"
2527   "vcvtdq2pd\t{%x1, %0|%0, %x1}"
2528   [(set_attr "type" "ssecvt")
2529    (set_attr "prefix" "vex")
2530    (set_attr "mode" "V4DF")])
2531
2532 (define_insn "sse2_cvtdq2pd"
2533   [(set (match_operand:V2DF 0 "register_operand" "=x")
2534         (float:V2DF
2535           (vec_select:V2SI
2536             (match_operand:V4SI 1 "nonimmediate_operand" "xm")
2537             (parallel [(const_int 0) (const_int 1)]))))]
2538   "TARGET_SSE2"
2539   "%vcvtdq2pd\t{%1, %0|%0, %1}"
2540   [(set_attr "type" "ssecvt")
2541    (set_attr "prefix" "maybe_vex")
2542    (set_attr "mode" "V2DF")])
2543
2544 (define_insn "avx_cvtpd2dq256"
2545   [(set (match_operand:V4SI 0 "register_operand" "=x")
2546         (unspec:V4SI [(match_operand:V4DF 1 "nonimmediate_operand" "xm")]
2547                      UNSPEC_FIX_NOTRUNC))]
2548   "TARGET_AVX"
2549   "vcvtpd2dq{y}\t{%1, %0|%0, %1}"
2550   [(set_attr "type" "ssecvt")
2551    (set_attr "prefix" "vex")
2552    (set_attr "mode" "OI")])
2553
2554 (define_expand "sse2_cvtpd2dq"
2555   [(set (match_operand:V4SI 0 "register_operand" "")
2556         (vec_concat:V4SI
2557           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "")]
2558                        UNSPEC_FIX_NOTRUNC)
2559           (match_dup 2)))]
2560   "TARGET_SSE2"
2561   "operands[2] = CONST0_RTX (V2SImode);")
2562
2563 (define_insn "*sse2_cvtpd2dq"
2564   [(set (match_operand:V4SI 0 "register_operand" "=x")
2565         (vec_concat:V4SI
2566           (unspec:V2SI [(match_operand:V2DF 1 "nonimmediate_operand" "xm")]
2567                        UNSPEC_FIX_NOTRUNC)
2568           (match_operand:V2SI 2 "const0_operand" "")))]
2569   "TARGET_SSE2"
2570 {
2571   if (TARGET_AVX)
2572     return "vcvtpd2dq{x}\t{%1, %0|%0, %1}";
2573   else
2574     return "cvtpd2dq\t{%1, %0|%0, %1}";
2575 }
2576   [(set_attr "type" "ssecvt")
2577    (set_attr "prefix_rep" "1")
2578    (set_attr "prefix_data16" "0")
2579    (set_attr "prefix" "maybe_vex")
2580    (set_attr "mode" "TI")
2581    (set_attr "amdfam10_decode" "double")
2582    (set_attr "athlon_decode" "vector")
2583    (set_attr "bdver1_decode" "double")])
2584
2585 (define_insn "avx_cvttpd2dq256"
2586   [(set (match_operand:V4SI 0 "register_operand" "=x")
2587         (fix:V4SI (match_operand:V4DF 1 "nonimmediate_operand" "xm")))]
2588   "TARGET_AVX"
2589   "vcvttpd2dq{y}\t{%1, %0|%0, %1}"
2590   [(set_attr "type" "ssecvt")
2591    (set_attr "prefix" "vex")
2592    (set_attr "mode" "OI")])
2593
2594 (define_expand "sse2_cvttpd2dq"
2595   [(set (match_operand:V4SI 0 "register_operand" "")
2596         (vec_concat:V4SI
2597           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" ""))
2598           (match_dup 2)))]
2599   "TARGET_SSE2"
2600   "operands[2] = CONST0_RTX (V2SImode);")
2601
2602 (define_insn "*sse2_cvttpd2dq"
2603   [(set (match_operand:V4SI 0 "register_operand" "=x")
2604         (vec_concat:V4SI
2605           (fix:V2SI (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2606           (match_operand:V2SI 2 "const0_operand" "")))]
2607   "TARGET_SSE2"
2608 {
2609   if (TARGET_AVX)
2610     return "vcvttpd2dq{x}\t{%1, %0|%0, %1}";
2611   else
2612     return "cvttpd2dq\t{%1, %0|%0, %1}";
2613 }
2614   [(set_attr "type" "ssecvt")
2615    (set_attr "amdfam10_decode" "double")
2616    (set_attr "athlon_decode" "vector")
2617    (set_attr "bdver1_decode" "double")
2618    (set_attr "prefix" "maybe_vex")
2619    (set_attr "mode" "TI")])
2620
2621 (define_insn "sse2_cvtsd2ss"
2622   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
2623         (vec_merge:V4SF
2624           (vec_duplicate:V4SF
2625             (float_truncate:V2SF
2626               (match_operand:V2DF 2 "nonimmediate_operand" "x,m,xm")))
2627           (match_operand:V4SF 1 "register_operand" "0,0,x")
2628           (const_int 1)))]
2629   "TARGET_SSE2"
2630   "@
2631    cvtsd2ss\t{%2, %0|%0, %2}
2632    cvtsd2ss\t{%2, %0|%0, %2}
2633    vcvtsd2ss\t{%2, %1, %0|%0, %1, %2}"
2634   [(set_attr "isa" "noavx,noavx,avx")
2635    (set_attr "type" "ssecvt")
2636    (set_attr "athlon_decode" "vector,double,*")
2637    (set_attr "amdfam10_decode" "vector,double,*")
2638    (set_attr "bdver1_decode" "direct,direct,*")
2639    (set_attr "prefix" "orig,orig,vex")
2640    (set_attr "mode" "SF")])
2641
2642 (define_insn "sse2_cvtss2sd"
2643   [(set (match_operand:V2DF 0 "register_operand" "=x,x,x")
2644         (vec_merge:V2DF
2645           (float_extend:V2DF
2646             (vec_select:V2SF
2647               (match_operand:V4SF 2 "nonimmediate_operand" "x,m,xm")
2648               (parallel [(const_int 0) (const_int 1)])))
2649           (match_operand:V2DF 1 "register_operand" "0,0,x")
2650           (const_int 1)))]
2651   "TARGET_SSE2"
2652   "@
2653    cvtss2sd\t{%2, %0|%0, %2}
2654    cvtss2sd\t{%2, %0|%0, %2}
2655    vcvtss2sd\t{%2, %1, %0|%0, %1, %2}"
2656   [(set_attr "isa" "noavx,noavx,avx")
2657    (set_attr "type" "ssecvt")
2658    (set_attr "amdfam10_decode" "vector,double,*")
2659    (set_attr "athlon_decode" "direct,direct,*")
2660    (set_attr "bdver1_decode" "direct,direct,*")
2661    (set_attr "prefix" "orig,orig,vex")
2662    (set_attr "mode" "DF")])
2663
2664 (define_insn "avx_cvtpd2ps256"
2665   [(set (match_operand:V4SF 0 "register_operand" "=x")
2666         (float_truncate:V4SF
2667           (match_operand:V4DF 1 "nonimmediate_operand" "xm")))]
2668   "TARGET_AVX"
2669   "vcvtpd2ps{y}\t{%1, %0|%0, %1}"
2670   [(set_attr "type" "ssecvt")
2671    (set_attr "prefix" "vex")
2672    (set_attr "mode" "V4SF")])
2673
2674 (define_expand "sse2_cvtpd2ps"
2675   [(set (match_operand:V4SF 0 "register_operand" "")
2676         (vec_concat:V4SF
2677           (float_truncate:V2SF
2678             (match_operand:V2DF 1 "nonimmediate_operand" ""))
2679           (match_dup 2)))]
2680   "TARGET_SSE2"
2681   "operands[2] = CONST0_RTX (V2SFmode);")
2682
2683 (define_insn "*sse2_cvtpd2ps"
2684   [(set (match_operand:V4SF 0 "register_operand" "=x")
2685         (vec_concat:V4SF
2686           (float_truncate:V2SF
2687             (match_operand:V2DF 1 "nonimmediate_operand" "xm"))
2688           (match_operand:V2SF 2 "const0_operand" "")))]
2689   "TARGET_SSE2"
2690 {
2691   if (TARGET_AVX)
2692     return "vcvtpd2ps{x}\t{%1, %0|%0, %1}";
2693   else
2694     return "cvtpd2ps\t{%1, %0|%0, %1}";
2695 }
2696   [(set_attr "type" "ssecvt")
2697    (set_attr "amdfam10_decode" "double")
2698    (set_attr "athlon_decode" "vector")
2699    (set_attr "bdver1_decode" "double")
2700    (set_attr "prefix_data16" "1")
2701    (set_attr "prefix" "maybe_vex")
2702    (set_attr "mode" "V4SF")])
2703
2704 (define_insn "avx_cvtps2pd256"
2705   [(set (match_operand:V4DF 0 "register_operand" "=x")
2706         (float_extend:V4DF
2707           (match_operand:V4SF 1 "nonimmediate_operand" "xm")))]
2708   "TARGET_AVX"
2709   "vcvtps2pd\t{%1, %0|%0, %1}"
2710   [(set_attr "type" "ssecvt")
2711    (set_attr "prefix" "vex")
2712    (set_attr "mode" "V4DF")])
2713
2714 (define_insn "*avx_cvtps2pd256_2"
2715   [(set (match_operand:V4DF 0 "register_operand" "=x")
2716         (float_extend:V4DF
2717           (vec_select:V4SF
2718             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
2719             (parallel [(const_int 0) (const_int 1)
2720                        (const_int 2) (const_int 3)]))))]
2721   "TARGET_AVX"
2722   "vcvtps2pd\t{%x1, %0|%0, %x1}"
2723   [(set_attr "type" "ssecvt")
2724    (set_attr "prefix" "vex")
2725    (set_attr "mode" "V4DF")])
2726
2727 (define_insn "sse2_cvtps2pd"
2728   [(set (match_operand:V2DF 0 "register_operand" "=x")
2729         (float_extend:V2DF
2730           (vec_select:V2SF
2731             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
2732             (parallel [(const_int 0) (const_int 1)]))))]
2733   "TARGET_SSE2"
2734   "%vcvtps2pd\t{%1, %0|%0, %1}"
2735   [(set_attr "type" "ssecvt")
2736    (set_attr "amdfam10_decode" "direct")
2737    (set_attr "athlon_decode" "double")
2738    (set_attr "bdver1_decode" "double")
2739    (set_attr "prefix_data16" "0")
2740    (set_attr "prefix" "maybe_vex")
2741    (set_attr "mode" "V2DF")])
2742
2743 (define_expand "vec_unpacks_hi_v4sf"
2744   [(set (match_dup 2)
2745    (vec_select:V4SF
2746      (vec_concat:V8SF
2747        (match_dup 2)
2748        (match_operand:V4SF 1 "nonimmediate_operand" ""))
2749      (parallel [(const_int 6) (const_int 7)
2750                 (const_int 2) (const_int 3)])))
2751   (set (match_operand:V2DF 0 "register_operand" "")
2752    (float_extend:V2DF
2753      (vec_select:V2SF
2754        (match_dup 2)
2755        (parallel [(const_int 0) (const_int 1)]))))]
2756   "TARGET_SSE2"
2757   "operands[2] = gen_reg_rtx (V4SFmode);")
2758
2759 (define_expand "vec_unpacks_hi_v8sf"
2760   [(set (match_dup 2)
2761         (vec_select:V4SF
2762           (match_operand:V8SF 1 "nonimmediate_operand" "")
2763           (parallel [(const_int 4) (const_int 5)
2764                      (const_int 6) (const_int 7)])))
2765    (set (match_operand:V4DF 0 "register_operand" "")
2766         (float_extend:V4DF
2767           (match_dup 2)))]
2768   "TARGET_AVX"
2769   "operands[2] = gen_reg_rtx (V4SFmode);")
2770
2771 (define_expand "vec_unpacks_lo_v4sf"
2772   [(set (match_operand:V2DF 0 "register_operand" "")
2773         (float_extend:V2DF
2774           (vec_select:V2SF
2775             (match_operand:V4SF 1 "nonimmediate_operand" "")
2776             (parallel [(const_int 0) (const_int 1)]))))]
2777   "TARGET_SSE2")
2778
2779 (define_expand "vec_unpacks_lo_v8sf"
2780   [(set (match_operand:V4DF 0 "register_operand" "")
2781         (float_extend:V4DF
2782           (vec_select:V4SF
2783             (match_operand:V8SF 1 "nonimmediate_operand" "")
2784             (parallel [(const_int 0) (const_int 1)
2785                        (const_int 2) (const_int 3)]))))]
2786   "TARGET_AVX")
2787
2788 (define_expand "vec_unpacks_float_hi_v8hi"
2789   [(match_operand:V4SF 0 "register_operand" "")
2790    (match_operand:V8HI 1 "register_operand" "")]
2791   "TARGET_SSE2"
2792 {
2793   rtx tmp = gen_reg_rtx (V4SImode);
2794
2795   emit_insn (gen_vec_unpacks_hi_v8hi (tmp, operands[1]));
2796   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2797   DONE;
2798 })
2799
2800 (define_expand "vec_unpacks_float_lo_v8hi"
2801   [(match_operand:V4SF 0 "register_operand" "")
2802    (match_operand:V8HI 1 "register_operand" "")]
2803   "TARGET_SSE2"
2804 {
2805   rtx tmp = gen_reg_rtx (V4SImode);
2806
2807   emit_insn (gen_vec_unpacks_lo_v8hi (tmp, operands[1]));
2808   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2809   DONE;
2810 })
2811
2812 (define_expand "vec_unpacku_float_hi_v8hi"
2813   [(match_operand:V4SF 0 "register_operand" "")
2814    (match_operand:V8HI 1 "register_operand" "")]
2815   "TARGET_SSE2"
2816 {
2817   rtx tmp = gen_reg_rtx (V4SImode);
2818
2819   emit_insn (gen_vec_unpacku_hi_v8hi (tmp, operands[1]));
2820   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2821   DONE;
2822 })
2823
2824 (define_expand "vec_unpacku_float_lo_v8hi"
2825   [(match_operand:V4SF 0 "register_operand" "")
2826    (match_operand:V8HI 1 "register_operand" "")]
2827   "TARGET_SSE2"
2828 {
2829   rtx tmp = gen_reg_rtx (V4SImode);
2830
2831   emit_insn (gen_vec_unpacku_lo_v8hi (tmp, operands[1]));
2832   emit_insn (gen_sse2_cvtdq2ps (operands[0], tmp));
2833   DONE;
2834 })
2835
2836 (define_expand "vec_unpacks_float_hi_v4si"
2837   [(set (match_dup 2)
2838         (vec_select:V4SI
2839           (match_operand:V4SI 1 "nonimmediate_operand" "")
2840           (parallel [(const_int 2) (const_int 3)
2841                      (const_int 2) (const_int 3)])))
2842    (set (match_operand:V2DF 0 "register_operand" "")
2843         (float:V2DF
2844           (vec_select:V2SI
2845           (match_dup 2)
2846             (parallel [(const_int 0) (const_int 1)]))))]
2847   "TARGET_SSE2"
2848   "operands[2] = gen_reg_rtx (V4SImode);")
2849
2850 (define_expand "vec_unpacks_float_lo_v4si"
2851   [(set (match_operand:V2DF 0 "register_operand" "")
2852         (float:V2DF
2853           (vec_select:V2SI
2854             (match_operand:V4SI 1 "nonimmediate_operand" "")
2855             (parallel [(const_int 0) (const_int 1)]))))]
2856   "TARGET_SSE2")
2857
2858 (define_expand "vec_unpacks_float_hi_v8si"
2859   [(set (match_dup 2)
2860         (vec_select:V4SI
2861           (match_operand:V8SI 1 "nonimmediate_operand" "")
2862           (parallel [(const_int 4) (const_int 5)
2863                      (const_int 6) (const_int 7)])))
2864    (set (match_operand:V4DF 0 "register_operand" "")
2865         (float:V4DF
2866           (match_dup 2)))]
2867   "TARGET_AVX"
2868   "operands[2] = gen_reg_rtx (V4SImode);")
2869
2870 (define_expand "vec_unpacks_float_lo_v8si"
2871   [(set (match_operand:V4DF 0 "register_operand" "")
2872         (float:V4DF
2873           (vec_select:V4SI
2874             (match_operand:V8SI 1 "nonimmediate_operand" "")
2875             (parallel [(const_int 0) (const_int 1)
2876                        (const_int 2) (const_int 3)]))))]
2877   "TARGET_AVX")
2878
2879 (define_expand "vec_unpacku_float_hi_v4si"
2880   [(set (match_dup 5)
2881         (vec_select:V4SI
2882           (match_operand:V4SI 1 "nonimmediate_operand" "")
2883           (parallel [(const_int 2) (const_int 3)
2884                      (const_int 2) (const_int 3)])))
2885    (set (match_dup 6)
2886         (float:V2DF
2887           (vec_select:V2SI
2888           (match_dup 5)
2889             (parallel [(const_int 0) (const_int 1)]))))
2890    (set (match_dup 7)
2891         (lt:V2DF (match_dup 6) (match_dup 3)))
2892    (set (match_dup 8)
2893         (and:V2DF (match_dup 7) (match_dup 4)))
2894    (set (match_operand:V2DF 0 "register_operand" "")
2895         (plus:V2DF (match_dup 6) (match_dup 8)))]
2896   "TARGET_SSE2"
2897 {
2898   REAL_VALUE_TYPE TWO32r;
2899   rtx x;
2900   int i;
2901
2902   real_ldexp (&TWO32r, &dconst1, 32);
2903   x = const_double_from_real_value (TWO32r, DFmode);
2904
2905   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
2906   operands[4] = force_reg (V2DFmode,
2907                            ix86_build_const_vector (V2DFmode, 1, x));
2908
2909   operands[5] = gen_reg_rtx (V4SImode);
2910
2911   for (i = 6; i < 9; i++)
2912     operands[i] = gen_reg_rtx (V2DFmode);
2913 })
2914
2915 (define_expand "vec_unpacku_float_lo_v4si"
2916   [(set (match_dup 5)
2917         (float:V2DF
2918           (vec_select:V2SI
2919             (match_operand:V4SI 1 "nonimmediate_operand" "")
2920             (parallel [(const_int 0) (const_int 1)]))))
2921    (set (match_dup 6)
2922         (lt:V2DF (match_dup 5) (match_dup 3)))
2923    (set (match_dup 7)
2924         (and:V2DF (match_dup 6) (match_dup 4)))
2925    (set (match_operand:V2DF 0 "register_operand" "")
2926         (plus:V2DF (match_dup 5) (match_dup 7)))]
2927   "TARGET_SSE2"
2928 {
2929   REAL_VALUE_TYPE TWO32r;
2930   rtx x;
2931   int i;
2932
2933   real_ldexp (&TWO32r, &dconst1, 32);
2934   x = const_double_from_real_value (TWO32r, DFmode);
2935
2936   operands[3] = force_reg (V2DFmode, CONST0_RTX (V2DFmode));
2937   operands[4] = force_reg (V2DFmode,
2938                            ix86_build_const_vector (V2DFmode, 1, x));
2939
2940   for (i = 5; i < 8; i++)
2941     operands[i] = gen_reg_rtx (V2DFmode);
2942 })
2943
2944 (define_expand "vec_pack_trunc_v4df"
2945   [(set (match_dup 3)
2946         (float_truncate:V4SF
2947           (match_operand:V4DF 1 "nonimmediate_operand" "")))
2948    (set (match_dup 4)
2949         (float_truncate:V4SF
2950           (match_operand:V4DF 2 "nonimmediate_operand" "")))
2951    (set (match_operand:V8SF 0 "register_operand" "")
2952         (vec_concat:V8SF
2953           (match_dup 3)
2954           (match_dup 4)))]
2955   "TARGET_AVX"
2956 {
2957   operands[3] = gen_reg_rtx (V4SFmode);
2958   operands[4] = gen_reg_rtx (V4SFmode);
2959 })
2960
2961 (define_expand "vec_pack_trunc_v2df"
2962   [(match_operand:V4SF 0 "register_operand" "")
2963    (match_operand:V2DF 1 "nonimmediate_operand" "")
2964    (match_operand:V2DF 2 "nonimmediate_operand" "")]
2965   "TARGET_SSE2"
2966 {
2967   rtx r1, r2;
2968
2969   r1 = gen_reg_rtx (V4SFmode);
2970   r2 = gen_reg_rtx (V4SFmode);
2971
2972   emit_insn (gen_sse2_cvtpd2ps (r1, operands[1]));
2973   emit_insn (gen_sse2_cvtpd2ps (r2, operands[2]));
2974   emit_insn (gen_sse_movlhps (operands[0], r1, r2));
2975   DONE;
2976 })
2977
2978 (define_expand "vec_pack_sfix_trunc_v2df"
2979   [(match_operand:V4SI 0 "register_operand" "")
2980    (match_operand:V2DF 1 "nonimmediate_operand" "")
2981    (match_operand:V2DF 2 "nonimmediate_operand" "")]
2982   "TARGET_SSE2"
2983 {
2984   rtx r1, r2;
2985
2986   r1 = gen_reg_rtx (V4SImode);
2987   r2 = gen_reg_rtx (V4SImode);
2988
2989   emit_insn (gen_sse2_cvttpd2dq (r1, operands[1]));
2990   emit_insn (gen_sse2_cvttpd2dq (r2, operands[2]));
2991   emit_insn (gen_vec_interleave_lowv2di (gen_lowpart (V2DImode, operands[0]),
2992                                          gen_lowpart (V2DImode, r1),
2993                                          gen_lowpart (V2DImode, r2)));
2994   DONE;
2995 })
2996
2997 (define_expand "vec_pack_sfix_v2df"
2998   [(match_operand:V4SI 0 "register_operand" "")
2999    (match_operand:V2DF 1 "nonimmediate_operand" "")
3000    (match_operand:V2DF 2 "nonimmediate_operand" "")]
3001   "TARGET_SSE2"
3002 {
3003   rtx r1, r2;
3004
3005   r1 = gen_reg_rtx (V4SImode);
3006   r2 = gen_reg_rtx (V4SImode);
3007
3008   emit_insn (gen_sse2_cvtpd2dq (r1, operands[1]));
3009   emit_insn (gen_sse2_cvtpd2dq (r2, operands[2]));
3010   emit_insn (gen_vec_interleave_lowv2di (gen_lowpart (V2DImode, operands[0]),
3011                                          gen_lowpart (V2DImode, r1),
3012                                          gen_lowpart (V2DImode, r2)));
3013   DONE;
3014 })
3015
3016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3017 ;;
3018 ;; Parallel single-precision floating point element swizzling
3019 ;;
3020 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3021
3022 (define_expand "sse_movhlps_exp"
3023   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3024         (vec_select:V4SF
3025           (vec_concat:V8SF
3026             (match_operand:V4SF 1 "nonimmediate_operand" "")
3027             (match_operand:V4SF 2 "nonimmediate_operand" ""))
3028           (parallel [(const_int 6)
3029                      (const_int 7)
3030                      (const_int 2)
3031                      (const_int 3)])))]
3032   "TARGET_SSE"
3033 {
3034   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3035
3036   emit_insn (gen_sse_movhlps (dst, operands[1], operands[2]));
3037
3038   /* Fix up the destination if needed.  */
3039   if (dst != operands[0])
3040     emit_move_insn (operands[0], dst);
3041
3042   DONE;
3043 })
3044
3045 (define_insn "sse_movhlps"
3046   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
3047         (vec_select:V4SF
3048           (vec_concat:V8SF
3049             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3050             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,o,o,x"))
3051           (parallel [(const_int 6)
3052                      (const_int 7)
3053                      (const_int 2)
3054                      (const_int 3)])))]
3055   "TARGET_SSE && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
3056   "@
3057    movhlps\t{%2, %0|%0, %2}
3058    vmovhlps\t{%2, %1, %0|%0, %1, %2}
3059    movlps\t{%H2, %0|%0, %H2}
3060    vmovlps\t{%H2, %1, %0|%0, %1, %H2}
3061    %vmovhps\t{%2, %0|%0, %2}"
3062   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3063    (set_attr "type" "ssemov")
3064    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3065    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3066
3067 (define_expand "sse_movlhps_exp"
3068   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3069         (vec_select:V4SF
3070           (vec_concat:V8SF
3071             (match_operand:V4SF 1 "nonimmediate_operand" "")
3072             (match_operand:V4SF 2 "nonimmediate_operand" ""))
3073           (parallel [(const_int 0)
3074                      (const_int 1)
3075                      (const_int 4)
3076                      (const_int 5)])))]
3077   "TARGET_SSE"
3078 {
3079   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3080
3081   emit_insn (gen_sse_movlhps (dst, operands[1], operands[2]));
3082
3083   /* Fix up the destination if needed.  */
3084   if (dst != operands[0])
3085     emit_move_insn (operands[0], dst);
3086
3087   DONE;
3088 })
3089
3090 (define_insn "sse_movlhps"
3091   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
3092         (vec_select:V4SF
3093           (vec_concat:V8SF
3094             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3095             (match_operand:V4SF 2 "nonimmediate_operand" " x,x,m,x,x"))
3096           (parallel [(const_int 0)
3097                      (const_int 1)
3098                      (const_int 4)
3099                      (const_int 5)])))]
3100   "TARGET_SSE && ix86_binary_operator_ok (UNKNOWN, V4SFmode, operands)"
3101   "@
3102    movlhps\t{%2, %0|%0, %2}
3103    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3104    movhps\t{%2, %0|%0, %2}
3105    vmovhps\t{%2, %1, %0|%0, %1, %2}
3106    %vmovlps\t{%2, %H0|%H0, %2}"
3107   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3108    (set_attr "type" "ssemov")
3109    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3110    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3111
3112 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
3113 (define_insn "avx_unpckhps256"
3114   [(set (match_operand:V8SF 0 "register_operand" "=x")
3115         (vec_select:V8SF
3116           (vec_concat:V16SF
3117             (match_operand:V8SF 1 "register_operand" "x")
3118             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3119           (parallel [(const_int 2) (const_int 10)
3120                      (const_int 3) (const_int 11)
3121                      (const_int 6) (const_int 14)
3122                      (const_int 7) (const_int 15)])))]
3123   "TARGET_AVX"
3124   "vunpckhps\t{%2, %1, %0|%0, %1, %2}"
3125   [(set_attr "type" "sselog")
3126    (set_attr "prefix" "vex")
3127    (set_attr "mode" "V8SF")])
3128
3129 (define_expand "vec_interleave_highv8sf"
3130   [(set (match_dup 3)
3131         (vec_select:V8SF
3132           (vec_concat:V16SF
3133             (match_operand:V8SF 1 "register_operand" "x")
3134             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3135           (parallel [(const_int 0) (const_int 8)
3136                      (const_int 1) (const_int 9)
3137                      (const_int 4) (const_int 12)
3138                      (const_int 5) (const_int 13)])))
3139    (set (match_dup 4)
3140         (vec_select:V8SF
3141           (vec_concat:V16SF
3142             (match_dup 1)
3143             (match_dup 2))
3144           (parallel [(const_int 2) (const_int 10)
3145                      (const_int 3) (const_int 11)
3146                      (const_int 6) (const_int 14)
3147                      (const_int 7) (const_int 15)])))
3148    (set (match_operand:V8SF 0 "register_operand" "")
3149         (vec_select:V8SF
3150           (vec_concat:V16SF
3151             (match_dup 3)
3152             (match_dup 4))
3153           (parallel [(const_int 4) (const_int 5)
3154                      (const_int 6) (const_int 7)
3155                      (const_int 12) (const_int 13)
3156                      (const_int 14) (const_int 15)])))]
3157  "TARGET_AVX"
3158 {
3159   operands[3] = gen_reg_rtx (V8SFmode);
3160   operands[4] = gen_reg_rtx (V8SFmode);
3161 })
3162
3163 (define_insn "vec_interleave_highv4sf"
3164   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3165         (vec_select:V4SF
3166           (vec_concat:V8SF
3167             (match_operand:V4SF 1 "register_operand" "0,x")
3168             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
3169           (parallel [(const_int 2) (const_int 6)
3170                      (const_int 3) (const_int 7)])))]
3171   "TARGET_SSE"
3172   "@
3173    unpckhps\t{%2, %0|%0, %2}
3174    vunpckhps\t{%2, %1, %0|%0, %1, %2}"
3175   [(set_attr "isa" "noavx,avx")
3176    (set_attr "type" "sselog")
3177    (set_attr "prefix" "orig,vex")
3178    (set_attr "mode" "V4SF")])
3179
3180 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
3181 (define_insn "avx_unpcklps256"
3182   [(set (match_operand:V8SF 0 "register_operand" "=x")
3183         (vec_select:V8SF
3184           (vec_concat:V16SF
3185             (match_operand:V8SF 1 "register_operand" "x")
3186             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3187           (parallel [(const_int 0) (const_int 8)
3188                      (const_int 1) (const_int 9)
3189                      (const_int 4) (const_int 12)
3190                      (const_int 5) (const_int 13)])))]
3191   "TARGET_AVX"
3192   "vunpcklps\t{%2, %1, %0|%0, %1, %2}"
3193   [(set_attr "type" "sselog")
3194    (set_attr "prefix" "vex")
3195    (set_attr "mode" "V8SF")])
3196
3197 (define_expand "vec_interleave_lowv8sf"
3198   [(set (match_dup 3)
3199         (vec_select:V8SF
3200           (vec_concat:V16SF
3201             (match_operand:V8SF 1 "register_operand" "x")
3202             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3203           (parallel [(const_int 0) (const_int 8)
3204                      (const_int 1) (const_int 9)
3205                      (const_int 4) (const_int 12)
3206                      (const_int 5) (const_int 13)])))
3207    (set (match_dup 4)
3208         (vec_select:V8SF
3209           (vec_concat:V16SF
3210             (match_dup 1)
3211             (match_dup 2))
3212           (parallel [(const_int 2) (const_int 10)
3213                      (const_int 3) (const_int 11)
3214                      (const_int 6) (const_int 14)
3215                      (const_int 7) (const_int 15)])))
3216    (set (match_operand:V8SF 0 "register_operand" "")
3217         (vec_select:V8SF
3218           (vec_concat:V16SF
3219             (match_dup 3)
3220             (match_dup 4))
3221           (parallel [(const_int 0) (const_int 1)
3222                      (const_int 2) (const_int 3)
3223                      (const_int 8) (const_int 9)
3224                      (const_int 10) (const_int 11)])))]
3225  "TARGET_AVX"
3226 {
3227   operands[3] = gen_reg_rtx (V8SFmode);
3228   operands[4] = gen_reg_rtx (V8SFmode);
3229 })
3230
3231 (define_insn "vec_interleave_lowv4sf"
3232   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3233         (vec_select:V4SF
3234           (vec_concat:V8SF
3235             (match_operand:V4SF 1 "register_operand" "0,x")
3236             (match_operand:V4SF 2 "nonimmediate_operand" "xm,xm"))
3237           (parallel [(const_int 0) (const_int 4)
3238                      (const_int 1) (const_int 5)])))]
3239   "TARGET_SSE"
3240   "@
3241    unpcklps\t{%2, %0|%0, %2}
3242    vunpcklps\t{%2, %1, %0|%0, %1, %2}"
3243   [(set_attr "isa" "noavx,avx")
3244    (set_attr "type" "sselog")
3245    (set_attr "prefix" "orig,vex")
3246    (set_attr "mode" "V4SF")])
3247
3248 ;; These are modeled with the same vec_concat as the others so that we
3249 ;; capture users of shufps that can use the new instructions
3250 (define_insn "avx_movshdup256"
3251   [(set (match_operand:V8SF 0 "register_operand" "=x")
3252         (vec_select:V8SF
3253           (vec_concat:V16SF
3254             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
3255             (match_dup 1))
3256           (parallel [(const_int 1) (const_int 1)
3257                      (const_int 3) (const_int 3)
3258                      (const_int 5) (const_int 5)
3259                      (const_int 7) (const_int 7)])))]
3260   "TARGET_AVX"
3261   "vmovshdup\t{%1, %0|%0, %1}"
3262   [(set_attr "type" "sse")
3263    (set_attr "prefix" "vex")
3264    (set_attr "mode" "V8SF")])
3265
3266 (define_insn "sse3_movshdup"
3267   [(set (match_operand:V4SF 0 "register_operand" "=x")
3268         (vec_select:V4SF
3269           (vec_concat:V8SF
3270             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
3271             (match_dup 1))
3272           (parallel [(const_int 1)
3273                      (const_int 1)
3274                      (const_int 7)
3275                      (const_int 7)])))]
3276   "TARGET_SSE3"
3277   "%vmovshdup\t{%1, %0|%0, %1}"
3278   [(set_attr "type" "sse")
3279    (set_attr "prefix_rep" "1")
3280    (set_attr "prefix" "maybe_vex")
3281    (set_attr "mode" "V4SF")])
3282
3283 (define_insn "avx_movsldup256"
3284   [(set (match_operand:V8SF 0 "register_operand" "=x")
3285         (vec_select:V8SF
3286           (vec_concat:V16SF
3287             (match_operand:V8SF 1 "nonimmediate_operand" "xm")
3288             (match_dup 1))
3289           (parallel [(const_int 0) (const_int 0)
3290                      (const_int 2) (const_int 2)
3291                      (const_int 4) (const_int 4)
3292                      (const_int 6) (const_int 6)])))]
3293   "TARGET_AVX"
3294   "vmovsldup\t{%1, %0|%0, %1}"
3295   [(set_attr "type" "sse")
3296    (set_attr "prefix" "vex")
3297    (set_attr "mode" "V8SF")])
3298
3299 (define_insn "sse3_movsldup"
3300   [(set (match_operand:V4SF 0 "register_operand" "=x")
3301         (vec_select:V4SF
3302           (vec_concat:V8SF
3303             (match_operand:V4SF 1 "nonimmediate_operand" "xm")
3304             (match_dup 1))
3305           (parallel [(const_int 0)
3306                      (const_int 0)
3307                      (const_int 6)
3308                      (const_int 6)])))]
3309   "TARGET_SSE3"
3310   "%vmovsldup\t{%1, %0|%0, %1}"
3311   [(set_attr "type" "sse")
3312    (set_attr "prefix_rep" "1")
3313    (set_attr "prefix" "maybe_vex")
3314    (set_attr "mode" "V4SF")])
3315
3316 (define_expand "avx_shufps256"
3317   [(match_operand:V8SF 0 "register_operand" "")
3318    (match_operand:V8SF 1 "register_operand" "")
3319    (match_operand:V8SF 2 "nonimmediate_operand" "")
3320    (match_operand:SI 3 "const_int_operand" "")]
3321   "TARGET_AVX"
3322 {
3323   int mask = INTVAL (operands[3]);
3324   emit_insn (gen_avx_shufps256_1 (operands[0], operands[1], operands[2],
3325                                   GEN_INT ((mask >> 0) & 3),
3326                                   GEN_INT ((mask >> 2) & 3),
3327                                   GEN_INT (((mask >> 4) & 3) + 8),
3328                                   GEN_INT (((mask >> 6) & 3) + 8),
3329                                   GEN_INT (((mask >> 0) & 3) + 4),
3330                                   GEN_INT (((mask >> 2) & 3) + 4),
3331                                   GEN_INT (((mask >> 4) & 3) + 12),
3332                                   GEN_INT (((mask >> 6) & 3) + 12)));
3333   DONE;
3334 })
3335
3336 ;; One bit in mask selects 2 elements.
3337 (define_insn "avx_shufps256_1"
3338   [(set (match_operand:V8SF 0 "register_operand" "=x")
3339         (vec_select:V8SF
3340           (vec_concat:V16SF
3341             (match_operand:V8SF 1 "register_operand" "x")
3342             (match_operand:V8SF 2 "nonimmediate_operand" "xm"))
3343           (parallel [(match_operand 3  "const_0_to_3_operand"   "")
3344                      (match_operand 4  "const_0_to_3_operand"   "")
3345                      (match_operand 5  "const_8_to_11_operand"  "")
3346                      (match_operand 6  "const_8_to_11_operand"  "")
3347                      (match_operand 7  "const_4_to_7_operand"   "")
3348                      (match_operand 8  "const_4_to_7_operand"   "")
3349                      (match_operand 9  "const_12_to_15_operand" "")
3350                      (match_operand 10 "const_12_to_15_operand" "")])))]
3351   "TARGET_AVX
3352    && (INTVAL (operands[3]) == (INTVAL (operands[7]) - 4)
3353        && INTVAL (operands[4]) == (INTVAL (operands[8]) - 4)
3354        && INTVAL (operands[5]) == (INTVAL (operands[9]) - 4)
3355        && INTVAL (operands[6]) == (INTVAL (operands[10]) - 4))"
3356 {
3357   int mask;
3358   mask = INTVAL (operands[3]);
3359   mask |= INTVAL (operands[4]) << 2;
3360   mask |= (INTVAL (operands[5]) - 8) << 4;
3361   mask |= (INTVAL (operands[6]) - 8) << 6;
3362   operands[3] = GEN_INT (mask);
3363
3364   return "vshufps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3365 }
3366   [(set_attr "type" "sselog")
3367    (set_attr "length_immediate" "1")
3368    (set_attr "prefix" "vex")
3369    (set_attr "mode" "V8SF")])
3370
3371 (define_expand "sse_shufps"
3372   [(match_operand:V4SF 0 "register_operand" "")
3373    (match_operand:V4SF 1 "register_operand" "")
3374    (match_operand:V4SF 2 "nonimmediate_operand" "")
3375    (match_operand:SI 3 "const_int_operand" "")]
3376   "TARGET_SSE"
3377 {
3378   int mask = INTVAL (operands[3]);
3379   emit_insn (gen_sse_shufps_v4sf (operands[0], operands[1], operands[2],
3380                                GEN_INT ((mask >> 0) & 3),
3381                                GEN_INT ((mask >> 2) & 3),
3382                                GEN_INT (((mask >> 4) & 3) + 4),
3383                                GEN_INT (((mask >> 6) & 3) + 4)));
3384   DONE;
3385 })
3386
3387 (define_insn "sse_shufps_<mode>"
3388   [(set (match_operand:VI4F_128 0 "register_operand" "=x,x")
3389         (vec_select:VI4F_128
3390           (vec_concat:<ssedoublevecmode>
3391             (match_operand:VI4F_128 1 "register_operand" "0,x")
3392             (match_operand:VI4F_128 2 "nonimmediate_operand" "xm,xm"))
3393           (parallel [(match_operand 3 "const_0_to_3_operand" "")
3394                      (match_operand 4 "const_0_to_3_operand" "")
3395                      (match_operand 5 "const_4_to_7_operand" "")
3396                      (match_operand 6 "const_4_to_7_operand" "")])))]
3397   "TARGET_SSE"
3398 {
3399   int mask = 0;
3400   mask |= INTVAL (operands[3]) << 0;
3401   mask |= INTVAL (operands[4]) << 2;
3402   mask |= (INTVAL (operands[5]) - 4) << 4;
3403   mask |= (INTVAL (operands[6]) - 4) << 6;
3404   operands[3] = GEN_INT (mask);
3405
3406   switch (which_alternative)
3407     {
3408     case 0:
3409       return "shufps\t{%3, %2, %0|%0, %2, %3}";
3410     case 1:
3411       return "vshufps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3412     default:
3413       gcc_unreachable ();
3414     }
3415 }
3416   [(set_attr "isa" "noavx,avx")
3417    (set_attr "type" "sselog")
3418    (set_attr "length_immediate" "1")
3419    (set_attr "prefix" "orig,vex")
3420    (set_attr "mode" "V4SF")])
3421
3422 (define_insn "sse_storehps"
3423   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=m,x,x")
3424         (vec_select:V2SF
3425           (match_operand:V4SF 1 "nonimmediate_operand" "x,x,o")
3426           (parallel [(const_int 2) (const_int 3)])))]
3427   "TARGET_SSE"
3428   "@
3429    %vmovhps\t{%1, %0|%0, %1}
3430    %vmovhlps\t{%1, %d0|%d0, %1}
3431    %vmovlps\t{%H1, %d0|%d0, %H1}"
3432   [(set_attr "type" "ssemov")
3433    (set_attr "prefix" "maybe_vex")
3434    (set_attr "mode" "V2SF,V4SF,V2SF")])
3435
3436 (define_expand "sse_loadhps_exp"
3437   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3438         (vec_concat:V4SF
3439           (vec_select:V2SF
3440             (match_operand:V4SF 1 "nonimmediate_operand" "")
3441             (parallel [(const_int 0) (const_int 1)]))
3442           (match_operand:V2SF 2 "nonimmediate_operand" "")))]
3443   "TARGET_SSE"
3444 {
3445   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3446
3447   emit_insn (gen_sse_loadhps (dst, operands[1], operands[2]));
3448
3449   /* Fix up the destination if needed.  */
3450   if (dst != operands[0])
3451     emit_move_insn (operands[0], dst);
3452
3453   DONE;
3454 })
3455
3456 (define_insn "sse_loadhps"
3457   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,o")
3458         (vec_concat:V4SF
3459           (vec_select:V2SF
3460             (match_operand:V4SF 1 "nonimmediate_operand" " 0,x,0,x,0")
3461             (parallel [(const_int 0) (const_int 1)]))
3462           (match_operand:V2SF 2 "nonimmediate_operand"   " m,m,x,x,x")))]
3463   "TARGET_SSE"
3464   "@
3465    movhps\t{%2, %0|%0, %2}
3466    vmovhps\t{%2, %1, %0|%0, %1, %2}
3467    movlhps\t{%2, %0|%0, %2}
3468    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3469    %vmovlps\t{%2, %H0|%H0, %2}"
3470   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3471    (set_attr "type" "ssemov")
3472    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3473    (set_attr "mode" "V2SF,V2SF,V4SF,V4SF,V2SF")])
3474
3475 (define_insn "sse_storelps"
3476   [(set (match_operand:V2SF 0 "nonimmediate_operand"   "=m,x,x")
3477         (vec_select:V2SF
3478           (match_operand:V4SF 1 "nonimmediate_operand" " x,x,m")
3479           (parallel [(const_int 0) (const_int 1)])))]
3480   "TARGET_SSE"
3481   "@
3482    %vmovlps\t{%1, %0|%0, %1}
3483    %vmovaps\t{%1, %0|%0, %1}
3484    %vmovlps\t{%1, %d0|%d0, %1}"
3485   [(set_attr "type" "ssemov")
3486    (set_attr "prefix" "maybe_vex")
3487    (set_attr "mode" "V2SF,V4SF,V2SF")])
3488
3489 (define_expand "sse_loadlps_exp"
3490   [(set (match_operand:V4SF 0 "nonimmediate_operand" "")
3491         (vec_concat:V4SF
3492           (match_operand:V2SF 2 "nonimmediate_operand" "")
3493           (vec_select:V2SF
3494             (match_operand:V4SF 1 "nonimmediate_operand" "")
3495             (parallel [(const_int 2) (const_int 3)]))))]
3496   "TARGET_SSE"
3497 {
3498   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V4SFmode, operands);
3499
3500   emit_insn (gen_sse_loadlps (dst, operands[1], operands[2]));
3501
3502   /* Fix up the destination if needed.  */
3503   if (dst != operands[0])
3504     emit_move_insn (operands[0], dst);
3505
3506   DONE;
3507 })
3508
3509 (define_insn "sse_loadlps"
3510   [(set (match_operand:V4SF 0 "nonimmediate_operand"     "=x,x,x,x,m")
3511         (vec_concat:V4SF
3512           (match_operand:V2SF 2 "nonimmediate_operand"   " 0,x,m,x,x")
3513           (vec_select:V2SF
3514             (match_operand:V4SF 1 "nonimmediate_operand" " x,x,0,x,0")
3515             (parallel [(const_int 2) (const_int 3)]))))]
3516   "TARGET_SSE"
3517   "@
3518    shufps\t{$0xe4, %1, %0|%0, %1, 0xe4}
3519    vshufps\t{$0xe4, %1, %2, %0|%0, %2, %1, 0xe4}
3520    movlps\t{%2, %0|%0, %2}
3521    vmovlps\t{%2, %1, %0|%0, %1, %2}
3522    %vmovlps\t{%2, %0|%0, %2}"
3523   [(set_attr "isa" "noavx,avx,noavx,avx,*")
3524    (set_attr "type" "sselog,sselog,ssemov,ssemov,ssemov")
3525    (set_attr "length_immediate" "1,1,*,*,*")
3526    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex")
3527    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF,V2SF")])
3528
3529 (define_insn "sse_movss"
3530   [(set (match_operand:V4SF 0 "register_operand"   "=x,x")
3531         (vec_merge:V4SF
3532           (match_operand:V4SF 2 "register_operand" " x,x")
3533           (match_operand:V4SF 1 "register_operand" " 0,x")
3534           (const_int 1)))]
3535   "TARGET_SSE"
3536   "@
3537    movss\t{%2, %0|%0, %2}
3538    vmovss\t{%2, %1, %0|%0, %1, %2}"
3539   [(set_attr "isa" "noavx,avx")
3540    (set_attr "type" "ssemov")
3541    (set_attr "prefix" "orig,vex")
3542    (set_attr "mode" "SF")])
3543
3544 (define_expand "vec_dupv4sf"
3545   [(set (match_operand:V4SF 0 "register_operand" "")
3546         (vec_duplicate:V4SF
3547           (match_operand:SF 1 "nonimmediate_operand" "")))]
3548   "TARGET_SSE"
3549 {
3550   if (!TARGET_AVX)
3551     operands[1] = force_reg (SFmode, operands[1]);
3552 })
3553
3554 (define_insn "avx2_vec_dupv4sf"
3555   [(set (match_operand:V4SF 0 "register_operand" "=x")
3556         (vec_duplicate:V4SF
3557           (vec_select:SF
3558             (match_operand:V4SF 1 "register_operand" "x")
3559             (parallel [(const_int 0)]))))]
3560   "TARGET_AVX2"
3561   "vbroadcastss\t{%1, %0|%0, %1}"
3562   [(set_attr "type" "sselog1")
3563     (set_attr "prefix" "vex")
3564     (set_attr "mode" "V4SF")])
3565
3566 (define_insn "*vec_dupv4sf_avx"
3567   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3568         (vec_duplicate:V4SF
3569           (match_operand:SF 1 "nonimmediate_operand" "x,m")))]
3570   "TARGET_AVX"
3571   "@
3572    vshufps\t{$0, %1, %1, %0|%0, %1, %1, 0}
3573    vbroadcastss\t{%1, %0|%0, %1}"
3574   [(set_attr "type" "sselog1,ssemov")
3575    (set_attr "length_immediate" "1,0")
3576    (set_attr "prefix_extra" "0,1")
3577    (set_attr "prefix" "vex")
3578    (set_attr "mode" "V4SF")])
3579
3580 (define_insn "avx2_vec_dupv8sf"
3581   [(set (match_operand:V8SF 0 "register_operand" "=x")
3582         (vec_duplicate:V8SF
3583           (vec_select:SF
3584             (match_operand:V4SF 1 "register_operand" "x")
3585             (parallel [(const_int 0)]))))]
3586   "TARGET_AVX2"
3587   "vbroadcastss\t{%1, %0|%0, %1}"
3588   [(set_attr "type" "sselog1")
3589    (set_attr "prefix" "vex")
3590    (set_attr "mode" "V8SF")])
3591
3592 (define_insn "*vec_dupv4sf"
3593   [(set (match_operand:V4SF 0 "register_operand" "=x")
3594         (vec_duplicate:V4SF
3595           (match_operand:SF 1 "register_operand" "0")))]
3596   "TARGET_SSE"
3597   "shufps\t{$0, %0, %0|%0, %0, 0}"
3598   [(set_attr "type" "sselog1")
3599    (set_attr "length_immediate" "1")
3600    (set_attr "mode" "V4SF")])
3601
3602 ;; Although insertps takes register source, we prefer
3603 ;; unpcklps with register source since it is shorter.
3604 (define_insn "*vec_concatv2sf_sse4_1"
3605   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,x,x,x,*y ,*y")
3606         (vec_concat:V2SF
3607           (match_operand:SF 1 "nonimmediate_operand" " 0,x,0,x,m, 0 , m")
3608           (match_operand:SF 2 "vector_move_operand"  " x,x,m,m,C,*ym, C")))]
3609   "TARGET_SSE4_1"
3610   "@
3611    unpcklps\t{%2, %0|%0, %2}
3612    vunpcklps\t{%2, %1, %0|%0, %1, %2}
3613    insertps\t{$0x10, %2, %0|%0, %2, 0x10}
3614    vinsertps\t{$0x10, %2, %1, %0|%0, %1, %2, 0x10}
3615    %vmovss\t{%1, %0|%0, %1}
3616    punpckldq\t{%2, %0|%0, %2}
3617    movd\t{%1, %0|%0, %1}"
3618   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
3619    (set_attr "type" "sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
3620    (set_attr "prefix_data16" "*,*,1,*,*,*,*")
3621    (set_attr "prefix_extra" "*,*,1,1,*,*,*")
3622    (set_attr "length_immediate" "*,*,1,1,*,*,*")
3623    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
3624    (set_attr "mode" "V4SF,V4SF,V4SF,V4SF,SF,DI,DI")])
3625
3626 ;; ??? In theory we can match memory for the MMX alternative, but allowing
3627 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
3628 ;; alternatives pretty much forces the MMX alternative to be chosen.
3629 (define_insn "*vec_concatv2sf_sse"
3630   [(set (match_operand:V2SF 0 "register_operand"     "=x,x,*y,*y")
3631         (vec_concat:V2SF
3632           (match_operand:SF 1 "nonimmediate_operand" " 0,m, 0, m")
3633           (match_operand:SF 2 "reg_or_0_operand"     " x,C,*y, C")))]
3634   "TARGET_SSE"
3635   "@
3636    unpcklps\t{%2, %0|%0, %2}
3637    movss\t{%1, %0|%0, %1}
3638    punpckldq\t{%2, %0|%0, %2}
3639    movd\t{%1, %0|%0, %1}"
3640   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
3641    (set_attr "mode" "V4SF,SF,DI,DI")])
3642
3643 (define_insn "*vec_concatv4sf"
3644   [(set (match_operand:V4SF 0 "register_operand"       "=x,x,x,x")
3645         (vec_concat:V4SF
3646           (match_operand:V2SF 1 "register_operand"     " 0,x,0,x")
3647           (match_operand:V2SF 2 "nonimmediate_operand" " x,x,m,m")))]
3648   "TARGET_SSE"
3649   "@
3650    movlhps\t{%2, %0|%0, %2}
3651    vmovlhps\t{%2, %1, %0|%0, %1, %2}
3652    movhps\t{%2, %0|%0, %2}
3653    vmovhps\t{%2, %1, %0|%0, %1, %2}"
3654   [(set_attr "isa" "noavx,avx,noavx,avx")
3655    (set_attr "type" "ssemov")
3656    (set_attr "prefix" "orig,vex,orig,vex")
3657    (set_attr "mode" "V4SF,V4SF,V2SF,V2SF")])
3658
3659 (define_expand "vec_init<mode>"
3660   [(match_operand:V_128 0 "register_operand" "")
3661    (match_operand 1 "" "")]
3662   "TARGET_SSE"
3663 {
3664   ix86_expand_vector_init (false, operands[0], operands[1]);
3665   DONE;
3666 })
3667
3668 ;; Avoid combining registers from different units in a single alternative,
3669 ;; see comment above inline_secondary_memory_needed function in i386.c
3670 (define_insn "vec_set<mode>_0"
3671   [(set (match_operand:VI4F_128 0 "nonimmediate_operand"
3672           "=x,x,x ,x,x,x,x  ,x  ,m,m ,m")
3673         (vec_merge:VI4F_128
3674           (vec_duplicate:VI4F_128
3675             (match_operand:<ssescalarmode> 2 "general_operand"
3676           " x,m,*r,m,x,x,*rm,*rm,x,fF,*r"))
3677           (match_operand:VI4F_128 1 "vector_move_operand"
3678           " C,C,C ,C,0,x,0  ,x  ,0,0 ,0")
3679           (const_int 1)))]
3680   "TARGET_SSE"
3681   "@
3682    %vinsertps\t{$0xe, %d2, %0|%0, %d2, 0xe}
3683    %vmov<ssescalarmodesuffix>\t{%2, %0|%0, %2}
3684    %vmovd\t{%2, %0|%0, %2}
3685    movss\t{%2, %0|%0, %2}
3686    movss\t{%2, %0|%0, %2}
3687    vmovss\t{%2, %1, %0|%0, %1, %2}
3688    pinsrd\t{$0, %2, %0|%0, %2, 0}
3689    vpinsrd\t{$0, %2, %1, %0|%0, %1, %2, 0}
3690    #
3691    #
3692    #"
3693   [(set_attr "isa" "sse4,sse2,sse2,noavx,noavx,avx,sse4_noavx,avx,*,*,*")
3694    (set (attr "type")
3695      (cond [(eq_attr "alternative" "0,6,7")
3696               (const_string "sselog")
3697             (eq_attr "alternative" "9")
3698               (const_string "fmov")
3699             (eq_attr "alternative" "10")
3700               (const_string "imov")
3701            ]
3702            (const_string "ssemov")))
3703    (set_attr "prefix_extra" "*,*,*,*,*,*,1,1,*,*,*")
3704    (set_attr "length_immediate" "*,*,*,*,*,*,1,1,*,*,*")
3705    (set_attr "prefix" "maybe_vex,maybe_vex,maybe_vex,orig,orig,vex,orig,vex,*,*,*")
3706    (set_attr "mode" "SF,<ssescalarmode>,SI,SF,SF,SF,TI,TI,*,*,*")])
3707
3708 ;; A subset is vec_setv4sf.
3709 (define_insn "*vec_setv4sf_sse4_1"
3710   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3711         (vec_merge:V4SF
3712           (vec_duplicate:V4SF
3713             (match_operand:SF 2 "nonimmediate_operand" "xm,xm"))
3714           (match_operand:V4SF 1 "register_operand" "0,x")
3715           (match_operand:SI 3 "const_int_operand" "")))]
3716   "TARGET_SSE4_1
3717    && ((unsigned) exact_log2 (INTVAL (operands[3]))
3718        < GET_MODE_NUNITS (V4SFmode))"
3719 {
3720   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])) << 4);
3721   switch (which_alternative)
3722     {
3723     case 0:
3724       return "insertps\t{%3, %2, %0|%0, %2, %3}";
3725     case 1:
3726       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3727     default:
3728       gcc_unreachable ();
3729     }
3730 }
3731   [(set_attr "isa" "noavx,avx")
3732    (set_attr "type" "sselog")
3733    (set_attr "prefix_data16" "1,*")
3734    (set_attr "prefix_extra" "1")
3735    (set_attr "length_immediate" "1")
3736    (set_attr "prefix" "orig,vex")
3737    (set_attr "mode" "V4SF")])
3738
3739 (define_insn "sse4_1_insertps"
3740   [(set (match_operand:V4SF 0 "register_operand" "=x,x")
3741         (unspec:V4SF [(match_operand:V4SF 2 "nonimmediate_operand" "xm,xm")
3742                       (match_operand:V4SF 1 "register_operand" "0,x")
3743                       (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
3744                      UNSPEC_INSERTPS))]
3745   "TARGET_SSE4_1"
3746 {
3747   if (MEM_P (operands[2]))
3748     {
3749       unsigned count_s = INTVAL (operands[3]) >> 6;
3750       if (count_s)
3751         operands[3] = GEN_INT (INTVAL (operands[3]) & 0x3f);
3752       operands[2] = adjust_address_nv (operands[2], SFmode, count_s * 4);
3753     }
3754   switch (which_alternative)
3755     {
3756     case 0:
3757       return "insertps\t{%3, %2, %0|%0, %2, %3}";
3758     case 1:
3759       return "vinsertps\t{%3, %2, %1, %0|%0, %1, %2, %3}";
3760     default:
3761       gcc_unreachable ();
3762     }
3763 }
3764   [(set_attr "isa" "noavx,avx")
3765    (set_attr "type" "sselog")
3766    (set_attr "prefix_data16" "1,*")
3767    (set_attr "prefix_extra" "1")
3768    (set_attr "length_immediate" "1")
3769    (set_attr "prefix" "orig,vex")
3770    (set_attr "mode" "V4SF")])
3771
3772 (define_split
3773   [(set (match_operand:VI4F_128 0 "memory_operand" "")
3774         (vec_merge:VI4F_128
3775           (vec_duplicate:VI4F_128
3776             (match_operand:<ssescalarmode> 1 "nonmemory_operand" ""))
3777           (match_dup 0)
3778           (const_int 1)))]
3779   "TARGET_SSE && reload_completed"
3780   [(const_int 0)]
3781 {
3782   emit_move_insn (adjust_address (operands[0], <ssescalarmode>mode, 0),
3783                   operands[1]);
3784   DONE;
3785 })
3786
3787 (define_expand "vec_set<mode>"
3788   [(match_operand:V_128 0 "register_operand" "")
3789    (match_operand:<ssescalarmode> 1 "register_operand" "")
3790    (match_operand 2 "const_int_operand" "")]
3791   "TARGET_SSE"
3792 {
3793   ix86_expand_vector_set (false, operands[0], operands[1],
3794                           INTVAL (operands[2]));
3795   DONE;
3796 })
3797
3798 (define_insn_and_split "*vec_extractv4sf_0"
3799   [(set (match_operand:SF 0 "nonimmediate_operand" "=x,m,f,r")
3800         (vec_select:SF
3801           (match_operand:V4SF 1 "nonimmediate_operand" "xm,x,m,m")
3802           (parallel [(const_int 0)])))]
3803   "TARGET_SSE && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3804   "#"
3805   "&& reload_completed"
3806   [(const_int 0)]
3807 {
3808   rtx op1 = operands[1];
3809   if (REG_P (op1))
3810     op1 = gen_rtx_REG (SFmode, REGNO (op1));
3811   else
3812     op1 = gen_lowpart (SFmode, op1);
3813   emit_move_insn (operands[0], op1);
3814   DONE;
3815 })
3816
3817 (define_expand "avx_vextractf128<mode>"
3818   [(match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "")
3819    (match_operand:V_256 1 "register_operand" "")
3820    (match_operand:SI 2 "const_0_to_1_operand" "")]
3821   "TARGET_AVX"
3822 {
3823   rtx (*insn)(rtx, rtx);
3824
3825   switch (INTVAL (operands[2]))
3826     {
3827     case 0:
3828       insn = gen_vec_extract_lo_<mode>;
3829       break;
3830     case 1:
3831       insn = gen_vec_extract_hi_<mode>;
3832       break;
3833     default:
3834       gcc_unreachable ();
3835     }
3836
3837   emit_insn (insn (operands[0], operands[1]));
3838   DONE;
3839 })
3840
3841 (define_insn_and_split "vec_extract_lo_<mode>"
3842   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
3843         (vec_select:<ssehalfvecmode>
3844           (match_operand:VI8F_256 1 "nonimmediate_operand" "xm,x")
3845           (parallel [(const_int 0) (const_int 1)])))]
3846   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3847   "#"
3848   "&& reload_completed"
3849   [(const_int 0)]
3850 {
3851   rtx op1 = operands[1];
3852   if (REG_P (op1))
3853     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
3854   else
3855     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
3856   emit_move_insn (operands[0], op1);
3857   DONE;
3858 })
3859
3860 (define_insn "vec_extract_hi_<mode>"
3861   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
3862         (vec_select:<ssehalfvecmode>
3863           (match_operand:VI8F_256 1 "register_operand" "x,x")
3864           (parallel [(const_int 2) (const_int 3)])))]
3865   "TARGET_AVX"
3866 {
3867   if (get_attr_mode (insn) == MODE_OI)
3868     return "vextracti128\t{$0x1, %1, %0|%0, %1, 0x1}";
3869   else
3870     return "vextractf128\t{$0x1, %1, %0|%0, %1, 0x1}";
3871 }
3872   [(set_attr "type" "sselog")
3873    (set_attr "prefix_extra" "1")
3874    (set_attr "length_immediate" "1")
3875    (set_attr "memory" "none,store")
3876    (set_attr "prefix" "vex")
3877    (set (attr "mode")
3878      (if_then_else
3879        (and (match_test "TARGET_AVX2")
3880             (eq (const_string "<MODE>mode") (const_string "V4DImode")))
3881      (const_string "OI")
3882      (const_string "V4DF")))])
3883
3884 (define_insn_and_split "vec_extract_lo_<mode>"
3885   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
3886         (vec_select:<ssehalfvecmode>
3887           (match_operand:VI4F_256 1 "nonimmediate_operand" "xm,x")
3888           (parallel [(const_int 0) (const_int 1)
3889                      (const_int 2) (const_int 3)])))]
3890   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3891   "#"
3892   "&& reload_completed"
3893   [(const_int 0)]
3894 {
3895   rtx op1 = operands[1];
3896   if (REG_P (op1))
3897     op1 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op1));
3898   else
3899     op1 = gen_lowpart (<ssehalfvecmode>mode, op1);
3900   emit_move_insn (operands[0], op1);
3901   DONE;
3902 })
3903
3904 (define_insn "vec_extract_hi_<mode>"
3905   [(set (match_operand:<ssehalfvecmode> 0 "nonimmediate_operand" "=x,m")
3906         (vec_select:<ssehalfvecmode>
3907           (match_operand:VI4F_256 1 "register_operand" "x,x")
3908           (parallel [(const_int 4) (const_int 5)
3909                      (const_int 6) (const_int 7)])))]
3910   "TARGET_AVX"
3911 {
3912   if (get_attr_mode (insn) == MODE_OI)
3913     return "vextracti128\t{$0x1, %1, %0|%0, %1, 0x1}";
3914   else
3915     return "vextractf128\t{$0x1, %1, %0|%0, %1, 0x1}";
3916 }
3917   [(set_attr "type" "sselog")
3918    (set_attr "prefix_extra" "1")
3919    (set_attr "length_immediate" "1")
3920    (set_attr "memory" "none,store")
3921    (set_attr "prefix" "vex")
3922    (set (attr "mode")
3923      (if_then_else
3924        (and (match_test "TARGET_AVX2")
3925             (eq (const_string "<MODE>mode") (const_string "V8SImode")))
3926      (const_string "OI")
3927      (const_string "V8SF")))])
3928
3929 (define_insn_and_split "vec_extract_lo_v16hi"
3930   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
3931         (vec_select:V8HI
3932           (match_operand:V16HI 1 "nonimmediate_operand" "xm,x")
3933           (parallel [(const_int 0) (const_int 1)
3934                      (const_int 2) (const_int 3)
3935                      (const_int 4) (const_int 5)
3936                      (const_int 6) (const_int 7)])))]
3937   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3938   "#"
3939   "&& reload_completed"
3940   [(const_int 0)]
3941 {
3942   rtx op1 = operands[1];
3943   if (REG_P (op1))
3944     op1 = gen_rtx_REG (V8HImode, REGNO (op1));
3945   else
3946     op1 = gen_lowpart (V8HImode, op1);
3947   emit_move_insn (operands[0], op1);
3948   DONE;
3949 })
3950
3951 (define_insn "vec_extract_hi_v16hi"
3952   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=x,m")
3953         (vec_select:V8HI
3954           (match_operand:V16HI 1 "register_operand" "x,x")
3955           (parallel [(const_int 8) (const_int 9)
3956                      (const_int 10) (const_int 11)
3957                      (const_int 12) (const_int 13)
3958                      (const_int 14) (const_int 15)])))]
3959   "TARGET_AVX"
3960 {
3961   if (get_attr_mode (insn) == MODE_OI)
3962     return "vextracti128\t{$0x1, %1, %0|%0, %1, 0x1}";
3963   else
3964     return "vextractf128\t{$0x1, %1, %0|%0, %1, 0x1}";
3965 }
3966   [(set_attr "type" "sselog")
3967    (set_attr "prefix_extra" "1")
3968    (set_attr "length_immediate" "1")
3969    (set_attr "memory" "none,store")
3970    (set_attr "prefix" "vex")
3971    (set (attr "mode")
3972      (if_then_else (match_test "TARGET_AVX2")
3973    (const_string "OI")
3974    (const_string "V8SF")))])
3975
3976 (define_insn_and_split "vec_extract_lo_v32qi"
3977   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
3978         (vec_select:V16QI
3979           (match_operand:V32QI 1 "nonimmediate_operand" "xm,x")
3980           (parallel [(const_int 0) (const_int 1)
3981                      (const_int 2) (const_int 3)
3982                      (const_int 4) (const_int 5)
3983                      (const_int 6) (const_int 7)
3984                      (const_int 8) (const_int 9)
3985                      (const_int 10) (const_int 11)
3986                      (const_int 12) (const_int 13)
3987                      (const_int 14) (const_int 15)])))]
3988   "TARGET_AVX && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
3989   "#"
3990   "&& reload_completed"
3991   [(const_int 0)]
3992 {
3993   rtx op1 = operands[1];
3994   if (REG_P (op1))
3995     op1 = gen_rtx_REG (V16QImode, REGNO (op1));
3996   else
3997     op1 = gen_lowpart (V16QImode, op1);
3998   emit_move_insn (operands[0], op1);
3999   DONE;
4000 })
4001
4002 (define_insn "vec_extract_hi_v32qi"
4003   [(set (match_operand:V16QI 0 "nonimmediate_operand" "=x,m")
4004         (vec_select:V16QI
4005           (match_operand:V32QI 1 "register_operand" "x,x")
4006           (parallel [(const_int 16) (const_int 17)
4007                      (const_int 18) (const_int 19)
4008                      (const_int 20) (const_int 21)
4009                      (const_int 22) (const_int 23)
4010                      (const_int 24) (const_int 25)
4011                      (const_int 26) (const_int 27)
4012                      (const_int 28) (const_int 29)
4013                      (const_int 30) (const_int 31)])))]
4014   "TARGET_AVX"
4015 {
4016   if (get_attr_mode (insn) == MODE_OI)
4017     return "vextracti128\t{$0x1, %1, %0|%0, %1, 0x1}";
4018   else
4019     return "vextractf128\t{$0x1, %1, %0|%0, %1, 0x1}";
4020 }
4021   [(set_attr "type" "sselog")
4022    (set_attr "prefix_extra" "1")
4023    (set_attr "length_immediate" "1")
4024    (set_attr "memory" "none,store")
4025    (set_attr "prefix" "vex")
4026    (set (attr "mode")
4027      (if_then_else (match_test "TARGET_AVX2")
4028    (const_string "OI")
4029    (const_string "V8SF")))])
4030
4031 (define_insn "*sse4_1_extractps"
4032   [(set (match_operand:SF 0 "nonimmediate_operand" "=rm")
4033         (vec_select:SF
4034           (match_operand:V4SF 1 "register_operand" "x")
4035           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")])))]
4036   "TARGET_SSE4_1"
4037   "%vextractps\t{%2, %1, %0|%0, %1, %2}"
4038   [(set_attr "type" "sselog")
4039    (set_attr "prefix_data16" "1")
4040    (set_attr "prefix_extra" "1")
4041    (set_attr "length_immediate" "1")
4042    (set_attr "prefix" "maybe_vex")
4043    (set_attr "mode" "V4SF")])
4044
4045 (define_insn_and_split "*vec_extract_v4sf_mem"
4046   [(set (match_operand:SF 0 "register_operand" "=x*rf")
4047        (vec_select:SF
4048          (match_operand:V4SF 1 "memory_operand" "o")
4049          (parallel [(match_operand 2 "const_0_to_3_operand" "n")])))]
4050   "TARGET_SSE"
4051   "#"
4052   "&& reload_completed"
4053   [(const_int 0)]
4054 {
4055   int i = INTVAL (operands[2]);
4056
4057   emit_move_insn (operands[0], adjust_address (operands[1], SFmode, i*4));
4058   DONE;
4059 })
4060
4061 ;; Modes handled by vec_extract patterns.
4062 (define_mode_iterator VEC_EXTRACT_MODE
4063   [(V32QI "TARGET_AVX") V16QI
4064    (V16HI "TARGET_AVX") V8HI
4065    (V8SI "TARGET_AVX") V4SI
4066    (V4DI "TARGET_AVX") V2DI
4067    (V8SF "TARGET_AVX") V4SF
4068    (V4DF "TARGET_AVX") V2DF])
4069
4070 (define_expand "vec_extract<mode>"
4071   [(match_operand:<ssescalarmode> 0 "register_operand" "")
4072    (match_operand:VEC_EXTRACT_MODE 1 "register_operand" "")
4073    (match_operand 2 "const_int_operand" "")]
4074   "TARGET_SSE"
4075 {
4076   ix86_expand_vector_extract (false, operands[0], operands[1],
4077                               INTVAL (operands[2]));
4078   DONE;
4079 })
4080
4081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4082 ;;
4083 ;; Parallel double-precision floating point element swizzling
4084 ;;
4085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4086
4087 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
4088 (define_insn "avx_unpckhpd256"
4089   [(set (match_operand:V4DF 0 "register_operand" "=x")
4090         (vec_select:V4DF
4091           (vec_concat:V8DF
4092             (match_operand:V4DF 1 "register_operand" "x")
4093             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4094           (parallel [(const_int 1) (const_int 5)
4095                      (const_int 3) (const_int 7)])))]
4096   "TARGET_AVX"
4097   "vunpckhpd\t{%2, %1, %0|%0, %1, %2}"
4098   [(set_attr "type" "sselog")
4099    (set_attr "prefix" "vex")
4100    (set_attr "mode" "V4DF")])
4101
4102 (define_expand "vec_interleave_highv4df"
4103   [(set (match_dup 3)
4104         (vec_select:V4DF
4105           (vec_concat:V8DF
4106             (match_operand:V4DF 1 "register_operand" "x")
4107             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4108           (parallel [(const_int 0) (const_int 4)
4109                      (const_int 2) (const_int 6)])))
4110    (set (match_dup 4)
4111         (vec_select:V4DF
4112           (vec_concat:V8DF
4113             (match_dup 1)
4114             (match_dup 2))
4115           (parallel [(const_int 1) (const_int 5)
4116                      (const_int 3) (const_int 7)])))
4117    (set (match_operand:V4DF 0 "register_operand" "")
4118         (vec_select:V4DF
4119           (vec_concat:V8DF
4120             (match_dup 3)
4121             (match_dup 4))
4122           (parallel [(const_int 2) (const_int 3)
4123                      (const_int 6) (const_int 7)])))]
4124  "TARGET_AVX"
4125 {
4126   operands[3] = gen_reg_rtx (V4DFmode);
4127   operands[4] = gen_reg_rtx (V4DFmode);
4128 })
4129
4130
4131 (define_expand "vec_interleave_highv2df"
4132   [(set (match_operand:V2DF 0 "register_operand" "")
4133         (vec_select:V2DF
4134           (vec_concat:V4DF
4135             (match_operand:V2DF 1 "nonimmediate_operand" "")
4136             (match_operand:V2DF 2 "nonimmediate_operand" ""))
4137           (parallel [(const_int 1)
4138                      (const_int 3)])))]
4139   "TARGET_SSE2"
4140 {
4141   if (!ix86_vec_interleave_v2df_operator_ok (operands, 1))
4142     operands[2] = force_reg (V2DFmode, operands[2]);
4143 })
4144
4145 (define_insn "*vec_interleave_highv2df"
4146   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,m")
4147         (vec_select:V2DF
4148           (vec_concat:V4DF
4149             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,o,o,o,x")
4150             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,0,x,0"))
4151           (parallel [(const_int 1)
4152                      (const_int 3)])))]
4153   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 1)"
4154   "@
4155    unpckhpd\t{%2, %0|%0, %2}
4156    vunpckhpd\t{%2, %1, %0|%0, %1, %2}
4157    %vmovddup\t{%H1, %0|%0, %H1}
4158    movlpd\t{%H1, %0|%0, %H1}
4159    vmovlpd\t{%H1, %2, %0|%0, %2, %H1}
4160    %vmovhpd\t{%1, %0|%0, %1}"
4161   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
4162   (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
4163    (set_attr "prefix_data16" "*,*,*,1,*,1")
4164    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
4165    (set_attr "mode" "V2DF,V2DF,V2DF,V1DF,V1DF,V1DF")])
4166
4167 ;; Recall that the 256-bit unpck insns only shuffle within their lanes.
4168 (define_expand "avx_movddup256"
4169   [(set (match_operand:V4DF 0 "register_operand" "")
4170         (vec_select:V4DF
4171           (vec_concat:V8DF
4172             (match_operand:V4DF 1 "nonimmediate_operand" "")
4173             (match_dup 1))
4174           (parallel [(const_int 0) (const_int 4)
4175                      (const_int 2) (const_int 6)])))]
4176   "TARGET_AVX")
4177
4178 (define_expand "avx_unpcklpd256"
4179   [(set (match_operand:V4DF 0 "register_operand" "")
4180         (vec_select:V4DF
4181           (vec_concat:V8DF
4182             (match_operand:V4DF 1 "register_operand" "")
4183             (match_operand:V4DF 2 "nonimmediate_operand" ""))
4184           (parallel [(const_int 0) (const_int 4)
4185                      (const_int 2) (const_int 6)])))]
4186   "TARGET_AVX")
4187
4188 (define_insn "*avx_unpcklpd256"
4189   [(set (match_operand:V4DF 0 "register_operand"         "=x,x")
4190         (vec_select:V4DF
4191           (vec_concat:V8DF
4192             (match_operand:V4DF 1 "nonimmediate_operand" "xm,x")
4193             (match_operand:V4DF 2 "nonimmediate_operand" " 1,xm"))
4194           (parallel [(const_int 0) (const_int 4)
4195                      (const_int 2) (const_int 6)])))]
4196   "TARGET_AVX
4197    && (!MEM_P (operands[1]) || rtx_equal_p (operands[1], operands[2]))"
4198   "@
4199    vmovddup\t{%1, %0|%0, %1}
4200    vunpcklpd\t{%2, %1, %0|%0, %1, %2}"
4201   [(set_attr "type" "sselog")
4202    (set_attr "prefix" "vex")
4203    (set_attr "mode" "V4DF")])
4204
4205 (define_expand "vec_interleave_lowv4df"
4206   [(set (match_dup 3)
4207         (vec_select:V4DF
4208           (vec_concat:V8DF
4209             (match_operand:V4DF 1 "register_operand" "x")
4210             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4211           (parallel [(const_int 0) (const_int 4)
4212                      (const_int 2) (const_int 6)])))
4213    (set (match_dup 4)
4214         (vec_select:V4DF
4215           (vec_concat:V8DF
4216             (match_dup 1)
4217             (match_dup 2))
4218           (parallel [(const_int 1) (const_int 5)
4219                      (const_int 3) (const_int 7)])))
4220    (set (match_operand:V4DF 0 "register_operand" "")
4221         (vec_select:V4DF
4222           (vec_concat:V8DF
4223             (match_dup 3)
4224             (match_dup 4))
4225           (parallel [(const_int 0) (const_int 1)
4226                      (const_int 4) (const_int 5)])))]
4227  "TARGET_AVX"
4228 {
4229   operands[3] = gen_reg_rtx (V4DFmode);
4230   operands[4] = gen_reg_rtx (V4DFmode);
4231 })
4232
4233 (define_expand "vec_interleave_lowv2df"
4234   [(set (match_operand:V2DF 0 "register_operand" "")
4235         (vec_select:V2DF
4236           (vec_concat:V4DF
4237             (match_operand:V2DF 1 "nonimmediate_operand" "")
4238             (match_operand:V2DF 2 "nonimmediate_operand" ""))
4239           (parallel [(const_int 0)
4240                      (const_int 2)])))]
4241   "TARGET_SSE2"
4242 {
4243   if (!ix86_vec_interleave_v2df_operator_ok (operands, 0))
4244     operands[1] = force_reg (V2DFmode, operands[1]);
4245 })
4246
4247 (define_insn "*vec_interleave_lowv2df"
4248   [(set (match_operand:V2DF 0 "nonimmediate_operand"     "=x,x,x,x,x,o")
4249         (vec_select:V2DF
4250           (vec_concat:V4DF
4251             (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,m,0,x,0")
4252             (match_operand:V2DF 2 "nonimmediate_operand" " x,x,1,m,m,x"))
4253           (parallel [(const_int 0)
4254                      (const_int 2)])))]
4255   "TARGET_SSE2 && ix86_vec_interleave_v2df_operator_ok (operands, 0)"
4256   "@
4257    unpcklpd\t{%2, %0|%0, %2}
4258    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4259    %vmovddup\t{%1, %0|%0, %1}
4260    movhpd\t{%2, %0|%0, %2}
4261    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4262    %vmovlpd\t{%2, %H0|%H0, %2}"
4263   [(set_attr "isa" "noavx,avx,sse3,noavx,avx,*")
4264    (set_attr "type" "sselog,sselog,sselog,ssemov,ssemov,ssemov")
4265    (set_attr "prefix_data16" "*,*,*,1,*,1")
4266    (set_attr "prefix" "orig,vex,maybe_vex,orig,vex,maybe_vex")
4267    (set_attr "mode" "V2DF,V2DF,V2DF,V1DF,V1DF,V1DF")])
4268
4269 (define_split
4270   [(set (match_operand:V2DF 0 "memory_operand" "")
4271         (vec_select:V2DF
4272           (vec_concat:V4DF
4273             (match_operand:V2DF 1 "register_operand" "")
4274             (match_dup 1))
4275           (parallel [(const_int 0)
4276                      (const_int 2)])))]
4277   "TARGET_SSE3 && reload_completed"
4278   [(const_int 0)]
4279 {
4280   rtx low = gen_rtx_REG (DFmode, REGNO (operands[1]));
4281   emit_move_insn (adjust_address (operands[0], DFmode, 0), low);
4282   emit_move_insn (adjust_address (operands[0], DFmode, 8), low);
4283   DONE;
4284 })
4285
4286 (define_split
4287   [(set (match_operand:V2DF 0 "register_operand" "")
4288         (vec_select:V2DF
4289           (vec_concat:V4DF
4290             (match_operand:V2DF 1 "memory_operand" "")
4291             (match_dup 1))
4292           (parallel [(match_operand:SI 2 "const_0_to_1_operand" "")
4293                      (match_operand:SI 3 "const_int_operand" "")])))]
4294   "TARGET_SSE3 && INTVAL (operands[2]) + 2 == INTVAL (operands[3])"
4295   [(set (match_dup 0) (vec_duplicate:V2DF (match_dup 1)))]
4296 {
4297   operands[1] = adjust_address (operands[1], DFmode, INTVAL (operands[2]) * 8);
4298 })
4299
4300 (define_expand "avx_shufpd256"
4301   [(match_operand:V4DF 0 "register_operand" "")
4302    (match_operand:V4DF 1 "register_operand" "")
4303    (match_operand:V4DF 2 "nonimmediate_operand" "")
4304    (match_operand:SI 3 "const_int_operand" "")]
4305   "TARGET_AVX"
4306 {
4307   int mask = INTVAL (operands[3]);
4308   emit_insn (gen_avx_shufpd256_1 (operands[0], operands[1], operands[2],
4309                                    GEN_INT (mask & 1),
4310                                    GEN_INT (mask & 2 ? 5 : 4),
4311                                    GEN_INT (mask & 4 ? 3 : 2),
4312                                    GEN_INT (mask & 8 ? 7 : 6)));
4313   DONE;
4314 })
4315
4316 (define_insn "avx_shufpd256_1"
4317   [(set (match_operand:V4DF 0 "register_operand" "=x")
4318         (vec_select:V4DF
4319           (vec_concat:V8DF
4320             (match_operand:V4DF 1 "register_operand" "x")
4321             (match_operand:V4DF 2 "nonimmediate_operand" "xm"))
4322           (parallel [(match_operand 3 "const_0_to_1_operand" "")
4323                      (match_operand 4 "const_4_to_5_operand" "")
4324                      (match_operand 5 "const_2_to_3_operand" "")
4325                      (match_operand 6 "const_6_to_7_operand" "")])))]
4326   "TARGET_AVX"
4327 {
4328   int mask;
4329   mask = INTVAL (operands[3]);
4330   mask |= (INTVAL (operands[4]) - 4) << 1;
4331   mask |= (INTVAL (operands[5]) - 2) << 2;
4332   mask |= (INTVAL (operands[6]) - 6) << 3;
4333   operands[3] = GEN_INT (mask);
4334
4335   return "vshufpd\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4336 }
4337   [(set_attr "type" "sselog")
4338    (set_attr "length_immediate" "1")
4339    (set_attr "prefix" "vex")
4340    (set_attr "mode" "V4DF")])
4341
4342 (define_expand "sse2_shufpd"
4343   [(match_operand:V2DF 0 "register_operand" "")
4344    (match_operand:V2DF 1 "register_operand" "")
4345    (match_operand:V2DF 2 "nonimmediate_operand" "")
4346    (match_operand:SI 3 "const_int_operand" "")]
4347   "TARGET_SSE2"
4348 {
4349   int mask = INTVAL (operands[3]);
4350   emit_insn (gen_sse2_shufpd_v2df (operands[0], operands[1], operands[2],
4351                                 GEN_INT (mask & 1),
4352                                 GEN_INT (mask & 2 ? 3 : 2)));
4353   DONE;
4354 })
4355
4356 ;; Modes handled by vec_extract_even/odd pattern.
4357 (define_mode_iterator VEC_EXTRACT_EVENODD_MODE
4358   [(V16QI "TARGET_SSE2")
4359    (V8HI "TARGET_SSE2")
4360    (V4SI "TARGET_SSE2")
4361    (V2DI "TARGET_SSE2")
4362    (V8SF "TARGET_AVX") V4SF
4363    (V4DF "TARGET_AVX") (V2DF "TARGET_SSE2")])
4364
4365 (define_expand "vec_extract_even<mode>"
4366   [(match_operand:VEC_EXTRACT_EVENODD_MODE 0 "register_operand" "")
4367    (match_operand:VEC_EXTRACT_EVENODD_MODE 1 "register_operand" "")
4368    (match_operand:VEC_EXTRACT_EVENODD_MODE 2 "register_operand" "")]
4369   "TARGET_SSE"
4370 {
4371   ix86_expand_vec_extract_even_odd (operands[0], operands[1], operands[2], 0);
4372   DONE;
4373 })
4374
4375 (define_expand "vec_extract_odd<mode>"
4376   [(match_operand:VEC_EXTRACT_EVENODD_MODE 0 "register_operand" "")
4377    (match_operand:VEC_EXTRACT_EVENODD_MODE 1 "register_operand" "")
4378    (match_operand:VEC_EXTRACT_EVENODD_MODE 2 "register_operand" "")]
4379   "TARGET_SSE"
4380 {
4381   ix86_expand_vec_extract_even_odd (operands[0], operands[1], operands[2], 1);
4382   DONE;
4383 })
4384
4385 ;; punpcklqdq and punpckhqdq are shorter than shufpd.
4386 (define_insn "avx2_interleave_highv4di"
4387   [(set (match_operand:V4DI 0 "register_operand" "=x")
4388         (vec_select:V4DI
4389           (vec_concat:V8DI
4390             (match_operand:V4DI 1 "register_operand" "x")
4391             (match_operand:V4DI 2 "nonimmediate_operand" "xm"))
4392           (parallel [(const_int 1)
4393                      (const_int 5)
4394                      (const_int 3)
4395                      (const_int 7)])))]
4396   "TARGET_AVX2"
4397   "vpunpckhqdq\t{%2, %1, %0|%0, %1, %2}"
4398   [(set_attr "type" "sselog")
4399    (set_attr "prefix" "vex")
4400    (set_attr "mode" "OI")])
4401
4402 (define_insn "vec_interleave_highv2di"
4403   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
4404         (vec_select:V2DI
4405           (vec_concat:V4DI
4406             (match_operand:V2DI 1 "register_operand" "0,x")
4407             (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm"))
4408           (parallel [(const_int 1)
4409                      (const_int 3)])))]
4410   "TARGET_SSE2"
4411   "@
4412    punpckhqdq\t{%2, %0|%0, %2}
4413    vpunpckhqdq\t{%2, %1, %0|%0, %1, %2}"
4414   [(set_attr "isa" "noavx,avx")
4415    (set_attr "type" "sselog")
4416    (set_attr "prefix_data16" "1,*")
4417    (set_attr "prefix" "orig,vex")
4418    (set_attr "mode" "TI")])
4419
4420 (define_insn "avx2_interleave_lowv4di"
4421   [(set (match_operand:V4DI 0 "register_operand" "=x")
4422         (vec_select:V4DI
4423           (vec_concat:V8DI
4424             (match_operand:V4DI 1 "register_operand" "x")
4425             (match_operand:V4DI 2 "nonimmediate_operand" "xm"))
4426           (parallel [(const_int 0)
4427                      (const_int 4)
4428                      (const_int 2)
4429                      (const_int 6)])))]
4430   "TARGET_AVX2"
4431   "vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}"
4432   [(set_attr "type" "sselog")
4433    (set_attr "prefix" "vex")
4434    (set_attr "mode" "OI")])
4435
4436 (define_insn "vec_interleave_lowv2di"
4437   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
4438         (vec_select:V2DI
4439           (vec_concat:V4DI
4440             (match_operand:V2DI 1 "register_operand" "0,x")
4441             (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm"))
4442           (parallel [(const_int 0)
4443                      (const_int 2)])))]
4444   "TARGET_SSE2"
4445   "@
4446    punpcklqdq\t{%2, %0|%0, %2}
4447    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}"
4448   [(set_attr "isa" "noavx,avx")
4449    (set_attr "type" "sselog")
4450    (set_attr "prefix_data16" "1,*")
4451    (set_attr "prefix" "orig,vex")
4452    (set_attr "mode" "TI")])
4453
4454 (define_insn "sse2_shufpd_<mode>"
4455   [(set (match_operand:VI8F_128 0 "register_operand" "=x,x")
4456         (vec_select:VI8F_128
4457           (vec_concat:<ssedoublevecmode>
4458             (match_operand:VI8F_128 1 "register_operand" "0,x")
4459             (match_operand:VI8F_128 2 "nonimmediate_operand" "xm,xm"))
4460           (parallel [(match_operand 3 "const_0_to_1_operand" "")
4461                      (match_operand 4 "const_2_to_3_operand" "")])))]
4462   "TARGET_SSE2"
4463 {
4464   int mask;
4465   mask = INTVAL (operands[3]);
4466   mask |= (INTVAL (operands[4]) - 2) << 1;
4467   operands[3] = GEN_INT (mask);
4468
4469   switch (which_alternative)
4470     {
4471     case 0:
4472       return "shufpd\t{%3, %2, %0|%0, %2, %3}";
4473     case 1:
4474       return "vshufpd\t{%3, %2, %1, %0|%0, %1, %2, %3}";
4475     default:
4476       gcc_unreachable ();
4477     }
4478 }
4479   [(set_attr "isa" "noavx,avx")
4480    (set_attr "type" "sselog")
4481    (set_attr "length_immediate" "1")
4482    (set_attr "prefix" "orig,vex")
4483    (set_attr "mode" "V2DF")])
4484
4485 ;; Avoid combining registers from different units in a single alternative,
4486 ;; see comment above inline_secondary_memory_needed function in i386.c
4487 (define_insn "sse2_storehpd"
4488   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,x,*f,r")
4489         (vec_select:DF
4490           (match_operand:V2DF 1 "nonimmediate_operand" " x,0,x,o,o,o")
4491           (parallel [(const_int 1)])))]
4492   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4493   "@
4494    %vmovhpd\t{%1, %0|%0, %1}
4495    unpckhpd\t%0, %0
4496    vunpckhpd\t{%d1, %0|%0, %d1}
4497    #
4498    #
4499    #"
4500   [(set_attr "isa" "*,noavx,avx,*,*,*")
4501    (set_attr "type" "ssemov,sselog1,sselog1,ssemov,fmov,imov")
4502    (set (attr "prefix_data16")
4503      (if_then_else
4504        (and (eq_attr "alternative" "0")
4505             (not (match_test "TARGET_AVX")))
4506        (const_string "1")
4507        (const_string "*")))
4508    (set_attr "prefix" "maybe_vex,orig,vex,*,*,*")
4509    (set_attr "mode" "V1DF,V1DF,V2DF,DF,DF,DF")])
4510
4511 (define_split
4512   [(set (match_operand:DF 0 "register_operand" "")
4513         (vec_select:DF
4514           (match_operand:V2DF 1 "memory_operand" "")
4515           (parallel [(const_int 1)])))]
4516   "TARGET_SSE2 && reload_completed"
4517   [(set (match_dup 0) (match_dup 1))]
4518   "operands[1] = adjust_address (operands[1], DFmode, 8);")
4519
4520 (define_insn "*vec_extractv2df_1_sse"
4521   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
4522         (vec_select:DF
4523           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,o")
4524           (parallel [(const_int 1)])))]
4525   "!TARGET_SSE2 && TARGET_SSE
4526    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4527   "@
4528    movhps\t{%1, %0|%0, %1}
4529    movhlps\t{%1, %0|%0, %1}
4530    movlps\t{%H1, %0|%0, %H1}"
4531   [(set_attr "type" "ssemov")
4532    (set_attr "mode" "V2SF,V4SF,V2SF")])
4533
4534 ;; Avoid combining registers from different units in a single alternative,
4535 ;; see comment above inline_secondary_memory_needed function in i386.c
4536 (define_insn "sse2_storelpd"
4537   [(set (match_operand:DF 0 "nonimmediate_operand"     "=m,x,x,*f,r")
4538         (vec_select:DF
4539           (match_operand:V2DF 1 "nonimmediate_operand" " x,x,m,m,m")
4540           (parallel [(const_int 0)])))]
4541   "TARGET_SSE2 && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4542   "@
4543    %vmovlpd\t{%1, %0|%0, %1}
4544    #
4545    #
4546    #
4547    #"
4548   [(set_attr "type" "ssemov,ssemov,ssemov,fmov,imov")
4549    (set_attr "prefix_data16" "1,*,*,*,*")
4550    (set_attr "prefix" "maybe_vex")
4551    (set_attr "mode" "V1DF,DF,DF,DF,DF")])
4552
4553 (define_split
4554   [(set (match_operand:DF 0 "register_operand" "")
4555         (vec_select:DF
4556           (match_operand:V2DF 1 "nonimmediate_operand" "")
4557           (parallel [(const_int 0)])))]
4558   "TARGET_SSE2 && reload_completed"
4559   [(const_int 0)]
4560 {
4561   rtx op1 = operands[1];
4562   if (REG_P (op1))
4563     op1 = gen_rtx_REG (DFmode, REGNO (op1));
4564   else
4565     op1 = gen_lowpart (DFmode, op1);
4566   emit_move_insn (operands[0], op1);
4567   DONE;
4568 })
4569
4570 (define_insn "*vec_extractv2df_0_sse"
4571   [(set (match_operand:DF 0 "nonimmediate_operand" "=m,x,x")
4572         (vec_select:DF
4573           (match_operand:V2DF 1 "nonimmediate_operand" "x,x,m")
4574           (parallel [(const_int 0)])))]
4575   "!TARGET_SSE2 && TARGET_SSE
4576    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
4577   "@
4578    movlps\t{%1, %0|%0, %1}
4579    movaps\t{%1, %0|%0, %1}
4580    movlps\t{%1, %0|%0, %1}"
4581   [(set_attr "type" "ssemov")
4582    (set_attr "mode" "V2SF,V4SF,V2SF")])
4583
4584 (define_expand "sse2_loadhpd_exp"
4585   [(set (match_operand:V2DF 0 "nonimmediate_operand" "")
4586         (vec_concat:V2DF
4587           (vec_select:DF
4588             (match_operand:V2DF 1 "nonimmediate_operand" "")
4589             (parallel [(const_int 0)]))
4590           (match_operand:DF 2 "nonimmediate_operand" "")))]
4591   "TARGET_SSE2"
4592 {
4593   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
4594
4595   emit_insn (gen_sse2_loadhpd (dst, operands[1], operands[2]));
4596
4597   /* Fix up the destination if needed.  */
4598   if (dst != operands[0])
4599     emit_move_insn (operands[0], dst);
4600
4601   DONE;
4602 })
4603
4604 ;; Avoid combining registers from different units in a single alternative,
4605 ;; see comment above inline_secondary_memory_needed function in i386.c
4606 (define_insn "sse2_loadhpd"
4607   [(set (match_operand:V2DF 0 "nonimmediate_operand"
4608           "=x,x,x,x,o,o ,o")
4609         (vec_concat:V2DF
4610           (vec_select:DF
4611             (match_operand:V2DF 1 "nonimmediate_operand"
4612           " 0,x,0,x,0,0 ,0")
4613             (parallel [(const_int 0)]))
4614           (match_operand:DF 2 "nonimmediate_operand"
4615           " m,m,x,x,x,*f,r")))]
4616   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
4617   "@
4618    movhpd\t{%2, %0|%0, %2}
4619    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4620    unpcklpd\t{%2, %0|%0, %2}
4621    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4622    #
4623    #
4624    #"
4625   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
4626    (set_attr "type" "ssemov,ssemov,sselog,sselog,ssemov,fmov,imov")
4627    (set_attr "prefix_data16" "1,*,*,*,*,*,*")
4628    (set_attr "prefix" "orig,vex,orig,vex,*,*,*")
4629    (set_attr "mode" "V1DF,V1DF,V2DF,V2DF,DF,DF,DF")])
4630
4631 (define_split
4632   [(set (match_operand:V2DF 0 "memory_operand" "")
4633         (vec_concat:V2DF
4634           (vec_select:DF (match_dup 0) (parallel [(const_int 0)]))
4635           (match_operand:DF 1 "register_operand" "")))]
4636   "TARGET_SSE2 && reload_completed"
4637   [(set (match_dup 0) (match_dup 1))]
4638   "operands[0] = adjust_address (operands[0], DFmode, 8);")
4639
4640 (define_expand "sse2_loadlpd_exp"
4641   [(set (match_operand:V2DF 0 "nonimmediate_operand" "")
4642         (vec_concat:V2DF
4643           (match_operand:DF 2 "nonimmediate_operand" "")
4644           (vec_select:DF
4645             (match_operand:V2DF 1 "nonimmediate_operand" "")
4646             (parallel [(const_int 1)]))))]
4647   "TARGET_SSE2"
4648 {
4649   rtx dst = ix86_fixup_binary_operands (UNKNOWN, V2DFmode, operands);
4650
4651   emit_insn (gen_sse2_loadlpd (dst, operands[1], operands[2]));
4652
4653   /* Fix up the destination if needed.  */
4654   if (dst != operands[0])
4655     emit_move_insn (operands[0], dst);
4656
4657   DONE;
4658 })
4659
4660 ;; Avoid combining registers from different units in a single alternative,
4661 ;; see comment above inline_secondary_memory_needed function in i386.c
4662 (define_insn "sse2_loadlpd"
4663   [(set (match_operand:V2DF 0 "nonimmediate_operand"
4664           "=x,x,x,x,x,x,x,x,m,m ,m")
4665         (vec_concat:V2DF
4666           (match_operand:DF 2 "nonimmediate_operand"
4667           " m,m,m,x,x,0,0,x,x,*f,r")
4668           (vec_select:DF
4669             (match_operand:V2DF 1 "vector_move_operand"
4670           " C,0,x,0,x,x,o,o,0,0 ,0")
4671             (parallel [(const_int 1)]))))]
4672   "TARGET_SSE2 && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
4673   "@
4674    %vmovsd\t{%2, %0|%0, %2}
4675    movlpd\t{%2, %0|%0, %2}
4676    vmovlpd\t{%2, %1, %0|%0, %1, %2}
4677    movsd\t{%2, %0|%0, %2}
4678    vmovsd\t{%2, %1, %0|%0, %1, %2}
4679    shufpd\t{$2, %1, %0|%0, %1, 2}
4680    movhpd\t{%H1, %0|%0, %H1}
4681    vmovhpd\t{%H1, %2, %0|%0, %2, %H1}
4682    #
4683    #
4684    #"
4685   [(set_attr "isa" "*,noavx,avx,noavx,avx,noavx,noavx,avx,*,*,*")
4686    (set (attr "type")
4687      (cond [(eq_attr "alternative" "5")
4688               (const_string "sselog")
4689             (eq_attr "alternative" "9")
4690               (const_string "fmov")
4691             (eq_attr "alternative" "10")
4692               (const_string "imov")
4693            ]
4694            (const_string "ssemov")))
4695    (set_attr "prefix_data16" "*,1,*,*,*,*,1,*,*,*,*")
4696    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*,*,*")
4697    (set_attr "prefix" "maybe_vex,orig,vex,orig,vex,orig,orig,vex,*,*,*")
4698    (set_attr "mode" "DF,V1DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,DF,DF,DF")])
4699
4700 (define_split
4701   [(set (match_operand:V2DF 0 "memory_operand" "")
4702         (vec_concat:V2DF
4703           (match_operand:DF 1 "register_operand" "")
4704           (vec_select:DF (match_dup 0) (parallel [(const_int 1)]))))]
4705   "TARGET_SSE2 && reload_completed"
4706   [(set (match_dup 0) (match_dup 1))]
4707   "operands[0] = adjust_address (operands[0], DFmode, 8);")
4708
4709 (define_insn "sse2_movsd"
4710   [(set (match_operand:V2DF 0 "nonimmediate_operand"   "=x,x,x,x,m,x,x,x,o")
4711         (vec_merge:V2DF
4712           (match_operand:V2DF 2 "nonimmediate_operand" " x,x,m,m,x,0,0,x,0")
4713           (match_operand:V2DF 1 "nonimmediate_operand" " 0,x,0,x,0,x,o,o,x")
4714           (const_int 1)))]
4715   "TARGET_SSE2"
4716   "@
4717    movsd\t{%2, %0|%0, %2}
4718    vmovsd\t{%2, %1, %0|%0, %1, %2}
4719    movlpd\t{%2, %0|%0, %2}
4720    vmovlpd\t{%2, %1, %0|%0, %1, %2}
4721    %vmovlpd\t{%2, %0|%0, %2}
4722    shufpd\t{$2, %1, %0|%0, %1, 2}
4723    movhps\t{%H1, %0|%0, %H1}
4724    vmovhps\t{%H1, %2, %0|%0, %2, %H1}
4725    %vmovhps\t{%1, %H0|%H0, %1}"
4726   [(set_attr "isa" "noavx,avx,noavx,avx,*,noavx,noavx,avx,*")
4727    (set (attr "type")
4728      (if_then_else
4729        (eq_attr "alternative" "5")
4730        (const_string "sselog")
4731        (const_string "ssemov")))
4732    (set (attr "prefix_data16")
4733      (if_then_else
4734        (and (eq_attr "alternative" "2,4")
4735             (not (match_test "TARGET_AVX")))
4736        (const_string "1")
4737        (const_string "*")))
4738    (set_attr "length_immediate" "*,*,*,*,*,1,*,*,*")
4739    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig,vex,maybe_vex")
4740    (set_attr "mode" "DF,DF,V1DF,V1DF,V1DF,V2DF,V1DF,V1DF,V1DF")])
4741
4742 (define_expand "vec_dupv2df"
4743   [(set (match_operand:V2DF 0 "register_operand" "")
4744         (vec_duplicate:V2DF
4745           (match_operand:DF 1 "nonimmediate_operand" "")))]
4746   "TARGET_SSE2"
4747 {
4748   if (!TARGET_SSE3)
4749     operands[1] = force_reg (DFmode, operands[1]);
4750 })
4751
4752 (define_insn "*vec_dupv2df_sse3"
4753   [(set (match_operand:V2DF 0 "register_operand" "=x")
4754         (vec_duplicate:V2DF
4755           (match_operand:DF 1 "nonimmediate_operand" "xm")))]
4756   "TARGET_SSE3"
4757   "%vmovddup\t{%1, %0|%0, %1}"
4758   [(set_attr "type" "sselog1")
4759    (set_attr "prefix" "maybe_vex")
4760    (set_attr "mode" "DF")])
4761
4762 (define_insn "*vec_dupv2df"
4763   [(set (match_operand:V2DF 0 "register_operand" "=x")
4764         (vec_duplicate:V2DF
4765           (match_operand:DF 1 "register_operand" "0")))]
4766   "TARGET_SSE2"
4767   "unpcklpd\t%0, %0"
4768   [(set_attr "type" "sselog1")
4769    (set_attr "mode" "V2DF")])
4770
4771 (define_insn "*vec_concatv2df_sse3"
4772   [(set (match_operand:V2DF 0 "register_operand" "=x")
4773         (vec_concat:V2DF
4774           (match_operand:DF 1 "nonimmediate_operand" "xm")
4775           (match_dup 1)))]
4776   "TARGET_SSE3"
4777   "%vmovddup\t{%1, %0|%0, %1}"
4778   [(set_attr "type" "sselog1")
4779    (set_attr "prefix" "maybe_vex")
4780    (set_attr "mode" "DF")])
4781
4782 (define_insn "*vec_concatv2df"
4783   [(set (match_operand:V2DF 0 "register_operand"     "=x,x,x,x,x,x,x")
4784         (vec_concat:V2DF
4785           (match_operand:DF 1 "nonimmediate_operand" " 0,x,0,x,m,0,0")
4786           (match_operand:DF 2 "vector_move_operand"  " x,x,m,m,C,x,m")))]
4787   "TARGET_SSE"
4788   "@
4789    unpcklpd\t{%2, %0|%0, %2}
4790    vunpcklpd\t{%2, %1, %0|%0, %1, %2}
4791    movhpd\t{%2, %0|%0, %2}
4792    vmovhpd\t{%2, %1, %0|%0, %1, %2}
4793    %vmovsd\t{%1, %0|%0, %1}
4794    movlhps\t{%2, %0|%0, %2}
4795    movhps\t{%2, %0|%0, %2}"
4796   [(set_attr "isa" "sse2_noavx,avx,sse2_noavx,avx,sse2,noavx,noavx")
4797    (set (attr "type")
4798      (if_then_else
4799        (eq_attr "alternative" "0,1")
4800        (const_string "sselog")
4801        (const_string "ssemov")))
4802    (set_attr "prefix_data16" "*,*,1,*,*,*,*")
4803    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
4804    (set_attr "mode" "V2DF,V2DF,V1DF,V1DF,DF,V4SF,V2SF")])
4805
4806 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4807 ;;
4808 ;; Parallel integral arithmetic
4809 ;;
4810 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4811
4812 (define_expand "neg<mode>2"
4813   [(set (match_operand:VI_128 0 "register_operand" "")
4814         (minus:VI_128
4815           (match_dup 2)
4816           (match_operand:VI_128 1 "nonimmediate_operand" "")))]
4817   "TARGET_SSE2"
4818   "operands[2] = force_reg (<MODE>mode, CONST0_RTX (<MODE>mode));")
4819
4820 (define_expand "<plusminus_insn><mode>3"
4821   [(set (match_operand:VI_AVX2 0 "register_operand" "")
4822         (plusminus:VI_AVX2
4823           (match_operand:VI_AVX2 1 "nonimmediate_operand" "")
4824           (match_operand:VI_AVX2 2 "nonimmediate_operand" "")))]
4825   "TARGET_SSE2"
4826   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
4827
4828 (define_insn "*<plusminus_insn><mode>3"
4829   [(set (match_operand:VI_AVX2 0 "register_operand" "=x,x")
4830         (plusminus:VI_AVX2
4831           (match_operand:VI_AVX2 1 "nonimmediate_operand" "<comm>0,x")
4832           (match_operand:VI_AVX2 2 "nonimmediate_operand" "xm,xm")))]
4833   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
4834   "@
4835    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
4836    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
4837   [(set_attr "isa" "noavx,avx")
4838    (set_attr "type" "sseiadd")
4839    (set_attr "prefix_data16" "1,*")
4840    (set_attr "prefix" "orig,vex")
4841    (set_attr "mode" "<sseinsnmode>")])
4842
4843 (define_expand "<sse2_avx2>_<plusminus_insn><mode>3"
4844   [(set (match_operand:VI12_AVX2 0 "register_operand" "")
4845         (sat_plusminus:VI12_AVX2
4846           (match_operand:VI12_AVX2 1 "nonimmediate_operand" "")
4847           (match_operand:VI12_AVX2 2 "nonimmediate_operand" "")))]
4848   "TARGET_SSE2"
4849   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
4850
4851 (define_insn "*<sse2_avx2>_<plusminus_insn><mode>3"
4852   [(set (match_operand:VI12_AVX2 0 "register_operand" "=x,x")
4853         (sat_plusminus:VI12_AVX2
4854           (match_operand:VI12_AVX2 1 "nonimmediate_operand" "<comm>0,x")
4855           (match_operand:VI12_AVX2 2 "nonimmediate_operand" "xm,xm")))]
4856   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
4857   "@
4858    p<plusminus_mnemonic><ssemodesuffix>\t{%2, %0|%0, %2}
4859    vp<plusminus_mnemonic><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
4860   [(set_attr "isa" "noavx,avx")
4861    (set_attr "type" "sseiadd")
4862    (set_attr "prefix_data16" "1,*")
4863    (set_attr "prefix" "orig,vex")
4864    (set_attr "mode" "TI")])
4865
4866 (define_insn_and_split "mulv16qi3"
4867   [(set (match_operand:V16QI 0 "register_operand" "")
4868         (mult:V16QI (match_operand:V16QI 1 "register_operand" "")
4869                     (match_operand:V16QI 2 "register_operand" "")))]
4870   "TARGET_SSE2
4871    && can_create_pseudo_p ()"
4872   "#"
4873   "&& 1"
4874   [(const_int 0)]
4875 {
4876   rtx t[6];
4877   int i;
4878
4879   for (i = 0; i < 6; ++i)
4880     t[i] = gen_reg_rtx (V16QImode);
4881
4882   /* Unpack data such that we've got a source byte in each low byte of
4883      each word.  We don't care what goes into the high byte of each word.
4884      Rather than trying to get zero in there, most convenient is to let
4885      it be a copy of the low byte.  */
4886   emit_insn (gen_vec_interleave_highv16qi (t[0], operands[1], operands[1]));
4887   emit_insn (gen_vec_interleave_highv16qi (t[1], operands[2], operands[2]));
4888   emit_insn (gen_vec_interleave_lowv16qi (t[2], operands[1], operands[1]));
4889   emit_insn (gen_vec_interleave_lowv16qi (t[3], operands[2], operands[2]));
4890
4891   /* Multiply words.  The end-of-line annotations here give a picture of what
4892      the output of that instruction looks like.  Dot means don't care; the
4893      letters are the bytes of the result with A being the most significant.  */
4894   emit_insn (gen_mulv8hi3 (gen_lowpart (V8HImode, t[4]), /* .A.B.C.D.E.F.G.H */
4895                            gen_lowpart (V8HImode, t[0]),
4896                            gen_lowpart (V8HImode, t[1])));
4897   emit_insn (gen_mulv8hi3 (gen_lowpart (V8HImode, t[5]), /* .I.J.K.L.M.N.O.P */
4898                            gen_lowpart (V8HImode, t[2]),
4899                            gen_lowpart (V8HImode, t[3])));
4900
4901   /* Extract the even bytes and merge them back together.  */
4902   ix86_expand_vec_extract_even_odd (operands[0], t[5], t[4], 0);
4903
4904   set_unique_reg_note (get_last_insn (), REG_EQUAL,
4905                        gen_rtx_MULT (V16QImode, operands[1], operands[2]));
4906   DONE;
4907 })
4908
4909 (define_expand "mul<mode>3"
4910   [(set (match_operand:VI2_AVX2 0 "register_operand" "")
4911         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "")
4912                        (match_operand:VI2_AVX2 2 "nonimmediate_operand" "")))]
4913   "TARGET_SSE2"
4914   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
4915
4916 (define_insn "*mul<mode>3"
4917   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
4918         (mult:VI2_AVX2 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,x")
4919                        (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")))]
4920   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
4921   "@
4922    pmullw\t{%2, %0|%0, %2}
4923    vpmullw\t{%2, %1, %0|%0, %1, %2}"
4924   [(set_attr "isa" "noavx,avx")
4925    (set_attr "type" "sseimul")
4926    (set_attr "prefix_data16" "1,*")
4927    (set_attr "prefix" "orig,vex")
4928    (set_attr "mode" "<sseinsnmode>")])
4929
4930 (define_expand "<s>mul<mode>3_highpart"
4931   [(set (match_operand:VI2_AVX2 0 "register_operand" "")
4932         (truncate:VI2_AVX2
4933           (lshiftrt:<ssedoublemode>
4934             (mult:<ssedoublemode>
4935               (any_extend:<ssedoublemode>
4936                 (match_operand:VI2_AVX2 1 "nonimmediate_operand" ""))
4937               (any_extend:<ssedoublemode>
4938                 (match_operand:VI2_AVX2 2 "nonimmediate_operand" "")))
4939             (const_int 16))))]
4940   "TARGET_SSE2"
4941   "ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);")
4942
4943 (define_insn "*<s>mul<mode>3_highpart"
4944   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
4945         (truncate:VI2_AVX2
4946           (lshiftrt:<ssedoublemode>
4947             (mult:<ssedoublemode>
4948               (any_extend:<ssedoublemode>
4949                 (match_operand:VI2_AVX2 1 "nonimmediate_operand" "%0,x"))
4950               (any_extend:<ssedoublemode>
4951                 (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")))
4952             (const_int 16))))]
4953   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
4954   "@
4955    pmulh<u>w\t{%2, %0|%0, %2}
4956    vpmulh<u>w\t{%2, %1, %0|%0, %1, %2}"
4957   [(set_attr "isa" "noavx,avx")
4958    (set_attr "type" "sseimul")
4959    (set_attr "prefix_data16" "1,*")
4960    (set_attr "prefix" "orig,vex")
4961    (set_attr "mode" "<sseinsnmode>")])
4962
4963 (define_expand "avx2_umulv4siv4di3"
4964   [(set (match_operand:V4DI 0 "register_operand" "")
4965         (mult:V4DI
4966           (zero_extend:V4DI
4967             (vec_select:V4SI
4968               (match_operand:V8SI 1 "nonimmediate_operand" "")
4969               (parallel [(const_int 0) (const_int 2)
4970                          (const_int 4) (const_int 6)])))
4971           (zero_extend:V4DI
4972             (vec_select:V4SI
4973               (match_operand:V8SI 2 "nonimmediate_operand" "")
4974               (parallel [(const_int 0) (const_int 2)
4975                          (const_int 4) (const_int 6)])))))]
4976   "TARGET_AVX2"
4977   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
4978
4979 (define_insn "*avx_umulv4siv4di3"
4980   [(set (match_operand:V4DI 0 "register_operand" "=x")
4981         (mult:V4DI
4982           (zero_extend:V4DI
4983             (vec_select:V4SI
4984               (match_operand:V8SI 1 "nonimmediate_operand" "%x")
4985               (parallel [(const_int 0) (const_int 2)
4986                          (const_int 4) (const_int 6)])))
4987           (zero_extend:V4DI
4988             (vec_select:V4SI
4989               (match_operand:V8SI 2 "nonimmediate_operand" "xm")
4990               (parallel [(const_int 0) (const_int 2)
4991                          (const_int 4) (const_int 6)])))))]
4992   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V8SImode, operands)"
4993   "vpmuludq\t{%2, %1, %0|%0, %1, %2}"
4994   [(set_attr "type" "sseimul")
4995    (set_attr "prefix" "vex")
4996    (set_attr "mode" "OI")])
4997
4998 (define_expand "sse2_umulv2siv2di3"
4999   [(set (match_operand:V2DI 0 "register_operand" "")
5000         (mult:V2DI
5001           (zero_extend:V2DI
5002             (vec_select:V2SI
5003               (match_operand:V4SI 1 "nonimmediate_operand" "")
5004               (parallel [(const_int 0) (const_int 2)])))
5005           (zero_extend:V2DI
5006             (vec_select:V2SI
5007               (match_operand:V4SI 2 "nonimmediate_operand" "")
5008               (parallel [(const_int 0) (const_int 2)])))))]
5009   "TARGET_SSE2"
5010   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
5011
5012 (define_insn "*sse2_umulv2siv2di3"
5013   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
5014         (mult:V2DI
5015           (zero_extend:V2DI
5016             (vec_select:V2SI
5017               (match_operand:V4SI 1 "nonimmediate_operand" "%0,x")
5018               (parallel [(const_int 0) (const_int 2)])))
5019           (zero_extend:V2DI
5020             (vec_select:V2SI
5021               (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
5022               (parallel [(const_int 0) (const_int 2)])))))]
5023   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
5024   "@
5025    pmuludq\t{%2, %0|%0, %2}
5026    vpmuludq\t{%2, %1, %0|%0, %1, %2}"
5027   [(set_attr "isa" "noavx,avx")
5028    (set_attr "type" "sseimul")
5029    (set_attr "prefix_data16" "1,*")
5030    (set_attr "prefix" "orig,vex")
5031    (set_attr "mode" "TI")])
5032
5033 (define_expand "avx2_mulv4siv4di3"
5034   [(set (match_operand:V4DI 0 "register_operand" "")
5035         (mult:V4DI
5036           (sign_extend:V4DI
5037             (vec_select:V4SI
5038               (match_operand:V8SI 1 "nonimmediate_operand" "")
5039               (parallel [(const_int 0) (const_int 2)
5040                          (const_int 4) (const_int 6)])))
5041           (sign_extend:V4DI
5042             (vec_select:V4SI
5043               (match_operand:V8SI 2 "nonimmediate_operand" "")
5044               (parallel [(const_int 0) (const_int 2)
5045                          (const_int 4) (const_int 6)])))))]
5046   "TARGET_AVX2"
5047   "ix86_fixup_binary_operands_no_copy (MULT, V8SImode, operands);")
5048
5049 (define_insn "*avx2_mulv4siv4di3"
5050   [(set (match_operand:V4DI 0 "register_operand" "=x")
5051         (mult:V4DI
5052           (sign_extend:V4DI
5053             (vec_select:V4SI
5054               (match_operand:V8SI 1 "nonimmediate_operand" "x")
5055               (parallel [(const_int 0) (const_int 2)
5056                          (const_int 4) (const_int 6)])))
5057           (sign_extend:V4DI
5058             (vec_select:V4SI
5059               (match_operand:V8SI 2 "nonimmediate_operand" "xm")
5060               (parallel [(const_int 0) (const_int 2)
5061                          (const_int 4) (const_int 6)])))))]
5062   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V8SImode, operands)"
5063   "vpmuldq\t{%2, %1, %0|%0, %1, %2}"
5064   [(set_attr "isa" "avx")
5065    (set_attr "type" "sseimul")
5066    (set_attr "prefix_extra" "1")
5067    (set_attr "prefix" "vex")
5068    (set_attr "mode" "OI")])
5069
5070 (define_expand "sse4_1_mulv2siv2di3"
5071   [(set (match_operand:V2DI 0 "register_operand" "")
5072         (mult:V2DI
5073           (sign_extend:V2DI
5074             (vec_select:V2SI
5075               (match_operand:V4SI 1 "nonimmediate_operand" "")
5076               (parallel [(const_int 0) (const_int 2)])))
5077           (sign_extend:V2DI
5078             (vec_select:V2SI
5079               (match_operand:V4SI 2 "nonimmediate_operand" "")
5080               (parallel [(const_int 0) (const_int 2)])))))]
5081   "TARGET_SSE4_1"
5082   "ix86_fixup_binary_operands_no_copy (MULT, V4SImode, operands);")
5083
5084 (define_insn "*sse4_1_mulv2siv2di3"
5085   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
5086         (mult:V2DI
5087           (sign_extend:V2DI
5088             (vec_select:V2SI
5089               (match_operand:V4SI 1 "nonimmediate_operand" "%0,x")
5090               (parallel [(const_int 0) (const_int 2)])))
5091           (sign_extend:V2DI
5092             (vec_select:V2SI
5093               (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
5094               (parallel [(const_int 0) (const_int 2)])))))]
5095   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, V4SImode, operands)"
5096   "@
5097    pmuldq\t{%2, %0|%0, %2}
5098    vpmuldq\t{%2, %1, %0|%0, %1, %2}"
5099   [(set_attr "isa" "noavx,avx")
5100    (set_attr "type" "sseimul")
5101    (set_attr "prefix_data16" "1,*")
5102    (set_attr "prefix_extra" "1")
5103    (set_attr "prefix" "orig,vex")
5104    (set_attr "mode" "TI")])
5105
5106 (define_expand "avx2_pmaddwd"
5107   [(set (match_operand:V8SI 0 "register_operand" "")
5108         (plus:V8SI
5109           (mult:V8SI
5110             (sign_extend:V8SI
5111               (vec_select:V8HI
5112                 (match_operand:V16HI 1 "nonimmediate_operand" "")
5113                 (parallel [(const_int 0)
5114                            (const_int 2)
5115                            (const_int 4)
5116                            (const_int 6)
5117                            (const_int 8)
5118                            (const_int 10)
5119                            (const_int 12)
5120                            (const_int 14)])))
5121             (sign_extend:V8SI
5122               (vec_select:V8HI
5123                 (match_operand:V16HI 2 "nonimmediate_operand" "")
5124                 (parallel [(const_int 0)
5125                            (const_int 2)
5126                            (const_int 4)
5127                            (const_int 6)
5128                            (const_int 8)
5129                            (const_int 10)
5130                            (const_int 12)
5131                            (const_int 14)]))))
5132           (mult:V8SI
5133             (sign_extend:V8SI
5134               (vec_select:V8HI (match_dup 1)
5135                 (parallel [(const_int 1)
5136                            (const_int 3)
5137                            (const_int 5)
5138                            (const_int 7)
5139                            (const_int 9)
5140                            (const_int 11)
5141                            (const_int 13)
5142                            (const_int 15)])))
5143             (sign_extend:V8SI
5144               (vec_select:V8HI (match_dup 2)
5145                 (parallel [(const_int 1)
5146                            (const_int 3)
5147                            (const_int 5)
5148                            (const_int 7)
5149                            (const_int 9)
5150                            (const_int 11)
5151                            (const_int 13)
5152                            (const_int 15)]))))))]
5153   "TARGET_AVX2"
5154   "ix86_fixup_binary_operands_no_copy (MULT, V16HImode, operands);")
5155
5156 (define_expand "sse2_pmaddwd"
5157   [(set (match_operand:V4SI 0 "register_operand" "")
5158         (plus:V4SI
5159           (mult:V4SI
5160             (sign_extend:V4SI
5161               (vec_select:V4HI
5162                 (match_operand:V8HI 1 "nonimmediate_operand" "")
5163                 (parallel [(const_int 0)
5164                            (const_int 2)
5165                            (const_int 4)
5166                            (const_int 6)])))
5167             (sign_extend:V4SI
5168               (vec_select:V4HI
5169                 (match_operand:V8HI 2 "nonimmediate_operand" "")
5170                 (parallel [(const_int 0)
5171                            (const_int 2)
5172                            (const_int 4)
5173                            (const_int 6)]))))
5174           (mult:V4SI
5175             (sign_extend:V4SI
5176               (vec_select:V4HI (match_dup 1)
5177                 (parallel [(const_int 1)
5178                            (const_int 3)
5179                            (const_int 5)
5180                            (const_int 7)])))
5181             (sign_extend:V4SI
5182               (vec_select:V4HI (match_dup 2)
5183                 (parallel [(const_int 1)
5184                            (const_int 3)
5185                            (const_int 5)
5186                            (const_int 7)]))))))]
5187   "TARGET_SSE2"
5188   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
5189
5190 (define_insn "*avx2_pmaddwd"
5191   [(set (match_operand:V8SI 0 "register_operand" "=x")
5192         (plus:V8SI
5193           (mult:V8SI
5194             (sign_extend:V8SI
5195               (vec_select:V8HI
5196                 (match_operand:V16HI 1 "nonimmediate_operand" "%x")
5197                 (parallel [(const_int 0)
5198                            (const_int 2)
5199                            (const_int 4)
5200                            (const_int 6)
5201                            (const_int 8)
5202                            (const_int 10)
5203                            (const_int 12)
5204                            (const_int 14)])))
5205             (sign_extend:V8SI
5206               (vec_select:V8HI
5207                 (match_operand:V16HI 2 "nonimmediate_operand" "xm")
5208                 (parallel [(const_int 0)
5209                            (const_int 2)
5210                            (const_int 4)
5211                            (const_int 6)
5212                            (const_int 8)
5213                            (const_int 10)
5214                            (const_int 12)
5215                            (const_int 14)]))))
5216           (mult:V8SI
5217             (sign_extend:V8SI
5218               (vec_select:V8HI (match_dup 1)
5219                 (parallel [(const_int 1)
5220                            (const_int 3)
5221                            (const_int 5)
5222                            (const_int 7)
5223                            (const_int 9)
5224                            (const_int 11)
5225                            (const_int 13)
5226                            (const_int 15)])))
5227             (sign_extend:V8SI
5228               (vec_select:V8HI (match_dup 2)
5229                 (parallel [(const_int 1)
5230                            (const_int 3)
5231                            (const_int 5)
5232                            (const_int 7)
5233                            (const_int 9)
5234                            (const_int 11)
5235                            (const_int 13)
5236                            (const_int 15)]))))))]
5237   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V16HImode, operands)"
5238   "vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
5239   [(set_attr "type" "sseiadd")
5240    (set_attr "prefix" "vex")
5241    (set_attr "mode" "OI")])
5242
5243 (define_insn "*sse2_pmaddwd"
5244   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
5245         (plus:V4SI
5246           (mult:V4SI
5247             (sign_extend:V4SI
5248               (vec_select:V4HI
5249                 (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
5250                 (parallel [(const_int 0)
5251                            (const_int 2)
5252                            (const_int 4)
5253                            (const_int 6)])))
5254             (sign_extend:V4SI
5255               (vec_select:V4HI
5256                 (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
5257                 (parallel [(const_int 0)
5258                            (const_int 2)
5259                            (const_int 4)
5260                            (const_int 6)]))))
5261           (mult:V4SI
5262             (sign_extend:V4SI
5263               (vec_select:V4HI (match_dup 1)
5264                 (parallel [(const_int 1)
5265                            (const_int 3)
5266                            (const_int 5)
5267                            (const_int 7)])))
5268             (sign_extend:V4SI
5269               (vec_select:V4HI (match_dup 2)
5270                 (parallel [(const_int 1)
5271                            (const_int 3)
5272                            (const_int 5)
5273                            (const_int 7)]))))))]
5274   "TARGET_SSE2 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
5275   "@
5276    pmaddwd\t{%2, %0|%0, %2}
5277    vpmaddwd\t{%2, %1, %0|%0, %1, %2}"
5278   [(set_attr "isa" "noavx,avx")
5279    (set_attr "type" "sseiadd")
5280    (set_attr "atom_unit" "simul")
5281    (set_attr "prefix_data16" "1,*")
5282    (set_attr "prefix" "orig,vex")
5283    (set_attr "mode" "TI")])
5284
5285 (define_expand "mul<mode>3"
5286   [(set (match_operand:VI4_AVX2 0 "register_operand" "")
5287         (mult:VI4_AVX2 (match_operand:VI4_AVX2 1 "register_operand" "")
5288                        (match_operand:VI4_AVX2 2 "register_operand" "")))]
5289   "TARGET_SSE2"
5290 {
5291   if (TARGET_SSE4_1 || TARGET_AVX)
5292     ix86_fixup_binary_operands_no_copy (MULT, <MODE>mode, operands);
5293 })
5294
5295 (define_insn "*<sse4_1_avx2>_mul<mode>3"
5296   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x,x")
5297         (mult:VI4_AVX2 (match_operand:VI4_AVX2 1 "nonimmediate_operand" "%0,x")
5298                        (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm,xm")))]
5299   "TARGET_SSE4_1 && ix86_binary_operator_ok (MULT, <MODE>mode, operands)"
5300   "@
5301    pmulld\t{%2, %0|%0, %2}
5302    vpmulld\t{%2, %1, %0|%0, %1, %2}"
5303   [(set_attr "isa" "noavx,avx")
5304    (set_attr "type" "sseimul")
5305    (set_attr "prefix_extra" "1")
5306    (set_attr "prefix" "orig,vex")
5307    (set_attr "mode" "<sseinsnmode>")])
5308
5309 (define_insn_and_split "*sse2_mulv4si3"
5310   [(set (match_operand:V4SI 0 "register_operand" "")
5311         (mult:V4SI (match_operand:V4SI 1 "register_operand" "")
5312                    (match_operand:V4SI 2 "register_operand" "")))]
5313   "TARGET_SSE2 && !TARGET_SSE4_1 && !TARGET_AVX
5314    && can_create_pseudo_p ()"
5315   "#"
5316   "&& 1"
5317   [(const_int 0)]
5318 {
5319   rtx t1, t2, t3, t4, t5, t6, thirtytwo;
5320   rtx op0, op1, op2;
5321
5322   op0 = operands[0];
5323   op1 = operands[1];
5324   op2 = operands[2];
5325   t1 = gen_reg_rtx (V4SImode);
5326   t2 = gen_reg_rtx (V4SImode);
5327   t3 = gen_reg_rtx (V4SImode);
5328   t4 = gen_reg_rtx (V4SImode);
5329   t5 = gen_reg_rtx (V4SImode);
5330   t6 = gen_reg_rtx (V4SImode);
5331   thirtytwo = GEN_INT (32);
5332
5333   /* Multiply elements 2 and 0.  */
5334   emit_insn (gen_sse2_umulv2siv2di3 (gen_lowpart (V2DImode, t1),
5335                                      op1, op2));
5336
5337   /* Shift both input vectors down one element, so that elements 3
5338      and 1 are now in the slots for elements 2 and 0.  For K8, at
5339      least, this is faster than using a shuffle.  */
5340   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t2),
5341                                  gen_lowpart (V1TImode, op1),
5342                                  thirtytwo));
5343   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t3),
5344                                  gen_lowpart (V1TImode, op2),
5345                                  thirtytwo));
5346   /* Multiply elements 3 and 1.  */
5347   emit_insn (gen_sse2_umulv2siv2di3 (gen_lowpart (V2DImode, t4),
5348                                      t2, t3));
5349
5350   /* Move the results in element 2 down to element 1; we don't care
5351      what goes in elements 2 and 3.  */
5352   emit_insn (gen_sse2_pshufd_1 (t5, t1, const0_rtx, const2_rtx,
5353                                 const0_rtx, const0_rtx));
5354   emit_insn (gen_sse2_pshufd_1 (t6, t4, const0_rtx, const2_rtx,
5355                                 const0_rtx, const0_rtx));
5356
5357   /* Merge the parts back together.  */
5358   emit_insn (gen_vec_interleave_lowv4si (op0, t5, t6));
5359
5360   set_unique_reg_note (get_last_insn (), REG_EQUAL,
5361                        gen_rtx_MULT (V4SImode, operands[1], operands[2]));
5362   DONE;
5363 })
5364
5365 (define_insn_and_split "mulv2di3"
5366   [(set (match_operand:V2DI 0 "register_operand" "")
5367         (mult:V2DI (match_operand:V2DI 1 "register_operand" "")
5368                    (match_operand:V2DI 2 "register_operand" "")))]
5369   "TARGET_SSE2
5370    && can_create_pseudo_p ()"
5371   "#"
5372   "&& 1"
5373   [(const_int 0)]
5374 {
5375   rtx t1, t2, t3, t4, t5, t6, thirtytwo;
5376   rtx op0, op1, op2;
5377
5378   op0 = operands[0];
5379   op1 = operands[1];
5380   op2 = operands[2];
5381
5382   if (TARGET_XOP)
5383     {
5384       /* op1: A,B,C,D, op2: E,F,G,H */
5385       op1 = gen_lowpart (V4SImode, op1);
5386       op2 = gen_lowpart (V4SImode, op2);
5387
5388       t1 = gen_reg_rtx (V4SImode);
5389       t2 = gen_reg_rtx (V4SImode);
5390       t3 = gen_reg_rtx (V2DImode);
5391       t4 = gen_reg_rtx (V2DImode);
5392
5393       /* t1: B,A,D,C */
5394       emit_insn (gen_sse2_pshufd_1 (t1, op1,
5395                                     GEN_INT (1),
5396                                     GEN_INT (0),
5397                                     GEN_INT (3),
5398                                     GEN_INT (2)));
5399
5400       /* t2: (B*E),(A*F),(D*G),(C*H) */
5401       emit_insn (gen_mulv4si3 (t2, t1, op2));
5402
5403       /* t4: (B*E)+(A*F), (D*G)+(C*H) */
5404       emit_insn (gen_xop_phadddq (t3, t2));
5405
5406       /* t5: ((B*E)+(A*F))<<32, ((D*G)+(C*H))<<32 */
5407       emit_insn (gen_ashlv2di3 (t4, t3, GEN_INT (32)));
5408
5409       /* op0: (((B*E)+(A*F))<<32)+(B*F), (((D*G)+(C*H))<<32)+(D*H) */
5410       emit_insn (gen_xop_pmacsdql (op0, op1, op2, t4));
5411     }
5412   else
5413     {
5414       t1 = gen_reg_rtx (V2DImode);
5415       t2 = gen_reg_rtx (V2DImode);
5416       t3 = gen_reg_rtx (V2DImode);
5417       t4 = gen_reg_rtx (V2DImode);
5418       t5 = gen_reg_rtx (V2DImode);
5419       t6 = gen_reg_rtx (V2DImode);
5420       thirtytwo = GEN_INT (32);
5421
5422       /* Multiply low parts.  */
5423       emit_insn (gen_sse2_umulv2siv2di3 (t1, gen_lowpart (V4SImode, op1),
5424                                          gen_lowpart (V4SImode, op2)));
5425
5426       /* Shift input vectors left 32 bits so we can multiply high parts.  */
5427       emit_insn (gen_lshrv2di3 (t2, op1, thirtytwo));
5428       emit_insn (gen_lshrv2di3 (t3, op2, thirtytwo));
5429
5430       /* Multiply high parts by low parts.  */
5431       emit_insn (gen_sse2_umulv2siv2di3 (t4, gen_lowpart (V4SImode, op1),
5432                                          gen_lowpart (V4SImode, t3)));
5433       emit_insn (gen_sse2_umulv2siv2di3 (t5, gen_lowpart (V4SImode, op2),
5434                                          gen_lowpart (V4SImode, t2)));
5435
5436       /* Shift them back.  */
5437       emit_insn (gen_ashlv2di3 (t4, t4, thirtytwo));
5438       emit_insn (gen_ashlv2di3 (t5, t5, thirtytwo));
5439
5440       /* Add the three parts together.  */
5441       emit_insn (gen_addv2di3 (t6, t1, t4));
5442       emit_insn (gen_addv2di3 (op0, t6, t5));
5443     }
5444
5445   set_unique_reg_note (get_last_insn (), REG_EQUAL,
5446                        gen_rtx_MULT (V2DImode, operands[1], operands[2]));
5447   DONE;
5448 })
5449
5450 (define_expand "vec_widen_smult_hi_v8hi"
5451   [(match_operand:V4SI 0 "register_operand" "")
5452    (match_operand:V8HI 1 "register_operand" "")
5453    (match_operand:V8HI 2 "register_operand" "")]
5454   "TARGET_SSE2"
5455 {
5456   rtx op1, op2, t1, t2, dest;
5457
5458   op1 = operands[1];
5459   op2 = operands[2];
5460   t1 = gen_reg_rtx (V8HImode);
5461   t2 = gen_reg_rtx (V8HImode);
5462   dest = gen_lowpart (V8HImode, operands[0]);
5463
5464   emit_insn (gen_mulv8hi3 (t1, op1, op2));
5465   emit_insn (gen_smulv8hi3_highpart (t2, op1, op2));
5466   emit_insn (gen_vec_interleave_highv8hi (dest, t1, t2));
5467   DONE;
5468 })
5469
5470 (define_expand "vec_widen_smult_lo_v8hi"
5471   [(match_operand:V4SI 0 "register_operand" "")
5472    (match_operand:V8HI 1 "register_operand" "")
5473    (match_operand:V8HI 2 "register_operand" "")]
5474   "TARGET_SSE2"
5475 {
5476   rtx op1, op2, t1, t2, dest;
5477
5478   op1 = operands[1];
5479   op2 = operands[2];
5480   t1 = gen_reg_rtx (V8HImode);
5481   t2 = gen_reg_rtx (V8HImode);
5482   dest = gen_lowpart (V8HImode, operands[0]);
5483
5484   emit_insn (gen_mulv8hi3 (t1, op1, op2));
5485   emit_insn (gen_smulv8hi3_highpart (t2, op1, op2));
5486   emit_insn (gen_vec_interleave_lowv8hi (dest, t1, t2));
5487   DONE;
5488 })
5489
5490 (define_expand "vec_widen_umult_hi_v8hi"
5491   [(match_operand:V4SI 0 "register_operand" "")
5492    (match_operand:V8HI 1 "register_operand" "")
5493    (match_operand:V8HI 2 "register_operand" "")]
5494   "TARGET_SSE2"
5495 {
5496   rtx op1, op2, t1, t2, dest;
5497
5498   op1 = operands[1];
5499   op2 = operands[2];
5500   t1 = gen_reg_rtx (V8HImode);
5501   t2 = gen_reg_rtx (V8HImode);
5502   dest = gen_lowpart (V8HImode, operands[0]);
5503
5504   emit_insn (gen_mulv8hi3 (t1, op1, op2));
5505   emit_insn (gen_umulv8hi3_highpart (t2, op1, op2));
5506   emit_insn (gen_vec_interleave_highv8hi (dest, t1, t2));
5507   DONE;
5508 })
5509
5510 (define_expand "vec_widen_umult_lo_v8hi"
5511   [(match_operand:V4SI 0 "register_operand" "")
5512    (match_operand:V8HI 1 "register_operand" "")
5513    (match_operand:V8HI 2 "register_operand" "")]
5514   "TARGET_SSE2"
5515 {
5516   rtx op1, op2, t1, t2, dest;
5517
5518   op1 = operands[1];
5519   op2 = operands[2];
5520   t1 = gen_reg_rtx (V8HImode);
5521   t2 = gen_reg_rtx (V8HImode);
5522   dest = gen_lowpart (V8HImode, operands[0]);
5523
5524   emit_insn (gen_mulv8hi3 (t1, op1, op2));
5525   emit_insn (gen_umulv8hi3_highpart (t2, op1, op2));
5526   emit_insn (gen_vec_interleave_lowv8hi (dest, t1, t2));
5527   DONE;
5528 })
5529
5530 (define_expand "vec_widen_smult_hi_v4si"
5531   [(match_operand:V2DI 0 "register_operand" "")
5532    (match_operand:V4SI 1 "register_operand" "")
5533    (match_operand:V4SI 2 "register_operand" "")]
5534   "TARGET_XOP"
5535 {
5536   rtx t1, t2;
5537
5538   t1 = gen_reg_rtx (V4SImode);
5539   t2 = gen_reg_rtx (V4SImode);
5540
5541   emit_insn (gen_sse2_pshufd_1 (t1, operands[1],
5542                                 GEN_INT (0),
5543                                 GEN_INT (2),
5544                                 GEN_INT (1),
5545                                 GEN_INT (3)));
5546   emit_insn (gen_sse2_pshufd_1 (t2, operands[2],
5547                                 GEN_INT (0),
5548                                 GEN_INT (2),
5549                                 GEN_INT (1),
5550                                 GEN_INT (3)));
5551   emit_insn (gen_xop_mulv2div2di3_high (operands[0], t1, t2));
5552   DONE;
5553 })
5554
5555 (define_expand "vec_widen_smult_lo_v4si"
5556   [(match_operand:V2DI 0 "register_operand" "")
5557    (match_operand:V4SI 1 "register_operand" "")
5558    (match_operand:V4SI 2 "register_operand" "")]
5559   "TARGET_XOP"
5560 {
5561   rtx t1, t2;
5562
5563   t1 = gen_reg_rtx (V4SImode);
5564   t2 = gen_reg_rtx (V4SImode);
5565
5566   emit_insn (gen_sse2_pshufd_1 (t1, operands[1],
5567                                 GEN_INT (0),
5568                                 GEN_INT (2),
5569                                 GEN_INT (1),
5570                                 GEN_INT (3)));
5571   emit_insn (gen_sse2_pshufd_1 (t2, operands[2],
5572                                 GEN_INT (0),
5573                                 GEN_INT (2),
5574                                 GEN_INT (1),
5575                                 GEN_INT (3)));
5576   emit_insn (gen_xop_mulv2div2di3_low (operands[0], t1, t2));
5577   DONE;
5578 })
5579
5580 (define_expand "vec_widen_umult_hi_v4si"
5581   [(match_operand:V2DI 0 "register_operand" "")
5582    (match_operand:V4SI 1 "register_operand" "")
5583    (match_operand:V4SI 2 "register_operand" "")]
5584   "TARGET_SSE2"
5585 {
5586   rtx op1, op2, t1, t2;
5587
5588   op1 = operands[1];
5589   op2 = operands[2];
5590   t1 = gen_reg_rtx (V4SImode);
5591   t2 = gen_reg_rtx (V4SImode);
5592
5593   emit_insn (gen_vec_interleave_highv4si (t1, op1, op1));
5594   emit_insn (gen_vec_interleave_highv4si (t2, op2, op2));
5595   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
5596   DONE;
5597 })
5598
5599 (define_expand "vec_widen_umult_lo_v4si"
5600   [(match_operand:V2DI 0 "register_operand" "")
5601    (match_operand:V4SI 1 "register_operand" "")
5602    (match_operand:V4SI 2 "register_operand" "")]
5603   "TARGET_SSE2"
5604 {
5605   rtx op1, op2, t1, t2;
5606
5607   op1 = operands[1];
5608   op2 = operands[2];
5609   t1 = gen_reg_rtx (V4SImode);
5610   t2 = gen_reg_rtx (V4SImode);
5611
5612   emit_insn (gen_vec_interleave_lowv4si (t1, op1, op1));
5613   emit_insn (gen_vec_interleave_lowv4si (t2, op2, op2));
5614   emit_insn (gen_sse2_umulv2siv2di3 (operands[0], t1, t2));
5615   DONE;
5616 })
5617
5618 (define_expand "sdot_prodv8hi"
5619   [(match_operand:V4SI 0 "register_operand" "")
5620    (match_operand:V8HI 1 "register_operand" "")
5621    (match_operand:V8HI 2 "register_operand" "")
5622    (match_operand:V4SI 3 "register_operand" "")]
5623   "TARGET_SSE2"
5624 {
5625   rtx t = gen_reg_rtx (V4SImode);
5626   emit_insn (gen_sse2_pmaddwd (t, operands[1], operands[2]));
5627   emit_insn (gen_addv4si3 (operands[0], operands[3], t));
5628   DONE;
5629 })
5630
5631 (define_expand "udot_prodv4si"
5632   [(match_operand:V2DI 0 "register_operand" "")
5633    (match_operand:V4SI 1 "register_operand" "")
5634    (match_operand:V4SI 2 "register_operand" "")
5635    (match_operand:V2DI 3 "register_operand" "")]
5636   "TARGET_SSE2"
5637 {
5638   rtx t1, t2, t3, t4;
5639
5640   t1 = gen_reg_rtx (V2DImode);
5641   emit_insn (gen_sse2_umulv2siv2di3 (t1, operands[1], operands[2]));
5642   emit_insn (gen_addv2di3 (t1, t1, operands[3]));
5643
5644   t2 = gen_reg_rtx (V4SImode);
5645   t3 = gen_reg_rtx (V4SImode);
5646   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t2),
5647                                  gen_lowpart (V1TImode, operands[1]),
5648                                  GEN_INT (32)));
5649   emit_insn (gen_sse2_lshrv1ti3 (gen_lowpart (V1TImode, t3),
5650                                  gen_lowpart (V1TImode, operands[2]),
5651                                  GEN_INT (32)));
5652
5653   t4 = gen_reg_rtx (V2DImode);
5654   emit_insn (gen_sse2_umulv2siv2di3 (t4, t2, t3));
5655
5656   emit_insn (gen_addv2di3 (operands[0], t1, t4));
5657   DONE;
5658 })
5659
5660 (define_insn "ashr<mode>3"
5661   [(set (match_operand:VI24_AVX2 0 "register_operand" "=x,x")
5662         (ashiftrt:VI24_AVX2
5663           (match_operand:VI24_AVX2 1 "register_operand" "0,x")
5664           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5665   "TARGET_SSE2"
5666   "@
5667    psra<ssemodesuffix>\t{%2, %0|%0, %2}
5668    vpsra<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5669   [(set_attr "isa" "noavx,avx")
5670    (set_attr "type" "sseishft")
5671    (set (attr "length_immediate")
5672      (if_then_else (match_operand 2 "const_int_operand" "")
5673        (const_string "1")
5674        (const_string "0")))
5675    (set_attr "prefix_data16" "1,*")
5676    (set_attr "prefix" "orig,vex")
5677    (set_attr "mode" "<sseinsnmode>")])
5678
5679 (define_insn "avx2_lshrqv4di3"
5680   [(set (match_operand:V4DI 0 "register_operand" "=x")
5681         (lshiftrt:V4DI
5682          (match_operand:V4DI 1 "register_operand" "x")
5683          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n")))]
5684   "TARGET_AVX2"
5685 {
5686   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5687   return "vpsrldq\t{%2, %1, %0|%0, %1, %2}";
5688 }
5689   [(set_attr "type" "sseishft")
5690    (set_attr "prefix" "vex")
5691    (set_attr "length_immediate" "1")
5692    (set_attr "mode" "OI")])
5693
5694 (define_insn "lshr<mode>3"
5695   [(set (match_operand:VI248_AVX2 0 "register_operand" "=x,x")
5696         (lshiftrt:VI248_AVX2
5697           (match_operand:VI248_AVX2 1 "register_operand" "0,x")
5698           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5699   "TARGET_SSE2"
5700   "@
5701    psrl<ssemodesuffix>\t{%2, %0|%0, %2}
5702    vpsrl<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5703   [(set_attr "isa" "noavx,avx")
5704    (set_attr "type" "sseishft")
5705    (set (attr "length_immediate")
5706      (if_then_else (match_operand 2 "const_int_operand" "")
5707        (const_string "1")
5708        (const_string "0")))
5709    (set_attr "prefix_data16" "1,*")
5710    (set_attr "prefix" "orig,vex")
5711    (set_attr "mode" "<sseinsnmode>")])
5712
5713 (define_insn "avx2_lshlqv4di3"
5714   [(set (match_operand:V4DI 0 "register_operand" "=x")
5715         (ashift:V4DI (match_operand:V4DI 1 "register_operand" "x")
5716                      (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n")))]
5717   "TARGET_AVX2"
5718 {
5719   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5720   return "vpslldq\t{%2, %1, %0|%0, %1, %2}";
5721 }
5722   [(set_attr "type" "sseishft")
5723    (set_attr "prefix" "vex")
5724    (set_attr "length_immediate" "1")
5725    (set_attr "mode" "OI")])
5726
5727 (define_insn "avx2_lshl<mode>3"
5728   [(set (match_operand:VI248_256 0 "register_operand" "=x")
5729         (ashift:VI248_256
5730           (match_operand:VI248_256 1 "register_operand" "x")
5731           (match_operand:SI 2 "nonmemory_operand" "xN")))]
5732   "TARGET_AVX2"
5733   "vpsll<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5734   [(set_attr "type" "sseishft")
5735    (set_attr "prefix" "vex")
5736    (set (attr "length_immediate")
5737      (if_then_else (match_operand 2 "const_int_operand" "")
5738        (const_string "1")
5739        (const_string "0")))
5740    (set_attr "mode" "OI")])
5741
5742 (define_insn "ashl<mode>3"
5743   [(set (match_operand:VI248_128 0 "register_operand" "=x,x")
5744         (ashift:VI248_128
5745           (match_operand:VI248_128 1 "register_operand" "0,x")
5746           (match_operand:SI 2 "nonmemory_operand" "xN,xN")))]
5747   "TARGET_SSE2"
5748   "@
5749    psll<ssemodesuffix>\t{%2, %0|%0, %2}
5750    vpsll<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5751   [(set_attr "isa" "noavx,avx")
5752    (set_attr "type" "sseishft")
5753    (set (attr "length_immediate")
5754      (if_then_else (match_operand 2 "const_int_operand" "")
5755        (const_string "1")
5756        (const_string "0")))
5757    (set_attr "prefix_data16" "1,*")
5758    (set_attr "prefix" "orig,vex")
5759    (set_attr "mode" "TI")])
5760
5761 (define_expand "vec_shl_<mode>"
5762   [(set (match_operand:VI_128 0 "register_operand" "")
5763         (ashift:V1TI
5764          (match_operand:VI_128 1 "register_operand" "")
5765          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "")))]
5766   "TARGET_SSE2"
5767 {
5768   operands[0] = gen_lowpart (V1TImode, operands[0]);
5769   operands[1] = gen_lowpart (V1TImode, operands[1]);
5770 })
5771
5772 (define_insn "<sse2_avx2>_ashl<mode>3"
5773   [(set (match_operand:VIMAX_AVX2 0 "register_operand" "=x,x")
5774         (ashift:VIMAX_AVX2
5775          (match_operand:VIMAX_AVX2 1 "register_operand" "0,x")
5776          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
5777   "TARGET_SSE2"
5778 {
5779   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5780
5781   switch (which_alternative)
5782     {
5783     case 0:
5784       return "pslldq\t{%2, %0|%0, %2}";
5785     case 1:
5786       return "vpslldq\t{%2, %1, %0|%0, %1, %2}";
5787     default:
5788       gcc_unreachable ();
5789     }
5790 }
5791   [(set_attr "isa" "noavx,avx")
5792    (set_attr "type" "sseishft")
5793    (set_attr "length_immediate" "1")
5794    (set_attr "prefix_data16" "1,*")
5795    (set_attr "prefix" "orig,vex")
5796    (set_attr "mode" "<sseinsnmode>")])
5797
5798 (define_expand "vec_shr_<mode>"
5799   [(set (match_operand:VI_128 0 "register_operand" "")
5800         (lshiftrt:V1TI
5801          (match_operand:VI_128 1 "register_operand" "")
5802          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "")))]
5803   "TARGET_SSE2"
5804 {
5805   operands[0] = gen_lowpart (V1TImode, operands[0]);
5806   operands[1] = gen_lowpart (V1TImode, operands[1]);
5807 })
5808
5809 (define_expand "<code><mode>3"
5810   [(set (match_operand:VI124_256 0 "register_operand" "")
5811         (umaxmin:VI124_256
5812           (match_operand:VI124_256 1 "nonimmediate_operand" "")
5813           (match_operand:VI124_256 2 "nonimmediate_operand" "")))]
5814   "TARGET_AVX2"
5815   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
5816
5817 (define_insn "*avx2_<code><mode>3"
5818   [(set (match_operand:VI124_256 0 "register_operand" "=x")
5819         (umaxmin:VI124_256
5820           (match_operand:VI124_256 1 "nonimmediate_operand" "%x")
5821           (match_operand:VI124_256 2 "nonimmediate_operand" "xm")))]
5822   "TARGET_AVX2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5823   "vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5824   [(set_attr "type" "sseiadd")
5825    (set_attr "prefix_extra" "1")
5826    (set_attr "prefix" "vex")
5827    (set_attr "mode" "OI")])
5828
5829 (define_insn "sse2_lshrv1ti3"
5830   [(set (match_operand:V1TI 0 "register_operand" "=x,x")
5831         (lshiftrt:V1TI
5832          (match_operand:V1TI 1 "register_operand" "0,x")
5833          (match_operand:SI 2 "const_0_to_255_mul_8_operand" "n,n")))]
5834   "TARGET_SSE2"
5835 {
5836   operands[2] = GEN_INT (INTVAL (operands[2]) / 8);
5837
5838   switch (which_alternative)
5839     {
5840     case 0:
5841       return "psrldq\t{%2, %0|%0, %2}";
5842     case 1:
5843       return "vpsrldq\t{%2, %1, %0|%0, %1, %2}";
5844     default:
5845       gcc_unreachable ();
5846     }
5847 }
5848   [(set_attr "isa" "noavx,avx")
5849    (set_attr "type" "sseishft")
5850    (set_attr "length_immediate" "1")
5851    (set_attr "atom_unit" "sishuf")
5852    (set_attr "prefix_data16" "1,*")
5853    (set_attr "prefix" "orig,vex")
5854    (set_attr "mode" "TI")])
5855
5856 (define_expand "<code><mode>3"
5857   [(set (match_operand:VI124_256 0 "register_operand" "")
5858         (smaxmin:VI124_256
5859           (match_operand:VI124_256 1 "nonimmediate_operand" "")
5860           (match_operand:VI124_256 2 "nonimmediate_operand" "")))]
5861   "TARGET_AVX2"
5862   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
5863
5864 (define_insn "*avx2_<code><mode>3"
5865   [(set (match_operand:VI124_256 0 "register_operand" "=x")
5866         (smaxmin:VI124_256
5867           (match_operand:VI124_256 1 "nonimmediate_operand" "%x")
5868           (match_operand:VI124_256 2 "nonimmediate_operand" "xm")))]
5869   "TARGET_AVX2 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5870   "vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5871   [(set_attr "type" "sseiadd")
5872    (set_attr "prefix_extra" "1")
5873    (set_attr "prefix" "vex")
5874    (set_attr "mode" "OI")])
5875
5876 (define_insn "*sse4_1_<code><mode>3"
5877   [(set (match_operand:VI14_128 0 "register_operand" "=x,x")
5878         (smaxmin:VI14_128
5879           (match_operand:VI14_128 1 "nonimmediate_operand" "%0,x")
5880           (match_operand:VI14_128 2 "nonimmediate_operand" "xm,xm")))]
5881   "TARGET_SSE4_1 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5882   "@
5883    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
5884    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5885   [(set_attr "isa" "noavx,avx")
5886    (set_attr "type" "sseiadd")
5887    (set_attr "prefix_extra" "1,*")
5888    (set_attr "prefix" "orig,vex")
5889    (set_attr "mode" "TI")])
5890
5891 (define_insn "*<code>v8hi3"
5892   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
5893         (smaxmin:V8HI
5894           (match_operand:V8HI 1 "nonimmediate_operand" "%0,x")
5895           (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))]
5896   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V8HImode, operands)"
5897   "@
5898    p<maxmin_int>w\t{%2, %0|%0, %2}
5899    vp<maxmin_int>w\t{%2, %1, %0|%0, %1, %2}"
5900   [(set_attr "isa" "noavx,avx")
5901    (set_attr "type" "sseiadd")
5902    (set_attr "prefix_data16" "1,*")
5903    (set_attr "prefix_extra" "*,1")
5904    (set_attr "prefix" "orig,vex")
5905    (set_attr "mode" "TI")])
5906
5907 (define_expand "<code><mode>3"
5908   [(set (match_operand:VI14_128 0 "register_operand" "")
5909         (smaxmin:VI14_128 (match_operand:VI14_128 1 "register_operand" "")
5910                           (match_operand:VI14_128 2 "register_operand" "")))]
5911   "TARGET_SSE2"
5912 {
5913   if (TARGET_SSE4_1)
5914     ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);
5915   else
5916     {
5917       rtx xops[6];
5918       bool ok;
5919
5920       xops[0] = operands[0];
5921       xops[1] = operands[<CODE> == SMAX ? 1 : 2];
5922       xops[2] = operands[<CODE> == SMAX ? 2 : 1];
5923       xops[3] = gen_rtx_GT (VOIDmode, operands[1], operands[2]);
5924       xops[4] = operands[1];
5925       xops[5] = operands[2];
5926       ok = ix86_expand_int_vcond (xops);
5927       gcc_assert (ok);
5928       DONE;
5929     }
5930 })
5931
5932 (define_expand "<code>v8hi3"
5933   [(set (match_operand:V8HI 0 "register_operand" "")
5934         (smaxmin:V8HI
5935           (match_operand:V8HI 1 "nonimmediate_operand" "")
5936           (match_operand:V8HI 2 "nonimmediate_operand" "")))]
5937   "TARGET_SSE2"
5938   "ix86_fixup_binary_operands_no_copy (<CODE>, V8HImode, operands);")
5939
5940 (define_expand "<code><mode>3"
5941   [(set (match_operand:VI8_AVX2 0 "register_operand" "")
5942         (smaxmin:VI8_AVX2 (match_operand:VI8_AVX2 1 "register_operand" "")
5943                           (match_operand:VI8_AVX2 2 "register_operand" "")))]
5944   "TARGET_SSE4_2"
5945 {
5946   rtx xops[6];
5947   bool ok;
5948
5949   xops[0] = operands[0];
5950   xops[1] = operands[<CODE> == SMAX ? 1 : 2];
5951   xops[2] = operands[<CODE> == SMAX ? 2 : 1];
5952   xops[3] = gen_rtx_GT (VOIDmode, operands[1], operands[2]);
5953   xops[4] = operands[1];
5954   xops[5] = operands[2];
5955   ok = ix86_expand_int_vcond (xops);
5956   gcc_assert (ok);
5957   DONE;
5958 })
5959
5960 (define_insn "*sse4_1_<code><mode>3"
5961   [(set (match_operand:VI24_128 0 "register_operand" "=x,x")
5962         (umaxmin:VI24_128
5963           (match_operand:VI24_128 1 "nonimmediate_operand" "%0,x")
5964           (match_operand:VI24_128 2 "nonimmediate_operand" "xm,xm")))]
5965   "TARGET_SSE4_1 && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
5966   "@
5967    p<maxmin_int><ssemodesuffix>\t{%2, %0|%0, %2}
5968    vp<maxmin_int><ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
5969   [(set_attr "isa" "noavx,avx")
5970    (set_attr "type" "sseiadd")
5971    (set_attr "prefix_extra" "1,*")
5972    (set_attr "prefix" "orig,vex")
5973    (set_attr "mode" "TI")])
5974
5975 (define_insn "*<code>v16qi3"
5976   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
5977         (umaxmin:V16QI
5978           (match_operand:V16QI 1 "nonimmediate_operand" "%0,x")
5979           (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")))]
5980   "TARGET_SSE2 && ix86_binary_operator_ok (<CODE>, V16QImode, operands)"
5981   "@
5982    p<maxmin_int>b\t{%2, %0|%0, %2}
5983    vp<maxmin_int>b\t{%2, %1, %0|%0, %1, %2}"
5984   [(set_attr "isa" "noavx,avx")
5985    (set_attr "type" "sseiadd")
5986    (set_attr "prefix_data16" "1,*")
5987    (set_attr "prefix_extra" "*,1")
5988    (set_attr "prefix" "orig,vex")
5989    (set_attr "mode" "TI")])
5990
5991 (define_expand "<code>v16qi3"
5992   [(set (match_operand:V16QI 0 "register_operand" "")
5993         (umaxmin:V16QI
5994           (match_operand:V16QI 1 "nonimmediate_operand" "")
5995           (match_operand:V16QI 2 "nonimmediate_operand" "")))]
5996   "TARGET_SSE2"
5997   "ix86_fixup_binary_operands_no_copy (<CODE>, V16QImode, operands);")
5998
5999 (define_expand "umaxv8hi3"
6000   [(set (match_operand:V8HI 0 "register_operand" "")
6001         (umax:V8HI (match_operand:V8HI 1 "register_operand" "")
6002                    (match_operand:V8HI 2 "nonimmediate_operand" "")))]
6003   "TARGET_SSE2"
6004 {
6005   if (TARGET_SSE4_1)
6006     ix86_fixup_binary_operands_no_copy (UMAX, V8HImode, operands);
6007   else
6008     {
6009       rtx op0 = operands[0], op2 = operands[2], op3 = op0;
6010       if (rtx_equal_p (op3, op2))
6011         op3 = gen_reg_rtx (V8HImode);
6012       emit_insn (gen_sse2_ussubv8hi3 (op3, operands[1], op2));
6013       emit_insn (gen_addv8hi3 (op0, op3, op2));
6014       DONE;
6015     }
6016 })
6017
6018 (define_expand "umaxv4si3"
6019   [(set (match_operand:V4SI 0 "register_operand" "")
6020         (umax:V4SI (match_operand:V4SI 1 "register_operand" "")
6021                    (match_operand:V4SI 2 "register_operand" "")))]
6022   "TARGET_SSE2"
6023 {
6024   if (TARGET_SSE4_1)
6025     ix86_fixup_binary_operands_no_copy (UMAX, V4SImode, operands);
6026   else
6027     {
6028       rtx xops[6];
6029       bool ok;
6030
6031       xops[0] = operands[0];
6032       xops[1] = operands[1];
6033       xops[2] = operands[2];
6034       xops[3] = gen_rtx_GTU (VOIDmode, operands[1], operands[2]);
6035       xops[4] = operands[1];
6036       xops[5] = operands[2];
6037       ok = ix86_expand_int_vcond (xops);
6038       gcc_assert (ok);
6039       DONE;
6040     }
6041 })
6042
6043 (define_expand "umin<mode>3"
6044   [(set (match_operand:VI24_128 0 "register_operand" "")
6045         (umin:VI24_128 (match_operand:VI24_128 1 "register_operand" "")
6046                        (match_operand:VI24_128 2 "register_operand" "")))]
6047   "TARGET_SSE2"
6048 {
6049   if (TARGET_SSE4_1)
6050     ix86_fixup_binary_operands_no_copy (UMIN, <MODE>mode, operands);
6051   else
6052     {
6053       rtx xops[6];
6054       bool ok;
6055
6056       xops[0] = operands[0];
6057       xops[1] = operands[2];
6058       xops[2] = operands[1];
6059       xops[3] = gen_rtx_GTU (VOIDmode, operands[1], operands[2]);
6060       xops[4] = operands[1];
6061       xops[5] = operands[2];
6062       ok = ix86_expand_int_vcond (xops);
6063       gcc_assert (ok);
6064       DONE;
6065     }
6066 })
6067
6068 (define_expand "<code><mode>3"
6069   [(set (match_operand:VI8_AVX2 0 "register_operand" "")
6070         (umaxmin:VI8_AVX2 (match_operand:VI8_AVX2 1 "register_operand" "")
6071                           (match_operand:VI8_AVX2 2 "register_operand" "")))]
6072   "TARGET_SSE4_2"
6073 {
6074   rtx xops[6];
6075   bool ok;
6076
6077   xops[0] = operands[0];
6078   xops[1] = operands[<CODE> == UMAX ? 1 : 2];
6079   xops[2] = operands[<CODE> == UMAX ? 2 : 1];
6080   xops[3] = gen_rtx_GTU (VOIDmode, operands[1], operands[2]);
6081   xops[4] = operands[1];
6082   xops[5] = operands[2];
6083   ok = ix86_expand_int_vcond (xops);
6084   gcc_assert (ok);
6085   DONE;
6086 })
6087
6088 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6089 ;;
6090 ;; Parallel integral comparisons
6091 ;;
6092 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6093
6094 (define_expand "avx2_eq<mode>3"
6095   [(set (match_operand:VI1248_256 0 "register_operand" "")
6096         (eq:VI1248_256
6097           (match_operand:VI1248_256 1 "nonimmediate_operand" "")
6098           (match_operand:VI1248_256 2 "nonimmediate_operand" "")))]
6099   "TARGET_AVX2"
6100   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
6101
6102 (define_insn "*avx2_eq<mode>3"
6103   [(set (match_operand:VI1248_256 0 "register_operand" "=x")
6104         (eq:VI1248_256
6105           (match_operand:VI1248_256 1 "nonimmediate_operand" "%x")
6106           (match_operand:VI1248_256 2 "nonimmediate_operand" "xm")))]
6107   "TARGET_AVX2 && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
6108   "vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6109   [(set_attr "type" "ssecmp")
6110    (set_attr "prefix_extra" "1")
6111    (set_attr "prefix" "vex")
6112    (set_attr "mode" "OI")])
6113
6114 (define_insn "*sse4_1_eqv2di3"
6115   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
6116         (eq:V2DI
6117           (match_operand:V2DI 1 "nonimmediate_operand" "%0,x")
6118           (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")))]
6119   "TARGET_SSE4_1 && ix86_binary_operator_ok (EQ, V2DImode, operands)"
6120   "@
6121    pcmpeqq\t{%2, %0|%0, %2}
6122    vpcmpeqq\t{%2, %1, %0|%0, %1, %2}"
6123   [(set_attr "isa" "noavx,avx")
6124    (set_attr "type" "ssecmp")
6125    (set_attr "prefix_extra" "1")
6126    (set_attr "prefix" "orig,vex")
6127    (set_attr "mode" "TI")])
6128
6129 (define_insn "*sse2_eq<mode>3"
6130   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
6131         (eq:VI124_128
6132           (match_operand:VI124_128 1 "nonimmediate_operand" "%0,x")
6133           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
6134   "TARGET_SSE2 && !TARGET_XOP
6135    && ix86_binary_operator_ok (EQ, <MODE>mode, operands)"
6136   "@
6137    pcmpeq<ssemodesuffix>\t{%2, %0|%0, %2}
6138    vpcmpeq<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6139   [(set_attr "isa" "noavx,avx")
6140    (set_attr "type" "ssecmp")
6141    (set_attr "prefix_data16" "1,*")
6142    (set_attr "prefix" "orig,vex")
6143    (set_attr "mode" "TI")])
6144
6145 (define_expand "sse2_eq<mode>3"
6146   [(set (match_operand:VI124_128 0 "register_operand" "")
6147         (eq:VI124_128
6148           (match_operand:VI124_128 1 "nonimmediate_operand" "")
6149           (match_operand:VI124_128 2 "nonimmediate_operand" "")))]
6150   "TARGET_SSE2 && !TARGET_XOP "
6151   "ix86_fixup_binary_operands_no_copy (EQ, <MODE>mode, operands);")
6152
6153 (define_expand "sse4_1_eqv2di3"
6154   [(set (match_operand:V2DI 0 "register_operand" "")
6155         (eq:V2DI
6156           (match_operand:V2DI 1 "nonimmediate_operand" "")
6157           (match_operand:V2DI 2 "nonimmediate_operand" "")))]
6158   "TARGET_SSE4_1"
6159   "ix86_fixup_binary_operands_no_copy (EQ, V2DImode, operands);")
6160
6161 (define_insn "sse4_2_gtv2di3"
6162   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
6163         (gt:V2DI
6164           (match_operand:V2DI 1 "register_operand" "0,x")
6165           (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")))]
6166   "TARGET_SSE4_2"
6167   "@
6168    pcmpgtq\t{%2, %0|%0, %2}
6169    vpcmpgtq\t{%2, %1, %0|%0, %1, %2}"
6170   [(set_attr "isa" "noavx,avx")
6171    (set_attr "type" "ssecmp")
6172    (set_attr "prefix_extra" "1")
6173    (set_attr "prefix" "orig,vex")
6174    (set_attr "mode" "TI")])
6175
6176 (define_insn "avx2_gt<mode>3"
6177   [(set (match_operand:VI1248_256 0 "register_operand" "=x")
6178         (gt:VI1248_256
6179           (match_operand:VI1248_256 1 "register_operand" "x")
6180           (match_operand:VI1248_256 2 "nonimmediate_operand" "xm")))]
6181   "TARGET_AVX2"
6182   "vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6183   [(set_attr "type" "ssecmp")
6184    (set_attr "prefix_extra" "1")
6185    (set_attr "prefix" "vex")
6186    (set_attr "mode" "OI")])
6187
6188 (define_insn "sse2_gt<mode>3"
6189   [(set (match_operand:VI124_128 0 "register_operand" "=x,x")
6190         (gt:VI124_128
6191           (match_operand:VI124_128 1 "register_operand" "0,x")
6192           (match_operand:VI124_128 2 "nonimmediate_operand" "xm,xm")))]
6193   "TARGET_SSE2 && !TARGET_XOP"
6194   "@
6195    pcmpgt<ssemodesuffix>\t{%2, %0|%0, %2}
6196    vpcmpgt<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
6197   [(set_attr "isa" "noavx,avx")
6198    (set_attr "type" "ssecmp")
6199    (set_attr "prefix_data16" "1,*")
6200    (set_attr "prefix" "orig,vex")
6201    (set_attr "mode" "TI")])
6202
6203 (define_expand "vcond<V_256:mode><VI_256:mode>"
6204   [(set (match_operand:V_256 0 "register_operand" "")
6205         (if_then_else:V_256
6206           (match_operator 3 ""
6207             [(match_operand:VI_256 4 "nonimmediate_operand" "")
6208              (match_operand:VI_256 5 "nonimmediate_operand" "")])
6209           (match_operand:V_256 1 "general_operand" "")
6210           (match_operand:V_256 2 "general_operand" "")))]
6211   "TARGET_AVX2
6212    && (GET_MODE_NUNITS (<V_256:MODE>mode)
6213        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
6214 {
6215   bool ok = ix86_expand_int_vcond (operands);
6216   gcc_assert (ok);
6217   DONE;
6218 })
6219
6220 (define_expand "vcond<V_128:mode><VI124_128:mode>"
6221   [(set (match_operand:V_128 0 "register_operand" "")
6222         (if_then_else:V_128
6223           (match_operator 3 ""
6224             [(match_operand:VI124_128 4 "nonimmediate_operand" "")
6225              (match_operand:VI124_128 5 "nonimmediate_operand" "")])
6226           (match_operand:V_128 1 "general_operand" "")
6227           (match_operand:V_128 2 "general_operand" "")))]
6228   "TARGET_SSE2
6229    && (GET_MODE_NUNITS (<V_128:MODE>mode)
6230        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
6231 {
6232   bool ok = ix86_expand_int_vcond (operands);
6233   gcc_assert (ok);
6234   DONE;
6235 })
6236
6237 (define_expand "vcond<VI8F_128:mode>v2di"
6238   [(set (match_operand:VI8F_128 0 "register_operand" "")
6239         (if_then_else:VI8F_128
6240           (match_operator 3 ""
6241             [(match_operand:V2DI 4 "nonimmediate_operand" "")
6242              (match_operand:V2DI 5 "nonimmediate_operand" "")])
6243           (match_operand:VI8F_128 1 "general_operand" "")
6244           (match_operand:VI8F_128 2 "general_operand" "")))]
6245   "TARGET_SSE4_2"
6246 {
6247   bool ok = ix86_expand_int_vcond (operands);
6248   gcc_assert (ok);
6249   DONE;
6250 })
6251
6252 (define_expand "vcondu<V_256:mode><VI_256:mode>"
6253   [(set (match_operand:V_256 0 "register_operand" "")
6254         (if_then_else:V_256
6255           (match_operator 3 ""
6256             [(match_operand:VI_256 4 "nonimmediate_operand" "")
6257              (match_operand:VI_256 5 "nonimmediate_operand" "")])
6258           (match_operand:V_256 1 "general_operand" "")
6259           (match_operand:V_256 2 "general_operand" "")))]
6260   "TARGET_AVX2
6261    && (GET_MODE_NUNITS (<V_256:MODE>mode)
6262        == GET_MODE_NUNITS (<VI_256:MODE>mode))"
6263 {
6264   bool ok = ix86_expand_int_vcond (operands);
6265   gcc_assert (ok);
6266   DONE;
6267 })
6268
6269 (define_expand "vcondu<V_128:mode><VI124_128:mode>"
6270   [(set (match_operand:V_128 0 "register_operand" "")
6271         (if_then_else:V_128
6272           (match_operator 3 ""
6273             [(match_operand:VI124_128 4 "nonimmediate_operand" "")
6274              (match_operand:VI124_128 5 "nonimmediate_operand" "")])
6275           (match_operand:V_128 1 "general_operand" "")
6276           (match_operand:V_128 2 "general_operand" "")))]
6277   "TARGET_SSE2
6278    && (GET_MODE_NUNITS (<V_128:MODE>mode)
6279        == GET_MODE_NUNITS (<VI124_128:MODE>mode))"
6280 {
6281   bool ok = ix86_expand_int_vcond (operands);
6282   gcc_assert (ok);
6283   DONE;
6284 })
6285
6286 (define_expand "vcondu<VI8F_128:mode>v2di"
6287   [(set (match_operand:VI8F_128 0 "register_operand" "")
6288         (if_then_else:VI8F_128
6289           (match_operator 3 ""
6290             [(match_operand:V2DI 4 "nonimmediate_operand" "")
6291              (match_operand:V2DI 5 "nonimmediate_operand" "")])
6292           (match_operand:VI8F_128 1 "general_operand" "")
6293           (match_operand:VI8F_128 2 "general_operand" "")))]
6294   "TARGET_SSE4_2"
6295 {
6296   bool ok = ix86_expand_int_vcond (operands);
6297   gcc_assert (ok);
6298   DONE;
6299 })
6300
6301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6302 ;;
6303 ;; Parallel bitwise logical operations
6304 ;;
6305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6306
6307 (define_expand "one_cmpl<mode>2"
6308   [(set (match_operand:VI 0 "register_operand" "")
6309         (xor:VI (match_operand:VI 1 "nonimmediate_operand" "")
6310                 (match_dup 2)))]
6311   "TARGET_SSE"
6312 {
6313   int i, n = GET_MODE_NUNITS (<MODE>mode);
6314   rtvec v = rtvec_alloc (n);
6315
6316   for (i = 0; i < n; ++i)
6317     RTVEC_ELT (v, i) = constm1_rtx;
6318
6319   operands[2] = force_reg (<MODE>mode, gen_rtx_CONST_VECTOR (<MODE>mode, v));
6320 })
6321
6322 (define_expand "<sse2_avx2>_andnot<mode>3"
6323   [(set (match_operand:VI_AVX2 0 "register_operand" "")
6324         (and:VI_AVX2
6325           (not:VI_AVX2 (match_operand:VI_AVX2 1 "register_operand" ""))
6326           (match_operand:VI_AVX2 2 "nonimmediate_operand" "")))]
6327   "TARGET_SSE2")
6328
6329 (define_insn "*andnot<mode>3"
6330   [(set (match_operand:VI 0 "register_operand" "=x,x")
6331         (and:VI
6332           (not:VI (match_operand:VI 1 "register_operand" "0,x"))
6333           (match_operand:VI 2 "nonimmediate_operand" "xm,xm")))]
6334   "TARGET_SSE"
6335 {
6336   static char buf[32];
6337   const char *ops;
6338   const char *tmp;
6339
6340   switch (get_attr_mode (insn))
6341     {
6342     case MODE_OI:
6343       gcc_assert (TARGET_AVX2);
6344     case MODE_TI:
6345       gcc_assert (TARGET_SSE2);
6346
6347       tmp = "pandn";
6348       break;
6349
6350    case MODE_V8SF:
6351       gcc_assert (TARGET_AVX);
6352    case MODE_V4SF:
6353       gcc_assert (TARGET_SSE);
6354
6355       tmp = "andnps";
6356       break;
6357
6358    default:
6359       gcc_unreachable ();
6360    }
6361
6362   switch (which_alternative)
6363     {
6364     case 0:
6365       ops = "%s\t{%%2, %%0|%%0, %%2}";
6366       break;
6367     case 1:
6368       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
6369       break;
6370     default:
6371       gcc_unreachable ();
6372     }
6373
6374   snprintf (buf, sizeof (buf), ops, tmp);
6375   return buf;
6376 }
6377   [(set_attr "isa" "noavx,avx")
6378    (set_attr "type" "sselog")
6379    (set (attr "prefix_data16")
6380      (if_then_else
6381        (and (eq_attr "alternative" "0")
6382             (eq_attr "mode" "TI"))
6383        (const_string "1")
6384        (const_string "*")))
6385    (set_attr "prefix" "orig,vex")
6386    (set (attr "mode")
6387      (cond [(and (not (match_test "TARGET_AVX2"))
6388                  (match_test "GET_MODE_SIZE (<MODE>mode) > 16"))
6389               (const_string "V8SF")
6390             (not (match_test "TARGET_SSE2"))
6391               (const_string "V4SF")
6392            ]
6393            (const_string "<sseinsnmode>")))])
6394
6395 (define_expand "<code><mode>3"
6396   [(set (match_operand:VI 0 "register_operand" "")
6397         (any_logic:VI
6398           (match_operand:VI 1 "nonimmediate_operand" "")
6399           (match_operand:VI 2 "nonimmediate_operand" "")))]
6400   "TARGET_SSE"
6401   "ix86_fixup_binary_operands_no_copy (<CODE>, <MODE>mode, operands);")
6402
6403 (define_insn "*<code><mode>3"
6404   [(set (match_operand:VI 0 "register_operand" "=x,x")
6405         (any_logic:VI
6406           (match_operand:VI 1 "nonimmediate_operand" "%0,x")
6407           (match_operand:VI 2 "nonimmediate_operand" "xm,xm")))]
6408   "TARGET_SSE
6409    && ix86_binary_operator_ok (<CODE>, <MODE>mode, operands)"
6410 {
6411   static char buf[32];
6412   const char *ops;
6413   const char *tmp;
6414
6415   switch (get_attr_mode (insn))
6416     {
6417     case MODE_OI:
6418       gcc_assert (TARGET_AVX2);
6419     case MODE_TI:
6420       gcc_assert (TARGET_SSE2);
6421
6422       tmp = "p<logic>";
6423       break;
6424
6425    case MODE_V8SF:
6426       gcc_assert (TARGET_AVX);
6427    case MODE_V4SF:
6428       gcc_assert (TARGET_SSE);
6429
6430       tmp = "<logic>ps";
6431       break;
6432
6433    default:
6434       gcc_unreachable ();
6435    }
6436
6437   switch (which_alternative)
6438     {
6439     case 0:
6440       ops = "%s\t{%%2, %%0|%%0, %%2}";
6441       break;
6442     case 1:
6443       ops = "v%s\t{%%2, %%1, %%0|%%0, %%1, %%2}";
6444       break;
6445     default:
6446       gcc_unreachable ();
6447     }
6448
6449   snprintf (buf, sizeof (buf), ops, tmp);
6450   return buf;
6451 }
6452   [(set_attr "isa" "noavx,avx")
6453    (set_attr "type" "sselog")
6454    (set (attr "prefix_data16")
6455      (if_then_else
6456        (and (eq_attr "alternative" "0")
6457             (eq_attr "mode" "TI"))
6458        (const_string "1")
6459        (const_string "*")))
6460    (set_attr "prefix" "orig,vex")
6461    (set (attr "mode")
6462      (cond [(and (not (match_test "TARGET_AVX2"))
6463                  (match_test "GET_MODE_SIZE (<MODE>mode) > 16"))
6464               (const_string "V8SF")
6465             (not (match_test "TARGET_SSE2"))
6466               (const_string "V4SF")
6467            ]
6468            (const_string "<sseinsnmode>")))])
6469
6470 (define_insn "*andnottf3"
6471   [(set (match_operand:TF 0 "register_operand" "=x,x")
6472         (and:TF
6473           (not:TF (match_operand:TF 1 "register_operand" "0,x"))
6474           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
6475   "TARGET_SSE2"
6476   "@
6477    pandn\t{%2, %0|%0, %2}
6478    vpandn\t{%2, %1, %0|%0, %1, %2}"
6479   [(set_attr "isa" "noavx,avx")
6480    (set_attr "type" "sselog")
6481    (set_attr "prefix_data16" "1,*")
6482    (set_attr "prefix" "orig,vex")
6483    (set_attr "mode" "TI")])
6484
6485 (define_expand "<code>tf3"
6486   [(set (match_operand:TF 0 "register_operand" "")
6487         (any_logic:TF
6488           (match_operand:TF 1 "nonimmediate_operand" "")
6489           (match_operand:TF 2 "nonimmediate_operand" "")))]
6490   "TARGET_SSE2"
6491   "ix86_fixup_binary_operands_no_copy (<CODE>, TFmode, operands);")
6492
6493 (define_insn "*<code>tf3"
6494   [(set (match_operand:TF 0 "register_operand" "=x,x")
6495         (any_logic:TF
6496           (match_operand:TF 1 "nonimmediate_operand" "%0,x")
6497           (match_operand:TF 2 "nonimmediate_operand" "xm,xm")))]
6498   "TARGET_SSE2
6499    && ix86_binary_operator_ok (<CODE>, TFmode, operands)"
6500   "@
6501    p<logic>\t{%2, %0|%0, %2}
6502    vp<logic>\t{%2, %1, %0|%0, %1, %2}"
6503   [(set_attr "isa" "noavx,avx")
6504    (set_attr "type" "sselog")
6505    (set_attr "prefix_data16" "1,*")
6506    (set_attr "prefix" "orig,vex")
6507    (set_attr "mode" "TI")])
6508
6509 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6510 ;;
6511 ;; Parallel integral element swizzling
6512 ;;
6513 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6514
6515 (define_expand "vec_pack_trunc_<mode>"
6516   [(match_operand:<ssepackmode> 0 "register_operand" "")
6517    (match_operand:VI248_128 1 "register_operand" "")
6518    (match_operand:VI248_128 2 "register_operand" "")]
6519   "TARGET_SSE2"
6520 {
6521   rtx op1 = gen_lowpart (<ssepackmode>mode, operands[1]);
6522   rtx op2 = gen_lowpart (<ssepackmode>mode, operands[2]);
6523   ix86_expand_vec_extract_even_odd (operands[0], op1, op2, 0);
6524   DONE;
6525 })
6526
6527 (define_insn "<sse2_avx2>_packsswb"
6528   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
6529         (vec_concat:VI1_AVX2
6530           (ss_truncate:<ssehalfvecmode>
6531             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6532           (ss_truncate:<ssehalfvecmode>
6533             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6534   "TARGET_SSE2"
6535   "@
6536    packsswb\t{%2, %0|%0, %2}
6537    vpacksswb\t{%2, %1, %0|%0, %1, %2}"
6538   [(set_attr "isa" "noavx,avx")
6539    (set_attr "type" "sselog")
6540    (set_attr "prefix_data16" "1,*")
6541    (set_attr "prefix" "orig,vex")
6542    (set_attr "mode" "<sseinsnmode>")])
6543
6544 (define_insn "<sse2_avx2>_packssdw"
6545   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
6546         (vec_concat:VI2_AVX2
6547           (ss_truncate:<ssehalfvecmode>
6548             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6549           (ss_truncate:<ssehalfvecmode>
6550             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6551   "TARGET_SSE2"
6552   "@
6553    packssdw\t{%2, %0|%0, %2}
6554    vpackssdw\t{%2, %1, %0|%0, %1, %2}"
6555   [(set_attr "isa" "noavx,avx")
6556    (set_attr "type" "sselog")
6557    (set_attr "prefix_data16" "1,*")
6558    (set_attr "prefix" "orig,vex")
6559    (set_attr "mode" "<sseinsnmode>")])
6560
6561 (define_insn "<sse2_avx2>_packuswb"
6562   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
6563         (vec_concat:VI1_AVX2
6564           (us_truncate:<ssehalfvecmode>
6565             (match_operand:<sseunpackmode> 1 "register_operand" "0,x"))
6566           (us_truncate:<ssehalfvecmode>
6567             (match_operand:<sseunpackmode> 2 "nonimmediate_operand" "xm,xm"))))]
6568   "TARGET_SSE2"
6569   "@
6570    packuswb\t{%2, %0|%0, %2}
6571    vpackuswb\t{%2, %1, %0|%0, %1, %2}"
6572   [(set_attr "isa" "noavx,avx")
6573    (set_attr "type" "sselog")
6574    (set_attr "prefix_data16" "1,*")
6575    (set_attr "prefix" "orig,vex")
6576    (set_attr "mode" "<sseinsnmode>")])
6577
6578 (define_insn "avx2_interleave_highv32qi"
6579   [(set (match_operand:V32QI 0 "register_operand" "=x")
6580         (vec_select:V32QI
6581           (vec_concat:V64QI
6582             (match_operand:V32QI 1 "register_operand" "x")
6583             (match_operand:V32QI 2 "nonimmediate_operand" "xm"))
6584           (parallel [(const_int 8)  (const_int 40)
6585                      (const_int 9)  (const_int 41)
6586                      (const_int 10) (const_int 42)
6587                      (const_int 11) (const_int 43)
6588                      (const_int 12) (const_int 44)
6589                      (const_int 13) (const_int 45)
6590                      (const_int 14) (const_int 46)
6591                      (const_int 15) (const_int 47)
6592                      (const_int 24) (const_int 56)
6593                      (const_int 25) (const_int 57)
6594                      (const_int 26) (const_int 58)
6595                      (const_int 27) (const_int 59)
6596                      (const_int 28) (const_int 60)
6597                      (const_int 29) (const_int 61)
6598                      (const_int 30) (const_int 62)
6599                      (const_int 31) (const_int 63)
6600                      (const_int 32) (const_int 64)])))]
6601   "TARGET_AVX2"
6602   "vpunpckhbw\t{%2, %1, %0|%0, %1, %2}"
6603   [(set_attr "type" "sselog")
6604    (set_attr "prefix" "vex")
6605    (set_attr "mode" "OI")])
6606
6607 (define_insn "vec_interleave_highv16qi"
6608   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6609         (vec_select:V16QI
6610           (vec_concat:V32QI
6611             (match_operand:V16QI 1 "register_operand" "0,x")
6612             (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm"))
6613           (parallel [(const_int 8)  (const_int 24)
6614                      (const_int 9)  (const_int 25)
6615                      (const_int 10) (const_int 26)
6616                      (const_int 11) (const_int 27)
6617                      (const_int 12) (const_int 28)
6618                      (const_int 13) (const_int 29)
6619                      (const_int 14) (const_int 30)
6620                      (const_int 15) (const_int 31)])))]
6621   "TARGET_SSE2"
6622   "@
6623    punpckhbw\t{%2, %0|%0, %2}
6624    vpunpckhbw\t{%2, %1, %0|%0, %1, %2}"
6625   [(set_attr "isa" "noavx,avx")
6626    (set_attr "type" "sselog")
6627    (set_attr "prefix_data16" "1,*")
6628    (set_attr "prefix" "orig,vex")
6629    (set_attr "mode" "TI")])
6630
6631 (define_insn "avx2_interleave_lowv32qi"
6632   [(set (match_operand:V32QI 0 "register_operand" "=x")
6633         (vec_select:V32QI
6634           (vec_concat:V64QI
6635             (match_operand:V32QI 1 "register_operand" "x")
6636             (match_operand:V32QI 2 "nonimmediate_operand" "xm"))
6637           (parallel [(const_int 0) (const_int 32)
6638                      (const_int 1) (const_int 33)
6639                      (const_int 2) (const_int 34)
6640                      (const_int 3) (const_int 35)
6641                      (const_int 4) (const_int 36)
6642                      (const_int 5) (const_int 37)
6643                      (const_int 6) (const_int 38)
6644                      (const_int 7) (const_int 39)
6645                      (const_int 15) (const_int 47)
6646                      (const_int 16) (const_int 48)
6647                      (const_int 17) (const_int 49)
6648                      (const_int 18) (const_int 50)
6649                      (const_int 19) (const_int 51)
6650                      (const_int 20) (const_int 52)
6651                      (const_int 21) (const_int 53)
6652                      (const_int 22) (const_int 54)
6653                      (const_int 23) (const_int 55)])))]
6654   "TARGET_AVX2"
6655   "vpunpcklbw\t{%2, %1, %0|%0, %1, %2}"
6656   [(set_attr "type" "sselog")
6657    (set_attr "prefix" "vex")
6658    (set_attr "mode" "OI")])
6659
6660 (define_insn "vec_interleave_lowv16qi"
6661   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
6662         (vec_select:V16QI
6663           (vec_concat:V32QI
6664             (match_operand:V16QI 1 "register_operand" "0,x")
6665             (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm"))
6666           (parallel [(const_int 0) (const_int 16)
6667                      (const_int 1) (const_int 17)
6668                      (const_int 2) (const_int 18)
6669                      (const_int 3) (const_int 19)
6670                      (const_int 4) (const_int 20)
6671                      (const_int 5) (const_int 21)
6672                      (const_int 6) (const_int 22)
6673                      (const_int 7) (const_int 23)])))]
6674   "TARGET_SSE2"
6675   "@
6676    punpcklbw\t{%2, %0|%0, %2}
6677    vpunpcklbw\t{%2, %1, %0|%0, %1, %2}"
6678   [(set_attr "isa" "noavx,avx")
6679    (set_attr "type" "sselog")
6680    (set_attr "prefix_data16" "1,*")
6681    (set_attr "prefix" "orig,vex")
6682    (set_attr "mode" "TI")])
6683
6684 (define_insn "avx2_interleave_highv16hi"
6685   [(set (match_operand:V16HI 0 "register_operand" "=x")
6686         (vec_select:V16HI
6687           (vec_concat:V32HI
6688             (match_operand:V16HI 1 "register_operand" "x")
6689             (match_operand:V16HI 2 "nonimmediate_operand" "xm"))
6690           (parallel [(const_int 4) (const_int 20)
6691                      (const_int 5) (const_int 21)
6692                      (const_int 6) (const_int 22)
6693                      (const_int 7) (const_int 23)
6694                      (const_int 12) (const_int 28)
6695                      (const_int 13) (const_int 29)
6696                      (const_int 14) (const_int 30)
6697                      (const_int 15) (const_int 31)])))]
6698   "TARGET_AVX2"
6699   "vpunpckhwd\t{%2, %1, %0|%0, %1, %2}"
6700   [(set_attr "type" "sselog")
6701    (set_attr "prefix" "vex")
6702    (set_attr "mode" "OI")])
6703
6704 (define_insn "vec_interleave_highv8hi"
6705   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
6706         (vec_select:V8HI
6707           (vec_concat:V16HI
6708             (match_operand:V8HI 1 "register_operand" "0,x")
6709             (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm"))
6710           (parallel [(const_int 4) (const_int 12)
6711                      (const_int 5) (const_int 13)
6712                      (const_int 6) (const_int 14)
6713                      (const_int 7) (const_int 15)])))]
6714   "TARGET_SSE2"
6715   "@
6716    punpckhwd\t{%2, %0|%0, %2}
6717    vpunpckhwd\t{%2, %1, %0|%0, %1, %2}"
6718   [(set_attr "isa" "noavx,avx")
6719    (set_attr "type" "sselog")
6720    (set_attr "prefix_data16" "1,*")
6721    (set_attr "prefix" "orig,vex")
6722    (set_attr "mode" "TI")])
6723
6724 (define_insn "avx2_interleave_lowv16hi"
6725   [(set (match_operand:V16HI 0 "register_operand" "=x")
6726         (vec_select:V16HI
6727           (vec_concat:V32HI
6728             (match_operand:V16HI 1 "register_operand" "x")
6729             (match_operand:V16HI 2 "nonimmediate_operand" "xm"))
6730           (parallel [(const_int 0) (const_int 16)
6731                      (const_int 1) (const_int 17)
6732                      (const_int 2) (const_int 18)
6733                      (const_int 3) (const_int 19)
6734                      (const_int 8) (const_int 24)
6735                      (const_int 9) (const_int 25)
6736                      (const_int 10) (const_int 26)
6737                      (const_int 11) (const_int 27)])))]
6738   "TARGET_AVX2"
6739   "vpunpcklwd\t{%2, %1, %0|%0, %1, %2}"
6740   [(set_attr "type" "sselog")
6741    (set_attr "prefix" "vex")
6742    (set_attr "mode" "OI")])
6743
6744 (define_insn "vec_interleave_lowv8hi"
6745   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
6746         (vec_select:V8HI
6747           (vec_concat:V16HI
6748             (match_operand:V8HI 1 "register_operand" "0,x")
6749             (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm"))
6750           (parallel [(const_int 0) (const_int 8)
6751                      (const_int 1) (const_int 9)
6752                      (const_int 2) (const_int 10)
6753                      (const_int 3) (const_int 11)])))]
6754   "TARGET_SSE2"
6755   "@
6756    punpcklwd\t{%2, %0|%0, %2}
6757    vpunpcklwd\t{%2, %1, %0|%0, %1, %2}"
6758   [(set_attr "isa" "noavx,avx")
6759    (set_attr "type" "sselog")
6760    (set_attr "prefix_data16" "1,*")
6761    (set_attr "prefix" "orig,vex")
6762    (set_attr "mode" "TI")])
6763
6764 (define_insn "avx2_interleave_highv8si"
6765   [(set (match_operand:V8SI 0 "register_operand" "=x")
6766         (vec_select:V8SI
6767           (vec_concat:V16SI
6768             (match_operand:V8SI 1 "register_operand" "x")
6769             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))
6770           (parallel [(const_int 2) (const_int 10)
6771                      (const_int 3) (const_int 11)
6772                      (const_int 6) (const_int 14)
6773                      (const_int 7) (const_int 15)])))]
6774   "TARGET_AVX2"
6775   "vpunpckhdq\t{%2, %1, %0|%0, %1, %2}"
6776   [(set_attr "type" "sselog")
6777    (set_attr "prefix" "vex")
6778    (set_attr "mode" "OI")])
6779
6780 (define_insn "vec_interleave_highv4si"
6781   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
6782         (vec_select:V4SI
6783           (vec_concat:V8SI
6784             (match_operand:V4SI 1 "register_operand" "0,x")
6785             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))
6786           (parallel [(const_int 2) (const_int 6)
6787                      (const_int 3) (const_int 7)])))]
6788   "TARGET_SSE2"
6789   "@
6790    punpckhdq\t{%2, %0|%0, %2}
6791    vpunpckhdq\t{%2, %1, %0|%0, %1, %2}"
6792   [(set_attr "isa" "noavx,avx")
6793    (set_attr "type" "sselog")
6794    (set_attr "prefix_data16" "1,*")
6795    (set_attr "prefix" "orig,vex")
6796    (set_attr "mode" "TI")])
6797
6798 (define_insn "avx2_interleave_lowv8si"
6799   [(set (match_operand:V8SI 0 "register_operand" "=x")
6800         (vec_select:V8SI
6801           (vec_concat:V16SI
6802             (match_operand:V8SI 1 "register_operand" "x")
6803             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))
6804           (parallel [(const_int 0) (const_int 8)
6805                      (const_int 1) (const_int 9)
6806                      (const_int 4) (const_int 12)
6807                      (const_int 5) (const_int 13)])))]
6808   "TARGET_AVX2"
6809   "vpunpckldq\t{%2, %1, %0|%0, %1, %2}"
6810   [(set_attr "type" "sselog")
6811    (set_attr "prefix" "vex")
6812    (set_attr "mode" "OI")])
6813
6814 (define_insn "vec_interleave_lowv4si"
6815   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
6816         (vec_select:V4SI
6817           (vec_concat:V8SI
6818             (match_operand:V4SI 1 "register_operand" "0,x")
6819             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))
6820           (parallel [(const_int 0) (const_int 4)
6821                      (const_int 1) (const_int 5)])))]
6822   "TARGET_SSE2"
6823   "@
6824    punpckldq\t{%2, %0|%0, %2}
6825    vpunpckldq\t{%2, %1, %0|%0, %1, %2}"
6826   [(set_attr "isa" "noavx,avx")
6827    (set_attr "type" "sselog")
6828    (set_attr "prefix_data16" "1,*")
6829    (set_attr "prefix" "orig,vex")
6830    (set_attr "mode" "TI")])
6831
6832 ;; Modes handled by pinsr patterns.
6833 (define_mode_iterator PINSR_MODE
6834   [(V16QI "TARGET_SSE4_1") V8HI
6835    (V4SI "TARGET_SSE4_1")
6836    (V2DI "TARGET_SSE4_1 && TARGET_64BIT")])
6837
6838 (define_mode_attr sse2p4_1
6839   [(V16QI "sse4_1") (V8HI "sse2")
6840    (V4SI "sse4_1") (V2DI "sse4_1")])
6841
6842 ;; sse4_1_pinsrd must come before sse2_loadld since it is preferred.
6843 (define_insn "<sse2p4_1>_pinsr<ssemodesuffix>"
6844   [(set (match_operand:PINSR_MODE 0 "register_operand" "=x,x,x,x")
6845         (vec_merge:PINSR_MODE
6846           (vec_duplicate:PINSR_MODE
6847             (match_operand:<ssescalarmode> 2 "nonimmediate_operand" "r,m,r,m"))
6848           (match_operand:PINSR_MODE 1 "register_operand" "0,0,x,x")
6849           (match_operand:SI 3 "const_int_operand" "")))]
6850   "TARGET_SSE2
6851    && ((unsigned) exact_log2 (INTVAL (operands[3]))
6852        < GET_MODE_NUNITS (<MODE>mode))"
6853 {
6854   operands[3] = GEN_INT (exact_log2 (INTVAL (operands[3])));
6855
6856   switch (which_alternative)
6857     {
6858     case 0:
6859       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
6860         return "pinsr<ssemodesuffix>\t{%3, %k2, %0|%0, %k2, %3}";
6861       /* FALLTHRU */
6862     case 1:
6863       return "pinsr<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}";
6864     case 2:
6865       if (GET_MODE_SIZE (<ssescalarmode>mode) < GET_MODE_SIZE (SImode))
6866         return "vpinsr<ssemodesuffix>\t{%3, %k2, %1, %0|%0, %1, %k2, %3}";
6867       /* FALLTHRU */
6868     case 3:
6869       return "vpinsr<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}";
6870     default:
6871       gcc_unreachable ();
6872     }
6873 }
6874   [(set_attr "isa" "noavx,noavx,avx,avx")
6875    (set_attr "type" "sselog")
6876    (set (attr "prefix_rex")
6877      (if_then_else
6878        (and (not (match_test "TARGET_AVX"))
6879             (eq (const_string "<MODE>mode") (const_string "V2DImode")))
6880        (const_string "1")
6881        (const_string "*")))
6882    (set (attr "prefix_data16")
6883      (if_then_else
6884        (and (not (match_test "TARGET_AVX"))
6885             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
6886        (const_string "1")
6887        (const_string "*")))
6888    (set (attr "prefix_extra")
6889      (if_then_else
6890        (and (not (match_test "TARGET_AVX"))
6891             (eq (const_string "<MODE>mode") (const_string "V8HImode")))
6892        (const_string "*")
6893        (const_string "1")))
6894    (set_attr "length_immediate" "1")
6895    (set_attr "prefix" "orig,orig,vex,vex")
6896    (set_attr "mode" "TI")])
6897
6898 (define_insn "*sse4_1_pextrb_<mode>"
6899   [(set (match_operand:SWI48 0 "register_operand" "=r")
6900         (zero_extend:SWI48
6901           (vec_select:QI
6902             (match_operand:V16QI 1 "register_operand" "x")
6903             (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")]))))]
6904   "TARGET_SSE4_1"
6905   "%vpextrb\t{%2, %1, %k0|%k0, %1, %2}"
6906   [(set_attr "type" "sselog")
6907    (set_attr "prefix_extra" "1")
6908    (set_attr "length_immediate" "1")
6909    (set_attr "prefix" "maybe_vex")
6910    (set_attr "mode" "TI")])
6911
6912 (define_insn "*sse4_1_pextrb_memory"
6913   [(set (match_operand:QI 0 "memory_operand" "=m")
6914         (vec_select:QI
6915           (match_operand:V16QI 1 "register_operand" "x")
6916           (parallel [(match_operand:SI 2 "const_0_to_15_operand" "n")])))]
6917   "TARGET_SSE4_1"
6918   "%vpextrb\t{%2, %1, %0|%0, %1, %2}"
6919   [(set_attr "type" "sselog")
6920    (set_attr "prefix_extra" "1")
6921    (set_attr "length_immediate" "1")
6922    (set_attr "prefix" "maybe_vex")
6923    (set_attr "mode" "TI")])
6924
6925 (define_insn "*sse2_pextrw_<mode>"
6926   [(set (match_operand:SWI48 0 "register_operand" "=r")
6927         (zero_extend:SWI48
6928           (vec_select:HI
6929             (match_operand:V8HI 1 "register_operand" "x")
6930             (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")]))))]
6931   "TARGET_SSE2"
6932   "%vpextrw\t{%2, %1, %k0|%k0, %1, %2}"
6933   [(set_attr "type" "sselog")
6934    (set_attr "prefix_data16" "1")
6935    (set_attr "length_immediate" "1")
6936    (set_attr "prefix" "maybe_vex")
6937    (set_attr "mode" "TI")])
6938
6939 (define_insn "*sse4_1_pextrw_memory"
6940   [(set (match_operand:HI 0 "memory_operand" "=m")
6941         (vec_select:HI
6942           (match_operand:V8HI 1 "register_operand" "x")
6943           (parallel [(match_operand:SI 2 "const_0_to_7_operand" "n")])))]
6944   "TARGET_SSE4_1"
6945   "%vpextrw\t{%2, %1, %0|%0, %1, %2}"
6946   [(set_attr "type" "sselog")
6947    (set_attr "prefix_extra" "1")
6948    (set_attr "length_immediate" "1")
6949    (set_attr "prefix" "maybe_vex")
6950    (set_attr "mode" "TI")])
6951
6952 (define_insn "*sse4_1_pextrd"
6953   [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6954         (vec_select:SI
6955           (match_operand:V4SI 1 "register_operand" "x")
6956           (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")])))]
6957   "TARGET_SSE4_1"
6958   "%vpextrd\t{%2, %1, %0|%0, %1, %2}"
6959   [(set_attr "type" "sselog")
6960    (set_attr "prefix_extra" "1")
6961    (set_attr "length_immediate" "1")
6962    (set_attr "prefix" "maybe_vex")
6963    (set_attr "mode" "TI")])
6964
6965 (define_insn "*sse4_1_pextrd_zext"
6966   [(set (match_operand:DI 0 "register_operand" "=r")
6967         (zero_extend:DI
6968           (vec_select:SI
6969             (match_operand:V4SI 1 "register_operand" "x")
6970             (parallel [(match_operand:SI 2 "const_0_to_3_operand" "n")]))))]
6971   "TARGET_64BIT && TARGET_SSE4_1"
6972   "%vpextrd\t{%2, %1, %k0|%k0, %1, %2}"
6973   [(set_attr "type" "sselog")
6974    (set_attr "prefix_extra" "1")
6975    (set_attr "length_immediate" "1")
6976    (set_attr "prefix" "maybe_vex")
6977    (set_attr "mode" "TI")])
6978
6979 ;; It must come before *vec_extractv2di_1_rex64 since it is preferred.
6980 (define_insn "*sse4_1_pextrq"
6981   [(set (match_operand:DI 0 "nonimmediate_operand" "=rm")
6982         (vec_select:DI
6983           (match_operand:V2DI 1 "register_operand" "x")
6984           (parallel [(match_operand:SI 2 "const_0_to_1_operand" "n")])))]
6985   "TARGET_SSE4_1 && TARGET_64BIT"
6986   "%vpextrq\t{%2, %1, %0|%0, %1, %2}"
6987   [(set_attr "type" "sselog")
6988    (set_attr "prefix_rex" "1")
6989    (set_attr "prefix_extra" "1")
6990    (set_attr "length_immediate" "1")
6991    (set_attr "prefix" "maybe_vex")
6992    (set_attr "mode" "TI")])
6993
6994 (define_expand "avx2_pshufdv3"
6995   [(match_operand:V8SI 0 "register_operand" "")
6996    (match_operand:V8SI 1 "nonimmediate_operand" "")
6997    (match_operand:SI 2 "const_0_to_255_operand" "")]
6998   "TARGET_AVX2"
6999 {
7000   int mask = INTVAL (operands[2]);
7001   emit_insn (gen_avx2_pshufd_1 (operands[0], operands[1],
7002                                 GEN_INT ((mask >> 0) & 3),
7003                                 GEN_INT ((mask >> 2) & 3),
7004                                 GEN_INT ((mask >> 4) & 3),
7005                                 GEN_INT ((mask >> 6) & 3)));
7006   DONE;
7007 })
7008
7009 (define_insn "avx2_pshufd_1"
7010   [(set (match_operand:V8SI 0 "register_operand" "=x")
7011         (vec_select:V8SI
7012           (match_operand:V8SI 1 "nonimmediate_operand" "xm")
7013           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7014                      (match_operand 3 "const_0_to_3_operand" "")
7015                      (match_operand 4 "const_0_to_3_operand" "")
7016                      (match_operand 5 "const_0_to_3_operand" "")
7017                      (match_dup 2)
7018                      (match_dup 3)
7019                      (match_dup 4)
7020                      (match_dup 5)])))]
7021   "TARGET_AVX2"
7022 {
7023   int mask = 0;
7024   mask |= INTVAL (operands[2]) << 0;
7025   mask |= INTVAL (operands[3]) << 2;
7026   mask |= INTVAL (operands[4]) << 4;
7027   mask |= INTVAL (operands[5]) << 6;
7028   operands[2] = GEN_INT (mask);
7029
7030   return "vpshufd\t{%2, %1, %0|%0, %1, %2}";
7031 }
7032   [(set_attr "type" "sselog1")
7033    (set_attr "prefix" "vex")
7034    (set_attr "length_immediate" "1")
7035    (set_attr "mode" "OI")])
7036
7037 (define_expand "sse2_pshufd"
7038   [(match_operand:V4SI 0 "register_operand" "")
7039    (match_operand:V4SI 1 "nonimmediate_operand" "")
7040    (match_operand:SI 2 "const_int_operand" "")]
7041   "TARGET_SSE2"
7042 {
7043   int mask = INTVAL (operands[2]);
7044   emit_insn (gen_sse2_pshufd_1 (operands[0], operands[1],
7045                                 GEN_INT ((mask >> 0) & 3),
7046                                 GEN_INT ((mask >> 2) & 3),
7047                                 GEN_INT ((mask >> 4) & 3),
7048                                 GEN_INT ((mask >> 6) & 3)));
7049   DONE;
7050 })
7051
7052 (define_insn "sse2_pshufd_1"
7053   [(set (match_operand:V4SI 0 "register_operand" "=x")
7054         (vec_select:V4SI
7055           (match_operand:V4SI 1 "nonimmediate_operand" "xm")
7056           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7057                      (match_operand 3 "const_0_to_3_operand" "")
7058                      (match_operand 4 "const_0_to_3_operand" "")
7059                      (match_operand 5 "const_0_to_3_operand" "")])))]
7060   "TARGET_SSE2"
7061 {
7062   int mask = 0;
7063   mask |= INTVAL (operands[2]) << 0;
7064   mask |= INTVAL (operands[3]) << 2;
7065   mask |= INTVAL (operands[4]) << 4;
7066   mask |= INTVAL (operands[5]) << 6;
7067   operands[2] = GEN_INT (mask);
7068
7069   return "%vpshufd\t{%2, %1, %0|%0, %1, %2}";
7070 }
7071   [(set_attr "type" "sselog1")
7072    (set_attr "prefix_data16" "1")
7073    (set_attr "prefix" "maybe_vex")
7074    (set_attr "length_immediate" "1")
7075    (set_attr "mode" "TI")])
7076
7077 (define_expand "avx2_pshuflwv3"
7078   [(match_operand:V16HI 0 "register_operand" "")
7079    (match_operand:V16HI 1 "nonimmediate_operand" "")
7080    (match_operand:SI 2 "const_0_to_255_operand" "")]
7081   "TARGET_AVX2"
7082 {
7083   int mask = INTVAL (operands[2]);
7084   emit_insn (gen_avx2_pshuflw_1 (operands[0], operands[1],
7085                                  GEN_INT ((mask >> 0) & 3),
7086                                  GEN_INT ((mask >> 2) & 3),
7087                                  GEN_INT ((mask >> 4) & 3),
7088                                  GEN_INT ((mask >> 6) & 3)));
7089   DONE;
7090 })
7091
7092 (define_insn "avx2_pshuflw_1"
7093   [(set (match_operand:V16HI 0 "register_operand" "=x")
7094         (vec_select:V16HI
7095           (match_operand:V16HI 1 "nonimmediate_operand" "xm")
7096           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7097                      (match_operand 3 "const_0_to_3_operand" "")
7098                      (match_operand 4 "const_0_to_3_operand" "")
7099                      (match_operand 5 "const_0_to_3_operand" "")
7100                      (const_int 4)
7101                      (const_int 5)
7102                      (const_int 6)
7103                      (const_int 7)
7104                      (match_dup 2)
7105                      (match_dup 3)
7106                      (match_dup 4)
7107                      (match_dup 5)
7108                      (const_int 12)
7109                      (const_int 13)
7110                      (const_int 14)
7111                      (const_int 15)])))]
7112   "TARGET_AVX2"
7113 {
7114   int mask = 0;
7115   mask |= INTVAL (operands[2]) << 0;
7116   mask |= INTVAL (operands[3]) << 2;
7117   mask |= INTVAL (operands[4]) << 4;
7118   mask |= INTVAL (operands[5]) << 6;
7119   operands[2] = GEN_INT (mask);
7120
7121   return "vpshuflw\t{%2, %1, %0|%0, %1, %2}";
7122 }
7123   [(set_attr "type" "sselog")
7124    (set_attr "prefix" "vex")
7125    (set_attr "length_immediate" "1")
7126    (set_attr "mode" "OI")])
7127
7128 (define_expand "sse2_pshuflw"
7129   [(match_operand:V8HI 0 "register_operand" "")
7130    (match_operand:V8HI 1 "nonimmediate_operand" "")
7131    (match_operand:SI 2 "const_int_operand" "")]
7132   "TARGET_SSE2"
7133 {
7134   int mask = INTVAL (operands[2]);
7135   emit_insn (gen_sse2_pshuflw_1 (operands[0], operands[1],
7136                                  GEN_INT ((mask >> 0) & 3),
7137                                  GEN_INT ((mask >> 2) & 3),
7138                                  GEN_INT ((mask >> 4) & 3),
7139                                  GEN_INT ((mask >> 6) & 3)));
7140   DONE;
7141 })
7142
7143 (define_insn "sse2_pshuflw_1"
7144   [(set (match_operand:V8HI 0 "register_operand" "=x")
7145         (vec_select:V8HI
7146           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
7147           (parallel [(match_operand 2 "const_0_to_3_operand" "")
7148                      (match_operand 3 "const_0_to_3_operand" "")
7149                      (match_operand 4 "const_0_to_3_operand" "")
7150                      (match_operand 5 "const_0_to_3_operand" "")
7151                      (const_int 4)
7152                      (const_int 5)
7153                      (const_int 6)
7154                      (const_int 7)])))]
7155   "TARGET_SSE2"
7156 {
7157   int mask = 0;
7158   mask |= INTVAL (operands[2]) << 0;
7159   mask |= INTVAL (operands[3]) << 2;
7160   mask |= INTVAL (operands[4]) << 4;
7161   mask |= INTVAL (operands[5]) << 6;
7162   operands[2] = GEN_INT (mask);
7163
7164   return "%vpshuflw\t{%2, %1, %0|%0, %1, %2}";
7165 }
7166   [(set_attr "type" "sselog")
7167    (set_attr "prefix_data16" "0")
7168    (set_attr "prefix_rep" "1")
7169    (set_attr "prefix" "maybe_vex")
7170    (set_attr "length_immediate" "1")
7171    (set_attr "mode" "TI")])
7172
7173 (define_expand "avx2_pshufhwv3"
7174   [(match_operand:V16HI 0 "register_operand" "")
7175    (match_operand:V16HI 1 "nonimmediate_operand" "")
7176    (match_operand:SI 2 "const_0_to_255_operand" "")]
7177   "TARGET_AVX2"
7178 {
7179   int mask = INTVAL (operands[2]);
7180   emit_insn (gen_avx2_pshufhw_1 (operands[0], operands[1],
7181                                  GEN_INT (((mask >> 0) & 3) + 4),
7182                                  GEN_INT (((mask >> 2) & 3) + 4),
7183                                  GEN_INT (((mask >> 4) & 3) + 4),
7184                                  GEN_INT (((mask >> 6) & 3) + 4)));
7185   DONE;
7186 })
7187
7188 (define_insn "avx2_pshufhw_1"
7189   [(set (match_operand:V16HI 0 "register_operand" "=x")
7190         (vec_select:V16HI
7191           (match_operand:V16HI 1 "nonimmediate_operand" "xm")
7192           (parallel [(const_int 0)
7193                      (const_int 1)
7194                      (const_int 2)
7195                      (const_int 3)
7196                      (match_operand 2 "const_4_to_7_operand" "")
7197                      (match_operand 3 "const_4_to_7_operand" "")
7198                      (match_operand 4 "const_4_to_7_operand" "")
7199                      (match_operand 5 "const_4_to_7_operand" "")
7200                      (const_int 8)
7201                      (const_int 9)
7202                      (const_int 10)
7203                      (const_int 11)
7204                      (match_dup 2)
7205                      (match_dup 3)
7206                      (match_dup 4)
7207                      (match_dup 5)])))]
7208   "TARGET_AVX2"
7209 {
7210   int mask = 0;
7211   mask |= (INTVAL (operands[2]) - 4) << 0;
7212   mask |= (INTVAL (operands[3]) - 4) << 2;
7213   mask |= (INTVAL (operands[4]) - 4) << 4;
7214   mask |= (INTVAL (operands[5]) - 4) << 6;
7215   operands[2] = GEN_INT (mask);
7216
7217   return "vpshufhw\t{%2, %1, %0|%0, %1, %2}";
7218 }
7219   [(set_attr "type" "sselog")
7220    (set_attr "prefix" "vex")
7221    (set_attr "length_immediate" "1")
7222    (set_attr "mode" "OI")])
7223
7224 (define_expand "sse2_pshufhw"
7225   [(match_operand:V8HI 0 "register_operand" "")
7226    (match_operand:V8HI 1 "nonimmediate_operand" "")
7227    (match_operand:SI 2 "const_int_operand" "")]
7228   "TARGET_SSE2"
7229 {
7230   int mask = INTVAL (operands[2]);
7231   emit_insn (gen_sse2_pshufhw_1 (operands[0], operands[1],
7232                                  GEN_INT (((mask >> 0) & 3) + 4),
7233                                  GEN_INT (((mask >> 2) & 3) + 4),
7234                                  GEN_INT (((mask >> 4) & 3) + 4),
7235                                  GEN_INT (((mask >> 6) & 3) + 4)));
7236   DONE;
7237 })
7238
7239 (define_insn "sse2_pshufhw_1"
7240   [(set (match_operand:V8HI 0 "register_operand" "=x")
7241         (vec_select:V8HI
7242           (match_operand:V8HI 1 "nonimmediate_operand" "xm")
7243           (parallel [(const_int 0)
7244                      (const_int 1)
7245                      (const_int 2)
7246                      (const_int 3)
7247                      (match_operand 2 "const_4_to_7_operand" "")
7248                      (match_operand 3 "const_4_to_7_operand" "")
7249                      (match_operand 4 "const_4_to_7_operand" "")
7250                      (match_operand 5 "const_4_to_7_operand" "")])))]
7251   "TARGET_SSE2"
7252 {
7253   int mask = 0;
7254   mask |= (INTVAL (operands[2]) - 4) << 0;
7255   mask |= (INTVAL (operands[3]) - 4) << 2;
7256   mask |= (INTVAL (operands[4]) - 4) << 4;
7257   mask |= (INTVAL (operands[5]) - 4) << 6;
7258   operands[2] = GEN_INT (mask);
7259
7260   return "%vpshufhw\t{%2, %1, %0|%0, %1, %2}";
7261 }
7262   [(set_attr "type" "sselog")
7263    (set_attr "prefix_rep" "1")
7264    (set_attr "prefix_data16" "0")
7265    (set_attr "prefix" "maybe_vex")
7266    (set_attr "length_immediate" "1")
7267    (set_attr "mode" "TI")])
7268
7269 (define_expand "sse2_loadd"
7270   [(set (match_operand:V4SI 0 "register_operand" "")
7271         (vec_merge:V4SI
7272           (vec_duplicate:V4SI
7273             (match_operand:SI 1 "nonimmediate_operand" ""))
7274           (match_dup 2)
7275           (const_int 1)))]
7276   "TARGET_SSE"
7277   "operands[2] = CONST0_RTX (V4SImode);")
7278
7279 (define_insn "sse2_loadld"
7280   [(set (match_operand:V4SI 0 "register_operand"       "=x,Yi,x,x,x")
7281         (vec_merge:V4SI
7282           (vec_duplicate:V4SI
7283             (match_operand:SI 2 "nonimmediate_operand" "m ,r ,m,x,x"))
7284           (match_operand:V4SI 1 "reg_or_0_operand"     "C ,C ,C,0,x")
7285           (const_int 1)))]
7286   "TARGET_SSE"
7287   "@
7288    %vmovd\t{%2, %0|%0, %2}
7289    %vmovd\t{%2, %0|%0, %2}
7290    movss\t{%2, %0|%0, %2}
7291    movss\t{%2, %0|%0, %2}
7292    vmovss\t{%2, %1, %0|%0, %1, %2}"
7293   [(set_attr "isa" "sse2,*,noavx,noavx,avx")
7294    (set_attr "type" "ssemov")
7295    (set_attr "prefix" "maybe_vex,maybe_vex,orig,orig,vex")
7296    (set_attr "mode" "TI,TI,V4SF,SF,SF")])
7297
7298 (define_insn_and_split "sse2_stored"
7299   [(set (match_operand:SI 0 "nonimmediate_operand" "=xm,r")
7300         (vec_select:SI
7301           (match_operand:V4SI 1 "register_operand" "x,Yi")
7302           (parallel [(const_int 0)])))]
7303   "TARGET_SSE"
7304   "#"
7305   "&& reload_completed
7306    && (TARGET_INTER_UNIT_MOVES
7307        || MEM_P (operands [0])
7308        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
7309   [(set (match_dup 0) (match_dup 1))]
7310   "operands[1] = gen_rtx_REG (SImode, REGNO (operands[1]));")
7311
7312 (define_insn_and_split "*vec_ext_v4si_mem"
7313   [(set (match_operand:SI 0 "register_operand" "=r")
7314         (vec_select:SI
7315           (match_operand:V4SI 1 "memory_operand" "o")
7316           (parallel [(match_operand 2 "const_0_to_3_operand" "")])))]
7317   ""
7318   "#"
7319   "reload_completed"
7320   [(const_int 0)]
7321 {
7322   int i = INTVAL (operands[2]);
7323
7324   emit_move_insn (operands[0], adjust_address (operands[1], SImode, i*4));
7325   DONE;
7326 })
7327
7328 (define_expand "sse_storeq"
7329   [(set (match_operand:DI 0 "nonimmediate_operand" "")
7330         (vec_select:DI
7331           (match_operand:V2DI 1 "register_operand" "")
7332           (parallel [(const_int 0)])))]
7333   "TARGET_SSE")
7334
7335 (define_insn "*sse2_storeq_rex64"
7336   [(set (match_operand:DI 0 "nonimmediate_operand" "=xm,*r,r")
7337         (vec_select:DI
7338           (match_operand:V2DI 1 "nonimmediate_operand" "x,Yi,o")
7339           (parallel [(const_int 0)])))]
7340   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7341   "@
7342    #
7343    #
7344    mov{q}\t{%1, %0|%0, %1}"
7345   [(set_attr "type" "*,*,imov")
7346    (set_attr "mode" "*,*,DI")])
7347
7348 (define_insn "*sse2_storeq"
7349   [(set (match_operand:DI 0 "nonimmediate_operand" "=xm")
7350         (vec_select:DI
7351           (match_operand:V2DI 1 "register_operand" "x")
7352           (parallel [(const_int 0)])))]
7353   "TARGET_SSE"
7354   "#")
7355
7356 (define_split
7357   [(set (match_operand:DI 0 "nonimmediate_operand" "")
7358         (vec_select:DI
7359           (match_operand:V2DI 1 "register_operand" "")
7360           (parallel [(const_int 0)])))]
7361   "TARGET_SSE
7362    && reload_completed
7363    && (TARGET_INTER_UNIT_MOVES
7364        || MEM_P (operands [0])
7365        || !GENERAL_REGNO_P (true_regnum (operands [0])))"
7366   [(set (match_dup 0) (match_dup 1))]
7367   "operands[1] = gen_rtx_REG (DImode, REGNO (operands[1]));")
7368
7369 (define_insn "*vec_extractv2di_1_rex64"
7370   [(set (match_operand:DI 0 "nonimmediate_operand"     "=m,x,x,x,r")
7371         (vec_select:DI
7372           (match_operand:V2DI 1 "nonimmediate_operand" " x,0,x,o,o")
7373           (parallel [(const_int 1)])))]
7374   "TARGET_64BIT && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7375   "@
7376    %vmovhps\t{%1, %0|%0, %1}
7377    psrldq\t{$8, %0|%0, 8}
7378    vpsrldq\t{$8, %1, %0|%0, %1, 8}
7379    %vmovq\t{%H1, %0|%0, %H1}
7380    mov{q}\t{%H1, %0|%0, %H1}"
7381   [(set_attr "isa" "*,noavx,avx,*,*")
7382    (set_attr "type" "ssemov,sseishft1,sseishft1,ssemov,imov")
7383    (set_attr "length_immediate" "*,1,1,*,*")
7384    (set_attr "memory" "*,none,none,*,*")
7385    (set_attr "prefix" "maybe_vex,orig,vex,maybe_vex,orig")
7386    (set_attr "mode" "V2SF,TI,TI,TI,DI")])
7387
7388 (define_insn "*vec_extractv2di_1"
7389   [(set (match_operand:DI 0 "nonimmediate_operand"     "=m,x,x,x,x,x")
7390         (vec_select:DI
7391           (match_operand:V2DI 1 "nonimmediate_operand" " x,0,x,o,x,o")
7392           (parallel [(const_int 1)])))]
7393   "!TARGET_64BIT && TARGET_SSE
7394    && !(MEM_P (operands[0]) && MEM_P (operands[1]))"
7395   "@
7396    %vmovhps\t{%1, %0|%0, %1}
7397    psrldq\t{$8, %0|%0, 8}
7398    vpsrldq\t{$8, %1, %0|%0, %1, 8}
7399    %vmovq\t{%H1, %0|%0, %H1}
7400    movhlps\t{%1, %0|%0, %1}
7401    movlps\t{%H1, %0|%0, %H1}"
7402   [(set_attr "isa" "*,sse2_noavx,avx,sse2,noavx,noavx")
7403    (set_attr "type" "ssemov,sseishft1,sseishft1,ssemov,ssemov,ssemov")
7404    (set_attr "length_immediate" "*,1,1,*,*,*")
7405    (set_attr "memory" "*,none,none,*,*,*")
7406    (set_attr "prefix" "maybe_vex,orig,vex,maybe_vex,orig,orig")
7407    (set_attr "mode" "V2SF,TI,TI,TI,V4SF,V2SF")])
7408
7409 (define_insn "*vec_dupv4si_avx"
7410   [(set (match_operand:V4SI 0 "register_operand"     "=x,x")
7411         (vec_duplicate:V4SI
7412           (match_operand:SI 1 "nonimmediate_operand" " x,m")))]
7413   "TARGET_AVX"
7414   "@
7415    vpshufd\t{$0, %1, %0|%0, %1, 0}
7416    vbroadcastss\t{%1, %0|%0, %1}"
7417   [(set_attr "type" "sselog1,ssemov")
7418    (set_attr "length_immediate" "1,0")
7419    (set_attr "prefix_extra" "0,1")
7420    (set_attr "prefix" "vex")
7421    (set_attr "mode" "TI,V4SF")])
7422
7423 (define_insn "*vec_dupv4si"
7424   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
7425         (vec_duplicate:V4SI
7426           (match_operand:SI 1 "register_operand" " x,0")))]
7427   "TARGET_SSE"
7428   "@
7429    pshufd\t{$0, %1, %0|%0, %1, 0}
7430    shufps\t{$0, %0, %0|%0, %0, 0}"
7431   [(set_attr "isa" "sse2,*")
7432    (set_attr "type" "sselog1")
7433    (set_attr "length_immediate" "1")
7434    (set_attr "mode" "TI,V4SF")])
7435
7436 (define_insn "*vec_dupv2di_sse3"
7437   [(set (match_operand:V2DI 0 "register_operand"     "=x,x,x")
7438         (vec_duplicate:V2DI
7439           (match_operand:DI 1 "nonimmediate_operand" " 0,x,m")))]
7440   "TARGET_SSE3"
7441   "@
7442    punpcklqdq\t%0, %0
7443    vpunpcklqdq\t{%d1, %0|%0, %d1}
7444    %vmovddup\t{%1, %0|%0, %1}"
7445   [(set_attr "isa" "noavx,avx,*")
7446    (set_attr "type" "sselog1")
7447    (set_attr "prefix" "orig,vex,maybe_vex")
7448    (set_attr "mode" "TI,TI,DF")])
7449
7450 (define_insn "*vec_dupv2di"
7451   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
7452         (vec_duplicate:V2DI
7453           (match_operand:DI 1 "register_operand" " 0,0")))]
7454   "TARGET_SSE"
7455   "@
7456    punpcklqdq\t%0, %0
7457    movlhps\t%0, %0"
7458   [(set_attr "isa" "sse2,*")
7459    (set_attr "type" "sselog1,ssemov")
7460    (set_attr "mode" "TI,V4SF")])
7461
7462 (define_insn "*vec_concatv2si_sse4_1"
7463   [(set (match_operand:V2SI 0 "register_operand"     "=x, x,x,x, x, *y,*y")
7464         (vec_concat:V2SI
7465           (match_operand:SI 1 "nonimmediate_operand" " 0, x,0,x,rm,  0,rm")
7466           (match_operand:SI 2 "vector_move_operand"  "rm,rm,x,x, C,*ym, C")))]
7467   "TARGET_SSE4_1"
7468   "@
7469    pinsrd\t{$1, %2, %0|%0, %2, 1}
7470    vpinsrd\t{$1, %2, %1, %0|%0, %1, %2, 1}
7471    punpckldq\t{%2, %0|%0, %2}
7472    vpunpckldq\t{%2, %1, %0|%0, %1, %2}
7473    %vmovd\t{%1, %0|%0, %1}
7474    punpckldq\t{%2, %0|%0, %2}
7475    movd\t{%1, %0|%0, %1}"
7476   [(set_attr "isa" "noavx,avx,noavx,avx,*,*,*")
7477    (set_attr "type" "sselog,sselog,sselog,sselog,ssemov,mmxcvt,mmxmov")
7478    (set_attr "prefix_extra" "1,1,*,*,*,*,*")
7479    (set_attr "length_immediate" "1,1,*,*,*,*,*")
7480    (set_attr "prefix" "orig,vex,orig,vex,maybe_vex,orig,orig")
7481    (set_attr "mode" "TI,TI,TI,TI,TI,DI,DI")])
7482
7483 ;; ??? In theory we can match memory for the MMX alternative, but allowing
7484 ;; nonimmediate_operand for operand 2 and *not* allowing memory for the SSE
7485 ;; alternatives pretty much forces the MMX alternative to be chosen.
7486 (define_insn "*vec_concatv2si_sse2"
7487   [(set (match_operand:V2SI 0 "register_operand"     "=x,x ,*y,*y")
7488         (vec_concat:V2SI
7489           (match_operand:SI 1 "nonimmediate_operand" " 0,rm, 0,rm")
7490           (match_operand:SI 2 "reg_or_0_operand"     " x,C ,*y, C")))]
7491   "TARGET_SSE2"
7492   "@
7493    punpckldq\t{%2, %0|%0, %2}
7494    movd\t{%1, %0|%0, %1}
7495    punpckldq\t{%2, %0|%0, %2}
7496    movd\t{%1, %0|%0, %1}"
7497   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
7498    (set_attr "mode" "TI,TI,DI,DI")])
7499
7500 (define_insn "*vec_concatv2si_sse"
7501   [(set (match_operand:V2SI 0 "register_operand"     "=x,x,*y,*y")
7502         (vec_concat:V2SI
7503           (match_operand:SI 1 "nonimmediate_operand" " 0,m, 0,*rm")
7504           (match_operand:SI 2 "reg_or_0_operand"     " x,C,*y,C")))]
7505   "TARGET_SSE"
7506   "@
7507    unpcklps\t{%2, %0|%0, %2}
7508    movss\t{%1, %0|%0, %1}
7509    punpckldq\t{%2, %0|%0, %2}
7510    movd\t{%1, %0|%0, %1}"
7511   [(set_attr "type" "sselog,ssemov,mmxcvt,mmxmov")
7512    (set_attr "mode" "V4SF,V4SF,DI,DI")])
7513
7514 (define_insn "*vec_concatv4si"
7515   [(set (match_operand:V4SI 0 "register_operand"       "=x,x,x,x,x")
7516         (vec_concat:V4SI
7517           (match_operand:V2SI 1 "register_operand"     " 0,x,0,0,x")
7518           (match_operand:V2SI 2 "nonimmediate_operand" " x,x,x,m,m")))]
7519   "TARGET_SSE"
7520   "@
7521    punpcklqdq\t{%2, %0|%0, %2}
7522    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7523    movlhps\t{%2, %0|%0, %2}
7524    movhps\t{%2, %0|%0, %2}
7525    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7526   [(set_attr "isa" "sse2_noavx,avx,noavx,noavx,avx")
7527    (set_attr "type" "sselog,sselog,ssemov,ssemov,ssemov")
7528    (set_attr "prefix" "orig,vex,orig,orig,vex")
7529    (set_attr "mode" "TI,TI,V4SF,V2SF,V2SF")])
7530
7531 ;; movd instead of movq is required to handle broken assemblers.
7532 (define_insn "*vec_concatv2di_rex64"
7533   [(set (match_operand:V2DI 0 "register_operand"
7534           "=x,x ,x ,Yi,!x,x,x,x,x")
7535         (vec_concat:V2DI
7536           (match_operand:DI 1 "nonimmediate_operand"
7537           " 0,x ,xm,r ,*y,0,x,0,x")
7538           (match_operand:DI 2 "vector_move_operand"
7539           "rm,rm,C ,C ,C ,x,x,m,m")))]
7540   "TARGET_64BIT"
7541   "@
7542    pinsrq\t{$1, %2, %0|%0, %2, 1}
7543    vpinsrq\t{$1, %2, %1, %0|%0, %1, %2, 1}
7544    %vmovq\t{%1, %0|%0, %1}
7545    %vmovd\t{%1, %0|%0, %1}
7546    movq2dq\t{%1, %0|%0, %1}
7547    punpcklqdq\t{%2, %0|%0, %2}
7548    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7549    movhps\t{%2, %0|%0, %2}
7550    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7551   [(set_attr "isa" "sse4_noavx,avx,*,*,*,noavx,avx,noavx,avx")
7552    (set (attr "type")
7553      (if_then_else
7554        (eq_attr "alternative" "0,1,5,6")
7555        (const_string "sselog")
7556        (const_string "ssemov")))
7557    (set (attr "prefix_rex")
7558      (if_then_else
7559        (and (eq_attr "alternative" "0,3")
7560             (not (match_test "TARGET_AVX")))
7561        (const_string "1")
7562        (const_string "*")))
7563    (set_attr "prefix_extra" "1,1,*,*,*,*,*,*,*")
7564    (set_attr "length_immediate" "1,1,*,*,*,*,*,*,*")
7565    (set_attr "prefix" "orig,vex,maybe_vex,maybe_vex,orig,orig,vex,orig,vex")
7566    (set_attr "mode" "TI,TI,TI,TI,TI,TI,TI,V2SF,V2SF")])
7567
7568 (define_insn "vec_concatv2di"
7569   [(set (match_operand:V2DI 0 "register_operand"     "=x,?x,x,x,x,x,x")
7570         (vec_concat:V2DI
7571           (match_operand:DI 1 "nonimmediate_operand" "xm,*y,0,x,0,0,x")
7572           (match_operand:DI 2 "vector_move_operand"  " C, C,x,x,x,m,m")))]
7573   "!TARGET_64BIT && TARGET_SSE"
7574   "@
7575    %vmovq\t{%1, %0|%0, %1}
7576    movq2dq\t{%1, %0|%0, %1}
7577    punpcklqdq\t{%2, %0|%0, %2}
7578    vpunpcklqdq\t{%2, %1, %0|%0, %1, %2}
7579    movlhps\t{%2, %0|%0, %2}
7580    movhps\t{%2, %0|%0, %2}
7581    vmovhps\t{%2, %1, %0|%0, %1, %2}"
7582   [(set_attr "isa" "sse2,sse2,sse2_noavx,avx,noavx,noavx,avx")
7583    (set_attr "type" "ssemov,ssemov,sselog,sselog,ssemov,ssemov,ssemov")
7584    (set_attr "prefix" "maybe_vex,orig,orig,vex,orig,orig,vex")
7585    (set_attr "mode" "TI,TI,TI,TI,V4SF,V2SF,V2SF")])
7586
7587 (define_expand "vec_unpacks_lo_<mode>"
7588   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7589    (match_operand:VI124_128 1 "register_operand" "")]
7590   "TARGET_SSE2"
7591   "ix86_expand_sse_unpack (operands, false, false); DONE;")
7592
7593 (define_expand "vec_unpacks_hi_<mode>"
7594   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7595    (match_operand:VI124_128 1 "register_operand" "")]
7596   "TARGET_SSE2"
7597   "ix86_expand_sse_unpack (operands, false, true); DONE;")
7598
7599 (define_expand "vec_unpacku_lo_<mode>"
7600   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7601    (match_operand:VI124_128 1 "register_operand" "")]
7602   "TARGET_SSE2"
7603   "ix86_expand_sse_unpack (operands, true, false); DONE;")
7604
7605 (define_expand "vec_unpacku_hi_<mode>"
7606   [(match_operand:<sseunpackmode> 0 "register_operand" "")
7607    (match_operand:VI124_128 1 "register_operand" "")]
7608   "TARGET_SSE2"
7609   "ix86_expand_sse_unpack (operands, true, true); DONE;")
7610
7611 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7612 ;;
7613 ;; Miscellaneous
7614 ;;
7615 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7616
7617 (define_expand "avx2_uavgv32qi3"
7618   [(set (match_operand:V32QI 0 "register_operand" "")
7619         (truncate:V32QI
7620           (lshiftrt:V32HI
7621             (plus:V32HI
7622               (plus:V32HI
7623                 (zero_extend:V32HI
7624                   (match_operand:V32QI 1 "nonimmediate_operand" ""))
7625                 (zero_extend:V32HI
7626                   (match_operand:V32QI 2 "nonimmediate_operand" "")))
7627               (const_vector:V32QI [(const_int 1) (const_int 1)
7628                                    (const_int 1) (const_int 1)
7629                                    (const_int 1) (const_int 1)
7630                                    (const_int 1) (const_int 1)
7631                                    (const_int 1) (const_int 1)
7632                                    (const_int 1) (const_int 1)
7633                                    (const_int 1) (const_int 1)
7634                                    (const_int 1) (const_int 1)
7635                                    (const_int 1) (const_int 1)
7636                                    (const_int 1) (const_int 1)
7637                                    (const_int 1) (const_int 1)
7638                                    (const_int 1) (const_int 1)
7639                                    (const_int 1) (const_int 1)
7640                                    (const_int 1) (const_int 1)
7641                                    (const_int 1) (const_int 1)
7642                                    (const_int 1) (const_int 1)]))
7643             (const_int 1))))]
7644   "TARGET_AVX2"
7645   "ix86_fixup_binary_operands_no_copy (PLUS, V32QImode, operands);")
7646
7647 (define_expand "sse2_uavgv16qi3"
7648   [(set (match_operand:V16QI 0 "register_operand" "")
7649         (truncate:V16QI
7650           (lshiftrt:V16HI
7651             (plus:V16HI
7652               (plus:V16HI
7653                 (zero_extend:V16HI
7654                   (match_operand:V16QI 1 "nonimmediate_operand" ""))
7655                 (zero_extend:V16HI
7656                   (match_operand:V16QI 2 "nonimmediate_operand" "")))
7657               (const_vector:V16QI [(const_int 1) (const_int 1)
7658                                    (const_int 1) (const_int 1)
7659                                    (const_int 1) (const_int 1)
7660                                    (const_int 1) (const_int 1)
7661                                    (const_int 1) (const_int 1)
7662                                    (const_int 1) (const_int 1)
7663                                    (const_int 1) (const_int 1)
7664                                    (const_int 1) (const_int 1)]))
7665             (const_int 1))))]
7666   "TARGET_SSE2"
7667   "ix86_fixup_binary_operands_no_copy (PLUS, V16QImode, operands);")
7668
7669 (define_insn "*avx2_uavgv32qi3"
7670   [(set (match_operand:V32QI 0 "register_operand" "=x")
7671         (truncate:V32QI
7672           (lshiftrt:V32HI
7673             (plus:V32HI
7674               (plus:V32HI
7675                 (zero_extend:V32HI
7676                   (match_operand:V32QI 1 "nonimmediate_operand" "%x"))
7677                 (zero_extend:V32HI
7678                   (match_operand:V32QI 2 "nonimmediate_operand" "xm")))
7679               (const_vector:V32QI [(const_int 1) (const_int 1)
7680                                    (const_int 1) (const_int 1)
7681                                    (const_int 1) (const_int 1)
7682                                    (const_int 1) (const_int 1)
7683                                    (const_int 1) (const_int 1)
7684                                    (const_int 1) (const_int 1)
7685                                    (const_int 1) (const_int 1)
7686                                    (const_int 1) (const_int 1)
7687                                    (const_int 1) (const_int 1)
7688                                    (const_int 1) (const_int 1)
7689                                    (const_int 1) (const_int 1)
7690                                    (const_int 1) (const_int 1)
7691                                    (const_int 1) (const_int 1)
7692                                    (const_int 1) (const_int 1)
7693                                    (const_int 1) (const_int 1)
7694                                    (const_int 1) (const_int 1)]))
7695             (const_int 1))))]
7696   "TARGET_AVX2 && ix86_binary_operator_ok (PLUS, V32QImode, operands)"
7697   "vpavgb\t{%2, %1, %0|%0, %1, %2}"
7698   [(set_attr "type" "sseiadd")
7699    (set_attr "prefix" "vex")
7700    (set_attr "mode" "OI")])
7701
7702 (define_insn "*sse2_uavgv16qi3"
7703   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
7704         (truncate:V16QI
7705           (lshiftrt:V16HI
7706             (plus:V16HI
7707               (plus:V16HI
7708                 (zero_extend:V16HI
7709                   (match_operand:V16QI 1 "nonimmediate_operand" "%0,x"))
7710                 (zero_extend:V16HI
7711                   (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")))
7712               (const_vector:V16QI [(const_int 1) (const_int 1)
7713                                    (const_int 1) (const_int 1)
7714                                    (const_int 1) (const_int 1)
7715                                    (const_int 1) (const_int 1)
7716                                    (const_int 1) (const_int 1)
7717                                    (const_int 1) (const_int 1)
7718                                    (const_int 1) (const_int 1)
7719                                    (const_int 1) (const_int 1)]))
7720             (const_int 1))))]
7721   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V16QImode, operands)"
7722   "@
7723    pavgb\t{%2, %0|%0, %2}
7724    vpavgb\t{%2, %1, %0|%0, %1, %2}"
7725   [(set_attr "isa" "noavx,avx")
7726    (set_attr "type" "sseiadd")
7727    (set_attr "prefix_data16" "1,*")
7728    (set_attr "prefix" "orig,vex")
7729    (set_attr "mode" "TI")])
7730
7731 (define_expand "avx2_uavgv16hi3"
7732   [(set (match_operand:V16HI 0 "register_operand" "")
7733         (truncate:V16HI
7734           (lshiftrt:V16SI
7735             (plus:V16SI
7736               (plus:V16SI
7737                 (zero_extend:V16SI
7738                   (match_operand:V16HI 1 "nonimmediate_operand" ""))
7739                 (zero_extend:V16SI
7740                   (match_operand:V16HI 2 "nonimmediate_operand" "")))
7741               (const_vector:V16HI [(const_int 1) (const_int 1)
7742                                    (const_int 1) (const_int 1)
7743                                    (const_int 1) (const_int 1)
7744                                    (const_int 1) (const_int 1)
7745                                    (const_int 1) (const_int 1)
7746                                    (const_int 1) (const_int 1)
7747                                    (const_int 1) (const_int 1)
7748                                    (const_int 1) (const_int 1)]))
7749             (const_int 1))))]
7750   "TARGET_AVX2"
7751   "ix86_fixup_binary_operands_no_copy (PLUS, V16HImode, operands);")
7752
7753 (define_expand "sse2_uavgv8hi3"
7754   [(set (match_operand:V8HI 0 "register_operand" "")
7755         (truncate:V8HI
7756           (lshiftrt:V8SI
7757             (plus:V8SI
7758               (plus:V8SI
7759                 (zero_extend:V8SI
7760                   (match_operand:V8HI 1 "nonimmediate_operand" ""))
7761                 (zero_extend:V8SI
7762                   (match_operand:V8HI 2 "nonimmediate_operand" "")))
7763               (const_vector:V8HI [(const_int 1) (const_int 1)
7764                                   (const_int 1) (const_int 1)
7765                                   (const_int 1) (const_int 1)
7766                                   (const_int 1) (const_int 1)]))
7767             (const_int 1))))]
7768   "TARGET_SSE2"
7769   "ix86_fixup_binary_operands_no_copy (PLUS, V8HImode, operands);")
7770
7771 (define_insn "*avx2_uavgv16hi3"
7772   [(set (match_operand:V16HI 0 "register_operand" "=x")
7773         (truncate:V16HI
7774           (lshiftrt:V16SI
7775             (plus:V16SI
7776               (plus:V16SI
7777                 (zero_extend:V16SI
7778                   (match_operand:V16HI 1 "nonimmediate_operand" "%x"))
7779                 (zero_extend:V16SI
7780                   (match_operand:V16HI 2 "nonimmediate_operand" "xm")))
7781               (const_vector:V16HI [(const_int 1) (const_int 1)
7782                                    (const_int 1) (const_int 1)
7783                                    (const_int 1) (const_int 1)
7784                                    (const_int 1) (const_int 1)
7785                                    (const_int 1) (const_int 1)
7786                                    (const_int 1) (const_int 1)
7787                                    (const_int 1) (const_int 1)
7788                                    (const_int 1) (const_int 1)]))
7789             (const_int 1))))]
7790   "TARGET_AVX2 && ix86_binary_operator_ok (PLUS, V16HImode, operands)"
7791   "vpavgw\t{%2, %1, %0|%0, %1, %2}"
7792   [(set_attr "type" "sseiadd")
7793    (set_attr "prefix" "vex")
7794    (set_attr "mode" "OI")])
7795
7796 (define_insn "*sse2_uavgv8hi3"
7797   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
7798         (truncate:V8HI
7799           (lshiftrt:V8SI
7800             (plus:V8SI
7801               (plus:V8SI
7802                 (zero_extend:V8SI
7803                   (match_operand:V8HI 1 "nonimmediate_operand" "%0,x"))
7804                 (zero_extend:V8SI
7805                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))
7806               (const_vector:V8HI [(const_int 1) (const_int 1)
7807                                   (const_int 1) (const_int 1)
7808                                   (const_int 1) (const_int 1)
7809                                   (const_int 1) (const_int 1)]))
7810             (const_int 1))))]
7811   "TARGET_SSE2 && ix86_binary_operator_ok (PLUS, V8HImode, operands)"
7812   "@
7813    pavgw\t{%2, %0|%0, %2}
7814    vpavgw\t{%2, %1, %0|%0, %1, %2}"
7815   [(set_attr "isa" "noavx,avx")
7816    (set_attr "type" "sseiadd")
7817    (set_attr "prefix_data16" "1,*")
7818    (set_attr "prefix" "orig,vex")
7819    (set_attr "mode" "TI")])
7820
7821 ;; The correct representation for this is absolutely enormous, and
7822 ;; surely not generally useful.
7823 (define_insn "<sse2_avx2>_psadbw"
7824   [(set (match_operand:VI8_AVX2 0 "register_operand" "=x,x")
7825         (unspec:VI8_AVX2 [(match_operand:<ssebytemode> 1 "register_operand" "0,x")
7826                           (match_operand:<ssebytemode> 2 "nonimmediate_operand" "xm,xm")]
7827                           UNSPEC_PSADBW))]
7828   "TARGET_SSE2"
7829   "@
7830    psadbw\t{%2, %0|%0, %2}
7831    vpsadbw\t{%2, %1, %0|%0, %1, %2}"
7832   [(set_attr "isa" "noavx,avx")
7833    (set_attr "type" "sseiadd")
7834    (set_attr "atom_unit" "simul")
7835    (set_attr "prefix_data16" "1,*")
7836    (set_attr "prefix" "orig,vex")
7837    (set_attr "mode" "<sseinsnmode>")])
7838
7839 (define_insn "<sse>_movmsk<ssemodesuffix><avxsizesuffix>"
7840   [(set (match_operand:SI 0 "register_operand" "=r")
7841         (unspec:SI
7842           [(match_operand:VF 1 "register_operand" "x")]
7843           UNSPEC_MOVMSK))]
7844   "TARGET_SSE"
7845   "%vmovmsk<ssemodesuffix>\t{%1, %0|%0, %1}"
7846   [(set_attr "type" "ssemov")
7847    (set_attr "prefix" "maybe_vex")
7848    (set_attr "mode" "<MODE>")])
7849
7850 (define_insn "avx2_pmovmskb"
7851   [(set (match_operand:SI 0 "register_operand" "=r")
7852         (unspec:SI [(match_operand:V32QI 1 "register_operand" "x")]
7853                    UNSPEC_MOVMSK))]
7854   "TARGET_AVX2"
7855   "vpmovmskb\t{%1, %0|%0, %1}"
7856   [(set_attr "type" "ssemov")
7857    (set_attr "prefix" "vex")
7858    (set_attr "mode" "DI")])
7859
7860 (define_insn "sse2_pmovmskb"
7861   [(set (match_operand:SI 0 "register_operand" "=r")
7862         (unspec:SI [(match_operand:V16QI 1 "register_operand" "x")]
7863                    UNSPEC_MOVMSK))]
7864   "TARGET_SSE2"
7865   "%vpmovmskb\t{%1, %0|%0, %1}"
7866   [(set_attr "type" "ssemov")
7867    (set_attr "prefix_data16" "1")
7868    (set_attr "prefix" "maybe_vex")
7869    (set_attr "mode" "SI")])
7870
7871 (define_expand "sse2_maskmovdqu"
7872   [(set (match_operand:V16QI 0 "memory_operand" "")
7873         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "")
7874                        (match_operand:V16QI 2 "register_operand" "")
7875                        (match_dup 0)]
7876                       UNSPEC_MASKMOV))]
7877   "TARGET_SSE2")
7878
7879 (define_insn "*sse2_maskmovdqu"
7880   [(set (mem:V16QI (match_operand:P 0 "register_operand" "D"))
7881         (unspec:V16QI [(match_operand:V16QI 1 "register_operand" "x")
7882                        (match_operand:V16QI 2 "register_operand" "x")
7883                        (mem:V16QI (match_dup 0))]
7884                       UNSPEC_MASKMOV))]
7885   "TARGET_SSE2"
7886   "%vmaskmovdqu\t{%2, %1|%1, %2}"
7887   [(set_attr "type" "ssemov")
7888    (set_attr "prefix_data16" "1")
7889    ;; The implicit %rdi operand confuses default length_vex computation.
7890    (set (attr "length_vex")
7891      (symbol_ref ("3 + REX_SSE_REGNO_P (REGNO (operands[2]))")))
7892    (set_attr "prefix" "maybe_vex")
7893    (set_attr "mode" "TI")])
7894
7895 (define_insn "sse_ldmxcsr"
7896   [(unspec_volatile [(match_operand:SI 0 "memory_operand" "m")]
7897                     UNSPECV_LDMXCSR)]
7898   "TARGET_SSE"
7899   "%vldmxcsr\t%0"
7900   [(set_attr "type" "sse")
7901    (set_attr "atom_sse_attr" "mxcsr")
7902    (set_attr "prefix" "maybe_vex")
7903    (set_attr "memory" "load")])
7904
7905 (define_insn "sse_stmxcsr"
7906   [(set (match_operand:SI 0 "memory_operand" "=m")
7907         (unspec_volatile:SI [(const_int 0)] UNSPECV_STMXCSR))]
7908   "TARGET_SSE"
7909   "%vstmxcsr\t%0"
7910   [(set_attr "type" "sse")
7911    (set_attr "atom_sse_attr" "mxcsr")
7912    (set_attr "prefix" "maybe_vex")
7913    (set_attr "memory" "store")])
7914
7915 (define_expand "sse_sfence"
7916   [(set (match_dup 0)
7917         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
7918   "TARGET_SSE || TARGET_3DNOW_A"
7919 {
7920   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
7921   MEM_VOLATILE_P (operands[0]) = 1;
7922 })
7923
7924 (define_insn "*sse_sfence"
7925   [(set (match_operand:BLK 0 "" "")
7926         (unspec:BLK [(match_dup 0)] UNSPEC_SFENCE))]
7927   "TARGET_SSE || TARGET_3DNOW_A"
7928   "sfence"
7929   [(set_attr "type" "sse")
7930    (set_attr "length_address" "0")
7931    (set_attr "atom_sse_attr" "fence")
7932    (set_attr "memory" "unknown")])
7933
7934 (define_insn "sse2_clflush"
7935   [(unspec_volatile [(match_operand 0 "address_operand" "p")]
7936                     UNSPECV_CLFLUSH)]
7937   "TARGET_SSE2"
7938   "clflush\t%a0"
7939   [(set_attr "type" "sse")
7940    (set_attr "atom_sse_attr" "fence")
7941    (set_attr "memory" "unknown")])
7942
7943 (define_expand "sse2_mfence"
7944   [(set (match_dup 0)
7945         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
7946   "TARGET_SSE2"
7947 {
7948   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
7949   MEM_VOLATILE_P (operands[0]) = 1;
7950 })
7951
7952 (define_insn "*sse2_mfence"
7953   [(set (match_operand:BLK 0 "" "")
7954         (unspec:BLK [(match_dup 0)] UNSPEC_MFENCE))]
7955   "TARGET_64BIT || TARGET_SSE2"
7956   "mfence"
7957   [(set_attr "type" "sse")
7958    (set_attr "length_address" "0")
7959    (set_attr "atom_sse_attr" "fence")
7960    (set_attr "memory" "unknown")])
7961
7962 (define_expand "sse2_lfence"
7963   [(set (match_dup 0)
7964         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
7965   "TARGET_SSE2"
7966 {
7967   operands[0] = gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode));
7968   MEM_VOLATILE_P (operands[0]) = 1;
7969 })
7970
7971 (define_insn "*sse2_lfence"
7972   [(set (match_operand:BLK 0 "" "")
7973         (unspec:BLK [(match_dup 0)] UNSPEC_LFENCE))]
7974   "TARGET_SSE2"
7975   "lfence"
7976   [(set_attr "type" "sse")
7977    (set_attr "length_address" "0")
7978    (set_attr "atom_sse_attr" "lfence")
7979    (set_attr "memory" "unknown")])
7980
7981 (define_insn "sse3_mwait"
7982   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
7983                      (match_operand:SI 1 "register_operand" "c")]
7984                     UNSPECV_MWAIT)]
7985   "TARGET_SSE3"
7986 ;; 64bit version is "mwait %rax,%rcx". But only lower 32bits are used.
7987 ;; Since 32bit register operands are implicitly zero extended to 64bit,
7988 ;; we only need to set up 32bit registers.
7989   "mwait"
7990   [(set_attr "length" "3")])
7991
7992 (define_insn "sse3_monitor"
7993   [(unspec_volatile [(match_operand:SI 0 "register_operand" "a")
7994                      (match_operand:SI 1 "register_operand" "c")
7995                      (match_operand:SI 2 "register_operand" "d")]
7996                     UNSPECV_MONITOR)]
7997   "TARGET_SSE3 && !TARGET_64BIT"
7998   "monitor\t%0, %1, %2"
7999   [(set_attr "length" "3")])
8000
8001 (define_insn "sse3_monitor64"
8002   [(unspec_volatile [(match_operand:DI 0 "register_operand" "a")
8003                      (match_operand:SI 1 "register_operand" "c")
8004                      (match_operand:SI 2 "register_operand" "d")]
8005                     UNSPECV_MONITOR)]
8006   "TARGET_SSE3 && TARGET_64BIT"
8007 ;; 64bit version is "monitor %rax,%rcx,%rdx". But only lower 32bits in
8008 ;; RCX and RDX are used.  Since 32bit register operands are implicitly
8009 ;; zero extended to 64bit, we only need to set up 32bit registers.
8010   "monitor"
8011   [(set_attr "length" "3")])
8012
8013 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8014 ;;
8015 ;; SSSE3 instructions
8016 ;;
8017 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8018
8019 (define_insn "avx2_phaddwv16hi3"
8020   [(set (match_operand:V16HI 0 "register_operand" "=x")
8021         (vec_concat:V16HI
8022           (vec_concat:V8HI
8023             (vec_concat:V4HI
8024               (vec_concat:V2HI
8025                 (plus:HI
8026                   (vec_select:HI
8027                     (match_operand:V16HI 1 "register_operand" "x")
8028                     (parallel [(const_int 0)]))
8029                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8030                 (plus:HI
8031                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8032                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8033               (vec_concat:V2HI
8034                 (plus:HI
8035                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8036                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8037                 (plus:HI
8038                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8039                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8040             (vec_concat:V4HI
8041               (vec_concat:V2HI
8042                 (plus:HI
8043                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8044                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8045                 (plus:HI
8046                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8047                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8048               (vec_concat:V2HI
8049                 (plus:HI
8050                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8051                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8052                 (plus:HI
8053                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8054                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8055           (vec_concat:V8HI
8056             (vec_concat:V4HI
8057               (vec_concat:V2HI
8058                 (plus:HI
8059                   (vec_select:HI
8060                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8061                     (parallel [(const_int 0)]))
8062                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8063                 (plus:HI
8064                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8065                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8066               (vec_concat:V2HI
8067                 (plus:HI
8068                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8069                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8070                 (plus:HI
8071                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8072                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8073             (vec_concat:V4HI
8074               (vec_concat:V2HI
8075                 (plus:HI
8076                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8077                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8078                 (plus:HI
8079                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8080                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8081               (vec_concat:V2HI
8082                 (plus:HI
8083                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8084                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8085                 (plus:HI
8086                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8087                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8088   "TARGET_AVX2"
8089   "vphaddw\t{%2, %1, %0|%0, %1, %2}"
8090   [(set_attr "type" "sseiadd")
8091    (set_attr "prefix_extra" "1")
8092    (set_attr "prefix" "vex")
8093    (set_attr "mode" "OI")])
8094
8095 (define_insn "ssse3_phaddwv8hi3"
8096   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8097         (vec_concat:V8HI
8098           (vec_concat:V4HI
8099             (vec_concat:V2HI
8100               (plus:HI
8101                 (vec_select:HI
8102                   (match_operand:V8HI 1 "register_operand" "0,x")
8103                   (parallel [(const_int 0)]))
8104                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8105               (plus:HI
8106                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8107                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8108             (vec_concat:V2HI
8109               (plus:HI
8110                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8111                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8112               (plus:HI
8113                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8114                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8115           (vec_concat:V4HI
8116             (vec_concat:V2HI
8117               (plus:HI
8118                 (vec_select:HI
8119                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8120                   (parallel [(const_int 0)]))
8121                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8122               (plus:HI
8123                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8124                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8125             (vec_concat:V2HI
8126               (plus:HI
8127                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8128                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8129               (plus:HI
8130                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8131                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8132   "TARGET_SSSE3"
8133   "@
8134    phaddw\t{%2, %0|%0, %2}
8135    vphaddw\t{%2, %1, %0|%0, %1, %2}"
8136   [(set_attr "isa" "noavx,avx")
8137    (set_attr "type" "sseiadd")
8138    (set_attr "atom_unit" "complex")
8139    (set_attr "prefix_data16" "1,*")
8140    (set_attr "prefix_extra" "1")
8141    (set_attr "prefix" "orig,vex")
8142    (set_attr "mode" "TI")])
8143
8144 (define_insn "ssse3_phaddwv4hi3"
8145   [(set (match_operand:V4HI 0 "register_operand" "=y")
8146         (vec_concat:V4HI
8147           (vec_concat:V2HI
8148             (plus:HI
8149               (vec_select:HI
8150                 (match_operand:V4HI 1 "register_operand" "0")
8151                 (parallel [(const_int 0)]))
8152               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8153             (plus:HI
8154               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8155               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8156           (vec_concat:V2HI
8157             (plus:HI
8158               (vec_select:HI
8159                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8160                 (parallel [(const_int 0)]))
8161               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8162             (plus:HI
8163               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8164               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8165   "TARGET_SSSE3"
8166   "phaddw\t{%2, %0|%0, %2}"
8167   [(set_attr "type" "sseiadd")
8168    (set_attr "atom_unit" "complex")
8169    (set_attr "prefix_extra" "1")
8170    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8171    (set_attr "mode" "DI")])
8172
8173 (define_insn "avx2_phadddv8si3"
8174   [(set (match_operand:V8SI 0 "register_operand" "=x")
8175         (vec_concat:V8SI
8176           (vec_concat:V4SI
8177             (vec_concat:V2SI
8178               (plus:SI
8179                 (vec_select:SI
8180                   (match_operand:V8SI 1 "register_operand" "x")
8181                   (parallel [(const_int 0)]))
8182                 (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8183               (plus:SI
8184                 (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8185                 (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8186             (vec_concat:V2SI
8187               (plus:SI
8188                 (vec_select:SI (match_dup 1) (parallel [(const_int 4)]))
8189                 (vec_select:SI (match_dup 1) (parallel [(const_int 5)])))
8190               (plus:SI
8191                 (vec_select:SI (match_dup 1) (parallel [(const_int 6)]))
8192                 (vec_select:SI (match_dup 1) (parallel [(const_int 7)])))))
8193           (vec_concat:V4SI
8194             (vec_concat:V2SI
8195               (plus:SI
8196                 (vec_select:SI
8197                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
8198                   (parallel [(const_int 0)]))
8199                 (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8200               (plus:SI
8201                 (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8202                 (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))
8203             (vec_concat:V2SI
8204               (plus:SI
8205                 (vec_select:SI (match_dup 2) (parallel [(const_int 4)]))
8206                 (vec_select:SI (match_dup 2) (parallel [(const_int 5)])))
8207               (plus:SI
8208                 (vec_select:SI (match_dup 2) (parallel [(const_int 6)]))
8209                 (vec_select:SI (match_dup 2) (parallel [(const_int 7)])))))))]
8210   "TARGET_AVX2"
8211   "vphaddd\t{%2, %1, %0|%0, %1, %2}"
8212   [(set_attr "type" "sseiadd")
8213    (set_attr "prefix_extra" "1")
8214    (set_attr "prefix" "vex")
8215    (set_attr "mode" "OI")])
8216
8217 (define_insn "ssse3_phadddv4si3"
8218   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
8219         (vec_concat:V4SI
8220           (vec_concat:V2SI
8221             (plus:SI
8222               (vec_select:SI
8223                 (match_operand:V4SI 1 "register_operand" "0,x")
8224                 (parallel [(const_int 0)]))
8225               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8226             (plus:SI
8227               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8228               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8229           (vec_concat:V2SI
8230             (plus:SI
8231               (vec_select:SI
8232                 (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
8233                 (parallel [(const_int 0)]))
8234               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8235             (plus:SI
8236               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8237               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
8238   "TARGET_SSSE3"
8239   "@
8240    phaddd\t{%2, %0|%0, %2}
8241    vphaddd\t{%2, %1, %0|%0, %1, %2}"
8242   [(set_attr "isa" "noavx,avx")
8243    (set_attr "type" "sseiadd")
8244    (set_attr "atom_unit" "complex")
8245    (set_attr "prefix_data16" "1,*")
8246    (set_attr "prefix_extra" "1")
8247    (set_attr "prefix" "orig,vex")
8248    (set_attr "mode" "TI")])
8249
8250 (define_insn "ssse3_phadddv2si3"
8251   [(set (match_operand:V2SI 0 "register_operand" "=y")
8252         (vec_concat:V2SI
8253           (plus:SI
8254             (vec_select:SI
8255               (match_operand:V2SI 1 "register_operand" "0")
8256               (parallel [(const_int 0)]))
8257             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8258           (plus:SI
8259             (vec_select:SI
8260               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
8261               (parallel [(const_int 0)]))
8262             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
8263   "TARGET_SSSE3"
8264   "phaddd\t{%2, %0|%0, %2}"
8265   [(set_attr "type" "sseiadd")
8266    (set_attr "atom_unit" "complex")
8267    (set_attr "prefix_extra" "1")
8268    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8269    (set_attr "mode" "DI")])
8270
8271 (define_insn "avx2_phaddswv16hi3"
8272   [(set (match_operand:V16HI 0 "register_operand" "=x")
8273         (vec_concat:V16HI
8274           (vec_concat:V8HI
8275             (vec_concat:V4HI
8276               (vec_concat:V2HI
8277                 (ss_plus:HI
8278                   (vec_select:HI
8279                     (match_operand:V16HI 1 "register_operand" "x")
8280                     (parallel [(const_int 0)]))
8281                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8282                 (ss_plus:HI
8283                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8284                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8285               (vec_concat:V2HI
8286                 (ss_plus:HI
8287                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8288                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8289                 (ss_plus:HI
8290                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8291                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8292             (vec_concat:V4HI
8293               (vec_concat:V2HI
8294                 (ss_plus:HI
8295                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8296                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8297                 (ss_plus:HI
8298                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8299                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8300               (vec_concat:V2HI
8301                 (ss_plus:HI
8302                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8303                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8304                 (ss_plus:HI
8305                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8306                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8307           (vec_concat:V8HI
8308             (vec_concat:V4HI
8309               (vec_concat:V2HI
8310                 (ss_plus:HI
8311                   (vec_select:HI
8312                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8313                     (parallel [(const_int 0)]))
8314                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8315                 (ss_plus:HI
8316                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8317                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8318               (vec_concat:V2HI
8319                 (ss_plus:HI
8320                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8321                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8322                 (ss_plus:HI
8323                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8324                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8325             (vec_concat:V4HI
8326               (vec_concat:V2HI
8327                 (ss_plus:HI
8328                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8329                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8330                 (ss_plus:HI
8331                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8332                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8333               (vec_concat:V2HI
8334                 (ss_plus:HI
8335                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8336                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8337                 (ss_plus:HI
8338                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8339                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8340   "TARGET_AVX2"
8341   "vphaddsw\t{%2, %1, %0|%0, %1, %2}"
8342   [(set_attr "type" "sseiadd")
8343    (set_attr "prefix_extra" "1")
8344    (set_attr "prefix" "vex")
8345    (set_attr "mode" "OI")])
8346
8347 (define_insn "ssse3_phaddswv8hi3"
8348   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8349         (vec_concat:V8HI
8350           (vec_concat:V4HI
8351             (vec_concat:V2HI
8352               (ss_plus:HI
8353                 (vec_select:HI
8354                   (match_operand:V8HI 1 "register_operand" "0,x")
8355                   (parallel [(const_int 0)]))
8356                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8357               (ss_plus:HI
8358                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8359                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8360             (vec_concat:V2HI
8361               (ss_plus:HI
8362                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8363                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8364               (ss_plus:HI
8365                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8366                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8367           (vec_concat:V4HI
8368             (vec_concat:V2HI
8369               (ss_plus:HI
8370                 (vec_select:HI
8371                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8372                   (parallel [(const_int 0)]))
8373                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8374               (ss_plus:HI
8375                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8376                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8377             (vec_concat:V2HI
8378               (ss_plus:HI
8379                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8380                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8381               (ss_plus:HI
8382                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8383                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8384   "TARGET_SSSE3"
8385   "@
8386    phaddsw\t{%2, %0|%0, %2}
8387    vphaddsw\t{%2, %1, %0|%0, %1, %2}"
8388   [(set_attr "isa" "noavx,avx")
8389    (set_attr "type" "sseiadd")
8390    (set_attr "atom_unit" "complex")
8391    (set_attr "prefix_data16" "1,*")
8392    (set_attr "prefix_extra" "1")
8393    (set_attr "prefix" "orig,vex")
8394    (set_attr "mode" "TI")])
8395
8396 (define_insn "ssse3_phaddswv4hi3"
8397   [(set (match_operand:V4HI 0 "register_operand" "=y")
8398         (vec_concat:V4HI
8399           (vec_concat:V2HI
8400             (ss_plus:HI
8401               (vec_select:HI
8402                 (match_operand:V4HI 1 "register_operand" "0")
8403                 (parallel [(const_int 0)]))
8404               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8405             (ss_plus:HI
8406               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8407               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8408           (vec_concat:V2HI
8409             (ss_plus:HI
8410               (vec_select:HI
8411                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8412                 (parallel [(const_int 0)]))
8413               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8414             (ss_plus:HI
8415               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8416               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8417   "TARGET_SSSE3"
8418   "phaddsw\t{%2, %0|%0, %2}"
8419   [(set_attr "type" "sseiadd")
8420    (set_attr "atom_unit" "complex")
8421    (set_attr "prefix_extra" "1")
8422    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8423    (set_attr "mode" "DI")])
8424
8425 (define_insn "avx2_phsubwv16hi3"
8426   [(set (match_operand:V16HI 0 "register_operand" "=x")
8427         (vec_concat:V16HI
8428           (vec_concat:V8HI
8429             (vec_concat:V4HI
8430               (vec_concat:V2HI
8431                 (minus:HI
8432                   (vec_select:HI
8433                     (match_operand:V16HI 1 "register_operand" "x")
8434                     (parallel [(const_int 0)]))
8435                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8436                 (minus:HI
8437                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8438                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8439               (vec_concat:V2HI
8440                 (minus:HI
8441                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8442                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8443                 (minus:HI
8444                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8445                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8446             (vec_concat:V4HI
8447               (vec_concat:V2HI
8448                 (minus:HI
8449                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8450                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8451                 (minus:HI
8452                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8453                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8454               (vec_concat:V2HI
8455                 (minus:HI
8456                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8457                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8458                 (minus:HI
8459                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8460                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8461           (vec_concat:V8HI
8462             (vec_concat:V4HI
8463               (vec_concat:V2HI
8464                 (minus:HI
8465                   (vec_select:HI
8466                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8467                     (parallel [(const_int 0)]))
8468                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8469                 (minus:HI
8470                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8471                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8472               (vec_concat:V2HI
8473                 (minus:HI
8474                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8475                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8476                 (minus:HI
8477                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8478                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8479             (vec_concat:V4HI
8480               (vec_concat:V2HI
8481                 (minus:HI
8482                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8483                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8484                 (minus:HI
8485                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8486                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8487               (vec_concat:V2HI
8488                 (minus:HI
8489                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8490                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8491                 (minus:HI
8492                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8493                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8494   "TARGET_AVX2"
8495   "vphsubw\t{%2, %1, %0|%0, %1, %2}"
8496   [(set_attr "type" "sseiadd")
8497    (set_attr "prefix_extra" "1")
8498    (set_attr "prefix" "vex")
8499    (set_attr "mode" "OI")])
8500
8501 (define_insn "ssse3_phsubwv8hi3"
8502   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8503         (vec_concat:V8HI
8504           (vec_concat:V4HI
8505             (vec_concat:V2HI
8506               (minus:HI
8507                 (vec_select:HI
8508                   (match_operand:V8HI 1 "register_operand" "0,x")
8509                   (parallel [(const_int 0)]))
8510                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8511               (minus:HI
8512                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8513                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8514             (vec_concat:V2HI
8515               (minus:HI
8516                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8517                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8518               (minus:HI
8519                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8520                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8521           (vec_concat:V4HI
8522             (vec_concat:V2HI
8523               (minus:HI
8524                 (vec_select:HI
8525                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8526                   (parallel [(const_int 0)]))
8527                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8528               (minus:HI
8529                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8530                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8531             (vec_concat:V2HI
8532               (minus:HI
8533                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8534                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8535               (minus:HI
8536                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8537                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8538   "TARGET_SSSE3"
8539   "@
8540    phsubw\t{%2, %0|%0, %2}
8541    vphsubw\t{%2, %1, %0|%0, %1, %2}"
8542   [(set_attr "isa" "noavx,avx")
8543    (set_attr "type" "sseiadd")
8544    (set_attr "atom_unit" "complex")
8545    (set_attr "prefix_data16" "1,*")
8546    (set_attr "prefix_extra" "1")
8547    (set_attr "prefix" "orig,vex")
8548    (set_attr "mode" "TI")])
8549
8550 (define_insn "ssse3_phsubwv4hi3"
8551   [(set (match_operand:V4HI 0 "register_operand" "=y")
8552         (vec_concat:V4HI
8553           (vec_concat:V2HI
8554             (minus:HI
8555               (vec_select:HI
8556                 (match_operand:V4HI 1 "register_operand" "0")
8557                 (parallel [(const_int 0)]))
8558               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8559             (minus:HI
8560               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8561               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8562           (vec_concat:V2HI
8563             (minus:HI
8564               (vec_select:HI
8565                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8566                 (parallel [(const_int 0)]))
8567               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8568             (minus:HI
8569               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8570               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8571   "TARGET_SSSE3"
8572   "phsubw\t{%2, %0|%0, %2}"
8573   [(set_attr "type" "sseiadd")
8574    (set_attr "atom_unit" "complex")
8575    (set_attr "prefix_extra" "1")
8576    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8577    (set_attr "mode" "DI")])
8578
8579 (define_insn "avx2_phsubdv8si3"
8580   [(set (match_operand:V8SI 0 "register_operand" "=x")
8581         (vec_concat:V8SI
8582           (vec_concat:V4SI
8583             (vec_concat:V2SI
8584               (minus:SI
8585                 (vec_select:SI
8586                   (match_operand:V8SI 1 "register_operand" "x")
8587                   (parallel [(const_int 0)]))
8588                 (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8589               (minus:SI
8590                 (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8591                 (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8592             (vec_concat:V2SI
8593               (minus:SI
8594                 (vec_select:SI (match_dup 1) (parallel [(const_int 4)]))
8595                 (vec_select:SI (match_dup 1) (parallel [(const_int 5)])))
8596               (minus:SI
8597                 (vec_select:SI (match_dup 1) (parallel [(const_int 6)]))
8598                 (vec_select:SI (match_dup 1) (parallel [(const_int 7)])))))
8599           (vec_concat:V4SI
8600             (vec_concat:V2SI
8601               (minus:SI
8602                 (vec_select:SI
8603                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
8604                   (parallel [(const_int 0)]))
8605                 (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8606               (minus:SI
8607                 (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8608                 (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))
8609             (vec_concat:V2SI
8610               (minus:SI
8611                 (vec_select:SI (match_dup 2) (parallel [(const_int 4)]))
8612                 (vec_select:SI (match_dup 2) (parallel [(const_int 5)])))
8613               (minus:SI
8614                 (vec_select:SI (match_dup 2) (parallel [(const_int 6)]))
8615                 (vec_select:SI (match_dup 2) (parallel [(const_int 7)])))))))]
8616   "TARGET_AVX2"
8617   "vphsubd\t{%2, %1, %0|%0, %1, %2}"
8618   [(set_attr "type" "sseiadd")
8619    (set_attr "prefix_extra" "1")
8620    (set_attr "prefix" "vex")
8621    (set_attr "mode" "OI")])
8622
8623 (define_insn "ssse3_phsubdv4si3"
8624   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
8625         (vec_concat:V4SI
8626           (vec_concat:V2SI
8627             (minus:SI
8628               (vec_select:SI
8629                 (match_operand:V4SI 1 "register_operand" "0,x")
8630                 (parallel [(const_int 0)]))
8631               (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8632             (minus:SI
8633               (vec_select:SI (match_dup 1) (parallel [(const_int 2)]))
8634               (vec_select:SI (match_dup 1) (parallel [(const_int 3)]))))
8635           (vec_concat:V2SI
8636             (minus:SI
8637               (vec_select:SI
8638                 (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm")
8639                 (parallel [(const_int 0)]))
8640               (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))
8641             (minus:SI
8642               (vec_select:SI (match_dup 2) (parallel [(const_int 2)]))
8643               (vec_select:SI (match_dup 2) (parallel [(const_int 3)]))))))]
8644   "TARGET_SSSE3"
8645   "@
8646    phsubd\t{%2, %0|%0, %2}
8647    vphsubd\t{%2, %1, %0|%0, %1, %2}"
8648
8649   [(set_attr "isa" "noavx,avx")
8650    (set_attr "type" "sseiadd")
8651    (set_attr "atom_unit" "complex")
8652    (set_attr "prefix_data16" "1,*")
8653    (set_attr "prefix_extra" "1")
8654    (set_attr "prefix" "orig,vex")
8655    (set_attr "mode" "TI")])
8656
8657 (define_insn "ssse3_phsubdv2si3"
8658   [(set (match_operand:V2SI 0 "register_operand" "=y")
8659         (vec_concat:V2SI
8660           (minus:SI
8661             (vec_select:SI
8662               (match_operand:V2SI 1 "register_operand" "0")
8663               (parallel [(const_int 0)]))
8664             (vec_select:SI (match_dup 1) (parallel [(const_int 1)])))
8665           (minus:SI
8666             (vec_select:SI
8667               (match_operand:V2SI 2 "nonimmediate_operand" "ym")
8668               (parallel [(const_int 0)]))
8669             (vec_select:SI (match_dup 2) (parallel [(const_int 1)])))))]
8670   "TARGET_SSSE3"
8671   "phsubd\t{%2, %0|%0, %2}"
8672   [(set_attr "type" "sseiadd")
8673    (set_attr "atom_unit" "complex")
8674    (set_attr "prefix_extra" "1")
8675    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8676    (set_attr "mode" "DI")])
8677
8678 (define_insn "avx2_phsubswv16hi3"
8679   [(set (match_operand:V16HI 0 "register_operand" "=x")
8680         (vec_concat:V16HI
8681           (vec_concat:V8HI
8682             (vec_concat:V4HI
8683               (vec_concat:V2HI
8684                 (ss_minus:HI
8685                   (vec_select:HI
8686                     (match_operand:V16HI 1 "register_operand" "x")
8687                     (parallel [(const_int 0)]))
8688                   (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8689                 (ss_minus:HI
8690                   (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8691                   (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8692               (vec_concat:V2HI
8693                 (ss_minus:HI
8694                   (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8695                   (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8696                 (ss_minus:HI
8697                   (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8698                   (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8699             (vec_concat:V4HI
8700               (vec_concat:V2HI
8701                 (ss_minus:HI
8702                   (vec_select:HI (match_dup 1) (parallel [(const_int 8)]))
8703                   (vec_select:HI (match_dup 1) (parallel [(const_int 9)])))
8704                 (ss_minus:HI
8705                   (vec_select:HI (match_dup 1) (parallel [(const_int 10)]))
8706                   (vec_select:HI (match_dup 1) (parallel [(const_int 11)]))))
8707               (vec_concat:V2HI
8708                 (ss_minus:HI
8709                   (vec_select:HI (match_dup 1) (parallel [(const_int 12)]))
8710                   (vec_select:HI (match_dup 1) (parallel [(const_int 13)])))
8711                 (ss_minus:HI
8712                   (vec_select:HI (match_dup 1) (parallel [(const_int 14)]))
8713                   (vec_select:HI (match_dup 1) (parallel [(const_int 15)]))))))
8714           (vec_concat:V8HI
8715             (vec_concat:V4HI
8716               (vec_concat:V2HI
8717                 (ss_minus:HI
8718                   (vec_select:HI
8719                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")
8720                     (parallel [(const_int 0)]))
8721                   (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8722                 (ss_minus:HI
8723                   (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8724                   (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8725               (vec_concat:V2HI
8726                 (ss_minus:HI
8727                   (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8728                   (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8729                 (ss_minus:HI
8730                   (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8731                   (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))
8732             (vec_concat:V4HI
8733               (vec_concat:V2HI
8734                 (ss_minus:HI
8735                   (vec_select:HI (match_dup 2) (parallel [(const_int 8)]))
8736                   (vec_select:HI (match_dup 2) (parallel [(const_int 9)])))
8737                 (ss_minus:HI
8738                   (vec_select:HI (match_dup 2) (parallel [(const_int 10)]))
8739                   (vec_select:HI (match_dup 2) (parallel [(const_int 11)]))))
8740               (vec_concat:V2HI
8741                 (ss_minus:HI
8742                   (vec_select:HI (match_dup 2) (parallel [(const_int 12)]))
8743                   (vec_select:HI (match_dup 2) (parallel [(const_int 13)])))
8744                 (ss_minus:HI
8745                   (vec_select:HI (match_dup 2) (parallel [(const_int 14)]))
8746                   (vec_select:HI (match_dup 2) (parallel [(const_int 15)]))))))))]
8747   "TARGET_AVX2"
8748   "vphsubsw\t{%2, %1, %0|%0, %1, %2}"
8749   [(set_attr "type" "sseiadd")
8750    (set_attr "prefix_extra" "1")
8751    (set_attr "prefix" "vex")
8752    (set_attr "mode" "OI")])
8753
8754 (define_insn "ssse3_phsubswv8hi3"
8755   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8756         (vec_concat:V8HI
8757           (vec_concat:V4HI
8758             (vec_concat:V2HI
8759               (ss_minus:HI
8760                 (vec_select:HI
8761                   (match_operand:V8HI 1 "register_operand" "0,x")
8762                   (parallel [(const_int 0)]))
8763                 (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8764               (ss_minus:HI
8765                 (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8766                 (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8767             (vec_concat:V2HI
8768               (ss_minus:HI
8769                 (vec_select:HI (match_dup 1) (parallel [(const_int 4)]))
8770                 (vec_select:HI (match_dup 1) (parallel [(const_int 5)])))
8771               (ss_minus:HI
8772                 (vec_select:HI (match_dup 1) (parallel [(const_int 6)]))
8773                 (vec_select:HI (match_dup 1) (parallel [(const_int 7)])))))
8774           (vec_concat:V4HI
8775             (vec_concat:V2HI
8776               (ss_minus:HI
8777                 (vec_select:HI
8778                   (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")
8779                   (parallel [(const_int 0)]))
8780                 (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8781               (ss_minus:HI
8782                 (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8783                 (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))
8784             (vec_concat:V2HI
8785               (ss_minus:HI
8786                 (vec_select:HI (match_dup 2) (parallel [(const_int 4)]))
8787                 (vec_select:HI (match_dup 2) (parallel [(const_int 5)])))
8788               (ss_minus:HI
8789                 (vec_select:HI (match_dup 2) (parallel [(const_int 6)]))
8790                 (vec_select:HI (match_dup 2) (parallel [(const_int 7)])))))))]
8791   "TARGET_SSSE3"
8792   "@
8793    phsubsw\t{%2, %0|%0, %2}
8794    vphsubsw\t{%2, %1, %0|%0, %1, %2}"
8795   [(set_attr "isa" "noavx,avx")
8796    (set_attr "type" "sseiadd")
8797    (set_attr "atom_unit" "complex")
8798    (set_attr "prefix_data16" "1,*")
8799    (set_attr "prefix_extra" "1")
8800    (set_attr "prefix" "orig,vex")
8801    (set_attr "mode" "TI")])
8802
8803 (define_insn "ssse3_phsubswv4hi3"
8804   [(set (match_operand:V4HI 0 "register_operand" "=y")
8805         (vec_concat:V4HI
8806           (vec_concat:V2HI
8807             (ss_minus:HI
8808               (vec_select:HI
8809                 (match_operand:V4HI 1 "register_operand" "0")
8810                 (parallel [(const_int 0)]))
8811               (vec_select:HI (match_dup 1) (parallel [(const_int 1)])))
8812             (ss_minus:HI
8813               (vec_select:HI (match_dup 1) (parallel [(const_int 2)]))
8814               (vec_select:HI (match_dup 1) (parallel [(const_int 3)]))))
8815           (vec_concat:V2HI
8816             (ss_minus:HI
8817               (vec_select:HI
8818                 (match_operand:V4HI 2 "nonimmediate_operand" "ym")
8819                 (parallel [(const_int 0)]))
8820               (vec_select:HI (match_dup 2) (parallel [(const_int 1)])))
8821             (ss_minus:HI
8822               (vec_select:HI (match_dup 2) (parallel [(const_int 2)]))
8823               (vec_select:HI (match_dup 2) (parallel [(const_int 3)]))))))]
8824   "TARGET_SSSE3"
8825   "phsubsw\t{%2, %0|%0, %2}"
8826   [(set_attr "type" "sseiadd")
8827    (set_attr "atom_unit" "complex")
8828    (set_attr "prefix_extra" "1")
8829    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
8830    (set_attr "mode" "DI")])
8831
8832 (define_insn "avx2_pmaddubsw256"
8833   [(set (match_operand:V16HI 0 "register_operand" "=x")
8834         (ss_plus:V16HI
8835           (mult:V16HI
8836             (zero_extend:V16HI
8837               (vec_select:V16QI
8838                 (match_operand:V32QI 1 "register_operand" "x")
8839                 (parallel [(const_int 0)
8840                            (const_int 2)
8841                            (const_int 4)
8842                            (const_int 6)
8843                            (const_int 8)
8844                            (const_int 10)
8845                            (const_int 12)
8846                            (const_int 14)
8847                            (const_int 16)
8848                            (const_int 18)
8849                            (const_int 20)
8850                            (const_int 22)
8851                            (const_int 24)
8852                            (const_int 26)
8853                            (const_int 28)
8854                            (const_int 30)])))
8855             (sign_extend:V16HI
8856               (vec_select:V16QI
8857                 (match_operand:V32QI 2 "nonimmediate_operand" "xm")
8858                 (parallel [(const_int 0)
8859                            (const_int 2)
8860                            (const_int 4)
8861                            (const_int 6)
8862                            (const_int 8)
8863                            (const_int 10)
8864                            (const_int 12)
8865                            (const_int 14)
8866                            (const_int 16)
8867                            (const_int 18)
8868                            (const_int 20)
8869                            (const_int 22)
8870                            (const_int 24)
8871                            (const_int 26)
8872                            (const_int 28)
8873                            (const_int 30)]))))
8874           (mult:V16HI
8875             (zero_extend:V16HI
8876               (vec_select:V16QI (match_dup 1)
8877                 (parallel [(const_int 1)
8878                            (const_int 3)
8879                            (const_int 5)
8880                            (const_int 7)
8881                            (const_int 9)
8882                            (const_int 11)
8883                            (const_int 13)
8884                            (const_int 15)
8885                            (const_int 17)
8886                            (const_int 19)
8887                            (const_int 21)
8888                            (const_int 23)
8889                            (const_int 25)
8890                            (const_int 27)
8891                            (const_int 29)
8892                            (const_int 31)])))
8893             (sign_extend:V16HI
8894               (vec_select:V16QI (match_dup 2)
8895                 (parallel [(const_int 1)
8896                            (const_int 3)
8897                            (const_int 5)
8898                            (const_int 7)
8899                            (const_int 9)
8900                            (const_int 11)
8901                            (const_int 13)
8902                            (const_int 15)
8903                            (const_int 17)
8904                            (const_int 19)
8905                            (const_int 21)
8906                            (const_int 23)
8907                            (const_int 25)
8908                            (const_int 27)
8909                            (const_int 29)
8910                            (const_int 31)]))))))]
8911   "TARGET_AVX2"
8912   "vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
8913   [(set_attr "type" "sseiadd")
8914    (set_attr "prefix_extra" "1")
8915    (set_attr "prefix" "vex")
8916    (set_attr "mode" "OI")])
8917
8918 (define_insn "ssse3_pmaddubsw128"
8919   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
8920         (ss_plus:V8HI
8921           (mult:V8HI
8922             (zero_extend:V8HI
8923               (vec_select:V8QI
8924                 (match_operand:V16QI 1 "register_operand" "0,x")
8925                 (parallel [(const_int 0)
8926                            (const_int 2)
8927                            (const_int 4)
8928                            (const_int 6)
8929                            (const_int 8)
8930                            (const_int 10)
8931                            (const_int 12)
8932                            (const_int 14)])))
8933             (sign_extend:V8HI
8934               (vec_select:V8QI
8935                 (match_operand:V16QI 2 "nonimmediate_operand" "xm,xm")
8936                 (parallel [(const_int 0)
8937                            (const_int 2)
8938                            (const_int 4)
8939                            (const_int 6)
8940                            (const_int 8)
8941                            (const_int 10)
8942                            (const_int 12)
8943                            (const_int 14)]))))
8944           (mult:V8HI
8945             (zero_extend:V8HI
8946               (vec_select:V8QI (match_dup 1)
8947                 (parallel [(const_int 1)
8948                            (const_int 3)
8949                            (const_int 5)
8950                            (const_int 7)
8951                            (const_int 9)
8952                            (const_int 11)
8953                            (const_int 13)
8954                            (const_int 15)])))
8955             (sign_extend:V8HI
8956               (vec_select:V8QI (match_dup 2)
8957                 (parallel [(const_int 1)
8958                            (const_int 3)
8959                            (const_int 5)
8960                            (const_int 7)
8961                            (const_int 9)
8962                            (const_int 11)
8963                            (const_int 13)
8964                            (const_int 15)]))))))]
8965   "TARGET_SSSE3"
8966   "@
8967    pmaddubsw\t{%2, %0|%0, %2}
8968    vpmaddubsw\t{%2, %1, %0|%0, %1, %2}"
8969   [(set_attr "isa" "noavx,avx")
8970    (set_attr "type" "sseiadd")
8971    (set_attr "atom_unit" "simul")
8972    (set_attr "prefix_data16" "1,*")
8973    (set_attr "prefix_extra" "1")
8974    (set_attr "prefix" "orig,vex")
8975    (set_attr "mode" "TI")])
8976
8977 (define_insn "ssse3_pmaddubsw"
8978   [(set (match_operand:V4HI 0 "register_operand" "=y")
8979         (ss_plus:V4HI
8980           (mult:V4HI
8981             (zero_extend:V4HI
8982               (vec_select:V4QI
8983                 (match_operand:V8QI 1 "register_operand" "0")
8984                 (parallel [(const_int 0)
8985                            (const_int 2)
8986                            (const_int 4)
8987                            (const_int 6)])))
8988             (sign_extend:V4HI
8989               (vec_select:V4QI
8990                 (match_operand:V8QI 2 "nonimmediate_operand" "ym")
8991                 (parallel [(const_int 0)
8992                            (const_int 2)
8993                            (const_int 4)
8994                            (const_int 6)]))))
8995           (mult:V4HI
8996             (zero_extend:V4HI
8997               (vec_select:V4QI (match_dup 1)
8998                 (parallel [(const_int 1)
8999                            (const_int 3)
9000                            (const_int 5)
9001                            (const_int 7)])))
9002             (sign_extend:V4HI
9003               (vec_select:V4QI (match_dup 2)
9004                 (parallel [(const_int 1)
9005                            (const_int 3)
9006                            (const_int 5)
9007                            (const_int 7)]))))))]
9008   "TARGET_SSSE3"
9009   "pmaddubsw\t{%2, %0|%0, %2}"
9010   [(set_attr "type" "sseiadd")
9011    (set_attr "atom_unit" "simul")
9012    (set_attr "prefix_extra" "1")
9013    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9014    (set_attr "mode" "DI")])
9015
9016 (define_expand "avx2_umulhrswv16hi3"
9017   [(set (match_operand:V16HI 0 "register_operand" "")
9018         (truncate:V16HI
9019           (lshiftrt:V16SI
9020             (plus:V16SI
9021               (lshiftrt:V16SI
9022                 (mult:V16SI
9023                   (sign_extend:V16SI
9024                     (match_operand:V16HI 1 "nonimmediate_operand" ""))
9025                   (sign_extend:V16SI
9026                     (match_operand:V16HI 2 "nonimmediate_operand" "")))
9027                 (const_int 14))
9028               (const_vector:V16HI [(const_int 1) (const_int 1)
9029                                    (const_int 1) (const_int 1)
9030                                    (const_int 1) (const_int 1)
9031                                    (const_int 1) (const_int 1)
9032                                    (const_int 1) (const_int 1)
9033                                    (const_int 1) (const_int 1)
9034                                    (const_int 1) (const_int 1)
9035                                    (const_int 1) (const_int 1)]))
9036             (const_int 1))))]
9037   "TARGET_AVX2"
9038   "ix86_fixup_binary_operands_no_copy (MULT, V16HImode, operands);")
9039
9040 (define_insn "*avx2_umulhrswv16hi3"
9041   [(set (match_operand:V16HI 0 "register_operand" "=x")
9042         (truncate:V16HI
9043           (lshiftrt:V16SI
9044             (plus:V16SI
9045               (lshiftrt:V16SI
9046                 (mult:V16SI
9047                   (sign_extend:V16SI
9048                     (match_operand:V16HI 1 "nonimmediate_operand" "%x"))
9049                   (sign_extend:V16SI
9050                     (match_operand:V16HI 2 "nonimmediate_operand" "xm")))
9051                 (const_int 14))
9052               (const_vector:V16HI [(const_int 1) (const_int 1)
9053                                    (const_int 1) (const_int 1)
9054                                    (const_int 1) (const_int 1)
9055                                    (const_int 1) (const_int 1)
9056                                    (const_int 1) (const_int 1)
9057                                    (const_int 1) (const_int 1)
9058                                    (const_int 1) (const_int 1)
9059                                    (const_int 1) (const_int 1)]))
9060             (const_int 1))))]
9061   "TARGET_AVX2 && ix86_binary_operator_ok (MULT, V16HImode, operands)"
9062   "vpmulhrsw\t{%2, %1, %0|%0, %1, %2}"
9063   [(set_attr "type" "sseimul")
9064    (set_attr "prefix_extra" "1")
9065    (set_attr "prefix" "vex")
9066    (set_attr "mode" "OI")])
9067
9068 (define_expand "ssse3_pmulhrswv8hi3"
9069   [(set (match_operand:V8HI 0 "register_operand" "")
9070         (truncate:V8HI
9071           (lshiftrt:V8SI
9072             (plus:V8SI
9073               (lshiftrt:V8SI
9074                 (mult:V8SI
9075                   (sign_extend:V8SI
9076                     (match_operand:V8HI 1 "nonimmediate_operand" ""))
9077                   (sign_extend:V8SI
9078                     (match_operand:V8HI 2 "nonimmediate_operand" "")))
9079                 (const_int 14))
9080               (const_vector:V8HI [(const_int 1) (const_int 1)
9081                                   (const_int 1) (const_int 1)
9082                                   (const_int 1) (const_int 1)
9083                                   (const_int 1) (const_int 1)]))
9084             (const_int 1))))]
9085   "TARGET_SSSE3"
9086   "ix86_fixup_binary_operands_no_copy (MULT, V8HImode, operands);")
9087
9088 (define_insn "*ssse3_pmulhrswv8hi3"
9089   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9090         (truncate:V8HI
9091           (lshiftrt:V8SI
9092             (plus:V8SI
9093               (lshiftrt:V8SI
9094                 (mult:V8SI
9095                   (sign_extend:V8SI
9096                     (match_operand:V8HI 1 "nonimmediate_operand" "%0,x"))
9097                   (sign_extend:V8SI
9098                     (match_operand:V8HI 2 "nonimmediate_operand" "xm,xm")))
9099                 (const_int 14))
9100               (const_vector:V8HI [(const_int 1) (const_int 1)
9101                                   (const_int 1) (const_int 1)
9102                                   (const_int 1) (const_int 1)
9103                                   (const_int 1) (const_int 1)]))
9104             (const_int 1))))]
9105   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V8HImode, operands)"
9106   "@
9107    pmulhrsw\t{%2, %0|%0, %2}
9108    vpmulhrsw\t{%2, %1, %0|%0, %1, %2}"
9109   [(set_attr "isa" "noavx,avx")
9110    (set_attr "type" "sseimul")
9111    (set_attr "prefix_data16" "1,*")
9112    (set_attr "prefix_extra" "1")
9113    (set_attr "prefix" "orig,vex")
9114    (set_attr "mode" "TI")])
9115
9116 (define_expand "ssse3_pmulhrswv4hi3"
9117   [(set (match_operand:V4HI 0 "register_operand" "")
9118         (truncate:V4HI
9119           (lshiftrt:V4SI
9120             (plus:V4SI
9121               (lshiftrt:V4SI
9122                 (mult:V4SI
9123                   (sign_extend:V4SI
9124                     (match_operand:V4HI 1 "nonimmediate_operand" ""))
9125                   (sign_extend:V4SI
9126                     (match_operand:V4HI 2 "nonimmediate_operand" "")))
9127                 (const_int 14))
9128               (const_vector:V4HI [(const_int 1) (const_int 1)
9129                                   (const_int 1) (const_int 1)]))
9130             (const_int 1))))]
9131   "TARGET_SSSE3"
9132   "ix86_fixup_binary_operands_no_copy (MULT, V4HImode, operands);")
9133
9134 (define_insn "*ssse3_pmulhrswv4hi3"
9135   [(set (match_operand:V4HI 0 "register_operand" "=y")
9136         (truncate:V4HI
9137           (lshiftrt:V4SI
9138             (plus:V4SI
9139               (lshiftrt:V4SI
9140                 (mult:V4SI
9141                   (sign_extend:V4SI
9142                     (match_operand:V4HI 1 "nonimmediate_operand" "%0"))
9143                   (sign_extend:V4SI
9144                     (match_operand:V4HI 2 "nonimmediate_operand" "ym")))
9145                 (const_int 14))
9146               (const_vector:V4HI [(const_int 1) (const_int 1)
9147                                   (const_int 1) (const_int 1)]))
9148             (const_int 1))))]
9149   "TARGET_SSSE3 && ix86_binary_operator_ok (MULT, V4HImode, operands)"
9150   "pmulhrsw\t{%2, %0|%0, %2}"
9151   [(set_attr "type" "sseimul")
9152    (set_attr "prefix_extra" "1")
9153    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9154    (set_attr "mode" "DI")])
9155
9156 (define_insn "<ssse3_avx2>_pshufb<mode>3"
9157   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
9158         (unspec:VI1_AVX2 [(match_operand:VI1_AVX2 1 "register_operand" "0,x")
9159                           (match_operand:VI1_AVX2 2 "nonimmediate_operand" "xm,xm")]
9160                          UNSPEC_PSHUFB))]
9161   "TARGET_SSSE3"
9162   "@
9163    pshufb\t{%2, %0|%0, %2}
9164    vpshufb\t{%2, %1, %0|%0, %1, %2}"
9165   [(set_attr "isa" "noavx,avx")
9166    (set_attr "type" "sselog1")
9167    (set_attr "prefix_data16" "1,*")
9168    (set_attr "prefix_extra" "1")
9169    (set_attr "prefix" "orig,vex")
9170    (set_attr "mode" "<sseinsnmode>")])
9171
9172 (define_insn "ssse3_pshufbv8qi3"
9173   [(set (match_operand:V8QI 0 "register_operand" "=y")
9174         (unspec:V8QI [(match_operand:V8QI 1 "register_operand" "0")
9175                       (match_operand:V8QI 2 "nonimmediate_operand" "ym")]
9176                      UNSPEC_PSHUFB))]
9177   "TARGET_SSSE3"
9178   "pshufb\t{%2, %0|%0, %2}";
9179   [(set_attr "type" "sselog1")
9180    (set_attr "prefix_extra" "1")
9181    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9182    (set_attr "mode" "DI")])
9183
9184 (define_insn "<ssse3_avx2>_psign<mode>3"
9185   [(set (match_operand:VI124_AVX2 0 "register_operand" "=x,x")
9186         (unspec:VI124_AVX2
9187           [(match_operand:VI124_AVX2 1 "register_operand" "0,x")
9188            (match_operand:VI124_AVX2 2 "nonimmediate_operand" "xm,xm")]
9189           UNSPEC_PSIGN))]
9190   "TARGET_SSSE3"
9191   "@
9192    psign<ssemodesuffix>\t{%2, %0|%0, %2}
9193    vpsign<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
9194   [(set_attr "isa" "noavx,avx")
9195    (set_attr "type" "sselog1")
9196    (set_attr "prefix_data16" "1,*")
9197    (set_attr "prefix_extra" "1")
9198    (set_attr "prefix" "orig,vex")
9199    (set_attr "mode" "<sseinsnmode>")])
9200
9201 (define_insn "ssse3_psign<mode>3"
9202   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
9203         (unspec:MMXMODEI
9204           [(match_operand:MMXMODEI 1 "register_operand" "0")
9205            (match_operand:MMXMODEI 2 "nonimmediate_operand" "ym")]
9206           UNSPEC_PSIGN))]
9207   "TARGET_SSSE3"
9208   "psign<mmxvecsize>\t{%2, %0|%0, %2}";
9209   [(set_attr "type" "sselog1")
9210    (set_attr "prefix_extra" "1")
9211    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9212    (set_attr "mode" "DI")])
9213
9214 (define_insn "<ssse3_avx2>_palignr<mode>"
9215   [(set (match_operand:SSESCALARMODE 0 "register_operand" "=x,x")
9216         (unspec:SSESCALARMODE [(match_operand:SSESCALARMODE 1 "register_operand" "0,x")
9217                                (match_operand:SSESCALARMODE 2 "nonimmediate_operand" "xm,xm")
9218                                (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n,n")]
9219                               UNSPEC_PALIGNR))]
9220   "TARGET_SSSE3"
9221 {
9222   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
9223
9224   switch (which_alternative)
9225     {
9226     case 0:
9227       return "palignr\t{%3, %2, %0|%0, %2, %3}";
9228     case 1:
9229       return "vpalignr\t{%3, %2, %1, %0|%0, %1, %2, %3}";
9230     default:
9231       gcc_unreachable ();
9232     }
9233 }
9234   [(set_attr "isa" "noavx,avx")
9235    (set_attr "type" "sseishft")
9236    (set_attr "atom_unit" "sishuf")
9237    (set_attr "prefix_data16" "1,*")
9238    (set_attr "prefix_extra" "1")
9239    (set_attr "length_immediate" "1")
9240    (set_attr "prefix" "orig,vex")
9241    (set_attr "mode" "<sseinsnmode>")])
9242
9243 (define_insn "ssse3_palignrdi"
9244   [(set (match_operand:DI 0 "register_operand" "=y")
9245         (unspec:DI [(match_operand:DI 1 "register_operand" "0")
9246                     (match_operand:DI 2 "nonimmediate_operand" "ym")
9247                     (match_operand:SI 3 "const_0_to_255_mul_8_operand" "n")]
9248                    UNSPEC_PALIGNR))]
9249   "TARGET_SSSE3"
9250 {
9251   operands[3] = GEN_INT (INTVAL (operands[3]) / 8);
9252   return "palignr\t{%3, %2, %0|%0, %2, %3}";
9253 }
9254   [(set_attr "type" "sseishft")
9255    (set_attr "atom_unit" "sishuf")
9256    (set_attr "prefix_extra" "1")
9257    (set_attr "length_immediate" "1")
9258    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9259    (set_attr "mode" "DI")])
9260
9261 (define_insn "abs<mode>2"
9262   [(set (match_operand:VI124_AVX2 0 "register_operand" "=x")
9263         (abs:VI124_AVX2
9264           (match_operand:VI124_AVX2 1 "nonimmediate_operand" "xm")))]
9265   "TARGET_SSSE3"
9266   "%vpabs<ssemodesuffix>\t{%1, %0|%0, %1}"
9267   [(set_attr "type" "sselog1")
9268    (set_attr "prefix_data16" "1")
9269    (set_attr "prefix_extra" "1")
9270    (set_attr "prefix" "maybe_vex")
9271    (set_attr "mode" "<sseinsnmode>")])
9272
9273 (define_insn "abs<mode>2"
9274   [(set (match_operand:MMXMODEI 0 "register_operand" "=y")
9275         (abs:MMXMODEI
9276           (match_operand:MMXMODEI 1 "nonimmediate_operand" "ym")))]
9277   "TARGET_SSSE3"
9278   "pabs<mmxvecsize>\t{%1, %0|%0, %1}";
9279   [(set_attr "type" "sselog1")
9280    (set_attr "prefix_rep" "0")
9281    (set_attr "prefix_extra" "1")
9282    (set (attr "prefix_rex") (symbol_ref "x86_extended_reg_mentioned_p (insn)"))
9283    (set_attr "mode" "DI")])
9284
9285 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9286 ;;
9287 ;; AMD SSE4A instructions
9288 ;;
9289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9290
9291 (define_insn "sse4a_movnt<mode>"
9292   [(set (match_operand:MODEF 0 "memory_operand" "=m")
9293         (unspec:MODEF
9294           [(match_operand:MODEF 1 "register_operand" "x")]
9295           UNSPEC_MOVNT))]
9296   "TARGET_SSE4A"
9297   "movnt<ssemodesuffix>\t{%1, %0|%0, %1}"
9298   [(set_attr "type" "ssemov")
9299    (set_attr "mode" "<MODE>")])
9300
9301 (define_insn "sse4a_vmmovnt<mode>"
9302   [(set (match_operand:<ssescalarmode> 0 "memory_operand" "=m")
9303         (unspec:<ssescalarmode>
9304           [(vec_select:<ssescalarmode>
9305              (match_operand:VF_128 1 "register_operand" "x")
9306              (parallel [(const_int 0)]))]
9307           UNSPEC_MOVNT))]
9308   "TARGET_SSE4A"
9309   "movnt<ssescalarmodesuffix>\t{%1, %0|%0, %1}"
9310   [(set_attr "type" "ssemov")
9311    (set_attr "mode" "<ssescalarmode>")])
9312
9313 (define_insn "sse4a_extrqi"
9314   [(set (match_operand:V2DI 0 "register_operand" "=x")
9315         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9316                       (match_operand 2 "const_0_to_255_operand" "")
9317                       (match_operand 3 "const_0_to_255_operand" "")]
9318                      UNSPEC_EXTRQI))]
9319   "TARGET_SSE4A"
9320   "extrq\t{%3, %2, %0|%0, %2, %3}"
9321   [(set_attr "type" "sse")
9322    (set_attr "prefix_data16" "1")
9323    (set_attr "length_immediate" "2")
9324    (set_attr "mode" "TI")])
9325
9326 (define_insn "sse4a_extrq"
9327   [(set (match_operand:V2DI 0 "register_operand" "=x")
9328         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9329                       (match_operand:V16QI 2 "register_operand" "x")]
9330                      UNSPEC_EXTRQ))]
9331   "TARGET_SSE4A"
9332   "extrq\t{%2, %0|%0, %2}"
9333   [(set_attr "type" "sse")
9334    (set_attr "prefix_data16" "1")
9335    (set_attr "mode" "TI")])
9336
9337 (define_insn "sse4a_insertqi"
9338   [(set (match_operand:V2DI 0 "register_operand" "=x")
9339         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9340                       (match_operand:V2DI 2 "register_operand" "x")
9341                       (match_operand 3 "const_0_to_255_operand" "")
9342                       (match_operand 4 "const_0_to_255_operand" "")]
9343                      UNSPEC_INSERTQI))]
9344   "TARGET_SSE4A"
9345   "insertq\t{%4, %3, %2, %0|%0, %2, %3, %4}"
9346   [(set_attr "type" "sseins")
9347    (set_attr "prefix_data16" "0")
9348    (set_attr "prefix_rep" "1")
9349    (set_attr "length_immediate" "2")
9350    (set_attr "mode" "TI")])
9351
9352 (define_insn "sse4a_insertq"
9353   [(set (match_operand:V2DI 0 "register_operand" "=x")
9354         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0")
9355                       (match_operand:V2DI 2 "register_operand" "x")]
9356                      UNSPEC_INSERTQ))]
9357   "TARGET_SSE4A"
9358   "insertq\t{%2, %0|%0, %2}"
9359   [(set_attr "type" "sseins")
9360    (set_attr "prefix_data16" "0")
9361    (set_attr "prefix_rep" "1")
9362    (set_attr "mode" "TI")])
9363
9364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9365 ;;
9366 ;; Intel SSE4.1 instructions
9367 ;;
9368 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9369
9370 (define_insn "<sse4_1>_blend<ssemodesuffix><avxsizesuffix>"
9371   [(set (match_operand:VF 0 "register_operand" "=x,x")
9372         (vec_merge:VF
9373           (match_operand:VF 2 "nonimmediate_operand" "xm,xm")
9374           (match_operand:VF 1 "register_operand" "0,x")
9375           (match_operand:SI 3 "const_0_to_<blendbits>_operand" "")))]
9376   "TARGET_SSE4_1"
9377   "@
9378    blend<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
9379    vblend<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9380   [(set_attr "isa" "noavx,avx")
9381    (set_attr "type" "ssemov")
9382    (set_attr "length_immediate" "1")
9383    (set_attr "prefix_data16" "1,*")
9384    (set_attr "prefix_extra" "1")
9385    (set_attr "prefix" "orig,vex")
9386    (set_attr "mode" "<MODE>")])
9387
9388 (define_insn "<sse4_1>_blendv<ssemodesuffix><avxsizesuffix>"
9389   [(set (match_operand:VF 0 "reg_not_xmm0_operand_maybe_avx" "=x,x")
9390         (unspec:VF
9391           [(match_operand:VF 1 "reg_not_xmm0_operand_maybe_avx" "0,x")
9392            (match_operand:VF 2 "nonimm_not_xmm0_operand_maybe_avx" "xm,xm")
9393            (match_operand:VF 3 "register_operand" "Yz,x")]
9394           UNSPEC_BLENDV))]
9395   "TARGET_SSE4_1"
9396   "@
9397    blendv<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
9398    vblendv<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9399   [(set_attr "isa" "noavx,avx")
9400    (set_attr "type" "ssemov")
9401    (set_attr "length_immediate" "1")
9402    (set_attr "prefix_data16" "1,*")
9403    (set_attr "prefix_extra" "1")
9404    (set_attr "prefix" "orig,vex")
9405    (set_attr "mode" "<MODE>")])
9406
9407 (define_insn "<sse4_1>_dp<ssemodesuffix><avxsizesuffix>"
9408   [(set (match_operand:VF 0 "register_operand" "=x,x")
9409         (unspec:VF
9410           [(match_operand:VF 1 "nonimmediate_operand" "%0,x")
9411            (match_operand:VF 2 "nonimmediate_operand" "xm,xm")
9412            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
9413           UNSPEC_DP))]
9414   "TARGET_SSE4_1"
9415   "@
9416    dp<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}
9417    vdp<ssemodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9418   [(set_attr "isa" "noavx,avx")
9419    (set_attr "type" "ssemul")
9420    (set_attr "length_immediate" "1")
9421    (set_attr "prefix_data16" "1,*")
9422    (set_attr "prefix_extra" "1")
9423    (set_attr "prefix" "orig,vex")
9424    (set_attr "mode" "<MODE>")])
9425
9426 (define_insn "<sse4_1_avx2>_movntdqa"
9427   [(set (match_operand:VI8_AVX2 0 "register_operand" "=x")
9428         (unspec:VI8_AVX2 [(match_operand:VI8_AVX2 1 "memory_operand" "m")]
9429                      UNSPEC_MOVNTDQA))]
9430   "TARGET_SSE4_1"
9431   "%vmovntdqa\t{%1, %0|%0, %1}"
9432   [(set_attr "type" "ssemov")
9433    (set_attr "prefix_extra" "1")
9434    (set_attr "prefix" "maybe_vex")
9435    (set_attr "mode" "<sseinsnmode>")])
9436
9437 (define_insn "<sse4_1_avx2>_mpsadbw"
9438   [(set (match_operand:VI1_AVX2 0 "register_operand" "=x,x")
9439         (unspec:VI1_AVX2 [(match_operand:VI1_AVX2 1 "register_operand" "0,x")
9440                           (match_operand:VI1_AVX2 2 "nonimmediate_operand" "xm,xm")
9441                           (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
9442                          UNSPEC_MPSADBW))]
9443   "TARGET_SSE4_1"
9444   "@
9445    mpsadbw\t{%3, %2, %0|%0, %2, %3}
9446    vmpsadbw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9447   [(set_attr "isa" "noavx,avx")
9448    (set_attr "type" "sselog1")
9449    (set_attr "length_immediate" "1")
9450    (set_attr "prefix_extra" "1")
9451    (set_attr "prefix" "orig,vex")
9452    (set_attr "mode" "<sseinsnmode>")])
9453
9454 (define_insn "avx2_packusdw"
9455   [(set (match_operand:V16HI 0 "register_operand" "=x")
9456         (vec_concat:V16HI
9457           (us_truncate:V8HI
9458             (match_operand:V8SI 1 "register_operand" "x"))
9459           (us_truncate:V8HI
9460             (match_operand:V8SI 2 "nonimmediate_operand" "xm"))))]
9461   "TARGET_AVX2"
9462   "vpackusdw\t{%2, %1, %0|%0, %1, %2}"
9463   [(set_attr "type" "sselog")
9464    (set_attr "prefix_extra" "1")
9465    (set_attr "prefix" "vex")
9466    (set_attr "mode" "OI")])
9467
9468 (define_insn "sse4_1_packusdw"
9469   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
9470         (vec_concat:V8HI
9471           (us_truncate:V4HI
9472             (match_operand:V4SI 1 "register_operand" "0,x"))
9473           (us_truncate:V4HI
9474             (match_operand:V4SI 2 "nonimmediate_operand" "xm,xm"))))]
9475   "TARGET_SSE4_1"
9476   "@
9477    packusdw\t{%2, %0|%0, %2}
9478    vpackusdw\t{%2, %1, %0|%0, %1, %2}"
9479   [(set_attr "isa" "noavx,avx")
9480    (set_attr "type" "sselog")
9481    (set_attr "prefix_extra" "1")
9482    (set_attr "prefix" "orig,vex")
9483    (set_attr "mode" "TI")])
9484
9485 (define_insn "<sse4_1_avx2>_pblendvb"
9486   [(set (match_operand:VI1_AVX2 0 "reg_not_xmm0_operand" "=x,x")
9487         (unspec:VI1_AVX2
9488           [(match_operand:VI1_AVX2 1 "reg_not_xmm0_operand_maybe_avx"  "0,x")
9489            (match_operand:VI1_AVX2 2 "nonimm_not_xmm0_operand_maybe_avx" "xm,xm")
9490            (match_operand:VI1_AVX2 3 "register_operand" "Yz,x")]
9491           UNSPEC_BLENDV))]
9492   "TARGET_SSE4_1"
9493   "@
9494    pblendvb\t{%3, %2, %0|%0, %2, %3}
9495    vpblendvb\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9496   [(set_attr "isa" "noavx,avx")
9497    (set_attr "type" "ssemov")
9498    (set_attr "prefix_extra" "1")
9499    (set_attr "length_immediate" "*,1")
9500    (set_attr "prefix" "orig,vex")
9501    (set_attr "mode" "<sseinsnmode>")])
9502
9503 (define_insn "<sse4_1_avx2>_pblendw"
9504   [(set (match_operand:VI2_AVX2 0 "register_operand" "=x,x")
9505         (vec_merge:VI2_AVX2
9506           (match_operand:VI2_AVX2 2 "nonimmediate_operand" "xm,xm")
9507           (match_operand:VI2_AVX2 1 "register_operand" "0,x")
9508           (match_operand:SI 3 "const_0_to_255_operand" "n,n")))]
9509   "TARGET_SSE4_1"
9510   "@
9511    pblendw\t{%3, %2, %0|%0, %2, %3}
9512    vpblendw\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9513   [(set_attr "isa" "noavx,avx")
9514    (set_attr "type" "ssemov")
9515    (set_attr "prefix_extra" "1")
9516    (set_attr "length_immediate" "1")
9517    (set_attr "prefix" "orig,vex")
9518    (set_attr "mode" "<sseinsnmode>")])
9519
9520 (define_insn "avx2_pblendd<mode>"
9521   [(set (match_operand:VI4_AVX2 0 "register_operand" "=x")
9522         (vec_merge:VI4_AVX2
9523           (match_operand:VI4_AVX2 2 "nonimmediate_operand" "xm")
9524           (match_operand:VI4_AVX2 1 "register_operand" "x")
9525           (match_operand:SI 3 "const_0_to_255_operand" "n")))]
9526   "TARGET_AVX2"
9527   "vpblendd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9528   [(set_attr "type" "ssemov")
9529    (set_attr "prefix_extra" "1")
9530    (set_attr "length_immediate" "1")
9531    (set_attr "prefix" "vex")
9532    (set_attr "mode" "<sseinsnmode>")])
9533
9534 (define_insn "sse4_1_phminposuw"
9535   [(set (match_operand:V8HI 0 "register_operand" "=x")
9536         (unspec:V8HI [(match_operand:V8HI 1 "nonimmediate_operand" "xm")]
9537                      UNSPEC_PHMINPOSUW))]
9538   "TARGET_SSE4_1"
9539   "%vphminposuw\t{%1, %0|%0, %1}"
9540   [(set_attr "type" "sselog1")
9541    (set_attr "prefix_extra" "1")
9542    (set_attr "prefix" "maybe_vex")
9543    (set_attr "mode" "TI")])
9544
9545 (define_insn "avx2_<code>v16qiv16hi2"
9546   [(set (match_operand:V16HI 0 "register_operand" "=x")
9547         (any_extend:V16HI
9548           (match_operand:V16QI 1 "nonimmediate_operand" "xm")))]
9549   "TARGET_AVX2"
9550   "vpmov<extsuffix>bw\t{%1, %0|%0, %1}"
9551   [(set_attr "type" "ssemov")
9552    (set_attr "prefix_extra" "1")
9553    (set_attr "prefix" "vex")
9554    (set_attr "mode" "OI")])
9555
9556 (define_insn "sse4_1_<code>v8qiv8hi2"
9557   [(set (match_operand:V8HI 0 "register_operand" "=x")
9558         (any_extend:V8HI
9559           (vec_select:V8QI
9560             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9561             (parallel [(const_int 0)
9562                        (const_int 1)
9563                        (const_int 2)
9564                        (const_int 3)
9565                        (const_int 4)
9566                        (const_int 5)
9567                        (const_int 6)
9568                        (const_int 7)]))))]
9569   "TARGET_SSE4_1"
9570   "%vpmov<extsuffix>bw\t{%1, %0|%0, %1}"
9571   [(set_attr "type" "ssemov")
9572    (set_attr "prefix_extra" "1")
9573    (set_attr "prefix" "maybe_vex")
9574    (set_attr "mode" "TI")])
9575
9576 (define_insn "avx2_<code>v8qiv8si2"
9577   [(set (match_operand:V8SI 0 "register_operand" "=x")
9578         (any_extend:V8SI
9579           (vec_select:V8QI
9580             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9581             (parallel [(const_int 0)
9582                        (const_int 1)
9583                        (const_int 2)
9584                        (const_int 3)
9585                        (const_int 4)
9586                        (const_int 5)
9587                        (const_int 6)
9588                        (const_int 7)]))))]
9589   "TARGET_AVX2"
9590   "vpmov<extsuffix>bd\t{%1, %0|%0, %1}"
9591   [(set_attr "type" "ssemov")
9592    (set_attr "prefix_extra" "1")
9593    (set_attr "prefix" "vex")
9594    (set_attr "mode" "OI")])
9595
9596 (define_insn "sse4_1_<code>v4qiv4si2"
9597   [(set (match_operand:V4SI 0 "register_operand" "=x")
9598         (any_extend:V4SI
9599           (vec_select:V4QI
9600             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9601             (parallel [(const_int 0)
9602                        (const_int 1)
9603                        (const_int 2)
9604                        (const_int 3)]))))]
9605   "TARGET_SSE4_1"
9606   "%vpmov<extsuffix>bd\t{%1, %0|%0, %1}"
9607   [(set_attr "type" "ssemov")
9608    (set_attr "prefix_extra" "1")
9609    (set_attr "prefix" "maybe_vex")
9610    (set_attr "mode" "TI")])
9611
9612 (define_insn "avx2_<code>v8hiv8si2"
9613   [(set (match_operand:V8SI 0 "register_operand" "=x")
9614         (any_extend:V8SI
9615             (match_operand:V8HI 1 "nonimmediate_operand" "xm")))]
9616   "TARGET_AVX2"
9617   "vpmov<extsuffix>wd\t{%1, %0|%0, %1}"
9618   [(set_attr "type" "ssemov")
9619    (set_attr "prefix_extra" "1")
9620    (set_attr "prefix" "vex")
9621    (set_attr "mode" "OI")])
9622
9623 (define_insn "sse4_1_<code>v4hiv4si2"
9624   [(set (match_operand:V4SI 0 "register_operand" "=x")
9625         (any_extend:V4SI
9626           (vec_select:V4HI
9627             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9628             (parallel [(const_int 0)
9629                        (const_int 1)
9630                        (const_int 2)
9631                        (const_int 3)]))))]
9632   "TARGET_SSE4_1"
9633   "%vpmov<extsuffix>wd\t{%1, %0|%0, %1}"
9634   [(set_attr "type" "ssemov")
9635    (set_attr "prefix_extra" "1")
9636    (set_attr "prefix" "maybe_vex")
9637    (set_attr "mode" "TI")])
9638
9639 (define_insn "avx2_<code>v4qiv4di2"
9640   [(set (match_operand:V4DI 0 "register_operand" "=x")
9641         (any_extend:V4DI
9642           (vec_select:V4QI
9643             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9644             (parallel [(const_int 0)
9645                        (const_int 1)
9646                        (const_int 2)
9647                        (const_int 3)]))))]
9648   "TARGET_AVX2"
9649   "vpmov<extsuffix>bq\t{%1, %0|%0, %1}"
9650   [(set_attr "type" "ssemov")
9651    (set_attr "prefix_extra" "1")
9652    (set_attr "prefix" "vex")
9653    (set_attr "mode" "OI")])
9654
9655 (define_insn "sse4_1_<code>v2qiv2di2"
9656   [(set (match_operand:V2DI 0 "register_operand" "=x")
9657         (any_extend:V2DI
9658           (vec_select:V2QI
9659             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
9660             (parallel [(const_int 0)
9661                        (const_int 1)]))))]
9662   "TARGET_SSE4_1"
9663   "%vpmov<extsuffix>bq\t{%1, %0|%0, %1}"
9664   [(set_attr "type" "ssemov")
9665    (set_attr "prefix_extra" "1")
9666    (set_attr "prefix" "maybe_vex")
9667    (set_attr "mode" "TI")])
9668
9669 (define_insn "avx2_<code>v4hiv4di2"
9670   [(set (match_operand:V4DI 0 "register_operand" "=x")
9671         (any_extend:V4DI
9672           (vec_select:V4HI
9673             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9674             (parallel [(const_int 0)
9675                        (const_int 1)
9676                        (const_int 2)
9677                        (const_int 3)]))))]
9678   "TARGET_AVX2"
9679   "vpmov<extsuffix>wq\t{%1, %0|%0, %1}"
9680   [(set_attr "type" "ssemov")
9681    (set_attr "prefix_extra" "1")
9682    (set_attr "prefix" "vex")
9683    (set_attr "mode" "OI")])
9684
9685 (define_insn "sse4_1_<code>v2hiv2di2"
9686   [(set (match_operand:V2DI 0 "register_operand" "=x")
9687         (any_extend:V2DI
9688           (vec_select:V2HI
9689             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
9690             (parallel [(const_int 0)
9691                        (const_int 1)]))))]
9692   "TARGET_SSE4_1"
9693   "%vpmov<extsuffix>wq\t{%1, %0|%0, %1}"
9694   [(set_attr "type" "ssemov")
9695    (set_attr "prefix_extra" "1")
9696    (set_attr "prefix" "maybe_vex")
9697    (set_attr "mode" "TI")])
9698
9699 (define_insn "avx2_<code>v4siv4di2"
9700   [(set (match_operand:V4DI 0 "register_operand" "=x")
9701         (any_extend:V4DI
9702             (match_operand:V4SI 1 "nonimmediate_operand" "xm")))]
9703   "TARGET_AVX2"
9704   "vpmov<extsuffix>dq\t{%1, %0|%0, %1}"
9705   [(set_attr "type" "ssemov")
9706    (set_attr "prefix_extra" "1")
9707    (set_attr "mode" "OI")])
9708
9709 (define_insn "sse4_1_<code>v2siv2di2"
9710   [(set (match_operand:V2DI 0 "register_operand" "=x")
9711         (any_extend:V2DI
9712           (vec_select:V2SI
9713             (match_operand:V4SI 1 "nonimmediate_operand" "xm")
9714             (parallel [(const_int 0)
9715                        (const_int 1)]))))]
9716   "TARGET_SSE4_1"
9717   "%vpmov<extsuffix>dq\t{%1, %0|%0, %1}"
9718   [(set_attr "type" "ssemov")
9719    (set_attr "prefix_extra" "1")
9720    (set_attr "prefix" "maybe_vex")
9721    (set_attr "mode" "TI")])
9722
9723 ;; ptestps/ptestpd are very similar to comiss and ucomiss when
9724 ;; setting FLAGS_REG. But it is not a really compare instruction.
9725 (define_insn "avx_vtest<ssemodesuffix><avxsizesuffix>"
9726   [(set (reg:CC FLAGS_REG)
9727         (unspec:CC [(match_operand:VF 0 "register_operand" "x")
9728                     (match_operand:VF 1 "nonimmediate_operand" "xm")]
9729                    UNSPEC_VTESTP))]
9730   "TARGET_AVX"
9731   "vtest<ssemodesuffix>\t{%1, %0|%0, %1}"
9732   [(set_attr "type" "ssecomi")
9733    (set_attr "prefix_extra" "1")
9734    (set_attr "prefix" "vex")
9735    (set_attr "mode" "<MODE>")])
9736
9737 ;; ptest is very similar to comiss and ucomiss when setting FLAGS_REG.
9738 ;; But it is not a really compare instruction.
9739 (define_insn "avx_ptest256"
9740   [(set (reg:CC FLAGS_REG)
9741         (unspec:CC [(match_operand:V4DI 0 "register_operand" "x")
9742                     (match_operand:V4DI 1 "nonimmediate_operand" "xm")]
9743                    UNSPEC_PTEST))]
9744   "TARGET_AVX"
9745   "vptest\t{%1, %0|%0, %1}"
9746   [(set_attr "type" "ssecomi")
9747    (set_attr "prefix_extra" "1")
9748    (set_attr "prefix" "vex")
9749    (set_attr "mode" "OI")])
9750
9751 (define_insn "sse4_1_ptest"
9752   [(set (reg:CC FLAGS_REG)
9753         (unspec:CC [(match_operand:V2DI 0 "register_operand" "x")
9754                     (match_operand:V2DI 1 "nonimmediate_operand" "xm")]
9755                    UNSPEC_PTEST))]
9756   "TARGET_SSE4_1"
9757   "%vptest\t{%1, %0|%0, %1}"
9758   [(set_attr "type" "ssecomi")
9759    (set_attr "prefix_extra" "1")
9760    (set_attr "prefix" "maybe_vex")
9761    (set_attr "mode" "TI")])
9762
9763 (define_insn "<sse4_1>_round<ssemodesuffix><avxsizesuffix>"
9764   [(set (match_operand:VF 0 "register_operand" "=x")
9765         (unspec:VF
9766           [(match_operand:VF 1 "nonimmediate_operand" "xm")
9767            (match_operand:SI 2 "const_0_to_15_operand" "n")]
9768           UNSPEC_ROUND))]
9769   "TARGET_ROUND"
9770   "%vround<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
9771   [(set_attr "type" "ssecvt")
9772    (set (attr "prefix_data16")
9773      (if_then_else
9774        (match_test "TARGET_AVX")
9775      (const_string "*")
9776      (const_string "1")))
9777    (set_attr "prefix_extra" "1")
9778    (set_attr "length_immediate" "1")
9779    (set_attr "prefix" "maybe_vex")
9780    (set_attr "mode" "<MODE>")])
9781
9782 (define_insn "sse4_1_round<ssescalarmodesuffix>"
9783   [(set (match_operand:VF_128 0 "register_operand" "=x,x")
9784         (vec_merge:VF_128
9785           (unspec:VF_128
9786             [(match_operand:VF_128 2 "register_operand" "x,x")
9787              (match_operand:SI 3 "const_0_to_15_operand" "n,n")]
9788             UNSPEC_ROUND)
9789           (match_operand:VF_128 1 "register_operand" "0,x")
9790           (const_int 1)))]
9791   "TARGET_ROUND"
9792   "@
9793    round<ssescalarmodesuffix>\t{%3, %2, %0|%0, %2, %3}
9794    vround<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %2, %3}"
9795   [(set_attr "isa" "noavx,avx")
9796    (set_attr "type" "ssecvt")
9797    (set_attr "length_immediate" "1")
9798    (set_attr "prefix_data16" "1,*")
9799    (set_attr "prefix_extra" "1")
9800    (set_attr "prefix" "orig,vex")
9801    (set_attr "mode" "<MODE>")])
9802
9803 (define_expand "round<mode>2"
9804   [(set (match_dup 4)
9805         (plus:VF
9806           (match_operand:VF 1 "nonimmediate_operand" "")
9807           (match_dup 3)))
9808    (set (match_operand:VF 0 "register_operand" "")
9809         (unspec:VF
9810           [(match_dup 4) (match_dup 5)]
9811           UNSPEC_ROUND))]
9812   "TARGET_ROUND && !flag_trapping_math"
9813 {
9814   enum machine_mode scalar_mode;
9815   const struct real_format *fmt;
9816   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
9817   rtx half, vec_half;
9818
9819   scalar_mode = GET_MODE_INNER (<MODE>mode);
9820
9821   /* load nextafter (0.5, 0.0) */
9822   fmt = REAL_MODE_FORMAT (scalar_mode);
9823   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, scalar_mode);
9824   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
9825   half = const_double_from_real_value (pred_half, scalar_mode);
9826
9827   vec_half = ix86_build_const_vector (<MODE>mode, true, half);
9828   vec_half = force_reg (<MODE>mode, vec_half);
9829
9830   operands[3] = gen_reg_rtx (<MODE>mode);
9831   emit_insn (gen_copysign<mode>3 (operands[3], vec_half, operands[1]));
9832
9833   operands[4] = gen_reg_rtx (<MODE>mode);
9834   operands[5] = GEN_INT (ROUND_TRUNC);
9835 })
9836
9837 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9838 ;;
9839 ;; Intel SSE4.2 string/text processing instructions
9840 ;;
9841 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9842
9843 (define_insn_and_split "sse4_2_pcmpestr"
9844   [(set (match_operand:SI 0 "register_operand" "=c,c")
9845         (unspec:SI
9846           [(match_operand:V16QI 2 "reg_not_xmm0_operand" "x,x")
9847            (match_operand:SI 3 "register_operand" "a,a")
9848            (match_operand:V16QI 4 "nonimm_not_xmm0_operand" "x,m")
9849            (match_operand:SI 5 "register_operand" "d,d")
9850            (match_operand:SI 6 "const_0_to_255_operand" "n,n")]
9851           UNSPEC_PCMPESTR))
9852    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
9853         (unspec:V16QI
9854           [(match_dup 2)
9855            (match_dup 3)
9856            (match_dup 4)
9857            (match_dup 5)
9858            (match_dup 6)]
9859           UNSPEC_PCMPESTR))
9860    (set (reg:CC FLAGS_REG)
9861         (unspec:CC
9862           [(match_dup 2)
9863            (match_dup 3)
9864            (match_dup 4)
9865            (match_dup 5)
9866            (match_dup 6)]
9867           UNSPEC_PCMPESTR))]
9868   "TARGET_SSE4_2
9869    && can_create_pseudo_p ()"
9870   "#"
9871   "&& 1"
9872   [(const_int 0)]
9873 {
9874   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
9875   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
9876   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
9877
9878   if (ecx)
9879     emit_insn (gen_sse4_2_pcmpestri (operands[0], operands[2],
9880                                      operands[3], operands[4],
9881                                      operands[5], operands[6]));
9882   if (xmm0)
9883     emit_insn (gen_sse4_2_pcmpestrm (operands[1], operands[2],
9884                                      operands[3], operands[4],
9885                                      operands[5], operands[6]));
9886   if (flags && !(ecx || xmm0))
9887     emit_insn (gen_sse4_2_pcmpestr_cconly (NULL, NULL,
9888                                            operands[2], operands[3],
9889                                            operands[4], operands[5],
9890                                            operands[6]));
9891   if (!(flags || ecx || xmm0))
9892     emit_note (NOTE_INSN_DELETED);
9893
9894   DONE;
9895 }
9896   [(set_attr "type" "sselog")
9897    (set_attr "prefix_data16" "1")
9898    (set_attr "prefix_extra" "1")
9899    (set_attr "length_immediate" "1")
9900    (set_attr "memory" "none,load")
9901    (set_attr "mode" "TI")])
9902
9903 (define_insn "sse4_2_pcmpestri"
9904   [(set (match_operand:SI 0 "register_operand" "=c,c")
9905         (unspec:SI
9906           [(match_operand:V16QI 1 "register_operand" "x,x")
9907            (match_operand:SI 2 "register_operand" "a,a")
9908            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
9909            (match_operand:SI 4 "register_operand" "d,d")
9910            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
9911           UNSPEC_PCMPESTR))
9912    (set (reg:CC FLAGS_REG)
9913         (unspec:CC
9914           [(match_dup 1)
9915            (match_dup 2)
9916            (match_dup 3)
9917            (match_dup 4)
9918            (match_dup 5)]
9919           UNSPEC_PCMPESTR))]
9920   "TARGET_SSE4_2"
9921   "%vpcmpestri\t{%5, %3, %1|%1, %3, %5}"
9922   [(set_attr "type" "sselog")
9923    (set_attr "prefix_data16" "1")
9924    (set_attr "prefix_extra" "1")
9925    (set_attr "prefix" "maybe_vex")
9926    (set_attr "length_immediate" "1")
9927    (set_attr "memory" "none,load")
9928    (set_attr "mode" "TI")])
9929
9930 (define_insn "sse4_2_pcmpestrm"
9931   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
9932         (unspec:V16QI
9933           [(match_operand:V16QI 1 "register_operand" "x,x")
9934            (match_operand:SI 2 "register_operand" "a,a")
9935            (match_operand:V16QI 3 "nonimmediate_operand" "x,m")
9936            (match_operand:SI 4 "register_operand" "d,d")
9937            (match_operand:SI 5 "const_0_to_255_operand" "n,n")]
9938           UNSPEC_PCMPESTR))
9939    (set (reg:CC FLAGS_REG)
9940         (unspec:CC
9941           [(match_dup 1)
9942            (match_dup 2)
9943            (match_dup 3)
9944            (match_dup 4)
9945            (match_dup 5)]
9946           UNSPEC_PCMPESTR))]
9947   "TARGET_SSE4_2"
9948   "%vpcmpestrm\t{%5, %3, %1|%1, %3, %5}"
9949   [(set_attr "type" "sselog")
9950    (set_attr "prefix_data16" "1")
9951    (set_attr "prefix_extra" "1")
9952    (set_attr "length_immediate" "1")
9953    (set_attr "prefix" "maybe_vex")
9954    (set_attr "memory" "none,load")
9955    (set_attr "mode" "TI")])
9956
9957 (define_insn "sse4_2_pcmpestr_cconly"
9958   [(set (reg:CC FLAGS_REG)
9959         (unspec:CC
9960           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
9961            (match_operand:SI 3 "register_operand" "a,a,a,a")
9962            (match_operand:V16QI 4 "nonimmediate_operand" "x,m,x,m")
9963            (match_operand:SI 5 "register_operand" "d,d,d,d")
9964            (match_operand:SI 6 "const_0_to_255_operand" "n,n,n,n")]
9965           UNSPEC_PCMPESTR))
9966    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
9967    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
9968   "TARGET_SSE4_2"
9969   "@
9970    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
9971    %vpcmpestrm\t{%6, %4, %2|%2, %4, %6}
9972    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}
9973    %vpcmpestri\t{%6, %4, %2|%2, %4, %6}"
9974   [(set_attr "type" "sselog")
9975    (set_attr "prefix_data16" "1")
9976    (set_attr "prefix_extra" "1")
9977    (set_attr "length_immediate" "1")
9978    (set_attr "memory" "none,load,none,load")
9979    (set_attr "prefix" "maybe_vex")
9980    (set_attr "mode" "TI")])
9981
9982 (define_insn_and_split "sse4_2_pcmpistr"
9983   [(set (match_operand:SI 0 "register_operand" "=c,c")
9984         (unspec:SI
9985           [(match_operand:V16QI 2 "reg_not_xmm0_operand" "x,x")
9986            (match_operand:V16QI 3 "nonimm_not_xmm0_operand" "x,m")
9987            (match_operand:SI 4 "const_0_to_255_operand" "n,n")]
9988           UNSPEC_PCMPISTR))
9989    (set (match_operand:V16QI 1 "register_operand" "=Yz,Yz")
9990         (unspec:V16QI
9991           [(match_dup 2)
9992            (match_dup 3)
9993            (match_dup 4)]
9994           UNSPEC_PCMPISTR))
9995    (set (reg:CC FLAGS_REG)
9996         (unspec:CC
9997           [(match_dup 2)
9998            (match_dup 3)
9999            (match_dup 4)]
10000           UNSPEC_PCMPISTR))]
10001   "TARGET_SSE4_2
10002    && can_create_pseudo_p ()"
10003   "#"
10004   "&& 1"
10005   [(const_int 0)]
10006 {
10007   int ecx = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[0]));
10008   int xmm0 = !find_regno_note (curr_insn, REG_UNUSED, REGNO (operands[1]));
10009   int flags = !find_regno_note (curr_insn, REG_UNUSED, FLAGS_REG);
10010
10011   if (ecx)
10012     emit_insn (gen_sse4_2_pcmpistri (operands[0], operands[2],
10013                                      operands[3], operands[4]));
10014   if (xmm0)
10015     emit_insn (gen_sse4_2_pcmpistrm (operands[1], operands[2],
10016                                      operands[3], operands[4]));
10017   if (flags && !(ecx || xmm0))
10018     emit_insn (gen_sse4_2_pcmpistr_cconly (NULL, NULL,
10019                                            operands[2], operands[3],
10020                                            operands[4]));
10021   if (!(flags || ecx || xmm0))
10022     emit_note (NOTE_INSN_DELETED);
10023
10024   DONE;
10025 }
10026   [(set_attr "type" "sselog")
10027    (set_attr "prefix_data16" "1")
10028    (set_attr "prefix_extra" "1")
10029    (set_attr "length_immediate" "1")
10030    (set_attr "memory" "none,load")
10031    (set_attr "mode" "TI")])
10032
10033 (define_insn "sse4_2_pcmpistri"
10034   [(set (match_operand:SI 0 "register_operand" "=c,c")
10035         (unspec:SI
10036           [(match_operand:V16QI 1 "register_operand" "x,x")
10037            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
10038            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
10039           UNSPEC_PCMPISTR))
10040    (set (reg:CC FLAGS_REG)
10041         (unspec:CC
10042           [(match_dup 1)
10043            (match_dup 2)
10044            (match_dup 3)]
10045           UNSPEC_PCMPISTR))]
10046   "TARGET_SSE4_2"
10047   "%vpcmpistri\t{%3, %2, %1|%1, %2, %3}"
10048   [(set_attr "type" "sselog")
10049    (set_attr "prefix_data16" "1")
10050    (set_attr "prefix_extra" "1")
10051    (set_attr "length_immediate" "1")
10052    (set_attr "prefix" "maybe_vex")
10053    (set_attr "memory" "none,load")
10054    (set_attr "mode" "TI")])
10055
10056 (define_insn "sse4_2_pcmpistrm"
10057   [(set (match_operand:V16QI 0 "register_operand" "=Yz,Yz")
10058         (unspec:V16QI
10059           [(match_operand:V16QI 1 "register_operand" "x,x")
10060            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
10061            (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
10062           UNSPEC_PCMPISTR))
10063    (set (reg:CC FLAGS_REG)
10064         (unspec:CC
10065           [(match_dup 1)
10066            (match_dup 2)
10067            (match_dup 3)]
10068           UNSPEC_PCMPISTR))]
10069   "TARGET_SSE4_2"
10070   "%vpcmpistrm\t{%3, %2, %1|%1, %2, %3}"
10071   [(set_attr "type" "sselog")
10072    (set_attr "prefix_data16" "1")
10073    (set_attr "prefix_extra" "1")
10074    (set_attr "length_immediate" "1")
10075    (set_attr "prefix" "maybe_vex")
10076    (set_attr "memory" "none,load")
10077    (set_attr "mode" "TI")])
10078
10079 (define_insn "sse4_2_pcmpistr_cconly"
10080   [(set (reg:CC FLAGS_REG)
10081         (unspec:CC
10082           [(match_operand:V16QI 2 "register_operand" "x,x,x,x")
10083            (match_operand:V16QI 3 "nonimmediate_operand" "x,m,x,m")
10084            (match_operand:SI 4 "const_0_to_255_operand" "n,n,n,n")]
10085           UNSPEC_PCMPISTR))
10086    (clobber (match_scratch:V16QI 0 "=Yz,Yz,X,X"))
10087    (clobber (match_scratch:SI    1 "= X, X,c,c"))]
10088   "TARGET_SSE4_2"
10089   "@
10090    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
10091    %vpcmpistrm\t{%4, %3, %2|%2, %3, %4}
10092    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}
10093    %vpcmpistri\t{%4, %3, %2|%2, %3, %4}"
10094   [(set_attr "type" "sselog")
10095    (set_attr "prefix_data16" "1")
10096    (set_attr "prefix_extra" "1")
10097    (set_attr "length_immediate" "1")
10098    (set_attr "memory" "none,load,none,load")
10099    (set_attr "prefix" "maybe_vex")
10100    (set_attr "mode" "TI")])
10101
10102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10103 ;;
10104 ;; XOP instructions
10105 ;;
10106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10107
10108 ;; XOP parallel integer multiply/add instructions.
10109 ;; Note the XOP multiply/add instructions
10110 ;;     a[i] = b[i] * c[i] + d[i];
10111 ;; do not allow the value being added to be a memory operation.
10112 (define_insn "xop_pmacsww"
10113   [(set (match_operand:V8HI 0 "register_operand" "=x")
10114         (plus:V8HI
10115          (mult:V8HI
10116           (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10117           (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
10118          (match_operand:V8HI 3 "nonimmediate_operand" "x")))]
10119   "TARGET_XOP"
10120   "vpmacsww\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10121   [(set_attr "type" "ssemuladd")
10122    (set_attr "mode" "TI")])
10123
10124 (define_insn "xop_pmacssww"
10125   [(set (match_operand:V8HI 0 "register_operand" "=x")
10126         (ss_plus:V8HI
10127          (mult:V8HI (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10128                     (match_operand:V8HI 2 "nonimmediate_operand" "xm"))
10129          (match_operand:V8HI 3 "nonimmediate_operand" "x")))]
10130   "TARGET_XOP"
10131   "vpmacssww\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10132   [(set_attr "type" "ssemuladd")
10133    (set_attr "mode" "TI")])
10134
10135 (define_insn "xop_pmacsdd"
10136   [(set (match_operand:V4SI 0 "register_operand" "=x")
10137         (plus:V4SI
10138          (mult:V4SI
10139           (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10140           (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
10141          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10142   "TARGET_XOP"
10143   "vpmacsdd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10144   [(set_attr "type" "ssemuladd")
10145    (set_attr "mode" "TI")])
10146
10147 (define_insn "xop_pmacssdd"
10148   [(set (match_operand:V4SI 0 "register_operand" "=x")
10149         (ss_plus:V4SI
10150          (mult:V4SI (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10151                     (match_operand:V4SI 2 "nonimmediate_operand" "xm"))
10152          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10153   "TARGET_XOP"
10154   "vpmacssdd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10155   [(set_attr "type" "ssemuladd")
10156    (set_attr "mode" "TI")])
10157
10158 (define_insn "xop_pmacssdql"
10159   [(set (match_operand:V2DI 0 "register_operand" "=x")
10160         (ss_plus:V2DI
10161          (mult:V2DI
10162           (sign_extend:V2DI
10163            (vec_select:V2SI
10164             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10165             (parallel [(const_int 1)
10166                        (const_int 3)])))
10167           (vec_select:V2SI
10168            (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10169            (parallel [(const_int 1)
10170                       (const_int 3)])))
10171          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10172   "TARGET_XOP"
10173   "vpmacssdql\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10174   [(set_attr "type" "ssemuladd")
10175    (set_attr "mode" "TI")])
10176
10177 (define_insn "xop_pmacssdqh"
10178   [(set (match_operand:V2DI 0 "register_operand" "=x")
10179         (ss_plus:V2DI
10180          (mult:V2DI
10181           (sign_extend:V2DI
10182            (vec_select:V2SI
10183             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10184             (parallel [(const_int 0)
10185                        (const_int 2)])))
10186           (sign_extend:V2DI
10187            (vec_select:V2SI
10188             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10189             (parallel [(const_int 0)
10190                        (const_int 2)]))))
10191          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10192   "TARGET_XOP"
10193   "vpmacssdqh\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10194   [(set_attr "type" "ssemuladd")
10195    (set_attr "mode" "TI")])
10196
10197 (define_insn "xop_pmacsdql"
10198   [(set (match_operand:V2DI 0 "register_operand" "=x")
10199         (plus:V2DI
10200          (mult:V2DI
10201           (sign_extend:V2DI
10202            (vec_select:V2SI
10203             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10204             (parallel [(const_int 1)
10205                        (const_int 3)])))
10206           (sign_extend:V2DI
10207            (vec_select:V2SI
10208             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10209             (parallel [(const_int 1)
10210                        (const_int 3)]))))
10211          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10212   "TARGET_XOP"
10213   "vpmacsdql\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10214   [(set_attr "type" "ssemuladd")
10215    (set_attr "mode" "TI")])
10216
10217 ;; We don't have a straight 32-bit parallel multiply and extend on XOP, so
10218 ;; fake it with a multiply/add.  In general, we expect the define_split to
10219 ;; occur before register allocation, so we have to handle the corner case where
10220 ;; the target is the same as operands 1/2
10221 (define_insn_and_split "xop_mulv2div2di3_low"
10222   [(set (match_operand:V2DI 0 "register_operand" "=&x")
10223         (mult:V2DI
10224           (sign_extend:V2DI
10225             (vec_select:V2SI
10226               (match_operand:V4SI 1 "register_operand" "%x")
10227               (parallel [(const_int 1)
10228                          (const_int 3)])))
10229           (sign_extend:V2DI
10230             (vec_select:V2SI
10231               (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10232               (parallel [(const_int 1)
10233                          (const_int 3)])))))]
10234   "TARGET_XOP"
10235   "#"
10236   "&& reload_completed"
10237   [(set (match_dup 0)
10238         (match_dup 3))
10239    (set (match_dup 0)
10240         (plus:V2DI
10241          (mult:V2DI
10242           (sign_extend:V2DI
10243            (vec_select:V2SI
10244             (match_dup 1)
10245             (parallel [(const_int 1)
10246                        (const_int 3)])))
10247           (sign_extend:V2DI
10248            (vec_select:V2SI
10249             (match_dup 2)
10250             (parallel [(const_int 1)
10251                        (const_int 3)]))))
10252          (match_dup 0)))]
10253 {
10254   operands[3] = CONST0_RTX (V2DImode);
10255 }
10256   [(set_attr "type" "ssemul")
10257    (set_attr "mode" "TI")])
10258
10259 (define_insn "xop_pmacsdqh"
10260   [(set (match_operand:V2DI 0 "register_operand" "=x")
10261         (plus:V2DI
10262          (mult:V2DI
10263           (sign_extend:V2DI
10264            (vec_select:V2SI
10265             (match_operand:V4SI 1 "nonimmediate_operand" "%x")
10266             (parallel [(const_int 0)
10267                        (const_int 2)])))
10268           (sign_extend:V2DI
10269            (vec_select:V2SI
10270             (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10271             (parallel [(const_int 0)
10272                        (const_int 2)]))))
10273          (match_operand:V2DI 3 "nonimmediate_operand" "x")))]
10274   "TARGET_XOP"
10275   "vpmacsdqh\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10276   [(set_attr "type" "ssemuladd")
10277    (set_attr "mode" "TI")])
10278
10279 ;; We don't have a straight 32-bit parallel multiply and extend on XOP, so
10280 ;; fake it with a multiply/add.  In general, we expect the define_split to
10281 ;; occur before register allocation, so we have to handle the corner case where
10282 ;; the target is the same as either operands[1] or operands[2]
10283 (define_insn_and_split "xop_mulv2div2di3_high"
10284   [(set (match_operand:V2DI 0 "register_operand" "=&x")
10285         (mult:V2DI
10286           (sign_extend:V2DI
10287             (vec_select:V2SI
10288               (match_operand:V4SI 1 "register_operand" "%x")
10289               (parallel [(const_int 0)
10290                          (const_int 2)])))
10291           (sign_extend:V2DI
10292             (vec_select:V2SI
10293               (match_operand:V4SI 2 "nonimmediate_operand" "xm")
10294               (parallel [(const_int 0)
10295                          (const_int 2)])))))]
10296   "TARGET_XOP"
10297   "#"
10298   "&& reload_completed"
10299   [(set (match_dup 0)
10300         (match_dup 3))
10301    (set (match_dup 0)
10302         (plus:V2DI
10303          (mult:V2DI
10304           (sign_extend:V2DI
10305            (vec_select:V2SI
10306             (match_dup 1)
10307             (parallel [(const_int 0)
10308                        (const_int 2)])))
10309           (sign_extend:V2DI
10310            (vec_select:V2SI
10311             (match_dup 2)
10312             (parallel [(const_int 0)
10313                        (const_int 2)]))))
10314          (match_dup 0)))]
10315 {
10316   operands[3] = CONST0_RTX (V2DImode);
10317 }
10318   [(set_attr "type" "ssemul")
10319    (set_attr "mode" "TI")])
10320
10321 ;; XOP parallel integer multiply/add instructions for the intrinisics
10322 (define_insn "xop_pmacsswd"
10323   [(set (match_operand:V4SI 0 "register_operand" "=x")
10324         (ss_plus:V4SI
10325          (mult:V4SI
10326           (sign_extend:V4SI
10327            (vec_select:V4HI
10328             (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10329             (parallel [(const_int 1)
10330                        (const_int 3)
10331                        (const_int 5)
10332                        (const_int 7)])))
10333           (sign_extend:V4SI
10334            (vec_select:V4HI
10335             (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10336             (parallel [(const_int 1)
10337                        (const_int 3)
10338                        (const_int 5)
10339                        (const_int 7)]))))
10340          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10341   "TARGET_XOP"
10342   "vpmacsswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10343   [(set_attr "type" "ssemuladd")
10344    (set_attr "mode" "TI")])
10345
10346 (define_insn "xop_pmacswd"
10347   [(set (match_operand:V4SI 0 "register_operand" "=x")
10348         (plus:V4SI
10349          (mult:V4SI
10350           (sign_extend:V4SI
10351            (vec_select:V4HI
10352             (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10353             (parallel [(const_int 1)
10354                        (const_int 3)
10355                        (const_int 5)
10356                        (const_int 7)])))
10357           (sign_extend:V4SI
10358            (vec_select:V4HI
10359             (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10360             (parallel [(const_int 1)
10361                        (const_int 3)
10362                        (const_int 5)
10363                        (const_int 7)]))))
10364          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10365   "TARGET_XOP"
10366   "vpmacswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10367   [(set_attr "type" "ssemuladd")
10368    (set_attr "mode" "TI")])
10369
10370 (define_insn "xop_pmadcsswd"
10371   [(set (match_operand:V4SI 0 "register_operand" "=x")
10372         (ss_plus:V4SI
10373          (plus:V4SI
10374           (mult:V4SI
10375            (sign_extend:V4SI
10376             (vec_select:V4HI
10377              (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10378              (parallel [(const_int 0)
10379                         (const_int 2)
10380                         (const_int 4)
10381                         (const_int 6)])))
10382            (sign_extend:V4SI
10383             (vec_select:V4HI
10384              (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10385              (parallel [(const_int 0)
10386                         (const_int 2)
10387                         (const_int 4)
10388                         (const_int 6)]))))
10389           (mult:V4SI
10390            (sign_extend:V4SI
10391             (vec_select:V4HI
10392              (match_dup 1)
10393              (parallel [(const_int 1)
10394                         (const_int 3)
10395                         (const_int 5)
10396                         (const_int 7)])))
10397            (sign_extend:V4SI
10398             (vec_select:V4HI
10399              (match_dup 2)
10400              (parallel [(const_int 1)
10401                         (const_int 3)
10402                         (const_int 5)
10403                         (const_int 7)])))))
10404          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10405   "TARGET_XOP"
10406   "vpmadcsswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10407   [(set_attr "type" "ssemuladd")
10408    (set_attr "mode" "TI")])
10409
10410 (define_insn "xop_pmadcswd"
10411   [(set (match_operand:V4SI 0 "register_operand" "=x")
10412         (plus:V4SI
10413          (plus:V4SI
10414           (mult:V4SI
10415            (sign_extend:V4SI
10416             (vec_select:V4HI
10417              (match_operand:V8HI 1 "nonimmediate_operand" "%x")
10418              (parallel [(const_int 0)
10419                         (const_int 2)
10420                         (const_int 4)
10421                         (const_int 6)])))
10422            (sign_extend:V4SI
10423             (vec_select:V4HI
10424              (match_operand:V8HI 2 "nonimmediate_operand" "xm")
10425              (parallel [(const_int 0)
10426                         (const_int 2)
10427                         (const_int 4)
10428                         (const_int 6)]))))
10429           (mult:V4SI
10430            (sign_extend:V4SI
10431             (vec_select:V4HI
10432              (match_dup 1)
10433              (parallel [(const_int 1)
10434                         (const_int 3)
10435                         (const_int 5)
10436                         (const_int 7)])))
10437            (sign_extend:V4SI
10438             (vec_select:V4HI
10439              (match_dup 2)
10440              (parallel [(const_int 1)
10441                         (const_int 3)
10442                         (const_int 5)
10443                         (const_int 7)])))))
10444          (match_operand:V4SI 3 "nonimmediate_operand" "x")))]
10445   "TARGET_XOP"
10446   "vpmadcswd\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10447   [(set_attr "type" "ssemuladd")
10448    (set_attr "mode" "TI")])
10449
10450 ;; XOP parallel XMM conditional moves
10451 (define_insn "xop_pcmov_<mode><avxsizesuffix>"
10452   [(set (match_operand:V 0 "register_operand" "=x,x")
10453         (if_then_else:V
10454           (match_operand:V 3 "nonimmediate_operand" "x,m")
10455           (match_operand:V 1 "vector_move_operand" "x,x")
10456           (match_operand:V 2 "vector_move_operand" "xm,x")))]
10457   "TARGET_XOP"
10458   "vpcmov\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10459   [(set_attr "type" "sse4arg")])
10460
10461 ;; XOP horizontal add/subtract instructions
10462 (define_insn "xop_phaddbw"
10463   [(set (match_operand:V8HI 0 "register_operand" "=x")
10464         (plus:V8HI
10465          (sign_extend:V8HI
10466           (vec_select:V8QI
10467            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10468            (parallel [(const_int 0)
10469                       (const_int 2)
10470                       (const_int 4)
10471                       (const_int 6)
10472                       (const_int 8)
10473                       (const_int 10)
10474                       (const_int 12)
10475                       (const_int 14)])))
10476          (sign_extend:V8HI
10477           (vec_select:V8QI
10478            (match_dup 1)
10479            (parallel [(const_int 1)
10480                       (const_int 3)
10481                       (const_int 5)
10482                       (const_int 7)
10483                       (const_int 9)
10484                       (const_int 11)
10485                       (const_int 13)
10486                       (const_int 15)])))))]
10487   "TARGET_XOP"
10488   "vphaddbw\t{%1, %0|%0, %1}"
10489   [(set_attr "type" "sseiadd1")])
10490
10491 (define_insn "xop_phaddbd"
10492   [(set (match_operand:V4SI 0 "register_operand" "=x")
10493         (plus:V4SI
10494          (plus:V4SI
10495           (sign_extend:V4SI
10496            (vec_select:V4QI
10497             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10498             (parallel [(const_int 0)
10499                        (const_int 4)
10500                        (const_int 8)
10501                        (const_int 12)])))
10502           (sign_extend:V4SI
10503            (vec_select:V4QI
10504             (match_dup 1)
10505             (parallel [(const_int 1)
10506                        (const_int 5)
10507                        (const_int 9)
10508                        (const_int 13)]))))
10509          (plus:V4SI
10510           (sign_extend:V4SI
10511            (vec_select:V4QI
10512             (match_dup 1)
10513             (parallel [(const_int 2)
10514                        (const_int 6)
10515                        (const_int 10)
10516                        (const_int 14)])))
10517           (sign_extend:V4SI
10518            (vec_select:V4QI
10519             (match_dup 1)
10520             (parallel [(const_int 3)
10521                        (const_int 7)
10522                        (const_int 11)
10523                        (const_int 15)]))))))]
10524   "TARGET_XOP"
10525   "vphaddbd\t{%1, %0|%0, %1}"
10526   [(set_attr "type" "sseiadd1")])
10527
10528 (define_insn "xop_phaddbq"
10529   [(set (match_operand:V2DI 0 "register_operand" "=x")
10530         (plus:V2DI
10531          (plus:V2DI
10532           (plus:V2DI
10533            (sign_extend:V2DI
10534             (vec_select:V2QI
10535              (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10536              (parallel [(const_int 0)
10537                         (const_int 4)])))
10538            (sign_extend:V2DI
10539             (vec_select:V2QI
10540              (match_dup 1)
10541              (parallel [(const_int 1)
10542                         (const_int 5)]))))
10543           (plus:V2DI
10544            (sign_extend:V2DI
10545             (vec_select:V2QI
10546              (match_dup 1)
10547              (parallel [(const_int 2)
10548                         (const_int 6)])))
10549            (sign_extend:V2DI
10550             (vec_select:V2QI
10551              (match_dup 1)
10552              (parallel [(const_int 3)
10553                         (const_int 7)])))))
10554          (plus:V2DI
10555           (plus:V2DI
10556            (sign_extend:V2DI
10557             (vec_select:V2QI
10558              (match_dup 1)
10559              (parallel [(const_int 8)
10560                         (const_int 12)])))
10561            (sign_extend:V2DI
10562             (vec_select:V2QI
10563              (match_dup 1)
10564              (parallel [(const_int 9)
10565                         (const_int 13)]))))
10566           (plus:V2DI
10567            (sign_extend:V2DI
10568             (vec_select:V2QI
10569              (match_dup 1)
10570              (parallel [(const_int 10)
10571                         (const_int 14)])))
10572            (sign_extend:V2DI
10573             (vec_select:V2QI
10574              (match_dup 1)
10575              (parallel [(const_int 11)
10576                         (const_int 15)])))))))]
10577   "TARGET_XOP"
10578   "vphaddbq\t{%1, %0|%0, %1}"
10579   [(set_attr "type" "sseiadd1")])
10580
10581 (define_insn "xop_phaddwd"
10582   [(set (match_operand:V4SI 0 "register_operand" "=x")
10583         (plus:V4SI
10584          (sign_extend:V4SI
10585           (vec_select:V4HI
10586            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10587            (parallel [(const_int 0)
10588                       (const_int 2)
10589                       (const_int 4)
10590                       (const_int 6)])))
10591          (sign_extend:V4SI
10592           (vec_select:V4HI
10593            (match_dup 1)
10594            (parallel [(const_int 1)
10595                       (const_int 3)
10596                       (const_int 5)
10597                       (const_int 7)])))))]
10598   "TARGET_XOP"
10599   "vphaddwd\t{%1, %0|%0, %1}"
10600   [(set_attr "type" "sseiadd1")])
10601
10602 (define_insn "xop_phaddwq"
10603   [(set (match_operand:V2DI 0 "register_operand" "=x")
10604         (plus:V2DI
10605          (plus:V2DI
10606           (sign_extend:V2DI
10607            (vec_select:V2HI
10608             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10609             (parallel [(const_int 0)
10610                        (const_int 4)])))
10611           (sign_extend:V2DI
10612            (vec_select:V2HI
10613             (match_dup 1)
10614             (parallel [(const_int 1)
10615                        (const_int 5)]))))
10616          (plus:V2DI
10617           (sign_extend:V2DI
10618            (vec_select:V2HI
10619             (match_dup 1)
10620             (parallel [(const_int 2)
10621                        (const_int 6)])))
10622           (sign_extend:V2DI
10623            (vec_select:V2HI
10624             (match_dup 1)
10625             (parallel [(const_int 3)
10626                        (const_int 7)]))))))]
10627   "TARGET_XOP"
10628   "vphaddwq\t{%1, %0|%0, %1}"
10629   [(set_attr "type" "sseiadd1")])
10630
10631 (define_insn "xop_phadddq"
10632   [(set (match_operand:V2DI 0 "register_operand" "=x")
10633         (plus:V2DI
10634          (sign_extend:V2DI
10635           (vec_select:V2SI
10636            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
10637            (parallel [(const_int 0)
10638                       (const_int 2)])))
10639          (sign_extend:V2DI
10640           (vec_select:V2SI
10641            (match_dup 1)
10642            (parallel [(const_int 1)
10643                       (const_int 3)])))))]
10644   "TARGET_XOP"
10645   "vphadddq\t{%1, %0|%0, %1}"
10646   [(set_attr "type" "sseiadd1")])
10647
10648 (define_insn "xop_phaddubw"
10649   [(set (match_operand:V8HI 0 "register_operand" "=x")
10650         (plus:V8HI
10651          (zero_extend:V8HI
10652           (vec_select:V8QI
10653            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10654            (parallel [(const_int 0)
10655                       (const_int 2)
10656                       (const_int 4)
10657                       (const_int 6)
10658                       (const_int 8)
10659                       (const_int 10)
10660                       (const_int 12)
10661                       (const_int 14)])))
10662          (zero_extend:V8HI
10663           (vec_select:V8QI
10664            (match_dup 1)
10665            (parallel [(const_int 1)
10666                       (const_int 3)
10667                       (const_int 5)
10668                       (const_int 7)
10669                       (const_int 9)
10670                       (const_int 11)
10671                       (const_int 13)
10672                       (const_int 15)])))))]
10673   "TARGET_XOP"
10674   "vphaddubw\t{%1, %0|%0, %1}"
10675   [(set_attr "type" "sseiadd1")])
10676
10677 (define_insn "xop_phaddubd"
10678   [(set (match_operand:V4SI 0 "register_operand" "=x")
10679         (plus:V4SI
10680          (plus:V4SI
10681           (zero_extend:V4SI
10682            (vec_select:V4QI
10683             (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10684             (parallel [(const_int 0)
10685                        (const_int 4)
10686                        (const_int 8)
10687                        (const_int 12)])))
10688           (zero_extend:V4SI
10689            (vec_select:V4QI
10690             (match_dup 1)
10691             (parallel [(const_int 1)
10692                        (const_int 5)
10693                        (const_int 9)
10694                        (const_int 13)]))))
10695          (plus:V4SI
10696           (zero_extend:V4SI
10697            (vec_select:V4QI
10698             (match_dup 1)
10699             (parallel [(const_int 2)
10700                        (const_int 6)
10701                        (const_int 10)
10702                        (const_int 14)])))
10703           (zero_extend:V4SI
10704            (vec_select:V4QI
10705             (match_dup 1)
10706             (parallel [(const_int 3)
10707                        (const_int 7)
10708                        (const_int 11)
10709                        (const_int 15)]))))))]
10710   "TARGET_XOP"
10711   "vphaddubd\t{%1, %0|%0, %1}"
10712   [(set_attr "type" "sseiadd1")])
10713
10714 (define_insn "xop_phaddubq"
10715   [(set (match_operand:V2DI 0 "register_operand" "=x")
10716         (plus:V2DI
10717          (plus:V2DI
10718           (plus:V2DI
10719            (zero_extend:V2DI
10720             (vec_select:V2QI
10721              (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10722              (parallel [(const_int 0)
10723                         (const_int 4)])))
10724            (sign_extend:V2DI
10725             (vec_select:V2QI
10726              (match_dup 1)
10727              (parallel [(const_int 1)
10728                         (const_int 5)]))))
10729           (plus:V2DI
10730            (zero_extend:V2DI
10731             (vec_select:V2QI
10732              (match_dup 1)
10733              (parallel [(const_int 2)
10734                         (const_int 6)])))
10735            (zero_extend:V2DI
10736             (vec_select:V2QI
10737              (match_dup 1)
10738              (parallel [(const_int 3)
10739                         (const_int 7)])))))
10740          (plus:V2DI
10741           (plus:V2DI
10742            (zero_extend:V2DI
10743             (vec_select:V2QI
10744              (match_dup 1)
10745              (parallel [(const_int 8)
10746                         (const_int 12)])))
10747            (sign_extend:V2DI
10748             (vec_select:V2QI
10749              (match_dup 1)
10750              (parallel [(const_int 9)
10751                         (const_int 13)]))))
10752           (plus:V2DI
10753            (zero_extend:V2DI
10754             (vec_select:V2QI
10755              (match_dup 1)
10756              (parallel [(const_int 10)
10757                         (const_int 14)])))
10758            (zero_extend:V2DI
10759             (vec_select:V2QI
10760              (match_dup 1)
10761              (parallel [(const_int 11)
10762                         (const_int 15)])))))))]
10763   "TARGET_XOP"
10764   "vphaddubq\t{%1, %0|%0, %1}"
10765   [(set_attr "type" "sseiadd1")])
10766
10767 (define_insn "xop_phadduwd"
10768   [(set (match_operand:V4SI 0 "register_operand" "=x")
10769         (plus:V4SI
10770          (zero_extend:V4SI
10771           (vec_select:V4HI
10772            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10773            (parallel [(const_int 0)
10774                       (const_int 2)
10775                       (const_int 4)
10776                       (const_int 6)])))
10777          (zero_extend:V4SI
10778           (vec_select:V4HI
10779            (match_dup 1)
10780            (parallel [(const_int 1)
10781                       (const_int 3)
10782                       (const_int 5)
10783                       (const_int 7)])))))]
10784   "TARGET_XOP"
10785   "vphadduwd\t{%1, %0|%0, %1}"
10786   [(set_attr "type" "sseiadd1")])
10787
10788 (define_insn "xop_phadduwq"
10789   [(set (match_operand:V2DI 0 "register_operand" "=x")
10790         (plus:V2DI
10791          (plus:V2DI
10792           (zero_extend:V2DI
10793            (vec_select:V2HI
10794             (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10795             (parallel [(const_int 0)
10796                        (const_int 4)])))
10797           (zero_extend:V2DI
10798            (vec_select:V2HI
10799             (match_dup 1)
10800             (parallel [(const_int 1)
10801                        (const_int 5)]))))
10802          (plus:V2DI
10803           (zero_extend:V2DI
10804            (vec_select:V2HI
10805             (match_dup 1)
10806             (parallel [(const_int 2)
10807                        (const_int 6)])))
10808           (zero_extend:V2DI
10809            (vec_select:V2HI
10810             (match_dup 1)
10811             (parallel [(const_int 3)
10812                        (const_int 7)]))))))]
10813   "TARGET_XOP"
10814   "vphadduwq\t{%1, %0|%0, %1}"
10815   [(set_attr "type" "sseiadd1")])
10816
10817 (define_insn "xop_phaddudq"
10818   [(set (match_operand:V2DI 0 "register_operand" "=x")
10819         (plus:V2DI
10820          (zero_extend:V2DI
10821           (vec_select:V2SI
10822            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
10823            (parallel [(const_int 0)
10824                       (const_int 2)])))
10825          (zero_extend:V2DI
10826           (vec_select:V2SI
10827            (match_dup 1)
10828            (parallel [(const_int 1)
10829                       (const_int 3)])))))]
10830   "TARGET_XOP"
10831   "vphaddudq\t{%1, %0|%0, %1}"
10832   [(set_attr "type" "sseiadd1")])
10833
10834 (define_insn "xop_phsubbw"
10835   [(set (match_operand:V8HI 0 "register_operand" "=x")
10836         (minus:V8HI
10837          (sign_extend:V8HI
10838           (vec_select:V8QI
10839            (match_operand:V16QI 1 "nonimmediate_operand" "xm")
10840            (parallel [(const_int 0)
10841                       (const_int 2)
10842                       (const_int 4)
10843                       (const_int 6)
10844                       (const_int 8)
10845                       (const_int 10)
10846                       (const_int 12)
10847                       (const_int 14)])))
10848          (sign_extend:V8HI
10849           (vec_select:V8QI
10850            (match_dup 1)
10851            (parallel [(const_int 1)
10852                       (const_int 3)
10853                       (const_int 5)
10854                       (const_int 7)
10855                       (const_int 9)
10856                       (const_int 11)
10857                       (const_int 13)
10858                       (const_int 15)])))))]
10859   "TARGET_XOP"
10860   "vphsubbw\t{%1, %0|%0, %1}"
10861   [(set_attr "type" "sseiadd1")])
10862
10863 (define_insn "xop_phsubwd"
10864   [(set (match_operand:V4SI 0 "register_operand" "=x")
10865         (minus:V4SI
10866          (sign_extend:V4SI
10867           (vec_select:V4HI
10868            (match_operand:V8HI 1 "nonimmediate_operand" "xm")
10869            (parallel [(const_int 0)
10870                       (const_int 2)
10871                       (const_int 4)
10872                       (const_int 6)])))
10873          (sign_extend:V4SI
10874           (vec_select:V4HI
10875            (match_dup 1)
10876            (parallel [(const_int 1)
10877                       (const_int 3)
10878                       (const_int 5)
10879                       (const_int 7)])))))]
10880   "TARGET_XOP"
10881   "vphsubwd\t{%1, %0|%0, %1}"
10882   [(set_attr "type" "sseiadd1")])
10883
10884 (define_insn "xop_phsubdq"
10885   [(set (match_operand:V2DI 0 "register_operand" "=x")
10886         (minus:V2DI
10887          (sign_extend:V2DI
10888           (vec_select:V2SI
10889            (match_operand:V4SI 1 "nonimmediate_operand" "xm")
10890            (parallel [(const_int 0)
10891                       (const_int 2)])))
10892          (sign_extend:V2DI
10893           (vec_select:V2SI
10894            (match_dup 1)
10895            (parallel [(const_int 1)
10896                       (const_int 3)])))))]
10897   "TARGET_XOP"
10898   "vphsubdq\t{%1, %0|%0, %1}"
10899   [(set_attr "type" "sseiadd1")])
10900
10901 ;; XOP permute instructions
10902 (define_insn "xop_pperm"
10903   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
10904         (unspec:V16QI
10905           [(match_operand:V16QI 1 "register_operand" "x,x")
10906            (match_operand:V16QI 2 "nonimmediate_operand" "x,m")
10907            (match_operand:V16QI 3 "nonimmediate_operand" "xm,x")]
10908           UNSPEC_XOP_PERMUTE))]
10909   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
10910   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10911   [(set_attr "type" "sse4arg")
10912    (set_attr "mode" "TI")])
10913
10914 ;; XOP pack instructions that combine two vectors into a smaller vector
10915 (define_insn "xop_pperm_pack_v2di_v4si"
10916   [(set (match_operand:V4SI 0 "register_operand" "=x,x")
10917         (vec_concat:V4SI
10918          (truncate:V2SI
10919           (match_operand:V2DI 1 "register_operand" "x,x"))
10920          (truncate:V2SI
10921           (match_operand:V2DI 2 "nonimmediate_operand" "x,m"))))
10922    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
10923   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
10924   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10925   [(set_attr "type" "sse4arg")
10926    (set_attr "mode" "TI")])
10927
10928 (define_insn "xop_pperm_pack_v4si_v8hi"
10929   [(set (match_operand:V8HI 0 "register_operand" "=x,x")
10930         (vec_concat:V8HI
10931          (truncate:V4HI
10932           (match_operand:V4SI 1 "register_operand" "x,x"))
10933          (truncate:V4HI
10934           (match_operand:V4SI 2 "nonimmediate_operand" "x,m"))))
10935    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
10936   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
10937   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10938   [(set_attr "type" "sse4arg")
10939    (set_attr "mode" "TI")])
10940
10941 (define_insn "xop_pperm_pack_v8hi_v16qi"
10942   [(set (match_operand:V16QI 0 "register_operand" "=x,x")
10943         (vec_concat:V16QI
10944          (truncate:V8QI
10945           (match_operand:V8HI 1 "register_operand" "x,x"))
10946          (truncate:V8QI
10947           (match_operand:V8HI 2 "nonimmediate_operand" "x,m"))))
10948    (use (match_operand:V16QI 3 "nonimmediate_operand" "xm,x"))]
10949   "TARGET_XOP && !(MEM_P (operands[2]) && MEM_P (operands[3]))"
10950   "vpperm\t{%3, %2, %1, %0|%0, %1, %2, %3}"
10951   [(set_attr "type" "sse4arg")
10952    (set_attr "mode" "TI")])
10953
10954 ;; XOP packed rotate instructions
10955 (define_expand "rotl<mode>3"
10956   [(set (match_operand:VI_128 0 "register_operand" "")
10957         (rotate:VI_128
10958          (match_operand:VI_128 1 "nonimmediate_operand" "")
10959          (match_operand:SI 2 "general_operand")))]
10960   "TARGET_XOP"
10961 {
10962   /* If we were given a scalar, convert it to parallel */
10963   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
10964     {
10965       rtvec vs = rtvec_alloc (<ssescalarnum>);
10966       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
10967       rtx reg = gen_reg_rtx (<MODE>mode);
10968       rtx op2 = operands[2];
10969       int i;
10970
10971       if (GET_MODE (op2) != <ssescalarmode>mode)
10972         {
10973           op2 = gen_reg_rtx (<ssescalarmode>mode);
10974           convert_move (op2, operands[2], false);
10975         }
10976
10977       for (i = 0; i < <ssescalarnum>; i++)
10978         RTVEC_ELT (vs, i) = op2;
10979
10980       emit_insn (gen_vec_init<mode> (reg, par));
10981       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
10982       DONE;
10983     }
10984 })
10985
10986 (define_expand "rotr<mode>3"
10987   [(set (match_operand:VI_128 0 "register_operand" "")
10988         (rotatert:VI_128
10989          (match_operand:VI_128 1 "nonimmediate_operand" "")
10990          (match_operand:SI 2 "general_operand")))]
10991   "TARGET_XOP"
10992 {
10993   /* If we were given a scalar, convert it to parallel */
10994   if (! const_0_to_<sserotatemax>_operand (operands[2], SImode))
10995     {
10996       rtvec vs = rtvec_alloc (<ssescalarnum>);
10997       rtx par = gen_rtx_PARALLEL (<MODE>mode, vs);
10998       rtx neg = gen_reg_rtx (<MODE>mode);
10999       rtx reg = gen_reg_rtx (<MODE>mode);
11000       rtx op2 = operands[2];
11001       int i;
11002
11003       if (GET_MODE (op2) != <ssescalarmode>mode)
11004         {
11005           op2 = gen_reg_rtx (<ssescalarmode>mode);
11006           convert_move (op2, operands[2], false);
11007         }
11008
11009       for (i = 0; i < <ssescalarnum>; i++)
11010         RTVEC_ELT (vs, i) = op2;
11011
11012       emit_insn (gen_vec_init<mode> (reg, par));
11013       emit_insn (gen_neg<mode>2 (neg, reg));
11014       emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], neg));
11015       DONE;
11016     }
11017 })
11018
11019 (define_insn "xop_rotl<mode>3"
11020   [(set (match_operand:VI_128 0 "register_operand" "=x")
11021         (rotate:VI_128
11022          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
11023          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
11024   "TARGET_XOP"
11025   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11026   [(set_attr "type" "sseishft")
11027    (set_attr "length_immediate" "1")
11028    (set_attr "mode" "TI")])
11029
11030 (define_insn "xop_rotr<mode>3"
11031   [(set (match_operand:VI_128 0 "register_operand" "=x")
11032         (rotatert:VI_128
11033          (match_operand:VI_128 1 "nonimmediate_operand" "xm")
11034          (match_operand:SI 2 "const_0_to_<sserotatemax>_operand" "n")))]
11035   "TARGET_XOP"
11036 {
11037   operands[3] = GEN_INT ((<ssescalarnum> * 8) - INTVAL (operands[2]));
11038   return \"vprot<ssemodesuffix>\t{%3, %1, %0|%0, %1, %3}\";
11039 }
11040   [(set_attr "type" "sseishft")
11041    (set_attr "length_immediate" "1")
11042    (set_attr "mode" "TI")])
11043
11044 (define_expand "vrotr<mode>3"
11045   [(match_operand:VI_128 0 "register_operand" "")
11046    (match_operand:VI_128 1 "register_operand" "")
11047    (match_operand:VI_128 2 "register_operand" "")]
11048   "TARGET_XOP"
11049 {
11050   rtx reg = gen_reg_rtx (<MODE>mode);
11051   emit_insn (gen_neg<mode>2 (reg, operands[2]));
11052   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], reg));
11053   DONE;
11054 })
11055
11056 (define_expand "vrotl<mode>3"
11057   [(match_operand:VI_128 0 "register_operand" "")
11058    (match_operand:VI_128 1 "register_operand" "")
11059    (match_operand:VI_128 2 "register_operand" "")]
11060   "TARGET_XOP"
11061 {
11062   emit_insn (gen_xop_vrotl<mode>3 (operands[0], operands[1], operands[2]));
11063   DONE;
11064 })
11065
11066 (define_insn "xop_vrotl<mode>3"
11067   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
11068         (if_then_else:VI_128
11069          (ge:VI_128
11070           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
11071           (const_int 0))
11072          (rotate:VI_128
11073           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
11074           (match_dup 2))
11075          (rotatert:VI_128
11076           (match_dup 1)
11077           (neg:VI_128 (match_dup 2)))))]
11078   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
11079   "vprot<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11080   [(set_attr "type" "sseishft")
11081    (set_attr "prefix_data16" "0")
11082    (set_attr "prefix_extra" "2")
11083    (set_attr "mode" "TI")])
11084
11085 ;; XOP packed shift instructions.
11086 ;; FIXME: add V2DI back in
11087 (define_expand "vlshr<mode>3"
11088   [(match_operand:VI124_128 0 "register_operand" "")
11089    (match_operand:VI124_128 1 "register_operand" "")
11090    (match_operand:VI124_128 2 "register_operand" "")]
11091   "TARGET_XOP"
11092 {
11093   rtx neg = gen_reg_rtx (<MODE>mode);
11094   emit_insn (gen_neg<mode>2 (neg, operands[2]));
11095   emit_insn (gen_xop_lshl<mode>3 (operands[0], operands[1], neg));
11096   DONE;
11097 })
11098
11099 (define_expand "vashr<mode>3"
11100   [(match_operand:VI124_128 0 "register_operand" "")
11101    (match_operand:VI124_128 1 "register_operand" "")
11102    (match_operand:VI124_128 2 "register_operand" "")]
11103   "TARGET_XOP"
11104 {
11105   rtx neg = gen_reg_rtx (<MODE>mode);
11106   emit_insn (gen_neg<mode>2 (neg, operands[2]));
11107   emit_insn (gen_xop_ashl<mode>3 (operands[0], operands[1], neg));
11108   DONE;
11109 })
11110
11111 (define_expand "vashl<mode>3"
11112   [(match_operand:VI124_128 0 "register_operand" "")
11113    (match_operand:VI124_128 1 "register_operand" "")
11114    (match_operand:VI124_128 2 "register_operand" "")]
11115   "TARGET_XOP"
11116 {
11117   emit_insn (gen_xop_ashl<mode>3 (operands[0], operands[1], operands[2]));
11118   DONE;
11119 })
11120
11121 (define_insn "xop_ashl<mode>3"
11122   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
11123         (if_then_else:VI_128
11124          (ge:VI_128
11125           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
11126           (const_int 0))
11127          (ashift:VI_128
11128           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
11129           (match_dup 2))
11130          (ashiftrt:VI_128
11131           (match_dup 1)
11132           (neg:VI_128 (match_dup 2)))))]
11133   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
11134   "vpsha<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11135   [(set_attr "type" "sseishft")
11136    (set_attr "prefix_data16" "0")
11137    (set_attr "prefix_extra" "2")
11138    (set_attr "mode" "TI")])
11139
11140 (define_insn "xop_lshl<mode>3"
11141   [(set (match_operand:VI_128 0 "register_operand" "=x,x")
11142         (if_then_else:VI_128
11143          (ge:VI_128
11144           (match_operand:VI_128 2 "nonimmediate_operand" "x,m")
11145           (const_int 0))
11146          (ashift:VI_128
11147           (match_operand:VI_128 1 "nonimmediate_operand" "xm,x")
11148           (match_dup 2))
11149          (lshiftrt:VI_128
11150           (match_dup 1)
11151           (neg:VI_128 (match_dup 2)))))]
11152   "TARGET_XOP && !(MEM_P (operands[1]) && MEM_P (operands[2]))"
11153   "vpshl<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11154   [(set_attr "type" "sseishft")
11155    (set_attr "prefix_data16" "0")
11156    (set_attr "prefix_extra" "2")
11157    (set_attr "mode" "TI")])
11158
11159 ;; SSE2 doesn't have some shift varients, so define versions for XOP
11160 (define_expand "ashlv16qi3"
11161   [(match_operand:V16QI 0 "register_operand" "")
11162    (match_operand:V16QI 1 "register_operand" "")
11163    (match_operand:SI 2 "nonmemory_operand" "")]
11164   "TARGET_XOP"
11165 {
11166   rtvec vs = rtvec_alloc (16);
11167   rtx par = gen_rtx_PARALLEL (V16QImode, vs);
11168   rtx reg = gen_reg_rtx (V16QImode);
11169   int i;
11170   for (i = 0; i < 16; i++)
11171     RTVEC_ELT (vs, i) = operands[2];
11172
11173   emit_insn (gen_vec_initv16qi (reg, par));
11174   emit_insn (gen_xop_ashlv16qi3 (operands[0], operands[1], reg));
11175   DONE;
11176 })
11177
11178 (define_expand "lshlv16qi3"
11179   [(match_operand:V16QI 0 "register_operand" "")
11180    (match_operand:V16QI 1 "register_operand" "")
11181    (match_operand:SI 2 "nonmemory_operand" "")]
11182   "TARGET_XOP"
11183 {
11184   rtvec vs = rtvec_alloc (16);
11185   rtx par = gen_rtx_PARALLEL (V16QImode, vs);
11186   rtx reg = gen_reg_rtx (V16QImode);
11187   int i;
11188   for (i = 0; i < 16; i++)
11189     RTVEC_ELT (vs, i) = operands[2];
11190
11191   emit_insn (gen_vec_initv16qi (reg, par));
11192   emit_insn (gen_xop_lshlv16qi3 (operands[0], operands[1], reg));
11193   DONE;
11194 })
11195
11196 (define_expand "ashrv16qi3"
11197   [(match_operand:V16QI 0 "register_operand" "")
11198    (match_operand:V16QI 1 "register_operand" "")
11199    (match_operand:SI 2 "nonmemory_operand" "")]
11200   "TARGET_XOP"
11201 {
11202   rtvec vs = rtvec_alloc (16);
11203   rtx par = gen_rtx_PARALLEL (V16QImode, vs);
11204   rtx reg = gen_reg_rtx (V16QImode);
11205   int i;
11206   rtx ele = ((CONST_INT_P (operands[2]))
11207              ? GEN_INT (- INTVAL (operands[2]))
11208              : operands[2]);
11209
11210   for (i = 0; i < 16; i++)
11211     RTVEC_ELT (vs, i) = ele;
11212
11213   emit_insn (gen_vec_initv16qi (reg, par));
11214
11215   if (!CONST_INT_P (operands[2]))
11216     {
11217       rtx neg = gen_reg_rtx (V16QImode);
11218       emit_insn (gen_negv16qi2 (neg, reg));
11219       emit_insn (gen_xop_ashlv16qi3 (operands[0], operands[1], neg));
11220     }
11221   else
11222     emit_insn (gen_xop_ashlv16qi3 (operands[0], operands[1], reg));
11223
11224   DONE;
11225 })
11226
11227 (define_expand "ashrv2di3"
11228   [(match_operand:V2DI 0 "register_operand" "")
11229    (match_operand:V2DI 1 "register_operand" "")
11230    (match_operand:DI 2 "nonmemory_operand" "")]
11231   "TARGET_XOP"
11232 {
11233   rtvec vs = rtvec_alloc (2);
11234   rtx par = gen_rtx_PARALLEL (V2DImode, vs);
11235   rtx reg = gen_reg_rtx (V2DImode);
11236   rtx ele;
11237
11238   if (CONST_INT_P (operands[2]))
11239     ele = GEN_INT (- INTVAL (operands[2]));
11240   else if (GET_MODE (operands[2]) != DImode)
11241     {
11242       rtx move = gen_reg_rtx (DImode);
11243       ele = gen_reg_rtx (DImode);
11244       convert_move (move, operands[2], false);
11245       emit_insn (gen_negdi2 (ele, move));
11246     }
11247   else
11248     {
11249       ele = gen_reg_rtx (DImode);
11250       emit_insn (gen_negdi2 (ele, operands[2]));
11251     }
11252
11253   RTVEC_ELT (vs, 0) = ele;
11254   RTVEC_ELT (vs, 1) = ele;
11255   emit_insn (gen_vec_initv2di (reg, par));
11256   emit_insn (gen_xop_ashlv2di3 (operands[0], operands[1], reg));
11257   DONE;
11258 })
11259
11260 ;; XOP FRCZ support
11261 (define_insn "xop_frcz<mode>2"
11262   [(set (match_operand:FMAMODE 0 "register_operand" "=x")
11263         (unspec:FMAMODE
11264          [(match_operand:FMAMODE 1 "nonimmediate_operand" "xm")]
11265          UNSPEC_FRCZ))]
11266   "TARGET_XOP"
11267   "vfrcz<ssemodesuffix>\t{%1, %0|%0, %1}"
11268   [(set_attr "type" "ssecvt1")
11269    (set_attr "mode" "<MODE>")])
11270
11271 ;; scalar insns
11272 (define_expand "xop_vmfrcz<mode>2"
11273   [(set (match_operand:VF_128 0 "register_operand")
11274         (vec_merge:VF_128
11275           (unspec:VF_128
11276            [(match_operand:VF_128 1 "nonimmediate_operand")]
11277            UNSPEC_FRCZ)
11278           (match_dup 3)
11279           (const_int 1)))]
11280   "TARGET_XOP"
11281 {
11282   operands[3] = CONST0_RTX (<MODE>mode);
11283 })
11284
11285 (define_insn "*xop_vmfrcz_<mode>"
11286   [(set (match_operand:VF_128 0 "register_operand" "=x")
11287         (vec_merge:VF_128
11288           (unspec:VF_128
11289            [(match_operand:VF_128 1 "nonimmediate_operand" "xm")]
11290            UNSPEC_FRCZ)
11291           (match_operand:VF_128 2 "const0_operand")
11292           (const_int 1)))]
11293   "TARGET_XOP"
11294   "vfrcz<ssescalarmodesuffix>\t{%1, %0|%0, %1}"
11295   [(set_attr "type" "ssecvt1")
11296    (set_attr "mode" "<MODE>")])
11297
11298 (define_insn "xop_maskcmp<mode>3"
11299   [(set (match_operand:VI_128 0 "register_operand" "=x")
11300         (match_operator:VI_128 1 "ix86_comparison_int_operator"
11301          [(match_operand:VI_128 2 "register_operand" "x")
11302           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
11303   "TARGET_XOP"
11304   "vpcom%Y1<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
11305   [(set_attr "type" "sse4arg")
11306    (set_attr "prefix_data16" "0")
11307    (set_attr "prefix_rep" "0")
11308    (set_attr "prefix_extra" "2")
11309    (set_attr "length_immediate" "1")
11310    (set_attr "mode" "TI")])
11311
11312 (define_insn "xop_maskcmp_uns<mode>3"
11313   [(set (match_operand:VI_128 0 "register_operand" "=x")
11314         (match_operator:VI_128 1 "ix86_comparison_uns_operator"
11315          [(match_operand:VI_128 2 "register_operand" "x")
11316           (match_operand:VI_128 3 "nonimmediate_operand" "xm")]))]
11317   "TARGET_XOP"
11318   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
11319   [(set_attr "type" "ssecmp")
11320    (set_attr "prefix_data16" "0")
11321    (set_attr "prefix_rep" "0")
11322    (set_attr "prefix_extra" "2")
11323    (set_attr "length_immediate" "1")
11324    (set_attr "mode" "TI")])
11325
11326 ;; Version of pcom*u* that is called from the intrinsics that allows pcomequ*
11327 ;; and pcomneu* not to be converted to the signed ones in case somebody needs
11328 ;; the exact instruction generated for the intrinsic.
11329 (define_insn "xop_maskcmp_uns2<mode>3"
11330   [(set (match_operand:VI_128 0 "register_operand" "=x")
11331         (unspec:VI_128
11332          [(match_operator:VI_128 1 "ix86_comparison_uns_operator"
11333           [(match_operand:VI_128 2 "register_operand" "x")
11334            (match_operand:VI_128 3 "nonimmediate_operand" "xm")])]
11335          UNSPEC_XOP_UNSIGNED_CMP))]
11336   "TARGET_XOP"
11337   "vpcom%Y1u<ssemodesuffix>\t{%3, %2, %0|%0, %2, %3}"
11338   [(set_attr "type" "ssecmp")
11339    (set_attr "prefix_data16" "0")
11340    (set_attr "prefix_extra" "2")
11341    (set_attr "length_immediate" "1")
11342    (set_attr "mode" "TI")])
11343
11344 ;; Pcomtrue and pcomfalse support.  These are useless instructions, but are
11345 ;; being added here to be complete.
11346 (define_insn "xop_pcom_tf<mode>3"
11347   [(set (match_operand:VI_128 0 "register_operand" "=x")
11348         (unspec:VI_128
11349           [(match_operand:VI_128 1 "register_operand" "x")
11350            (match_operand:VI_128 2 "nonimmediate_operand" "xm")
11351            (match_operand:SI 3 "const_int_operand" "n")]
11352           UNSPEC_XOP_TRUEFALSE))]
11353   "TARGET_XOP"
11354 {
11355   return ((INTVAL (operands[3]) != 0)
11356           ? "vpcomtrue<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11357           : "vpcomfalse<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}");
11358 }
11359   [(set_attr "type" "ssecmp")
11360    (set_attr "prefix_data16" "0")
11361    (set_attr "prefix_extra" "2")
11362    (set_attr "length_immediate" "1")
11363    (set_attr "mode" "TI")])
11364
11365 (define_insn "xop_vpermil2<mode>3"
11366   [(set (match_operand:VF 0 "register_operand" "=x")
11367         (unspec:VF
11368           [(match_operand:VF 1 "register_operand" "x")
11369            (match_operand:VF 2 "nonimmediate_operand" "%x")
11370            (match_operand:<sseintvecmode> 3 "nonimmediate_operand" "xm")
11371            (match_operand:SI 4 "const_0_to_3_operand" "n")]
11372           UNSPEC_VPERMIL2))]
11373   "TARGET_XOP"
11374   "vpermil2<ssemodesuffix>\t{%4, %3, %2, %1, %0|%0, %1, %2, %3, %4}"
11375   [(set_attr "type" "sse4arg")
11376    (set_attr "length_immediate" "1")
11377    (set_attr "mode" "<MODE>")])
11378
11379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11380
11381 (define_insn "aesenc"
11382   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11383         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11384                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11385                       UNSPEC_AESENC))]
11386   "TARGET_AES"
11387   "@
11388    aesenc\t{%2, %0|%0, %2}
11389    vaesenc\t{%2, %1, %0|%0, %1, %2}"
11390   [(set_attr "isa" "noavx,avx")
11391    (set_attr "type" "sselog1")
11392    (set_attr "prefix_extra" "1")
11393    (set_attr "prefix" "orig,vex")
11394    (set_attr "mode" "TI")])
11395
11396 (define_insn "aesenclast"
11397   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11398         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11399                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11400                       UNSPEC_AESENCLAST))]
11401   "TARGET_AES"
11402   "@
11403    aesenclast\t{%2, %0|%0, %2}
11404    vaesenclast\t{%2, %1, %0|%0, %1, %2}"
11405   [(set_attr "isa" "noavx,avx")
11406    (set_attr "type" "sselog1")
11407    (set_attr "prefix_extra" "1")
11408    (set_attr "prefix" "orig,vex")
11409    (set_attr "mode" "TI")])
11410
11411 (define_insn "aesdec"
11412   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11413         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11414                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11415                       UNSPEC_AESDEC))]
11416   "TARGET_AES"
11417   "@
11418    aesdec\t{%2, %0|%0, %2}
11419    vaesdec\t{%2, %1, %0|%0, %1, %2}"
11420   [(set_attr "isa" "noavx,avx")
11421    (set_attr "type" "sselog1")
11422    (set_attr "prefix_extra" "1")
11423    (set_attr "prefix" "orig,vex")
11424    (set_attr "mode" "TI")])
11425
11426 (define_insn "aesdeclast"
11427   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11428         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11429                        (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")]
11430                       UNSPEC_AESDECLAST))]
11431   "TARGET_AES"
11432   "@
11433    aesdeclast\t{%2, %0|%0, %2}
11434    vaesdeclast\t{%2, %1, %0|%0, %1, %2}"
11435   [(set_attr "isa" "noavx,avx")
11436    (set_attr "type" "sselog1")
11437    (set_attr "prefix_extra" "1")
11438    (set_attr "prefix" "orig,vex")
11439    (set_attr "mode" "TI")])
11440
11441 (define_insn "aesimc"
11442   [(set (match_operand:V2DI 0 "register_operand" "=x")
11443         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")]
11444                       UNSPEC_AESIMC))]
11445   "TARGET_AES"
11446   "%vaesimc\t{%1, %0|%0, %1}"
11447   [(set_attr "type" "sselog1")
11448    (set_attr "prefix_extra" "1")
11449    (set_attr "prefix" "maybe_vex")
11450    (set_attr "mode" "TI")])
11451
11452 (define_insn "aeskeygenassist"
11453   [(set (match_operand:V2DI 0 "register_operand" "=x")
11454         (unspec:V2DI [(match_operand:V2DI 1 "nonimmediate_operand" "xm")
11455                       (match_operand:SI 2 "const_0_to_255_operand" "n")]
11456                      UNSPEC_AESKEYGENASSIST))]
11457   "TARGET_AES"
11458   "%vaeskeygenassist\t{%2, %1, %0|%0, %1, %2}"
11459   [(set_attr "type" "sselog1")
11460    (set_attr "prefix_extra" "1")
11461    (set_attr "length_immediate" "1")
11462    (set_attr "prefix" "maybe_vex")
11463    (set_attr "mode" "TI")])
11464
11465 (define_insn "pclmulqdq"
11466   [(set (match_operand:V2DI 0 "register_operand" "=x,x")
11467         (unspec:V2DI [(match_operand:V2DI 1 "register_operand" "0,x")
11468                       (match_operand:V2DI 2 "nonimmediate_operand" "xm,xm")
11469                       (match_operand:SI 3 "const_0_to_255_operand" "n,n")]
11470                      UNSPEC_PCLMUL))]
11471   "TARGET_PCLMUL"
11472   "@
11473    pclmulqdq\t{%3, %2, %0|%0, %2, %3}
11474    vpclmulqdq\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11475   [(set_attr "isa" "noavx,avx")
11476    (set_attr "type" "sselog1")
11477    (set_attr "prefix_extra" "1")
11478    (set_attr "length_immediate" "1")
11479    (set_attr "prefix" "orig,vex")
11480    (set_attr "mode" "TI")])
11481
11482 (define_expand "avx_vzeroall"
11483   [(match_par_dup 0 [(const_int 0)])]
11484   "TARGET_AVX"
11485 {
11486   int nregs = TARGET_64BIT ? 16 : 8;
11487   int regno;
11488
11489   operands[0] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (nregs + 1));
11490
11491   XVECEXP (operands[0], 0, 0)
11492     = gen_rtx_UNSPEC_VOLATILE (VOIDmode, gen_rtvec (1, const0_rtx),
11493                                UNSPECV_VZEROALL);
11494
11495   for (regno = 0; regno < nregs; regno++)
11496     XVECEXP (operands[0], 0, regno + 1)
11497       = gen_rtx_SET (VOIDmode,
11498                      gen_rtx_REG (V8SImode, SSE_REGNO (regno)),
11499                      CONST0_RTX (V8SImode));
11500 })
11501
11502 (define_insn "*avx_vzeroall"
11503   [(match_parallel 0 "vzeroall_operation"
11504     [(unspec_volatile [(const_int 0)] UNSPECV_VZEROALL)])]
11505   "TARGET_AVX"
11506   "vzeroall"
11507   [(set_attr "type" "sse")
11508    (set_attr "modrm" "0")
11509    (set_attr "memory" "none")
11510    (set_attr "prefix" "vex")
11511    (set_attr "mode" "OI")])
11512
11513 ;; Clear the upper 128bits of AVX registers, equivalent to a NOP
11514 ;; if the upper 128bits are unused.
11515 (define_insn "avx_vzeroupper"
11516   [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
11517                     UNSPECV_VZEROUPPER)]
11518   "TARGET_AVX"
11519   "vzeroupper"
11520   [(set_attr "type" "sse")
11521    (set_attr "modrm" "0")
11522    (set_attr "memory" "none")
11523    (set_attr "prefix" "vex")
11524    (set_attr "mode" "OI")])
11525
11526 (define_mode_attr AVXTOSSEMODE
11527   [(V4DI "V2DI") (V2DI "V2DI")
11528    (V8SI "V4SI") (V4SI "V4SI")
11529    (V16HI "V8HI") (V8HI "V8HI")
11530    (V32QI "V16QI") (V16QI "V16QI")])
11531
11532 (define_insn "avx2_pbroadcast<mode>"
11533   [(set (match_operand:VI 0 "register_operand" "=x")
11534         (vec_duplicate:VI
11535           (vec_select:<ssescalarmode>
11536             (match_operand:<AVXTOSSEMODE> 1 "nonimmediate_operand" "xm")
11537             (parallel [(const_int 0)]))))]
11538   "TARGET_AVX2"
11539   "vpbroadcast<ssemodesuffix>\t{%1, %0|%0, %1}"
11540   [(set_attr "type" "ssemov")
11541    (set_attr "prefix_extra" "1")
11542    (set_attr "prefix" "vex")
11543    (set_attr "mode" "<sseinsnmode>")])
11544
11545 (define_insn "avx2_permvarv8si"
11546   [(set (match_operand:V8SI 0 "register_operand" "=x")
11547         (unspec:V8SI
11548           [(match_operand:V8SI 1 "register_operand" "x")
11549            (match_operand:V8SI 2 "nonimmediate_operand" "xm")]
11550           UNSPEC_VPERMSI))]
11551   "TARGET_AVX2"
11552   "vpermd\t{%2, %1, %0|%0, %1, %2}"
11553   [(set_attr "type" "sselog")
11554    (set_attr "prefix" "vex")
11555    (set_attr "mode" "OI")])
11556
11557 (define_insn "avx2_permv4df"
11558   [(set (match_operand:V4DF 0 "register_operand" "=x")
11559         (unspec:V4DF
11560           [(match_operand:V4DF 1 "register_operand" "xm")
11561            (match_operand:SI 2 "const_0_to_255_operand" "n")]
11562           UNSPEC_VPERMDF))]
11563   "TARGET_AVX2"
11564   "vpermpd\t{%2, %1, %0|%0, %1, %2}"
11565   [(set_attr "type" "sselog")
11566    (set_attr "prefix_extra" "1")
11567    (set_attr "prefix" "vex")
11568    (set_attr "mode" "OI")])
11569
11570 (define_insn "avx2_permvarv8sf"
11571   [(set (match_operand:V8SF 0 "register_operand" "=x")
11572         (unspec:V8SF
11573           [(match_operand:V8SF 1 "register_operand" "x")
11574            (match_operand:V8SF 2 "nonimmediate_operand" "xm")]
11575           UNSPEC_VPERMSF))]
11576   "TARGET_AVX2"
11577   "vpermps\t{%2, %1, %0|%0, %1, %2}"
11578   [(set_attr "type" "sselog")
11579    (set_attr "prefix" "vex")
11580    (set_attr "mode" "OI")])
11581
11582 (define_insn "avx2_permv4di"
11583   [(set (match_operand:V4DI 0 "register_operand" "=x")
11584         (unspec:V4DI
11585           [(match_operand:V4DI 1 "register_operand" "xm")
11586            (match_operand:SI 2 "const_0_to_255_operand" "n")]
11587           UNSPEC_VPERMDI))]
11588   "TARGET_AVX2"
11589   "vpermq\t{%2, %1, %0|%0, %1, %2}"
11590   [(set_attr "type" "sselog")
11591    (set_attr "prefix" "vex")
11592    (set_attr "mode" "OI")])
11593
11594 (define_insn "avx2_permv2ti"
11595   [(set (match_operand:V4DI 0 "register_operand" "=x")
11596         (unspec:V4DI
11597           [(match_operand:V4DI 1 "register_operand" "x")
11598            (match_operand:V4DI 2 "register_operand" "xm")
11599            (match_operand:SI 3 "const_0_to_255_operand" "n")]
11600           UNSPEC_VPERMTI))]
11601   "TARGET_AVX2"
11602   "vperm2i128\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11603   [(set_attr "type" "sselog")
11604    (set_attr "prefix" "vex")
11605    (set_attr "mode" "OI")])
11606
11607 (define_insn "avx2_vec_dupv4df"
11608   [(set (match_operand:V4DF 0 "register_operand" "=x")
11609         (vec_duplicate:V4DF
11610           (vec_select:DF
11611             (match_operand:V2DF 1 "register_operand" "x")
11612             (parallel [(const_int 0)]))))]
11613   "TARGET_AVX2"
11614   "vbroadcastsd\t{%1, %0|%0, %1}"
11615   [(set_attr "type" "sselog1")
11616    (set_attr "prefix" "vex")
11617    (set_attr "mode" "V4DF")])
11618
11619 ;; Modes handled by AVX vec_dup patterns.
11620 (define_mode_iterator AVX_VEC_DUP_MODE
11621   [V8SI V8SF V4DI V4DF])
11622
11623 (define_insn "vec_dup<mode>"
11624   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "=x,x")
11625         (vec_duplicate:AVX_VEC_DUP_MODE
11626           (match_operand:<ssescalarmode> 1 "nonimmediate_operand" "m,?x")))]
11627   "TARGET_AVX"
11628   "@
11629    vbroadcast<ssescalarmodesuffix>\t{%1, %0|%0, %1}
11630    #"
11631   [(set_attr "type" "ssemov")
11632    (set_attr "prefix_extra" "1")
11633    (set_attr "prefix" "vex")
11634    (set_attr "mode" "V8SF")])
11635
11636 (define_insn "avx2_vbroadcasti128_<mode>"
11637   [(set (match_operand:VI_256 0 "register_operand" "=x")
11638         (vec_concat:VI_256
11639           (match_operand:<ssehalfvecmode> 1 "memory_operand" "m")
11640           (match_dup 1)))]
11641   "TARGET_AVX2"
11642   "vbroadcasti128\t{%1, %0|%0, %1}"
11643   [(set_attr "type" "ssemov")
11644    (set_attr "prefix_extra" "1")
11645    (set_attr "prefix" "vex")
11646    (set_attr "mode" "OI")])
11647
11648 (define_split
11649   [(set (match_operand:AVX_VEC_DUP_MODE 0 "register_operand" "")
11650         (vec_duplicate:AVX_VEC_DUP_MODE
11651           (match_operand:<ssescalarmode> 1 "register_operand" "")))]
11652   "TARGET_AVX && reload_completed"
11653   [(set (match_dup 2)
11654         (vec_duplicate:<ssehalfvecmode> (match_dup 1)))
11655    (set (match_dup 0)
11656         (vec_concat:AVX_VEC_DUP_MODE (match_dup 2) (match_dup 2)))]
11657   "operands[2] = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (operands[0]));")
11658
11659 (define_insn "avx_vbroadcastf128_<mode>"
11660   [(set (match_operand:V_256 0 "register_operand" "=x,x,x")
11661         (vec_concat:V_256
11662           (match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "m,0,?x")
11663           (match_dup 1)))]
11664   "TARGET_AVX"
11665   "@
11666    vbroadcastf128\t{%1, %0|%0, %1}
11667    vinsertf128\t{$1, %1, %0, %0|%0, %0, %1, 1}
11668    vperm2f128\t{$0, %t1, %t1, %0|%0, %t1, %t1, 0}"
11669   [(set_attr "type" "ssemov,sselog1,sselog1")
11670    (set_attr "prefix_extra" "1")
11671    (set_attr "length_immediate" "0,1,1")
11672    (set_attr "prefix" "vex")
11673    (set_attr "mode" "V4SF,V8SF,V8SF")])
11674
11675 ;; Recognize broadcast as a vec_select as produced by builtin_vec_perm.
11676 ;; If it so happens that the input is in memory, use vbroadcast.
11677 ;; Otherwise use vpermilp (and in the case of 256-bit modes, vperm2f128).
11678 (define_insn "*avx_vperm_broadcast_v4sf"
11679   [(set (match_operand:V4SF 0 "register_operand" "=x,x,x")
11680         (vec_select:V4SF
11681           (match_operand:V4SF 1 "nonimmediate_operand" "m,o,x")
11682           (match_parallel 2 "avx_vbroadcast_operand"
11683             [(match_operand 3 "const_int_operand" "C,n,n")])))]
11684   "TARGET_AVX"
11685 {
11686   int elt = INTVAL (operands[3]);
11687   switch (which_alternative)
11688     {
11689     case 0:
11690     case 1:
11691       operands[1] = adjust_address_nv (operands[1], SFmode, elt * 4);
11692       return "vbroadcastss\t{%1, %0|%0, %1}";
11693     case 2:
11694       operands[2] = GEN_INT (elt * 0x55);
11695       return "vpermilps\t{%2, %1, %0|%0, %1, %2}";
11696     default:
11697       gcc_unreachable ();
11698     }
11699 }
11700   [(set_attr "type" "ssemov,ssemov,sselog1")
11701    (set_attr "prefix_extra" "1")
11702    (set_attr "length_immediate" "0,0,1")
11703    (set_attr "prefix" "vex")
11704    (set_attr "mode" "SF,SF,V4SF")])
11705
11706 (define_insn_and_split "*avx_vperm_broadcast_<mode>"
11707   [(set (match_operand:VF_256 0 "register_operand" "=x,x,x")
11708         (vec_select:VF_256
11709           (match_operand:VF_256 1 "nonimmediate_operand" "m,o,?x")
11710           (match_parallel 2 "avx_vbroadcast_operand"
11711             [(match_operand 3 "const_int_operand" "C,n,n")])))]
11712   "TARGET_AVX"
11713   "#"
11714   "&& reload_completed"
11715   [(set (match_dup 0) (vec_duplicate:VF_256 (match_dup 1)))]
11716 {
11717   rtx op0 = operands[0], op1 = operands[1];
11718   int elt = INTVAL (operands[3]);
11719
11720   if (REG_P (op1))
11721     {
11722       int mask;
11723
11724       /* Shuffle element we care about into all elements of the 128-bit lane.
11725          The other lane gets shuffled too, but we don't care.  */
11726       if (<MODE>mode == V4DFmode)
11727         mask = (elt & 1 ? 15 : 0);
11728       else
11729         mask = (elt & 3) * 0x55;
11730       emit_insn (gen_avx_vpermil<mode> (op0, op1, GEN_INT (mask)));
11731
11732       /* Shuffle the lane we care about into both lanes of the dest.  */
11733       mask = (elt / (<ssescalarnum> / 2)) * 0x11;
11734       emit_insn (gen_avx_vperm2f128<mode>3 (op0, op0, op0, GEN_INT (mask)));
11735       DONE;
11736     }
11737
11738   operands[1] = adjust_address_nv (op1, <ssescalarmode>mode,
11739                                    elt * GET_MODE_SIZE (<ssescalarmode>mode));
11740 })
11741
11742 (define_expand "avx_vpermil<mode>"
11743   [(set (match_operand:VF2 0 "register_operand" "")
11744         (vec_select:VF2
11745           (match_operand:VF2 1 "nonimmediate_operand" "")
11746           (match_operand:SI 2 "const_0_to_255_operand" "")))]
11747   "TARGET_AVX"
11748 {
11749   int mask = INTVAL (operands[2]);
11750   rtx perm[<ssescalarnum>];
11751
11752   perm[0] = GEN_INT (mask & 1);
11753   perm[1] = GEN_INT ((mask >> 1) & 1);
11754   if (<MODE>mode == V4DFmode)
11755     {
11756       perm[2] = GEN_INT (((mask >> 2) & 1) + 2);
11757       perm[3] = GEN_INT (((mask >> 3) & 1) + 2);
11758     }
11759
11760   operands[2]
11761     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
11762 })
11763
11764 (define_expand "avx_vpermil<mode>"
11765   [(set (match_operand:VF1 0 "register_operand" "")
11766         (vec_select:VF1
11767           (match_operand:VF1 1 "nonimmediate_operand" "")
11768           (match_operand:SI 2 "const_0_to_255_operand" "")))]
11769   "TARGET_AVX"
11770 {
11771   int mask = INTVAL (operands[2]);
11772   rtx perm[<ssescalarnum>];
11773
11774   perm[0] = GEN_INT (mask & 3);
11775   perm[1] = GEN_INT ((mask >> 2) & 3);
11776   perm[2] = GEN_INT ((mask >> 4) & 3);
11777   perm[3] = GEN_INT ((mask >> 6) & 3);
11778   if (<MODE>mode == V8SFmode)
11779     {
11780       perm[4] = GEN_INT ((mask & 3) + 4);
11781       perm[5] = GEN_INT (((mask >> 2) & 3) + 4);
11782       perm[6] = GEN_INT (((mask >> 4) & 3) + 4);
11783       perm[7] = GEN_INT (((mask >> 6) & 3) + 4);
11784     }
11785
11786   operands[2]
11787     = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (<ssescalarnum>, perm));
11788 })
11789
11790 (define_insn "*avx_vpermilp<mode>"
11791   [(set (match_operand:VF 0 "register_operand" "=x")
11792         (vec_select:VF
11793           (match_operand:VF 1 "nonimmediate_operand" "xm")
11794           (match_parallel 2 ""
11795             [(match_operand 3 "const_int_operand" "")])))]
11796   "TARGET_AVX
11797    && avx_vpermilp_parallel (operands[2], <MODE>mode)"
11798 {
11799   int mask = avx_vpermilp_parallel (operands[2], <MODE>mode) - 1;
11800   operands[2] = GEN_INT (mask);
11801   return "vpermil<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}";
11802 }
11803   [(set_attr "type" "sselog")
11804    (set_attr "prefix_extra" "1")
11805    (set_attr "length_immediate" "1")
11806    (set_attr "prefix" "vex")
11807    (set_attr "mode" "<MODE>")])
11808
11809 (define_insn "avx_vpermilvar<mode>3"
11810   [(set (match_operand:VF 0 "register_operand" "=x")
11811         (unspec:VF
11812           [(match_operand:VF 1 "register_operand" "x")
11813            (match_operand:<sseintvecmode> 2 "nonimmediate_operand" "xm")]
11814           UNSPEC_VPERMIL))]
11815   "TARGET_AVX"
11816   "vpermil<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
11817   [(set_attr "type" "sselog")
11818    (set_attr "prefix_extra" "1")
11819    (set_attr "prefix" "vex")
11820    (set_attr "mode" "<MODE>")])
11821
11822 (define_expand "avx_vperm2f128<mode>3"
11823   [(set (match_operand:AVX256MODE2P 0 "register_operand" "")
11824         (unspec:AVX256MODE2P
11825           [(match_operand:AVX256MODE2P 1 "register_operand" "")
11826            (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "")
11827            (match_operand:SI 3 "const_0_to_255_operand" "")]
11828           UNSPEC_VPERMIL2F128))]
11829   "TARGET_AVX"
11830 {
11831   int mask = INTVAL (operands[3]);
11832   if ((mask & 0x88) == 0)
11833     {
11834       rtx perm[<ssescalarnum>], t1, t2;
11835       int i, base, nelt = <ssescalarnum>, nelt2 = nelt / 2;
11836
11837       base = (mask & 3) * nelt2;
11838       for (i = 0; i < nelt2; ++i)
11839         perm[i] = GEN_INT (base + i);
11840
11841       base = ((mask >> 4) & 3) * nelt2;
11842       for (i = 0; i < nelt2; ++i)
11843         perm[i + nelt2] = GEN_INT (base + i);
11844
11845       t2 = gen_rtx_VEC_CONCAT (<ssedoublevecmode>mode,
11846                                operands[1], operands[2]);
11847       t1 = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (nelt, perm));
11848       t2 = gen_rtx_VEC_SELECT (<MODE>mode, t2, t1);
11849       t2 = gen_rtx_SET (VOIDmode, operands[0], t2);
11850       emit_insn (t2);
11851       DONE;
11852     }
11853 })
11854
11855 ;; Note that bits 7 and 3 of the imm8 allow lanes to be zeroed, which
11856 ;; means that in order to represent this properly in rtl we'd have to
11857 ;; nest *another* vec_concat with a zero operand and do the select from
11858 ;; a 4x wide vector.  That doesn't seem very nice.
11859 (define_insn "*avx_vperm2f128<mode>_full"
11860   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
11861         (unspec:AVX256MODE2P
11862           [(match_operand:AVX256MODE2P 1 "register_operand" "x")
11863            (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm")
11864            (match_operand:SI 3 "const_0_to_255_operand" "n")]
11865           UNSPEC_VPERMIL2F128))]
11866   "TARGET_AVX"
11867   "vperm2f128\t{%3, %2, %1, %0|%0, %1, %2, %3}"
11868   [(set_attr "type" "sselog")
11869    (set_attr "prefix_extra" "1")
11870    (set_attr "length_immediate" "1")
11871    (set_attr "prefix" "vex")
11872    (set_attr "mode" "V8SF")])
11873
11874 (define_insn "*avx_vperm2f128<mode>_nozero"
11875   [(set (match_operand:AVX256MODE2P 0 "register_operand" "=x")
11876         (vec_select:AVX256MODE2P
11877           (vec_concat:<ssedoublevecmode>
11878             (match_operand:AVX256MODE2P 1 "register_operand" "x")
11879             (match_operand:AVX256MODE2P 2 "nonimmediate_operand" "xm"))
11880           (match_parallel 3 ""
11881             [(match_operand 4 "const_int_operand" "")])))]
11882   "TARGET_AVX
11883    && avx_vperm2f128_parallel (operands[3], <MODE>mode)"
11884 {
11885   int mask = avx_vperm2f128_parallel (operands[3], <MODE>mode) - 1;
11886   operands[3] = GEN_INT (mask);
11887   return "vperm2f128\t{%3, %2, %1, %0|%0, %1, %2, %3}";
11888 }
11889   [(set_attr "type" "sselog")
11890    (set_attr "prefix_extra" "1")
11891    (set_attr "length_immediate" "1")
11892    (set_attr "prefix" "vex")
11893    (set_attr "mode" "V8SF")])
11894
11895 (define_expand "avx_vinsertf128<mode>"
11896   [(match_operand:V_256 0 "register_operand" "")
11897    (match_operand:V_256 1 "register_operand" "")
11898    (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "")
11899    (match_operand:SI 3 "const_0_to_1_operand" "")]
11900   "TARGET_AVX"
11901 {
11902   rtx (*insn)(rtx, rtx, rtx);
11903
11904   switch (INTVAL (operands[3]))
11905     {
11906     case 0:
11907       insn = gen_vec_set_lo_<mode>;
11908       break;
11909     case 1:
11910       insn = gen_vec_set_hi_<mode>;
11911       break;
11912     default:
11913       gcc_unreachable ();
11914     }
11915
11916   emit_insn (insn (operands[0], operands[1], operands[2]));
11917   DONE;
11918 })
11919
11920 (define_insn "avx2_vec_set_lo_v4di"
11921   [(set (match_operand:V4DI 0 "register_operand" "=x")
11922         (vec_concat:V4DI
11923           (match_operand:V2DI 2 "nonimmediate_operand" "xm")
11924           (vec_select:V2DI
11925             (match_operand:V4DI 1 "register_operand" "x")
11926             (parallel [(const_int 2) (const_int 3)]))))]
11927   "TARGET_AVX2"
11928   "vinserti128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
11929   [(set_attr "type" "sselog")
11930    (set_attr "prefix_extra" "1")
11931    (set_attr "length_immediate" "1")
11932    (set_attr "prefix" "vex")
11933    (set_attr "mode" "OI")])
11934
11935 (define_insn "avx2_vec_set_hi_v4di"
11936   [(set (match_operand:V4DI 0 "register_operand" "=x")
11937         (vec_concat:V4DI
11938           (vec_select:V2DI
11939             (match_operand:V4DI 1 "register_operand" "x")
11940             (parallel [(const_int 0) (const_int 1)]))
11941           (match_operand:V2DI 2 "nonimmediate_operand" "xm")))]
11942   "TARGET_AVX2"
11943   "vinserti128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
11944   [(set_attr "type" "sselog")
11945    (set_attr "prefix_extra" "1")
11946    (set_attr "length_immediate" "1")
11947    (set_attr "prefix" "vex")
11948    (set_attr "mode" "OI")])
11949
11950 (define_insn "vec_set_lo_<mode>"
11951   [(set (match_operand:VI8F_256 0 "register_operand" "=x")
11952         (vec_concat:VI8F_256
11953           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")
11954           (vec_select:<ssehalfvecmode>
11955             (match_operand:VI8F_256 1 "register_operand" "x")
11956             (parallel [(const_int 2) (const_int 3)]))))]
11957   "TARGET_AVX"
11958   "vinsertf128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
11959   [(set_attr "type" "sselog")
11960    (set_attr "prefix_extra" "1")
11961    (set_attr "length_immediate" "1")
11962    (set_attr "prefix" "vex")
11963    (set_attr "mode" "V4DF")])
11964
11965 (define_insn "vec_set_hi_<mode>"
11966   [(set (match_operand:VI8F_256 0 "register_operand" "=x")
11967         (vec_concat:VI8F_256
11968           (vec_select:<ssehalfvecmode>
11969             (match_operand:VI8F_256 1 "register_operand" "x")
11970             (parallel [(const_int 0) (const_int 1)]))
11971           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")))]
11972   "TARGET_AVX"
11973   "vinsertf128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
11974   [(set_attr "type" "sselog")
11975    (set_attr "prefix_extra" "1")
11976    (set_attr "length_immediate" "1")
11977    (set_attr "prefix" "vex")
11978    (set_attr "mode" "V4DF")])
11979
11980 (define_insn "vec_set_lo_<mode>"
11981   [(set (match_operand:VI4F_256 0 "register_operand" "=x")
11982         (vec_concat:VI4F_256
11983           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")
11984           (vec_select:<ssehalfvecmode>
11985             (match_operand:VI4F_256 1 "register_operand" "x")
11986             (parallel [(const_int 4) (const_int 5)
11987                        (const_int 6) (const_int 7)]))))]
11988   "TARGET_AVX"
11989   "vinsertf128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
11990   [(set_attr "type" "sselog")
11991    (set_attr "prefix_extra" "1")
11992    (set_attr "length_immediate" "1")
11993    (set_attr "prefix" "vex")
11994    (set_attr "mode" "V8SF")])
11995
11996 (define_insn "vec_set_hi_<mode>"
11997   [(set (match_operand:VI4F_256 0 "register_operand" "=x")
11998         (vec_concat:VI4F_256
11999           (vec_select:<ssehalfvecmode>
12000             (match_operand:VI4F_256 1 "register_operand" "x")
12001             (parallel [(const_int 0) (const_int 1)
12002                        (const_int 2) (const_int 3)]))
12003           (match_operand:<ssehalfvecmode> 2 "nonimmediate_operand" "xm")))]
12004   "TARGET_AVX"
12005   "vinsertf128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12006   [(set_attr "type" "sselog")
12007    (set_attr "prefix_extra" "1")
12008    (set_attr "length_immediate" "1")
12009    (set_attr "prefix" "vex")
12010    (set_attr "mode" "V8SF")])
12011
12012 (define_insn "vec_set_lo_v16hi"
12013   [(set (match_operand:V16HI 0 "register_operand" "=x")
12014         (vec_concat:V16HI
12015           (match_operand:V8HI 2 "nonimmediate_operand" "xm")
12016           (vec_select:V8HI
12017             (match_operand:V16HI 1 "register_operand" "x")
12018             (parallel [(const_int 8) (const_int 9)
12019                        (const_int 10) (const_int 11)
12020                        (const_int 12) (const_int 13)
12021                        (const_int 14) (const_int 15)]))))]
12022   "TARGET_AVX"
12023   "vinsertf128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12024   [(set_attr "type" "sselog")
12025    (set_attr "prefix_extra" "1")
12026    (set_attr "length_immediate" "1")
12027    (set_attr "prefix" "vex")
12028    (set_attr "mode" "V8SF")])
12029
12030 (define_insn "vec_set_hi_v16hi"
12031   [(set (match_operand:V16HI 0 "register_operand" "=x")
12032         (vec_concat:V16HI
12033           (vec_select:V8HI
12034             (match_operand:V16HI 1 "register_operand" "x")
12035             (parallel [(const_int 0) (const_int 1)
12036                        (const_int 2) (const_int 3)
12037                        (const_int 4) (const_int 5)
12038                        (const_int 6) (const_int 7)]))
12039           (match_operand:V8HI 2 "nonimmediate_operand" "xm")))]
12040   "TARGET_AVX"
12041   "vinsertf128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12042   [(set_attr "type" "sselog")
12043    (set_attr "prefix_extra" "1")
12044    (set_attr "length_immediate" "1")
12045    (set_attr "prefix" "vex")
12046    (set_attr "mode" "V8SF")])
12047
12048 (define_insn "vec_set_lo_v32qi"
12049   [(set (match_operand:V32QI 0 "register_operand" "=x")
12050         (vec_concat:V32QI
12051           (match_operand:V16QI 2 "nonimmediate_operand" "xm")
12052           (vec_select:V16QI
12053             (match_operand:V32QI 1 "register_operand" "x")
12054             (parallel [(const_int 16) (const_int 17)
12055                        (const_int 18) (const_int 19)
12056                        (const_int 20) (const_int 21)
12057                        (const_int 22) (const_int 23)
12058                        (const_int 24) (const_int 25)
12059                        (const_int 26) (const_int 27)
12060                        (const_int 28) (const_int 29)
12061                        (const_int 30) (const_int 31)]))))]
12062   "TARGET_AVX"
12063   "vinsertf128\t{$0x0, %2, %1, %0|%0, %1, %2, 0x0}"
12064   [(set_attr "type" "sselog")
12065    (set_attr "prefix_extra" "1")
12066    (set_attr "length_immediate" "1")
12067    (set_attr "prefix" "vex")
12068    (set_attr "mode" "V8SF")])
12069
12070 (define_insn "vec_set_hi_v32qi"
12071   [(set (match_operand:V32QI 0 "register_operand" "=x")
12072         (vec_concat:V32QI
12073           (vec_select:V16QI
12074             (match_operand:V32QI 1 "register_operand" "x")
12075             (parallel [(const_int 0) (const_int 1)
12076                        (const_int 2) (const_int 3)
12077                        (const_int 4) (const_int 5)
12078                        (const_int 6) (const_int 7)
12079                        (const_int 8) (const_int 9)
12080                        (const_int 10) (const_int 11)
12081                        (const_int 12) (const_int 13)
12082                        (const_int 14) (const_int 15)]))
12083           (match_operand:V16QI 2 "nonimmediate_operand" "xm")))]
12084   "TARGET_AVX"
12085   "vinsertf128\t{$0x1, %2, %1, %0|%0, %1, %2, 0x1}"
12086   [(set_attr "type" "sselog")
12087    (set_attr "prefix_extra" "1")
12088    (set_attr "length_immediate" "1")
12089    (set_attr "prefix" "vex")
12090    (set_attr "mode" "V8SF")])
12091
12092 (define_expand "<avx_avx2>_maskload<ssemodesuffix><avxsizesuffix>"
12093   [(set (match_operand:V48_AVX2 0 "register_operand" "")
12094         (unspec:V48_AVX2
12095           [(match_operand:<sseintvecmode> 2 "register_operand" "")
12096            (match_operand:V48_AVX2 1 "memory_operand" "")
12097            (match_dup 0)]
12098           UNSPEC_MASKMOV))]
12099   "TARGET_AVX")
12100
12101 (define_expand "<avx_avx2>_maskstore<ssemodesuffix><avxsizesuffix>"
12102   [(set (match_operand:V48_AVX2 0 "memory_operand" "")
12103         (unspec:V48_AVX2
12104           [(match_operand:<sseintvecmode> 1 "register_operand" "")
12105            (match_operand:V48_AVX2 2 "register_operand" "")
12106            (match_dup 0)]
12107           UNSPEC_MASKMOV))]
12108   "TARGET_AVX")
12109
12110 (define_insn "*avx2_maskmov<ssemodesuffix><avxsizesuffix>"
12111   [(set (match_operand:VI48_AVX2 0 "nonimmediate_operand" "=x,m")
12112         (unspec:VI48_AVX2
12113           [(match_operand:<sseintvecmode> 1 "register_operand" "x,x")
12114            (match_operand:VI48_AVX2 2 "nonimmediate_operand" "m,x")
12115            (match_dup 0)]
12116           UNSPEC_MASKMOV))]
12117   "TARGET_AVX2
12118    && (REG_P (operands[0]) == MEM_P (operands[2]))"
12119   "vpmaskmov<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12120   [(set_attr "type" "sselog1")
12121    (set_attr "prefix_extra" "1")
12122    (set_attr "prefix" "vex")
12123    (set_attr "mode" "<sseinsnmode>")])
12124
12125 (define_insn "*avx_maskmov<ssemodesuffix><avxsizesuffix>"
12126   [(set (match_operand:VF 0 "nonimmediate_operand" "=x,m")
12127         (unspec:VF
12128           [(match_operand:<sseintvecmode> 1 "register_operand" "x,x")
12129            (match_operand:VF 2 "nonimmediate_operand" "m,x")
12130            (match_dup 0)]
12131           UNSPEC_MASKMOV))]
12132   "TARGET_AVX
12133    && (REG_P (operands[0]) == MEM_P (operands[2]))"
12134   "vmaskmov<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12135   [(set_attr "type" "sselog1")
12136    (set_attr "prefix_extra" "1")
12137    (set_attr "prefix" "vex")
12138    (set_attr "mode" "<MODE>")])
12139
12140 (define_insn_and_split "avx_<castmode><avxsizesuffix>_<castmode>"
12141   [(set (match_operand:AVX256MODE2P 0 "nonimmediate_operand" "=x,m")
12142         (unspec:AVX256MODE2P
12143           [(match_operand:<ssehalfvecmode> 1 "nonimmediate_operand" "xm,x")]
12144           UNSPEC_CAST))]
12145   "TARGET_AVX"
12146   "#"
12147   "&& reload_completed"
12148   [(const_int 0)]
12149 {
12150   rtx op0 = operands[0];
12151   rtx op1 = operands[1];
12152   if (REG_P (op0))
12153     op0 = gen_rtx_REG (<ssehalfvecmode>mode, REGNO (op0));
12154   else
12155     op1 = gen_rtx_REG (<MODE>mode, REGNO (op1));
12156   emit_move_insn (op0, op1);
12157   DONE;
12158 })
12159
12160 (define_expand "vec_init<mode>"
12161   [(match_operand:V_256 0 "register_operand" "")
12162    (match_operand 1 "" "")]
12163   "TARGET_AVX"
12164 {
12165   ix86_expand_vector_init (false, operands[0], operands[1]);
12166   DONE;
12167 })
12168
12169 (define_expand "avx2_extracti128"
12170   [(match_operand:V2DI 0 "nonimmediate_operand" "")
12171    (match_operand:V4DI 1 "register_operand" "")
12172    (match_operand:SI 2 "const_0_to_1_operand" "")]
12173   "TARGET_AVX2"
12174 {
12175   rtx (*insn)(rtx, rtx);
12176
12177   switch (INTVAL (operands[2]))
12178     {
12179     case 0:
12180       insn = gen_vec_extract_lo_v4di;
12181       break;
12182     case 1:
12183       insn = gen_vec_extract_hi_v4di;
12184       break;
12185     default:
12186       gcc_unreachable ();
12187     }
12188
12189   emit_insn (insn (operands[0], operands[1]));
12190   DONE;
12191 })
12192
12193 (define_expand "avx2_inserti128"
12194   [(match_operand:V4DI 0 "register_operand" "")
12195    (match_operand:V4DI 1 "register_operand" "")
12196    (match_operand:V2DI 2 "nonimmediate_operand" "")
12197    (match_operand:SI 3 "const_0_to_1_operand" "")]
12198   "TARGET_AVX2"
12199 {
12200   rtx (*insn)(rtx, rtx, rtx);
12201
12202   switch (INTVAL (operands[3]))
12203     {
12204     case 0:
12205       insn = gen_avx2_vec_set_lo_v4di;
12206       break;
12207     case 1:
12208       insn = gen_avx2_vec_set_hi_v4di;
12209       break;
12210     default:
12211       gcc_unreachable ();
12212     }
12213
12214   emit_insn (insn (operands[0], operands[1], operands[2]));
12215   DONE;
12216 })
12217
12218 (define_insn "avx2_ashrvv8si"
12219   [(set (match_operand:V8SI 0 "register_operand" "=x")
12220         (vec_concat:V8SI
12221           (vec_concat:V4SI
12222             (vec_concat:V2SI
12223               (ashiftrt:SI
12224                 (vec_select:SI
12225                   (match_operand:V8SI 1 "register_operand" "x")
12226                   (parallel [(const_int 0)]))
12227                 (vec_select:SI
12228                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
12229                   (parallel [(const_int 0)])))
12230               (ashiftrt:SI
12231                 (vec_select:SI
12232                   (match_dup 1)
12233                   (parallel [(const_int 1)]))
12234                 (vec_select:SI
12235                   (match_dup 2)
12236                   (parallel [(const_int 1)]))))
12237             (vec_concat:V2SI
12238               (ashiftrt:SI
12239                 (vec_select:SI
12240                   (match_dup 1)
12241                   (parallel [(const_int 2)]))
12242                 (vec_select:SI
12243                   (match_dup 2)
12244                   (parallel [(const_int 2)])))
12245               (ashiftrt:SI
12246                 (vec_select:SI
12247                   (match_dup 1)
12248                   (parallel [(const_int 3)]))
12249                 (vec_select:SI
12250                   (match_dup 2)
12251                   (parallel [(const_int 3)])))))
12252           (vec_concat:V4SI
12253             (vec_concat:V2SI
12254               (ashiftrt:SI
12255                 (vec_select:SI
12256                   (match_dup 1)
12257                   (parallel [(const_int 0)]))
12258                 (vec_select:SI
12259                   (match_dup 2)
12260                   (parallel [(const_int 0)])))
12261               (ashiftrt:SI
12262                 (vec_select:SI
12263                   (match_dup 1)
12264                   (parallel [(const_int 1)]))
12265                 (vec_select:SI
12266                   (match_dup 2)
12267                   (parallel [(const_int 1)]))))
12268             (vec_concat:V2SI
12269               (ashiftrt:SI
12270                 (vec_select:SI
12271                   (match_dup 1)
12272                   (parallel [(const_int 2)]))
12273                 (vec_select:SI
12274                   (match_dup 2)
12275                   (parallel [(const_int 2)])))
12276               (ashiftrt:SI
12277                 (vec_select:SI
12278                   (match_dup 1)
12279                   (parallel [(const_int 3)]))
12280                 (vec_select:SI
12281                   (match_dup 2)
12282                   (parallel [(const_int 3)])))))))]
12283   "TARGET_AVX2"
12284   "vpsravd\t{%2, %1, %0|%0, %1, %2}"
12285   [(set_attr "type" "sseishft")
12286    (set_attr "prefix" "vex")
12287    (set_attr "mode" "OI")])
12288
12289 (define_insn "avx2_ashrvv4si"
12290   [(set (match_operand:V4SI 0 "register_operand" "=x")
12291         (vec_concat:V4SI
12292           (vec_concat:V2SI
12293             (ashiftrt:SI
12294               (vec_select:SI
12295                 (match_operand:V4SI 1 "register_operand" "x")
12296                 (parallel [(const_int 0)]))
12297               (vec_select:SI
12298                 (match_operand:V4SI 2 "nonimmediate_operand" "xm")
12299                 (parallel [(const_int 0)])))
12300             (ashiftrt:SI
12301               (vec_select:SI
12302                 (match_dup 1)
12303                 (parallel [(const_int 1)]))
12304               (vec_select:SI
12305                 (match_dup 2)
12306                 (parallel [(const_int 1)]))))
12307           (vec_concat:V2SI
12308             (ashiftrt:SI
12309               (vec_select:SI
12310                 (match_dup 1)
12311                 (parallel [(const_int 2)]))
12312               (vec_select:SI
12313                 (match_dup 2)
12314                 (parallel [(const_int 2)])))
12315             (ashiftrt:SI
12316               (vec_select:SI
12317                 (match_dup 1)
12318                 (parallel [(const_int 3)]))
12319               (vec_select:SI
12320                 (match_dup 2)
12321                 (parallel [(const_int 3)]))))))]
12322   "TARGET_AVX2"
12323   "vpsravd\t{%2, %1, %0|%0, %1, %2}"
12324   [(set_attr "type" "sseishft")
12325    (set_attr "prefix" "vex")
12326    (set_attr "mode" "TI")])
12327
12328 (define_insn "avx2_<lshift>vv8si"
12329   [(set (match_operand:V8SI 0 "register_operand" "=x")
12330         (vec_concat:V8SI
12331           (vec_concat:V4SI
12332             (vec_concat:V2SI
12333               (lshift:SI
12334                 (vec_select:SI
12335                   (match_operand:V8SI 1 "register_operand" "x")
12336                   (parallel [(const_int 0)]))
12337                 (vec_select:SI
12338                   (match_operand:V8SI 2 "nonimmediate_operand" "xm")
12339                   (parallel [(const_int 0)])))
12340               (lshift:SI
12341                 (vec_select:SI
12342                   (match_dup 1)
12343                   (parallel [(const_int 1)]))
12344                 (vec_select:SI
12345                   (match_dup 2)
12346                   (parallel [(const_int 1)]))))
12347             (vec_concat:V2SI
12348               (lshift:SI
12349                 (vec_select:SI
12350                   (match_dup 1)
12351                   (parallel [(const_int 2)]))
12352                 (vec_select:SI
12353                   (match_dup 2)
12354                   (parallel [(const_int 2)])))
12355               (lshift:SI
12356                 (vec_select:SI
12357                   (match_dup 1)
12358                   (parallel [(const_int 3)]))
12359                 (vec_select:SI
12360                   (match_dup 2)
12361                   (parallel [(const_int 3)])))))
12362           (vec_concat:V4SI
12363             (vec_concat:V2SI
12364               (lshift:SI
12365                 (vec_select:SI
12366                   (match_dup 1)
12367                   (parallel [(const_int 0)]))
12368                 (vec_select:SI
12369                   (match_dup 2)
12370                   (parallel [(const_int 0)])))
12371               (lshift:SI
12372                 (vec_select:SI
12373                   (match_dup 1)
12374                   (parallel [(const_int 1)]))
12375                 (vec_select:SI
12376                   (match_dup 2)
12377                   (parallel [(const_int 1)]))))
12378             (vec_concat:V2SI
12379               (lshift:SI
12380                 (vec_select:SI
12381                   (match_dup 1)
12382                   (parallel [(const_int 2)]))
12383                 (vec_select:SI
12384                   (match_dup 2)
12385                   (parallel [(const_int 2)])))
12386               (lshift:SI
12387                 (vec_select:SI
12388                   (match_dup 1)
12389                   (parallel [(const_int 3)]))
12390                 (vec_select:SI
12391                   (match_dup 2)
12392                   (parallel [(const_int 3)])))))))]
12393   "TARGET_AVX2"
12394   "vp<lshift_insn>vd\t{%2, %1, %0|%0, %1, %2}"
12395   [(set_attr "type" "sseishft")
12396    (set_attr "prefix" "vex")
12397    (set_attr "mode" "OI")])
12398
12399 (define_insn "avx2_<lshift>v<mode>"
12400   [(set (match_operand:VI4SD_AVX2 0 "register_operand" "=x")
12401         (vec_concat:VI4SD_AVX2
12402           (vec_concat:<ssehalfvecmode>
12403             (lshift:<ssescalarmode>
12404               (vec_select:<ssescalarmode>
12405                 (match_operand:VI4SD_AVX2 1 "register_operand" "x")
12406                 (parallel [(const_int 0)]))
12407               (vec_select:<ssescalarmode>
12408                 (match_operand:VI4SD_AVX2 2 "nonimmediate_operand" "xm")
12409                 (parallel [(const_int 0)])))
12410             (lshift:<ssescalarmode>
12411               (vec_select:<ssescalarmode>
12412                 (match_dup 1)
12413                 (parallel [(const_int 1)]))
12414               (vec_select:<ssescalarmode>
12415                 (match_dup 2)
12416                 (parallel [(const_int 1)]))))
12417           (vec_concat:<ssehalfvecmode>
12418             (lshift:<ssescalarmode>
12419               (vec_select:<ssescalarmode>
12420                 (match_dup 1)
12421                 (parallel [(const_int 2)]))
12422               (vec_select:<ssescalarmode>
12423                 (match_dup 2)
12424                 (parallel [(const_int 2)])))
12425             (lshift:<ssescalarmode>
12426               (vec_select:<ssescalarmode>
12427                 (match_dup 1)
12428                 (parallel [(const_int 3)]))
12429               (vec_select:<ssescalarmode>
12430                 (match_dup 2)
12431                 (parallel [(const_int 3)]))))))]
12432   "TARGET_AVX2"
12433   "vp<lshift_insn>v<ssemodesuffix>\t{%2, %1, %0|%0, %1, %2}"
12434   [(set_attr "type" "sseishft")
12435    (set_attr "prefix" "vex")
12436    (set_attr "mode" "<sseinsnmode>")])
12437
12438 (define_insn "avx2_<lshift>vv2di"
12439   [(set (match_operand:V2DI 0 "register_operand" "=x")
12440         (vec_concat:V2DI
12441           (lshift:DI
12442             (vec_select:DI
12443               (match_operand:V2DI 1 "register_operand" "x")
12444               (parallel [(const_int 0)]))
12445             (vec_select:DI
12446               (match_operand:V2DI 2 "nonimmediate_operand" "xm")
12447               (parallel [(const_int 0)])))
12448           (lshift:DI
12449             (vec_select:DI
12450               (match_dup 1)
12451               (parallel [(const_int 1)]))
12452             (vec_select:DI
12453               (match_dup 2)
12454               (parallel [(const_int 1)])))))]
12455   "TARGET_AVX2"
12456   "vp<lshift_insn>vq\t{%2, %1, %0|%0, %1, %2}"
12457   [(set_attr "type" "sseishft")
12458    (set_attr "prefix" "vex")
12459    (set_attr "mode" "TI")])
12460
12461 (define_insn "*vec_concat<mode>_avx"
12462   [(set (match_operand:V_256 0 "register_operand" "=x,x")
12463         (vec_concat:V_256
12464           (match_operand:<ssehalfvecmode> 1 "register_operand" "x,x")
12465           (match_operand:<ssehalfvecmode> 2 "vector_move_operand" "xm,C")))]
12466   "TARGET_AVX"
12467 {
12468   switch (which_alternative)
12469     {
12470     case 0:
12471       return "vinsertf128\t{$0x1, %2, %t1, %0|%0, %t1, %2, 0x1}";
12472     case 1:
12473       switch (get_attr_mode (insn))
12474         {
12475         case MODE_V8SF:
12476           return "vmovaps\t{%1, %x0|%x0, %1}";
12477         case MODE_V4DF:
12478           return "vmovapd\t{%1, %x0|%x0, %1}";
12479         default:
12480           return "vmovdqa\t{%1, %x0|%x0, %1}";
12481         }
12482     default:
12483       gcc_unreachable ();
12484     }
12485 }
12486   [(set_attr "type" "sselog,ssemov")
12487    (set_attr "prefix_extra" "1,*")
12488    (set_attr "length_immediate" "1,*")
12489    (set_attr "prefix" "vex")
12490    (set_attr "mode" "<sseinsnmode>")])
12491
12492 (define_insn "vcvtph2ps"
12493   [(set (match_operand:V4SF 0 "register_operand" "=x")
12494         (vec_select:V4SF
12495           (unspec:V8SF [(match_operand:V8HI 1 "register_operand" "x")]
12496                        UNSPEC_VCVTPH2PS)
12497           (parallel [(const_int 0) (const_int 1)
12498                      (const_int 1) (const_int 2)])))]
12499   "TARGET_F16C"
12500   "vcvtph2ps\t{%1, %0|%0, %1}"
12501   [(set_attr "type" "ssecvt")
12502    (set_attr "prefix" "vex")
12503    (set_attr "mode" "V4SF")])
12504
12505 (define_insn "*vcvtph2ps_load"
12506   [(set (match_operand:V4SF 0 "register_operand" "=x")
12507         (unspec:V4SF [(match_operand:V4HI 1 "memory_operand" "m")]
12508                      UNSPEC_VCVTPH2PS))]
12509   "TARGET_F16C"
12510   "vcvtph2ps\t{%1, %0|%0, %1}"
12511   [(set_attr "type" "ssecvt")
12512    (set_attr "prefix" "vex")
12513    (set_attr "mode" "V8SF")])
12514
12515 (define_insn "vcvtph2ps256"
12516   [(set (match_operand:V8SF 0 "register_operand" "=x")
12517         (unspec:V8SF [(match_operand:V8HI 1 "nonimmediate_operand" "xm")]
12518                      UNSPEC_VCVTPH2PS))]
12519   "TARGET_F16C"
12520   "vcvtph2ps\t{%1, %0|%0, %1}"
12521   [(set_attr "type" "ssecvt")
12522    (set_attr "prefix" "vex")
12523    (set_attr "mode" "V8SF")])
12524
12525 (define_expand "vcvtps2ph"
12526   [(set (match_operand:V8HI 0 "register_operand" "")
12527         (vec_concat:V8HI
12528           (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "")
12529                         (match_operand:SI 2 "const_0_to_255_operand" "")]
12530                        UNSPEC_VCVTPS2PH)
12531           (match_dup 3)))]
12532   "TARGET_F16C"
12533   "operands[3] = CONST0_RTX (V4HImode);")
12534
12535 (define_insn "*vcvtps2ph"
12536   [(set (match_operand:V8HI 0 "register_operand" "=x")
12537         (vec_concat:V8HI
12538           (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "x")
12539                         (match_operand:SI 2 "const_0_to_255_operand" "N")]
12540                        UNSPEC_VCVTPS2PH)
12541           (match_operand:V4HI 3 "const0_operand" "")))]
12542   "TARGET_F16C"
12543   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
12544   [(set_attr "type" "ssecvt")
12545    (set_attr "prefix" "vex")
12546    (set_attr "mode" "V4SF")])
12547
12548 (define_insn "*vcvtps2ph_store"
12549   [(set (match_operand:V4HI 0 "memory_operand" "=m")
12550         (unspec:V4HI [(match_operand:V4SF 1 "register_operand" "x")
12551                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
12552                      UNSPEC_VCVTPS2PH))]
12553   "TARGET_F16C"
12554   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
12555   [(set_attr "type" "ssecvt")
12556    (set_attr "prefix" "vex")
12557    (set_attr "mode" "V4SF")])
12558
12559 (define_insn "vcvtps2ph256"
12560   [(set (match_operand:V8HI 0 "nonimmediate_operand" "=xm")
12561         (unspec:V8HI [(match_operand:V8SF 1 "register_operand" "x")
12562                       (match_operand:SI 2 "const_0_to_255_operand" "N")]
12563                      UNSPEC_VCVTPS2PH))]
12564   "TARGET_F16C"
12565   "vcvtps2ph\t{%2, %1, %0|%0, %1, %2}"
12566   [(set_attr "type" "ssecvt")
12567    (set_attr "prefix" "vex")
12568    (set_attr "mode" "V8SF")])
12569
12570 ;; For gather* insn patterns
12571 (define_mode_iterator VEC_GATHER_MODE
12572                       [V2DI V2DF V4DI V4DF V4SI V4SF V8SI V8SF])
12573 (define_mode_attr VEC_GATHER_MODE
12574                       [(V2DI "V4SI") (V2DF "V4SI")
12575                        (V4DI "V4SI") (V4DF "V4SI")
12576                        (V4SI "V4SI") (V4SF "V4SI")
12577                        (V8SI "V8SI") (V8SF "V8SI")])
12578
12579 (define_expand "avx2_gathersi<mode>"
12580   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "")
12581         (unspec:VEC_GATHER_MODE
12582           [(match_operand:VEC_GATHER_MODE 1 "register_operand" "")
12583            (match_operand:<ssescalarmode> 2 "memory_operand" "")
12584            (match_operand:<VEC_GATHER_MODE> 3 "register_operand" "")
12585            (match_operand:VEC_GATHER_MODE 4 "register_operand" "")
12586            (match_operand:SI 5 "const1248_operand " "")]
12587           UNSPEC_GATHER))]
12588   "TARGET_AVX2")
12589
12590 (define_insn "*avx2_gathersi<mode>"
12591   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "=x")
12592         (unspec:VEC_GATHER_MODE
12593           [(match_operand:VEC_GATHER_MODE 1 "register_operand" "0")
12594            (mem:<ssescalarmode>
12595              (match_operand:P 2 "register_operand" "r"))
12596            (match_operand:<VEC_GATHER_MODE> 3 "register_operand" "x")
12597            (match_operand:VEC_GATHER_MODE 4 "register_operand" "x")
12598            (match_operand:SI 5 "const1248_operand" "n")]
12599           UNSPEC_GATHER))]
12600   "TARGET_AVX2"
12601   "v<gthrfirstp>gatherd<gthrlastp>\t{%4, (%2, %3, %c5), %0|%0, (%2, %3, %c5), %4}"
12602   [(set_attr "type" "ssemov")
12603    (set_attr "prefix" "vex")
12604    (set_attr "mode" "<sseinsnmode>")])
12605
12606 (define_expand "avx2_gatherdi<mode>"
12607   [(set (match_operand:VEC_GATHER_MODE 0 "register_operand" "")
12608         (unspec:VEC_GATHER_MODE
12609           [(match_operand:VEC_GATHER_MODE 1 "register_operand" "")
12610            (match_operand:<ssescalarmode> 2 "memory_operand" "")
12611            (match_operand:<AVXMODE48P_DI> 3 "register_operand" "")
12612            (match_operand:VEC_GATHER_MODE 4 "register_operand" "")
12613            (match_operand:SI 5 "const1248_operand " "")]
12614           UNSPEC_GATHER))]
12615   "TARGET_AVX2")
12616
12617 (define_insn "*avx2_gatherdi<mode>"
12618   [(set (match_operand:AVXMODE48P_DI 0 "register_operand" "=x")
12619         (unspec:AVXMODE48P_DI
12620           [(match_operand:AVXMODE48P_DI 1 "register_operand" "0")
12621            (mem:<ssescalarmode>
12622              (match_operand:P 2 "register_operand" "r"))
12623            (match_operand:<AVXMODE48P_DI> 3 "register_operand" "x")
12624            (match_operand:AVXMODE48P_DI 4 "register_operand" "x")
12625            (match_operand:SI 5 "const1248_operand" "n")]
12626           UNSPEC_GATHER))]
12627   "TARGET_AVX2"
12628   "v<gthrfirstp>gatherq<gthrlastp>\t{%4, (%2, %3, %c5), %0|%0, (%2, %3, %c5), %4}"
12629   [(set_attr "type" "ssemov")
12630    (set_attr "prefix" "vex")
12631    (set_attr "mode" "<sseinsnmode>")])
12632
12633 ;; Special handling for VEX.256 with float arguments
12634 ;; since there're still xmms as operands
12635 (define_expand "avx2_gatherdi<mode>256"
12636   [(set (match_operand:VI4F_128 0 "register_operand" "")
12637         (unspec:VI4F_128
12638           [(match_operand:VI4F_128 1 "register_operand" "")
12639            (match_operand:<ssescalarmode> 2 "memory_operand" "")
12640            (match_operand:V4DI 3 "register_operand" "")
12641            (match_operand:VI4F_128 4 "register_operand" "")
12642            (match_operand:SI 5 "const1248_operand " "")]
12643           UNSPEC_GATHER))]
12644   "TARGET_AVX2")
12645
12646 (define_insn "*avx2_gatherdi<mode>256"
12647   [(set (match_operand:VI4F_128 0 "register_operand" "=x")
12648         (unspec:VI4F_128
12649           [(match_operand:VI4F_128 1 "register_operand" "0")
12650            (mem:<ssescalarmode>
12651              (match_operand:P 2 "register_operand" "r"))
12652            (match_operand:V4DI 3 "register_operand" "x")
12653            (match_operand:VI4F_128 4 "register_operand" "x")
12654            (match_operand:SI 5 "const1248_operand" "n")]
12655           UNSPEC_GATHER))]
12656   "TARGET_AVX2"
12657   "v<gthrfirstp>gatherq<gthrlastp>\t{%4, (%2, %3, %c5), %0|%0, (%2, %3, %c5), %4}"
12658   [(set_attr "type" "ssemov")
12659    (set_attr "prefix" "vex")
12660    (set_attr "mode" "<sseinsnmode>")])