Revert the last P_POPCNT order change
[platform/upstream/gcc.git] / gcc / config / i386 / i386.c
1 /* Subroutines used for code generation on IA-32.
2    Copyright (C) 1988-2015 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3.  If not see
18 <http://www.gnu.org/licenses/>.  */
19
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "rtl.h"
25 #include "hash-set.h"
26 #include "machmode.h"
27 #include "vec.h"
28 #include "double-int.h"
29 #include "input.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "tree.h"
35 #include "fold-const.h"
36 #include "stringpool.h"
37 #include "attribs.h"
38 #include "calls.h"
39 #include "stor-layout.h"
40 #include "varasm.h"
41 #include "tm_p.h"
42 #include "regs.h"
43 #include "hard-reg-set.h"
44 #include "insn-config.h"
45 #include "conditions.h"
46 #include "output.h"
47 #include "insn-codes.h"
48 #include "insn-attr.h"
49 #include "flags.h"
50 #include "except.h"
51 #include "function.h"
52 #include "recog.h"
53 #include "hashtab.h"
54 #include "statistics.h"
55 #include "real.h"
56 #include "fixed-value.h"
57 #include "expmed.h"
58 #include "dojump.h"
59 #include "explow.h"
60 #include "emit-rtl.h"
61 #include "stmt.h"
62 #include "expr.h"
63 #include "optabs.h"
64 #include "diagnostic-core.h"
65 #include "toplev.h"
66 #include "predict.h"
67 #include "dominance.h"
68 #include "cfg.h"
69 #include "cfgrtl.h"
70 #include "cfganal.h"
71 #include "lcm.h"
72 #include "cfgbuild.h"
73 #include "cfgcleanup.h"
74 #include "basic-block.h"
75 #include "ggc.h"
76 #include "target.h"
77 #include "target-def.h"
78 #include "common/common-target.h"
79 #include "langhooks.h"
80 #include "reload.h"
81 #include "hash-map.h"
82 #include "is-a.h"
83 #include "plugin-api.h"
84 #include "ipa-ref.h"
85 #include "cgraph.h"
86 #include "hash-table.h"
87 #include "tree-ssa-alias.h"
88 #include "internal-fn.h"
89 #include "gimple-fold.h"
90 #include "tree-eh.h"
91 #include "gimple-expr.h"
92 #include "gimple.h"
93 #include "gimplify.h"
94 #include "cfgloop.h"
95 #include "dwarf2.h"
96 #include "df.h"
97 #include "tm-constrs.h"
98 #include "params.h"
99 #include "cselib.h"
100 #include "debug.h"
101 #include "sched-int.h"
102 #include "sbitmap.h"
103 #include "fibheap.h"
104 #include "opts.h"
105 #include "diagnostic.h"
106 #include "dumpfile.h"
107 #include "tree-pass.h"
108 #include "context.h"
109 #include "pass_manager.h"
110 #include "target-globals.h"
111 #include "tree-vectorizer.h"
112 #include "shrink-wrap.h"
113 #include "builtins.h"
114 #include "rtl-iter.h"
115 #include "tree-iterator.h"
116 #include "tree-chkp.h"
117 #include "rtl-chkp.h"
118
119 static rtx legitimize_dllimport_symbol (rtx, bool);
120 static rtx legitimize_pe_coff_extern_decl (rtx, bool);
121 static rtx legitimize_pe_coff_symbol (rtx, bool);
122
123 #ifndef CHECK_STACK_LIMIT
124 #define CHECK_STACK_LIMIT (-1)
125 #endif
126
127 /* Return index of given mode in mult and division cost tables.  */
128 #define MODE_INDEX(mode)                                        \
129   ((mode) == QImode ? 0                                         \
130    : (mode) == HImode ? 1                                       \
131    : (mode) == SImode ? 2                                       \
132    : (mode) == DImode ? 3                                       \
133    : 4)
134
135 /* Processor costs (relative to an add) */
136 /* We assume COSTS_N_INSNS is defined as (N)*4 and an addition is 2 bytes.  */
137 #define COSTS_N_BYTES(N) ((N) * 2)
138
139 #define DUMMY_STRINGOP_ALGS {libcall, {{-1, libcall, false}}}
140
141 static stringop_algs ix86_size_memcpy[2] = {
142   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
143   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}}};
144 static stringop_algs ix86_size_memset[2] = {
145   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
146   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}}};
147
148 const
149 struct processor_costs ix86_size_cost = {/* costs for tuning for size */
150   COSTS_N_BYTES (2),                    /* cost of an add instruction */
151   COSTS_N_BYTES (3),                    /* cost of a lea instruction */
152   COSTS_N_BYTES (2),                    /* variable shift costs */
153   COSTS_N_BYTES (3),                    /* constant shift costs */
154   {COSTS_N_BYTES (3),                   /* cost of starting multiply for QI */
155    COSTS_N_BYTES (3),                   /*                               HI */
156    COSTS_N_BYTES (3),                   /*                               SI */
157    COSTS_N_BYTES (3),                   /*                               DI */
158    COSTS_N_BYTES (5)},                  /*                            other */
159   0,                                    /* cost of multiply per each bit set */
160   {COSTS_N_BYTES (3),                   /* cost of a divide/mod for QI */
161    COSTS_N_BYTES (3),                   /*                          HI */
162    COSTS_N_BYTES (3),                   /*                          SI */
163    COSTS_N_BYTES (3),                   /*                          DI */
164    COSTS_N_BYTES (5)},                  /*                          other */
165   COSTS_N_BYTES (3),                    /* cost of movsx */
166   COSTS_N_BYTES (3),                    /* cost of movzx */
167   0,                                    /* "large" insn */
168   2,                                    /* MOVE_RATIO */
169   2,                                 /* cost for loading QImode using movzbl */
170   {2, 2, 2},                            /* cost of loading integer registers
171                                            in QImode, HImode and SImode.
172                                            Relative to reg-reg move (2).  */
173   {2, 2, 2},                            /* cost of storing integer registers */
174   2,                                    /* cost of reg,reg fld/fst */
175   {2, 2, 2},                            /* cost of loading fp registers
176                                            in SFmode, DFmode and XFmode */
177   {2, 2, 2},                            /* cost of storing fp registers
178                                            in SFmode, DFmode and XFmode */
179   3,                                    /* cost of moving MMX register */
180   {3, 3},                               /* cost of loading MMX registers
181                                            in SImode and DImode */
182   {3, 3},                               /* cost of storing MMX registers
183                                            in SImode and DImode */
184   3,                                    /* cost of moving SSE register */
185   {3, 3, 3},                            /* cost of loading SSE registers
186                                            in SImode, DImode and TImode */
187   {3, 3, 3},                            /* cost of storing SSE registers
188                                            in SImode, DImode and TImode */
189   3,                                    /* MMX or SSE register to integer */
190   0,                                    /* size of l1 cache  */
191   0,                                    /* size of l2 cache  */
192   0,                                    /* size of prefetch block */
193   0,                                    /* number of parallel prefetches */
194   2,                                    /* Branch cost */
195   COSTS_N_BYTES (2),                    /* cost of FADD and FSUB insns.  */
196   COSTS_N_BYTES (2),                    /* cost of FMUL instruction.  */
197   COSTS_N_BYTES (2),                    /* cost of FDIV instruction.  */
198   COSTS_N_BYTES (2),                    /* cost of FABS instruction.  */
199   COSTS_N_BYTES (2),                    /* cost of FCHS instruction.  */
200   COSTS_N_BYTES (2),                    /* cost of FSQRT instruction.  */
201   ix86_size_memcpy,
202   ix86_size_memset,
203   1,                                    /* scalar_stmt_cost.  */
204   1,                                    /* scalar load_cost.  */
205   1,                                    /* scalar_store_cost.  */
206   1,                                    /* vec_stmt_cost.  */
207   1,                                    /* vec_to_scalar_cost.  */
208   1,                                    /* scalar_to_vec_cost.  */
209   1,                                    /* vec_align_load_cost.  */
210   1,                                    /* vec_unalign_load_cost.  */
211   1,                                    /* vec_store_cost.  */
212   1,                                    /* cond_taken_branch_cost.  */
213   1,                                    /* cond_not_taken_branch_cost.  */
214 };
215
216 /* Processor costs (relative to an add) */
217 static stringop_algs i386_memcpy[2] = {
218   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
219   DUMMY_STRINGOP_ALGS};
220 static stringop_algs i386_memset[2] = {
221   {rep_prefix_1_byte, {{-1, rep_prefix_1_byte, false}}},
222   DUMMY_STRINGOP_ALGS};
223
224 static const
225 struct processor_costs i386_cost = {    /* 386 specific costs */
226   COSTS_N_INSNS (1),                    /* cost of an add instruction */
227   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
228   COSTS_N_INSNS (3),                    /* variable shift costs */
229   COSTS_N_INSNS (2),                    /* constant shift costs */
230   {COSTS_N_INSNS (6),                   /* cost of starting multiply for QI */
231    COSTS_N_INSNS (6),                   /*                               HI */
232    COSTS_N_INSNS (6),                   /*                               SI */
233    COSTS_N_INSNS (6),                   /*                               DI */
234    COSTS_N_INSNS (6)},                  /*                            other */
235   COSTS_N_INSNS (1),                    /* cost of multiply per each bit set */
236   {COSTS_N_INSNS (23),                  /* cost of a divide/mod for QI */
237    COSTS_N_INSNS (23),                  /*                          HI */
238    COSTS_N_INSNS (23),                  /*                          SI */
239    COSTS_N_INSNS (23),                  /*                          DI */
240    COSTS_N_INSNS (23)},                 /*                          other */
241   COSTS_N_INSNS (3),                    /* cost of movsx */
242   COSTS_N_INSNS (2),                    /* cost of movzx */
243   15,                                   /* "large" insn */
244   3,                                    /* MOVE_RATIO */
245   4,                                 /* cost for loading QImode using movzbl */
246   {2, 4, 2},                            /* cost of loading integer registers
247                                            in QImode, HImode and SImode.
248                                            Relative to reg-reg move (2).  */
249   {2, 4, 2},                            /* cost of storing integer registers */
250   2,                                    /* cost of reg,reg fld/fst */
251   {8, 8, 8},                            /* cost of loading fp registers
252                                            in SFmode, DFmode and XFmode */
253   {8, 8, 8},                            /* cost of storing fp registers
254                                            in SFmode, DFmode and XFmode */
255   2,                                    /* cost of moving MMX register */
256   {4, 8},                               /* cost of loading MMX registers
257                                            in SImode and DImode */
258   {4, 8},                               /* cost of storing MMX registers
259                                            in SImode and DImode */
260   2,                                    /* cost of moving SSE register */
261   {4, 8, 16},                           /* cost of loading SSE registers
262                                            in SImode, DImode and TImode */
263   {4, 8, 16},                           /* cost of storing SSE registers
264                                            in SImode, DImode and TImode */
265   3,                                    /* MMX or SSE register to integer */
266   0,                                    /* size of l1 cache  */
267   0,                                    /* size of l2 cache  */
268   0,                                    /* size of prefetch block */
269   0,                                    /* number of parallel prefetches */
270   1,                                    /* Branch cost */
271   COSTS_N_INSNS (23),                   /* cost of FADD and FSUB insns.  */
272   COSTS_N_INSNS (27),                   /* cost of FMUL instruction.  */
273   COSTS_N_INSNS (88),                   /* cost of FDIV instruction.  */
274   COSTS_N_INSNS (22),                   /* cost of FABS instruction.  */
275   COSTS_N_INSNS (24),                   /* cost of FCHS instruction.  */
276   COSTS_N_INSNS (122),                  /* cost of FSQRT instruction.  */
277   i386_memcpy,
278   i386_memset,
279   1,                                    /* scalar_stmt_cost.  */
280   1,                                    /* scalar load_cost.  */
281   1,                                    /* scalar_store_cost.  */
282   1,                                    /* vec_stmt_cost.  */
283   1,                                    /* vec_to_scalar_cost.  */
284   1,                                    /* scalar_to_vec_cost.  */
285   1,                                    /* vec_align_load_cost.  */
286   2,                                    /* vec_unalign_load_cost.  */
287   1,                                    /* vec_store_cost.  */
288   3,                                    /* cond_taken_branch_cost.  */
289   1,                                    /* cond_not_taken_branch_cost.  */
290 };
291
292 static stringop_algs i486_memcpy[2] = {
293   {rep_prefix_4_byte, {{-1, rep_prefix_4_byte, false}}},
294   DUMMY_STRINGOP_ALGS};
295 static stringop_algs i486_memset[2] = {
296   {rep_prefix_4_byte, {{-1, rep_prefix_4_byte, false}}},
297   DUMMY_STRINGOP_ALGS};
298
299 static const
300 struct processor_costs i486_cost = {    /* 486 specific costs */
301   COSTS_N_INSNS (1),                    /* cost of an add instruction */
302   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
303   COSTS_N_INSNS (3),                    /* variable shift costs */
304   COSTS_N_INSNS (2),                    /* constant shift costs */
305   {COSTS_N_INSNS (12),                  /* cost of starting multiply for QI */
306    COSTS_N_INSNS (12),                  /*                               HI */
307    COSTS_N_INSNS (12),                  /*                               SI */
308    COSTS_N_INSNS (12),                  /*                               DI */
309    COSTS_N_INSNS (12)},                 /*                            other */
310   1,                                    /* cost of multiply per each bit set */
311   {COSTS_N_INSNS (40),                  /* cost of a divide/mod for QI */
312    COSTS_N_INSNS (40),                  /*                          HI */
313    COSTS_N_INSNS (40),                  /*                          SI */
314    COSTS_N_INSNS (40),                  /*                          DI */
315    COSTS_N_INSNS (40)},                 /*                          other */
316   COSTS_N_INSNS (3),                    /* cost of movsx */
317   COSTS_N_INSNS (2),                    /* cost of movzx */
318   15,                                   /* "large" insn */
319   3,                                    /* MOVE_RATIO */
320   4,                                 /* cost for loading QImode using movzbl */
321   {2, 4, 2},                            /* cost of loading integer registers
322                                            in QImode, HImode and SImode.
323                                            Relative to reg-reg move (2).  */
324   {2, 4, 2},                            /* cost of storing integer registers */
325   2,                                    /* cost of reg,reg fld/fst */
326   {8, 8, 8},                            /* cost of loading fp registers
327                                            in SFmode, DFmode and XFmode */
328   {8, 8, 8},                            /* cost of storing fp registers
329                                            in SFmode, DFmode and XFmode */
330   2,                                    /* cost of moving MMX register */
331   {4, 8},                               /* cost of loading MMX registers
332                                            in SImode and DImode */
333   {4, 8},                               /* cost of storing MMX registers
334                                            in SImode and DImode */
335   2,                                    /* cost of moving SSE register */
336   {4, 8, 16},                           /* cost of loading SSE registers
337                                            in SImode, DImode and TImode */
338   {4, 8, 16},                           /* cost of storing SSE registers
339                                            in SImode, DImode and TImode */
340   3,                                    /* MMX or SSE register to integer */
341   4,                                    /* size of l1 cache.  486 has 8kB cache
342                                            shared for code and data, so 4kB is
343                                            not really precise.  */
344   4,                                    /* size of l2 cache  */
345   0,                                    /* size of prefetch block */
346   0,                                    /* number of parallel prefetches */
347   1,                                    /* Branch cost */
348   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
349   COSTS_N_INSNS (16),                   /* cost of FMUL instruction.  */
350   COSTS_N_INSNS (73),                   /* cost of FDIV instruction.  */
351   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
352   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
353   COSTS_N_INSNS (83),                   /* cost of FSQRT instruction.  */
354   i486_memcpy,
355   i486_memset,
356   1,                                    /* scalar_stmt_cost.  */
357   1,                                    /* scalar load_cost.  */
358   1,                                    /* scalar_store_cost.  */
359   1,                                    /* vec_stmt_cost.  */
360   1,                                    /* vec_to_scalar_cost.  */
361   1,                                    /* scalar_to_vec_cost.  */
362   1,                                    /* vec_align_load_cost.  */
363   2,                                    /* vec_unalign_load_cost.  */
364   1,                                    /* vec_store_cost.  */
365   3,                                    /* cond_taken_branch_cost.  */
366   1,                                    /* cond_not_taken_branch_cost.  */
367 };
368
369 static stringop_algs pentium_memcpy[2] = {
370   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
371   DUMMY_STRINGOP_ALGS};
372 static stringop_algs pentium_memset[2] = {
373   {libcall, {{-1, rep_prefix_4_byte, false}}},
374   DUMMY_STRINGOP_ALGS};
375
376 static const
377 struct processor_costs pentium_cost = {
378   COSTS_N_INSNS (1),                    /* cost of an add instruction */
379   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
380   COSTS_N_INSNS (4),                    /* variable shift costs */
381   COSTS_N_INSNS (1),                    /* constant shift costs */
382   {COSTS_N_INSNS (11),                  /* cost of starting multiply for QI */
383    COSTS_N_INSNS (11),                  /*                               HI */
384    COSTS_N_INSNS (11),                  /*                               SI */
385    COSTS_N_INSNS (11),                  /*                               DI */
386    COSTS_N_INSNS (11)},                 /*                            other */
387   0,                                    /* cost of multiply per each bit set */
388   {COSTS_N_INSNS (25),                  /* cost of a divide/mod for QI */
389    COSTS_N_INSNS (25),                  /*                          HI */
390    COSTS_N_INSNS (25),                  /*                          SI */
391    COSTS_N_INSNS (25),                  /*                          DI */
392    COSTS_N_INSNS (25)},                 /*                          other */
393   COSTS_N_INSNS (3),                    /* cost of movsx */
394   COSTS_N_INSNS (2),                    /* cost of movzx */
395   8,                                    /* "large" insn */
396   6,                                    /* MOVE_RATIO */
397   6,                                 /* cost for loading QImode using movzbl */
398   {2, 4, 2},                            /* cost of loading integer registers
399                                            in QImode, HImode and SImode.
400                                            Relative to reg-reg move (2).  */
401   {2, 4, 2},                            /* cost of storing integer registers */
402   2,                                    /* cost of reg,reg fld/fst */
403   {2, 2, 6},                            /* cost of loading fp registers
404                                            in SFmode, DFmode and XFmode */
405   {4, 4, 6},                            /* cost of storing fp registers
406                                            in SFmode, DFmode and XFmode */
407   8,                                    /* cost of moving MMX register */
408   {8, 8},                               /* cost of loading MMX registers
409                                            in SImode and DImode */
410   {8, 8},                               /* cost of storing MMX registers
411                                            in SImode and DImode */
412   2,                                    /* cost of moving SSE register */
413   {4, 8, 16},                           /* cost of loading SSE registers
414                                            in SImode, DImode and TImode */
415   {4, 8, 16},                           /* cost of storing SSE registers
416                                            in SImode, DImode and TImode */
417   3,                                    /* MMX or SSE register to integer */
418   8,                                    /* size of l1 cache.  */
419   8,                                    /* size of l2 cache  */
420   0,                                    /* size of prefetch block */
421   0,                                    /* number of parallel prefetches */
422   2,                                    /* Branch cost */
423   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
424   COSTS_N_INSNS (3),                    /* cost of FMUL instruction.  */
425   COSTS_N_INSNS (39),                   /* cost of FDIV instruction.  */
426   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
427   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
428   COSTS_N_INSNS (70),                   /* cost of FSQRT instruction.  */
429   pentium_memcpy,
430   pentium_memset,
431   1,                                    /* scalar_stmt_cost.  */
432   1,                                    /* scalar load_cost.  */
433   1,                                    /* scalar_store_cost.  */
434   1,                                    /* vec_stmt_cost.  */
435   1,                                    /* vec_to_scalar_cost.  */
436   1,                                    /* scalar_to_vec_cost.  */
437   1,                                    /* vec_align_load_cost.  */
438   2,                                    /* vec_unalign_load_cost.  */
439   1,                                    /* vec_store_cost.  */
440   3,                                    /* cond_taken_branch_cost.  */
441   1,                                    /* cond_not_taken_branch_cost.  */
442 };
443
444 /* PentiumPro has optimized rep instructions for blocks aligned by 8 bytes
445    (we ensure the alignment).  For small blocks inline loop is still a
446    noticeable win, for bigger blocks either rep movsl or rep movsb is
447    way to go.  Rep movsb has apparently more expensive startup time in CPU,
448    but after 4K the difference is down in the noise.  */
449 static stringop_algs pentiumpro_memcpy[2] = {
450   {rep_prefix_4_byte, {{128, loop, false}, {1024, unrolled_loop, false},
451                        {8192, rep_prefix_4_byte, false},
452                        {-1, rep_prefix_1_byte, false}}},
453   DUMMY_STRINGOP_ALGS};
454 static stringop_algs pentiumpro_memset[2] = {
455   {rep_prefix_4_byte, {{1024, unrolled_loop, false},
456                        {8192, rep_prefix_4_byte, false},
457                        {-1, libcall, false}}},
458   DUMMY_STRINGOP_ALGS};
459 static const
460 struct processor_costs pentiumpro_cost = {
461   COSTS_N_INSNS (1),                    /* cost of an add instruction */
462   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
463   COSTS_N_INSNS (1),                    /* variable shift costs */
464   COSTS_N_INSNS (1),                    /* constant shift costs */
465   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
466    COSTS_N_INSNS (4),                   /*                               HI */
467    COSTS_N_INSNS (4),                   /*                               SI */
468    COSTS_N_INSNS (4),                   /*                               DI */
469    COSTS_N_INSNS (4)},                  /*                            other */
470   0,                                    /* cost of multiply per each bit set */
471   {COSTS_N_INSNS (17),                  /* cost of a divide/mod for QI */
472    COSTS_N_INSNS (17),                  /*                          HI */
473    COSTS_N_INSNS (17),                  /*                          SI */
474    COSTS_N_INSNS (17),                  /*                          DI */
475    COSTS_N_INSNS (17)},                 /*                          other */
476   COSTS_N_INSNS (1),                    /* cost of movsx */
477   COSTS_N_INSNS (1),                    /* cost of movzx */
478   8,                                    /* "large" insn */
479   6,                                    /* MOVE_RATIO */
480   2,                                 /* cost for loading QImode using movzbl */
481   {4, 4, 4},                            /* cost of loading integer registers
482                                            in QImode, HImode and SImode.
483                                            Relative to reg-reg move (2).  */
484   {2, 2, 2},                            /* cost of storing integer registers */
485   2,                                    /* cost of reg,reg fld/fst */
486   {2, 2, 6},                            /* cost of loading fp registers
487                                            in SFmode, DFmode and XFmode */
488   {4, 4, 6},                            /* cost of storing fp registers
489                                            in SFmode, DFmode and XFmode */
490   2,                                    /* cost of moving MMX register */
491   {2, 2},                               /* cost of loading MMX registers
492                                            in SImode and DImode */
493   {2, 2},                               /* cost of storing MMX registers
494                                            in SImode and DImode */
495   2,                                    /* cost of moving SSE register */
496   {2, 2, 8},                            /* cost of loading SSE registers
497                                            in SImode, DImode and TImode */
498   {2, 2, 8},                            /* cost of storing SSE registers
499                                            in SImode, DImode and TImode */
500   3,                                    /* MMX or SSE register to integer */
501   8,                                    /* size of l1 cache.  */
502   256,                                  /* size of l2 cache  */
503   32,                                   /* size of prefetch block */
504   6,                                    /* number of parallel prefetches */
505   2,                                    /* Branch cost */
506   COSTS_N_INSNS (3),                    /* cost of FADD and FSUB insns.  */
507   COSTS_N_INSNS (5),                    /* cost of FMUL instruction.  */
508   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
509   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
510   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
511   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
512   pentiumpro_memcpy,
513   pentiumpro_memset,
514   1,                                    /* scalar_stmt_cost.  */
515   1,                                    /* scalar load_cost.  */
516   1,                                    /* scalar_store_cost.  */
517   1,                                    /* vec_stmt_cost.  */
518   1,                                    /* vec_to_scalar_cost.  */
519   1,                                    /* scalar_to_vec_cost.  */
520   1,                                    /* vec_align_load_cost.  */
521   2,                                    /* vec_unalign_load_cost.  */
522   1,                                    /* vec_store_cost.  */
523   3,                                    /* cond_taken_branch_cost.  */
524   1,                                    /* cond_not_taken_branch_cost.  */
525 };
526
527 static stringop_algs geode_memcpy[2] = {
528   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
529   DUMMY_STRINGOP_ALGS};
530 static stringop_algs geode_memset[2] = {
531   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
532   DUMMY_STRINGOP_ALGS};
533 static const
534 struct processor_costs geode_cost = {
535   COSTS_N_INSNS (1),                    /* cost of an add instruction */
536   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
537   COSTS_N_INSNS (2),                    /* variable shift costs */
538   COSTS_N_INSNS (1),                    /* constant shift costs */
539   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
540    COSTS_N_INSNS (4),                   /*                               HI */
541    COSTS_N_INSNS (7),                   /*                               SI */
542    COSTS_N_INSNS (7),                   /*                               DI */
543    COSTS_N_INSNS (7)},                  /*                            other */
544   0,                                    /* cost of multiply per each bit set */
545   {COSTS_N_INSNS (15),                  /* cost of a divide/mod for QI */
546    COSTS_N_INSNS (23),                  /*                          HI */
547    COSTS_N_INSNS (39),                  /*                          SI */
548    COSTS_N_INSNS (39),                  /*                          DI */
549    COSTS_N_INSNS (39)},                 /*                          other */
550   COSTS_N_INSNS (1),                    /* cost of movsx */
551   COSTS_N_INSNS (1),                    /* cost of movzx */
552   8,                                    /* "large" insn */
553   4,                                    /* MOVE_RATIO */
554   1,                                 /* cost for loading QImode using movzbl */
555   {1, 1, 1},                            /* cost of loading integer registers
556                                            in QImode, HImode and SImode.
557                                            Relative to reg-reg move (2).  */
558   {1, 1, 1},                            /* cost of storing integer registers */
559   1,                                    /* cost of reg,reg fld/fst */
560   {1, 1, 1},                            /* cost of loading fp registers
561                                            in SFmode, DFmode and XFmode */
562   {4, 6, 6},                            /* cost of storing fp registers
563                                            in SFmode, DFmode and XFmode */
564
565   1,                                    /* cost of moving MMX register */
566   {1, 1},                               /* cost of loading MMX registers
567                                            in SImode and DImode */
568   {1, 1},                               /* cost of storing MMX registers
569                                            in SImode and DImode */
570   1,                                    /* cost of moving SSE register */
571   {1, 1, 1},                            /* cost of loading SSE registers
572                                            in SImode, DImode and TImode */
573   {1, 1, 1},                            /* cost of storing SSE registers
574                                            in SImode, DImode and TImode */
575   1,                                    /* MMX or SSE register to integer */
576   64,                                   /* size of l1 cache.  */
577   128,                                  /* size of l2 cache.  */
578   32,                                   /* size of prefetch block */
579   1,                                    /* number of parallel prefetches */
580   1,                                    /* Branch cost */
581   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
582   COSTS_N_INSNS (11),                   /* cost of FMUL instruction.  */
583   COSTS_N_INSNS (47),                   /* cost of FDIV instruction.  */
584   COSTS_N_INSNS (1),                    /* cost of FABS instruction.  */
585   COSTS_N_INSNS (1),                    /* cost of FCHS instruction.  */
586   COSTS_N_INSNS (54),                   /* cost of FSQRT instruction.  */
587   geode_memcpy,
588   geode_memset,
589   1,                                    /* scalar_stmt_cost.  */
590   1,                                    /* scalar load_cost.  */
591   1,                                    /* scalar_store_cost.  */
592   1,                                    /* vec_stmt_cost.  */
593   1,                                    /* vec_to_scalar_cost.  */
594   1,                                    /* scalar_to_vec_cost.  */
595   1,                                    /* vec_align_load_cost.  */
596   2,                                    /* vec_unalign_load_cost.  */
597   1,                                    /* vec_store_cost.  */
598   3,                                    /* cond_taken_branch_cost.  */
599   1,                                    /* cond_not_taken_branch_cost.  */
600 };
601
602 static stringop_algs k6_memcpy[2] = {
603   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
604   DUMMY_STRINGOP_ALGS};
605 static stringop_algs k6_memset[2] = {
606   {libcall, {{256, rep_prefix_4_byte, false}, {-1, libcall, false}}},
607   DUMMY_STRINGOP_ALGS};
608 static const
609 struct processor_costs k6_cost = {
610   COSTS_N_INSNS (1),                    /* cost of an add instruction */
611   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
612   COSTS_N_INSNS (1),                    /* variable shift costs */
613   COSTS_N_INSNS (1),                    /* constant shift costs */
614   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
615    COSTS_N_INSNS (3),                   /*                               HI */
616    COSTS_N_INSNS (3),                   /*                               SI */
617    COSTS_N_INSNS (3),                   /*                               DI */
618    COSTS_N_INSNS (3)},                  /*                            other */
619   0,                                    /* cost of multiply per each bit set */
620   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
621    COSTS_N_INSNS (18),                  /*                          HI */
622    COSTS_N_INSNS (18),                  /*                          SI */
623    COSTS_N_INSNS (18),                  /*                          DI */
624    COSTS_N_INSNS (18)},                 /*                          other */
625   COSTS_N_INSNS (2),                    /* cost of movsx */
626   COSTS_N_INSNS (2),                    /* cost of movzx */
627   8,                                    /* "large" insn */
628   4,                                    /* MOVE_RATIO */
629   3,                                 /* cost for loading QImode using movzbl */
630   {4, 5, 4},                            /* cost of loading integer registers
631                                            in QImode, HImode and SImode.
632                                            Relative to reg-reg move (2).  */
633   {2, 3, 2},                            /* cost of storing integer registers */
634   4,                                    /* cost of reg,reg fld/fst */
635   {6, 6, 6},                            /* cost of loading fp registers
636                                            in SFmode, DFmode and XFmode */
637   {4, 4, 4},                            /* cost of storing fp registers
638                                            in SFmode, DFmode and XFmode */
639   2,                                    /* cost of moving MMX register */
640   {2, 2},                               /* cost of loading MMX registers
641                                            in SImode and DImode */
642   {2, 2},                               /* cost of storing MMX registers
643                                            in SImode and DImode */
644   2,                                    /* cost of moving SSE register */
645   {2, 2, 8},                            /* cost of loading SSE registers
646                                            in SImode, DImode and TImode */
647   {2, 2, 8},                            /* cost of storing SSE registers
648                                            in SImode, DImode and TImode */
649   6,                                    /* MMX or SSE register to integer */
650   32,                                   /* size of l1 cache.  */
651   32,                                   /* size of l2 cache.  Some models
652                                            have integrated l2 cache, but
653                                            optimizing for k6 is not important
654                                            enough to worry about that.  */
655   32,                                   /* size of prefetch block */
656   1,                                    /* number of parallel prefetches */
657   1,                                    /* Branch cost */
658   COSTS_N_INSNS (2),                    /* cost of FADD and FSUB insns.  */
659   COSTS_N_INSNS (2),                    /* cost of FMUL instruction.  */
660   COSTS_N_INSNS (56),                   /* cost of FDIV instruction.  */
661   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
662   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
663   COSTS_N_INSNS (56),                   /* cost of FSQRT instruction.  */
664   k6_memcpy,
665   k6_memset,
666   1,                                    /* scalar_stmt_cost.  */
667   1,                                    /* scalar load_cost.  */
668   1,                                    /* scalar_store_cost.  */
669   1,                                    /* vec_stmt_cost.  */
670   1,                                    /* vec_to_scalar_cost.  */
671   1,                                    /* scalar_to_vec_cost.  */
672   1,                                    /* vec_align_load_cost.  */
673   2,                                    /* vec_unalign_load_cost.  */
674   1,                                    /* vec_store_cost.  */
675   3,                                    /* cond_taken_branch_cost.  */
676   1,                                    /* cond_not_taken_branch_cost.  */
677 };
678
679 /* For some reason, Athlon deals better with REP prefix (relative to loops)
680    compared to K8. Alignment becomes important after 8 bytes for memcpy and
681    128 bytes for memset.  */
682 static stringop_algs athlon_memcpy[2] = {
683   {libcall, {{2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
684   DUMMY_STRINGOP_ALGS};
685 static stringop_algs athlon_memset[2] = {
686   {libcall, {{2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
687   DUMMY_STRINGOP_ALGS};
688 static const
689 struct processor_costs athlon_cost = {
690   COSTS_N_INSNS (1),                    /* cost of an add instruction */
691   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
692   COSTS_N_INSNS (1),                    /* variable shift costs */
693   COSTS_N_INSNS (1),                    /* constant shift costs */
694   {COSTS_N_INSNS (5),                   /* cost of starting multiply for QI */
695    COSTS_N_INSNS (5),                   /*                               HI */
696    COSTS_N_INSNS (5),                   /*                               SI */
697    COSTS_N_INSNS (5),                   /*                               DI */
698    COSTS_N_INSNS (5)},                  /*                            other */
699   0,                                    /* cost of multiply per each bit set */
700   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
701    COSTS_N_INSNS (26),                  /*                          HI */
702    COSTS_N_INSNS (42),                  /*                          SI */
703    COSTS_N_INSNS (74),                  /*                          DI */
704    COSTS_N_INSNS (74)},                 /*                          other */
705   COSTS_N_INSNS (1),                    /* cost of movsx */
706   COSTS_N_INSNS (1),                    /* cost of movzx */
707   8,                                    /* "large" insn */
708   9,                                    /* MOVE_RATIO */
709   4,                                 /* cost for loading QImode using movzbl */
710   {3, 4, 3},                            /* cost of loading integer registers
711                                            in QImode, HImode and SImode.
712                                            Relative to reg-reg move (2).  */
713   {3, 4, 3},                            /* cost of storing integer registers */
714   4,                                    /* cost of reg,reg fld/fst */
715   {4, 4, 12},                           /* cost of loading fp registers
716                                            in SFmode, DFmode and XFmode */
717   {6, 6, 8},                            /* cost of storing fp registers
718                                            in SFmode, DFmode and XFmode */
719   2,                                    /* cost of moving MMX register */
720   {4, 4},                               /* cost of loading MMX registers
721                                            in SImode and DImode */
722   {4, 4},                               /* cost of storing MMX registers
723                                            in SImode and DImode */
724   2,                                    /* cost of moving SSE register */
725   {4, 4, 6},                            /* cost of loading SSE registers
726                                            in SImode, DImode and TImode */
727   {4, 4, 5},                            /* cost of storing SSE registers
728                                            in SImode, DImode and TImode */
729   5,                                    /* MMX or SSE register to integer */
730   64,                                   /* size of l1 cache.  */
731   256,                                  /* size of l2 cache.  */
732   64,                                   /* size of prefetch block */
733   6,                                    /* number of parallel prefetches */
734   5,                                    /* Branch cost */
735   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
736   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
737   COSTS_N_INSNS (24),                   /* cost of FDIV instruction.  */
738   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
739   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
740   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
741   athlon_memcpy,
742   athlon_memset,
743   1,                                    /* scalar_stmt_cost.  */
744   1,                                    /* scalar load_cost.  */
745   1,                                    /* scalar_store_cost.  */
746   1,                                    /* vec_stmt_cost.  */
747   1,                                    /* vec_to_scalar_cost.  */
748   1,                                    /* scalar_to_vec_cost.  */
749   1,                                    /* vec_align_load_cost.  */
750   2,                                    /* vec_unalign_load_cost.  */
751   1,                                    /* vec_store_cost.  */
752   3,                                    /* cond_taken_branch_cost.  */
753   1,                                    /* cond_not_taken_branch_cost.  */
754 };
755
756 /* K8 has optimized REP instruction for medium sized blocks, but for very
757    small blocks it is better to use loop. For large blocks, libcall can
758    do nontemporary accesses and beat inline considerably.  */
759 static stringop_algs k8_memcpy[2] = {
760   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
761              {-1, rep_prefix_4_byte, false}}},
762   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
763              {-1, libcall, false}}}};
764 static stringop_algs k8_memset[2] = {
765   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
766              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
767   {libcall, {{48, unrolled_loop, false},
768              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
769 static const
770 struct processor_costs k8_cost = {
771   COSTS_N_INSNS (1),                    /* cost of an add instruction */
772   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
773   COSTS_N_INSNS (1),                    /* variable shift costs */
774   COSTS_N_INSNS (1),                    /* constant shift costs */
775   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
776    COSTS_N_INSNS (4),                   /*                               HI */
777    COSTS_N_INSNS (3),                   /*                               SI */
778    COSTS_N_INSNS (4),                   /*                               DI */
779    COSTS_N_INSNS (5)},                  /*                            other */
780   0,                                    /* cost of multiply per each bit set */
781   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
782    COSTS_N_INSNS (26),                  /*                          HI */
783    COSTS_N_INSNS (42),                  /*                          SI */
784    COSTS_N_INSNS (74),                  /*                          DI */
785    COSTS_N_INSNS (74)},                 /*                          other */
786   COSTS_N_INSNS (1),                    /* cost of movsx */
787   COSTS_N_INSNS (1),                    /* cost of movzx */
788   8,                                    /* "large" insn */
789   9,                                    /* MOVE_RATIO */
790   4,                                 /* cost for loading QImode using movzbl */
791   {3, 4, 3},                            /* cost of loading integer registers
792                                            in QImode, HImode and SImode.
793                                            Relative to reg-reg move (2).  */
794   {3, 4, 3},                            /* cost of storing integer registers */
795   4,                                    /* cost of reg,reg fld/fst */
796   {4, 4, 12},                           /* cost of loading fp registers
797                                            in SFmode, DFmode and XFmode */
798   {6, 6, 8},                            /* cost of storing fp registers
799                                            in SFmode, DFmode and XFmode */
800   2,                                    /* cost of moving MMX register */
801   {3, 3},                               /* cost of loading MMX registers
802                                            in SImode and DImode */
803   {4, 4},                               /* cost of storing MMX registers
804                                            in SImode and DImode */
805   2,                                    /* cost of moving SSE register */
806   {4, 3, 6},                            /* cost of loading SSE registers
807                                            in SImode, DImode and TImode */
808   {4, 4, 5},                            /* cost of storing SSE registers
809                                            in SImode, DImode and TImode */
810   5,                                    /* MMX or SSE register to integer */
811   64,                                   /* size of l1 cache.  */
812   512,                                  /* size of l2 cache.  */
813   64,                                   /* size of prefetch block */
814   /* New AMD processors never drop prefetches; if they cannot be performed
815      immediately, they are queued.  We set number of simultaneous prefetches
816      to a large constant to reflect this (it probably is not a good idea not
817      to limit number of prefetches at all, as their execution also takes some
818      time).  */
819   100,                                  /* number of parallel prefetches */
820   3,                                    /* Branch cost */
821   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
822   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
823   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
824   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
825   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
826   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
827
828   k8_memcpy,
829   k8_memset,
830   4,                                    /* scalar_stmt_cost.  */
831   2,                                    /* scalar load_cost.  */
832   2,                                    /* scalar_store_cost.  */
833   5,                                    /* vec_stmt_cost.  */
834   0,                                    /* vec_to_scalar_cost.  */
835   2,                                    /* scalar_to_vec_cost.  */
836   2,                                    /* vec_align_load_cost.  */
837   3,                                    /* vec_unalign_load_cost.  */
838   3,                                    /* vec_store_cost.  */
839   3,                                    /* cond_taken_branch_cost.  */
840   2,                                    /* cond_not_taken_branch_cost.  */
841 };
842
843 /* AMDFAM10 has optimized REP instruction for medium sized blocks, but for
844    very small blocks it is better to use loop. For large blocks, libcall can
845    do nontemporary accesses and beat inline considerably.  */
846 static stringop_algs amdfam10_memcpy[2] = {
847   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
848              {-1, rep_prefix_4_byte, false}}},
849   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
850              {-1, libcall, false}}}};
851 static stringop_algs amdfam10_memset[2] = {
852   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
853              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
854   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
855              {-1, libcall, false}}}};
856 struct processor_costs amdfam10_cost = {
857   COSTS_N_INSNS (1),                    /* cost of an add instruction */
858   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
859   COSTS_N_INSNS (1),                    /* variable shift costs */
860   COSTS_N_INSNS (1),                    /* constant shift costs */
861   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
862    COSTS_N_INSNS (4),                   /*                               HI */
863    COSTS_N_INSNS (3),                   /*                               SI */
864    COSTS_N_INSNS (4),                   /*                               DI */
865    COSTS_N_INSNS (5)},                  /*                            other */
866   0,                                    /* cost of multiply per each bit set */
867   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
868    COSTS_N_INSNS (35),                  /*                          HI */
869    COSTS_N_INSNS (51),                  /*                          SI */
870    COSTS_N_INSNS (83),                  /*                          DI */
871    COSTS_N_INSNS (83)},                 /*                          other */
872   COSTS_N_INSNS (1),                    /* cost of movsx */
873   COSTS_N_INSNS (1),                    /* cost of movzx */
874   8,                                    /* "large" insn */
875   9,                                    /* MOVE_RATIO */
876   4,                                 /* cost for loading QImode using movzbl */
877   {3, 4, 3},                            /* cost of loading integer registers
878                                            in QImode, HImode and SImode.
879                                            Relative to reg-reg move (2).  */
880   {3, 4, 3},                            /* cost of storing integer registers */
881   4,                                    /* cost of reg,reg fld/fst */
882   {4, 4, 12},                           /* cost of loading fp registers
883                                            in SFmode, DFmode and XFmode */
884   {6, 6, 8},                            /* cost of storing fp registers
885                                            in SFmode, DFmode and XFmode */
886   2,                                    /* cost of moving MMX register */
887   {3, 3},                               /* cost of loading MMX registers
888                                            in SImode and DImode */
889   {4, 4},                               /* cost of storing MMX registers
890                                            in SImode and DImode */
891   2,                                    /* cost of moving SSE register */
892   {4, 4, 3},                            /* cost of loading SSE registers
893                                            in SImode, DImode and TImode */
894   {4, 4, 5},                            /* cost of storing SSE registers
895                                            in SImode, DImode and TImode */
896   3,                                    /* MMX or SSE register to integer */
897                                         /* On K8:
898                                             MOVD reg64, xmmreg Double FSTORE 4
899                                             MOVD reg32, xmmreg Double FSTORE 4
900                                            On AMDFAM10:
901                                             MOVD reg64, xmmreg Double FADD 3
902                                                                1/1  1/1
903                                             MOVD reg32, xmmreg Double FADD 3
904                                                                1/1  1/1 */
905   64,                                   /* size of l1 cache.  */
906   512,                                  /* size of l2 cache.  */
907   64,                                   /* size of prefetch block */
908   /* New AMD processors never drop prefetches; if they cannot be performed
909      immediately, they are queued.  We set number of simultaneous prefetches
910      to a large constant to reflect this (it probably is not a good idea not
911      to limit number of prefetches at all, as their execution also takes some
912      time).  */
913   100,                                  /* number of parallel prefetches */
914   2,                                    /* Branch cost */
915   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
916   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
917   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
918   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
919   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
920   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
921
922   amdfam10_memcpy,
923   amdfam10_memset,
924   4,                                    /* scalar_stmt_cost.  */
925   2,                                    /* scalar load_cost.  */
926   2,                                    /* scalar_store_cost.  */
927   6,                                    /* vec_stmt_cost.  */
928   0,                                    /* vec_to_scalar_cost.  */
929   2,                                    /* scalar_to_vec_cost.  */
930   2,                                    /* vec_align_load_cost.  */
931   2,                                    /* vec_unalign_load_cost.  */
932   2,                                    /* vec_store_cost.  */
933   2,                                    /* cond_taken_branch_cost.  */
934   1,                                    /* cond_not_taken_branch_cost.  */
935 };
936
937 /*  BDVER1 has optimized REP instruction for medium sized blocks, but for
938     very small blocks it is better to use loop. For large blocks, libcall
939     can do nontemporary accesses and beat inline considerably.  */
940 static stringop_algs bdver1_memcpy[2] = {
941   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
942              {-1, rep_prefix_4_byte, false}}},
943   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
944              {-1, libcall, false}}}};
945 static stringop_algs bdver1_memset[2] = {
946   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
947              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
948   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
949              {-1, libcall, false}}}};
950
951 const struct processor_costs bdver1_cost = {
952   COSTS_N_INSNS (1),                    /* cost of an add instruction */
953   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
954   COSTS_N_INSNS (1),                    /* variable shift costs */
955   COSTS_N_INSNS (1),                    /* constant shift costs */
956   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
957    COSTS_N_INSNS (4),                   /*                               HI */
958    COSTS_N_INSNS (4),                   /*                               SI */
959    COSTS_N_INSNS (6),                   /*                               DI */
960    COSTS_N_INSNS (6)},                  /*                            other */
961   0,                                    /* cost of multiply per each bit set */
962   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
963    COSTS_N_INSNS (35),                  /*                          HI */
964    COSTS_N_INSNS (51),                  /*                          SI */
965    COSTS_N_INSNS (83),                  /*                          DI */
966    COSTS_N_INSNS (83)},                 /*                          other */
967   COSTS_N_INSNS (1),                    /* cost of movsx */
968   COSTS_N_INSNS (1),                    /* cost of movzx */
969   8,                                    /* "large" insn */
970   9,                                    /* MOVE_RATIO */
971   4,                                 /* cost for loading QImode using movzbl */
972   {5, 5, 4},                            /* cost of loading integer registers
973                                            in QImode, HImode and SImode.
974                                            Relative to reg-reg move (2).  */
975   {4, 4, 4},                            /* cost of storing integer registers */
976   2,                                    /* cost of reg,reg fld/fst */
977   {5, 5, 12},                           /* cost of loading fp registers
978                                            in SFmode, DFmode and XFmode */
979   {4, 4, 8},                            /* cost of storing fp registers
980                                            in SFmode, DFmode and XFmode */
981   2,                                    /* cost of moving MMX register */
982   {4, 4},                               /* cost of loading MMX registers
983                                            in SImode and DImode */
984   {4, 4},                               /* cost of storing MMX registers
985                                            in SImode and DImode */
986   2,                                    /* cost of moving SSE register */
987   {4, 4, 4},                            /* cost of loading SSE registers
988                                            in SImode, DImode and TImode */
989   {4, 4, 4},                            /* cost of storing SSE registers
990                                            in SImode, DImode and TImode */
991   2,                                    /* MMX or SSE register to integer */
992                                         /* On K8:
993                                             MOVD reg64, xmmreg Double FSTORE 4
994                                             MOVD reg32, xmmreg Double FSTORE 4
995                                            On AMDFAM10:
996                                             MOVD reg64, xmmreg Double FADD 3
997                                                                1/1  1/1
998                                             MOVD reg32, xmmreg Double FADD 3
999                                                                1/1  1/1 */
1000   16,                                   /* size of l1 cache.  */
1001   2048,                                 /* size of l2 cache.  */
1002   64,                                   /* size of prefetch block */
1003   /* New AMD processors never drop prefetches; if they cannot be performed
1004      immediately, they are queued.  We set number of simultaneous prefetches
1005      to a large constant to reflect this (it probably is not a good idea not
1006      to limit number of prefetches at all, as their execution also takes some
1007      time).  */
1008   100,                                  /* number of parallel prefetches */
1009   2,                                    /* Branch cost */
1010   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1011   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1012   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1013   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1014   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1015   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1016
1017   bdver1_memcpy,
1018   bdver1_memset,
1019   6,                                    /* scalar_stmt_cost.  */
1020   4,                                    /* scalar load_cost.  */
1021   4,                                    /* scalar_store_cost.  */
1022   6,                                    /* vec_stmt_cost.  */
1023   0,                                    /* vec_to_scalar_cost.  */
1024   2,                                    /* scalar_to_vec_cost.  */
1025   4,                                    /* vec_align_load_cost.  */
1026   4,                                    /* vec_unalign_load_cost.  */
1027   4,                                    /* vec_store_cost.  */
1028   2,                                    /* cond_taken_branch_cost.  */
1029   1,                                    /* cond_not_taken_branch_cost.  */
1030 };
1031
1032 /*  BDVER2 has optimized REP instruction for medium sized blocks, but for
1033     very small blocks it is better to use loop. For large blocks, libcall
1034     can do nontemporary accesses and beat inline considerably.  */
1035
1036 static stringop_algs bdver2_memcpy[2] = {
1037   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1038              {-1, rep_prefix_4_byte, false}}},
1039   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1040              {-1, libcall, false}}}};
1041 static stringop_algs bdver2_memset[2] = {
1042   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1043              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1044   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1045              {-1, libcall, false}}}};
1046
1047 const struct processor_costs bdver2_cost = {
1048   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1049   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1050   COSTS_N_INSNS (1),                    /* variable shift costs */
1051   COSTS_N_INSNS (1),                    /* constant shift costs */
1052   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
1053    COSTS_N_INSNS (4),                   /*                               HI */
1054    COSTS_N_INSNS (4),                   /*                               SI */
1055    COSTS_N_INSNS (6),                   /*                               DI */
1056    COSTS_N_INSNS (6)},                  /*                            other */
1057   0,                                    /* cost of multiply per each bit set */
1058   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1059    COSTS_N_INSNS (35),                  /*                          HI */
1060    COSTS_N_INSNS (51),                  /*                          SI */
1061    COSTS_N_INSNS (83),                  /*                          DI */
1062    COSTS_N_INSNS (83)},                 /*                          other */
1063   COSTS_N_INSNS (1),                    /* cost of movsx */
1064   COSTS_N_INSNS (1),                    /* cost of movzx */
1065   8,                                    /* "large" insn */
1066   9,                                    /* MOVE_RATIO */
1067   4,                                 /* cost for loading QImode using movzbl */
1068   {5, 5, 4},                            /* cost of loading integer registers
1069                                            in QImode, HImode and SImode.
1070                                            Relative to reg-reg move (2).  */
1071   {4, 4, 4},                            /* cost of storing integer registers */
1072   2,                                    /* cost of reg,reg fld/fst */
1073   {5, 5, 12},                           /* cost of loading fp registers
1074                                            in SFmode, DFmode and XFmode */
1075   {4, 4, 8},                            /* cost of storing fp registers
1076                                            in SFmode, DFmode and XFmode */
1077   2,                                    /* cost of moving MMX register */
1078   {4, 4},                               /* cost of loading MMX registers
1079                                            in SImode and DImode */
1080   {4, 4},                               /* cost of storing MMX registers
1081                                            in SImode and DImode */
1082   2,                                    /* cost of moving SSE register */
1083   {4, 4, 4},                            /* cost of loading SSE registers
1084                                            in SImode, DImode and TImode */
1085   {4, 4, 4},                            /* cost of storing SSE registers
1086                                            in SImode, DImode and TImode */
1087   2,                                    /* MMX or SSE register to integer */
1088                                         /* On K8:
1089                                             MOVD reg64, xmmreg Double FSTORE 4
1090                                             MOVD reg32, xmmreg Double FSTORE 4
1091                                            On AMDFAM10:
1092                                             MOVD reg64, xmmreg Double FADD 3
1093                                                                1/1  1/1
1094                                             MOVD reg32, xmmreg Double FADD 3
1095                                                                1/1  1/1 */
1096   16,                                   /* size of l1 cache.  */
1097   2048,                                 /* size of l2 cache.  */
1098   64,                                   /* size of prefetch block */
1099   /* New AMD processors never drop prefetches; if they cannot be performed
1100      immediately, they are queued.  We set number of simultaneous prefetches
1101      to a large constant to reflect this (it probably is not a good idea not
1102      to limit number of prefetches at all, as their execution also takes some
1103      time).  */
1104   100,                                  /* number of parallel prefetches */
1105   2,                                    /* Branch cost */
1106   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1107   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1108   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1109   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1110   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1111   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1112
1113   bdver2_memcpy,
1114   bdver2_memset,
1115   6,                                    /* scalar_stmt_cost.  */
1116   4,                                    /* scalar load_cost.  */
1117   4,                                    /* scalar_store_cost.  */
1118   6,                                    /* vec_stmt_cost.  */
1119   0,                                    /* vec_to_scalar_cost.  */
1120   2,                                    /* scalar_to_vec_cost.  */
1121   4,                                    /* vec_align_load_cost.  */
1122   4,                                    /* vec_unalign_load_cost.  */
1123   4,                                    /* vec_store_cost.  */
1124   2,                                    /* cond_taken_branch_cost.  */
1125   1,                                    /* cond_not_taken_branch_cost.  */
1126 };
1127
1128
1129   /*  BDVER3 has optimized REP instruction for medium sized blocks, but for
1130       very small blocks it is better to use loop. For large blocks, libcall
1131       can do nontemporary accesses and beat inline considerably.  */
1132 static stringop_algs bdver3_memcpy[2] = {
1133   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1134              {-1, rep_prefix_4_byte, false}}},
1135   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1136              {-1, libcall, false}}}};
1137 static stringop_algs bdver3_memset[2] = {
1138   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1139              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1140   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1141              {-1, libcall, false}}}};
1142 struct processor_costs bdver3_cost = {
1143   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1144   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1145   COSTS_N_INSNS (1),                    /* variable shift costs */
1146   COSTS_N_INSNS (1),                    /* constant shift costs */
1147   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
1148    COSTS_N_INSNS (4),                   /*                               HI */
1149    COSTS_N_INSNS (4),                   /*                               SI */
1150    COSTS_N_INSNS (6),                   /*                               DI */
1151    COSTS_N_INSNS (6)},                  /*                            other */
1152   0,                                    /* cost of multiply per each bit set */
1153   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1154    COSTS_N_INSNS (35),                  /*                          HI */
1155    COSTS_N_INSNS (51),                  /*                          SI */
1156    COSTS_N_INSNS (83),                  /*                          DI */
1157    COSTS_N_INSNS (83)},                 /*                          other */
1158   COSTS_N_INSNS (1),                    /* cost of movsx */
1159   COSTS_N_INSNS (1),                    /* cost of movzx */
1160   8,                                    /* "large" insn */
1161   9,                                    /* MOVE_RATIO */
1162   4,                                 /* cost for loading QImode using movzbl */
1163   {5, 5, 4},                            /* cost of loading integer registers
1164                                            in QImode, HImode and SImode.
1165                                            Relative to reg-reg move (2).  */
1166   {4, 4, 4},                            /* cost of storing integer registers */
1167   2,                                    /* cost of reg,reg fld/fst */
1168   {5, 5, 12},                           /* cost of loading fp registers
1169                                            in SFmode, DFmode and XFmode */
1170   {4, 4, 8},                            /* cost of storing fp registers
1171                                            in SFmode, DFmode and XFmode */
1172   2,                                    /* cost of moving MMX register */
1173   {4, 4},                               /* cost of loading MMX registers
1174                                            in SImode and DImode */
1175   {4, 4},                               /* cost of storing MMX registers
1176                                            in SImode and DImode */
1177   2,                                    /* cost of moving SSE register */
1178   {4, 4, 4},                            /* cost of loading SSE registers
1179                                            in SImode, DImode and TImode */
1180   {4, 4, 4},                            /* cost of storing SSE registers
1181                                            in SImode, DImode and TImode */
1182   2,                                    /* MMX or SSE register to integer */
1183   16,                                   /* size of l1 cache.  */
1184   2048,                                 /* size of l2 cache.  */
1185   64,                                   /* size of prefetch block */
1186   /* New AMD processors never drop prefetches; if they cannot be performed
1187      immediately, they are queued.  We set number of simultaneous prefetches
1188      to a large constant to reflect this (it probably is not a good idea not
1189      to limit number of prefetches at all, as their execution also takes some
1190      time).  */
1191   100,                                  /* number of parallel prefetches */
1192   2,                                    /* Branch cost */
1193   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1194   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1195   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1196   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1197   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1198   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1199
1200   bdver3_memcpy,
1201   bdver3_memset,
1202   6,                                    /* scalar_stmt_cost.  */
1203   4,                                    /* scalar load_cost.  */
1204   4,                                    /* scalar_store_cost.  */
1205   6,                                    /* vec_stmt_cost.  */
1206   0,                                    /* vec_to_scalar_cost.  */
1207   2,                                    /* scalar_to_vec_cost.  */
1208   4,                                    /* vec_align_load_cost.  */
1209   4,                                    /* vec_unalign_load_cost.  */
1210   4,                                    /* vec_store_cost.  */
1211   2,                                    /* cond_taken_branch_cost.  */
1212   1,                                    /* cond_not_taken_branch_cost.  */
1213 };
1214
1215 /*  BDVER4 has optimized REP instruction for medium sized blocks, but for
1216     very small blocks it is better to use loop. For large blocks, libcall
1217     can do nontemporary accesses and beat inline considerably.  */
1218 static stringop_algs bdver4_memcpy[2] = {
1219   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1220              {-1, rep_prefix_4_byte, false}}},
1221   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1222              {-1, libcall, false}}}};
1223 static stringop_algs bdver4_memset[2] = {
1224   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1225              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1226   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1227              {-1, libcall, false}}}};
1228 struct processor_costs bdver4_cost = {
1229   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1230   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1231   COSTS_N_INSNS (1),                    /* variable shift costs */
1232   COSTS_N_INSNS (1),                    /* constant shift costs */
1233   {COSTS_N_INSNS (4),                   /* cost of starting multiply for QI */
1234    COSTS_N_INSNS (4),                   /*                               HI */
1235    COSTS_N_INSNS (4),                   /*                               SI */
1236    COSTS_N_INSNS (6),                   /*                               DI */
1237    COSTS_N_INSNS (6)},                  /*                            other */
1238   0,                                    /* cost of multiply per each bit set */
1239   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1240    COSTS_N_INSNS (35),                  /*                          HI */
1241    COSTS_N_INSNS (51),                  /*                          SI */
1242    COSTS_N_INSNS (83),                  /*                          DI */
1243    COSTS_N_INSNS (83)},                 /*                          other */
1244   COSTS_N_INSNS (1),                    /* cost of movsx */
1245   COSTS_N_INSNS (1),                    /* cost of movzx */
1246   8,                                    /* "large" insn */
1247   9,                                    /* MOVE_RATIO */
1248   4,                                 /* cost for loading QImode using movzbl */
1249   {5, 5, 4},                            /* cost of loading integer registers
1250                                            in QImode, HImode and SImode.
1251                                            Relative to reg-reg move (2).  */
1252   {4, 4, 4},                            /* cost of storing integer registers */
1253   2,                                    /* cost of reg,reg fld/fst */
1254   {5, 5, 12},                           /* cost of loading fp registers
1255                                            in SFmode, DFmode and XFmode */
1256   {4, 4, 8},                            /* cost of storing fp registers
1257                                            in SFmode, DFmode and XFmode */
1258   2,                                    /* cost of moving MMX register */
1259   {4, 4},                               /* cost of loading MMX registers
1260                                            in SImode and DImode */
1261   {4, 4},                               /* cost of storing MMX registers
1262                                            in SImode and DImode */
1263   2,                                    /* cost of moving SSE register */
1264   {4, 4, 4},                            /* cost of loading SSE registers
1265                                            in SImode, DImode and TImode */
1266   {4, 4, 4},                            /* cost of storing SSE registers
1267                                            in SImode, DImode and TImode */
1268   2,                                    /* MMX or SSE register to integer */
1269   16,                                   /* size of l1 cache.  */
1270   2048,                                 /* size of l2 cache.  */
1271   64,                                   /* size of prefetch block */
1272   /* New AMD processors never drop prefetches; if they cannot be performed
1273      immediately, they are queued.  We set number of simultaneous prefetches
1274      to a large constant to reflect this (it probably is not a good idea not
1275      to limit number of prefetches at all, as their execution also takes some
1276      time).  */
1277   100,                                  /* number of parallel prefetches */
1278   2,                                    /* Branch cost */
1279   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1280   COSTS_N_INSNS (6),                    /* cost of FMUL instruction.  */
1281   COSTS_N_INSNS (42),                   /* cost of FDIV instruction.  */
1282   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1283   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1284   COSTS_N_INSNS (52),                   /* cost of FSQRT instruction.  */
1285
1286   bdver4_memcpy,
1287   bdver4_memset,
1288   6,                                    /* scalar_stmt_cost.  */
1289   4,                                    /* scalar load_cost.  */
1290   4,                                    /* scalar_store_cost.  */
1291   6,                                    /* vec_stmt_cost.  */
1292   0,                                    /* vec_to_scalar_cost.  */
1293   2,                                    /* scalar_to_vec_cost.  */
1294   4,                                    /* vec_align_load_cost.  */
1295   4,                                    /* vec_unalign_load_cost.  */
1296   4,                                    /* vec_store_cost.  */
1297   2,                                    /* cond_taken_branch_cost.  */
1298   1,                                    /* cond_not_taken_branch_cost.  */
1299 };
1300
1301   /* BTVER1 has optimized REP instruction for medium sized blocks, but for
1302      very small blocks it is better to use loop. For large blocks, libcall can
1303      do nontemporary accesses and beat inline considerably.  */
1304 static stringop_algs btver1_memcpy[2] = {
1305   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1306              {-1, rep_prefix_4_byte, false}}},
1307   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1308              {-1, libcall, false}}}};
1309 static stringop_algs btver1_memset[2] = {
1310   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1311              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1312   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1313              {-1, libcall, false}}}};
1314 const struct processor_costs btver1_cost = {
1315   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1316   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
1317   COSTS_N_INSNS (1),                    /* variable shift costs */
1318   COSTS_N_INSNS (1),                    /* constant shift costs */
1319   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1320    COSTS_N_INSNS (4),                   /*                               HI */
1321    COSTS_N_INSNS (3),                   /*                               SI */
1322    COSTS_N_INSNS (4),                   /*                               DI */
1323    COSTS_N_INSNS (5)},                  /*                            other */
1324   0,                                    /* cost of multiply per each bit set */
1325   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1326    COSTS_N_INSNS (35),                  /*                          HI */
1327    COSTS_N_INSNS (51),                  /*                          SI */
1328    COSTS_N_INSNS (83),                  /*                          DI */
1329    COSTS_N_INSNS (83)},                 /*                          other */
1330   COSTS_N_INSNS (1),                    /* cost of movsx */
1331   COSTS_N_INSNS (1),                    /* cost of movzx */
1332   8,                                    /* "large" insn */
1333   9,                                    /* MOVE_RATIO */
1334   4,                                 /* cost for loading QImode using movzbl */
1335   {3, 4, 3},                            /* cost of loading integer registers
1336                                            in QImode, HImode and SImode.
1337                                            Relative to reg-reg move (2).  */
1338   {3, 4, 3},                            /* cost of storing integer registers */
1339   4,                                    /* cost of reg,reg fld/fst */
1340   {4, 4, 12},                           /* cost of loading fp registers
1341                                            in SFmode, DFmode and XFmode */
1342   {6, 6, 8},                            /* cost of storing fp registers
1343                                            in SFmode, DFmode and XFmode */
1344   2,                                    /* cost of moving MMX register */
1345   {3, 3},                               /* cost of loading MMX registers
1346                                            in SImode and DImode */
1347   {4, 4},                               /* cost of storing MMX registers
1348                                            in SImode and DImode */
1349   2,                                    /* cost of moving SSE register */
1350   {4, 4, 3},                            /* cost of loading SSE registers
1351                                            in SImode, DImode and TImode */
1352   {4, 4, 5},                            /* cost of storing SSE registers
1353                                            in SImode, DImode and TImode */
1354   3,                                    /* MMX or SSE register to integer */
1355                                         /* On K8:
1356                                            MOVD reg64, xmmreg Double FSTORE 4
1357                                            MOVD reg32, xmmreg Double FSTORE 4
1358                                            On AMDFAM10:
1359                                            MOVD reg64, xmmreg Double FADD 3
1360                                                                1/1  1/1
1361                                             MOVD reg32, xmmreg Double FADD 3
1362                                                                1/1  1/1 */
1363   32,                                   /* size of l1 cache.  */
1364   512,                                  /* size of l2 cache.  */
1365   64,                                   /* size of prefetch block */
1366   100,                                  /* number of parallel prefetches */
1367   2,                                    /* Branch cost */
1368   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
1369   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
1370   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
1371   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1372   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1373   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
1374
1375   btver1_memcpy,
1376   btver1_memset,
1377   4,                                    /* scalar_stmt_cost.  */
1378   2,                                    /* scalar load_cost.  */
1379   2,                                    /* scalar_store_cost.  */
1380   6,                                    /* vec_stmt_cost.  */
1381   0,                                    /* vec_to_scalar_cost.  */
1382   2,                                    /* scalar_to_vec_cost.  */
1383   2,                                    /* vec_align_load_cost.  */
1384   2,                                    /* vec_unalign_load_cost.  */
1385   2,                                    /* vec_store_cost.  */
1386   2,                                    /* cond_taken_branch_cost.  */
1387   1,                                    /* cond_not_taken_branch_cost.  */
1388 };
1389
1390 static stringop_algs btver2_memcpy[2] = {
1391   {libcall, {{6, loop, false}, {14, unrolled_loop, false},
1392              {-1, rep_prefix_4_byte, false}}},
1393   {libcall, {{16, loop, false}, {8192, rep_prefix_8_byte, false},
1394              {-1, libcall, false}}}};
1395 static stringop_algs btver2_memset[2] = {
1396   {libcall, {{8, loop, false}, {24, unrolled_loop, false},
1397              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1398   {libcall, {{48, unrolled_loop, false}, {8192, rep_prefix_8_byte, false},
1399              {-1, libcall, false}}}};
1400 const struct processor_costs btver2_cost = {
1401   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1402   COSTS_N_INSNS (2),                    /* cost of a lea instruction */
1403   COSTS_N_INSNS (1),                    /* variable shift costs */
1404   COSTS_N_INSNS (1),                    /* constant shift costs */
1405   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1406    COSTS_N_INSNS (4),                   /*                               HI */
1407    COSTS_N_INSNS (3),                   /*                               SI */
1408    COSTS_N_INSNS (4),                   /*                               DI */
1409    COSTS_N_INSNS (5)},                  /*                            other */
1410   0,                                    /* cost of multiply per each bit set */
1411   {COSTS_N_INSNS (19),                  /* cost of a divide/mod for QI */
1412    COSTS_N_INSNS (35),                  /*                          HI */
1413    COSTS_N_INSNS (51),                  /*                          SI */
1414    COSTS_N_INSNS (83),                  /*                          DI */
1415    COSTS_N_INSNS (83)},                 /*                          other */
1416   COSTS_N_INSNS (1),                    /* cost of movsx */
1417   COSTS_N_INSNS (1),                    /* cost of movzx */
1418   8,                                    /* "large" insn */
1419   9,                                    /* MOVE_RATIO */
1420   4,                                 /* cost for loading QImode using movzbl */
1421   {3, 4, 3},                            /* cost of loading integer registers
1422                                            in QImode, HImode and SImode.
1423                                            Relative to reg-reg move (2).  */
1424   {3, 4, 3},                            /* cost of storing integer registers */
1425   4,                                    /* cost of reg,reg fld/fst */
1426   {4, 4, 12},                           /* cost of loading fp registers
1427                                            in SFmode, DFmode and XFmode */
1428   {6, 6, 8},                            /* cost of storing fp registers
1429                                            in SFmode, DFmode and XFmode */
1430   2,                                    /* cost of moving MMX register */
1431   {3, 3},                               /* cost of loading MMX registers
1432                                            in SImode and DImode */
1433   {4, 4},                               /* cost of storing MMX registers
1434                                            in SImode and DImode */
1435   2,                                    /* cost of moving SSE register */
1436   {4, 4, 3},                            /* cost of loading SSE registers
1437                                            in SImode, DImode and TImode */
1438   {4, 4, 5},                            /* cost of storing SSE registers
1439                                            in SImode, DImode and TImode */
1440   3,                                    /* MMX or SSE register to integer */
1441                                         /* On K8:
1442                                            MOVD reg64, xmmreg Double FSTORE 4
1443                                            MOVD reg32, xmmreg Double FSTORE 4
1444                                            On AMDFAM10:
1445                                            MOVD reg64, xmmreg Double FADD 3
1446                                                                1/1  1/1
1447                                             MOVD reg32, xmmreg Double FADD 3
1448                                                                1/1  1/1 */
1449   32,                                   /* size of l1 cache.  */
1450   2048,                                 /* size of l2 cache.  */
1451   64,                                   /* size of prefetch block */
1452   100,                                  /* number of parallel prefetches */
1453   2,                                    /* Branch cost */
1454   COSTS_N_INSNS (4),                    /* cost of FADD and FSUB insns.  */
1455   COSTS_N_INSNS (4),                    /* cost of FMUL instruction.  */
1456   COSTS_N_INSNS (19),                   /* cost of FDIV instruction.  */
1457   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1458   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1459   COSTS_N_INSNS (35),                   /* cost of FSQRT instruction.  */
1460   btver2_memcpy,
1461   btver2_memset,
1462   4,                                    /* scalar_stmt_cost.  */
1463   2,                                    /* scalar load_cost.  */
1464   2,                                    /* scalar_store_cost.  */
1465   6,                                    /* vec_stmt_cost.  */
1466   0,                                    /* vec_to_scalar_cost.  */
1467   2,                                    /* scalar_to_vec_cost.  */
1468   2,                                    /* vec_align_load_cost.  */
1469   2,                                    /* vec_unalign_load_cost.  */
1470   2,                                    /* vec_store_cost.  */
1471   2,                                    /* cond_taken_branch_cost.  */
1472   1,                                    /* cond_not_taken_branch_cost.  */
1473 };
1474
1475 static stringop_algs pentium4_memcpy[2] = {
1476   {libcall, {{12, loop_1_byte, false}, {-1, rep_prefix_4_byte, false}}},
1477   DUMMY_STRINGOP_ALGS};
1478 static stringop_algs pentium4_memset[2] = {
1479   {libcall, {{6, loop_1_byte, false}, {48, loop, false},
1480              {20480, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1481   DUMMY_STRINGOP_ALGS};
1482
1483 static const
1484 struct processor_costs pentium4_cost = {
1485   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1486   COSTS_N_INSNS (3),                    /* cost of a lea instruction */
1487   COSTS_N_INSNS (4),                    /* variable shift costs */
1488   COSTS_N_INSNS (4),                    /* constant shift costs */
1489   {COSTS_N_INSNS (15),                  /* cost of starting multiply for QI */
1490    COSTS_N_INSNS (15),                  /*                               HI */
1491    COSTS_N_INSNS (15),                  /*                               SI */
1492    COSTS_N_INSNS (15),                  /*                               DI */
1493    COSTS_N_INSNS (15)},                 /*                            other */
1494   0,                                    /* cost of multiply per each bit set */
1495   {COSTS_N_INSNS (56),                  /* cost of a divide/mod for QI */
1496    COSTS_N_INSNS (56),                  /*                          HI */
1497    COSTS_N_INSNS (56),                  /*                          SI */
1498    COSTS_N_INSNS (56),                  /*                          DI */
1499    COSTS_N_INSNS (56)},                 /*                          other */
1500   COSTS_N_INSNS (1),                    /* cost of movsx */
1501   COSTS_N_INSNS (1),                    /* cost of movzx */
1502   16,                                   /* "large" insn */
1503   6,                                    /* MOVE_RATIO */
1504   2,                                 /* cost for loading QImode using movzbl */
1505   {4, 5, 4},                            /* cost of loading integer registers
1506                                            in QImode, HImode and SImode.
1507                                            Relative to reg-reg move (2).  */
1508   {2, 3, 2},                            /* cost of storing integer registers */
1509   2,                                    /* cost of reg,reg fld/fst */
1510   {2, 2, 6},                            /* cost of loading fp registers
1511                                            in SFmode, DFmode and XFmode */
1512   {4, 4, 6},                            /* cost of storing fp registers
1513                                            in SFmode, DFmode and XFmode */
1514   2,                                    /* cost of moving MMX register */
1515   {2, 2},                               /* cost of loading MMX registers
1516                                            in SImode and DImode */
1517   {2, 2},                               /* cost of storing MMX registers
1518                                            in SImode and DImode */
1519   12,                                   /* cost of moving SSE register */
1520   {12, 12, 12},                         /* cost of loading SSE registers
1521                                            in SImode, DImode and TImode */
1522   {2, 2, 8},                            /* cost of storing SSE registers
1523                                            in SImode, DImode and TImode */
1524   10,                                   /* MMX or SSE register to integer */
1525   8,                                    /* size of l1 cache.  */
1526   256,                                  /* size of l2 cache.  */
1527   64,                                   /* size of prefetch block */
1528   6,                                    /* number of parallel prefetches */
1529   2,                                    /* Branch cost */
1530   COSTS_N_INSNS (5),                    /* cost of FADD and FSUB insns.  */
1531   COSTS_N_INSNS (7),                    /* cost of FMUL instruction.  */
1532   COSTS_N_INSNS (43),                   /* cost of FDIV instruction.  */
1533   COSTS_N_INSNS (2),                    /* cost of FABS instruction.  */
1534   COSTS_N_INSNS (2),                    /* cost of FCHS instruction.  */
1535   COSTS_N_INSNS (43),                   /* cost of FSQRT instruction.  */
1536   pentium4_memcpy,
1537   pentium4_memset,
1538   1,                                    /* scalar_stmt_cost.  */
1539   1,                                    /* scalar load_cost.  */
1540   1,                                    /* scalar_store_cost.  */
1541   1,                                    /* vec_stmt_cost.  */
1542   1,                                    /* vec_to_scalar_cost.  */
1543   1,                                    /* scalar_to_vec_cost.  */
1544   1,                                    /* vec_align_load_cost.  */
1545   2,                                    /* vec_unalign_load_cost.  */
1546   1,                                    /* vec_store_cost.  */
1547   3,                                    /* cond_taken_branch_cost.  */
1548   1,                                    /* cond_not_taken_branch_cost.  */
1549 };
1550
1551 static stringop_algs nocona_memcpy[2] = {
1552   {libcall, {{12, loop_1_byte, false}, {-1, rep_prefix_4_byte, false}}},
1553   {libcall, {{32, loop, false}, {20000, rep_prefix_8_byte, false},
1554              {100000, unrolled_loop, false}, {-1, libcall, false}}}};
1555
1556 static stringop_algs nocona_memset[2] = {
1557   {libcall, {{6, loop_1_byte, false}, {48, loop, false},
1558              {20480, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1559   {libcall, {{24, loop, false}, {64, unrolled_loop, false},
1560              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1561
1562 static const
1563 struct processor_costs nocona_cost = {
1564   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1565   COSTS_N_INSNS (1),                    /* cost of a lea instruction */
1566   COSTS_N_INSNS (1),                    /* variable shift costs */
1567   COSTS_N_INSNS (1),                    /* constant shift costs */
1568   {COSTS_N_INSNS (10),                  /* cost of starting multiply for QI */
1569    COSTS_N_INSNS (10),                  /*                               HI */
1570    COSTS_N_INSNS (10),                  /*                               SI */
1571    COSTS_N_INSNS (10),                  /*                               DI */
1572    COSTS_N_INSNS (10)},                 /*                            other */
1573   0,                                    /* cost of multiply per each bit set */
1574   {COSTS_N_INSNS (66),                  /* cost of a divide/mod for QI */
1575    COSTS_N_INSNS (66),                  /*                          HI */
1576    COSTS_N_INSNS (66),                  /*                          SI */
1577    COSTS_N_INSNS (66),                  /*                          DI */
1578    COSTS_N_INSNS (66)},                 /*                          other */
1579   COSTS_N_INSNS (1),                    /* cost of movsx */
1580   COSTS_N_INSNS (1),                    /* cost of movzx */
1581   16,                                   /* "large" insn */
1582   17,                                   /* MOVE_RATIO */
1583   4,                                 /* cost for loading QImode using movzbl */
1584   {4, 4, 4},                            /* cost of loading integer registers
1585                                            in QImode, HImode and SImode.
1586                                            Relative to reg-reg move (2).  */
1587   {4, 4, 4},                            /* cost of storing integer registers */
1588   3,                                    /* cost of reg,reg fld/fst */
1589   {12, 12, 12},                         /* cost of loading fp registers
1590                                            in SFmode, DFmode and XFmode */
1591   {4, 4, 4},                            /* cost of storing fp registers
1592                                            in SFmode, DFmode and XFmode */
1593   6,                                    /* cost of moving MMX register */
1594   {12, 12},                             /* cost of loading MMX registers
1595                                            in SImode and DImode */
1596   {12, 12},                             /* cost of storing MMX registers
1597                                            in SImode and DImode */
1598   6,                                    /* cost of moving SSE register */
1599   {12, 12, 12},                         /* cost of loading SSE registers
1600                                            in SImode, DImode and TImode */
1601   {12, 12, 12},                         /* cost of storing SSE registers
1602                                            in SImode, DImode and TImode */
1603   8,                                    /* MMX or SSE register to integer */
1604   8,                                    /* size of l1 cache.  */
1605   1024,                                 /* size of l2 cache.  */
1606   64,                                   /* size of prefetch block */
1607   8,                                    /* number of parallel prefetches */
1608   1,                                    /* Branch cost */
1609   COSTS_N_INSNS (6),                    /* cost of FADD and FSUB insns.  */
1610   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1611   COSTS_N_INSNS (40),                   /* cost of FDIV instruction.  */
1612   COSTS_N_INSNS (3),                    /* cost of FABS instruction.  */
1613   COSTS_N_INSNS (3),                    /* cost of FCHS instruction.  */
1614   COSTS_N_INSNS (44),                   /* cost of FSQRT instruction.  */
1615   nocona_memcpy,
1616   nocona_memset,
1617   1,                                    /* scalar_stmt_cost.  */
1618   1,                                    /* scalar load_cost.  */
1619   1,                                    /* scalar_store_cost.  */
1620   1,                                    /* vec_stmt_cost.  */
1621   1,                                    /* vec_to_scalar_cost.  */
1622   1,                                    /* scalar_to_vec_cost.  */
1623   1,                                    /* vec_align_load_cost.  */
1624   2,                                    /* vec_unalign_load_cost.  */
1625   1,                                    /* vec_store_cost.  */
1626   3,                                    /* cond_taken_branch_cost.  */
1627   1,                                    /* cond_not_taken_branch_cost.  */
1628 };
1629
1630 static stringop_algs atom_memcpy[2] = {
1631   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
1632   {libcall, {{32, loop, false}, {64, rep_prefix_4_byte, false},
1633              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1634 static stringop_algs atom_memset[2] = {
1635   {libcall, {{8, loop, false}, {15, unrolled_loop, false},
1636              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1637   {libcall, {{24, loop, false}, {32, unrolled_loop, false},
1638              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1639 static const
1640 struct processor_costs atom_cost = {
1641   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1642   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1643   COSTS_N_INSNS (1),                    /* variable shift costs */
1644   COSTS_N_INSNS (1),                    /* constant shift costs */
1645   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1646    COSTS_N_INSNS (4),                   /*                               HI */
1647    COSTS_N_INSNS (3),                   /*                               SI */
1648    COSTS_N_INSNS (4),                   /*                               DI */
1649    COSTS_N_INSNS (2)},                  /*                            other */
1650   0,                                    /* cost of multiply per each bit set */
1651   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1652    COSTS_N_INSNS (26),                  /*                          HI */
1653    COSTS_N_INSNS (42),                  /*                          SI */
1654    COSTS_N_INSNS (74),                  /*                          DI */
1655    COSTS_N_INSNS (74)},                 /*                          other */
1656   COSTS_N_INSNS (1),                    /* cost of movsx */
1657   COSTS_N_INSNS (1),                    /* cost of movzx */
1658   8,                                    /* "large" insn */
1659   17,                                   /* MOVE_RATIO */
1660   4,                                    /* cost for loading QImode using movzbl */
1661   {4, 4, 4},                            /* cost of loading integer registers
1662                                            in QImode, HImode and SImode.
1663                                            Relative to reg-reg move (2).  */
1664   {4, 4, 4},                            /* cost of storing integer registers */
1665   4,                                    /* cost of reg,reg fld/fst */
1666   {12, 12, 12},                         /* cost of loading fp registers
1667                                            in SFmode, DFmode and XFmode */
1668   {6, 6, 8},                            /* cost of storing fp registers
1669                                            in SFmode, DFmode and XFmode */
1670   2,                                    /* cost of moving MMX register */
1671   {8, 8},                               /* cost of loading MMX registers
1672                                            in SImode and DImode */
1673   {8, 8},                               /* cost of storing MMX registers
1674                                            in SImode and DImode */
1675   2,                                    /* cost of moving SSE register */
1676   {8, 8, 8},                            /* cost of loading SSE registers
1677                                            in SImode, DImode and TImode */
1678   {8, 8, 8},                            /* cost of storing SSE registers
1679                                            in SImode, DImode and TImode */
1680   5,                                    /* MMX or SSE register to integer */
1681   32,                                   /* size of l1 cache.  */
1682   256,                                  /* size of l2 cache.  */
1683   64,                                   /* size of prefetch block */
1684   6,                                    /* number of parallel prefetches */
1685   3,                                    /* Branch cost */
1686   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1687   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1688   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1689   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1690   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1691   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1692   atom_memcpy,
1693   atom_memset,
1694   1,                                    /* scalar_stmt_cost.  */
1695   1,                                    /* scalar load_cost.  */
1696   1,                                    /* scalar_store_cost.  */
1697   1,                                    /* vec_stmt_cost.  */
1698   1,                                    /* vec_to_scalar_cost.  */
1699   1,                                    /* scalar_to_vec_cost.  */
1700   1,                                    /* vec_align_load_cost.  */
1701   2,                                    /* vec_unalign_load_cost.  */
1702   1,                                    /* vec_store_cost.  */
1703   3,                                    /* cond_taken_branch_cost.  */
1704   1,                                    /* cond_not_taken_branch_cost.  */
1705 };
1706
1707 static stringop_algs slm_memcpy[2] = {
1708   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
1709   {libcall, {{32, loop, false}, {64, rep_prefix_4_byte, false},
1710              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1711 static stringop_algs slm_memset[2] = {
1712   {libcall, {{8, loop, false}, {15, unrolled_loop, false},
1713              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1714   {libcall, {{24, loop, false}, {32, unrolled_loop, false},
1715              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1716 static const
1717 struct processor_costs slm_cost = {
1718   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1719   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1720   COSTS_N_INSNS (1),                    /* variable shift costs */
1721   COSTS_N_INSNS (1),                    /* constant shift costs */
1722   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1723    COSTS_N_INSNS (3),                   /*                               HI */
1724    COSTS_N_INSNS (3),                   /*                               SI */
1725    COSTS_N_INSNS (4),                   /*                               DI */
1726    COSTS_N_INSNS (2)},                  /*                            other */
1727   0,                                    /* cost of multiply per each bit set */
1728   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1729    COSTS_N_INSNS (26),                  /*                          HI */
1730    COSTS_N_INSNS (42),                  /*                          SI */
1731    COSTS_N_INSNS (74),                  /*                          DI */
1732    COSTS_N_INSNS (74)},                 /*                          other */
1733   COSTS_N_INSNS (1),                    /* cost of movsx */
1734   COSTS_N_INSNS (1),                    /* cost of movzx */
1735   8,                                    /* "large" insn */
1736   17,                                   /* MOVE_RATIO */
1737   4,                                    /* cost for loading QImode using movzbl */
1738   {4, 4, 4},                            /* cost of loading integer registers
1739                                            in QImode, HImode and SImode.
1740                                            Relative to reg-reg move (2).  */
1741   {4, 4, 4},                            /* cost of storing integer registers */
1742   4,                                    /* cost of reg,reg fld/fst */
1743   {12, 12, 12},                         /* cost of loading fp registers
1744                                            in SFmode, DFmode and XFmode */
1745   {6, 6, 8},                            /* cost of storing fp registers
1746                                            in SFmode, DFmode and XFmode */
1747   2,                                    /* cost of moving MMX register */
1748   {8, 8},                               /* cost of loading MMX registers
1749                                            in SImode and DImode */
1750   {8, 8},                               /* cost of storing MMX registers
1751                                            in SImode and DImode */
1752   2,                                    /* cost of moving SSE register */
1753   {8, 8, 8},                            /* cost of loading SSE registers
1754                                            in SImode, DImode and TImode */
1755   {8, 8, 8},                            /* cost of storing SSE registers
1756                                            in SImode, DImode and TImode */
1757   5,                                    /* MMX or SSE register to integer */
1758   32,                                   /* size of l1 cache.  */
1759   256,                                  /* size of l2 cache.  */
1760   64,                                   /* size of prefetch block */
1761   6,                                    /* number of parallel prefetches */
1762   3,                                    /* Branch cost */
1763   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1764   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1765   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1766   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1767   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1768   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1769   slm_memcpy,
1770   slm_memset,
1771   1,                                    /* scalar_stmt_cost.  */
1772   1,                                    /* scalar load_cost.  */
1773   1,                                    /* scalar_store_cost.  */
1774   1,                                    /* vec_stmt_cost.  */
1775   4,                                    /* vec_to_scalar_cost.  */
1776   1,                                    /* scalar_to_vec_cost.  */
1777   1,                                    /* vec_align_load_cost.  */
1778   2,                                    /* vec_unalign_load_cost.  */
1779   1,                                    /* vec_store_cost.  */
1780   3,                                    /* cond_taken_branch_cost.  */
1781   1,                                    /* cond_not_taken_branch_cost.  */
1782 };
1783
1784 static stringop_algs intel_memcpy[2] = {
1785   {libcall, {{11, loop, false}, {-1, rep_prefix_4_byte, false}}},
1786   {libcall, {{32, loop, false}, {64, rep_prefix_4_byte, false},
1787              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1788 static stringop_algs intel_memset[2] = {
1789   {libcall, {{8, loop, false}, {15, unrolled_loop, false},
1790              {2048, rep_prefix_4_byte, false}, {-1, libcall, false}}},
1791   {libcall, {{24, loop, false}, {32, unrolled_loop, false},
1792              {8192, rep_prefix_8_byte, false}, {-1, libcall, false}}}};
1793 static const
1794 struct processor_costs intel_cost = {
1795   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1796   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1797   COSTS_N_INSNS (1),                    /* variable shift costs */
1798   COSTS_N_INSNS (1),                    /* constant shift costs */
1799   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1800    COSTS_N_INSNS (3),                   /*                               HI */
1801    COSTS_N_INSNS (3),                   /*                               SI */
1802    COSTS_N_INSNS (4),                   /*                               DI */
1803    COSTS_N_INSNS (2)},                  /*                            other */
1804   0,                                    /* cost of multiply per each bit set */
1805   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1806    COSTS_N_INSNS (26),                  /*                          HI */
1807    COSTS_N_INSNS (42),                  /*                          SI */
1808    COSTS_N_INSNS (74),                  /*                          DI */
1809    COSTS_N_INSNS (74)},                 /*                          other */
1810   COSTS_N_INSNS (1),                    /* cost of movsx */
1811   COSTS_N_INSNS (1),                    /* cost of movzx */
1812   8,                                    /* "large" insn */
1813   17,                                   /* MOVE_RATIO */
1814   4,                                    /* cost for loading QImode using movzbl */
1815   {4, 4, 4},                            /* cost of loading integer registers
1816                                            in QImode, HImode and SImode.
1817                                            Relative to reg-reg move (2).  */
1818   {4, 4, 4},                            /* cost of storing integer registers */
1819   4,                                    /* cost of reg,reg fld/fst */
1820   {12, 12, 12},                         /* cost of loading fp registers
1821                                            in SFmode, DFmode and XFmode */
1822   {6, 6, 8},                            /* cost of storing fp registers
1823                                            in SFmode, DFmode and XFmode */
1824   2,                                    /* cost of moving MMX register */
1825   {8, 8},                               /* cost of loading MMX registers
1826                                            in SImode and DImode */
1827   {8, 8},                               /* cost of storing MMX registers
1828                                            in SImode and DImode */
1829   2,                                    /* cost of moving SSE register */
1830   {8, 8, 8},                            /* cost of loading SSE registers
1831                                            in SImode, DImode and TImode */
1832   {8, 8, 8},                            /* cost of storing SSE registers
1833                                            in SImode, DImode and TImode */
1834   5,                                    /* MMX or SSE register to integer */
1835   32,                                   /* size of l1 cache.  */
1836   256,                                  /* size of l2 cache.  */
1837   64,                                   /* size of prefetch block */
1838   6,                                    /* number of parallel prefetches */
1839   3,                                    /* Branch cost */
1840   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1841   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1842   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1843   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1844   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1845   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1846   intel_memcpy,
1847   intel_memset,
1848   1,                                    /* scalar_stmt_cost.  */
1849   1,                                    /* scalar load_cost.  */
1850   1,                                    /* scalar_store_cost.  */
1851   1,                                    /* vec_stmt_cost.  */
1852   4,                                    /* vec_to_scalar_cost.  */
1853   1,                                    /* scalar_to_vec_cost.  */
1854   1,                                    /* vec_align_load_cost.  */
1855   2,                                    /* vec_unalign_load_cost.  */
1856   1,                                    /* vec_store_cost.  */
1857   3,                                    /* cond_taken_branch_cost.  */
1858   1,                                    /* cond_not_taken_branch_cost.  */
1859 };
1860
1861 /* Generic should produce code tuned for Core-i7 (and newer chips)
1862    and btver1 (and newer chips).  */
1863
1864 static stringop_algs generic_memcpy[2] = {
1865   {libcall, {{32, loop, false}, {8192, rep_prefix_4_byte, false},
1866              {-1, libcall, false}}},
1867   {libcall, {{32, loop, false}, {8192, rep_prefix_8_byte, false},
1868              {-1, libcall, false}}}};
1869 static stringop_algs generic_memset[2] = {
1870   {libcall, {{32, loop, false}, {8192, rep_prefix_4_byte, false},
1871              {-1, libcall, false}}},
1872   {libcall, {{32, loop, false}, {8192, rep_prefix_8_byte, false},
1873              {-1, libcall, false}}}};
1874 static const
1875 struct processor_costs generic_cost = {
1876   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1877   /* On all chips taken into consideration lea is 2 cycles and more.  With
1878      this cost however our current implementation of synth_mult results in
1879      use of unnecessary temporary registers causing regression on several
1880      SPECfp benchmarks.  */
1881   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1882   COSTS_N_INSNS (1),                    /* variable shift costs */
1883   COSTS_N_INSNS (1),                    /* constant shift costs */
1884   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1885    COSTS_N_INSNS (4),                   /*                               HI */
1886    COSTS_N_INSNS (3),                   /*                               SI */
1887    COSTS_N_INSNS (4),                   /*                               DI */
1888    COSTS_N_INSNS (2)},                  /*                            other */
1889   0,                                    /* cost of multiply per each bit set */
1890   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1891    COSTS_N_INSNS (26),                  /*                          HI */
1892    COSTS_N_INSNS (42),                  /*                          SI */
1893    COSTS_N_INSNS (74),                  /*                          DI */
1894    COSTS_N_INSNS (74)},                 /*                          other */
1895   COSTS_N_INSNS (1),                    /* cost of movsx */
1896   COSTS_N_INSNS (1),                    /* cost of movzx */
1897   8,                                    /* "large" insn */
1898   17,                                   /* MOVE_RATIO */
1899   4,                                 /* cost for loading QImode using movzbl */
1900   {4, 4, 4},                            /* cost of loading integer registers
1901                                            in QImode, HImode and SImode.
1902                                            Relative to reg-reg move (2).  */
1903   {4, 4, 4},                            /* cost of storing integer registers */
1904   4,                                    /* cost of reg,reg fld/fst */
1905   {12, 12, 12},                         /* cost of loading fp registers
1906                                            in SFmode, DFmode and XFmode */
1907   {6, 6, 8},                            /* cost of storing fp registers
1908                                            in SFmode, DFmode and XFmode */
1909   2,                                    /* cost of moving MMX register */
1910   {8, 8},                               /* cost of loading MMX registers
1911                                            in SImode and DImode */
1912   {8, 8},                               /* cost of storing MMX registers
1913                                            in SImode and DImode */
1914   2,                                    /* cost of moving SSE register */
1915   {8, 8, 8},                            /* cost of loading SSE registers
1916                                            in SImode, DImode and TImode */
1917   {8, 8, 8},                            /* cost of storing SSE registers
1918                                            in SImode, DImode and TImode */
1919   5,                                    /* MMX or SSE register to integer */
1920   32,                                   /* size of l1 cache.  */
1921   512,                                  /* size of l2 cache.  */
1922   64,                                   /* size of prefetch block */
1923   6,                                    /* number of parallel prefetches */
1924   /* Benchmarks shows large regressions on K8 sixtrack benchmark when this
1925      value is increased to perhaps more appropriate value of 5.  */
1926   3,                                    /* Branch cost */
1927   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
1928   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
1929   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
1930   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
1931   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
1932   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
1933   generic_memcpy,
1934   generic_memset,
1935   1,                                    /* scalar_stmt_cost.  */
1936   1,                                    /* scalar load_cost.  */
1937   1,                                    /* scalar_store_cost.  */
1938   1,                                    /* vec_stmt_cost.  */
1939   1,                                    /* vec_to_scalar_cost.  */
1940   1,                                    /* scalar_to_vec_cost.  */
1941   1,                                    /* vec_align_load_cost.  */
1942   2,                                    /* vec_unalign_load_cost.  */
1943   1,                                    /* vec_store_cost.  */
1944   3,                                    /* cond_taken_branch_cost.  */
1945   1,                                    /* cond_not_taken_branch_cost.  */
1946 };
1947
1948 /* core_cost should produce code tuned for Core familly of CPUs.  */
1949 static stringop_algs core_memcpy[2] = {
1950   {libcall, {{1024, rep_prefix_4_byte, true}, {-1, libcall, false}}},
1951   {libcall, {{24, loop, true}, {128, rep_prefix_8_byte, true},
1952              {-1, libcall, false}}}};
1953 static stringop_algs core_memset[2] = {
1954   {libcall, {{6, loop_1_byte, true},
1955              {24, loop, true},
1956              {8192, rep_prefix_4_byte, true},
1957              {-1, libcall, false}}},
1958   {libcall, {{24, loop, true}, {512, rep_prefix_8_byte, true},
1959              {-1, libcall, false}}}};
1960
1961 static const
1962 struct processor_costs core_cost = {
1963   COSTS_N_INSNS (1),                    /* cost of an add instruction */
1964   /* On all chips taken into consideration lea is 2 cycles and more.  With
1965      this cost however our current implementation of synth_mult results in
1966      use of unnecessary temporary registers causing regression on several
1967      SPECfp benchmarks.  */
1968   COSTS_N_INSNS (1) + 1,                /* cost of a lea instruction */
1969   COSTS_N_INSNS (1),                    /* variable shift costs */
1970   COSTS_N_INSNS (1),                    /* constant shift costs */
1971   {COSTS_N_INSNS (3),                   /* cost of starting multiply for QI */
1972    COSTS_N_INSNS (4),                   /*                               HI */
1973    COSTS_N_INSNS (3),                   /*                               SI */
1974    COSTS_N_INSNS (4),                   /*                               DI */
1975    COSTS_N_INSNS (2)},                  /*                            other */
1976   0,                                    /* cost of multiply per each bit set */
1977   {COSTS_N_INSNS (18),                  /* cost of a divide/mod for QI */
1978    COSTS_N_INSNS (26),                  /*                          HI */
1979    COSTS_N_INSNS (42),                  /*                          SI */
1980    COSTS_N_INSNS (74),                  /*                          DI */
1981    COSTS_N_INSNS (74)},                 /*                          other */
1982   COSTS_N_INSNS (1),                    /* cost of movsx */
1983   COSTS_N_INSNS (1),                    /* cost of movzx */
1984   8,                                    /* "large" insn */
1985   17,                                   /* MOVE_RATIO */
1986   4,                                 /* cost for loading QImode using movzbl */
1987   {4, 4, 4},                            /* cost of loading integer registers
1988                                            in QImode, HImode and SImode.
1989                                            Relative to reg-reg move (2).  */
1990   {4, 4, 4},                            /* cost of storing integer registers */
1991   4,                                    /* cost of reg,reg fld/fst */
1992   {12, 12, 12},                         /* cost of loading fp registers
1993                                            in SFmode, DFmode and XFmode */
1994   {6, 6, 8},                            /* cost of storing fp registers
1995                                            in SFmode, DFmode and XFmode */
1996   2,                                    /* cost of moving MMX register */
1997   {8, 8},                               /* cost of loading MMX registers
1998                                            in SImode and DImode */
1999   {8, 8},                               /* cost of storing MMX registers
2000                                            in SImode and DImode */
2001   2,                                    /* cost of moving SSE register */
2002   {8, 8, 8},                            /* cost of loading SSE registers
2003                                            in SImode, DImode and TImode */
2004   {8, 8, 8},                            /* cost of storing SSE registers
2005                                            in SImode, DImode and TImode */
2006   5,                                    /* MMX or SSE register to integer */
2007   64,                                   /* size of l1 cache.  */
2008   512,                                  /* size of l2 cache.  */
2009   64,                                   /* size of prefetch block */
2010   6,                                    /* number of parallel prefetches */
2011   /* FIXME perhaps more appropriate value is 5.  */
2012   3,                                    /* Branch cost */
2013   COSTS_N_INSNS (8),                    /* cost of FADD and FSUB insns.  */
2014   COSTS_N_INSNS (8),                    /* cost of FMUL instruction.  */
2015   COSTS_N_INSNS (20),                   /* cost of FDIV instruction.  */
2016   COSTS_N_INSNS (8),                    /* cost of FABS instruction.  */
2017   COSTS_N_INSNS (8),                    /* cost of FCHS instruction.  */
2018   COSTS_N_INSNS (40),                   /* cost of FSQRT instruction.  */
2019   core_memcpy,
2020   core_memset,
2021   1,                                    /* scalar_stmt_cost.  */
2022   1,                                    /* scalar load_cost.  */
2023   1,                                    /* scalar_store_cost.  */
2024   1,                                    /* vec_stmt_cost.  */
2025   1,                                    /* vec_to_scalar_cost.  */
2026   1,                                    /* scalar_to_vec_cost.  */
2027   1,                                    /* vec_align_load_cost.  */
2028   2,                                    /* vec_unalign_load_cost.  */
2029   1,                                    /* vec_store_cost.  */
2030   3,                                    /* cond_taken_branch_cost.  */
2031   1,                                    /* cond_not_taken_branch_cost.  */
2032 };
2033
2034
2035 /* Set by -mtune.  */
2036 const struct processor_costs *ix86_tune_cost = &pentium_cost;
2037
2038 /* Set by -mtune or -Os.  */
2039 const struct processor_costs *ix86_cost = &pentium_cost;
2040
2041 /* Processor feature/optimization bitmasks.  */
2042 #define m_386 (1<<PROCESSOR_I386)
2043 #define m_486 (1<<PROCESSOR_I486)
2044 #define m_PENT (1<<PROCESSOR_PENTIUM)
2045 #define m_PPRO (1<<PROCESSOR_PENTIUMPRO)
2046 #define m_PENT4 (1<<PROCESSOR_PENTIUM4)
2047 #define m_NOCONA (1<<PROCESSOR_NOCONA)
2048 #define m_P4_NOCONA (m_PENT4 | m_NOCONA)
2049 #define m_CORE2 (1<<PROCESSOR_CORE2)
2050 #define m_NEHALEM (1<<PROCESSOR_NEHALEM)
2051 #define m_SANDYBRIDGE (1<<PROCESSOR_SANDYBRIDGE)
2052 #define m_HASWELL (1<<PROCESSOR_HASWELL)
2053 #define m_CORE_ALL (m_CORE2 | m_NEHALEM  | m_SANDYBRIDGE | m_HASWELL)
2054 #define m_BONNELL (1<<PROCESSOR_BONNELL)
2055 #define m_SILVERMONT (1<<PROCESSOR_SILVERMONT)
2056 #define m_KNL (1<<PROCESSOR_KNL)
2057 #define m_INTEL (1<<PROCESSOR_INTEL)
2058
2059 #define m_GEODE (1<<PROCESSOR_GEODE)
2060 #define m_K6 (1<<PROCESSOR_K6)
2061 #define m_K6_GEODE (m_K6 | m_GEODE)
2062 #define m_K8 (1<<PROCESSOR_K8)
2063 #define m_ATHLON (1<<PROCESSOR_ATHLON)
2064 #define m_ATHLON_K8 (m_K8 | m_ATHLON)
2065 #define m_AMDFAM10 (1<<PROCESSOR_AMDFAM10)
2066 #define m_BDVER1 (1<<PROCESSOR_BDVER1)
2067 #define m_BDVER2 (1<<PROCESSOR_BDVER2)
2068 #define m_BDVER3 (1<<PROCESSOR_BDVER3)
2069 #define m_BDVER4 (1<<PROCESSOR_BDVER4)
2070 #define m_BTVER1 (1<<PROCESSOR_BTVER1)
2071 #define m_BTVER2 (1<<PROCESSOR_BTVER2)
2072 #define m_BDVER (m_BDVER1 | m_BDVER2 | m_BDVER3 | m_BDVER4)
2073 #define m_BTVER (m_BTVER1 | m_BTVER2)
2074 #define m_AMD_MULTIPLE (m_ATHLON_K8 | m_AMDFAM10 | m_BDVER | m_BTVER)
2075
2076 #define m_GENERIC (1<<PROCESSOR_GENERIC)
2077
2078 const char* ix86_tune_feature_names[X86_TUNE_LAST] = {
2079 #undef DEF_TUNE
2080 #define DEF_TUNE(tune, name, selector) name,
2081 #include "x86-tune.def"
2082 #undef DEF_TUNE
2083 };
2084
2085 /* Feature tests against the various tunings.  */
2086 unsigned char ix86_tune_features[X86_TUNE_LAST];
2087
2088 /* Feature tests against the various tunings used to create ix86_tune_features
2089    based on the processor mask.  */
2090 static unsigned int initial_ix86_tune_features[X86_TUNE_LAST] = {
2091 #undef DEF_TUNE
2092 #define DEF_TUNE(tune, name, selector) selector,
2093 #include "x86-tune.def"
2094 #undef DEF_TUNE
2095 };
2096
2097 /* Feature tests against the various architecture variations.  */
2098 unsigned char ix86_arch_features[X86_ARCH_LAST];
2099
2100 /* Feature tests against the various architecture variations, used to create
2101    ix86_arch_features based on the processor mask.  */
2102 static unsigned int initial_ix86_arch_features[X86_ARCH_LAST] = {
2103   /* X86_ARCH_CMOV: Conditional move was added for pentiumpro.  */
2104   ~(m_386 | m_486 | m_PENT | m_K6),
2105
2106   /* X86_ARCH_CMPXCHG: Compare and exchange was added for 80486.  */
2107   ~m_386,
2108
2109   /* X86_ARCH_CMPXCHG8B: Compare and exchange 8 bytes was added for pentium. */
2110   ~(m_386 | m_486),
2111
2112   /* X86_ARCH_XADD: Exchange and add was added for 80486.  */
2113   ~m_386,
2114
2115   /* X86_ARCH_BSWAP: Byteswap was added for 80486.  */
2116   ~m_386,
2117 };
2118
2119 /* In case the average insn count for single function invocation is
2120    lower than this constant, emit fast (but longer) prologue and
2121    epilogue code.  */
2122 #define FAST_PROLOGUE_INSN_COUNT 20
2123
2124 /* Names for 8 (low), 8 (high), and 16-bit registers, respectively.  */
2125 static const char *const qi_reg_name[] = QI_REGISTER_NAMES;
2126 static const char *const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES;
2127 static const char *const hi_reg_name[] = HI_REGISTER_NAMES;
2128
2129 /* Array of the smallest class containing reg number REGNO, indexed by
2130    REGNO.  Used by REGNO_REG_CLASS in i386.h.  */
2131
2132 enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] =
2133 {
2134   /* ax, dx, cx, bx */
2135   AREG, DREG, CREG, BREG,
2136   /* si, di, bp, sp */
2137   SIREG, DIREG, NON_Q_REGS, NON_Q_REGS,
2138   /* FP registers */
2139   FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS,
2140   FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS,
2141   /* arg pointer */
2142   NON_Q_REGS,
2143   /* flags, fpsr, fpcr, frame */
2144   NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS,
2145   /* SSE registers */
2146   SSE_FIRST_REG, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
2147   SSE_REGS, SSE_REGS,
2148   /* MMX registers */
2149   MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS, MMX_REGS,
2150   MMX_REGS, MMX_REGS,
2151   /* REX registers */
2152   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
2153   NON_Q_REGS, NON_Q_REGS, NON_Q_REGS, NON_Q_REGS,
2154   /* SSE REX registers */
2155   SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS, SSE_REGS,
2156   SSE_REGS, SSE_REGS,
2157   /* AVX-512 SSE registers */
2158   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2159   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2160   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2161   EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS, EVEX_SSE_REGS,
2162   /* Mask registers.  */
2163   MASK_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS,
2164   MASK_EVEX_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS, MASK_EVEX_REGS,
2165   /* MPX bound registers */
2166   BND_REGS, BND_REGS, BND_REGS, BND_REGS,
2167 };
2168
2169 /* The "default" register map used in 32bit mode.  */
2170
2171 int const dbx_register_map[FIRST_PSEUDO_REGISTER] =
2172 {
2173   0, 2, 1, 3, 6, 7, 4, 5,               /* general regs */
2174   12, 13, 14, 15, 16, 17, 18, 19,       /* fp regs */
2175   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
2176   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE */
2177   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX */
2178   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
2179   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
2180   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 16-23*/
2181   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 24-31*/
2182   93, 94, 95, 96, 97, 98, 99, 100,      /* Mask registers */
2183   101, 102, 103, 104,                   /* bound registers */
2184 };
2185
2186 /* The "default" register map used in 64bit mode.  */
2187
2188 int const dbx64_register_map[FIRST_PSEUDO_REGISTER] =
2189 {
2190   0, 1, 2, 3, 4, 5, 6, 7,               /* general regs */
2191   33, 34, 35, 36, 37, 38, 39, 40,       /* fp regs */
2192   -1, -1, -1, -1, -1,                   /* arg, flags, fpsr, fpcr, frame */
2193   17, 18, 19, 20, 21, 22, 23, 24,       /* SSE */
2194   41, 42, 43, 44, 45, 46, 47, 48,       /* MMX */
2195   8,9,10,11,12,13,14,15,                /* extended integer registers */
2196   25, 26, 27, 28, 29, 30, 31, 32,       /* extended SSE registers */
2197   67, 68, 69, 70, 71, 72, 73, 74,       /* AVX-512 registers 16-23 */
2198   75, 76, 77, 78, 79, 80, 81, 82,       /* AVX-512 registers 24-31 */
2199   118, 119, 120, 121, 122, 123, 124, 125, /* Mask registers */
2200   126, 127, 128, 129,                   /* bound registers */
2201 };
2202
2203 /* Define the register numbers to be used in Dwarf debugging information.
2204    The SVR4 reference port C compiler uses the following register numbers
2205    in its Dwarf output code:
2206         0 for %eax (gcc regno = 0)
2207         1 for %ecx (gcc regno = 2)
2208         2 for %edx (gcc regno = 1)
2209         3 for %ebx (gcc regno = 3)
2210         4 for %esp (gcc regno = 7)
2211         5 for %ebp (gcc regno = 6)
2212         6 for %esi (gcc regno = 4)
2213         7 for %edi (gcc regno = 5)
2214    The following three DWARF register numbers are never generated by
2215    the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
2216    believes these numbers have these meanings.
2217         8  for %eip    (no gcc equivalent)
2218         9  for %eflags (gcc regno = 17)
2219         10 for %trapno (no gcc equivalent)
2220    It is not at all clear how we should number the FP stack registers
2221    for the x86 architecture.  If the version of SDB on x86/svr4 were
2222    a bit less brain dead with respect to floating-point then we would
2223    have a precedent to follow with respect to DWARF register numbers
2224    for x86 FP registers, but the SDB on x86/svr4 is so completely
2225    broken with respect to FP registers that it is hardly worth thinking
2226    of it as something to strive for compatibility with.
2227    The version of x86/svr4 SDB I have at the moment does (partially)
2228    seem to believe that DWARF register number 11 is associated with
2229    the x86 register %st(0), but that's about all.  Higher DWARF
2230    register numbers don't seem to be associated with anything in
2231    particular, and even for DWARF regno 11, SDB only seems to under-
2232    stand that it should say that a variable lives in %st(0) (when
2233    asked via an `=' command) if we said it was in DWARF regno 11,
2234    but SDB still prints garbage when asked for the value of the
2235    variable in question (via a `/' command).
2236    (Also note that the labels SDB prints for various FP stack regs
2237    when doing an `x' command are all wrong.)
2238    Note that these problems generally don't affect the native SVR4
2239    C compiler because it doesn't allow the use of -O with -g and
2240    because when it is *not* optimizing, it allocates a memory
2241    location for each floating-point variable, and the memory
2242    location is what gets described in the DWARF AT_location
2243    attribute for the variable in question.
2244    Regardless of the severe mental illness of the x86/svr4 SDB, we
2245    do something sensible here and we use the following DWARF
2246    register numbers.  Note that these are all stack-top-relative
2247    numbers.
2248         11 for %st(0) (gcc regno = 8)
2249         12 for %st(1) (gcc regno = 9)
2250         13 for %st(2) (gcc regno = 10)
2251         14 for %st(3) (gcc regno = 11)
2252         15 for %st(4) (gcc regno = 12)
2253         16 for %st(5) (gcc regno = 13)
2254         17 for %st(6) (gcc regno = 14)
2255         18 for %st(7) (gcc regno = 15)
2256 */
2257 int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] =
2258 {
2259   0, 2, 1, 3, 6, 7, 5, 4,               /* general regs */
2260   11, 12, 13, 14, 15, 16, 17, 18,       /* fp regs */
2261   -1, 9, -1, -1, -1,                    /* arg, flags, fpsr, fpcr, frame */
2262   21, 22, 23, 24, 25, 26, 27, 28,       /* SSE registers */
2263   29, 30, 31, 32, 33, 34, 35, 36,       /* MMX registers */
2264   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended integer registers */
2265   -1, -1, -1, -1, -1, -1, -1, -1,       /* extended SSE registers */
2266   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 16-23*/
2267   -1, -1, -1, -1, -1, -1, -1, -1,       /* AVX-512 registers 24-31*/
2268   93, 94, 95, 96, 97, 98, 99, 100,      /* Mask registers */
2269   101, 102, 103, 104,                   /* bound registers */
2270 };
2271
2272 /* Define parameter passing and return registers.  */
2273
2274 static int const x86_64_int_parameter_registers[6] =
2275 {
2276   DI_REG, SI_REG, DX_REG, CX_REG, R8_REG, R9_REG
2277 };
2278
2279 static int const x86_64_ms_abi_int_parameter_registers[4] =
2280 {
2281   CX_REG, DX_REG, R8_REG, R9_REG
2282 };
2283
2284 static int const x86_64_int_return_registers[4] =
2285 {
2286   AX_REG, DX_REG, DI_REG, SI_REG
2287 };
2288
2289 /* Additional registers that are clobbered by SYSV calls.  */
2290
2291 int const x86_64_ms_sysv_extra_clobbered_registers[12] =
2292 {
2293   SI_REG, DI_REG,
2294   XMM6_REG, XMM7_REG,
2295   XMM8_REG, XMM9_REG, XMM10_REG, XMM11_REG,
2296   XMM12_REG, XMM13_REG, XMM14_REG, XMM15_REG
2297 };
2298
2299 /* Define the structure for the machine field in struct function.  */
2300
2301 struct GTY(()) stack_local_entry {
2302   unsigned short mode;
2303   unsigned short n;
2304   rtx rtl;
2305   struct stack_local_entry *next;
2306 };
2307
2308 /* Structure describing stack frame layout.
2309    Stack grows downward:
2310
2311    [arguments]
2312                                         <- ARG_POINTER
2313    saved pc
2314
2315    saved static chain                   if ix86_static_chain_on_stack
2316
2317    saved frame pointer                  if frame_pointer_needed
2318                                         <- HARD_FRAME_POINTER
2319    [saved regs]
2320                                         <- regs_save_offset
2321    [padding0]
2322
2323    [saved SSE regs]
2324                                         <- sse_regs_save_offset
2325    [padding1]          |
2326                        |                <- FRAME_POINTER
2327    [va_arg registers]  |
2328                        |
2329    [frame]             |
2330                        |
2331    [padding2]          | = to_allocate
2332                                         <- STACK_POINTER
2333   */
2334 struct ix86_frame
2335 {
2336   int nsseregs;
2337   int nregs;
2338   int va_arg_size;
2339   int red_zone_size;
2340   int outgoing_arguments_size;
2341
2342   /* The offsets relative to ARG_POINTER.  */
2343   HOST_WIDE_INT frame_pointer_offset;
2344   HOST_WIDE_INT hard_frame_pointer_offset;
2345   HOST_WIDE_INT stack_pointer_offset;
2346   HOST_WIDE_INT hfp_save_offset;
2347   HOST_WIDE_INT reg_save_offset;
2348   HOST_WIDE_INT sse_reg_save_offset;
2349
2350   /* When save_regs_using_mov is set, emit prologue using
2351      move instead of push instructions.  */
2352   bool save_regs_using_mov;
2353 };
2354
2355 /* Which cpu are we scheduling for.  */
2356 enum attr_cpu ix86_schedule;
2357
2358 /* Which cpu are we optimizing for.  */
2359 enum processor_type ix86_tune;
2360
2361 /* Which instruction set architecture to use.  */
2362 enum processor_type ix86_arch;
2363
2364 /* True if processor has SSE prefetch instruction.  */
2365 unsigned char x86_prefetch_sse;
2366
2367 /* -mstackrealign option */
2368 static const char ix86_force_align_arg_pointer_string[]
2369   = "force_align_arg_pointer";
2370
2371 static rtx (*ix86_gen_leave) (void);
2372 static rtx (*ix86_gen_add3) (rtx, rtx, rtx);
2373 static rtx (*ix86_gen_sub3) (rtx, rtx, rtx);
2374 static rtx (*ix86_gen_sub3_carry) (rtx, rtx, rtx, rtx, rtx);
2375 static rtx (*ix86_gen_one_cmpl2) (rtx, rtx);
2376 static rtx (*ix86_gen_monitor) (rtx, rtx, rtx);
2377 static rtx (*ix86_gen_andsp) (rtx, rtx, rtx);
2378 static rtx (*ix86_gen_allocate_stack_worker) (rtx, rtx);
2379 static rtx (*ix86_gen_adjust_stack_and_probe) (rtx, rtx, rtx);
2380 static rtx (*ix86_gen_probe_stack_range) (rtx, rtx, rtx);
2381 static rtx (*ix86_gen_tls_global_dynamic_64) (rtx, rtx, rtx);
2382 static rtx (*ix86_gen_tls_local_dynamic_base_64) (rtx, rtx);
2383
2384 /* Preferred alignment for stack boundary in bits.  */
2385 unsigned int ix86_preferred_stack_boundary;
2386
2387 /* Alignment for incoming stack boundary in bits specified at
2388    command line.  */
2389 static unsigned int ix86_user_incoming_stack_boundary;
2390
2391 /* Default alignment for incoming stack boundary in bits.  */
2392 static unsigned int ix86_default_incoming_stack_boundary;
2393
2394 /* Alignment for incoming stack boundary in bits.  */
2395 unsigned int ix86_incoming_stack_boundary;
2396
2397 /* Calling abi specific va_list type nodes.  */
2398 static GTY(()) tree sysv_va_list_type_node;
2399 static GTY(()) tree ms_va_list_type_node;
2400
2401 /* Prefix built by ASM_GENERATE_INTERNAL_LABEL.  */
2402 char internal_label_prefix[16];
2403 int internal_label_prefix_len;
2404
2405 /* Fence to use after loop using movnt.  */
2406 tree x86_mfence;
2407
2408 /* Register class used for passing given 64bit part of the argument.
2409    These represent classes as documented by the PS ABI, with the exception
2410    of SSESF, SSEDF classes, that are basically SSE class, just gcc will
2411    use SF or DFmode move instead of DImode to avoid reformatting penalties.
2412
2413    Similarly we play games with INTEGERSI_CLASS to use cheaper SImode moves
2414    whenever possible (upper half does contain padding).  */
2415 enum x86_64_reg_class
2416   {
2417     X86_64_NO_CLASS,
2418     X86_64_INTEGER_CLASS,
2419     X86_64_INTEGERSI_CLASS,
2420     X86_64_SSE_CLASS,
2421     X86_64_SSESF_CLASS,
2422     X86_64_SSEDF_CLASS,
2423     X86_64_SSEUP_CLASS,
2424     X86_64_X87_CLASS,
2425     X86_64_X87UP_CLASS,
2426     X86_64_COMPLEX_X87_CLASS,
2427     X86_64_MEMORY_CLASS
2428   };
2429
2430 #define MAX_CLASSES 8
2431
2432 /* Table of constants used by fldpi, fldln2, etc....  */
2433 static REAL_VALUE_TYPE ext_80387_constants_table [5];
2434 static bool ext_80387_constants_init = 0;
2435
2436 \f
2437 static struct machine_function * ix86_init_machine_status (void);
2438 static rtx ix86_function_value (const_tree, const_tree, bool);
2439 static bool ix86_function_value_regno_p (const unsigned int);
2440 static unsigned int ix86_function_arg_boundary (machine_mode,
2441                                                 const_tree);
2442 static rtx ix86_static_chain (const_tree, bool);
2443 static int ix86_function_regparm (const_tree, const_tree);
2444 static void ix86_compute_frame_layout (struct ix86_frame *);
2445 static bool ix86_expand_vector_init_one_nonzero (bool, machine_mode,
2446                                                  rtx, rtx, int);
2447 static void ix86_add_new_builtins (HOST_WIDE_INT);
2448 static tree ix86_canonical_va_list_type (tree);
2449 static void predict_jump (int);
2450 static unsigned int split_stack_prologue_scratch_regno (void);
2451 static bool i386_asm_output_addr_const_extra (FILE *, rtx);
2452
2453 enum ix86_function_specific_strings
2454 {
2455   IX86_FUNCTION_SPECIFIC_ARCH,
2456   IX86_FUNCTION_SPECIFIC_TUNE,
2457   IX86_FUNCTION_SPECIFIC_MAX
2458 };
2459
2460 static char *ix86_target_string (HOST_WIDE_INT, int, const char *,
2461                                  const char *, enum fpmath_unit, bool);
2462 static void ix86_function_specific_save (struct cl_target_option *,
2463                                          struct gcc_options *opts);
2464 static void ix86_function_specific_restore (struct gcc_options *opts,
2465                                             struct cl_target_option *);
2466 static void ix86_function_specific_print (FILE *, int,
2467                                           struct cl_target_option *);
2468 static bool ix86_valid_target_attribute_p (tree, tree, tree, int);
2469 static bool ix86_valid_target_attribute_inner_p (tree, char *[],
2470                                                  struct gcc_options *,
2471                                                  struct gcc_options *,
2472                                                  struct gcc_options *);
2473 static bool ix86_can_inline_p (tree, tree);
2474 static void ix86_set_current_function (tree);
2475 static unsigned int ix86_minimum_incoming_stack_boundary (bool);
2476
2477 static enum calling_abi ix86_function_abi (const_tree);
2478
2479 \f
2480 #ifndef SUBTARGET32_DEFAULT_CPU
2481 #define SUBTARGET32_DEFAULT_CPU "i386"
2482 #endif
2483
2484 /* Whether -mtune= or -march= were specified */
2485 static int ix86_tune_defaulted;
2486 static int ix86_arch_specified;
2487
2488 /* Vectorization library interface and handlers.  */
2489 static tree (*ix86_veclib_handler) (enum built_in_function, tree, tree);
2490
2491 static tree ix86_veclibabi_svml (enum built_in_function, tree, tree);
2492 static tree ix86_veclibabi_acml (enum built_in_function, tree, tree);
2493
2494 /* Processor target table, indexed by processor number */
2495 struct ptt
2496 {
2497   const char *const name;                       /* processor name  */
2498   const struct processor_costs *cost;           /* Processor costs */
2499   const int align_loop;                         /* Default alignments.  */
2500   const int align_loop_max_skip;
2501   const int align_jump;
2502   const int align_jump_max_skip;
2503   const int align_func;
2504 };
2505
2506 /* This table must be in sync with enum processor_type in i386.h.  */ 
2507 static const struct ptt processor_target_table[PROCESSOR_max] =
2508 {
2509   {"generic", &generic_cost, 16, 10, 16, 10, 16},
2510   {"i386", &i386_cost, 4, 3, 4, 3, 4},
2511   {"i486", &i486_cost, 16, 15, 16, 15, 16},
2512   {"pentium", &pentium_cost, 16, 7, 16, 7, 16},
2513   {"pentiumpro", &pentiumpro_cost, 16, 15, 16, 10, 16},
2514   {"pentium4", &pentium4_cost, 0, 0, 0, 0, 0},
2515   {"nocona", &nocona_cost, 0, 0, 0, 0, 0},
2516   {"core2", &core_cost, 16, 10, 16, 10, 16},
2517   {"nehalem", &core_cost, 16, 10, 16, 10, 16},
2518   {"sandybridge", &core_cost, 16, 10, 16, 10, 16},
2519   {"haswell", &core_cost, 16, 10, 16, 10, 16},
2520   {"bonnell", &atom_cost, 16, 15, 16, 7, 16},
2521   {"silvermont", &slm_cost, 16, 15, 16, 7, 16},
2522   {"knl", &slm_cost, 16, 15, 16, 7, 16},
2523   {"intel", &intel_cost, 16, 15, 16, 7, 16},
2524   {"geode", &geode_cost, 0, 0, 0, 0, 0},
2525   {"k6", &k6_cost, 32, 7, 32, 7, 32},
2526   {"athlon", &athlon_cost, 16, 7, 16, 7, 16},
2527   {"k8", &k8_cost, 16, 7, 16, 7, 16},
2528   {"amdfam10", &amdfam10_cost, 32, 24, 32, 7, 32},
2529   {"bdver1", &bdver1_cost, 16, 10, 16, 7, 11},
2530   {"bdver2", &bdver2_cost, 16, 10, 16, 7, 11},
2531   {"bdver3", &bdver3_cost, 16, 10, 16, 7, 11},
2532   {"bdver4", &bdver4_cost, 16, 10, 16, 7, 11},
2533   {"btver1", &btver1_cost, 16, 10, 16, 7, 11},
2534   {"btver2", &btver2_cost, 16, 10, 16, 7, 11}
2535 };
2536 \f
2537 static unsigned int
2538 rest_of_handle_insert_vzeroupper (void)
2539 {
2540   int i;
2541
2542   /* vzeroupper instructions are inserted immediately after reload to
2543      account for possible spills from 256bit registers.  The pass
2544      reuses mode switching infrastructure by re-running mode insertion
2545      pass, so disable entities that have already been processed.  */
2546   for (i = 0; i < MAX_386_ENTITIES; i++)
2547     ix86_optimize_mode_switching[i] = 0;
2548
2549   ix86_optimize_mode_switching[AVX_U128] = 1;
2550
2551   /* Call optimize_mode_switching.  */
2552   g->get_passes ()->execute_pass_mode_switching ();
2553   return 0;
2554 }
2555
2556 namespace {
2557
2558 const pass_data pass_data_insert_vzeroupper =
2559 {
2560   RTL_PASS, /* type */
2561   "vzeroupper", /* name */
2562   OPTGROUP_NONE, /* optinfo_flags */
2563   TV_NONE, /* tv_id */
2564   0, /* properties_required */
2565   0, /* properties_provided */
2566   0, /* properties_destroyed */
2567   0, /* todo_flags_start */
2568   TODO_df_finish, /* todo_flags_finish */
2569 };
2570
2571 class pass_insert_vzeroupper : public rtl_opt_pass
2572 {
2573 public:
2574   pass_insert_vzeroupper(gcc::context *ctxt)
2575     : rtl_opt_pass(pass_data_insert_vzeroupper, ctxt)
2576   {}
2577
2578   /* opt_pass methods: */
2579   virtual bool gate (function *)
2580     {
2581       return TARGET_AVX && !TARGET_AVX512F
2582              && TARGET_VZEROUPPER && flag_expensive_optimizations
2583              && !optimize_size;
2584     }
2585
2586   virtual unsigned int execute (function *)
2587     {
2588       return rest_of_handle_insert_vzeroupper ();
2589     }
2590
2591 }; // class pass_insert_vzeroupper
2592
2593 } // anon namespace
2594
2595 rtl_opt_pass *
2596 make_pass_insert_vzeroupper (gcc::context *ctxt)
2597 {
2598   return new pass_insert_vzeroupper (ctxt);
2599 }
2600
2601 /* Return true if a red-zone is in use.  */
2602
2603 static inline bool
2604 ix86_using_red_zone (void)
2605 {
2606   return TARGET_RED_ZONE && !TARGET_64BIT_MS_ABI;
2607 }
2608 \f
2609 /* Return a string that documents the current -m options.  The caller is
2610    responsible for freeing the string.  */
2611
2612 static char *
2613 ix86_target_string (HOST_WIDE_INT isa, int flags, const char *arch,
2614                     const char *tune, enum fpmath_unit fpmath,
2615                     bool add_nl_p)
2616 {
2617   struct ix86_target_opts
2618   {
2619     const char *option;         /* option string */
2620     HOST_WIDE_INT mask;         /* isa mask options */
2621   };
2622
2623   /* This table is ordered so that options like -msse4.2 that imply
2624      preceding options while match those first.  */
2625   static struct ix86_target_opts isa_opts[] =
2626   {
2627     { "-mfma4",         OPTION_MASK_ISA_FMA4 },
2628     { "-mfma",          OPTION_MASK_ISA_FMA },
2629     { "-mxop",          OPTION_MASK_ISA_XOP },
2630     { "-mlwp",          OPTION_MASK_ISA_LWP },
2631     { "-mavx512f",      OPTION_MASK_ISA_AVX512F },
2632     { "-mavx512er",     OPTION_MASK_ISA_AVX512ER },
2633     { "-mavx512cd",     OPTION_MASK_ISA_AVX512CD },
2634     { "-mavx512pf",     OPTION_MASK_ISA_AVX512PF },
2635     { "-mavx512dq",     OPTION_MASK_ISA_AVX512DQ },
2636     { "-mavx512bw",     OPTION_MASK_ISA_AVX512BW },
2637     { "-mavx512vl",     OPTION_MASK_ISA_AVX512VL },
2638     { "-mavx512ifma",   OPTION_MASK_ISA_AVX512IFMA },
2639     { "-mavx512vbmi",   OPTION_MASK_ISA_AVX512VBMI },
2640     { "-msse4a",        OPTION_MASK_ISA_SSE4A },
2641     { "-msse4.2",       OPTION_MASK_ISA_SSE4_2 },
2642     { "-msse4.1",       OPTION_MASK_ISA_SSE4_1 },
2643     { "-mssse3",        OPTION_MASK_ISA_SSSE3 },
2644     { "-msse3",         OPTION_MASK_ISA_SSE3 },
2645     { "-msse2",         OPTION_MASK_ISA_SSE2 },
2646     { "-msse",          OPTION_MASK_ISA_SSE },
2647     { "-m3dnow",        OPTION_MASK_ISA_3DNOW },
2648     { "-m3dnowa",       OPTION_MASK_ISA_3DNOW_A },
2649     { "-mmmx",          OPTION_MASK_ISA_MMX },
2650     { "-mabm",          OPTION_MASK_ISA_ABM },
2651     { "-mbmi",          OPTION_MASK_ISA_BMI },
2652     { "-mbmi2",         OPTION_MASK_ISA_BMI2 },
2653     { "-mlzcnt",        OPTION_MASK_ISA_LZCNT },
2654     { "-mhle",          OPTION_MASK_ISA_HLE },
2655     { "-mfxsr",         OPTION_MASK_ISA_FXSR },
2656     { "-mrdseed",       OPTION_MASK_ISA_RDSEED },
2657     { "-mprfchw",       OPTION_MASK_ISA_PRFCHW },
2658     { "-madx",          OPTION_MASK_ISA_ADX },
2659     { "-mtbm",          OPTION_MASK_ISA_TBM },
2660     { "-mpopcnt",       OPTION_MASK_ISA_POPCNT },
2661     { "-mmovbe",        OPTION_MASK_ISA_MOVBE },
2662     { "-mcrc32",        OPTION_MASK_ISA_CRC32 },
2663     { "-maes",          OPTION_MASK_ISA_AES },
2664     { "-msha",          OPTION_MASK_ISA_SHA },
2665     { "-mpclmul",       OPTION_MASK_ISA_PCLMUL },
2666     { "-mfsgsbase",     OPTION_MASK_ISA_FSGSBASE },
2667     { "-mrdrnd",        OPTION_MASK_ISA_RDRND },
2668     { "-mf16c",         OPTION_MASK_ISA_F16C },
2669     { "-mrtm",          OPTION_MASK_ISA_RTM },
2670     { "-mxsave",        OPTION_MASK_ISA_XSAVE },
2671     { "-mxsaveopt",     OPTION_MASK_ISA_XSAVEOPT },
2672     { "-mprefetchwt1",  OPTION_MASK_ISA_PREFETCHWT1 },
2673     { "-mclflushopt",   OPTION_MASK_ISA_CLFLUSHOPT },
2674     { "-mxsavec",       OPTION_MASK_ISA_XSAVEC },
2675     { "-mxsaves",       OPTION_MASK_ISA_XSAVES },
2676     { "-mmpx",          OPTION_MASK_ISA_MPX },
2677     { "-mclwb",         OPTION_MASK_ISA_CLWB },
2678     { "-mpcommit",      OPTION_MASK_ISA_PCOMMIT },
2679   };
2680
2681   /* Flag options.  */
2682   static struct ix86_target_opts flag_opts[] =
2683   {
2684     { "-m128bit-long-double",           MASK_128BIT_LONG_DOUBLE },
2685     { "-mlong-double-128",              MASK_LONG_DOUBLE_128 },
2686     { "-mlong-double-64",               MASK_LONG_DOUBLE_64 },
2687     { "-m80387",                        MASK_80387 },
2688     { "-maccumulate-outgoing-args",     MASK_ACCUMULATE_OUTGOING_ARGS },
2689     { "-malign-double",                 MASK_ALIGN_DOUBLE },
2690     { "-mcld",                          MASK_CLD },
2691     { "-mfp-ret-in-387",                MASK_FLOAT_RETURNS },
2692     { "-mieee-fp",                      MASK_IEEE_FP },
2693     { "-minline-all-stringops",         MASK_INLINE_ALL_STRINGOPS },
2694     { "-minline-stringops-dynamically", MASK_INLINE_STRINGOPS_DYNAMICALLY },
2695     { "-mms-bitfields",                 MASK_MS_BITFIELD_LAYOUT },
2696     { "-mno-align-stringops",           MASK_NO_ALIGN_STRINGOPS },
2697     { "-mno-fancy-math-387",            MASK_NO_FANCY_MATH_387 },
2698     { "-mno-push-args",                 MASK_NO_PUSH_ARGS },
2699     { "-mno-red-zone",                  MASK_NO_RED_ZONE },
2700     { "-momit-leaf-frame-pointer",      MASK_OMIT_LEAF_FRAME_POINTER },
2701     { "-mrecip",                        MASK_RECIP },
2702     { "-mrtd",                          MASK_RTD },
2703     { "-msseregparm",                   MASK_SSEREGPARM },
2704     { "-mstack-arg-probe",              MASK_STACK_PROBE },
2705     { "-mtls-direct-seg-refs",          MASK_TLS_DIRECT_SEG_REFS },
2706     { "-mvect8-ret-in-mem",             MASK_VECT8_RETURNS },
2707     { "-m8bit-idiv",                    MASK_USE_8BIT_IDIV },
2708     { "-mvzeroupper",                   MASK_VZEROUPPER },
2709     { "-mavx256-split-unaligned-load",  MASK_AVX256_SPLIT_UNALIGNED_LOAD},
2710     { "-mavx256-split-unaligned-store", MASK_AVX256_SPLIT_UNALIGNED_STORE},
2711     { "-mprefer-avx128",                MASK_PREFER_AVX128},
2712   };
2713
2714   const char *opts[ARRAY_SIZE (isa_opts) + ARRAY_SIZE (flag_opts) + 6][2];
2715
2716   char isa_other[40];
2717   char target_other[40];
2718   unsigned num = 0;
2719   unsigned i, j;
2720   char *ret;
2721   char *ptr;
2722   size_t len;
2723   size_t line_len;
2724   size_t sep_len;
2725   const char *abi;
2726
2727   memset (opts, '\0', sizeof (opts));
2728
2729   /* Add -march= option.  */
2730   if (arch)
2731     {
2732       opts[num][0] = "-march=";
2733       opts[num++][1] = arch;
2734     }
2735
2736   /* Add -mtune= option.  */
2737   if (tune)
2738     {
2739       opts[num][0] = "-mtune=";
2740       opts[num++][1] = tune;
2741     }
2742
2743   /* Add -m32/-m64/-mx32.  */
2744   if ((isa & OPTION_MASK_ISA_64BIT) != 0)
2745     {
2746       if ((isa & OPTION_MASK_ABI_64) != 0)
2747         abi = "-m64";
2748       else
2749         abi = "-mx32";
2750       isa &= ~ (OPTION_MASK_ISA_64BIT
2751                 | OPTION_MASK_ABI_64
2752                 | OPTION_MASK_ABI_X32);
2753     }
2754   else
2755     abi = "-m32";
2756   opts[num++][0] = abi;
2757
2758   /* Pick out the options in isa options.  */
2759   for (i = 0; i < ARRAY_SIZE (isa_opts); i++)
2760     {
2761       if ((isa & isa_opts[i].mask) != 0)
2762         {
2763           opts[num++][0] = isa_opts[i].option;
2764           isa &= ~ isa_opts[i].mask;
2765         }
2766     }
2767
2768   if (isa && add_nl_p)
2769     {
2770       opts[num++][0] = isa_other;
2771       sprintf (isa_other, "(other isa: %#" HOST_WIDE_INT_PRINT "x)",
2772                isa);
2773     }
2774
2775   /* Add flag options.  */
2776   for (i = 0; i < ARRAY_SIZE (flag_opts); i++)
2777     {
2778       if ((flags & flag_opts[i].mask) != 0)
2779         {
2780           opts[num++][0] = flag_opts[i].option;
2781           flags &= ~ flag_opts[i].mask;
2782         }
2783     }
2784
2785   if (flags && add_nl_p)
2786     {
2787       opts[num++][0] = target_other;
2788       sprintf (target_other, "(other flags: %#x)", flags);
2789     }
2790
2791   /* Add -fpmath= option.  */
2792   if (fpmath)
2793     {
2794       opts[num][0] = "-mfpmath=";
2795       switch ((int) fpmath)
2796         {
2797         case FPMATH_387:
2798           opts[num++][1] = "387";
2799           break;
2800
2801         case FPMATH_SSE:
2802           opts[num++][1] = "sse";
2803           break;
2804
2805         case FPMATH_387 | FPMATH_SSE:
2806           opts[num++][1] = "sse+387";
2807           break;
2808
2809         default:
2810           gcc_unreachable ();
2811         }
2812     }
2813
2814   /* Any options?  */
2815   if (num == 0)
2816     return NULL;
2817
2818   gcc_assert (num < ARRAY_SIZE (opts));
2819
2820   /* Size the string.  */
2821   len = 0;
2822   sep_len = (add_nl_p) ? 3 : 1;
2823   for (i = 0; i < num; i++)
2824     {
2825       len += sep_len;
2826       for (j = 0; j < 2; j++)
2827         if (opts[i][j])
2828           len += strlen (opts[i][j]);
2829     }
2830
2831   /* Build the string.  */
2832   ret = ptr = (char *) xmalloc (len);
2833   line_len = 0;
2834
2835   for (i = 0; i < num; i++)
2836     {
2837       size_t len2[2];
2838
2839       for (j = 0; j < 2; j++)
2840         len2[j] = (opts[i][j]) ? strlen (opts[i][j]) : 0;
2841
2842       if (i != 0)
2843         {
2844           *ptr++ = ' ';
2845           line_len++;
2846
2847           if (add_nl_p && line_len + len2[0] + len2[1] > 70)
2848             {
2849               *ptr++ = '\\';
2850               *ptr++ = '\n';
2851               line_len = 0;
2852             }
2853         }
2854
2855       for (j = 0; j < 2; j++)
2856         if (opts[i][j])
2857           {
2858             memcpy (ptr, opts[i][j], len2[j]);
2859             ptr += len2[j];
2860             line_len += len2[j];
2861           }
2862     }
2863
2864   *ptr = '\0';
2865   gcc_assert (ret + len >= ptr);
2866
2867   return ret;
2868 }
2869
2870 /* Return true, if profiling code should be emitted before
2871    prologue. Otherwise it returns false.
2872    Note: For x86 with "hotfix" it is sorried.  */
2873 static bool
2874 ix86_profile_before_prologue (void)
2875 {
2876   return flag_fentry != 0;
2877 }
2878
2879 /* Function that is callable from the debugger to print the current
2880    options.  */
2881 void ATTRIBUTE_UNUSED
2882 ix86_debug_options (void)
2883 {
2884   char *opts = ix86_target_string (ix86_isa_flags, target_flags,
2885                                    ix86_arch_string, ix86_tune_string,
2886                                    ix86_fpmath, true);
2887
2888   if (opts)
2889     {
2890       fprintf (stderr, "%s\n\n", opts);
2891       free (opts);
2892     }
2893   else
2894     fputs ("<no options>\n\n", stderr);
2895
2896   return;
2897 }
2898
2899 static const char *stringop_alg_names[] = {
2900 #define DEF_ENUM
2901 #define DEF_ALG(alg, name) #name,
2902 #include "stringop.def"
2903 #undef DEF_ENUM
2904 #undef DEF_ALG
2905 };
2906
2907 /* Parse parameter string passed to -mmemcpy-strategy= or -mmemset-strategy=.
2908    The string is of the following form (or comma separated list of it):
2909
2910      strategy_alg:max_size:[align|noalign]
2911
2912    where the full size range for the strategy is either [0, max_size] or
2913    [min_size, max_size], in which min_size is the max_size + 1 of the
2914    preceding range.  The last size range must have max_size == -1.
2915
2916    Examples:
2917
2918     1.
2919        -mmemcpy-strategy=libcall:-1:noalign
2920
2921       this is equivalent to (for known size memcpy) -mstringop-strategy=libcall
2922
2923
2924    2.
2925       -mmemset-strategy=rep_8byte:16:noalign,vector_loop:2048:align,libcall:-1:noalign
2926
2927       This is to tell the compiler to use the following strategy for memset
2928       1) when the expected size is between [1, 16], use rep_8byte strategy;
2929       2) when the size is between [17, 2048], use vector_loop;
2930       3) when the size is > 2048, use libcall.  */
2931
2932 struct stringop_size_range
2933 {
2934   int max;
2935   stringop_alg alg;
2936   bool noalign;
2937 };
2938
2939 static void
2940 ix86_parse_stringop_strategy_string (char *strategy_str, bool is_memset)
2941 {
2942   const struct stringop_algs *default_algs;
2943   stringop_size_range input_ranges[MAX_STRINGOP_ALGS];
2944   char *curr_range_str, *next_range_str;
2945   int i = 0, n = 0;
2946
2947   if (is_memset)
2948     default_algs = &ix86_cost->memset[TARGET_64BIT != 0];
2949   else
2950     default_algs = &ix86_cost->memcpy[TARGET_64BIT != 0];
2951
2952   curr_range_str = strategy_str;
2953
2954   do
2955     {
2956       int maxs;
2957       char alg_name[128];
2958       char align[16];
2959       next_range_str = strchr (curr_range_str, ',');
2960       if (next_range_str)
2961         *next_range_str++ = '\0';
2962
2963       if (3 != sscanf (curr_range_str, "%20[^:]:%d:%10s",
2964                        alg_name, &maxs, align))
2965         {
2966           error ("wrong arg %s to option %s", curr_range_str,
2967                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2968           return;
2969         }
2970
2971       if (n > 0 && (maxs < (input_ranges[n - 1].max + 1) && maxs != -1))
2972         {
2973           error ("size ranges of option %s should be increasing",
2974                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2975           return;
2976         }
2977
2978       for (i = 0; i < last_alg; i++)
2979         if (!strcmp (alg_name, stringop_alg_names[i]))
2980           break;
2981
2982       if (i == last_alg)
2983         {
2984           error ("wrong stringop strategy name %s specified for option %s",
2985                  alg_name,
2986                  is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
2987           return;
2988         }
2989
2990       input_ranges[n].max = maxs;
2991       input_ranges[n].alg = (stringop_alg) i;
2992       if (!strcmp (align, "align"))
2993         input_ranges[n].noalign = false;
2994       else if (!strcmp (align, "noalign"))
2995         input_ranges[n].noalign = true;
2996       else
2997         {
2998           error ("unknown alignment %s specified for option %s",
2999                  align, is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
3000           return;
3001         }
3002       n++;
3003       curr_range_str = next_range_str;
3004     }
3005   while (curr_range_str);
3006
3007   if (input_ranges[n - 1].max != -1)
3008     {
3009       error ("the max value for the last size range should be -1"
3010              " for option %s",
3011              is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
3012       return;
3013     }
3014
3015   if (n > MAX_STRINGOP_ALGS)
3016     {
3017       error ("too many size ranges specified in option %s",
3018              is_memset ? "-mmemset_strategy=" : "-mmemcpy_strategy=");
3019       return;
3020     }
3021
3022   /* Now override the default algs array.  */
3023   for (i = 0; i < n; i++)
3024     {
3025       *const_cast<int *>(&default_algs->size[i].max) = input_ranges[i].max;
3026       *const_cast<stringop_alg *>(&default_algs->size[i].alg)
3027           = input_ranges[i].alg;
3028       *const_cast<int *>(&default_algs->size[i].noalign)
3029           = input_ranges[i].noalign;
3030     }
3031 }
3032
3033 \f
3034 /* parse -mtune-ctrl= option. When DUMP is true,
3035    print the features that are explicitly set.  */
3036
3037 static void
3038 parse_mtune_ctrl_str (bool dump)
3039 {
3040   if (!ix86_tune_ctrl_string)
3041     return;
3042
3043   char *next_feature_string = NULL;
3044   char *curr_feature_string = xstrdup (ix86_tune_ctrl_string);
3045   char *orig = curr_feature_string;
3046   int i;
3047   do
3048     {
3049       bool clear = false;
3050
3051       next_feature_string = strchr (curr_feature_string, ',');
3052       if (next_feature_string)
3053         *next_feature_string++ = '\0';
3054       if (*curr_feature_string == '^')
3055         {
3056           curr_feature_string++;
3057           clear = true;
3058         }
3059       for (i = 0; i < X86_TUNE_LAST; i++)
3060         {
3061           if (!strcmp (curr_feature_string, ix86_tune_feature_names[i]))
3062             {
3063               ix86_tune_features[i] = !clear;
3064               if (dump)
3065                 fprintf (stderr, "Explicitly %s feature %s\n",
3066                          clear ? "clear" : "set", ix86_tune_feature_names[i]);
3067               break;
3068             }
3069         }
3070       if (i == X86_TUNE_LAST)
3071         error ("Unknown parameter to option -mtune-ctrl: %s",
3072                clear ? curr_feature_string - 1 : curr_feature_string);
3073       curr_feature_string = next_feature_string;
3074     }
3075   while (curr_feature_string);
3076   free (orig);
3077 }
3078
3079 /* Helper function to set ix86_tune_features. IX86_TUNE is the
3080    processor type.  */
3081
3082 static void
3083 set_ix86_tune_features (enum processor_type ix86_tune, bool dump)
3084 {
3085   unsigned int ix86_tune_mask = 1u << ix86_tune;
3086   int i;
3087
3088   for (i = 0; i < X86_TUNE_LAST; ++i)
3089     {
3090       if (ix86_tune_no_default)
3091         ix86_tune_features[i] = 0;
3092       else
3093         ix86_tune_features[i] = !!(initial_ix86_tune_features[i] & ix86_tune_mask);
3094     }
3095
3096   if (dump)
3097     {
3098       fprintf (stderr, "List of x86 specific tuning parameter names:\n");
3099       for (i = 0; i < X86_TUNE_LAST; i++)
3100         fprintf (stderr, "%s : %s\n", ix86_tune_feature_names[i],
3101                  ix86_tune_features[i] ? "on" : "off");
3102     }
3103
3104   parse_mtune_ctrl_str (dump);
3105 }
3106
3107
3108 /* Override various settings based on options.  If MAIN_ARGS_P, the
3109    options are from the command line, otherwise they are from
3110    attributes.  */
3111
3112 static void
3113 ix86_option_override_internal (bool main_args_p,
3114                                struct gcc_options *opts,
3115                                struct gcc_options *opts_set)
3116 {
3117   int i;
3118   unsigned int ix86_arch_mask;
3119   const bool ix86_tune_specified = (opts->x_ix86_tune_string != NULL);
3120   const char *prefix;
3121   const char *suffix;
3122   const char *sw;
3123
3124 #define PTA_3DNOW               (HOST_WIDE_INT_1 << 0)
3125 #define PTA_3DNOW_A             (HOST_WIDE_INT_1 << 1)
3126 #define PTA_64BIT               (HOST_WIDE_INT_1 << 2)
3127 #define PTA_ABM                 (HOST_WIDE_INT_1 << 3)
3128 #define PTA_AES                 (HOST_WIDE_INT_1 << 4)
3129 #define PTA_AVX                 (HOST_WIDE_INT_1 << 5)
3130 #define PTA_BMI                 (HOST_WIDE_INT_1 << 6)
3131 #define PTA_CX16                (HOST_WIDE_INT_1 << 7)
3132 #define PTA_F16C                (HOST_WIDE_INT_1 << 8)
3133 #define PTA_FMA                 (HOST_WIDE_INT_1 << 9)
3134 #define PTA_FMA4                (HOST_WIDE_INT_1 << 10)
3135 #define PTA_FSGSBASE            (HOST_WIDE_INT_1 << 11)
3136 #define PTA_LWP                 (HOST_WIDE_INT_1 << 12)
3137 #define PTA_LZCNT               (HOST_WIDE_INT_1 << 13)
3138 #define PTA_MMX                 (HOST_WIDE_INT_1 << 14)
3139 #define PTA_MOVBE               (HOST_WIDE_INT_1 << 15)
3140 #define PTA_NO_SAHF             (HOST_WIDE_INT_1 << 16)
3141 #define PTA_PCLMUL              (HOST_WIDE_INT_1 << 17)
3142 #define PTA_POPCNT              (HOST_WIDE_INT_1 << 18)
3143 #define PTA_PREFETCH_SSE        (HOST_WIDE_INT_1 << 19)
3144 #define PTA_RDRND               (HOST_WIDE_INT_1 << 20)
3145 #define PTA_SSE                 (HOST_WIDE_INT_1 << 21)
3146 #define PTA_SSE2                (HOST_WIDE_INT_1 << 22)
3147 #define PTA_SSE3                (HOST_WIDE_INT_1 << 23)
3148 #define PTA_SSE4_1              (HOST_WIDE_INT_1 << 24)
3149 #define PTA_SSE4_2              (HOST_WIDE_INT_1 << 25)
3150 #define PTA_SSE4A               (HOST_WIDE_INT_1 << 26)
3151 #define PTA_SSSE3               (HOST_WIDE_INT_1 << 27)
3152 #define PTA_TBM                 (HOST_WIDE_INT_1 << 28)
3153 #define PTA_XOP                 (HOST_WIDE_INT_1 << 29)
3154 #define PTA_AVX2                (HOST_WIDE_INT_1 << 30)
3155 #define PTA_BMI2                (HOST_WIDE_INT_1 << 31)
3156 #define PTA_RTM                 (HOST_WIDE_INT_1 << 32)
3157 #define PTA_HLE                 (HOST_WIDE_INT_1 << 33)
3158 #define PTA_PRFCHW              (HOST_WIDE_INT_1 << 34)
3159 #define PTA_RDSEED              (HOST_WIDE_INT_1 << 35)
3160 #define PTA_ADX                 (HOST_WIDE_INT_1 << 36)
3161 #define PTA_FXSR                (HOST_WIDE_INT_1 << 37)
3162 #define PTA_XSAVE               (HOST_WIDE_INT_1 << 38)
3163 #define PTA_XSAVEOPT            (HOST_WIDE_INT_1 << 39)
3164 #define PTA_AVX512F             (HOST_WIDE_INT_1 << 40)
3165 #define PTA_AVX512ER            (HOST_WIDE_INT_1 << 41)
3166 #define PTA_AVX512PF            (HOST_WIDE_INT_1 << 42)
3167 #define PTA_AVX512CD            (HOST_WIDE_INT_1 << 43)
3168 #define PTA_MPX                 (HOST_WIDE_INT_1 << 44)
3169 #define PTA_SHA                 (HOST_WIDE_INT_1 << 45)
3170 #define PTA_PREFETCHWT1         (HOST_WIDE_INT_1 << 46)
3171 #define PTA_CLFLUSHOPT          (HOST_WIDE_INT_1 << 47)
3172 #define PTA_XSAVEC              (HOST_WIDE_INT_1 << 48)
3173 #define PTA_XSAVES              (HOST_WIDE_INT_1 << 49)
3174 #define PTA_AVX512DQ            (HOST_WIDE_INT_1 << 50)
3175 #define PTA_AVX512BW            (HOST_WIDE_INT_1 << 51)
3176 #define PTA_AVX512VL            (HOST_WIDE_INT_1 << 52)
3177 #define PTA_AVX512IFMA          (HOST_WIDE_INT_1 << 53)
3178 #define PTA_AVX512VBMI          (HOST_WIDE_INT_1 << 54)
3179 #define PTA_CLWB                (HOST_WIDE_INT_1 << 55)
3180 #define PTA_PCOMMIT             (HOST_WIDE_INT_1 << 56)
3181
3182 #define PTA_CORE2 \
3183   (PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3 | PTA_SSSE3 \
3184    | PTA_CX16 | PTA_FXSR)
3185 #define PTA_NEHALEM \
3186   (PTA_CORE2 | PTA_SSE4_1 | PTA_SSE4_2 | PTA_POPCNT)
3187 #define PTA_WESTMERE \
3188   (PTA_NEHALEM | PTA_AES | PTA_PCLMUL)
3189 #define PTA_SANDYBRIDGE \
3190   (PTA_WESTMERE | PTA_AVX | PTA_XSAVE | PTA_XSAVEOPT)
3191 #define PTA_IVYBRIDGE \
3192   (PTA_SANDYBRIDGE | PTA_FSGSBASE | PTA_RDRND | PTA_F16C)
3193 #define PTA_HASWELL \
3194   (PTA_IVYBRIDGE | PTA_AVX2 | PTA_BMI | PTA_BMI2 | PTA_LZCNT \
3195    | PTA_FMA | PTA_MOVBE | PTA_HLE)
3196 #define PTA_BROADWELL \
3197   (PTA_HASWELL | PTA_ADX | PTA_PRFCHW | PTA_RDSEED)
3198 #define PTA_KNL \
3199   (PTA_BROADWELL | PTA_AVX512PF | PTA_AVX512ER | PTA_AVX512F | PTA_AVX512CD)
3200 #define PTA_BONNELL \
3201   (PTA_CORE2 | PTA_MOVBE)
3202 #define PTA_SILVERMONT \
3203   (PTA_WESTMERE | PTA_MOVBE)
3204
3205 /* if this reaches 64, need to widen struct pta flags below */
3206
3207   static struct pta
3208     {
3209       const char *const name;           /* processor name or nickname.  */
3210       const enum processor_type processor;
3211       const enum attr_cpu schedule;
3212       const unsigned HOST_WIDE_INT flags;
3213     }
3214   const processor_alias_table[] =
3215     {
3216       {"i386", PROCESSOR_I386, CPU_NONE, 0},
3217       {"i486", PROCESSOR_I486, CPU_NONE, 0},
3218       {"i586", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
3219       {"pentium", PROCESSOR_PENTIUM, CPU_PENTIUM, 0},
3220       {"pentium-mmx", PROCESSOR_PENTIUM, CPU_PENTIUM, PTA_MMX},
3221       {"winchip-c6", PROCESSOR_I486, CPU_NONE, PTA_MMX},
3222       {"winchip2", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3223       {"c3", PROCESSOR_I486, CPU_NONE, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3224       {"c3-2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3225         PTA_MMX | PTA_SSE | PTA_FXSR},
3226       {"i686", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
3227       {"pentiumpro", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, 0},
3228       {"pentium2", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO, PTA_MMX | PTA_FXSR},
3229       {"pentium3", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3230         PTA_MMX | PTA_SSE | PTA_FXSR},
3231       {"pentium3m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3232         PTA_MMX | PTA_SSE | PTA_FXSR},
3233       {"pentium-m", PROCESSOR_PENTIUMPRO, CPU_PENTIUMPRO,
3234         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_FXSR},
3235       {"pentium4", PROCESSOR_PENTIUM4, CPU_NONE,
3236         PTA_MMX |PTA_SSE | PTA_SSE2 | PTA_FXSR},
3237       {"pentium4m", PROCESSOR_PENTIUM4, CPU_NONE,
3238         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_FXSR},
3239       {"prescott", PROCESSOR_NOCONA, CPU_NONE,
3240         PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3 | PTA_FXSR},
3241       {"nocona", PROCESSOR_NOCONA, CPU_NONE,
3242         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3243         | PTA_CX16 | PTA_NO_SAHF | PTA_FXSR},
3244       {"core2", PROCESSOR_CORE2, CPU_CORE2, PTA_CORE2},
3245       {"nehalem", PROCESSOR_NEHALEM, CPU_NEHALEM, PTA_NEHALEM},
3246       {"corei7", PROCESSOR_NEHALEM, CPU_NEHALEM, PTA_NEHALEM},
3247       {"westmere", PROCESSOR_NEHALEM, CPU_NEHALEM, PTA_WESTMERE},
3248       {"sandybridge", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3249         PTA_SANDYBRIDGE},
3250       {"corei7-avx", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3251         PTA_SANDYBRIDGE},
3252       {"ivybridge", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3253         PTA_IVYBRIDGE},
3254       {"core-avx-i", PROCESSOR_SANDYBRIDGE, CPU_NEHALEM,
3255         PTA_IVYBRIDGE},
3256       {"haswell", PROCESSOR_HASWELL, CPU_NEHALEM, PTA_HASWELL},
3257       {"core-avx2", PROCESSOR_HASWELL, CPU_NEHALEM, PTA_HASWELL},
3258       {"broadwell", PROCESSOR_HASWELL, CPU_NEHALEM, PTA_BROADWELL},
3259       {"bonnell", PROCESSOR_BONNELL, CPU_ATOM, PTA_BONNELL},
3260       {"atom", PROCESSOR_BONNELL, CPU_ATOM, PTA_BONNELL},
3261       {"silvermont", PROCESSOR_SILVERMONT, CPU_SLM, PTA_SILVERMONT},
3262       {"slm", PROCESSOR_SILVERMONT, CPU_SLM, PTA_SILVERMONT},
3263       {"knl", PROCESSOR_KNL, CPU_KNL, PTA_KNL},
3264       {"intel", PROCESSOR_INTEL, CPU_SLM, PTA_NEHALEM},
3265       {"geode", PROCESSOR_GEODE, CPU_GEODE,
3266         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE | PTA_PRFCHW},
3267       {"k6", PROCESSOR_K6, CPU_K6, PTA_MMX},
3268       {"k6-2", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3269       {"k6-3", PROCESSOR_K6, CPU_K6, PTA_MMX | PTA_3DNOW | PTA_PRFCHW},
3270       {"athlon", PROCESSOR_ATHLON, CPU_ATHLON,
3271         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE | PTA_PRFCHW},
3272       {"athlon-tbird", PROCESSOR_ATHLON, CPU_ATHLON,
3273         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_PREFETCH_SSE | PTA_PRFCHW},
3274       {"athlon-4", PROCESSOR_ATHLON, CPU_ATHLON,
3275         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_PRFCHW | PTA_FXSR},
3276       {"athlon-xp", PROCESSOR_ATHLON, CPU_ATHLON,
3277         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_PRFCHW | PTA_FXSR},
3278       {"athlon-mp", PROCESSOR_ATHLON, CPU_ATHLON,
3279         PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_PRFCHW | PTA_FXSR},
3280       {"x86-64", PROCESSOR_K8, CPU_K8,
3281         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_NO_SAHF | PTA_FXSR},
3282       {"k8", PROCESSOR_K8, CPU_K8,
3283         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3284         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3285       {"k8-sse3", PROCESSOR_K8, CPU_K8,
3286         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3287         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3288       {"opteron", PROCESSOR_K8, CPU_K8,
3289         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3290         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3291       {"opteron-sse3", PROCESSOR_K8, CPU_K8,
3292         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3293         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3294       {"athlon64", PROCESSOR_K8, CPU_K8,
3295         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3296         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3297       {"athlon64-sse3", PROCESSOR_K8, CPU_K8,
3298         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3299         | PTA_SSE2 | PTA_SSE3 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3300       {"athlon-fx", PROCESSOR_K8, CPU_K8,
3301         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE
3302         | PTA_SSE2 | PTA_NO_SAHF | PTA_PRFCHW | PTA_FXSR},
3303       {"amdfam10", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
3304         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_SSE2
3305         | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_PRFCHW | PTA_FXSR},
3306       {"barcelona", PROCESSOR_AMDFAM10, CPU_AMDFAM10,
3307         PTA_64BIT | PTA_MMX | PTA_3DNOW | PTA_3DNOW_A | PTA_SSE | PTA_SSE2
3308         | PTA_SSE3 | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_PRFCHW | PTA_FXSR},
3309       {"bdver1", PROCESSOR_BDVER1, CPU_BDVER1,
3310         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3311         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3312         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_FMA4
3313         | PTA_XOP | PTA_LWP | PTA_PRFCHW | PTA_FXSR | PTA_XSAVE},
3314       {"bdver2", PROCESSOR_BDVER2, CPU_BDVER2,
3315         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3316         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3317         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_FMA4
3318         | PTA_XOP | PTA_LWP | PTA_BMI | PTA_TBM | PTA_F16C
3319         | PTA_FMA | PTA_PRFCHW | PTA_FXSR | PTA_XSAVE},
3320       {"bdver3", PROCESSOR_BDVER3, CPU_BDVER3,
3321         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3322         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3323         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_FMA4
3324         | PTA_XOP | PTA_LWP | PTA_BMI | PTA_TBM | PTA_F16C
3325         | PTA_FMA | PTA_PRFCHW | PTA_FXSR | PTA_XSAVE 
3326         | PTA_XSAVEOPT | PTA_FSGSBASE},
3327      {"bdver4", PROCESSOR_BDVER4, CPU_BDVER4,
3328         PTA_64BIT | PTA_MMX | PTA_SSE | PTA_SSE2 | PTA_SSE3
3329         | PTA_SSE4A | PTA_CX16 | PTA_ABM | PTA_SSSE3 | PTA_SSE4_1
3330         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX | PTA_AVX2 
3331         | PTA_FMA4 | PTA_XOP | PTA_LWP | PTA_BMI | PTA_BMI2 
3332         | PTA_TBM | PTA_F16C | PTA_FMA | PTA_PRFCHW | PTA_FXSR 
3333         | PTA_XSAVE | PTA_XSAVEOPT | PTA_FSGSBASE | PTA_RDRND
3334         | PTA_MOVBE},
3335       {"btver1", PROCESSOR_BTVER1, CPU_GENERIC,
3336         PTA_64BIT | PTA_MMX |  PTA_SSE  | PTA_SSE2 | PTA_SSE3
3337         | PTA_SSSE3 | PTA_SSE4A |PTA_ABM | PTA_CX16 | PTA_PRFCHW
3338         | PTA_FXSR | PTA_XSAVE},
3339       {"btver2", PROCESSOR_BTVER2, CPU_BTVER2,
3340         PTA_64BIT | PTA_MMX |  PTA_SSE  | PTA_SSE2 | PTA_SSE3
3341         | PTA_SSSE3 | PTA_SSE4A |PTA_ABM | PTA_CX16 | PTA_SSE4_1
3342         | PTA_SSE4_2 | PTA_AES | PTA_PCLMUL | PTA_AVX
3343         | PTA_BMI | PTA_F16C | PTA_MOVBE | PTA_PRFCHW
3344         | PTA_FXSR | PTA_XSAVE | PTA_XSAVEOPT},
3345
3346       {"generic", PROCESSOR_GENERIC, CPU_GENERIC,
3347         PTA_64BIT
3348         | PTA_HLE /* flags are only used for -march switch.  */ },
3349     };
3350
3351   /* -mrecip options.  */
3352   static struct
3353     {
3354       const char *string;           /* option name */
3355       unsigned int mask;            /* mask bits to set */
3356     }
3357   const recip_options[] =
3358     {
3359       { "all",       RECIP_MASK_ALL },
3360       { "none",      RECIP_MASK_NONE },
3361       { "div",       RECIP_MASK_DIV },
3362       { "sqrt",      RECIP_MASK_SQRT },
3363       { "vec-div",   RECIP_MASK_VEC_DIV },
3364       { "vec-sqrt",  RECIP_MASK_VEC_SQRT },
3365     };
3366
3367   int const pta_size = ARRAY_SIZE (processor_alias_table);
3368
3369   /* Set up prefix/suffix so the error messages refer to either the command
3370      line argument, or the attribute(target).  */
3371   if (main_args_p)
3372     {
3373       prefix = "-m";
3374       suffix = "";
3375       sw = "switch";
3376     }
3377   else
3378     {
3379       prefix = "option(\"";
3380       suffix = "\")";
3381       sw = "attribute";
3382     }
3383
3384   /* Turn off both OPTION_MASK_ABI_64 and OPTION_MASK_ABI_X32 if
3385      TARGET_64BIT_DEFAULT is true and TARGET_64BIT is false.  */
3386   if (TARGET_64BIT_DEFAULT && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
3387     opts->x_ix86_isa_flags &= ~(OPTION_MASK_ABI_64 | OPTION_MASK_ABI_X32);
3388 #ifdef TARGET_BI_ARCH
3389   else
3390     {
3391 #if TARGET_BI_ARCH == 1
3392       /* When TARGET_BI_ARCH == 1, by default, OPTION_MASK_ABI_64
3393          is on and OPTION_MASK_ABI_X32 is off.  We turn off
3394          OPTION_MASK_ABI_64 if OPTION_MASK_ABI_X32 is turned on by
3395          -mx32.  */
3396       if (TARGET_X32_P (opts->x_ix86_isa_flags))
3397         opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
3398 #else
3399       /* When TARGET_BI_ARCH == 2, by default, OPTION_MASK_ABI_X32 is
3400          on and OPTION_MASK_ABI_64 is off.  We turn off
3401          OPTION_MASK_ABI_X32 if OPTION_MASK_ABI_64 is turned on by
3402          -m64 or OPTION_MASK_CODE16 is turned on by -m16.  */
3403       if (TARGET_LP64_P (opts->x_ix86_isa_flags)
3404           || TARGET_16BIT_P (opts->x_ix86_isa_flags))
3405         opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
3406 #endif
3407     }
3408 #endif
3409
3410   if (TARGET_X32_P (opts->x_ix86_isa_flags))
3411     {
3412       /* Always turn on OPTION_MASK_ISA_64BIT and turn off
3413          OPTION_MASK_ABI_64 for TARGET_X32.  */
3414       opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
3415       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_64;
3416     }
3417   else if (TARGET_16BIT_P (opts->x_ix86_isa_flags))
3418     opts->x_ix86_isa_flags &= ~(OPTION_MASK_ISA_64BIT
3419                                 | OPTION_MASK_ABI_X32
3420                                 | OPTION_MASK_ABI_64);
3421   else if (TARGET_LP64_P (opts->x_ix86_isa_flags))
3422     {
3423       /* Always turn on OPTION_MASK_ISA_64BIT and turn off
3424          OPTION_MASK_ABI_X32 for TARGET_LP64.  */
3425       opts->x_ix86_isa_flags |= OPTION_MASK_ISA_64BIT;
3426       opts->x_ix86_isa_flags &= ~OPTION_MASK_ABI_X32;
3427     }
3428
3429 #ifdef SUBTARGET_OVERRIDE_OPTIONS
3430   SUBTARGET_OVERRIDE_OPTIONS;
3431 #endif
3432
3433 #ifdef SUBSUBTARGET_OVERRIDE_OPTIONS
3434   SUBSUBTARGET_OVERRIDE_OPTIONS;
3435 #endif
3436
3437   /* -fPIC is the default for x86_64.  */
3438   if (TARGET_MACHO && TARGET_64BIT_P (opts->x_ix86_isa_flags))
3439     opts->x_flag_pic = 2;
3440
3441   /* Need to check -mtune=generic first.  */
3442   if (opts->x_ix86_tune_string)
3443     {
3444       /* As special support for cross compilers we read -mtune=native
3445              as -mtune=generic.  With native compilers we won't see the
3446              -mtune=native, as it was changed by the driver.  */
3447       if (!strcmp (opts->x_ix86_tune_string, "native"))
3448         {
3449           opts->x_ix86_tune_string = "generic";
3450         }
3451       else if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
3452         warning (OPT_Wdeprecated, "%stune=x86-64%s is deprecated; use "
3453                  "%stune=k8%s or %stune=generic%s instead as appropriate",
3454                  prefix, suffix, prefix, suffix, prefix, suffix);
3455     }
3456   else
3457     {
3458       if (opts->x_ix86_arch_string)
3459         opts->x_ix86_tune_string = opts->x_ix86_arch_string;
3460       if (!opts->x_ix86_tune_string)
3461         {
3462           opts->x_ix86_tune_string
3463             = processor_target_table[TARGET_CPU_DEFAULT].name;
3464           ix86_tune_defaulted = 1;
3465         }
3466
3467       /* opts->x_ix86_tune_string is set to opts->x_ix86_arch_string
3468          or defaulted.  We need to use a sensible tune option.  */
3469       if (!strcmp (opts->x_ix86_tune_string, "x86-64"))
3470         {
3471           opts->x_ix86_tune_string = "generic";
3472         }
3473     }
3474
3475   if (opts->x_ix86_stringop_alg == rep_prefix_8_byte
3476       && !TARGET_64BIT_P (opts->x_ix86_isa_flags))
3477     {
3478       /* rep; movq isn't available in 32-bit code.  */
3479       error ("-mstringop-strategy=rep_8byte not supported for 32-bit code");
3480       opts->x_ix86_stringop_alg = no_stringop;
3481     }
3482
3483   if (!opts->x_ix86_arch_string)
3484     opts->x_ix86_arch_string
3485       = TARGET_64BIT_P (opts->x_ix86_isa_flags)
3486         ? "x86-64" : SUBTARGET32_DEFAULT_CPU;
3487   else
3488     ix86_arch_specified = 1;
3489
3490   if (opts_set->x_ix86_pmode)
3491     {
3492       if ((TARGET_LP64_P (opts->x_ix86_isa_flags)
3493            && opts->x_ix86_pmode == PMODE_SI)
3494           || (!TARGET_64BIT_P (opts->x_ix86_isa_flags)
3495                && opts->x_ix86_pmode == PMODE_DI))
3496         error ("address mode %qs not supported in the %s bit mode",
3497                TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "short" : "long",
3498                TARGET_64BIT_P (opts->x_ix86_isa_flags) ? "64" : "32");
3499     }
3500   else
3501     opts->x_ix86_pmode = TARGET_LP64_P (opts->x_ix86_isa_flags)
3502                          ? PMODE_DI : PMODE_SI;
3503
3504   if (!opts_set->x_ix86_abi)
3505     opts->x_ix86_abi = DEFAULT_ABI;
3506
3507   /* For targets using ms ABI enable ms-extensions, if not
3508      explicit turned off.  For non-ms ABI we turn off this
3509      option.  */
3510   if (!opts_set->x_flag_ms_extensions)
3511     opts->x_flag_ms_extensions = (MS_ABI == DEFAULT_ABI);
3512
3513   if (opts_set->x_ix86_cmodel)
3514     {
3515       switch (opts->x_ix86_cmodel)
3516         {
3517         case CM_SMALL:
3518         case CM_SMALL_PIC:
3519           if (opts->x_flag_pic)
3520             opts->x_ix86_cmodel = CM_SMALL_PIC;
3521           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3522             error ("code model %qs not supported in the %s bit mode",
3523                    "small", "32");
3524           break;
3525
3526         case CM_MEDIUM:
3527         case CM_MEDIUM_PIC:
3528           if (opts->x_flag_pic)
3529             opts->x_ix86_cmodel = CM_MEDIUM_PIC;
3530           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3531             error ("code model %qs not supported in the %s bit mode",
3532                    "medium", "32");
3533           else if (TARGET_X32_P (opts->x_ix86_isa_flags))
3534             error ("code model %qs not supported in x32 mode",
3535                    "medium");
3536           break;
3537
3538         case CM_LARGE:
3539         case CM_LARGE_PIC:
3540           if (opts->x_flag_pic)
3541             opts->x_ix86_cmodel = CM_LARGE_PIC;
3542           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3543             error ("code model %qs not supported in the %s bit mode",
3544                    "large", "32");
3545           else if (TARGET_X32_P (opts->x_ix86_isa_flags))
3546             error ("code model %qs not supported in x32 mode",
3547                    "large");
3548           break;
3549
3550         case CM_32:
3551           if (opts->x_flag_pic)
3552             error ("code model %s does not support PIC mode", "32");
3553           if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3554             error ("code model %qs not supported in the %s bit mode",
3555                    "32", "64");
3556           break;
3557
3558         case CM_KERNEL:
3559           if (opts->x_flag_pic)
3560             {
3561               error ("code model %s does not support PIC mode", "kernel");
3562               opts->x_ix86_cmodel = CM_32;
3563             }
3564           if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
3565             error ("code model %qs not supported in the %s bit mode",
3566                    "kernel", "32");
3567           break;
3568
3569         default:
3570           gcc_unreachable ();
3571         }
3572     }
3573   else
3574     {
3575       /* For TARGET_64BIT and MS_ABI, force pic on, in order to enable the
3576          use of rip-relative addressing.  This eliminates fixups that
3577          would otherwise be needed if this object is to be placed in a
3578          DLL, and is essentially just as efficient as direct addressing.  */
3579       if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
3580           && (TARGET_RDOS || TARGET_PECOFF))
3581         opts->x_ix86_cmodel = CM_MEDIUM_PIC, opts->x_flag_pic = 1;
3582       else if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3583         opts->x_ix86_cmodel = opts->x_flag_pic ? CM_SMALL_PIC : CM_SMALL;
3584       else
3585         opts->x_ix86_cmodel = CM_32;
3586     }
3587   if (TARGET_MACHO && opts->x_ix86_asm_dialect == ASM_INTEL)
3588     {
3589       error ("-masm=intel not supported in this configuration");
3590       opts->x_ix86_asm_dialect = ASM_ATT;
3591     }
3592   if ((TARGET_64BIT_P (opts->x_ix86_isa_flags) != 0)
3593       != ((opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) != 0))
3594     sorry ("%i-bit mode not compiled in",
3595            (opts->x_ix86_isa_flags & OPTION_MASK_ISA_64BIT) ? 64 : 32);
3596
3597   for (i = 0; i < pta_size; i++)
3598     if (! strcmp (opts->x_ix86_arch_string, processor_alias_table[i].name))
3599       {
3600         ix86_schedule = processor_alias_table[i].schedule;
3601         ix86_arch = processor_alias_table[i].processor;
3602         /* Default cpu tuning to the architecture.  */
3603         ix86_tune = ix86_arch;
3604
3605         if (TARGET_64BIT_P (opts->x_ix86_isa_flags)
3606             && !(processor_alias_table[i].flags & PTA_64BIT))
3607           error ("CPU you selected does not support x86-64 "
3608                  "instruction set");
3609
3610         if (processor_alias_table[i].flags & PTA_MMX
3611             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MMX))
3612           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MMX;
3613         if (processor_alias_table[i].flags & PTA_3DNOW
3614             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW))
3615           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_3DNOW;
3616         if (processor_alias_table[i].flags & PTA_3DNOW_A
3617             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_3DNOW_A))
3618           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_3DNOW_A;
3619         if (processor_alias_table[i].flags & PTA_SSE
3620             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE))
3621           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE;
3622         if (processor_alias_table[i].flags & PTA_SSE2
3623             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE2))
3624           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE2;
3625         if (processor_alias_table[i].flags & PTA_SSE3
3626             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE3))
3627           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE3;
3628         if (processor_alias_table[i].flags & PTA_SSSE3
3629             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSSE3))
3630           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSSE3;
3631         if (processor_alias_table[i].flags & PTA_SSE4_1
3632             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_1))
3633           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4_1;
3634         if (processor_alias_table[i].flags & PTA_SSE4_2
3635             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4_2))
3636           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4_2;
3637         if (processor_alias_table[i].flags & PTA_AVX
3638             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX))
3639           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX;
3640         if (processor_alias_table[i].flags & PTA_AVX2
3641             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX2))
3642           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX2;
3643         if (processor_alias_table[i].flags & PTA_FMA
3644             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA))
3645           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FMA;
3646         if (processor_alias_table[i].flags & PTA_SSE4A
3647             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SSE4A))
3648           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SSE4A;
3649         if (processor_alias_table[i].flags & PTA_FMA4
3650             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FMA4))
3651           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FMA4;
3652         if (processor_alias_table[i].flags & PTA_XOP
3653             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XOP))
3654           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XOP;
3655         if (processor_alias_table[i].flags & PTA_LWP
3656             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_LWP))
3657           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_LWP;
3658         if (processor_alias_table[i].flags & PTA_ABM
3659             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_ABM))
3660           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_ABM;
3661         if (processor_alias_table[i].flags & PTA_BMI
3662             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_BMI))
3663           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_BMI;
3664         if (processor_alias_table[i].flags & (PTA_LZCNT | PTA_ABM)
3665             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_LZCNT))
3666           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_LZCNT;
3667         if (processor_alias_table[i].flags & PTA_TBM
3668             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_TBM))
3669           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_TBM;
3670         if (processor_alias_table[i].flags & PTA_BMI2
3671             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_BMI2))
3672           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_BMI2;
3673         if (processor_alias_table[i].flags & PTA_CX16
3674             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_CX16))
3675           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_CX16;
3676         if (processor_alias_table[i].flags & (PTA_POPCNT | PTA_ABM)
3677             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_POPCNT))
3678           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_POPCNT;
3679         if (!(TARGET_64BIT_P (opts->x_ix86_isa_flags)
3680             && (processor_alias_table[i].flags & PTA_NO_SAHF))
3681             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_SAHF))
3682           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_SAHF;
3683         if (processor_alias_table[i].flags & PTA_MOVBE
3684             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MOVBE))
3685           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MOVBE;
3686         if (processor_alias_table[i].flags & PTA_AES
3687             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_AES))
3688           ix86_isa_flags |= OPTION_MASK_ISA_AES;
3689         if (processor_alias_table[i].flags & PTA_SHA
3690             && !(ix86_isa_flags_explicit & OPTION_MASK_ISA_SHA))
3691           ix86_isa_flags |= OPTION_MASK_ISA_SHA;
3692         if (processor_alias_table[i].flags & PTA_PCLMUL
3693             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PCLMUL))
3694           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PCLMUL;
3695         if (processor_alias_table[i].flags & PTA_FSGSBASE
3696             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FSGSBASE))
3697           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FSGSBASE;
3698         if (processor_alias_table[i].flags & PTA_RDRND
3699             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_RDRND))
3700           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_RDRND;
3701         if (processor_alias_table[i].flags & PTA_F16C
3702             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_F16C))
3703           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_F16C;
3704         if (processor_alias_table[i].flags & PTA_RTM
3705             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_RTM))
3706           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_RTM;
3707         if (processor_alias_table[i].flags & PTA_HLE
3708             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_HLE))
3709           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_HLE;
3710         if (processor_alias_table[i].flags & PTA_PRFCHW
3711             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PRFCHW))
3712           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PRFCHW;
3713         if (processor_alias_table[i].flags & PTA_RDSEED
3714             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_RDSEED))
3715           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_RDSEED;
3716         if (processor_alias_table[i].flags & PTA_ADX
3717             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_ADX))
3718           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_ADX;
3719         if (processor_alias_table[i].flags & PTA_FXSR
3720             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_FXSR))
3721           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_FXSR;
3722         if (processor_alias_table[i].flags & PTA_XSAVE
3723             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVE))
3724           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVE;
3725         if (processor_alias_table[i].flags & PTA_XSAVEOPT
3726             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVEOPT))
3727           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVEOPT;
3728         if (processor_alias_table[i].flags & PTA_AVX512F
3729             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512F))
3730           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512F;
3731         if (processor_alias_table[i].flags & PTA_AVX512ER
3732             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512ER))
3733           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512ER;
3734         if (processor_alias_table[i].flags & PTA_AVX512PF
3735             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512PF))
3736           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512PF;
3737         if (processor_alias_table[i].flags & PTA_AVX512CD
3738             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512CD))
3739           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512CD;
3740         if (processor_alias_table[i].flags & PTA_PREFETCHWT1
3741             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PREFETCHWT1))
3742           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PREFETCHWT1;
3743         if (processor_alias_table[i].flags & PTA_PCOMMIT
3744             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_PCOMMIT))
3745           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_PCOMMIT;
3746         if (processor_alias_table[i].flags & PTA_CLWB
3747             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_CLWB))
3748           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_CLWB;
3749         if (processor_alias_table[i].flags & PTA_CLFLUSHOPT
3750             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_CLFLUSHOPT))
3751           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_CLFLUSHOPT;
3752         if (processor_alias_table[i].flags & PTA_XSAVEC
3753             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVEC))
3754           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVEC;
3755         if (processor_alias_table[i].flags & PTA_XSAVES
3756             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_XSAVES))
3757           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_XSAVES;
3758         if (processor_alias_table[i].flags & PTA_AVX512DQ
3759             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512DQ))
3760           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512DQ;
3761         if (processor_alias_table[i].flags & PTA_AVX512BW
3762             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512BW))
3763           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512BW;
3764         if (processor_alias_table[i].flags & PTA_AVX512VL
3765             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512VL))
3766           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512VL;
3767         if (processor_alias_table[i].flags & PTA_MPX
3768             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_MPX))
3769           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_MPX;
3770         if (processor_alias_table[i].flags & PTA_AVX512VBMI
3771             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512VBMI))
3772           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512VBMI;
3773         if (processor_alias_table[i].flags & PTA_AVX512IFMA
3774             && !(opts->x_ix86_isa_flags_explicit & OPTION_MASK_ISA_AVX512IFMA))
3775           opts->x_ix86_isa_flags |= OPTION_MASK_ISA_AVX512IFMA;
3776         if (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE))
3777           x86_prefetch_sse = true;
3778
3779         break;
3780       }
3781
3782   if (TARGET_X32 && (opts->x_ix86_isa_flags & OPTION_MASK_ISA_MPX))
3783     error ("Intel MPX does not support x32");
3784
3785   if (TARGET_X32 && (ix86_isa_flags & OPTION_MASK_ISA_MPX))
3786     error ("Intel MPX does not support x32");
3787
3788   if (!strcmp (opts->x_ix86_arch_string, "generic"))
3789     error ("generic CPU can be used only for %stune=%s %s",
3790            prefix, suffix, sw);
3791   else if (!strcmp (opts->x_ix86_arch_string, "intel"))
3792     error ("intel CPU can be used only for %stune=%s %s",
3793            prefix, suffix, sw);
3794   else if (i == pta_size)
3795     error ("bad value (%s) for %sarch=%s %s",
3796            opts->x_ix86_arch_string, prefix, suffix, sw);
3797
3798   ix86_arch_mask = 1u << ix86_arch;
3799   for (i = 0; i < X86_ARCH_LAST; ++i)
3800     ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
3801
3802   for (i = 0; i < pta_size; i++)
3803     if (! strcmp (opts->x_ix86_tune_string, processor_alias_table[i].name))
3804       {
3805         ix86_schedule = processor_alias_table[i].schedule;
3806         ix86_tune = processor_alias_table[i].processor;
3807         if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3808           {
3809             if (!(processor_alias_table[i].flags & PTA_64BIT))
3810               {
3811                 if (ix86_tune_defaulted)
3812                   {
3813                     opts->x_ix86_tune_string = "x86-64";
3814                     for (i = 0; i < pta_size; i++)
3815                       if (! strcmp (opts->x_ix86_tune_string,
3816                                     processor_alias_table[i].name))
3817                         break;
3818                     ix86_schedule = processor_alias_table[i].schedule;
3819                     ix86_tune = processor_alias_table[i].processor;
3820                   }
3821                 else
3822                   error ("CPU you selected does not support x86-64 "
3823                          "instruction set");
3824               }
3825           }
3826         /* Intel CPUs have always interpreted SSE prefetch instructions as
3827            NOPs; so, we can enable SSE prefetch instructions even when
3828            -mtune (rather than -march) points us to a processor that has them.
3829            However, the VIA C3 gives a SIGILL, so we only do that for i686 and
3830            higher processors.  */
3831         if (TARGET_CMOV
3832             && (processor_alias_table[i].flags & (PTA_PREFETCH_SSE | PTA_SSE)))
3833           x86_prefetch_sse = true;
3834         break;
3835       }
3836
3837   if (ix86_tune_specified && i == pta_size)
3838     error ("bad value (%s) for %stune=%s %s",
3839            opts->x_ix86_tune_string, prefix, suffix, sw);
3840
3841   set_ix86_tune_features (ix86_tune, opts->x_ix86_dump_tunes);
3842
3843 #ifndef USE_IX86_FRAME_POINTER
3844 #define USE_IX86_FRAME_POINTER 0
3845 #endif
3846
3847 #ifndef USE_X86_64_FRAME_POINTER
3848 #define USE_X86_64_FRAME_POINTER 0
3849 #endif
3850
3851   /* Set the default values for switches whose default depends on TARGET_64BIT
3852      in case they weren't overwritten by command line options.  */
3853   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3854     {
3855       if (opts->x_optimize >= 1 && !opts_set->x_flag_omit_frame_pointer)
3856         opts->x_flag_omit_frame_pointer = !USE_X86_64_FRAME_POINTER;
3857       if (opts->x_flag_asynchronous_unwind_tables
3858           && !opts_set->x_flag_unwind_tables
3859           && TARGET_64BIT_MS_ABI)
3860         opts->x_flag_unwind_tables = 1;
3861       if (opts->x_flag_asynchronous_unwind_tables == 2)
3862         opts->x_flag_unwind_tables
3863           = opts->x_flag_asynchronous_unwind_tables = 1;
3864       if (opts->x_flag_pcc_struct_return == 2)
3865         opts->x_flag_pcc_struct_return = 0;
3866     }
3867   else
3868     {
3869       if (opts->x_optimize >= 1 && !opts_set->x_flag_omit_frame_pointer)
3870         opts->x_flag_omit_frame_pointer
3871           = !(USE_IX86_FRAME_POINTER || opts->x_optimize_size);
3872       if (opts->x_flag_asynchronous_unwind_tables == 2)
3873         opts->x_flag_asynchronous_unwind_tables = !USE_IX86_FRAME_POINTER;
3874       if (opts->x_flag_pcc_struct_return == 2)
3875         opts->x_flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
3876     }
3877
3878   ix86_tune_cost = processor_target_table[ix86_tune].cost;
3879   /* TODO: ix86_cost should be chosen at instruction or function granuality
3880      so for cold code we use size_cost even in !optimize_size compilation.  */
3881   if (opts->x_optimize_size)
3882     ix86_cost = &ix86_size_cost;
3883   else
3884     ix86_cost = ix86_tune_cost;
3885
3886   /* Arrange to set up i386_stack_locals for all functions.  */
3887   init_machine_status = ix86_init_machine_status;
3888
3889   /* Validate -mregparm= value.  */
3890   if (opts_set->x_ix86_regparm)
3891     {
3892       if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3893         warning (0, "-mregparm is ignored in 64-bit mode");
3894       if (opts->x_ix86_regparm > REGPARM_MAX)
3895         {
3896           error ("-mregparm=%d is not between 0 and %d",
3897                  opts->x_ix86_regparm, REGPARM_MAX);
3898           opts->x_ix86_regparm = 0;
3899         }
3900     }
3901   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3902     opts->x_ix86_regparm = REGPARM_MAX;
3903
3904   /* Default align_* from the processor table.  */
3905   if (opts->x_align_loops == 0)
3906     {
3907       opts->x_align_loops = processor_target_table[ix86_tune].align_loop;
3908       align_loops_max_skip = processor_target_table[ix86_tune].align_loop_max_skip;
3909     }
3910   if (opts->x_align_jumps == 0)
3911     {
3912       opts->x_align_jumps = processor_target_table[ix86_tune].align_jump;
3913       align_jumps_max_skip = processor_target_table[ix86_tune].align_jump_max_skip;
3914     }
3915   if (opts->x_align_functions == 0)
3916     {
3917       opts->x_align_functions = processor_target_table[ix86_tune].align_func;
3918     }
3919
3920   /* Provide default for -mbranch-cost= value.  */
3921   if (!opts_set->x_ix86_branch_cost)
3922     opts->x_ix86_branch_cost = ix86_tune_cost->branch_cost;
3923
3924   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
3925     {
3926       opts->x_target_flags
3927         |= TARGET_SUBTARGET64_DEFAULT & ~opts_set->x_target_flags;
3928
3929       /* Enable by default the SSE and MMX builtins.  Do allow the user to
3930          explicitly disable any of these.  In particular, disabling SSE and
3931          MMX for kernel code is extremely useful.  */
3932       if (!ix86_arch_specified)
3933       opts->x_ix86_isa_flags
3934         |= ((OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_MMX
3935              | TARGET_SUBTARGET64_ISA_DEFAULT)
3936             & ~opts->x_ix86_isa_flags_explicit);
3937
3938       if (TARGET_RTD_P (opts->x_target_flags))
3939         warning (0, "%srtd%s is ignored in 64bit mode", prefix, suffix);
3940     }
3941   else
3942     {
3943       opts->x_target_flags
3944         |= TARGET_SUBTARGET32_DEFAULT & ~opts_set->x_target_flags;
3945
3946       if (!ix86_arch_specified)
3947         opts->x_ix86_isa_flags
3948           |= TARGET_SUBTARGET32_ISA_DEFAULT & ~opts->x_ix86_isa_flags_explicit;
3949
3950       /* i386 ABI does not specify red zone.  It still makes sense to use it
3951          when programmer takes care to stack from being destroyed.  */
3952       if (!(opts_set->x_target_flags & MASK_NO_RED_ZONE))
3953         opts->x_target_flags |= MASK_NO_RED_ZONE;
3954     }
3955
3956   /* Keep nonleaf frame pointers.  */
3957   if (opts->x_flag_omit_frame_pointer)
3958     opts->x_target_flags &= ~MASK_OMIT_LEAF_FRAME_POINTER;
3959   else if (TARGET_OMIT_LEAF_FRAME_POINTER_P (opts->x_target_flags))
3960     opts->x_flag_omit_frame_pointer = 1;
3961
3962   /* If we're doing fast math, we don't care about comparison order
3963      wrt NaNs.  This lets us use a shorter comparison sequence.  */
3964   if (opts->x_flag_finite_math_only)
3965     opts->x_target_flags &= ~MASK_IEEE_FP;
3966
3967   /* If the architecture always has an FPU, turn off NO_FANCY_MATH_387,
3968      since the insns won't need emulation.  */
3969   if (ix86_tune_features [X86_TUNE_ALWAYS_FANCY_MATH_387])
3970     opts->x_target_flags &= ~MASK_NO_FANCY_MATH_387;
3971
3972   /* Likewise, if the target doesn't have a 387, or we've specified
3973      software floating point, don't use 387 inline intrinsics.  */
3974   if (!TARGET_80387_P (opts->x_target_flags))
3975     opts->x_target_flags |= MASK_NO_FANCY_MATH_387;
3976
3977   /* Turn on MMX builtins for -msse.  */
3978   if (TARGET_SSE_P (opts->x_ix86_isa_flags))
3979     opts->x_ix86_isa_flags
3980       |= OPTION_MASK_ISA_MMX & ~opts->x_ix86_isa_flags_explicit;
3981
3982   /* Enable SSE prefetch.  */
3983   if (TARGET_SSE_P (opts->x_ix86_isa_flags)
3984       || (TARGET_PRFCHW && !TARGET_3DNOW_P (opts->x_ix86_isa_flags)))
3985     x86_prefetch_sse = true;
3986
3987   /* Enable prefetch{,w} instructions for -m3dnow and -mprefetchwt1.  */
3988   if (TARGET_3DNOW_P (opts->x_ix86_isa_flags)
3989       || TARGET_PREFETCHWT1_P (opts->x_ix86_isa_flags))
3990     opts->x_ix86_isa_flags
3991       |= OPTION_MASK_ISA_PRFCHW & ~opts->x_ix86_isa_flags_explicit;
3992
3993   /* Enable popcnt instruction for -msse4.2 or -mabm.  */
3994   if (TARGET_SSE4_2_P (opts->x_ix86_isa_flags)
3995       || TARGET_ABM_P (opts->x_ix86_isa_flags))
3996     opts->x_ix86_isa_flags
3997       |= OPTION_MASK_ISA_POPCNT & ~opts->x_ix86_isa_flags_explicit;
3998
3999   /* Enable lzcnt instruction for -mabm.  */
4000   if (TARGET_ABM_P(opts->x_ix86_isa_flags))
4001     opts->x_ix86_isa_flags
4002       |= OPTION_MASK_ISA_LZCNT & ~opts->x_ix86_isa_flags_explicit;
4003
4004   /* Validate -mpreferred-stack-boundary= value or default it to
4005      PREFERRED_STACK_BOUNDARY_DEFAULT.  */
4006   ix86_preferred_stack_boundary = PREFERRED_STACK_BOUNDARY_DEFAULT;
4007   if (opts_set->x_ix86_preferred_stack_boundary_arg)
4008     {
4009       int min = (TARGET_64BIT_P (opts->x_ix86_isa_flags)
4010                  ? (TARGET_SSE_P (opts->x_ix86_isa_flags) ? 4 : 3) : 2);
4011       int max = (TARGET_SEH ? 4 : 12);
4012
4013       if (opts->x_ix86_preferred_stack_boundary_arg < min
4014           || opts->x_ix86_preferred_stack_boundary_arg > max)
4015         {
4016           if (min == max)
4017             error ("-mpreferred-stack-boundary is not supported "
4018                    "for this target");
4019           else
4020             error ("-mpreferred-stack-boundary=%d is not between %d and %d",
4021                    opts->x_ix86_preferred_stack_boundary_arg, min, max);
4022         }
4023       else
4024         ix86_preferred_stack_boundary
4025           = (1 << opts->x_ix86_preferred_stack_boundary_arg) * BITS_PER_UNIT;
4026     }
4027
4028   /* Set the default value for -mstackrealign.  */
4029   if (opts->x_ix86_force_align_arg_pointer == -1)
4030     opts->x_ix86_force_align_arg_pointer = STACK_REALIGN_DEFAULT;
4031
4032   ix86_default_incoming_stack_boundary = PREFERRED_STACK_BOUNDARY;
4033
4034   /* Validate -mincoming-stack-boundary= value or default it to
4035      MIN_STACK_BOUNDARY/PREFERRED_STACK_BOUNDARY.  */
4036   ix86_incoming_stack_boundary = ix86_default_incoming_stack_boundary;
4037   if (opts_set->x_ix86_incoming_stack_boundary_arg)
4038     {
4039       if (opts->x_ix86_incoming_stack_boundary_arg
4040           < (TARGET_64BIT_P (opts->x_ix86_isa_flags) ? 4 : 2)
4041           || opts->x_ix86_incoming_stack_boundary_arg > 12)
4042         error ("-mincoming-stack-boundary=%d is not between %d and 12",
4043                opts->x_ix86_incoming_stack_boundary_arg,
4044                TARGET_64BIT_P (opts->x_ix86_isa_flags) ? 4 : 2);
4045       else
4046         {
4047           ix86_user_incoming_stack_boundary
4048             = (1 << opts->x_ix86_incoming_stack_boundary_arg) * BITS_PER_UNIT;
4049           ix86_incoming_stack_boundary
4050             = ix86_user_incoming_stack_boundary;
4051         }
4052     }
4053
4054 #ifndef NO_PROFILE_COUNTERS
4055   if (flag_nop_mcount)
4056     error ("-mnop-mcount is not compatible with this target");
4057 #endif
4058   if (flag_nop_mcount && flag_pic)
4059     error ("-mnop-mcount is not implemented for -fPIC");
4060
4061   /* Accept -msseregparm only if at least SSE support is enabled.  */
4062   if (TARGET_SSEREGPARM_P (opts->x_target_flags)
4063       && ! TARGET_SSE_P (opts->x_ix86_isa_flags))
4064     error ("%ssseregparm%s used without SSE enabled", prefix, suffix);
4065
4066   if (opts_set->x_ix86_fpmath)
4067     {
4068       if (opts->x_ix86_fpmath & FPMATH_SSE)
4069         {
4070           if (!TARGET_SSE_P (opts->x_ix86_isa_flags))
4071             {
4072               warning (0, "SSE instruction set disabled, using 387 arithmetics");
4073               opts->x_ix86_fpmath = FPMATH_387;
4074             }
4075           else if ((opts->x_ix86_fpmath & FPMATH_387)
4076                    && !TARGET_80387_P (opts->x_target_flags))
4077             {
4078               warning (0, "387 instruction set disabled, using SSE arithmetics");
4079               opts->x_ix86_fpmath = FPMATH_SSE;
4080             }
4081         }
4082     }
4083   /* For all chips supporting SSE2, -mfpmath=sse performs better than
4084      fpmath=387.  The second is however default at many targets since the
4085      extra 80bit precision of temporaries is considered to be part of ABI.
4086      Overwrite the default at least for -ffast-math. 
4087      TODO: -mfpmath=both seems to produce same performing code with bit
4088      smaller binaries.  It is however not clear if register allocation is
4089      ready for this setting.
4090      Also -mfpmath=387 is overall a lot more compact (bout 4-5%) than SSE
4091      codegen.  We may switch to 387 with -ffast-math for size optimized
4092      functions. */
4093   else if (fast_math_flags_set_p (&global_options)
4094            && TARGET_SSE2_P (opts->x_ix86_isa_flags))
4095     opts->x_ix86_fpmath = FPMATH_SSE;
4096   else
4097     opts->x_ix86_fpmath = TARGET_FPMATH_DEFAULT_P (opts->x_ix86_isa_flags);
4098
4099   /* If the i387 is disabled, then do not return values in it. */
4100   if (!TARGET_80387_P (opts->x_target_flags))
4101     opts->x_target_flags &= ~MASK_FLOAT_RETURNS;
4102
4103   /* Use external vectorized library in vectorizing intrinsics.  */
4104   if (opts_set->x_ix86_veclibabi_type)
4105     switch (opts->x_ix86_veclibabi_type)
4106       {
4107       case ix86_veclibabi_type_svml:
4108         ix86_veclib_handler = ix86_veclibabi_svml;
4109         break;
4110
4111       case ix86_veclibabi_type_acml:
4112         ix86_veclib_handler = ix86_veclibabi_acml;
4113         break;
4114
4115       default:
4116         gcc_unreachable ();
4117       }
4118
4119   if (ix86_tune_features [X86_TUNE_ACCUMULATE_OUTGOING_ARGS]
4120       && !(opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
4121     opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
4122
4123   /* If stack probes are required, the space used for large function
4124      arguments on the stack must also be probed, so enable
4125      -maccumulate-outgoing-args so this happens in the prologue.  */
4126   if (TARGET_STACK_PROBE_P (opts->x_target_flags)
4127       && !(opts->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS))
4128     {
4129       if (opts_set->x_target_flags & MASK_ACCUMULATE_OUTGOING_ARGS)
4130         warning (0, "stack probing requires %saccumulate-outgoing-args%s "
4131                  "for correctness", prefix, suffix);
4132       opts->x_target_flags |= MASK_ACCUMULATE_OUTGOING_ARGS;
4133     }
4134
4135   /* Figure out what ASM_GENERATE_INTERNAL_LABEL builds as a prefix.  */
4136   {
4137     char *p;
4138     ASM_GENERATE_INTERNAL_LABEL (internal_label_prefix, "LX", 0);
4139     p = strchr (internal_label_prefix, 'X');
4140     internal_label_prefix_len = p - internal_label_prefix;
4141     *p = '\0';
4142   }
4143
4144   /* When scheduling description is not available, disable scheduler pass
4145      so it won't slow down the compilation and make x87 code slower.  */
4146   if (!TARGET_SCHEDULE)
4147     opts->x_flag_schedule_insns_after_reload = opts->x_flag_schedule_insns = 0;
4148
4149   maybe_set_param_value (PARAM_SIMULTANEOUS_PREFETCHES,
4150                          ix86_tune_cost->simultaneous_prefetches,
4151                          opts->x_param_values,
4152                          opts_set->x_param_values);
4153   maybe_set_param_value (PARAM_L1_CACHE_LINE_SIZE,
4154                          ix86_tune_cost->prefetch_block,
4155                          opts->x_param_values,
4156                          opts_set->x_param_values);
4157   maybe_set_param_value (PARAM_L1_CACHE_SIZE,
4158                          ix86_tune_cost->l1_cache_size,
4159                          opts->x_param_values,
4160                          opts_set->x_param_values);
4161   maybe_set_param_value (PARAM_L2_CACHE_SIZE,
4162                          ix86_tune_cost->l2_cache_size,
4163                          opts->x_param_values,
4164                          opts_set->x_param_values);
4165
4166   /* Enable sw prefetching at -O3 for CPUS that prefetching is helpful.  */
4167   if (opts->x_flag_prefetch_loop_arrays < 0
4168       && HAVE_prefetch
4169       && (opts->x_optimize >= 3 || opts->x_flag_profile_use)
4170       && TARGET_SOFTWARE_PREFETCHING_BENEFICIAL)
4171     opts->x_flag_prefetch_loop_arrays = 1;
4172
4173   /* If using typedef char *va_list, signal that __builtin_va_start (&ap, 0)
4174      can be opts->x_optimized to ap = __builtin_next_arg (0).  */
4175   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && !opts->x_flag_split_stack)
4176     targetm.expand_builtin_va_start = NULL;
4177
4178   if (TARGET_64BIT_P (opts->x_ix86_isa_flags))
4179     {
4180       ix86_gen_leave = gen_leave_rex64;
4181       if (Pmode == DImode)
4182         {
4183           ix86_gen_tls_global_dynamic_64 = gen_tls_global_dynamic_64_di;
4184           ix86_gen_tls_local_dynamic_base_64
4185             = gen_tls_local_dynamic_base_64_di;
4186         }
4187       else
4188         {
4189           ix86_gen_tls_global_dynamic_64 = gen_tls_global_dynamic_64_si;
4190           ix86_gen_tls_local_dynamic_base_64
4191             = gen_tls_local_dynamic_base_64_si;
4192         }
4193     }
4194   else
4195     ix86_gen_leave = gen_leave;
4196
4197   if (Pmode == DImode)
4198     {
4199       ix86_gen_add3 = gen_adddi3;
4200       ix86_gen_sub3 = gen_subdi3;
4201       ix86_gen_sub3_carry = gen_subdi3_carry;
4202       ix86_gen_one_cmpl2 = gen_one_cmpldi2;
4203       ix86_gen_andsp = gen_anddi3;
4204       ix86_gen_allocate_stack_worker = gen_allocate_stack_worker_probe_di;
4205       ix86_gen_adjust_stack_and_probe = gen_adjust_stack_and_probedi;
4206       ix86_gen_probe_stack_range = gen_probe_stack_rangedi;
4207       ix86_gen_monitor = gen_sse3_monitor_di;
4208     }
4209   else
4210     {
4211       ix86_gen_add3 = gen_addsi3;
4212       ix86_gen_sub3 = gen_subsi3;
4213       ix86_gen_sub3_carry = gen_subsi3_carry;
4214       ix86_gen_one_cmpl2 = gen_one_cmplsi2;
4215       ix86_gen_andsp = gen_andsi3;
4216       ix86_gen_allocate_stack_worker = gen_allocate_stack_worker_probe_si;
4217       ix86_gen_adjust_stack_and_probe = gen_adjust_stack_and_probesi;
4218       ix86_gen_probe_stack_range = gen_probe_stack_rangesi;
4219       ix86_gen_monitor = gen_sse3_monitor_si;
4220     }
4221
4222 #ifdef USE_IX86_CLD
4223   /* Use -mcld by default for 32-bit code if configured with --enable-cld.  */
4224   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags))
4225     opts->x_target_flags |= MASK_CLD & ~opts_set->x_target_flags;
4226 #endif
4227
4228   if (!TARGET_64BIT_P (opts->x_ix86_isa_flags) && opts->x_flag_pic)
4229     {
4230       if (opts->x_flag_fentry > 0)
4231         sorry ("-mfentry isn%'t supported for 32-bit in combination "
4232                "with -fpic");
4233       opts->x_flag_fentry = 0;
4234     }
4235   else if (TARGET_SEH)
4236     {
4237       if (opts->x_flag_fentry == 0)
4238         sorry ("-mno-fentry isn%'t compatible with SEH");
4239       opts->x_flag_fentry = 1;
4240     }
4241   else if (opts->x_flag_fentry < 0)
4242    {
4243 #if defined(PROFILE_BEFORE_PROLOGUE)
4244      opts->x_flag_fentry = 1;
4245 #else
4246      opts->x_flag_fentry = 0;
4247 #endif
4248    }
4249
4250   if (!(opts_set->x_target_flags & MASK_VZEROUPPER))
4251     opts->x_target_flags |= MASK_VZEROUPPER;
4252   if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_LOAD_OPTIMAL]
4253       && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_LOAD))
4254     opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_LOAD;
4255   if (!ix86_tune_features[X86_TUNE_AVX256_UNALIGNED_STORE_OPTIMAL]
4256       && !(opts_set->x_target_flags & MASK_AVX256_SPLIT_UNALIGNED_STORE))
4257     opts->x_target_flags |= MASK_AVX256_SPLIT_UNALIGNED_STORE;
4258   /* Enable 128-bit AVX instruction generation
4259      for the auto-vectorizer.  */
4260   if (TARGET_AVX128_OPTIMAL
4261       && !(opts_set->x_target_flags & MASK_PREFER_AVX128))
4262     opts->x_target_flags |= MASK_PREFER_AVX128;
4263
4264   if (opts->x_ix86_recip_name)
4265     {
4266       char *p = ASTRDUP (opts->x_ix86_recip_name);
4267       char *q;
4268       unsigned int mask, i;
4269       bool invert;
4270
4271       while ((q = strtok (p, ",")) != NULL)
4272         {
4273           p = NULL;
4274           if (*q == '!')
4275             {
4276               invert = true;
4277               q++;
4278             }
4279           else
4280             invert = false;
4281
4282           if (!strcmp (q, "default"))
4283             mask = RECIP_MASK_ALL;
4284           else
4285             {
4286               for (i = 0; i < ARRAY_SIZE (recip_options); i++)
4287                 if (!strcmp (q, recip_options[i].string))
4288                   {
4289                     mask = recip_options[i].mask;
4290                     break;
4291                   }
4292
4293               if (i == ARRAY_SIZE (recip_options))
4294                 {
4295                   error ("unknown option for -mrecip=%s", q);
4296                   invert = false;
4297                   mask = RECIP_MASK_NONE;
4298                 }
4299             }
4300
4301           opts->x_recip_mask_explicit |= mask;
4302           if (invert)
4303             opts->x_recip_mask &= ~mask;
4304           else
4305             opts->x_recip_mask |= mask;
4306         }
4307     }
4308
4309   if (TARGET_RECIP_P (opts->x_target_flags))
4310     opts->x_recip_mask |= RECIP_MASK_ALL & ~opts->x_recip_mask_explicit;
4311   else if (opts_set->x_target_flags & MASK_RECIP)
4312     opts->x_recip_mask &= ~(RECIP_MASK_ALL & ~opts->x_recip_mask_explicit);
4313
4314   /* Default long double to 64-bit for 32-bit Bionic and to __float128
4315      for 64-bit Bionic.  */
4316   if (TARGET_HAS_BIONIC
4317       && !(opts_set->x_target_flags
4318            & (MASK_LONG_DOUBLE_64 | MASK_LONG_DOUBLE_128)))
4319     opts->x_target_flags |= (TARGET_64BIT
4320                              ? MASK_LONG_DOUBLE_128
4321                              : MASK_LONG_DOUBLE_64);
4322
4323   /* Only one of them can be active.  */
4324   gcc_assert ((opts->x_target_flags & MASK_LONG_DOUBLE_64) == 0
4325               || (opts->x_target_flags & MASK_LONG_DOUBLE_128) == 0);
4326
4327   /* Save the initial options in case the user does function specific
4328      options.  */
4329   if (main_args_p)
4330     target_option_default_node = target_option_current_node
4331       = build_target_option_node (opts);
4332
4333   /* Handle stack protector */
4334   if (!opts_set->x_ix86_stack_protector_guard)
4335     opts->x_ix86_stack_protector_guard
4336       = TARGET_HAS_BIONIC ? SSP_GLOBAL : SSP_TLS;
4337
4338   /* Handle -mmemcpy-strategy= and -mmemset-strategy=  */
4339   if (opts->x_ix86_tune_memcpy_strategy)
4340     {
4341       char *str = xstrdup (opts->x_ix86_tune_memcpy_strategy);
4342       ix86_parse_stringop_strategy_string (str, false);
4343       free (str);
4344     }
4345
4346   if (opts->x_ix86_tune_memset_strategy)
4347     {
4348       char *str = xstrdup (opts->x_ix86_tune_memset_strategy);
4349       ix86_parse_stringop_strategy_string (str, true);
4350       free (str);
4351     }
4352 }
4353
4354 /* Implement the TARGET_OPTION_OVERRIDE hook.  */
4355
4356 static void
4357 ix86_option_override (void)
4358 {
4359   opt_pass *pass_insert_vzeroupper = make_pass_insert_vzeroupper (g);
4360   struct register_pass_info insert_vzeroupper_info
4361     = { pass_insert_vzeroupper, "reload",
4362         1, PASS_POS_INSERT_AFTER
4363       };
4364
4365   ix86_option_override_internal (true, &global_options, &global_options_set);
4366
4367
4368   /* This needs to be done at start up.  It's convenient to do it here.  */
4369   register_pass (&insert_vzeroupper_info);
4370 }
4371
4372 /* Implement the TARGET_OFFLOAD_OPTIONS hook.  */
4373 static char *
4374 ix86_offload_options (void)
4375 {
4376   if (TARGET_LP64)
4377     return xstrdup ("-foffload-abi=lp64");
4378   return xstrdup ("-foffload-abi=ilp32");
4379 }
4380
4381 /* Update register usage after having seen the compiler flags.  */
4382
4383 static void
4384 ix86_conditional_register_usage (void)
4385 {
4386   int i, c_mask;
4387   unsigned int j;
4388
4389   /* The PIC register, if it exists, is fixed.  */
4390   j = PIC_OFFSET_TABLE_REGNUM;
4391   if (j != INVALID_REGNUM)
4392     fixed_regs[j] = call_used_regs[j] = 1;
4393
4394   /* For 32-bit targets, squash the REX registers.  */
4395   if (! TARGET_64BIT)
4396     {
4397       for (i = FIRST_REX_INT_REG; i <= LAST_REX_INT_REG; i++)
4398         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4399       for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
4400         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4401       for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
4402         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4403     }
4404
4405   /*  See the definition of CALL_USED_REGISTERS in i386.h.  */
4406   c_mask = (TARGET_64BIT_MS_ABI ? (1 << 3)
4407             : TARGET_64BIT ? (1 << 2)
4408             : (1 << 1));
4409   
4410   CLEAR_HARD_REG_SET (reg_class_contents[(int)CLOBBERED_REGS]);
4411
4412   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4413     {
4414       /* Set/reset conditionally defined registers from
4415          CALL_USED_REGISTERS initializer.  */
4416       if (call_used_regs[i] > 1)
4417         call_used_regs[i] = !!(call_used_regs[i] & c_mask);
4418
4419       /* Calculate registers of CLOBBERED_REGS register set
4420          as call used registers from GENERAL_REGS register set.  */
4421       if (TEST_HARD_REG_BIT (reg_class_contents[(int)GENERAL_REGS], i)
4422           && call_used_regs[i])
4423         SET_HARD_REG_BIT (reg_class_contents[(int)CLOBBERED_REGS], i);
4424     }
4425
4426   /* If MMX is disabled, squash the registers.  */
4427   if (! TARGET_MMX)
4428     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4429       if (TEST_HARD_REG_BIT (reg_class_contents[(int)MMX_REGS], i))
4430         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4431
4432   /* If SSE is disabled, squash the registers.  */
4433   if (! TARGET_SSE)
4434     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4435       if (TEST_HARD_REG_BIT (reg_class_contents[(int)SSE_REGS], i))
4436         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4437
4438   /* If the FPU is disabled, squash the registers.  */
4439   if (! (TARGET_80387 || TARGET_FLOAT_RETURNS_IN_80387))
4440     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
4441       if (TEST_HARD_REG_BIT (reg_class_contents[(int)FLOAT_REGS], i))
4442         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4443
4444   /* If AVX512F is disabled, squash the registers.  */
4445   if (! TARGET_AVX512F)
4446     {
4447       for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
4448         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4449
4450       for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++)
4451         fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4452     }
4453
4454   /* If MPX is disabled, squash the registers.  */
4455   if (! TARGET_MPX)
4456     for (i = FIRST_BND_REG; i <= LAST_BND_REG; i++)
4457       fixed_regs[i] = call_used_regs[i] = 1, reg_names[i] = "";
4458 }
4459
4460 \f
4461 /* Save the current options */
4462
4463 static void
4464 ix86_function_specific_save (struct cl_target_option *ptr,
4465                              struct gcc_options *opts)
4466 {
4467   ptr->arch = ix86_arch;
4468   ptr->schedule = ix86_schedule;
4469   ptr->prefetch_sse = x86_prefetch_sse;
4470   ptr->tune = ix86_tune;
4471   ptr->branch_cost = ix86_branch_cost;
4472   ptr->tune_defaulted = ix86_tune_defaulted;
4473   ptr->arch_specified = ix86_arch_specified;
4474   ptr->x_ix86_isa_flags_explicit = opts->x_ix86_isa_flags_explicit;
4475   ptr->x_ix86_target_flags_explicit = opts->x_ix86_target_flags_explicit;
4476   ptr->x_recip_mask_explicit = opts->x_recip_mask_explicit;
4477   ptr->x_ix86_arch_string = opts->x_ix86_arch_string;
4478   ptr->x_ix86_tune_string = opts->x_ix86_tune_string;
4479   ptr->x_ix86_cmodel = opts->x_ix86_cmodel;
4480   ptr->x_ix86_abi = opts->x_ix86_abi;
4481   ptr->x_ix86_asm_dialect = opts->x_ix86_asm_dialect;
4482   ptr->x_ix86_branch_cost = opts->x_ix86_branch_cost;
4483   ptr->x_ix86_dump_tunes = opts->x_ix86_dump_tunes;
4484   ptr->x_ix86_force_align_arg_pointer = opts->x_ix86_force_align_arg_pointer;
4485   ptr->x_ix86_force_drap = opts->x_ix86_force_drap;
4486   ptr->x_ix86_incoming_stack_boundary_arg = opts->x_ix86_incoming_stack_boundary_arg;
4487   ptr->x_ix86_pmode = opts->x_ix86_pmode;
4488   ptr->x_ix86_preferred_stack_boundary_arg = opts->x_ix86_preferred_stack_boundary_arg;
4489   ptr->x_ix86_recip_name = opts->x_ix86_recip_name;
4490   ptr->x_ix86_regparm = opts->x_ix86_regparm;
4491   ptr->x_ix86_section_threshold = opts->x_ix86_section_threshold;
4492   ptr->x_ix86_sse2avx = opts->x_ix86_sse2avx;
4493   ptr->x_ix86_stack_protector_guard = opts->x_ix86_stack_protector_guard;
4494   ptr->x_ix86_stringop_alg = opts->x_ix86_stringop_alg;
4495   ptr->x_ix86_tls_dialect = opts->x_ix86_tls_dialect;
4496   ptr->x_ix86_tune_ctrl_string = opts->x_ix86_tune_ctrl_string;
4497   ptr->x_ix86_tune_memcpy_strategy = opts->x_ix86_tune_memcpy_strategy;
4498   ptr->x_ix86_tune_memset_strategy = opts->x_ix86_tune_memset_strategy;
4499   ptr->x_ix86_tune_no_default = opts->x_ix86_tune_no_default;
4500   ptr->x_ix86_veclibabi_type = opts->x_ix86_veclibabi_type;
4501
4502   /* The fields are char but the variables are not; make sure the
4503      values fit in the fields.  */
4504   gcc_assert (ptr->arch == ix86_arch);
4505   gcc_assert (ptr->schedule == ix86_schedule);
4506   gcc_assert (ptr->tune == ix86_tune);
4507   gcc_assert (ptr->branch_cost == ix86_branch_cost);
4508 }
4509
4510 /* Restore the current options */
4511
4512 static void
4513 ix86_function_specific_restore (struct gcc_options *opts,
4514                                 struct cl_target_option *ptr)
4515 {
4516   enum processor_type old_tune = ix86_tune;
4517   enum processor_type old_arch = ix86_arch;
4518   unsigned int ix86_arch_mask;
4519   int i;
4520
4521   /* We don't change -fPIC.  */
4522   opts->x_flag_pic = flag_pic;
4523
4524   ix86_arch = (enum processor_type) ptr->arch;
4525   ix86_schedule = (enum attr_cpu) ptr->schedule;
4526   ix86_tune = (enum processor_type) ptr->tune;
4527   x86_prefetch_sse = ptr->prefetch_sse;
4528   opts->x_ix86_branch_cost = ptr->branch_cost;
4529   ix86_tune_defaulted = ptr->tune_defaulted;
4530   ix86_arch_specified = ptr->arch_specified;
4531   opts->x_ix86_isa_flags_explicit = ptr->x_ix86_isa_flags_explicit;
4532   opts->x_ix86_target_flags_explicit = ptr->x_ix86_target_flags_explicit;
4533   opts->x_recip_mask_explicit = ptr->x_recip_mask_explicit;
4534   opts->x_ix86_arch_string = ptr->x_ix86_arch_string;
4535   opts->x_ix86_tune_string = ptr->x_ix86_tune_string;
4536   opts->x_ix86_cmodel = ptr->x_ix86_cmodel;
4537   opts->x_ix86_abi = ptr->x_ix86_abi;
4538   opts->x_ix86_asm_dialect = ptr->x_ix86_asm_dialect;
4539   opts->x_ix86_branch_cost = ptr->x_ix86_branch_cost;
4540   opts->x_ix86_dump_tunes = ptr->x_ix86_dump_tunes;
4541   opts->x_ix86_force_align_arg_pointer = ptr->x_ix86_force_align_arg_pointer;
4542   opts->x_ix86_force_drap = ptr->x_ix86_force_drap;
4543   opts->x_ix86_incoming_stack_boundary_arg = ptr->x_ix86_incoming_stack_boundary_arg;
4544   opts->x_ix86_pmode = ptr->x_ix86_pmode;
4545   opts->x_ix86_preferred_stack_boundary_arg = ptr->x_ix86_preferred_stack_boundary_arg;
4546   opts->x_ix86_recip_name = ptr->x_ix86_recip_name;
4547   opts->x_ix86_regparm = ptr->x_ix86_regparm;
4548   opts->x_ix86_section_threshold = ptr->x_ix86_section_threshold;
4549   opts->x_ix86_sse2avx = ptr->x_ix86_sse2avx;
4550   opts->x_ix86_stack_protector_guard = ptr->x_ix86_stack_protector_guard;
4551   opts->x_ix86_stringop_alg = ptr->x_ix86_stringop_alg;
4552   opts->x_ix86_tls_dialect = ptr->x_ix86_tls_dialect;
4553   opts->x_ix86_tune_ctrl_string = ptr->x_ix86_tune_ctrl_string;
4554   opts->x_ix86_tune_memcpy_strategy = ptr->x_ix86_tune_memcpy_strategy;
4555   opts->x_ix86_tune_memset_strategy = ptr->x_ix86_tune_memset_strategy;
4556   opts->x_ix86_tune_no_default = ptr->x_ix86_tune_no_default;
4557   opts->x_ix86_veclibabi_type = ptr->x_ix86_veclibabi_type;
4558   ix86_tune_cost = processor_target_table[ix86_tune].cost;
4559   /* TODO: ix86_cost should be chosen at instruction or function granuality
4560      so for cold code we use size_cost even in !optimize_size compilation.  */
4561   if (opts->x_optimize_size)
4562     ix86_cost = &ix86_size_cost;
4563   else
4564     ix86_cost = ix86_tune_cost;
4565
4566   /* Recreate the arch feature tests if the arch changed */
4567   if (old_arch != ix86_arch)
4568     {
4569       ix86_arch_mask = 1u << ix86_arch;
4570       for (i = 0; i < X86_ARCH_LAST; ++i)
4571         ix86_arch_features[i]
4572           = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
4573     }
4574
4575   /* Recreate the tune optimization tests */
4576   if (old_tune != ix86_tune)
4577     set_ix86_tune_features (ix86_tune, false);
4578 }
4579
4580 /* Print the current options */
4581
4582 static void
4583 ix86_function_specific_print (FILE *file, int indent,
4584                               struct cl_target_option *ptr)
4585 {
4586   char *target_string
4587     = ix86_target_string (ptr->x_ix86_isa_flags, ptr->x_target_flags,
4588                           NULL, NULL, ptr->x_ix86_fpmath, false);
4589
4590   gcc_assert (ptr->arch < PROCESSOR_max);
4591   fprintf (file, "%*sarch = %d (%s)\n",
4592            indent, "",
4593            ptr->arch, processor_target_table[ptr->arch].name);
4594
4595   gcc_assert (ptr->tune < PROCESSOR_max);
4596   fprintf (file, "%*stune = %d (%s)\n",
4597            indent, "",
4598            ptr->tune, processor_target_table[ptr->tune].name);
4599
4600   fprintf (file, "%*sbranch_cost = %d\n", indent, "", ptr->branch_cost);
4601
4602   if (target_string)
4603     {
4604       fprintf (file, "%*s%s\n", indent, "", target_string);
4605       free (target_string);
4606     }
4607 }
4608
4609 \f
4610 /* Inner function to process the attribute((target(...))), take an argument and
4611    set the current options from the argument. If we have a list, recursively go
4612    over the list.  */
4613
4614 static bool
4615 ix86_valid_target_attribute_inner_p (tree args, char *p_strings[],
4616                                      struct gcc_options *opts,
4617                                      struct gcc_options *opts_set,
4618                                      struct gcc_options *enum_opts_set)
4619 {
4620   char *next_optstr;
4621   bool ret = true;
4622
4623 #define IX86_ATTR_ISA(S,O)   { S, sizeof (S)-1, ix86_opt_isa, O, 0 }
4624 #define IX86_ATTR_STR(S,O)   { S, sizeof (S)-1, ix86_opt_str, O, 0 }
4625 #define IX86_ATTR_ENUM(S,O)  { S, sizeof (S)-1, ix86_opt_enum, O, 0 }
4626 #define IX86_ATTR_YES(S,O,M) { S, sizeof (S)-1, ix86_opt_yes, O, M }
4627 #define IX86_ATTR_NO(S,O,M)  { S, sizeof (S)-1, ix86_opt_no,  O, M }
4628
4629   enum ix86_opt_type
4630   {
4631     ix86_opt_unknown,
4632     ix86_opt_yes,
4633     ix86_opt_no,
4634     ix86_opt_str,
4635     ix86_opt_enum,
4636     ix86_opt_isa
4637   };
4638
4639   static const struct
4640   {
4641     const char *string;
4642     size_t len;
4643     enum ix86_opt_type type;
4644     int opt;
4645     int mask;
4646   } attrs[] = {
4647     /* isa options */
4648     IX86_ATTR_ISA ("3dnow",     OPT_m3dnow),
4649     IX86_ATTR_ISA ("abm",       OPT_mabm),
4650     IX86_ATTR_ISA ("bmi",       OPT_mbmi),
4651     IX86_ATTR_ISA ("bmi2",      OPT_mbmi2),
4652     IX86_ATTR_ISA ("lzcnt",     OPT_mlzcnt),
4653     IX86_ATTR_ISA ("tbm",       OPT_mtbm),
4654     IX86_ATTR_ISA ("aes",       OPT_maes),
4655     IX86_ATTR_ISA ("sha",       OPT_msha),
4656     IX86_ATTR_ISA ("avx",       OPT_mavx),
4657     IX86_ATTR_ISA ("avx2",      OPT_mavx2),
4658     IX86_ATTR_ISA ("avx512f",   OPT_mavx512f),
4659     IX86_ATTR_ISA ("avx512pf",  OPT_mavx512pf),
4660     IX86_ATTR_ISA ("avx512er",  OPT_mavx512er),
4661     IX86_ATTR_ISA ("avx512cd",  OPT_mavx512cd),
4662     IX86_ATTR_ISA ("avx512dq",  OPT_mavx512dq),
4663     IX86_ATTR_ISA ("avx512bw",  OPT_mavx512bw),
4664     IX86_ATTR_ISA ("avx512vl",  OPT_mavx512vl),
4665     IX86_ATTR_ISA ("mmx",       OPT_mmmx),
4666     IX86_ATTR_ISA ("pclmul",    OPT_mpclmul),
4667     IX86_ATTR_ISA ("popcnt",    OPT_mpopcnt),
4668     IX86_ATTR_ISA ("sse",       OPT_msse),
4669     IX86_ATTR_ISA ("sse2",      OPT_msse2),
4670     IX86_ATTR_ISA ("sse3",      OPT_msse3),
4671     IX86_ATTR_ISA ("sse4",      OPT_msse4),
4672     IX86_ATTR_ISA ("sse4.1",    OPT_msse4_1),
4673     IX86_ATTR_ISA ("sse4.2",    OPT_msse4_2),
4674     IX86_ATTR_ISA ("sse4a",     OPT_msse4a),
4675     IX86_ATTR_ISA ("ssse3",     OPT_mssse3),
4676     IX86_ATTR_ISA ("fma4",      OPT_mfma4),
4677     IX86_ATTR_ISA ("fma",       OPT_mfma),
4678     IX86_ATTR_ISA ("xop",       OPT_mxop),
4679     IX86_ATTR_ISA ("lwp",       OPT_mlwp),
4680     IX86_ATTR_ISA ("fsgsbase",  OPT_mfsgsbase),
4681     IX86_ATTR_ISA ("rdrnd",     OPT_mrdrnd),
4682     IX86_ATTR_ISA ("f16c",      OPT_mf16c),
4683     IX86_ATTR_ISA ("rtm",       OPT_mrtm),
4684     IX86_ATTR_ISA ("hle",       OPT_mhle),
4685     IX86_ATTR_ISA ("prfchw",    OPT_mprfchw),
4686     IX86_ATTR_ISA ("rdseed",    OPT_mrdseed),
4687     IX86_ATTR_ISA ("adx",       OPT_madx),
4688     IX86_ATTR_ISA ("fxsr",      OPT_mfxsr),
4689     IX86_ATTR_ISA ("xsave",     OPT_mxsave),
4690     IX86_ATTR_ISA ("xsaveopt",  OPT_mxsaveopt),
4691     IX86_ATTR_ISA ("prefetchwt1", OPT_mprefetchwt1),
4692     IX86_ATTR_ISA ("clflushopt",        OPT_mclflushopt),
4693     IX86_ATTR_ISA ("xsavec",    OPT_mxsavec),
4694     IX86_ATTR_ISA ("xsaves",    OPT_mxsaves),
4695     IX86_ATTR_ISA ("avx512vbmi",        OPT_mavx512vbmi),
4696     IX86_ATTR_ISA ("avx512ifma",        OPT_mavx512ifma),
4697     IX86_ATTR_ISA ("clwb",      OPT_mclwb),
4698     IX86_ATTR_ISA ("pcommit",   OPT_mpcommit),
4699
4700     /* enum options */
4701     IX86_ATTR_ENUM ("fpmath=",  OPT_mfpmath_),
4702
4703     /* string options */
4704     IX86_ATTR_STR ("arch=",     IX86_FUNCTION_SPECIFIC_ARCH),
4705     IX86_ATTR_STR ("tune=",     IX86_FUNCTION_SPECIFIC_TUNE),
4706
4707     /* flag options */
4708     IX86_ATTR_YES ("cld",
4709                    OPT_mcld,
4710                    MASK_CLD),
4711
4712     IX86_ATTR_NO ("fancy-math-387",
4713                   OPT_mfancy_math_387,
4714                   MASK_NO_FANCY_MATH_387),
4715
4716     IX86_ATTR_YES ("ieee-fp",
4717                    OPT_mieee_fp,
4718                    MASK_IEEE_FP),
4719
4720     IX86_ATTR_YES ("inline-all-stringops",
4721                    OPT_minline_all_stringops,
4722                    MASK_INLINE_ALL_STRINGOPS),
4723
4724     IX86_ATTR_YES ("inline-stringops-dynamically",
4725                    OPT_minline_stringops_dynamically,
4726                    MASK_INLINE_STRINGOPS_DYNAMICALLY),
4727
4728     IX86_ATTR_NO ("align-stringops",
4729                   OPT_mno_align_stringops,
4730                   MASK_NO_ALIGN_STRINGOPS),
4731
4732     IX86_ATTR_YES ("recip",
4733                    OPT_mrecip,
4734                    MASK_RECIP),
4735
4736   };
4737
4738   /* If this is a list, recurse to get the options.  */
4739   if (TREE_CODE (args) == TREE_LIST)
4740     {
4741       bool ret = true;
4742
4743       for (; args; args = TREE_CHAIN (args))
4744         if (TREE_VALUE (args)
4745             && !ix86_valid_target_attribute_inner_p (TREE_VALUE (args),
4746                                                      p_strings, opts, opts_set,
4747                                                      enum_opts_set))
4748           ret = false;
4749
4750       return ret;
4751     }
4752
4753   else if (TREE_CODE (args) != STRING_CST)
4754     {
4755       error ("attribute %<target%> argument not a string");
4756       return false;
4757     }
4758
4759   /* Handle multiple arguments separated by commas.  */
4760   next_optstr = ASTRDUP (TREE_STRING_POINTER (args));
4761
4762   while (next_optstr && *next_optstr != '\0')
4763     {
4764       char *p = next_optstr;
4765       char *orig_p = p;
4766       char *comma = strchr (next_optstr, ',');
4767       const char *opt_string;
4768       size_t len, opt_len;
4769       int opt;
4770       bool opt_set_p;
4771       char ch;
4772       unsigned i;
4773       enum ix86_opt_type type = ix86_opt_unknown;
4774       int mask = 0;
4775
4776       if (comma)
4777         {
4778           *comma = '\0';
4779           len = comma - next_optstr;
4780           next_optstr = comma + 1;
4781         }
4782       else
4783         {
4784           len = strlen (p);
4785           next_optstr = NULL;
4786         }
4787
4788       /* Recognize no-xxx.  */
4789       if (len > 3 && p[0] == 'n' && p[1] == 'o' && p[2] == '-')
4790         {
4791           opt_set_p = false;
4792           p += 3;
4793           len -= 3;
4794         }
4795       else
4796         opt_set_p = true;
4797
4798       /* Find the option.  */
4799       ch = *p;
4800       opt = N_OPTS;
4801       for (i = 0; i < ARRAY_SIZE (attrs); i++)
4802         {
4803           type = attrs[i].type;
4804           opt_len = attrs[i].len;
4805           if (ch == attrs[i].string[0]
4806               && ((type != ix86_opt_str && type != ix86_opt_enum)
4807                   ? len == opt_len
4808                   : len > opt_len)
4809               && memcmp (p, attrs[i].string, opt_len) == 0)
4810             {
4811               opt = attrs[i].opt;
4812               mask = attrs[i].mask;
4813               opt_string = attrs[i].string;
4814               break;
4815             }
4816         }
4817
4818       /* Process the option.  */
4819       if (opt == N_OPTS)
4820         {
4821           error ("attribute(target(\"%s\")) is unknown", orig_p);
4822           ret = false;
4823         }
4824
4825       else if (type == ix86_opt_isa)
4826         {
4827           struct cl_decoded_option decoded;
4828
4829           generate_option (opt, NULL, opt_set_p, CL_TARGET, &decoded);
4830           ix86_handle_option (opts, opts_set,
4831                               &decoded, input_location);
4832         }
4833
4834       else if (type == ix86_opt_yes || type == ix86_opt_no)
4835         {
4836           if (type == ix86_opt_no)
4837             opt_set_p = !opt_set_p;
4838
4839           if (opt_set_p)
4840             opts->x_target_flags |= mask;
4841           else
4842             opts->x_target_flags &= ~mask;
4843         }
4844
4845       else if (type == ix86_opt_str)
4846         {
4847           if (p_strings[opt])
4848             {
4849               error ("option(\"%s\") was already specified", opt_string);
4850               ret = false;
4851             }
4852           else
4853             p_strings[opt] = xstrdup (p + opt_len);
4854         }
4855
4856       else if (type == ix86_opt_enum)
4857         {
4858           bool arg_ok;
4859           int value;
4860
4861           arg_ok = opt_enum_arg_to_value (opt, p + opt_len, &value, CL_TARGET);
4862           if (arg_ok)
4863             set_option (opts, enum_opts_set, opt, value,
4864                         p + opt_len, DK_UNSPECIFIED, input_location,
4865                         global_dc);
4866           else
4867             {
4868               error ("attribute(target(\"%s\")) is unknown", orig_p);
4869               ret = false;
4870             }
4871         }
4872
4873       else
4874         gcc_unreachable ();
4875     }
4876
4877   return ret;
4878 }
4879
4880 /* Return a TARGET_OPTION_NODE tree of the target options listed or NULL.  */
4881
4882 tree
4883 ix86_valid_target_attribute_tree (tree args,
4884                                   struct gcc_options *opts,
4885                                   struct gcc_options *opts_set)
4886 {
4887   const char *orig_arch_string = opts->x_ix86_arch_string;
4888   const char *orig_tune_string = opts->x_ix86_tune_string;
4889   enum fpmath_unit orig_fpmath_set = opts_set->x_ix86_fpmath;
4890   int orig_tune_defaulted = ix86_tune_defaulted;
4891   int orig_arch_specified = ix86_arch_specified;
4892   char *option_strings[IX86_FUNCTION_SPECIFIC_MAX] = { NULL, NULL };
4893   tree t = NULL_TREE;
4894   int i;
4895   struct cl_target_option *def
4896     = TREE_TARGET_OPTION (target_option_default_node);
4897   struct gcc_options enum_opts_set;
4898
4899   memset (&enum_opts_set, 0, sizeof (enum_opts_set));
4900
4901   /* Process each of the options on the chain.  */
4902   if (! ix86_valid_target_attribute_inner_p (args, option_strings, opts,
4903                                              opts_set, &enum_opts_set))
4904     return error_mark_node;
4905
4906   /* If the changed options are different from the default, rerun
4907      ix86_option_override_internal, and then save the options away.
4908      The string options are are attribute options, and will be undone
4909      when we copy the save structure.  */
4910   if (opts->x_ix86_isa_flags != def->x_ix86_isa_flags
4911       || opts->x_target_flags != def->x_target_flags
4912       || option_strings[IX86_FUNCTION_SPECIFIC_ARCH]
4913       || option_strings[IX86_FUNCTION_SPECIFIC_TUNE]
4914       || enum_opts_set.x_ix86_fpmath)
4915     {
4916       /* If we are using the default tune= or arch=, undo the string assigned,
4917          and use the default.  */
4918       if (option_strings[IX86_FUNCTION_SPECIFIC_ARCH])
4919         opts->x_ix86_arch_string = option_strings[IX86_FUNCTION_SPECIFIC_ARCH];
4920       else if (!orig_arch_specified)
4921         opts->x_ix86_arch_string = NULL;
4922
4923       if (option_strings[IX86_FUNCTION_SPECIFIC_TUNE])
4924         opts->x_ix86_tune_string = option_strings[IX86_FUNCTION_SPECIFIC_TUNE];
4925       else if (orig_tune_defaulted)
4926         opts->x_ix86_tune_string = NULL;
4927
4928       /* If fpmath= is not set, and we now have sse2 on 32-bit, use it.  */
4929       if (enum_opts_set.x_ix86_fpmath)
4930         opts_set->x_ix86_fpmath = (enum fpmath_unit) 1;
4931       else if (!TARGET_64BIT_P (opts->x_ix86_isa_flags)
4932                && TARGET_SSE_P (opts->x_ix86_isa_flags))
4933         {
4934           opts->x_ix86_fpmath = (enum fpmath_unit) (FPMATH_SSE | FPMATH_387);
4935           opts_set->x_ix86_fpmath = (enum fpmath_unit) 1;
4936         }
4937
4938       /* Do any overrides, such as arch=xxx, or tune=xxx support.  */
4939       ix86_option_override_internal (false, opts, opts_set);
4940
4941       /* Add any builtin functions with the new isa if any.  */
4942       ix86_add_new_builtins (opts->x_ix86_isa_flags);
4943
4944       /* Save the current options unless we are validating options for
4945          #pragma.  */
4946       t = build_target_option_node (opts);
4947
4948       opts->x_ix86_arch_string = orig_arch_string;
4949       opts->x_ix86_tune_string = orig_tune_string;
4950       opts_set->x_ix86_fpmath = orig_fpmath_set;
4951
4952       /* Free up memory allocated to hold the strings */
4953       for (i = 0; i < IX86_FUNCTION_SPECIFIC_MAX; i++)
4954         free (option_strings[i]);
4955     }
4956
4957   return t;
4958 }
4959
4960 /* Hook to validate attribute((target("string"))).  */
4961
4962 static bool
4963 ix86_valid_target_attribute_p (tree fndecl,
4964                                tree ARG_UNUSED (name),
4965                                tree args,
4966                                int ARG_UNUSED (flags))
4967 {
4968   struct gcc_options func_options;
4969   tree new_target, new_optimize;
4970   bool ret = true;
4971
4972   /* attribute((target("default"))) does nothing, beyond
4973      affecting multi-versioning.  */
4974   if (TREE_VALUE (args)
4975       && TREE_CODE (TREE_VALUE (args)) == STRING_CST
4976       && TREE_CHAIN (args) == NULL_TREE
4977       && strcmp (TREE_STRING_POINTER (TREE_VALUE (args)), "default") == 0)
4978     return true;
4979
4980   tree old_optimize = build_optimization_node (&global_options);
4981
4982   /* Get the optimization options of the current function.  */  
4983   tree func_optimize = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl);
4984  
4985   if (!func_optimize)
4986     func_optimize = old_optimize;
4987
4988   /* Init func_options.  */
4989   memset (&func_options, 0, sizeof (func_options));
4990   init_options_struct (&func_options, NULL);
4991   lang_hooks.init_options_struct (&func_options);
4992  
4993   cl_optimization_restore (&func_options,
4994                            TREE_OPTIMIZATION (func_optimize));
4995
4996   /* Initialize func_options to the default before its target options can
4997      be set.  */
4998   cl_target_option_restore (&func_options,
4999                             TREE_TARGET_OPTION (target_option_default_node));
5000
5001   new_target = ix86_valid_target_attribute_tree (args, &func_options,
5002                                                  &global_options_set);
5003
5004   new_optimize = build_optimization_node (&func_options);
5005
5006   if (new_target == error_mark_node)
5007     ret = false;
5008
5009   else if (fndecl && new_target)
5010     {
5011       DECL_FUNCTION_SPECIFIC_TARGET (fndecl) = new_target;
5012
5013       if (old_optimize != new_optimize)
5014         DECL_FUNCTION_SPECIFIC_OPTIMIZATION (fndecl) = new_optimize;
5015     }
5016
5017   return ret;
5018 }
5019
5020 \f
5021 /* Hook to determine if one function can safely inline another.  */
5022
5023 static bool
5024 ix86_can_inline_p (tree caller, tree callee)
5025 {
5026   bool ret = false;
5027   tree caller_tree = DECL_FUNCTION_SPECIFIC_TARGET (caller);
5028   tree callee_tree = DECL_FUNCTION_SPECIFIC_TARGET (callee);
5029
5030   /* If callee has no option attributes, then it is ok to inline.  */
5031   if (!callee_tree)
5032     ret = true;
5033
5034   /* If caller has no option attributes, but callee does then it is not ok to
5035      inline.  */
5036   else if (!caller_tree)
5037     ret = false;
5038
5039   else
5040     {
5041       struct cl_target_option *caller_opts = TREE_TARGET_OPTION (caller_tree);
5042       struct cl_target_option *callee_opts = TREE_TARGET_OPTION (callee_tree);
5043
5044       /* Callee's isa options should a subset of the caller's, i.e. a SSE4 function
5045          can inline a SSE2 function but a SSE2 function can't inline a SSE4
5046          function.  */
5047       if ((caller_opts->x_ix86_isa_flags & callee_opts->x_ix86_isa_flags)
5048           != callee_opts->x_ix86_isa_flags)
5049         ret = false;
5050
5051       /* See if we have the same non-isa options.  */
5052       else if (caller_opts->x_target_flags != callee_opts->x_target_flags)
5053         ret = false;
5054
5055       /* See if arch, tune, etc. are the same.  */
5056       else if (caller_opts->arch != callee_opts->arch)
5057         ret = false;
5058
5059       else if (caller_opts->tune != callee_opts->tune)
5060         ret = false;
5061
5062       else if (caller_opts->x_ix86_fpmath != callee_opts->x_ix86_fpmath)
5063         ret = false;
5064
5065       else if (caller_opts->branch_cost != callee_opts->branch_cost)
5066         ret = false;
5067
5068       else
5069         ret = true;
5070     }
5071
5072   return ret;
5073 }
5074
5075 \f
5076 /* Remember the last target of ix86_set_current_function.  */
5077 static GTY(()) tree ix86_previous_fndecl;
5078
5079 /* Set target globals to default.  */
5080
5081 static void
5082 ix86_reset_to_default_globals (void)
5083 {
5084   tree old_tree = (ix86_previous_fndecl
5085                    ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
5086                    : NULL_TREE);
5087
5088   if (old_tree)
5089     {
5090       tree new_tree = target_option_current_node;
5091       cl_target_option_restore (&global_options,
5092                                 TREE_TARGET_OPTION (new_tree));
5093       if (TREE_TARGET_GLOBALS (new_tree))
5094         restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
5095       else if (new_tree == target_option_default_node)
5096         restore_target_globals (&default_target_globals);
5097       else
5098         TREE_TARGET_GLOBALS (new_tree)
5099           = save_target_globals_default_opts ();
5100     }
5101 }
5102
5103 /* Invalidate ix86_previous_fndecl cache.  */
5104 void
5105 ix86_reset_previous_fndecl (void)
5106 {
5107   ix86_reset_to_default_globals ();
5108   ix86_previous_fndecl = NULL_TREE;
5109 }
5110
5111 /* Establish appropriate back-end context for processing the function
5112    FNDECL.  The argument might be NULL to indicate processing at top
5113    level, outside of any function scope.  */
5114 static void
5115 ix86_set_current_function (tree fndecl)
5116 {
5117   /* Only change the context if the function changes.  This hook is called
5118      several times in the course of compiling a function, and we don't want to
5119      slow things down too much or call target_reinit when it isn't safe.  */
5120   if (fndecl && fndecl != ix86_previous_fndecl)
5121     {
5122       tree old_tree = (ix86_previous_fndecl
5123                        ? DECL_FUNCTION_SPECIFIC_TARGET (ix86_previous_fndecl)
5124                        : NULL_TREE);
5125
5126       tree new_tree = (fndecl
5127                        ? DECL_FUNCTION_SPECIFIC_TARGET (fndecl)
5128                        : NULL_TREE);
5129
5130       if (old_tree == new_tree)
5131         ;
5132
5133       else if (new_tree && new_tree != target_option_default_node)
5134         {
5135           cl_target_option_restore (&global_options,
5136                                     TREE_TARGET_OPTION (new_tree));
5137           if (TREE_TARGET_GLOBALS (new_tree))
5138             restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
5139           else
5140             TREE_TARGET_GLOBALS (new_tree)
5141               = save_target_globals_default_opts ();
5142         }
5143
5144       else if (old_tree && old_tree != target_option_default_node)
5145         ix86_reset_to_default_globals ();
5146       ix86_previous_fndecl = fndecl;
5147     }
5148 }
5149
5150 \f
5151 /* Return true if this goes in large data/bss.  */
5152
5153 static bool
5154 ix86_in_large_data_p (tree exp)
5155 {
5156   if (ix86_cmodel != CM_MEDIUM && ix86_cmodel != CM_MEDIUM_PIC)
5157     return false;
5158
5159   /* Functions are never large data.  */
5160   if (TREE_CODE (exp) == FUNCTION_DECL)
5161     return false;
5162
5163   /* Automatic variables are never large data.  */
5164   if (TREE_CODE (exp) == VAR_DECL && !is_global_var (exp))
5165     return false;
5166
5167   if (TREE_CODE (exp) == VAR_DECL && DECL_SECTION_NAME (exp))
5168     {
5169       const char *section = DECL_SECTION_NAME (exp);
5170       if (strcmp (section, ".ldata") == 0
5171           || strcmp (section, ".lbss") == 0)
5172         return true;
5173       return false;
5174     }
5175   else
5176     {
5177       HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
5178
5179       /* If this is an incomplete type with size 0, then we can't put it
5180          in data because it might be too big when completed.  Also,
5181          int_size_in_bytes returns -1 if size can vary or is larger than
5182          an integer in which case also it is safer to assume that it goes in
5183          large data.  */
5184       if (size <= 0 || size > ix86_section_threshold)
5185         return true;
5186     }
5187
5188   return false;
5189 }
5190
5191 /* Switch to the appropriate section for output of DECL.
5192    DECL is either a `VAR_DECL' node or a constant of some sort.
5193    RELOC indicates whether forming the initial value of DECL requires
5194    link-time relocations.  */
5195
5196 ATTRIBUTE_UNUSED static section *
5197 x86_64_elf_select_section (tree decl, int reloc,
5198                            unsigned HOST_WIDE_INT align)
5199 {
5200   if (ix86_in_large_data_p (decl))
5201     {
5202       const char *sname = NULL;
5203       unsigned int flags = SECTION_WRITE;
5204       switch (categorize_decl_for_section (decl, reloc))
5205         {
5206         case SECCAT_DATA:
5207           sname = ".ldata";
5208           break;
5209         case SECCAT_DATA_REL:
5210           sname = ".ldata.rel";
5211           break;
5212         case SECCAT_DATA_REL_LOCAL:
5213           sname = ".ldata.rel.local";
5214           break;
5215         case SECCAT_DATA_REL_RO:
5216           sname = ".ldata.rel.ro";
5217           break;
5218         case SECCAT_DATA_REL_RO_LOCAL:
5219           sname = ".ldata.rel.ro.local";
5220           break;
5221         case SECCAT_BSS:
5222           sname = ".lbss";
5223           flags |= SECTION_BSS;
5224           break;
5225         case SECCAT_RODATA:
5226         case SECCAT_RODATA_MERGE_STR:
5227         case SECCAT_RODATA_MERGE_STR_INIT:
5228         case SECCAT_RODATA_MERGE_CONST:
5229           sname = ".lrodata";
5230           flags = 0;
5231           break;
5232         case SECCAT_SRODATA:
5233         case SECCAT_SDATA:
5234         case SECCAT_SBSS:
5235           gcc_unreachable ();
5236         case SECCAT_TEXT:
5237         case SECCAT_TDATA:
5238         case SECCAT_TBSS:
5239           /* We don't split these for medium model.  Place them into
5240              default sections and hope for best.  */
5241           break;
5242         }
5243       if (sname)
5244         {
5245           /* We might get called with string constants, but get_named_section
5246              doesn't like them as they are not DECLs.  Also, we need to set
5247              flags in that case.  */
5248           if (!DECL_P (decl))
5249             return get_section (sname, flags, NULL);
5250           return get_named_section (decl, sname, reloc);
5251         }
5252     }
5253   return default_elf_select_section (decl, reloc, align);
5254 }
5255
5256 /* Select a set of attributes for section NAME based on the properties
5257    of DECL and whether or not RELOC indicates that DECL's initializer
5258    might contain runtime relocations.  */
5259
5260 static unsigned int ATTRIBUTE_UNUSED
5261 x86_64_elf_section_type_flags (tree decl, const char *name, int reloc)
5262 {
5263   unsigned int flags = default_section_type_flags (decl, name, reloc);
5264
5265   if (decl == NULL_TREE
5266       && (strcmp (name, ".ldata.rel.ro") == 0
5267           || strcmp (name, ".ldata.rel.ro.local") == 0))
5268     flags |= SECTION_RELRO;
5269
5270   if (strcmp (name, ".lbss") == 0
5271       || strncmp (name, ".lbss.", 5) == 0
5272       || strncmp (name, ".gnu.linkonce.lb.", 16) == 0)
5273     flags |= SECTION_BSS;
5274
5275   return flags;
5276 }
5277
5278 /* Build up a unique section name, expressed as a
5279    STRING_CST node, and assign it to DECL_SECTION_NAME (decl).
5280    RELOC indicates whether the initial value of EXP requires
5281    link-time relocations.  */
5282
5283 static void ATTRIBUTE_UNUSED
5284 x86_64_elf_unique_section (tree decl, int reloc)
5285 {
5286   if (ix86_in_large_data_p (decl))
5287     {
5288       const char *prefix = NULL;
5289       /* We only need to use .gnu.linkonce if we don't have COMDAT groups.  */
5290       bool one_only = DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP;
5291
5292       switch (categorize_decl_for_section (decl, reloc))
5293         {
5294         case SECCAT_DATA:
5295         case SECCAT_DATA_REL:
5296         case SECCAT_DATA_REL_LOCAL:
5297         case SECCAT_DATA_REL_RO:
5298         case SECCAT_DATA_REL_RO_LOCAL:
5299           prefix = one_only ? ".ld" : ".ldata";
5300           break;
5301         case SECCAT_BSS:
5302           prefix = one_only ? ".lb" : ".lbss";
5303           break;
5304         case SECCAT_RODATA:
5305         case SECCAT_RODATA_MERGE_STR:
5306         case SECCAT_RODATA_MERGE_STR_INIT:
5307         case SECCAT_RODATA_MERGE_CONST:
5308           prefix = one_only ? ".lr" : ".lrodata";
5309           break;
5310         case SECCAT_SRODATA:
5311         case SECCAT_SDATA:
5312         case SECCAT_SBSS:
5313           gcc_unreachable ();
5314         case SECCAT_TEXT:
5315         case SECCAT_TDATA:
5316         case SECCAT_TBSS:
5317           /* We don't split these for medium model.  Place them into
5318              default sections and hope for best.  */
5319           break;
5320         }
5321       if (prefix)
5322         {
5323           const char *name, *linkonce;
5324           char *string;
5325
5326           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5327           name = targetm.strip_name_encoding (name);
5328
5329           /* If we're using one_only, then there needs to be a .gnu.linkonce
5330              prefix to the section name.  */
5331           linkonce = one_only ? ".gnu.linkonce" : "";
5332
5333           string = ACONCAT ((linkonce, prefix, ".", name, NULL));
5334
5335           set_decl_section_name (decl, string);
5336           return;
5337         }
5338     }
5339   default_unique_section (decl, reloc);
5340 }
5341
5342 #ifdef COMMON_ASM_OP
5343 /* This says how to output assembler code to declare an
5344    uninitialized external linkage data object.
5345
5346    For medium model x86-64 we need to use .largecomm opcode for
5347    large objects.  */
5348 void
5349 x86_elf_aligned_common (FILE *file,
5350                         const char *name, unsigned HOST_WIDE_INT size,
5351                         int align)
5352 {
5353   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
5354       && size > (unsigned int)ix86_section_threshold)
5355     fputs ("\t.largecomm\t", file);
5356   else
5357     fputs (COMMON_ASM_OP, file);
5358   assemble_name (file, name);
5359   fprintf (file, "," HOST_WIDE_INT_PRINT_UNSIGNED ",%u\n",
5360            size, align / BITS_PER_UNIT);
5361 }
5362 #endif
5363
5364 /* Utility function for targets to use in implementing
5365    ASM_OUTPUT_ALIGNED_BSS.  */
5366
5367 void
5368 x86_output_aligned_bss (FILE *file, tree decl, const char *name,
5369                         unsigned HOST_WIDE_INT size, int align)
5370 {
5371   if ((ix86_cmodel == CM_MEDIUM || ix86_cmodel == CM_MEDIUM_PIC)
5372       && size > (unsigned int)ix86_section_threshold)
5373     switch_to_section (get_named_section (decl, ".lbss", 0));
5374   else
5375     switch_to_section (bss_section);
5376   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
5377 #ifdef ASM_DECLARE_OBJECT_NAME
5378   last_assemble_variable_decl = decl;
5379   ASM_DECLARE_OBJECT_NAME (file, name, decl);
5380 #else
5381   /* Standard thing is just output label for the object.  */
5382   ASM_OUTPUT_LABEL (file, name);
5383 #endif /* ASM_DECLARE_OBJECT_NAME */
5384   ASM_OUTPUT_SKIP (file, size ? size : 1);
5385 }
5386 \f
5387 /* Decide whether we must probe the stack before any space allocation
5388    on this target.  It's essentially TARGET_STACK_PROBE except when
5389    -fstack-check causes the stack to be already probed differently.  */
5390
5391 bool
5392 ix86_target_stack_probe (void)
5393 {
5394   /* Do not probe the stack twice if static stack checking is enabled.  */
5395   if (flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
5396     return false;
5397
5398   return TARGET_STACK_PROBE;
5399 }
5400 \f
5401 /* Decide whether we can make a sibling call to a function.  DECL is the
5402    declaration of the function being targeted by the call and EXP is the
5403    CALL_EXPR representing the call.  */
5404
5405 static bool
5406 ix86_function_ok_for_sibcall (tree decl, tree exp)
5407 {
5408   tree type, decl_or_type;
5409   rtx a, b;
5410
5411   /* If we are generating position-independent code, we cannot sibcall
5412      optimize any indirect call, or a direct call to a global function,
5413      as the PLT requires %ebx be live. (Darwin does not have a PLT.)  */
5414   if (!TARGET_MACHO
5415       && !TARGET_64BIT
5416       && flag_pic
5417       && (!decl || !targetm.binds_local_p (decl)))
5418     return false;
5419
5420   /* If we need to align the outgoing stack, then sibcalling would
5421      unalign the stack, which may break the called function.  */
5422   if (ix86_minimum_incoming_stack_boundary (true)
5423       < PREFERRED_STACK_BOUNDARY)
5424     return false;
5425
5426   if (decl)
5427     {
5428       decl_or_type = decl;
5429       type = TREE_TYPE (decl);
5430     }
5431   else
5432     {
5433       /* We're looking at the CALL_EXPR, we need the type of the function.  */
5434       type = CALL_EXPR_FN (exp);                /* pointer expression */
5435       type = TREE_TYPE (type);                  /* pointer type */
5436       type = TREE_TYPE (type);                  /* function type */
5437       decl_or_type = type;
5438     }
5439
5440   /* Check that the return value locations are the same.  Like
5441      if we are returning floats on the 80387 register stack, we cannot
5442      make a sibcall from a function that doesn't return a float to a
5443      function that does or, conversely, from a function that does return
5444      a float to a function that doesn't; the necessary stack adjustment
5445      would not be executed.  This is also the place we notice
5446      differences in the return value ABI.  Note that it is ok for one
5447      of the functions to have void return type as long as the return
5448      value of the other is passed in a register.  */
5449   a = ix86_function_value (TREE_TYPE (exp), decl_or_type, false);
5450   b = ix86_function_value (TREE_TYPE (DECL_RESULT (cfun->decl)),
5451                            cfun->decl, false);
5452   if (STACK_REG_P (a) || STACK_REG_P (b))
5453     {
5454       if (!rtx_equal_p (a, b))
5455         return false;
5456     }
5457   else if (VOID_TYPE_P (TREE_TYPE (DECL_RESULT (cfun->decl))))
5458     ;
5459   else if (!rtx_equal_p (a, b))
5460     return false;
5461
5462   if (TARGET_64BIT)
5463     {
5464       /* The SYSV ABI has more call-clobbered registers;
5465          disallow sibcalls from MS to SYSV.  */
5466       if (cfun->machine->call_abi == MS_ABI
5467           && ix86_function_type_abi (type) == SYSV_ABI)
5468         return false;
5469     }
5470   else
5471     {
5472       /* If this call is indirect, we'll need to be able to use a
5473          call-clobbered register for the address of the target function.
5474          Make sure that all such registers are not used for passing
5475          parameters.  Note that DLLIMPORT functions are indirect.  */
5476       if (!decl
5477           || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl)))
5478         {
5479           if (ix86_function_regparm (type, NULL) >= 3)
5480             {
5481               /* ??? Need to count the actual number of registers to be used,
5482                  not the possible number of registers.  Fix later.  */
5483               return false;
5484             }
5485         }
5486     }
5487
5488   /* Otherwise okay.  That also includes certain types of indirect calls.  */
5489   return true;
5490 }
5491
5492 /* Handle "cdecl", "stdcall", "fastcall", "regparm", "thiscall",
5493    and "sseregparm" calling convention attributes;
5494    arguments as in struct attribute_spec.handler.  */
5495
5496 static tree
5497 ix86_handle_cconv_attribute (tree *node, tree name,
5498                                    tree args,
5499                                    int,
5500                                    bool *no_add_attrs)
5501 {
5502   if (TREE_CODE (*node) != FUNCTION_TYPE
5503       && TREE_CODE (*node) != METHOD_TYPE
5504       && TREE_CODE (*node) != FIELD_DECL
5505       && TREE_CODE (*node) != TYPE_DECL)
5506     {
5507       warning (OPT_Wattributes, "%qE attribute only applies to functions",
5508                name);
5509       *no_add_attrs = true;
5510       return NULL_TREE;
5511     }
5512
5513   /* Can combine regparm with all attributes but fastcall, and thiscall.  */
5514   if (is_attribute_p ("regparm", name))
5515     {
5516       tree cst;
5517
5518       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5519         {
5520           error ("fastcall and regparm attributes are not compatible");
5521         }
5522
5523       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5524         {
5525           error ("regparam and thiscall attributes are not compatible");
5526         }
5527
5528       cst = TREE_VALUE (args);
5529       if (TREE_CODE (cst) != INTEGER_CST)
5530         {
5531           warning (OPT_Wattributes,
5532                    "%qE attribute requires an integer constant argument",
5533                    name);
5534           *no_add_attrs = true;
5535         }
5536       else if (compare_tree_int (cst, REGPARM_MAX) > 0)
5537         {
5538           warning (OPT_Wattributes, "argument to %qE attribute larger than %d",
5539                    name, REGPARM_MAX);
5540           *no_add_attrs = true;
5541         }
5542
5543       return NULL_TREE;
5544     }
5545
5546   if (TARGET_64BIT)
5547     {
5548       /* Do not warn when emulating the MS ABI.  */
5549       if ((TREE_CODE (*node) != FUNCTION_TYPE
5550            && TREE_CODE (*node) != METHOD_TYPE)
5551           || ix86_function_type_abi (*node) != MS_ABI)
5552         warning (OPT_Wattributes, "%qE attribute ignored",
5553                  name);
5554       *no_add_attrs = true;
5555       return NULL_TREE;
5556     }
5557
5558   /* Can combine fastcall with stdcall (redundant) and sseregparm.  */
5559   if (is_attribute_p ("fastcall", name))
5560     {
5561       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
5562         {
5563           error ("fastcall and cdecl attributes are not compatible");
5564         }
5565       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
5566         {
5567           error ("fastcall and stdcall attributes are not compatible");
5568         }
5569       if (lookup_attribute ("regparm", TYPE_ATTRIBUTES (*node)))
5570         {
5571           error ("fastcall and regparm attributes are not compatible");
5572         }
5573       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5574         {
5575           error ("fastcall and thiscall attributes are not compatible");
5576         }
5577     }
5578
5579   /* Can combine stdcall with fastcall (redundant), regparm and
5580      sseregparm.  */
5581   else if (is_attribute_p ("stdcall", name))
5582     {
5583       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
5584         {
5585           error ("stdcall and cdecl attributes are not compatible");
5586         }
5587       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5588         {
5589           error ("stdcall and fastcall attributes are not compatible");
5590         }
5591       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5592         {
5593           error ("stdcall and thiscall attributes are not compatible");
5594         }
5595     }
5596
5597   /* Can combine cdecl with regparm and sseregparm.  */
5598   else if (is_attribute_p ("cdecl", name))
5599     {
5600       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
5601         {
5602           error ("stdcall and cdecl attributes are not compatible");
5603         }
5604       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5605         {
5606           error ("fastcall and cdecl attributes are not compatible");
5607         }
5608       if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (*node)))
5609         {
5610           error ("cdecl and thiscall attributes are not compatible");
5611         }
5612     }
5613   else if (is_attribute_p ("thiscall", name))
5614     {
5615       if (TREE_CODE (*node) != METHOD_TYPE && pedantic)
5616         warning (OPT_Wattributes, "%qE attribute is used for none class-method",
5617                  name);
5618       if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (*node)))
5619         {
5620           error ("stdcall and thiscall attributes are not compatible");
5621         }
5622       if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (*node)))
5623         {
5624           error ("fastcall and thiscall attributes are not compatible");
5625         }
5626       if (lookup_attribute ("cdecl", TYPE_ATTRIBUTES (*node)))
5627         {
5628           error ("cdecl and thiscall attributes are not compatible");
5629         }
5630     }
5631
5632   /* Can combine sseregparm with all attributes.  */
5633
5634   return NULL_TREE;
5635 }
5636
5637 /* The transactional memory builtins are implicitly regparm or fastcall
5638    depending on the ABI.  Override the generic do-nothing attribute that
5639    these builtins were declared with, and replace it with one of the two
5640    attributes that we expect elsewhere.  */
5641
5642 static tree
5643 ix86_handle_tm_regparm_attribute (tree *node, tree, tree,
5644                                   int flags, bool *no_add_attrs)
5645 {
5646   tree alt;
5647
5648   /* In no case do we want to add the placeholder attribute.  */
5649   *no_add_attrs = true;
5650
5651   /* The 64-bit ABI is unchanged for transactional memory.  */
5652   if (TARGET_64BIT)
5653     return NULL_TREE;
5654
5655   /* ??? Is there a better way to validate 32-bit windows?  We have
5656      cfun->machine->call_abi, but that seems to be set only for 64-bit.  */
5657   if (CHECK_STACK_LIMIT > 0)
5658     alt = tree_cons (get_identifier ("fastcall"), NULL, NULL);
5659   else
5660     {
5661       alt = tree_cons (NULL, build_int_cst (NULL, 2), NULL);
5662       alt = tree_cons (get_identifier ("regparm"), alt, NULL);
5663     }
5664   decl_attributes (node, alt, flags);
5665
5666   return NULL_TREE;
5667 }
5668
5669 /* This function determines from TYPE the calling-convention.  */
5670
5671 unsigned int
5672 ix86_get_callcvt (const_tree type)
5673 {
5674   unsigned int ret = 0;
5675   bool is_stdarg;
5676   tree attrs;
5677
5678   if (TARGET_64BIT)
5679     return IX86_CALLCVT_CDECL;
5680
5681   attrs = TYPE_ATTRIBUTES (type);
5682   if (attrs != NULL_TREE)
5683     {
5684       if (lookup_attribute ("cdecl", attrs))
5685         ret |= IX86_CALLCVT_CDECL;
5686       else if (lookup_attribute ("stdcall", attrs))
5687         ret |= IX86_CALLCVT_STDCALL;
5688       else if (lookup_attribute ("fastcall", attrs))
5689         ret |= IX86_CALLCVT_FASTCALL;
5690       else if (lookup_attribute ("thiscall", attrs))
5691         ret |= IX86_CALLCVT_THISCALL;
5692
5693       /* Regparam isn't allowed for thiscall and fastcall.  */
5694       if ((ret & (IX86_CALLCVT_THISCALL | IX86_CALLCVT_FASTCALL)) == 0)
5695         {
5696           if (lookup_attribute ("regparm", attrs))
5697             ret |= IX86_CALLCVT_REGPARM;
5698           if (lookup_attribute ("sseregparm", attrs))
5699             ret |= IX86_CALLCVT_SSEREGPARM;
5700         }
5701
5702       if (IX86_BASE_CALLCVT(ret) != 0)
5703         return ret;
5704     }
5705
5706   is_stdarg = stdarg_p (type);
5707   if (TARGET_RTD && !is_stdarg)
5708     return IX86_CALLCVT_STDCALL | ret;
5709
5710   if (ret != 0
5711       || is_stdarg
5712       || TREE_CODE (type) != METHOD_TYPE
5713       || ix86_function_type_abi (type) != MS_ABI)
5714     return IX86_CALLCVT_CDECL | ret;
5715
5716   return IX86_CALLCVT_THISCALL;
5717 }
5718
5719 /* Return 0 if the attributes for two types are incompatible, 1 if they
5720    are compatible, and 2 if they are nearly compatible (which causes a
5721    warning to be generated).  */
5722
5723 static int
5724 ix86_comp_type_attributes (const_tree type1, const_tree type2)
5725 {
5726   unsigned int ccvt1, ccvt2;
5727
5728   if (TREE_CODE (type1) != FUNCTION_TYPE
5729       && TREE_CODE (type1) != METHOD_TYPE)
5730     return 1;
5731
5732   ccvt1 = ix86_get_callcvt (type1);
5733   ccvt2 = ix86_get_callcvt (type2);
5734   if (ccvt1 != ccvt2)
5735     return 0;
5736   if (ix86_function_regparm (type1, NULL)
5737       != ix86_function_regparm (type2, NULL))
5738     return 0;
5739
5740   return 1;
5741 }
5742 \f
5743 /* Return the regparm value for a function with the indicated TYPE and DECL.
5744    DECL may be NULL when calling function indirectly
5745    or considering a libcall.  */
5746
5747 static int
5748 ix86_function_regparm (const_tree type, const_tree decl)
5749 {
5750   tree attr;
5751   int regparm;
5752   unsigned int ccvt;
5753
5754   if (TARGET_64BIT)
5755     return (ix86_function_type_abi (type) == SYSV_ABI
5756             ? X86_64_REGPARM_MAX : X86_64_MS_REGPARM_MAX);
5757   ccvt = ix86_get_callcvt (type);
5758   regparm = ix86_regparm;
5759
5760   if ((ccvt & IX86_CALLCVT_REGPARM) != 0)
5761     {
5762       attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (type));
5763       if (attr)
5764         {
5765           regparm = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr)));
5766           return regparm;
5767         }
5768     }
5769   else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
5770     return 2;
5771   else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
5772     return 1;
5773
5774   /* Use register calling convention for local functions when possible.  */
5775   if (decl
5776       && TREE_CODE (decl) == FUNCTION_DECL
5777       /* Caller and callee must agree on the calling convention, so
5778          checking here just optimize means that with
5779          __attribute__((optimize (...))) caller could use regparm convention
5780          and callee not, or vice versa.  Instead look at whether the callee
5781          is optimized or not.  */
5782       && opt_for_fn (decl, optimize)
5783       && !(profile_flag && !flag_fentry))
5784     {
5785       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
5786       cgraph_local_info *i = cgraph_node::local_info (CONST_CAST_TREE (decl));
5787       if (i && i->local && i->can_change_signature)
5788         {
5789           int local_regparm, globals = 0, regno;
5790
5791           /* Make sure no regparm register is taken by a
5792              fixed register variable.  */
5793           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
5794             if (fixed_regs[local_regparm])
5795               break;
5796
5797           /* We don't want to use regparm(3) for nested functions as
5798              these use a static chain pointer in the third argument.  */
5799           if (local_regparm == 3 && DECL_STATIC_CHAIN (decl))
5800             local_regparm = 2;
5801
5802           /* In 32-bit mode save a register for the split stack.  */
5803           if (!TARGET_64BIT && local_regparm == 3 && flag_split_stack)
5804             local_regparm = 2;
5805
5806           /* Each fixed register usage increases register pressure,
5807              so less registers should be used for argument passing.
5808              This functionality can be overriden by an explicit
5809              regparm value.  */
5810           for (regno = AX_REG; regno <= DI_REG; regno++)
5811             if (fixed_regs[regno])
5812               globals++;
5813
5814           local_regparm
5815             = globals < local_regparm ? local_regparm - globals : 0;
5816
5817           if (local_regparm > regparm)
5818             regparm = local_regparm;
5819         }
5820     }
5821
5822   return regparm;
5823 }
5824
5825 /* Return 1 or 2, if we can pass up to SSE_REGPARM_MAX SFmode (1) and
5826    DFmode (2) arguments in SSE registers for a function with the
5827    indicated TYPE and DECL.  DECL may be NULL when calling function
5828    indirectly or considering a libcall.  Otherwise return 0.  */
5829
5830 static int
5831 ix86_function_sseregparm (const_tree type, const_tree decl, bool warn)
5832 {
5833   gcc_assert (!TARGET_64BIT);
5834
5835   /* Use SSE registers to pass SFmode and DFmode arguments if requested
5836      by the sseregparm attribute.  */
5837   if (TARGET_SSEREGPARM
5838       || (type && lookup_attribute ("sseregparm", TYPE_ATTRIBUTES (type))))
5839     {
5840       if (!TARGET_SSE)
5841         {
5842           if (warn)
5843             {
5844               if (decl)
5845                 error ("calling %qD with attribute sseregparm without "
5846                        "SSE/SSE2 enabled", decl);
5847               else
5848                 error ("calling %qT with attribute sseregparm without "
5849                        "SSE/SSE2 enabled", type);
5850             }
5851           return 0;
5852         }
5853
5854       return 2;
5855     }
5856
5857   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
5858      (and DFmode for SSE2) arguments in SSE registers.  */
5859   if (decl && TARGET_SSE_MATH && optimize
5860       && !(profile_flag && !flag_fentry))
5861     {
5862       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
5863       cgraph_local_info *i = cgraph_node::local_info (CONST_CAST_TREE(decl));
5864       if (i && i->local && i->can_change_signature)
5865         return TARGET_SSE2 ? 2 : 1;
5866     }
5867
5868   return 0;
5869 }
5870
5871 /* Return true if EAX is live at the start of the function.  Used by
5872    ix86_expand_prologue to determine if we need special help before
5873    calling allocate_stack_worker.  */
5874
5875 static bool
5876 ix86_eax_live_at_start_p (void)
5877 {
5878   /* Cheat.  Don't bother working forward from ix86_function_regparm
5879      to the function type to whether an actual argument is located in
5880      eax.  Instead just look at cfg info, which is still close enough
5881      to correct at this point.  This gives false positives for broken
5882      functions that might use uninitialized data that happens to be
5883      allocated in eax, but who cares?  */
5884   return REGNO_REG_SET_P (df_get_live_out (ENTRY_BLOCK_PTR_FOR_FN (cfun)), 0);
5885 }
5886
5887 static bool
5888 ix86_keep_aggregate_return_pointer (tree fntype)
5889 {
5890   tree attr;
5891
5892   if (!TARGET_64BIT)
5893     {
5894       attr = lookup_attribute ("callee_pop_aggregate_return",
5895                                TYPE_ATTRIBUTES (fntype));
5896       if (attr)
5897         return (TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))) == 0);
5898
5899       /* For 32-bit MS-ABI the default is to keep aggregate
5900          return pointer.  */
5901       if (ix86_function_type_abi (fntype) == MS_ABI)
5902         return true;
5903     }
5904   return KEEP_AGGREGATE_RETURN_POINTER != 0;
5905 }
5906
5907 /* Value is the number of bytes of arguments automatically
5908    popped when returning from a subroutine call.
5909    FUNDECL is the declaration node of the function (as a tree),
5910    FUNTYPE is the data type of the function (as a tree),
5911    or for a library call it is an identifier node for the subroutine name.
5912    SIZE is the number of bytes of arguments passed on the stack.
5913
5914    On the 80386, the RTD insn may be used to pop them if the number
5915      of args is fixed, but if the number is variable then the caller
5916      must pop them all.  RTD can't be used for library calls now
5917      because the library is compiled with the Unix compiler.
5918    Use of RTD is a selectable option, since it is incompatible with
5919    standard Unix calling sequences.  If the option is not selected,
5920    the caller must always pop the args.
5921
5922    The attribute stdcall is equivalent to RTD on a per module basis.  */
5923
5924 static int
5925 ix86_return_pops_args (tree fundecl, tree funtype, int size)
5926 {
5927   unsigned int ccvt;
5928
5929   /* None of the 64-bit ABIs pop arguments.  */
5930   if (TARGET_64BIT)
5931     return 0;
5932
5933   ccvt = ix86_get_callcvt (funtype);
5934
5935   if ((ccvt & (IX86_CALLCVT_STDCALL | IX86_CALLCVT_FASTCALL
5936                | IX86_CALLCVT_THISCALL)) != 0
5937       && ! stdarg_p (funtype))
5938     return size;
5939
5940   /* Lose any fake structure return argument if it is passed on the stack.  */
5941   if (aggregate_value_p (TREE_TYPE (funtype), fundecl)
5942       && !ix86_keep_aggregate_return_pointer (funtype))
5943     {
5944       int nregs = ix86_function_regparm (funtype, fundecl);
5945       if (nregs == 0)
5946         return GET_MODE_SIZE (Pmode);
5947     }
5948
5949   return 0;
5950 }
5951
5952 /* Implement the TARGET_LEGITIMATE_COMBINED_INSN hook.  */
5953
5954 static bool
5955 ix86_legitimate_combined_insn (rtx_insn *insn)
5956 {
5957   /* Check operand constraints in case hard registers were propagated
5958      into insn pattern.  This check prevents combine pass from
5959      generating insn patterns with invalid hard register operands.
5960      These invalid insns can eventually confuse reload to error out
5961      with a spill failure.  See also PRs 46829 and 46843.  */
5962   if ((INSN_CODE (insn) = recog (PATTERN (insn), insn, 0)) >= 0)
5963     {
5964       int i;
5965
5966       extract_insn (insn);
5967       preprocess_constraints (insn);
5968
5969       int n_operands = recog_data.n_operands;
5970       int n_alternatives = recog_data.n_alternatives;
5971       for (i = 0; i < n_operands; i++)
5972         {
5973           rtx op = recog_data.operand[i];
5974           machine_mode mode = GET_MODE (op);
5975           const operand_alternative *op_alt;
5976           int offset = 0;
5977           bool win;
5978           int j;
5979
5980           /* For pre-AVX disallow unaligned loads/stores where the
5981              instructions don't support it.  */
5982           if (!TARGET_AVX
5983               && VECTOR_MODE_P (GET_MODE (op))
5984               && misaligned_operand (op, GET_MODE (op)))
5985             {
5986               int min_align = get_attr_ssememalign (insn);
5987               if (min_align == 0)
5988                 return false;
5989             }
5990
5991           /* A unary operator may be accepted by the predicate, but it
5992              is irrelevant for matching constraints.  */
5993           if (UNARY_P (op))
5994             op = XEXP (op, 0);
5995
5996           if (GET_CODE (op) == SUBREG)
5997             {
5998               if (REG_P (SUBREG_REG (op))
5999                   && REGNO (SUBREG_REG (op)) < FIRST_PSEUDO_REGISTER)
6000                 offset = subreg_regno_offset (REGNO (SUBREG_REG (op)),
6001                                               GET_MODE (SUBREG_REG (op)),
6002                                               SUBREG_BYTE (op),
6003                                               GET_MODE (op));
6004               op = SUBREG_REG (op);
6005             }
6006
6007           if (!(REG_P (op) && HARD_REGISTER_P (op)))
6008             continue;
6009
6010           op_alt = recog_op_alt;
6011
6012           /* Operand has no constraints, anything is OK.  */
6013           win = !n_alternatives;
6014
6015           alternative_mask preferred = get_preferred_alternatives (insn);
6016           for (j = 0; j < n_alternatives; j++, op_alt += n_operands)
6017             {
6018               if (!TEST_BIT (preferred, j))
6019                 continue;
6020               if (op_alt[i].anything_ok
6021                   || (op_alt[i].matches != -1
6022                       && operands_match_p
6023                           (recog_data.operand[i],
6024                            recog_data.operand[op_alt[i].matches]))
6025                   || reg_fits_class_p (op, op_alt[i].cl, offset, mode))
6026                 {
6027                   win = true;
6028                   break;
6029                 }
6030             }
6031
6032           if (!win)
6033             return false;
6034         }
6035     }
6036
6037   return true;
6038 }
6039 \f
6040 /* Implement the TARGET_ASAN_SHADOW_OFFSET hook.  */
6041
6042 static unsigned HOST_WIDE_INT
6043 ix86_asan_shadow_offset (void)
6044 {
6045   return TARGET_LP64 ? (TARGET_MACHO ? (HOST_WIDE_INT_1 << 44)
6046                                      : HOST_WIDE_INT_C (0x7fff8000))
6047                      : (HOST_WIDE_INT_1 << 29);
6048 }
6049 \f
6050 /* Argument support functions.  */
6051
6052 /* Return true when register may be used to pass function parameters.  */
6053 bool
6054 ix86_function_arg_regno_p (int regno)
6055 {
6056   int i;
6057   const int *parm_regs;
6058
6059   if (!TARGET_64BIT)
6060     {
6061       if (TARGET_MACHO)
6062         return (regno < REGPARM_MAX
6063                 || (TARGET_SSE && SSE_REGNO_P (regno) && !fixed_regs[regno]));
6064       else
6065         return (regno < REGPARM_MAX
6066                 || (TARGET_MMX && MMX_REGNO_P (regno)
6067                     && (regno < FIRST_MMX_REG + MMX_REGPARM_MAX))
6068                 || (TARGET_SSE && SSE_REGNO_P (regno)
6069                     && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX)));
6070     }
6071
6072   if (TARGET_SSE && SSE_REGNO_P (regno)
6073       && (regno < FIRST_SSE_REG + SSE_REGPARM_MAX))
6074     return true;
6075
6076   /* TODO: The function should depend on current function ABI but
6077      builtins.c would need updating then. Therefore we use the
6078      default ABI.  */
6079
6080   /* RAX is used as hidden argument to va_arg functions.  */
6081   if (ix86_abi == SYSV_ABI && regno == AX_REG)
6082     return true;
6083
6084   if (ix86_abi == MS_ABI)
6085     parm_regs = x86_64_ms_abi_int_parameter_registers;
6086   else
6087     parm_regs = x86_64_int_parameter_registers;
6088   for (i = 0; i < (ix86_abi == MS_ABI
6089                    ? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++)
6090     if (regno == parm_regs[i])
6091       return true;
6092   return false;
6093 }
6094
6095 /* Return if we do not know how to pass TYPE solely in registers.  */
6096
6097 static bool
6098 ix86_must_pass_in_stack (machine_mode mode, const_tree type)
6099 {
6100   if (must_pass_in_stack_var_size_or_pad (mode, type))
6101     return true;
6102
6103   /* For 32-bit, we want TImode aggregates to go on the stack.  But watch out!
6104      The layout_type routine is crafty and tries to trick us into passing
6105      currently unsupported vector types on the stack by using TImode.  */
6106   return (!TARGET_64BIT && mode == TImode
6107           && type && TREE_CODE (type) != VECTOR_TYPE);
6108 }
6109
6110 /* It returns the size, in bytes, of the area reserved for arguments passed
6111    in registers for the function represented by fndecl dependent to the used
6112    abi format.  */
6113 int
6114 ix86_reg_parm_stack_space (const_tree fndecl)
6115 {
6116   enum calling_abi call_abi = SYSV_ABI;
6117   if (fndecl != NULL_TREE && TREE_CODE (fndecl) == FUNCTION_DECL)
6118     call_abi = ix86_function_abi (fndecl);
6119   else
6120     call_abi = ix86_function_type_abi (fndecl);
6121   if (TARGET_64BIT && call_abi == MS_ABI)
6122     return 32;
6123   return 0;
6124 }
6125
6126 /* Returns value SYSV_ABI, MS_ABI dependent on fntype, specifying the
6127    call abi used.  */
6128 enum calling_abi
6129 ix86_function_type_abi (const_tree fntype)
6130 {
6131   if (fntype != NULL_TREE && TYPE_ATTRIBUTES (fntype) != NULL_TREE)
6132     {
6133       enum calling_abi abi = ix86_abi;
6134       if (abi == SYSV_ABI)
6135         {
6136           if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (fntype)))
6137             {
6138               if (TARGET_X32)
6139                 {
6140                   static bool warned = false;
6141                   if (!warned)
6142                     {
6143                       error ("X32 does not support ms_abi attribute");
6144                       warned = true;
6145                     }
6146                 }
6147               abi = MS_ABI;
6148             }
6149         }
6150       else if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (fntype)))
6151         abi = SYSV_ABI;
6152       return abi;
6153     }
6154   return ix86_abi;
6155 }
6156
6157 /* We add this as a workaround in order to use libc_has_function
6158    hook in i386.md.  */
6159 bool
6160 ix86_libc_has_function (enum function_class fn_class)
6161 {
6162   return targetm.libc_has_function (fn_class);
6163 }
6164
6165 static bool
6166 ix86_function_ms_hook_prologue (const_tree fn)
6167 {
6168   if (fn && lookup_attribute ("ms_hook_prologue", DECL_ATTRIBUTES (fn)))
6169     {
6170       if (decl_function_context (fn) != NULL_TREE)
6171         error_at (DECL_SOURCE_LOCATION (fn),
6172                   "ms_hook_prologue is not compatible with nested function");
6173       else
6174         return true;
6175     }
6176   return false;
6177 }
6178
6179 static enum calling_abi
6180 ix86_function_abi (const_tree fndecl)
6181 {
6182   if (! fndecl)
6183     return ix86_abi;
6184   return ix86_function_type_abi (TREE_TYPE (fndecl));
6185 }
6186
6187 /* Returns value SYSV_ABI, MS_ABI dependent on cfun, specifying the
6188    call abi used.  */
6189 enum calling_abi
6190 ix86_cfun_abi (void)
6191 {
6192   if (! cfun)
6193     return ix86_abi;
6194   return cfun->machine->call_abi;
6195 }
6196
6197 /* Write the extra assembler code needed to declare a function properly.  */
6198
6199 void
6200 ix86_asm_output_function_label (FILE *asm_out_file, const char *fname,
6201                                 tree decl)
6202 {
6203   bool is_ms_hook = ix86_function_ms_hook_prologue (decl);
6204
6205   if (is_ms_hook)
6206     {
6207       int i, filler_count = (TARGET_64BIT ? 32 : 16);
6208       unsigned int filler_cc = 0xcccccccc;
6209
6210       for (i = 0; i < filler_count; i += 4)
6211         fprintf (asm_out_file, ASM_LONG " %#x\n", filler_cc);
6212     }
6213
6214 #ifdef SUBTARGET_ASM_UNWIND_INIT
6215   SUBTARGET_ASM_UNWIND_INIT (asm_out_file);
6216 #endif
6217
6218   ASM_OUTPUT_LABEL (asm_out_file, fname);
6219
6220   /* Output magic byte marker, if hot-patch attribute is set.  */
6221   if (is_ms_hook)
6222     {
6223       if (TARGET_64BIT)
6224         {
6225           /* leaq [%rsp + 0], %rsp  */
6226           asm_fprintf (asm_out_file, ASM_BYTE
6227                        "0x48, 0x8d, 0xa4, 0x24, 0x00, 0x00, 0x00, 0x00\n");
6228         }
6229       else
6230         {
6231           /* movl.s %edi, %edi
6232              push   %ebp
6233              movl.s %esp, %ebp */
6234           asm_fprintf (asm_out_file, ASM_BYTE
6235                        "0x8b, 0xff, 0x55, 0x8b, 0xec\n");
6236         }
6237     }
6238 }
6239
6240 /* regclass.c  */
6241 extern void init_regs (void);
6242
6243 /* Implementation of call abi switching target hook. Specific to FNDECL
6244    the specific call register sets are set.  See also
6245    ix86_conditional_register_usage for more details.  */
6246 void
6247 ix86_call_abi_override (const_tree fndecl)
6248 {
6249   if (fndecl == NULL_TREE)
6250     cfun->machine->call_abi = ix86_abi;
6251   else
6252     cfun->machine->call_abi = ix86_function_type_abi (TREE_TYPE (fndecl));
6253 }
6254
6255 /* 64-bit MS and SYSV ABI have different set of call used registers.  Avoid
6256    expensive re-initialization of init_regs each time we switch function context
6257    since this is needed only during RTL expansion.  */
6258 static void
6259 ix86_maybe_switch_abi (void)
6260 {
6261   if (TARGET_64BIT &&
6262       call_used_regs[SI_REG] == (cfun->machine->call_abi == MS_ABI))
6263     reinit_regs ();
6264 }
6265
6266 /* Return 1 if pseudo register should be created and used to hold
6267    GOT address for PIC code.  */
6268 static bool
6269 ix86_use_pseudo_pic_reg (void)
6270 {
6271   if ((TARGET_64BIT
6272        && (ix86_cmodel == CM_SMALL_PIC
6273            || TARGET_PECOFF))
6274       || !flag_pic)
6275     return false;
6276   return true;
6277 }
6278
6279 /* Initialize large model PIC register.  */
6280
6281 static void
6282 ix86_init_large_pic_reg (unsigned int tmp_regno)
6283 {
6284   rtx_code_label *label;
6285   rtx tmp_reg;
6286
6287   gcc_assert (Pmode == DImode);
6288   label = gen_label_rtx ();
6289   emit_label (label);
6290   LABEL_PRESERVE_P (label) = 1;
6291   tmp_reg = gen_rtx_REG (Pmode, tmp_regno);
6292   gcc_assert (REGNO (pic_offset_table_rtx) != tmp_regno);
6293   emit_insn (gen_set_rip_rex64 (pic_offset_table_rtx,
6294                                 label));
6295   emit_insn (gen_set_got_offset_rex64 (tmp_reg, label));
6296   emit_insn (ix86_gen_add3 (pic_offset_table_rtx,
6297                             pic_offset_table_rtx, tmp_reg));
6298 }
6299
6300 /* Create and initialize PIC register if required.  */
6301 static void
6302 ix86_init_pic_reg (void)
6303 {
6304   edge entry_edge;
6305   rtx_insn *seq;
6306
6307   if (!ix86_use_pseudo_pic_reg ())
6308     return;
6309
6310   start_sequence ();
6311
6312   if (TARGET_64BIT)
6313     {
6314       if (ix86_cmodel == CM_LARGE_PIC)
6315         ix86_init_large_pic_reg (R11_REG);
6316       else
6317         emit_insn (gen_set_got_rex64 (pic_offset_table_rtx));
6318     }
6319   else
6320     {
6321       /*  If there is future mcount call in the function it is more profitable
6322           to emit SET_GOT into ABI defined REAL_PIC_OFFSET_TABLE_REGNUM.  */
6323       rtx reg = crtl->profile
6324                 ? gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM)
6325                 : pic_offset_table_rtx;
6326       rtx insn = emit_insn (gen_set_got (reg));
6327       RTX_FRAME_RELATED_P (insn) = 1;
6328       if (crtl->profile)
6329         emit_move_insn (pic_offset_table_rtx, reg);
6330       add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
6331     }
6332
6333   seq = get_insns ();
6334   end_sequence ();
6335
6336   entry_edge = single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun));
6337   insert_insn_on_edge (seq, entry_edge);
6338   commit_one_edge_insertion (entry_edge);
6339 }
6340
6341 /* Initialize a variable CUM of type CUMULATIVE_ARGS
6342    for a call to a function whose data type is FNTYPE.
6343    For a library call, FNTYPE is 0.  */
6344
6345 void
6346 init_cumulative_args (CUMULATIVE_ARGS *cum,  /* Argument info to initialize */
6347                       tree fntype,      /* tree ptr for function decl */
6348                       rtx libname,      /* SYMBOL_REF of library name or 0 */
6349                       tree fndecl,
6350                       int caller)
6351 {
6352   struct cgraph_local_info *i;
6353
6354   memset (cum, 0, sizeof (*cum));
6355
6356   if (fndecl)
6357     {
6358       i = cgraph_node::local_info (fndecl);
6359       cum->call_abi = ix86_function_abi (fndecl);
6360     }
6361   else
6362     {
6363       i = NULL;
6364       cum->call_abi = ix86_function_type_abi (fntype);
6365     }
6366
6367   cum->caller = caller;
6368
6369   /* Set up the number of registers to use for passing arguments.  */
6370   cum->nregs = ix86_regparm;
6371   if (TARGET_64BIT)
6372     {
6373       cum->nregs = (cum->call_abi == SYSV_ABI
6374                    ? X86_64_REGPARM_MAX
6375                    : X86_64_MS_REGPARM_MAX);
6376     }
6377   if (TARGET_SSE)
6378     {
6379       cum->sse_nregs = SSE_REGPARM_MAX;
6380       if (TARGET_64BIT)
6381         {
6382           cum->sse_nregs = (cum->call_abi == SYSV_ABI
6383                            ? X86_64_SSE_REGPARM_MAX
6384                            : X86_64_MS_SSE_REGPARM_MAX);
6385         }
6386     }
6387   if (TARGET_MMX)
6388     cum->mmx_nregs = MMX_REGPARM_MAX;
6389   cum->warn_avx512f = true;
6390   cum->warn_avx = true;
6391   cum->warn_sse = true;
6392   cum->warn_mmx = true;
6393
6394   /* Because type might mismatch in between caller and callee, we need to
6395      use actual type of function for local calls.
6396      FIXME: cgraph_analyze can be told to actually record if function uses
6397      va_start so for local functions maybe_vaarg can be made aggressive
6398      helping K&R code.
6399      FIXME: once typesytem is fixed, we won't need this code anymore.  */
6400   if (i && i->local && i->can_change_signature)
6401     fntype = TREE_TYPE (fndecl);
6402   cum->stdarg = stdarg_p (fntype);
6403   cum->maybe_vaarg = (fntype
6404                       ? (!prototype_p (fntype) || stdarg_p (fntype))
6405                       : !libname);
6406
6407   cum->bnd_regno = FIRST_BND_REG;
6408   cum->bnds_in_bt = 0;
6409   cum->force_bnd_pass = 0;
6410
6411   if (!TARGET_64BIT)
6412     {
6413       /* If there are variable arguments, then we won't pass anything
6414          in registers in 32-bit mode. */
6415       if (stdarg_p (fntype))
6416         {
6417           cum->nregs = 0;
6418           cum->sse_nregs = 0;
6419           cum->mmx_nregs = 0;
6420           cum->warn_avx512f = false;
6421           cum->warn_avx = false;
6422           cum->warn_sse = false;
6423           cum->warn_mmx = false;
6424           return;
6425         }
6426
6427       /* Use ecx and edx registers if function has fastcall attribute,
6428          else look for regparm information.  */
6429       if (fntype)
6430         {
6431           unsigned int ccvt = ix86_get_callcvt (fntype);
6432           if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
6433             {
6434               cum->nregs = 1;
6435               cum->fastcall = 1; /* Same first register as in fastcall.  */
6436             }
6437           else if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
6438             {
6439               cum->nregs = 2;
6440               cum->fastcall = 1;
6441             }
6442           else
6443             cum->nregs = ix86_function_regparm (fntype, fndecl);
6444         }
6445
6446       /* Set up the number of SSE registers used for passing SFmode
6447          and DFmode arguments.  Warn for mismatching ABI.  */
6448       cum->float_in_sse = ix86_function_sseregparm (fntype, fndecl, true);
6449     }
6450 }
6451
6452 /* Return the "natural" mode for TYPE.  In most cases, this is just TYPE_MODE.
6453    But in the case of vector types, it is some vector mode.
6454
6455    When we have only some of our vector isa extensions enabled, then there
6456    are some modes for which vector_mode_supported_p is false.  For these
6457    modes, the generic vector support in gcc will choose some non-vector mode
6458    in order to implement the type.  By computing the natural mode, we'll
6459    select the proper ABI location for the operand and not depend on whatever
6460    the middle-end decides to do with these vector types.
6461
6462    The midde-end can't deal with the vector types > 16 bytes.  In this
6463    case, we return the original mode and warn ABI change if CUM isn't
6464    NULL. 
6465
6466    If INT_RETURN is true, warn ABI change if the vector mode isn't
6467    available for function return value.  */
6468
6469 static machine_mode
6470 type_natural_mode (const_tree type, const CUMULATIVE_ARGS *cum,
6471                    bool in_return)
6472 {
6473   machine_mode mode = TYPE_MODE (type);
6474
6475   if (TREE_CODE (type) == VECTOR_TYPE && !VECTOR_MODE_P (mode))
6476     {
6477       HOST_WIDE_INT size = int_size_in_bytes (type);
6478       if ((size == 8 || size == 16 || size == 32 || size == 64)
6479           /* ??? Generic code allows us to create width 1 vectors.  Ignore.  */
6480           && TYPE_VECTOR_SUBPARTS (type) > 1)
6481         {
6482           machine_mode innermode = TYPE_MODE (TREE_TYPE (type));
6483
6484           if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
6485             mode = MIN_MODE_VECTOR_FLOAT;
6486           else
6487             mode = MIN_MODE_VECTOR_INT;
6488
6489           /* Get the mode which has this inner mode and number of units.  */
6490           for (; mode != VOIDmode; mode = GET_MODE_WIDER_MODE (mode))
6491             if (GET_MODE_NUNITS (mode) == TYPE_VECTOR_SUBPARTS (type)
6492                 && GET_MODE_INNER (mode) == innermode)
6493               {
6494                 if (size == 64 && !TARGET_AVX512F)
6495                   {
6496                     static bool warnedavx512f;
6497                     static bool warnedavx512f_ret;
6498
6499                     if (cum && cum->warn_avx512f && !warnedavx512f)
6500                       {
6501                         if (warning (OPT_Wpsabi, "AVX512F vector argument "
6502                                      "without AVX512F enabled changes the ABI"))
6503                           warnedavx512f = true;
6504                       }
6505                     else if (in_return && !warnedavx512f_ret)
6506                       {
6507                         if (warning (OPT_Wpsabi, "AVX512F vector return "
6508                                      "without AVX512F enabled changes the ABI"))
6509                           warnedavx512f_ret = true;
6510                       }
6511
6512                     return TYPE_MODE (type);
6513                   }
6514                 else if (size == 32 && !TARGET_AVX)
6515                   {
6516                     static bool warnedavx;
6517                     static bool warnedavx_ret;
6518
6519                     if (cum && cum->warn_avx && !warnedavx)
6520                       {
6521                         if (warning (OPT_Wpsabi, "AVX vector argument "
6522                                      "without AVX enabled changes the ABI"))
6523                           warnedavx = true;
6524                       }
6525                     else if (in_return && !warnedavx_ret)
6526                       {
6527                         if (warning (OPT_Wpsabi, "AVX vector return "
6528                                      "without AVX enabled changes the ABI"))
6529                           warnedavx_ret = true;
6530                       }
6531
6532                     return TYPE_MODE (type);
6533                   }
6534                 else if (((size == 8 && TARGET_64BIT) || size == 16)
6535                          && !TARGET_SSE)
6536                   {
6537                     static bool warnedsse;
6538                     static bool warnedsse_ret;
6539
6540                     if (cum && cum->warn_sse && !warnedsse)
6541                       {
6542                         if (warning (OPT_Wpsabi, "SSE vector argument "
6543                                      "without SSE enabled changes the ABI"))
6544                           warnedsse = true;
6545                       }
6546                     else if (!TARGET_64BIT && in_return && !warnedsse_ret)
6547                       {
6548                         if (warning (OPT_Wpsabi, "SSE vector return "
6549                                      "without SSE enabled changes the ABI"))
6550                           warnedsse_ret = true;
6551                       }
6552                   }
6553                 else if ((size == 8 && !TARGET_64BIT) && !TARGET_MMX)
6554                   {
6555                     static bool warnedmmx;
6556                     static bool warnedmmx_ret;
6557
6558                     if (cum && cum->warn_mmx && !warnedmmx)
6559                       {
6560                         if (warning (OPT_Wpsabi, "MMX vector argument "
6561                                      "without MMX enabled changes the ABI"))
6562                           warnedmmx = true;
6563                       }
6564                     else if (in_return && !warnedmmx_ret)
6565                       {
6566                         if (warning (OPT_Wpsabi, "MMX vector return "
6567                                      "without MMX enabled changes the ABI"))
6568                           warnedmmx_ret = true;
6569                       }
6570                   }
6571                 return mode;
6572               }
6573
6574           gcc_unreachable ();
6575         }
6576     }
6577
6578   return mode;
6579 }
6580
6581 /* We want to pass a value in REGNO whose "natural" mode is MODE.  However,
6582    this may not agree with the mode that the type system has chosen for the
6583    register, which is ORIG_MODE.  If ORIG_MODE is not BLKmode, then we can
6584    go ahead and use it.  Otherwise we have to build a PARALLEL instead.  */
6585
6586 static rtx
6587 gen_reg_or_parallel (machine_mode mode, machine_mode orig_mode,
6588                      unsigned int regno)
6589 {
6590   rtx tmp;
6591
6592   if (orig_mode != BLKmode)
6593     tmp = gen_rtx_REG (orig_mode, regno);
6594   else
6595     {
6596       tmp = gen_rtx_REG (mode, regno);
6597       tmp = gen_rtx_EXPR_LIST (VOIDmode, tmp, const0_rtx);
6598       tmp = gen_rtx_PARALLEL (orig_mode, gen_rtvec (1, tmp));
6599     }
6600
6601   return tmp;
6602 }
6603
6604 /* x86-64 register passing implementation.  See x86-64 ABI for details.  Goal
6605    of this code is to classify each 8bytes of incoming argument by the register
6606    class and assign registers accordingly.  */
6607
6608 /* Return the union class of CLASS1 and CLASS2.
6609    See the x86-64 PS ABI for details.  */
6610
6611 static enum x86_64_reg_class
6612 merge_classes (enum x86_64_reg_class class1, enum x86_64_reg_class class2)
6613 {
6614   /* Rule #1: If both classes are equal, this is the resulting class.  */
6615   if (class1 == class2)
6616     return class1;
6617
6618   /* Rule #2: If one of the classes is NO_CLASS, the resulting class is
6619      the other class.  */
6620   if (class1 == X86_64_NO_CLASS)
6621     return class2;
6622   if (class2 == X86_64_NO_CLASS)
6623     return class1;
6624
6625   /* Rule #3: If one of the classes is MEMORY, the result is MEMORY.  */
6626   if (class1 == X86_64_MEMORY_CLASS || class2 == X86_64_MEMORY_CLASS)
6627     return X86_64_MEMORY_CLASS;
6628
6629   /* Rule #4: If one of the classes is INTEGER, the result is INTEGER.  */
6630   if ((class1 == X86_64_INTEGERSI_CLASS && class2 == X86_64_SSESF_CLASS)
6631       || (class2 == X86_64_INTEGERSI_CLASS && class1 == X86_64_SSESF_CLASS))
6632     return X86_64_INTEGERSI_CLASS;
6633   if (class1 == X86_64_INTEGER_CLASS || class1 == X86_64_INTEGERSI_CLASS
6634       || class2 == X86_64_INTEGER_CLASS || class2 == X86_64_INTEGERSI_CLASS)
6635     return X86_64_INTEGER_CLASS;
6636
6637   /* Rule #5: If one of the classes is X87, X87UP, or COMPLEX_X87 class,
6638      MEMORY is used.  */
6639   if (class1 == X86_64_X87_CLASS
6640       || class1 == X86_64_X87UP_CLASS
6641       || class1 == X86_64_COMPLEX_X87_CLASS
6642       || class2 == X86_64_X87_CLASS
6643       || class2 == X86_64_X87UP_CLASS
6644       || class2 == X86_64_COMPLEX_X87_CLASS)
6645     return X86_64_MEMORY_CLASS;
6646
6647   /* Rule #6: Otherwise class SSE is used.  */
6648   return X86_64_SSE_CLASS;
6649 }
6650
6651 /* Classify the argument of type TYPE and mode MODE.
6652    CLASSES will be filled by the register class used to pass each word
6653    of the operand.  The number of words is returned.  In case the parameter
6654    should be passed in memory, 0 is returned. As a special case for zero
6655    sized containers, classes[0] will be NO_CLASS and 1 is returned.
6656
6657    BIT_OFFSET is used internally for handling records and specifies offset
6658    of the offset in bits modulo 512 to avoid overflow cases.
6659
6660    See the x86-64 PS ABI for details.
6661 */
6662
6663 static int
6664 classify_argument (machine_mode mode, const_tree type,
6665                    enum x86_64_reg_class classes[MAX_CLASSES], int bit_offset)
6666 {
6667   HOST_WIDE_INT bytes =
6668     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
6669   int words
6670     = (bytes + (bit_offset % 64) / 8 + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
6671
6672   /* Variable sized entities are always passed/returned in memory.  */
6673   if (bytes < 0)
6674     return 0;
6675
6676   if (mode != VOIDmode
6677       && targetm.calls.must_pass_in_stack (mode, type))
6678     return 0;
6679
6680   if (type && AGGREGATE_TYPE_P (type))
6681     {
6682       int i;
6683       tree field;
6684       enum x86_64_reg_class subclasses[MAX_CLASSES];
6685
6686       /* On x86-64 we pass structures larger than 64 bytes on the stack.  */
6687       if (bytes > 64)
6688         return 0;
6689
6690       for (i = 0; i < words; i++)
6691         classes[i] = X86_64_NO_CLASS;
6692
6693       /* Zero sized arrays or structures are NO_CLASS.  We return 0 to
6694          signalize memory class, so handle it as special case.  */
6695       if (!words)
6696         {
6697           classes[0] = X86_64_NO_CLASS;
6698           return 1;
6699         }
6700
6701       /* Classify each field of record and merge classes.  */
6702       switch (TREE_CODE (type))
6703         {
6704         case RECORD_TYPE:
6705           /* And now merge the fields of structure.  */
6706           for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6707             {
6708               if (TREE_CODE (field) == FIELD_DECL)
6709                 {
6710                   int num;
6711
6712                   if (TREE_TYPE (field) == error_mark_node)
6713                     continue;
6714
6715                   /* Bitfields are always classified as integer.  Handle them
6716                      early, since later code would consider them to be
6717                      misaligned integers.  */
6718                   if (DECL_BIT_FIELD (field))
6719                     {
6720                       for (i = (int_bit_position (field)
6721                                 + (bit_offset % 64)) / 8 / 8;
6722                            i < ((int_bit_position (field) + (bit_offset % 64))
6723                                 + tree_to_shwi (DECL_SIZE (field))
6724                                 + 63) / 8 / 8; i++)
6725                         classes[i] =
6726                           merge_classes (X86_64_INTEGER_CLASS,
6727                                          classes[i]);
6728                     }
6729                   else
6730                     {
6731                       int pos;
6732
6733                       type = TREE_TYPE (field);
6734
6735                       /* Flexible array member is ignored.  */
6736                       if (TYPE_MODE (type) == BLKmode
6737                           && TREE_CODE (type) == ARRAY_TYPE
6738                           && TYPE_SIZE (type) == NULL_TREE
6739                           && TYPE_DOMAIN (type) != NULL_TREE
6740                           && (TYPE_MAX_VALUE (TYPE_DOMAIN (type))
6741                               == NULL_TREE))
6742                         {
6743                           static bool warned;
6744
6745                           if (!warned && warn_psabi)
6746                             {
6747                               warned = true;
6748                               inform (input_location,
6749                                       "the ABI of passing struct with"
6750                                       " a flexible array member has"
6751                                       " changed in GCC 4.4");
6752                             }
6753                           continue;
6754                         }
6755                       num = classify_argument (TYPE_MODE (type), type,
6756                                                subclasses,
6757                                                (int_bit_position (field)
6758                                                 + bit_offset) % 512);
6759                       if (!num)
6760                         return 0;
6761                       pos = (int_bit_position (field)
6762                              + (bit_offset % 64)) / 8 / 8;
6763                       for (i = 0; i < num && (i + pos) < words; i++)
6764                         classes[i + pos] =
6765                           merge_classes (subclasses[i], classes[i + pos]);
6766                     }
6767                 }
6768             }
6769           break;
6770
6771         case ARRAY_TYPE:
6772           /* Arrays are handled as small records.  */
6773           {
6774             int num;
6775             num = classify_argument (TYPE_MODE (TREE_TYPE (type)),
6776                                      TREE_TYPE (type), subclasses, bit_offset);
6777             if (!num)
6778               return 0;
6779
6780             /* The partial classes are now full classes.  */
6781             if (subclasses[0] == X86_64_SSESF_CLASS && bytes != 4)
6782               subclasses[0] = X86_64_SSE_CLASS;
6783             if (subclasses[0] == X86_64_INTEGERSI_CLASS
6784                 && !((bit_offset % 64) == 0 && bytes == 4))
6785               subclasses[0] = X86_64_INTEGER_CLASS;
6786
6787             for (i = 0; i < words; i++)
6788               classes[i] = subclasses[i % num];
6789
6790             break;
6791           }
6792         case UNION_TYPE:
6793         case QUAL_UNION_TYPE:
6794           /* Unions are similar to RECORD_TYPE but offset is always 0.
6795              */
6796           for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
6797             {
6798               if (TREE_CODE (field) == FIELD_DECL)
6799                 {
6800                   int num;
6801
6802                   if (TREE_TYPE (field) == error_mark_node)
6803                     continue;
6804
6805                   num = classify_argument (TYPE_MODE (TREE_TYPE (field)),
6806                                            TREE_TYPE (field), subclasses,
6807                                            bit_offset);
6808                   if (!num)
6809                     return 0;
6810                   for (i = 0; i < num && i < words; i++)
6811                     classes[i] = merge_classes (subclasses[i], classes[i]);
6812                 }
6813             }
6814           break;
6815
6816         default:
6817           gcc_unreachable ();
6818         }
6819
6820       if (words > 2)
6821         {
6822           /* When size > 16 bytes, if the first one isn't
6823              X86_64_SSE_CLASS or any other ones aren't
6824              X86_64_SSEUP_CLASS, everything should be passed in
6825              memory.  */
6826           if (classes[0] != X86_64_SSE_CLASS)
6827               return 0;
6828
6829           for (i = 1; i < words; i++)
6830             if (classes[i] != X86_64_SSEUP_CLASS)
6831               return 0;
6832         }
6833
6834       /* Final merger cleanup.  */
6835       for (i = 0; i < words; i++)
6836         {
6837           /* If one class is MEMORY, everything should be passed in
6838              memory.  */
6839           if (classes[i] == X86_64_MEMORY_CLASS)
6840             return 0;
6841
6842           /* The X86_64_SSEUP_CLASS should be always preceded by
6843              X86_64_SSE_CLASS or X86_64_SSEUP_CLASS.  */
6844           if (classes[i] == X86_64_SSEUP_CLASS
6845               && classes[i - 1] != X86_64_SSE_CLASS
6846               && classes[i - 1] != X86_64_SSEUP_CLASS)
6847             {
6848               /* The first one should never be X86_64_SSEUP_CLASS.  */
6849               gcc_assert (i != 0);
6850               classes[i] = X86_64_SSE_CLASS;
6851             }
6852
6853           /*  If X86_64_X87UP_CLASS isn't preceded by X86_64_X87_CLASS,
6854                everything should be passed in memory.  */
6855           if (classes[i] == X86_64_X87UP_CLASS
6856               && (classes[i - 1] != X86_64_X87_CLASS))
6857             {
6858               static bool warned;
6859
6860               /* The first one should never be X86_64_X87UP_CLASS.  */
6861               gcc_assert (i != 0);
6862               if (!warned && warn_psabi)
6863                 {
6864                   warned = true;
6865                   inform (input_location,
6866                           "the ABI of passing union with long double"
6867                           " has changed in GCC 4.4");
6868                 }
6869               return 0;
6870             }
6871         }
6872       return words;
6873     }
6874
6875   /* Compute alignment needed.  We align all types to natural boundaries with
6876      exception of XFmode that is aligned to 64bits.  */
6877   if (mode != VOIDmode && mode != BLKmode)
6878     {
6879       int mode_alignment = GET_MODE_BITSIZE (mode);
6880
6881       if (mode == XFmode)
6882         mode_alignment = 128;
6883       else if (mode == XCmode)
6884         mode_alignment = 256;
6885       if (COMPLEX_MODE_P (mode))
6886         mode_alignment /= 2;
6887       /* Misaligned fields are always returned in memory.  */
6888       if (bit_offset % mode_alignment)
6889         return 0;
6890     }
6891
6892   /* for V1xx modes, just use the base mode */
6893   if (VECTOR_MODE_P (mode) && mode != V1DImode && mode != V1TImode
6894       && GET_MODE_SIZE (GET_MODE_INNER (mode)) == bytes)
6895     mode = GET_MODE_INNER (mode);
6896
6897   /* Classification of atomic types.  */
6898   switch (mode)
6899     {
6900     case SDmode:
6901     case DDmode:
6902       classes[0] = X86_64_SSE_CLASS;
6903       return 1;
6904     case TDmode:
6905       classes[0] = X86_64_SSE_CLASS;
6906       classes[1] = X86_64_SSEUP_CLASS;
6907       return 2;
6908     case DImode:
6909     case SImode:
6910     case HImode:
6911     case QImode:
6912     case CSImode:
6913     case CHImode:
6914     case CQImode:
6915       {
6916         int size = bit_offset + (int) GET_MODE_BITSIZE (mode);
6917
6918         /* Analyze last 128 bits only.  */
6919         size = (size - 1) & 0x7f;
6920
6921         if (size < 32)
6922           {
6923             classes[0] = X86_64_INTEGERSI_CLASS;
6924             return 1;
6925           }
6926         else if (size < 64)
6927           {
6928             classes[0] = X86_64_INTEGER_CLASS;
6929             return 1;
6930           }
6931         else if (size < 64+32)
6932           {
6933             classes[0] = X86_64_INTEGER_CLASS;
6934             classes[1] = X86_64_INTEGERSI_CLASS;
6935             return 2;
6936           }
6937         else if (size < 64+64)
6938           {
6939             classes[0] = classes[1] = X86_64_INTEGER_CLASS;
6940             return 2;
6941           }
6942         else
6943           gcc_unreachable ();
6944       }
6945     case CDImode:
6946     case TImode:
6947       classes[0] = classes[1] = X86_64_INTEGER_CLASS;
6948       return 2;
6949     case COImode:
6950     case OImode:
6951       /* OImode shouldn't be used directly.  */
6952       gcc_unreachable ();
6953     case CTImode:
6954       return 0;
6955     case SFmode:
6956       if (!(bit_offset % 64))
6957         classes[0] = X86_64_SSESF_CLASS;
6958       else
6959         classes[0] = X86_64_SSE_CLASS;
6960       return 1;
6961     case DFmode:
6962       classes[0] = X86_64_SSEDF_CLASS;
6963       return 1;
6964     case XFmode:
6965       classes[0] = X86_64_X87_CLASS;
6966       classes[1] = X86_64_X87UP_CLASS;
6967       return 2;
6968     case TFmode:
6969       classes[0] = X86_64_SSE_CLASS;
6970       classes[1] = X86_64_SSEUP_CLASS;
6971       return 2;
6972     case SCmode:
6973       classes[0] = X86_64_SSE_CLASS;
6974       if (!(bit_offset % 64))
6975         return 1;
6976       else
6977         {
6978           static bool warned;
6979
6980           if (!warned && warn_psabi)
6981             {
6982               warned = true;
6983               inform (input_location,
6984                       "the ABI of passing structure with complex float"
6985                       " member has changed in GCC 4.4");
6986             }
6987           classes[1] = X86_64_SSESF_CLASS;
6988           return 2;
6989         }
6990     case DCmode:
6991       classes[0] = X86_64_SSEDF_CLASS;
6992       classes[1] = X86_64_SSEDF_CLASS;
6993       return 2;
6994     case XCmode:
6995       classes[0] = X86_64_COMPLEX_X87_CLASS;
6996       return 1;
6997     case TCmode:
6998       /* This modes is larger than 16 bytes.  */
6999       return 0;
7000     case V8SFmode:
7001     case V8SImode:
7002     case V32QImode:
7003     case V16HImode:
7004     case V4DFmode:
7005     case V4DImode:
7006       classes[0] = X86_64_SSE_CLASS;
7007       classes[1] = X86_64_SSEUP_CLASS;
7008       classes[2] = X86_64_SSEUP_CLASS;
7009       classes[3] = X86_64_SSEUP_CLASS;
7010       return 4;
7011     case V8DFmode:
7012     case V16SFmode:
7013     case V8DImode:
7014     case V16SImode:
7015     case V32HImode:
7016     case V64QImode:
7017       classes[0] = X86_64_SSE_CLASS;
7018       classes[1] = X86_64_SSEUP_CLASS;
7019       classes[2] = X86_64_SSEUP_CLASS;
7020       classes[3] = X86_64_SSEUP_CLASS;
7021       classes[4] = X86_64_SSEUP_CLASS;
7022       classes[5] = X86_64_SSEUP_CLASS;
7023       classes[6] = X86_64_SSEUP_CLASS;
7024       classes[7] = X86_64_SSEUP_CLASS;
7025       return 8;
7026     case V4SFmode:
7027     case V4SImode:
7028     case V16QImode:
7029     case V8HImode:
7030     case V2DFmode:
7031     case V2DImode:
7032       classes[0] = X86_64_SSE_CLASS;
7033       classes[1] = X86_64_SSEUP_CLASS;
7034       return 2;
7035     case V1TImode:
7036     case V1DImode:
7037     case V2SFmode:
7038     case V2SImode:
7039     case V4HImode:
7040     case V8QImode:
7041       classes[0] = X86_64_SSE_CLASS;
7042       return 1;
7043     case BLKmode:
7044     case VOIDmode:
7045       return 0;
7046     default:
7047       gcc_assert (VECTOR_MODE_P (mode));
7048
7049       if (bytes > 16)
7050         return 0;
7051
7052       gcc_assert (GET_MODE_CLASS (GET_MODE_INNER (mode)) == MODE_INT);
7053
7054       if (bit_offset + GET_MODE_BITSIZE (mode) <= 32)
7055         classes[0] = X86_64_INTEGERSI_CLASS;
7056       else
7057         classes[0] = X86_64_INTEGER_CLASS;
7058       classes[1] = X86_64_INTEGER_CLASS;
7059       return 1 + (bytes > 8);
7060     }
7061 }
7062
7063 /* Examine the argument and return set number of register required in each
7064    class.  Return true iff parameter should be passed in memory.  */
7065
7066 static bool
7067 examine_argument (machine_mode mode, const_tree type, int in_return,
7068                   int *int_nregs, int *sse_nregs)
7069 {
7070   enum x86_64_reg_class regclass[MAX_CLASSES];
7071   int n = classify_argument (mode, type, regclass, 0);
7072
7073   *int_nregs = 0;
7074   *sse_nregs = 0;
7075
7076   if (!n)
7077     return true;
7078   for (n--; n >= 0; n--)
7079     switch (regclass[n])
7080       {
7081       case X86_64_INTEGER_CLASS:
7082       case X86_64_INTEGERSI_CLASS:
7083         (*int_nregs)++;
7084         break;
7085       case X86_64_SSE_CLASS:
7086       case X86_64_SSESF_CLASS:
7087       case X86_64_SSEDF_CLASS:
7088         (*sse_nregs)++;
7089         break;
7090       case X86_64_NO_CLASS:
7091       case X86_64_SSEUP_CLASS:
7092         break;
7093       case X86_64_X87_CLASS:
7094       case X86_64_X87UP_CLASS:
7095       case X86_64_COMPLEX_X87_CLASS:
7096         if (!in_return)
7097           return true;
7098         break;
7099       case X86_64_MEMORY_CLASS:
7100         gcc_unreachable ();
7101       }
7102
7103   return false;
7104 }
7105
7106 /* Construct container for the argument used by GCC interface.  See
7107    FUNCTION_ARG for the detailed description.  */
7108
7109 static rtx
7110 construct_container (machine_mode mode, machine_mode orig_mode,
7111                      const_tree type, int in_return, int nintregs, int nsseregs,
7112                      const int *intreg, int sse_regno)
7113 {
7114   /* The following variables hold the static issued_error state.  */
7115   static bool issued_sse_arg_error;
7116   static bool issued_sse_ret_error;
7117   static bool issued_x87_ret_error;
7118
7119   machine_mode tmpmode;
7120   int bytes =
7121     (mode == BLKmode) ? int_size_in_bytes (type) : (int) GET_MODE_SIZE (mode);
7122   enum x86_64_reg_class regclass[MAX_CLASSES];
7123   int n;
7124   int i;
7125   int nexps = 0;
7126   int needed_sseregs, needed_intregs;
7127   rtx exp[MAX_CLASSES];
7128   rtx ret;
7129
7130   n = classify_argument (mode, type, regclass, 0);
7131   if (!n)
7132     return NULL;
7133   if (examine_argument (mode, type, in_return, &needed_intregs,
7134                         &needed_sseregs))
7135     return NULL;
7136   if (needed_intregs > nintregs || needed_sseregs > nsseregs)
7137     return NULL;
7138
7139   /* We allowed the user to turn off SSE for kernel mode.  Don't crash if
7140      some less clueful developer tries to use floating-point anyway.  */
7141   if (needed_sseregs && !TARGET_SSE)
7142     {
7143       if (in_return)
7144         {
7145           if (!issued_sse_ret_error)
7146             {
7147               error ("SSE register return with SSE disabled");
7148               issued_sse_ret_error = true;
7149             }
7150         }
7151       else if (!issued_sse_arg_error)
7152         {
7153           error ("SSE register argument with SSE disabled");
7154           issued_sse_arg_error = true;
7155         }
7156       return NULL;
7157     }
7158
7159   /* Likewise, error if the ABI requires us to return values in the
7160      x87 registers and the user specified -mno-80387.  */
7161   if (!TARGET_FLOAT_RETURNS_IN_80387 && in_return)
7162     for (i = 0; i < n; i++)
7163       if (regclass[i] == X86_64_X87_CLASS
7164           || regclass[i] == X86_64_X87UP_CLASS
7165           || regclass[i] == X86_64_COMPLEX_X87_CLASS)
7166         {
7167           if (!issued_x87_ret_error)
7168             {
7169               error ("x87 register return with x87 disabled");
7170               issued_x87_ret_error = true;
7171             }
7172           return NULL;
7173         }
7174
7175   /* First construct simple cases.  Avoid SCmode, since we want to use
7176      single register to pass this type.  */
7177   if (n == 1 && mode != SCmode)
7178     switch (regclass[0])
7179       {
7180       case X86_64_INTEGER_CLASS:
7181       case X86_64_INTEGERSI_CLASS:
7182         return gen_rtx_REG (mode, intreg[0]);
7183       case X86_64_SSE_CLASS:
7184       case X86_64_SSESF_CLASS:
7185       case X86_64_SSEDF_CLASS:
7186         if (mode != BLKmode)
7187           return gen_reg_or_parallel (mode, orig_mode,
7188                                       SSE_REGNO (sse_regno));
7189         break;
7190       case X86_64_X87_CLASS:
7191       case X86_64_COMPLEX_X87_CLASS:
7192         return gen_rtx_REG (mode, FIRST_STACK_REG);
7193       case X86_64_NO_CLASS:
7194         /* Zero sized array, struct or class.  */
7195         return NULL;
7196       default:
7197         gcc_unreachable ();
7198       }
7199   if (n == 2
7200       && regclass[0] == X86_64_SSE_CLASS
7201       && regclass[1] == X86_64_SSEUP_CLASS
7202       && mode != BLKmode)
7203     return gen_reg_or_parallel (mode, orig_mode,
7204                                 SSE_REGNO (sse_regno));
7205   if (n == 4
7206       && regclass[0] == X86_64_SSE_CLASS
7207       && regclass[1] == X86_64_SSEUP_CLASS
7208       && regclass[2] == X86_64_SSEUP_CLASS
7209       && regclass[3] == X86_64_SSEUP_CLASS
7210       && mode != BLKmode)
7211     return gen_reg_or_parallel (mode, orig_mode,
7212                                 SSE_REGNO (sse_regno));
7213   if (n == 8
7214       && regclass[0] == X86_64_SSE_CLASS
7215       && regclass[1] == X86_64_SSEUP_CLASS
7216       && regclass[2] == X86_64_SSEUP_CLASS
7217       && regclass[3] == X86_64_SSEUP_CLASS
7218       && regclass[4] == X86_64_SSEUP_CLASS
7219       && regclass[5] == X86_64_SSEUP_CLASS
7220       && regclass[6] == X86_64_SSEUP_CLASS
7221       && regclass[7] == X86_64_SSEUP_CLASS
7222       && mode != BLKmode)
7223     return gen_reg_or_parallel (mode, orig_mode,
7224                                 SSE_REGNO (sse_regno));
7225   if (n == 2
7226       && regclass[0] == X86_64_X87_CLASS
7227       && regclass[1] == X86_64_X87UP_CLASS)
7228     return gen_rtx_REG (XFmode, FIRST_STACK_REG);
7229
7230   if (n == 2
7231       && regclass[0] == X86_64_INTEGER_CLASS
7232       && regclass[1] == X86_64_INTEGER_CLASS
7233       && (mode == CDImode || mode == TImode)
7234       && intreg[0] + 1 == intreg[1])
7235     return gen_rtx_REG (mode, intreg[0]);
7236
7237   /* Otherwise figure out the entries of the PARALLEL.  */
7238   for (i = 0; i < n; i++)
7239     {
7240       int pos;
7241
7242       switch (regclass[i])
7243         {
7244           case X86_64_NO_CLASS:
7245             break;
7246           case X86_64_INTEGER_CLASS:
7247           case X86_64_INTEGERSI_CLASS:
7248             /* Merge TImodes on aligned occasions here too.  */
7249             if (i * 8 + 8 > bytes)
7250               tmpmode
7251                 = mode_for_size ((bytes - i * 8) * BITS_PER_UNIT, MODE_INT, 0);
7252             else if (regclass[i] == X86_64_INTEGERSI_CLASS)
7253               tmpmode = SImode;
7254             else
7255               tmpmode = DImode;
7256             /* We've requested 24 bytes we
7257                don't have mode for.  Use DImode.  */
7258             if (tmpmode == BLKmode)
7259               tmpmode = DImode;
7260             exp [nexps++]
7261               = gen_rtx_EXPR_LIST (VOIDmode,
7262                                    gen_rtx_REG (tmpmode, *intreg),
7263                                    GEN_INT (i*8));
7264             intreg++;
7265             break;
7266           case X86_64_SSESF_CLASS:
7267             exp [nexps++]
7268               = gen_rtx_EXPR_LIST (VOIDmode,
7269                                    gen_rtx_REG (SFmode,
7270                                                 SSE_REGNO (sse_regno)),
7271                                    GEN_INT (i*8));
7272             sse_regno++;
7273             break;
7274           case X86_64_SSEDF_CLASS:
7275             exp [nexps++]
7276               = gen_rtx_EXPR_LIST (VOIDmode,
7277                                    gen_rtx_REG (DFmode,
7278                                                 SSE_REGNO (sse_regno)),
7279                                    GEN_INT (i*8));
7280             sse_regno++;
7281             break;
7282           case X86_64_SSE_CLASS:
7283             pos = i;
7284             switch (n)
7285               {
7286               case 1:
7287                 tmpmode = DImode;
7288                 break;
7289               case 2:
7290                 if (i == 0 && regclass[1] == X86_64_SSEUP_CLASS)
7291                   {
7292                     tmpmode = TImode;
7293                     i++;
7294                   }
7295                 else
7296                   tmpmode = DImode;
7297                 break;
7298               case 4:
7299                 gcc_assert (i == 0
7300                             && regclass[1] == X86_64_SSEUP_CLASS
7301                             && regclass[2] == X86_64_SSEUP_CLASS
7302                             && regclass[3] == X86_64_SSEUP_CLASS);
7303                 tmpmode = OImode;
7304                 i += 3;
7305                 break;
7306               case 8:
7307                 gcc_assert (i == 0
7308                             && regclass[1] == X86_64_SSEUP_CLASS
7309                             && regclass[2] == X86_64_SSEUP_CLASS
7310                             && regclass[3] == X86_64_SSEUP_CLASS
7311                             && regclass[4] == X86_64_SSEUP_CLASS
7312                             && regclass[5] == X86_64_SSEUP_CLASS
7313                             && regclass[6] == X86_64_SSEUP_CLASS
7314                             && regclass[7] == X86_64_SSEUP_CLASS);
7315                 tmpmode = XImode;
7316                 i += 7;
7317                 break;
7318               default:
7319                 gcc_unreachable ();
7320               }
7321             exp [nexps++]
7322               = gen_rtx_EXPR_LIST (VOIDmode,
7323                                    gen_rtx_REG (tmpmode,
7324                                                 SSE_REGNO (sse_regno)),
7325                                    GEN_INT (pos*8));
7326             sse_regno++;
7327             break;
7328           default:
7329             gcc_unreachable ();
7330         }
7331     }
7332
7333   /* Empty aligned struct, union or class.  */
7334   if (nexps == 0)
7335     return NULL;
7336
7337   ret =  gen_rtx_PARALLEL (mode, rtvec_alloc (nexps));
7338   for (i = 0; i < nexps; i++)
7339     XVECEXP (ret, 0, i) = exp [i];
7340   return ret;
7341 }
7342
7343 /* Update the data in CUM to advance over an argument of mode MODE
7344    and data type TYPE.  (TYPE is null for libcalls where that information
7345    may not be available.)
7346
7347    Return a number of integer regsiters advanced over.  */
7348
7349 static int
7350 function_arg_advance_32 (CUMULATIVE_ARGS *cum, machine_mode mode,
7351                          const_tree type, HOST_WIDE_INT bytes,
7352                          HOST_WIDE_INT words)
7353 {
7354   int res = 0;
7355
7356   switch (mode)
7357     {
7358     default:
7359       break;
7360
7361     case BLKmode:
7362       if (bytes < 0)
7363         break;
7364       /* FALLTHRU */
7365
7366     case DImode:
7367     case SImode:
7368     case HImode:
7369     case QImode:
7370       cum->words += words;
7371       cum->nregs -= words;
7372       cum->regno += words;
7373       if (cum->nregs >= 0)
7374         res = words;
7375       if (cum->nregs <= 0)
7376         {
7377           cum->nregs = 0;
7378           cum->regno = 0;
7379         }
7380       break;
7381
7382     case OImode:
7383       /* OImode shouldn't be used directly.  */
7384       gcc_unreachable ();
7385
7386     case DFmode:
7387       if (cum->float_in_sse < 2)
7388         break;
7389     case SFmode:
7390       if (cum->float_in_sse < 1)
7391         break;
7392       /* FALLTHRU */
7393
7394     case V8SFmode:
7395     case V8SImode:
7396     case V64QImode:
7397     case V32HImode:
7398     case V16SImode:
7399     case V8DImode:
7400     case V16SFmode:
7401     case V8DFmode:
7402     case V32QImode:
7403     case V16HImode:
7404     case V4DFmode:
7405     case V4DImode:
7406     case TImode:
7407     case V16QImode:
7408     case V8HImode:
7409     case V4SImode:
7410     case V2DImode:
7411     case V4SFmode:
7412     case V2DFmode:
7413       if (!type || !AGGREGATE_TYPE_P (type))
7414         {
7415           cum->sse_words += words;
7416           cum->sse_nregs -= 1;
7417           cum->sse_regno += 1;
7418           if (cum->sse_nregs <= 0)
7419             {
7420               cum->sse_nregs = 0;
7421               cum->sse_regno = 0;
7422             }
7423         }
7424       break;
7425
7426     case V8QImode:
7427     case V4HImode:
7428     case V2SImode:
7429     case V2SFmode:
7430     case V1TImode:
7431     case V1DImode:
7432       if (!type || !AGGREGATE_TYPE_P (type))
7433         {
7434           cum->mmx_words += words;
7435           cum->mmx_nregs -= 1;
7436           cum->mmx_regno += 1;
7437           if (cum->mmx_nregs <= 0)
7438             {
7439               cum->mmx_nregs = 0;
7440               cum->mmx_regno = 0;
7441             }
7442         }
7443       break;
7444     }
7445
7446   return res;
7447 }
7448
7449 static int
7450 function_arg_advance_64 (CUMULATIVE_ARGS *cum, machine_mode mode,
7451                          const_tree type, HOST_WIDE_INT words, bool named)
7452 {
7453   int int_nregs, sse_nregs;
7454
7455   /* Unnamed 512 and 256bit vector mode parameters are passed on stack.  */
7456   if (!named && (VALID_AVX512F_REG_MODE (mode)
7457                  || VALID_AVX256_REG_MODE (mode)))
7458     return 0;
7459
7460   if (!examine_argument (mode, type, 0, &int_nregs, &sse_nregs)
7461       && sse_nregs <= cum->sse_nregs && int_nregs <= cum->nregs)
7462     {
7463       cum->nregs -= int_nregs;
7464       cum->sse_nregs -= sse_nregs;
7465       cum->regno += int_nregs;
7466       cum->sse_regno += sse_nregs;
7467       return int_nregs;
7468     }
7469   else
7470     {
7471       int align = ix86_function_arg_boundary (mode, type) / BITS_PER_WORD;
7472       cum->words = (cum->words + align - 1) & ~(align - 1);
7473       cum->words += words;
7474       return 0;
7475     }
7476 }
7477
7478 static int
7479 function_arg_advance_ms_64 (CUMULATIVE_ARGS *cum, HOST_WIDE_INT bytes,
7480                             HOST_WIDE_INT words)
7481 {
7482   /* Otherwise, this should be passed indirect.  */
7483   gcc_assert (bytes == 1 || bytes == 2 || bytes == 4 || bytes == 8);
7484
7485   cum->words += words;
7486   if (cum->nregs > 0)
7487     {
7488       cum->nregs -= 1;
7489       cum->regno += 1;
7490       return 1;
7491     }
7492   return 0;
7493 }
7494
7495 /* Update the data in CUM to advance over an argument of mode MODE and
7496    data type TYPE.  (TYPE is null for libcalls where that information
7497    may not be available.)  */
7498
7499 static void
7500 ix86_function_arg_advance (cumulative_args_t cum_v, machine_mode mode,
7501                            const_tree type, bool named)
7502 {
7503   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7504   HOST_WIDE_INT bytes, words;
7505   int nregs;
7506
7507   if (mode == BLKmode)
7508     bytes = int_size_in_bytes (type);
7509   else
7510     bytes = GET_MODE_SIZE (mode);
7511   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7512
7513   if (type)
7514     mode = type_natural_mode (type, NULL, false);
7515
7516   if ((type && POINTER_BOUNDS_TYPE_P (type))
7517       || POINTER_BOUNDS_MODE_P (mode))
7518     {
7519       /* If we pass bounds in BT then just update remained bounds count.  */
7520       if (cum->bnds_in_bt)
7521         {
7522           cum->bnds_in_bt--;
7523           return;
7524         }
7525
7526       /* Update remained number of bounds to force.  */
7527       if (cum->force_bnd_pass)
7528         cum->force_bnd_pass--;
7529
7530       cum->bnd_regno++;
7531
7532       return;
7533     }
7534
7535   /* The first arg not going to Bounds Tables resets this counter.  */
7536   cum->bnds_in_bt = 0;
7537   /* For unnamed args we always pass bounds to avoid bounds mess when
7538      passed and received types do not match.  If bounds do not follow
7539      unnamed arg, still pretend required number of bounds were passed.  */
7540   if (cum->force_bnd_pass)
7541     {
7542       cum->bnd_regno += cum->force_bnd_pass;
7543       cum->force_bnd_pass = 0;
7544     }
7545
7546   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
7547     nregs = function_arg_advance_ms_64 (cum, bytes, words);
7548   else if (TARGET_64BIT)
7549     nregs = function_arg_advance_64 (cum, mode, type, words, named);
7550   else
7551     nregs = function_arg_advance_32 (cum, mode, type, bytes, words);
7552
7553   /* For stdarg we expect bounds to be passed for each value passed
7554      in register.  */
7555   if (cum->stdarg)
7556     cum->force_bnd_pass = nregs;
7557   /* For pointers passed in memory we expect bounds passed in Bounds
7558      Table.  */
7559   if (!nregs)
7560     cum->bnds_in_bt = chkp_type_bounds_count (type);
7561 }
7562
7563 /* Define where to put the arguments to a function.
7564    Value is zero to push the argument on the stack,
7565    or a hard register in which to store the argument.
7566
7567    MODE is the argument's machine mode.
7568    TYPE is the data type of the argument (as a tree).
7569     This is null for libcalls where that information may
7570     not be available.
7571    CUM is a variable of type CUMULATIVE_ARGS which gives info about
7572     the preceding args and about the function being called.
7573    NAMED is nonzero if this argument is a named parameter
7574     (otherwise it is an extra parameter matching an ellipsis).  */
7575
7576 static rtx
7577 function_arg_32 (const CUMULATIVE_ARGS *cum, machine_mode mode,
7578                  machine_mode orig_mode, const_tree type,
7579                  HOST_WIDE_INT bytes, HOST_WIDE_INT words)
7580 {
7581   /* Avoid the AL settings for the Unix64 ABI.  */
7582   if (mode == VOIDmode)
7583     return constm1_rtx;
7584
7585   switch (mode)
7586     {
7587     default:
7588       break;
7589
7590     case BLKmode:
7591       if (bytes < 0)
7592         break;
7593       /* FALLTHRU */
7594     case DImode:
7595     case SImode:
7596     case HImode:
7597     case QImode:
7598       if (words <= cum->nregs)
7599         {
7600           int regno = cum->regno;
7601
7602           /* Fastcall allocates the first two DWORD (SImode) or
7603             smaller arguments to ECX and EDX if it isn't an
7604             aggregate type .  */
7605           if (cum->fastcall)
7606             {
7607               if (mode == BLKmode
7608                   || mode == DImode
7609                   || (type && AGGREGATE_TYPE_P (type)))
7610                 break;
7611
7612               /* ECX not EAX is the first allocated register.  */
7613               if (regno == AX_REG)
7614                 regno = CX_REG;
7615             }
7616           return gen_rtx_REG (mode, regno);
7617         }
7618       break;
7619
7620     case DFmode:
7621       if (cum->float_in_sse < 2)
7622         break;
7623     case SFmode:
7624       if (cum->float_in_sse < 1)
7625         break;
7626       /* FALLTHRU */
7627     case TImode:
7628       /* In 32bit, we pass TImode in xmm registers.  */
7629     case V16QImode:
7630     case V8HImode:
7631     case V4SImode:
7632     case V2DImode:
7633     case V4SFmode:
7634     case V2DFmode:
7635       if (!type || !AGGREGATE_TYPE_P (type))
7636         {
7637           if (cum->sse_nregs)
7638             return gen_reg_or_parallel (mode, orig_mode,
7639                                         cum->sse_regno + FIRST_SSE_REG);
7640         }
7641       break;
7642
7643     case OImode:
7644     case XImode:
7645       /* OImode and XImode shouldn't be used directly.  */
7646       gcc_unreachable ();
7647
7648     case V64QImode:
7649     case V32HImode:
7650     case V16SImode:
7651     case V8DImode:
7652     case V16SFmode:
7653     case V8DFmode:
7654     case V8SFmode:
7655     case V8SImode:
7656     case V32QImode:
7657     case V16HImode:
7658     case V4DFmode:
7659     case V4DImode:
7660       if (!type || !AGGREGATE_TYPE_P (type))
7661         {
7662           if (cum->sse_nregs)
7663             return gen_reg_or_parallel (mode, orig_mode,
7664                                         cum->sse_regno + FIRST_SSE_REG);
7665         }
7666       break;
7667
7668     case V8QImode:
7669     case V4HImode:
7670     case V2SImode:
7671     case V2SFmode:
7672     case V1TImode:
7673     case V1DImode:
7674       if (!type || !AGGREGATE_TYPE_P (type))
7675         {
7676           if (cum->mmx_nregs)
7677             return gen_reg_or_parallel (mode, orig_mode,
7678                                         cum->mmx_regno + FIRST_MMX_REG);
7679         }
7680       break;
7681     }
7682
7683   return NULL_RTX;
7684 }
7685
7686 static rtx
7687 function_arg_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
7688                  machine_mode orig_mode, const_tree type, bool named)
7689 {
7690   /* Handle a hidden AL argument containing number of registers
7691      for varargs x86-64 functions.  */
7692   if (mode == VOIDmode)
7693     return GEN_INT (cum->maybe_vaarg
7694                     ? (cum->sse_nregs < 0
7695                        ? X86_64_SSE_REGPARM_MAX
7696                        : cum->sse_regno)
7697                     : -1);
7698
7699   switch (mode)
7700     {
7701     default:
7702       break;
7703
7704     case V8SFmode:
7705     case V8SImode:
7706     case V32QImode:
7707     case V16HImode:
7708     case V4DFmode:
7709     case V4DImode:
7710     case V16SFmode:
7711     case V16SImode:
7712     case V64QImode:
7713     case V32HImode:
7714     case V8DFmode:
7715     case V8DImode:
7716       /* Unnamed 256 and 512bit vector mode parameters are passed on stack.  */
7717       if (!named)
7718         return NULL;
7719       break;
7720     }
7721
7722   return construct_container (mode, orig_mode, type, 0, cum->nregs,
7723                               cum->sse_nregs,
7724                               &x86_64_int_parameter_registers [cum->regno],
7725                               cum->sse_regno);
7726 }
7727
7728 static rtx
7729 function_arg_ms_64 (const CUMULATIVE_ARGS *cum, machine_mode mode,
7730                     machine_mode orig_mode, bool named,
7731                     HOST_WIDE_INT bytes)
7732 {
7733   unsigned int regno;
7734
7735   /* We need to add clobber for MS_ABI->SYSV ABI calls in expand_call.
7736      We use value of -2 to specify that current function call is MSABI.  */
7737   if (mode == VOIDmode)
7738     return GEN_INT (-2);
7739
7740   /* If we've run out of registers, it goes on the stack.  */
7741   if (cum->nregs == 0)
7742     return NULL_RTX;
7743
7744   regno = x86_64_ms_abi_int_parameter_registers[cum->regno];
7745
7746   /* Only floating point modes are passed in anything but integer regs.  */
7747   if (TARGET_SSE && (mode == SFmode || mode == DFmode))
7748     {
7749       if (named)
7750         regno = cum->regno + FIRST_SSE_REG;
7751       else
7752         {
7753           rtx t1, t2;
7754
7755           /* Unnamed floating parameters are passed in both the
7756              SSE and integer registers.  */
7757           t1 = gen_rtx_REG (mode, cum->regno + FIRST_SSE_REG);
7758           t2 = gen_rtx_REG (mode, regno);
7759           t1 = gen_rtx_EXPR_LIST (VOIDmode, t1, const0_rtx);
7760           t2 = gen_rtx_EXPR_LIST (VOIDmode, t2, const0_rtx);
7761           return gen_rtx_PARALLEL (mode, gen_rtvec (2, t1, t2));
7762         }
7763     }
7764   /* Handle aggregated types passed in register.  */
7765   if (orig_mode == BLKmode)
7766     {
7767       if (bytes > 0 && bytes <= 8)
7768         mode = (bytes > 4 ? DImode : SImode);
7769       if (mode == BLKmode)
7770         mode = DImode;
7771     }
7772
7773   return gen_reg_or_parallel (mode, orig_mode, regno);
7774 }
7775
7776 /* Return where to put the arguments to a function.
7777    Return zero to push the argument on the stack, or a hard register in which to store the argument.
7778
7779    MODE is the argument's machine mode.  TYPE is the data type of the
7780    argument.  It is null for libcalls where that information may not be
7781    available.  CUM gives information about the preceding args and about
7782    the function being called.  NAMED is nonzero if this argument is a
7783    named parameter (otherwise it is an extra parameter matching an
7784    ellipsis).  */
7785
7786 static rtx
7787 ix86_function_arg (cumulative_args_t cum_v, machine_mode omode,
7788                    const_tree type, bool named)
7789 {
7790   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7791   machine_mode mode = omode;
7792   HOST_WIDE_INT bytes, words;
7793   rtx arg;
7794
7795   /* All pointer bounds argumntas are handled separately here.  */
7796   if ((type && POINTER_BOUNDS_TYPE_P (type))
7797       || POINTER_BOUNDS_MODE_P (mode))
7798     {
7799       /* Return NULL if bounds are forced to go in Bounds Table.  */
7800       if (cum->bnds_in_bt)
7801         arg = NULL;
7802       /* Return the next available bound reg if any.  */
7803       else if (cum->bnd_regno <= LAST_BND_REG)
7804         arg = gen_rtx_REG (BNDmode, cum->bnd_regno);
7805       /* Return the next special slot number otherwise.  */
7806       else
7807         arg = GEN_INT (cum->bnd_regno - LAST_BND_REG - 1);
7808
7809       return arg;
7810     }
7811
7812   if (mode == BLKmode)
7813     bytes = int_size_in_bytes (type);
7814   else
7815     bytes = GET_MODE_SIZE (mode);
7816   words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
7817
7818   /* To simplify the code below, represent vector types with a vector mode
7819      even if MMX/SSE are not active.  */
7820   if (type && TREE_CODE (type) == VECTOR_TYPE)
7821     mode = type_natural_mode (type, cum, false);
7822
7823   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
7824     arg = function_arg_ms_64 (cum, mode, omode, named, bytes);
7825   else if (TARGET_64BIT)
7826     arg = function_arg_64 (cum, mode, omode, type, named);
7827   else
7828     arg = function_arg_32 (cum, mode, omode, type, bytes, words);
7829
7830   return arg;
7831 }
7832
7833 /* A C expression that indicates when an argument must be passed by
7834    reference.  If nonzero for an argument, a copy of that argument is
7835    made in memory and a pointer to the argument is passed instead of
7836    the argument itself.  The pointer is passed in whatever way is
7837    appropriate for passing a pointer to that type.  */
7838
7839 static bool
7840 ix86_pass_by_reference (cumulative_args_t cum_v, machine_mode mode,
7841                         const_tree type, bool)
7842 {
7843   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
7844
7845   /* See Windows x64 Software Convention.  */
7846   if (TARGET_64BIT && (cum ? cum->call_abi : ix86_abi) == MS_ABI)
7847     {
7848       int msize = (int) GET_MODE_SIZE (mode);
7849       if (type)
7850         {
7851           /* Arrays are passed by reference.  */
7852           if (TREE_CODE (type) == ARRAY_TYPE)
7853             return true;
7854
7855           if (AGGREGATE_TYPE_P (type))
7856             {
7857               /* Structs/unions of sizes other than 8, 16, 32, or 64 bits
7858                  are passed by reference.  */
7859               msize = int_size_in_bytes (type);
7860             }
7861         }
7862
7863       /* __m128 is passed by reference.  */
7864       switch (msize) {
7865       case 1: case 2: case 4: case 8:
7866         break;
7867       default:
7868         return true;
7869       }
7870     }
7871   else if (TARGET_64BIT && type && int_size_in_bytes (type) == -1)
7872     return 1;
7873
7874   return 0;
7875 }
7876
7877 /* Return true when TYPE should be 128bit aligned for 32bit argument
7878    passing ABI.  XXX: This function is obsolete and is only used for
7879    checking psABI compatibility with previous versions of GCC.  */
7880
7881 static bool
7882 ix86_compat_aligned_value_p (const_tree type)
7883 {
7884   machine_mode mode = TYPE_MODE (type);
7885   if (((TARGET_SSE && SSE_REG_MODE_P (mode))
7886        || mode == TDmode
7887        || mode == TFmode
7888        || mode == TCmode)
7889       && (!TYPE_USER_ALIGN (type) || TYPE_ALIGN (type) > 128))
7890     return true;
7891   if (TYPE_ALIGN (type) < 128)
7892     return false;
7893
7894   if (AGGREGATE_TYPE_P (type))
7895     {
7896       /* Walk the aggregates recursively.  */
7897       switch (TREE_CODE (type))
7898         {
7899         case RECORD_TYPE:
7900         case UNION_TYPE:
7901         case QUAL_UNION_TYPE:
7902           {
7903             tree field;
7904
7905             /* Walk all the structure fields.  */
7906             for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
7907               {
7908                 if (TREE_CODE (field) == FIELD_DECL
7909                     && ix86_compat_aligned_value_p (TREE_TYPE (field)))
7910                   return true;
7911               }
7912             break;
7913           }
7914
7915         case ARRAY_TYPE:
7916           /* Just for use if some languages passes arrays by value.  */
7917           if (ix86_compat_aligned_value_p (TREE_TYPE (type)))
7918             return true;
7919           break;
7920
7921         default:
7922           gcc_unreachable ();
7923         }
7924     }
7925   return false;
7926 }
7927
7928 /* Return the alignment boundary for MODE and TYPE with alignment ALIGN.
7929    XXX: This function is obsolete and is only used for checking psABI
7930    compatibility with previous versions of GCC.  */
7931
7932 static unsigned int
7933 ix86_compat_function_arg_boundary (machine_mode mode,
7934                                    const_tree type, unsigned int align)
7935 {
7936   /* In 32bit, only _Decimal128 and __float128 are aligned to their
7937      natural boundaries.  */
7938   if (!TARGET_64BIT && mode != TDmode && mode != TFmode)
7939     {
7940       /* i386 ABI defines all arguments to be 4 byte aligned.  We have to
7941          make an exception for SSE modes since these require 128bit
7942          alignment.
7943
7944          The handling here differs from field_alignment.  ICC aligns MMX
7945          arguments to 4 byte boundaries, while structure fields are aligned
7946          to 8 byte boundaries.  */
7947       if (!type)
7948         {
7949           if (!(TARGET_SSE && SSE_REG_MODE_P (mode)))
7950             align = PARM_BOUNDARY;
7951         }
7952       else
7953         {
7954           if (!ix86_compat_aligned_value_p (type))
7955             align = PARM_BOUNDARY;
7956         }
7957     }
7958   if (align > BIGGEST_ALIGNMENT)
7959     align = BIGGEST_ALIGNMENT;
7960   return align;
7961 }
7962
7963 /* Return true when TYPE should be 128bit aligned for 32bit argument
7964    passing ABI.  */
7965
7966 static bool
7967 ix86_contains_aligned_value_p (const_tree type)
7968 {
7969   machine_mode mode = TYPE_MODE (type);
7970
7971   if (mode == XFmode || mode == XCmode)
7972     return false;
7973
7974   if (TYPE_ALIGN (type) < 128)
7975     return false;
7976
7977   if (AGGREGATE_TYPE_P (type))
7978     {
7979       /* Walk the aggregates recursively.  */
7980       switch (TREE_CODE (type))
7981         {
7982         case RECORD_TYPE:
7983         case UNION_TYPE:
7984         case QUAL_UNION_TYPE:
7985           {
7986             tree field;
7987
7988             /* Walk all the structure fields.  */
7989             for (field = TYPE_FIELDS (type);
7990                  field;
7991                  field = DECL_CHAIN (field))
7992               {
7993                 if (TREE_CODE (field) == FIELD_DECL
7994                     && ix86_contains_aligned_value_p (TREE_TYPE (field)))
7995                   return true;
7996               }
7997             break;
7998           }
7999
8000         case ARRAY_TYPE:
8001           /* Just for use if some languages passes arrays by value.  */
8002           if (ix86_contains_aligned_value_p (TREE_TYPE (type)))
8003             return true;
8004           break;
8005
8006         default:
8007           gcc_unreachable ();
8008         }
8009     }
8010   else
8011     return TYPE_ALIGN (type) >= 128;
8012
8013   return false;
8014 }
8015
8016 /* Gives the alignment boundary, in bits, of an argument with the
8017    specified mode and type.  */
8018
8019 static unsigned int
8020 ix86_function_arg_boundary (machine_mode mode, const_tree type)
8021 {
8022   unsigned int align;
8023   if (type)
8024     {
8025       /* Since the main variant type is used for call, we convert it to
8026          the main variant type.  */
8027       type = TYPE_MAIN_VARIANT (type);
8028       align = TYPE_ALIGN (type);
8029     }
8030   else
8031     align = GET_MODE_ALIGNMENT (mode);
8032   if (align < PARM_BOUNDARY)
8033     align = PARM_BOUNDARY;
8034   else
8035     {
8036       static bool warned;
8037       unsigned int saved_align = align;
8038
8039       if (!TARGET_64BIT)
8040         {
8041           /* i386 ABI defines XFmode arguments to be 4 byte aligned.  */
8042           if (!type)
8043             {
8044               if (mode == XFmode || mode == XCmode)
8045                 align = PARM_BOUNDARY;
8046             }
8047           else if (!ix86_contains_aligned_value_p (type))
8048             align = PARM_BOUNDARY;
8049
8050           if (align < 128)
8051             align = PARM_BOUNDARY;
8052         }
8053
8054       if (warn_psabi
8055           && !warned
8056           && align != ix86_compat_function_arg_boundary (mode, type,
8057                                                          saved_align))
8058         {
8059           warned = true;
8060           inform (input_location,
8061                   "The ABI for passing parameters with %d-byte"
8062                   " alignment has changed in GCC 4.6",
8063                   align / BITS_PER_UNIT);
8064         }
8065     }
8066
8067   return align;
8068 }
8069
8070 /* Return true if N is a possible register number of function value.  */
8071
8072 static bool
8073 ix86_function_value_regno_p (const unsigned int regno)
8074 {
8075   switch (regno)
8076     {
8077     case AX_REG:
8078       return true;
8079     case DX_REG:
8080       return (!TARGET_64BIT || ix86_abi != MS_ABI);
8081     case DI_REG:
8082     case SI_REG:
8083       return TARGET_64BIT && ix86_abi != MS_ABI;
8084
8085     case FIRST_BND_REG:
8086       return chkp_function_instrumented_p (current_function_decl);
8087
8088       /* Complex values are returned in %st(0)/%st(1) pair.  */
8089     case ST0_REG:
8090     case ST1_REG:
8091       /* TODO: The function should depend on current function ABI but
8092        builtins.c would need updating then. Therefore we use the
8093        default ABI.  */
8094       if (TARGET_64BIT && ix86_abi == MS_ABI)
8095         return false;
8096       return TARGET_FLOAT_RETURNS_IN_80387;
8097
8098       /* Complex values are returned in %xmm0/%xmm1 pair.  */
8099     case XMM0_REG:
8100     case XMM1_REG:
8101       return TARGET_SSE;
8102
8103     case MM0_REG:
8104       if (TARGET_MACHO || TARGET_64BIT)
8105         return false;
8106       return TARGET_MMX;
8107     }
8108
8109   return false;
8110 }
8111
8112 /* Define how to find the value returned by a function.
8113    VALTYPE is the data type of the value (as a tree).
8114    If the precise function being called is known, FUNC is its FUNCTION_DECL;
8115    otherwise, FUNC is 0.  */
8116
8117 static rtx
8118 function_value_32 (machine_mode orig_mode, machine_mode mode,
8119                    const_tree fntype, const_tree fn)
8120 {
8121   unsigned int regno;
8122
8123   /* 8-byte vector modes in %mm0. See ix86_return_in_memory for where
8124      we normally prevent this case when mmx is not available.  However
8125      some ABIs may require the result to be returned like DImode.  */
8126   if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 8)
8127     regno = FIRST_MMX_REG;
8128
8129   /* 16-byte vector modes in %xmm0.  See ix86_return_in_memory for where
8130      we prevent this case when sse is not available.  However some ABIs
8131      may require the result to be returned like integer TImode.  */
8132   else if (mode == TImode
8133            || (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 16))
8134     regno = FIRST_SSE_REG;
8135
8136   /* 32-byte vector modes in %ymm0.   */
8137   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 32)
8138     regno = FIRST_SSE_REG;
8139
8140   /* 64-byte vector modes in %zmm0.   */
8141   else if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64)
8142     regno = FIRST_SSE_REG;
8143
8144   /* Floating point return values in %st(0) (unless -mno-fp-ret-in-387).  */
8145   else if (X87_FLOAT_MODE_P (mode) && TARGET_FLOAT_RETURNS_IN_80387)
8146     regno = FIRST_FLOAT_REG;
8147   else
8148     /* Most things go in %eax.  */
8149     regno = AX_REG;
8150
8151   /* Override FP return register with %xmm0 for local functions when
8152      SSE math is enabled or for functions with sseregparm attribute.  */
8153   if ((fn || fntype) && (mode == SFmode || mode == DFmode))
8154     {
8155       int sse_level = ix86_function_sseregparm (fntype, fn, false);
8156       if ((sse_level >= 1 && mode == SFmode)
8157           || (sse_level == 2 && mode == DFmode))
8158         regno = FIRST_SSE_REG;
8159     }
8160
8161   /* OImode shouldn't be used directly.  */
8162   gcc_assert (mode != OImode);
8163
8164   return gen_rtx_REG (orig_mode, regno);
8165 }
8166
8167 static rtx
8168 function_value_64 (machine_mode orig_mode, machine_mode mode,
8169                    const_tree valtype)
8170 {
8171   rtx ret;
8172
8173   /* Handle libcalls, which don't provide a type node.  */
8174   if (valtype == NULL)
8175     {
8176       unsigned int regno;
8177
8178       switch (mode)
8179         {
8180         case SFmode:
8181         case SCmode:
8182         case DFmode:
8183         case DCmode:
8184         case TFmode:
8185         case SDmode:
8186         case DDmode:
8187         case TDmode:
8188           regno = FIRST_SSE_REG;
8189           break;
8190         case XFmode:
8191         case XCmode:
8192           regno = FIRST_FLOAT_REG;
8193           break;
8194         case TCmode:
8195           return NULL;
8196         default:
8197           regno = AX_REG;
8198         }
8199
8200       return gen_rtx_REG (mode, regno);
8201     }
8202   else if (POINTER_TYPE_P (valtype))
8203     {
8204       /* Pointers are always returned in word_mode.  */
8205       mode = word_mode;
8206     }
8207
8208   ret = construct_container (mode, orig_mode, valtype, 1,
8209                              X86_64_REGPARM_MAX, X86_64_SSE_REGPARM_MAX,
8210                              x86_64_int_return_registers, 0);
8211
8212   /* For zero sized structures, construct_container returns NULL, but we
8213      need to keep rest of compiler happy by returning meaningful value.  */
8214   if (!ret)
8215     ret = gen_rtx_REG (orig_mode, AX_REG);
8216
8217   return ret;
8218 }
8219
8220 static rtx
8221 function_value_ms_64 (machine_mode orig_mode, machine_mode mode,
8222                       const_tree valtype)
8223 {
8224   unsigned int regno = AX_REG;
8225
8226   if (TARGET_SSE)
8227     {
8228       switch (GET_MODE_SIZE (mode))
8229         {
8230         case 16:
8231           if (valtype != NULL_TREE
8232               && !VECTOR_INTEGER_TYPE_P (valtype)
8233               && !VECTOR_INTEGER_TYPE_P (valtype)
8234               && !INTEGRAL_TYPE_P (valtype)
8235               && !VECTOR_FLOAT_TYPE_P (valtype))
8236             break;
8237           if ((SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
8238               && !COMPLEX_MODE_P (mode))
8239             regno = FIRST_SSE_REG;
8240           break;
8241         case 8:
8242         case 4:
8243           if (mode == SFmode || mode == DFmode)
8244             regno = FIRST_SSE_REG;
8245           break;
8246         default:
8247           break;
8248         }
8249     }
8250   return gen_rtx_REG (orig_mode, regno);
8251 }
8252
8253 static rtx
8254 ix86_function_value_1 (const_tree valtype, const_tree fntype_or_decl,
8255                        machine_mode orig_mode, machine_mode mode)
8256 {
8257   const_tree fn, fntype;
8258
8259   fn = NULL_TREE;
8260   if (fntype_or_decl && DECL_P (fntype_or_decl))
8261     fn = fntype_or_decl;
8262   fntype = fn ? TREE_TYPE (fn) : fntype_or_decl;
8263
8264   if ((valtype && POINTER_BOUNDS_TYPE_P (valtype))
8265       || POINTER_BOUNDS_MODE_P (mode))
8266     return gen_rtx_REG (BNDmode, FIRST_BND_REG);
8267   else if (TARGET_64BIT && ix86_function_type_abi (fntype) == MS_ABI)
8268     return function_value_ms_64 (orig_mode, mode, valtype);
8269   else if (TARGET_64BIT)
8270     return function_value_64 (orig_mode, mode, valtype);
8271   else
8272     return function_value_32 (orig_mode, mode, fntype, fn);
8273 }
8274
8275 static rtx
8276 ix86_function_value (const_tree valtype, const_tree fntype_or_decl, bool)
8277 {
8278   machine_mode mode, orig_mode;
8279
8280   orig_mode = TYPE_MODE (valtype);
8281   mode = type_natural_mode (valtype, NULL, true);
8282   return ix86_function_value_1 (valtype, fntype_or_decl, orig_mode, mode);
8283 }
8284
8285 /*  Return an RTX representing a place where a function returns
8286     or recieves pointer bounds or NULL if no bounds are returned.
8287
8288     VALTYPE is a data type of a value returned by the function.
8289
8290     FN_DECL_OR_TYPE is a tree node representing FUNCTION_DECL
8291     or FUNCTION_TYPE of the function.
8292
8293     If OUTGOING is false, return a place in which the caller will
8294     see the return value.  Otherwise, return a place where a
8295     function returns a value.  */
8296
8297 static rtx
8298 ix86_function_value_bounds (const_tree valtype,
8299                             const_tree fntype_or_decl ATTRIBUTE_UNUSED,
8300                             bool outgoing ATTRIBUTE_UNUSED)
8301 {
8302   rtx res = NULL_RTX;
8303
8304   if (BOUNDED_TYPE_P (valtype))
8305     res = gen_rtx_REG (BNDmode, FIRST_BND_REG);
8306   else if (chkp_type_has_pointer (valtype))
8307     {
8308       bitmap slots;
8309       rtx bounds[2];
8310       bitmap_iterator bi;
8311       unsigned i, bnd_no = 0;
8312
8313       bitmap_obstack_initialize (NULL);
8314       slots = BITMAP_ALLOC (NULL);
8315       chkp_find_bound_slots (valtype, slots);
8316
8317       EXECUTE_IF_SET_IN_BITMAP (slots, 0, i, bi)
8318         {
8319           rtx reg = gen_rtx_REG (BNDmode, FIRST_BND_REG + bnd_no);
8320           rtx offs = GEN_INT (i * POINTER_SIZE / BITS_PER_UNIT);
8321           gcc_assert (bnd_no < 2);
8322           bounds[bnd_no++] = gen_rtx_EXPR_LIST (VOIDmode, reg, offs);
8323         }
8324
8325       res = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (bnd_no, bounds));
8326
8327       BITMAP_FREE (slots);
8328       bitmap_obstack_release (NULL);
8329     }
8330   else
8331     res = NULL_RTX;
8332
8333   return res;
8334 }
8335
8336 /* Pointer function arguments and return values are promoted to
8337    word_mode.  */
8338
8339 static machine_mode
8340 ix86_promote_function_mode (const_tree type, machine_mode mode,
8341                             int *punsignedp, const_tree fntype,
8342                             int for_return)
8343 {
8344   if (type != NULL_TREE && POINTER_TYPE_P (type))
8345     {
8346       *punsignedp = POINTERS_EXTEND_UNSIGNED;
8347       return word_mode;
8348     }
8349   return default_promote_function_mode (type, mode, punsignedp, fntype,
8350                                         for_return);
8351 }
8352
8353 /* Return true if a structure, union or array with MODE containing FIELD
8354    should be accessed using BLKmode.  */
8355
8356 static bool
8357 ix86_member_type_forces_blk (const_tree field, machine_mode mode)
8358 {
8359   /* Union with XFmode must be in BLKmode.  */
8360   return (mode == XFmode
8361           && (TREE_CODE (DECL_FIELD_CONTEXT (field)) == UNION_TYPE
8362               || TREE_CODE (DECL_FIELD_CONTEXT (field)) == QUAL_UNION_TYPE));
8363 }
8364
8365 rtx
8366 ix86_libcall_value (machine_mode mode)
8367 {
8368   return ix86_function_value_1 (NULL, NULL, mode, mode);
8369 }
8370
8371 /* Return true iff type is returned in memory.  */
8372
8373 static bool
8374 ix86_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
8375 {
8376 #ifdef SUBTARGET_RETURN_IN_MEMORY
8377   return SUBTARGET_RETURN_IN_MEMORY (type, fntype);
8378 #else
8379   const machine_mode mode = type_natural_mode (type, NULL, true);
8380   HOST_WIDE_INT size;
8381
8382   if (POINTER_BOUNDS_TYPE_P (type))
8383     return false;
8384
8385   if (TARGET_64BIT)
8386     {
8387       if (ix86_function_type_abi (fntype) == MS_ABI)
8388         {
8389           size = int_size_in_bytes (type);
8390
8391           /* __m128 is returned in xmm0.  */
8392           if ((!type || VECTOR_INTEGER_TYPE_P (type)
8393                || INTEGRAL_TYPE_P (type)
8394                || VECTOR_FLOAT_TYPE_P (type))
8395               && (SCALAR_INT_MODE_P (mode) || VECTOR_MODE_P (mode))
8396               && !COMPLEX_MODE_P (mode)
8397               && (GET_MODE_SIZE (mode) == 16 || size == 16))
8398             return false;
8399
8400           /* Otherwise, the size must be exactly in [1248]. */
8401           return size != 1 && size != 2 && size != 4 && size != 8;
8402         }
8403       else
8404         {
8405           int needed_intregs, needed_sseregs;
8406
8407           return examine_argument (mode, type, 1,
8408                                    &needed_intregs, &needed_sseregs);
8409         }
8410     }
8411   else
8412     {
8413       if (mode == BLKmode)
8414         return true;
8415
8416       size = int_size_in_bytes (type);
8417
8418       if (MS_AGGREGATE_RETURN && AGGREGATE_TYPE_P (type) && size <= 8)
8419         return false;
8420
8421       if (VECTOR_MODE_P (mode) || mode == TImode)
8422         {
8423           /* User-created vectors small enough to fit in EAX.  */
8424           if (size < 8)
8425             return false;
8426
8427           /* Unless ABI prescibes otherwise,
8428              MMX/3dNow values are returned in MM0 if available.  */
8429              
8430           if (size == 8)
8431             return TARGET_VECT8_RETURNS || !TARGET_MMX;
8432
8433           /* SSE values are returned in XMM0 if available.  */
8434           if (size == 16)
8435             return !TARGET_SSE;
8436
8437           /* AVX values are returned in YMM0 if available.  */
8438           if (size == 32)
8439             return !TARGET_AVX;
8440
8441           /* AVX512F values are returned in ZMM0 if available.  */
8442           if (size == 64)
8443             return !TARGET_AVX512F;
8444         }
8445
8446       if (mode == XFmode)
8447         return false;
8448
8449       if (size > 12)
8450         return true;
8451
8452       /* OImode shouldn't be used directly.  */
8453       gcc_assert (mode != OImode);
8454
8455       return false;
8456     }
8457 #endif
8458 }
8459
8460 \f
8461 /* Create the va_list data type.  */
8462
8463 /* Returns the calling convention specific va_list date type.
8464    The argument ABI can be DEFAULT_ABI, MS_ABI, or SYSV_ABI.  */
8465
8466 static tree
8467 ix86_build_builtin_va_list_abi (enum calling_abi abi)
8468 {
8469   tree f_gpr, f_fpr, f_ovf, f_sav, record, type_decl;
8470
8471   /* For i386 we use plain pointer to argument area.  */
8472   if (!TARGET_64BIT || abi == MS_ABI)
8473     return build_pointer_type (char_type_node);
8474
8475   record = lang_hooks.types.make_type (RECORD_TYPE);
8476   type_decl = build_decl (BUILTINS_LOCATION,
8477                           TYPE_DECL, get_identifier ("__va_list_tag"), record);
8478
8479   f_gpr = build_decl (BUILTINS_LOCATION,
8480                       FIELD_DECL, get_identifier ("gp_offset"),
8481                       unsigned_type_node);
8482   f_fpr = build_decl (BUILTINS_LOCATION,
8483                       FIELD_DECL, get_identifier ("fp_offset"),
8484                       unsigned_type_node);
8485   f_ovf = build_decl (BUILTINS_LOCATION,
8486                       FIELD_DECL, get_identifier ("overflow_arg_area"),
8487                       ptr_type_node);
8488   f_sav = build_decl (BUILTINS_LOCATION,
8489                       FIELD_DECL, get_identifier ("reg_save_area"),
8490                       ptr_type_node);
8491
8492   va_list_gpr_counter_field = f_gpr;
8493   va_list_fpr_counter_field = f_fpr;
8494
8495   DECL_FIELD_CONTEXT (f_gpr) = record;
8496   DECL_FIELD_CONTEXT (f_fpr) = record;
8497   DECL_FIELD_CONTEXT (f_ovf) = record;
8498   DECL_FIELD_CONTEXT (f_sav) = record;
8499
8500   TYPE_STUB_DECL (record) = type_decl;
8501   TYPE_NAME (record) = type_decl;
8502   TYPE_FIELDS (record) = f_gpr;
8503   DECL_CHAIN (f_gpr) = f_fpr;
8504   DECL_CHAIN (f_fpr) = f_ovf;
8505   DECL_CHAIN (f_ovf) = f_sav;
8506
8507   layout_type (record);
8508
8509   /* The correct type is an array type of one element.  */
8510   return build_array_type (record, build_index_type (size_zero_node));
8511 }
8512
8513 /* Setup the builtin va_list data type and for 64-bit the additional
8514    calling convention specific va_list data types.  */
8515
8516 static tree
8517 ix86_build_builtin_va_list (void)
8518 {
8519   tree ret = ix86_build_builtin_va_list_abi (ix86_abi);
8520
8521   /* Initialize abi specific va_list builtin types.  */
8522   if (TARGET_64BIT)
8523     {
8524       tree t;
8525       if (ix86_abi == MS_ABI)
8526         {
8527           t = ix86_build_builtin_va_list_abi (SYSV_ABI);
8528           if (TREE_CODE (t) != RECORD_TYPE)
8529             t = build_variant_type_copy (t);
8530           sysv_va_list_type_node = t;
8531         }
8532       else
8533         {
8534           t = ret;
8535           if (TREE_CODE (t) != RECORD_TYPE)
8536             t = build_variant_type_copy (t);
8537           sysv_va_list_type_node = t;
8538         }
8539       if (ix86_abi != MS_ABI)
8540         {
8541           t = ix86_build_builtin_va_list_abi (MS_ABI);
8542           if (TREE_CODE (t) != RECORD_TYPE)
8543             t = build_variant_type_copy (t);
8544           ms_va_list_type_node = t;
8545         }
8546       else
8547         {
8548           t = ret;
8549           if (TREE_CODE (t) != RECORD_TYPE)
8550             t = build_variant_type_copy (t);
8551           ms_va_list_type_node = t;
8552         }
8553     }
8554
8555   return ret;
8556 }
8557
8558 /* Worker function for TARGET_SETUP_INCOMING_VARARGS.  */
8559
8560 static void
8561 setup_incoming_varargs_64 (CUMULATIVE_ARGS *cum)
8562 {
8563   rtx save_area, mem;
8564   alias_set_type set;
8565   int i, max;
8566
8567   /* GPR size of varargs save area.  */
8568   if (cfun->va_list_gpr_size)
8569     ix86_varargs_gpr_size = X86_64_REGPARM_MAX * UNITS_PER_WORD;
8570   else
8571     ix86_varargs_gpr_size = 0;
8572
8573   /* FPR size of varargs save area.  We don't need it if we don't pass
8574      anything in SSE registers.  */
8575   if (TARGET_SSE && cfun->va_list_fpr_size)
8576     ix86_varargs_fpr_size = X86_64_SSE_REGPARM_MAX * 16;
8577   else
8578     ix86_varargs_fpr_size = 0;
8579
8580   if (! ix86_varargs_gpr_size && ! ix86_varargs_fpr_size)
8581     return;
8582
8583   save_area = frame_pointer_rtx;
8584   set = get_varargs_alias_set ();
8585
8586   max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
8587   if (max > X86_64_REGPARM_MAX)
8588     max = X86_64_REGPARM_MAX;
8589
8590   for (i = cum->regno; i < max; i++)
8591     {
8592       mem = gen_rtx_MEM (word_mode,
8593                          plus_constant (Pmode, save_area, i * UNITS_PER_WORD));
8594       MEM_NOTRAP_P (mem) = 1;
8595       set_mem_alias_set (mem, set);
8596       emit_move_insn (mem,
8597                       gen_rtx_REG (word_mode,
8598                                    x86_64_int_parameter_registers[i]));
8599     }
8600
8601   if (ix86_varargs_fpr_size)
8602     {
8603       machine_mode smode;
8604       rtx_code_label *label;
8605       rtx test;
8606
8607       /* Now emit code to save SSE registers.  The AX parameter contains number
8608          of SSE parameter registers used to call this function, though all we
8609          actually check here is the zero/non-zero status.  */
8610
8611       label = gen_label_rtx ();
8612       test = gen_rtx_EQ (VOIDmode, gen_rtx_REG (QImode, AX_REG), const0_rtx);
8613       emit_jump_insn (gen_cbranchqi4 (test, XEXP (test, 0), XEXP (test, 1),
8614                                       label));
8615
8616       /* ??? If !TARGET_SSE_TYPELESS_STORES, would we perform better if
8617          we used movdqa (i.e. TImode) instead?  Perhaps even better would
8618          be if we could determine the real mode of the data, via a hook
8619          into pass_stdarg.  Ignore all that for now.  */
8620       smode = V4SFmode;
8621       if (crtl->stack_alignment_needed < GET_MODE_ALIGNMENT (smode))
8622         crtl->stack_alignment_needed = GET_MODE_ALIGNMENT (smode);
8623
8624       max = cum->sse_regno + cfun->va_list_fpr_size / 16;
8625       if (max > X86_64_SSE_REGPARM_MAX)
8626         max = X86_64_SSE_REGPARM_MAX;
8627
8628       for (i = cum->sse_regno; i < max; ++i)
8629         {
8630           mem = plus_constant (Pmode, save_area,
8631                                i * 16 + ix86_varargs_gpr_size);
8632           mem = gen_rtx_MEM (smode, mem);
8633           MEM_NOTRAP_P (mem) = 1;
8634           set_mem_alias_set (mem, set);
8635           set_mem_align (mem, GET_MODE_ALIGNMENT (smode));
8636
8637           emit_move_insn (mem, gen_rtx_REG (smode, SSE_REGNO (i)));
8638         }
8639
8640       emit_label (label);
8641     }
8642 }
8643
8644 static void
8645 setup_incoming_varargs_ms_64 (CUMULATIVE_ARGS *cum)
8646 {
8647   alias_set_type set = get_varargs_alias_set ();
8648   int i;
8649
8650   /* Reset to zero, as there might be a sysv vaarg used
8651      before.  */
8652   ix86_varargs_gpr_size = 0;
8653   ix86_varargs_fpr_size = 0;
8654
8655   for (i = cum->regno; i < X86_64_MS_REGPARM_MAX; i++)
8656     {
8657       rtx reg, mem;
8658
8659       mem = gen_rtx_MEM (Pmode,
8660                          plus_constant (Pmode, virtual_incoming_args_rtx,
8661                                         i * UNITS_PER_WORD));
8662       MEM_NOTRAP_P (mem) = 1;
8663       set_mem_alias_set (mem, set);
8664
8665       reg = gen_rtx_REG (Pmode, x86_64_ms_abi_int_parameter_registers[i]);
8666       emit_move_insn (mem, reg);
8667     }
8668 }
8669
8670 static void
8671 ix86_setup_incoming_varargs (cumulative_args_t cum_v, machine_mode mode,
8672                              tree type, int *, int no_rtl)
8673 {
8674   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
8675   CUMULATIVE_ARGS next_cum;
8676   tree fntype;
8677
8678   /* This argument doesn't appear to be used anymore.  Which is good,
8679      because the old code here didn't suppress rtl generation.  */
8680   gcc_assert (!no_rtl);
8681
8682   if (!TARGET_64BIT)
8683     return;
8684
8685   fntype = TREE_TYPE (current_function_decl);
8686
8687   /* For varargs, we do not want to skip the dummy va_dcl argument.
8688      For stdargs, we do want to skip the last named argument.  */
8689   next_cum = *cum;
8690   if (stdarg_p (fntype))
8691     ix86_function_arg_advance (pack_cumulative_args (&next_cum), mode, type,
8692                                true);
8693
8694   if (cum->call_abi == MS_ABI)
8695     setup_incoming_varargs_ms_64 (&next_cum);
8696   else
8697     setup_incoming_varargs_64 (&next_cum);
8698 }
8699
8700 static void
8701 ix86_setup_incoming_vararg_bounds (cumulative_args_t cum_v,
8702                                    enum machine_mode mode,
8703                                    tree type,
8704                                    int *pretend_size ATTRIBUTE_UNUSED,
8705                                    int no_rtl)
8706 {
8707   CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v);
8708   CUMULATIVE_ARGS next_cum;
8709   tree fntype;
8710   rtx save_area;
8711   int bnd_reg, i, max;
8712
8713   gcc_assert (!no_rtl);
8714
8715   /* Do nothing if we use plain pointer to argument area.  */
8716   if (!TARGET_64BIT || cum->call_abi == MS_ABI)
8717     return;
8718
8719   fntype = TREE_TYPE (current_function_decl);
8720
8721   /* For varargs, we do not want to skip the dummy va_dcl argument.
8722      For stdargs, we do want to skip the last named argument.  */
8723   next_cum = *cum;
8724   if (stdarg_p (fntype))
8725     ix86_function_arg_advance (pack_cumulative_args (&next_cum), mode, type,
8726                                true);
8727   save_area = frame_pointer_rtx;
8728
8729   max = cum->regno + cfun->va_list_gpr_size / UNITS_PER_WORD;
8730   if (max > X86_64_REGPARM_MAX)
8731     max = X86_64_REGPARM_MAX;
8732
8733   bnd_reg = cum->bnd_regno + cum->force_bnd_pass;
8734   if (chkp_function_instrumented_p (current_function_decl))
8735     for (i = cum->regno; i < max; i++)
8736       {
8737         rtx addr = plus_constant (Pmode, save_area, i * UNITS_PER_WORD);
8738         rtx reg = gen_rtx_REG (DImode,
8739                                x86_64_int_parameter_registers[i]);
8740         rtx ptr = reg;
8741         rtx bounds;
8742
8743         if (bnd_reg <= LAST_BND_REG)
8744           bounds = gen_rtx_REG (BNDmode, bnd_reg);
8745         else
8746           {
8747             rtx ldx_addr =
8748               plus_constant (Pmode, arg_pointer_rtx,
8749                              (LAST_BND_REG - bnd_reg) * GET_MODE_SIZE (Pmode));
8750             bounds = gen_reg_rtx (BNDmode);
8751             emit_insn (BNDmode == BND64mode
8752                        ? gen_bnd64_ldx (bounds, ldx_addr, ptr)
8753                        : gen_bnd32_ldx (bounds, ldx_addr, ptr));
8754           }
8755
8756         emit_insn (BNDmode == BND64mode
8757                    ? gen_bnd64_stx (addr, ptr, bounds)
8758                    : gen_bnd32_stx (addr, ptr, bounds));
8759
8760         bnd_reg++;
8761       }
8762 }
8763
8764
8765 /* Checks if TYPE is of kind va_list char *.  */
8766
8767 static bool
8768 is_va_list_char_pointer (tree type)
8769 {
8770   tree canonic;
8771
8772   /* For 32-bit it is always true.  */
8773   if (!TARGET_64BIT)
8774     return true;
8775   canonic = ix86_canonical_va_list_type (type);
8776   return (canonic == ms_va_list_type_node
8777           || (ix86_abi == MS_ABI && canonic == va_list_type_node));
8778 }
8779
8780 /* Implement va_start.  */
8781
8782 static void
8783 ix86_va_start (tree valist, rtx nextarg)
8784 {
8785   HOST_WIDE_INT words, n_gpr, n_fpr;
8786   tree f_gpr, f_fpr, f_ovf, f_sav;
8787   tree gpr, fpr, ovf, sav, t;
8788   tree type;
8789   rtx ovf_rtx;
8790
8791   if (flag_split_stack
8792       && cfun->machine->split_stack_varargs_pointer == NULL_RTX)
8793     {
8794       unsigned int scratch_regno;
8795
8796       /* When we are splitting the stack, we can't refer to the stack
8797          arguments using internal_arg_pointer, because they may be on
8798          the old stack.  The split stack prologue will arrange to
8799          leave a pointer to the old stack arguments in a scratch
8800          register, which we here copy to a pseudo-register.  The split
8801          stack prologue can't set the pseudo-register directly because
8802          it (the prologue) runs before any registers have been saved.  */
8803
8804       scratch_regno = split_stack_prologue_scratch_regno ();
8805       if (scratch_regno != INVALID_REGNUM)
8806         {
8807           rtx reg;
8808           rtx_insn *seq;
8809
8810           reg = gen_reg_rtx (Pmode);
8811           cfun->machine->split_stack_varargs_pointer = reg;
8812
8813           start_sequence ();
8814           emit_move_insn (reg, gen_rtx_REG (Pmode, scratch_regno));
8815           seq = get_insns ();
8816           end_sequence ();
8817
8818           push_topmost_sequence ();
8819           emit_insn_after (seq, entry_of_function ());
8820           pop_topmost_sequence ();
8821         }
8822     }
8823
8824   /* Only 64bit target needs something special.  */
8825   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
8826     {
8827       if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
8828         std_expand_builtin_va_start (valist, nextarg);
8829       else
8830         {
8831           rtx va_r, next;
8832
8833           va_r = expand_expr (valist, NULL_RTX, VOIDmode, EXPAND_WRITE);
8834           next = expand_binop (ptr_mode, add_optab,
8835                                cfun->machine->split_stack_varargs_pointer,
8836                                crtl->args.arg_offset_rtx,
8837                                NULL_RTX, 0, OPTAB_LIB_WIDEN);
8838           convert_move (va_r, next, 0);
8839
8840           /* Store zero bounds for va_list.  */
8841           if (chkp_function_instrumented_p (current_function_decl))
8842             chkp_expand_bounds_reset_for_mem (valist,
8843                                               make_tree (TREE_TYPE (valist),
8844                                                          next));
8845
8846         }
8847       return;
8848     }
8849
8850   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
8851   f_fpr = DECL_CHAIN (f_gpr);
8852   f_ovf = DECL_CHAIN (f_fpr);
8853   f_sav = DECL_CHAIN (f_ovf);
8854
8855   valist = build_simple_mem_ref (valist);
8856   TREE_TYPE (valist) = TREE_TYPE (sysv_va_list_type_node);
8857   /* The following should be folded into the MEM_REF offset.  */
8858   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr), unshare_expr (valist),
8859                 f_gpr, NULL_TREE);
8860   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), unshare_expr (valist),
8861                 f_fpr, NULL_TREE);
8862   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), unshare_expr (valist),
8863                 f_ovf, NULL_TREE);
8864   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), unshare_expr (valist),
8865                 f_sav, NULL_TREE);
8866
8867   /* Count number of gp and fp argument registers used.  */
8868   words = crtl->args.info.words;
8869   n_gpr = crtl->args.info.regno;
8870   n_fpr = crtl->args.info.sse_regno;
8871
8872   if (cfun->va_list_gpr_size)
8873     {
8874       type = TREE_TYPE (gpr);
8875       t = build2 (MODIFY_EXPR, type,
8876                   gpr, build_int_cst (type, n_gpr * 8));
8877       TREE_SIDE_EFFECTS (t) = 1;
8878       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
8879     }
8880
8881   if (TARGET_SSE && cfun->va_list_fpr_size)
8882     {
8883       type = TREE_TYPE (fpr);
8884       t = build2 (MODIFY_EXPR, type, fpr,
8885                   build_int_cst (type, n_fpr * 16 + 8*X86_64_REGPARM_MAX));
8886       TREE_SIDE_EFFECTS (t) = 1;
8887       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
8888     }
8889
8890   /* Find the overflow area.  */
8891   type = TREE_TYPE (ovf);
8892   if (cfun->machine->split_stack_varargs_pointer == NULL_RTX)
8893     ovf_rtx = crtl->args.internal_arg_pointer;
8894   else
8895     ovf_rtx = cfun->machine->split_stack_varargs_pointer;
8896   t = make_tree (type, ovf_rtx);
8897   if (words != 0)
8898     t = fold_build_pointer_plus_hwi (t, words * UNITS_PER_WORD);
8899
8900   /* Store zero bounds for overflow area pointer.  */
8901   if (chkp_function_instrumented_p (current_function_decl))
8902     chkp_expand_bounds_reset_for_mem (ovf, t);
8903
8904   t = build2 (MODIFY_EXPR, type, ovf, t);
8905   TREE_SIDE_EFFECTS (t) = 1;
8906   expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
8907
8908   if (ix86_varargs_gpr_size || ix86_varargs_fpr_size)
8909     {
8910       /* Find the register save area.
8911          Prologue of the function save it right above stack frame.  */
8912       type = TREE_TYPE (sav);
8913       t = make_tree (type, frame_pointer_rtx);
8914       if (!ix86_varargs_gpr_size)
8915         t = fold_build_pointer_plus_hwi (t, -8 * X86_64_REGPARM_MAX);
8916
8917       /* Store zero bounds for save area pointer.  */
8918       if (chkp_function_instrumented_p (current_function_decl))
8919         chkp_expand_bounds_reset_for_mem (sav, t);
8920
8921       t = build2 (MODIFY_EXPR, type, sav, t);
8922       TREE_SIDE_EFFECTS (t) = 1;
8923       expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
8924     }
8925 }
8926
8927 /* Implement va_arg.  */
8928
8929 static tree
8930 ix86_gimplify_va_arg (tree valist, tree type, gimple_seq *pre_p,
8931                       gimple_seq *post_p)
8932 {
8933   static const int intreg[6] = { 0, 1, 2, 3, 4, 5 };
8934   tree f_gpr, f_fpr, f_ovf, f_sav;
8935   tree gpr, fpr, ovf, sav, t;
8936   int size, rsize;
8937   tree lab_false, lab_over = NULL_TREE;
8938   tree addr, t2;
8939   rtx container;
8940   int indirect_p = 0;
8941   tree ptrtype;
8942   machine_mode nat_mode;
8943   unsigned int arg_boundary;
8944
8945   /* Only 64bit target needs something special.  */
8946   if (!TARGET_64BIT || is_va_list_char_pointer (TREE_TYPE (valist)))
8947     return std_gimplify_va_arg_expr (valist, type, pre_p, post_p);
8948
8949   f_gpr = TYPE_FIELDS (TREE_TYPE (sysv_va_list_type_node));
8950   f_fpr = DECL_CHAIN (f_gpr);
8951   f_ovf = DECL_CHAIN (f_fpr);
8952   f_sav = DECL_CHAIN (f_ovf);
8953
8954   gpr = build3 (COMPONENT_REF, TREE_TYPE (f_gpr),
8955                 build_va_arg_indirect_ref (valist), f_gpr, NULL_TREE);
8956   valist = build_va_arg_indirect_ref (valist);
8957   fpr = build3 (COMPONENT_REF, TREE_TYPE (f_fpr), valist, f_fpr, NULL_TREE);
8958   ovf = build3 (COMPONENT_REF, TREE_TYPE (f_ovf), valist, f_ovf, NULL_TREE);
8959   sav = build3 (COMPONENT_REF, TREE_TYPE (f_sav), valist, f_sav, NULL_TREE);
8960
8961   indirect_p = pass_by_reference (NULL, TYPE_MODE (type), type, false);
8962   if (indirect_p)
8963     type = build_pointer_type (type);
8964   size = int_size_in_bytes (type);
8965   rsize = (size + UNITS_PER_WORD - 1) / UNITS_PER_WORD;
8966
8967   nat_mode = type_natural_mode (type, NULL, false);
8968   switch (nat_mode)
8969     {
8970     case V8SFmode:
8971     case V8SImode:
8972     case V32QImode:
8973     case V16HImode:
8974     case V4DFmode:
8975     case V4DImode:
8976     case V16SFmode:
8977     case V16SImode:
8978     case V64QImode:
8979     case V32HImode:
8980     case V8DFmode:
8981     case V8DImode:
8982       /* Unnamed 256 and 512bit vector mode parameters are passed on stack.  */
8983       if (!TARGET_64BIT_MS_ABI)
8984         {
8985           container = NULL;
8986           break;
8987         }
8988
8989     default:
8990       container = construct_container (nat_mode, TYPE_MODE (type),
8991                                        type, 0, X86_64_REGPARM_MAX,
8992                                        X86_64_SSE_REGPARM_MAX, intreg,
8993                                        0);
8994       break;
8995     }
8996
8997   /* Pull the value out of the saved registers.  */
8998
8999   addr = create_tmp_var (ptr_type_node, "addr");
9000
9001   if (container)
9002     {
9003       int needed_intregs, needed_sseregs;
9004       bool need_temp;
9005       tree int_addr, sse_addr;
9006
9007       lab_false = create_artificial_label (UNKNOWN_LOCATION);
9008       lab_over = create_artificial_label (UNKNOWN_LOCATION);
9009
9010       examine_argument (nat_mode, type, 0, &needed_intregs, &needed_sseregs);
9011
9012       need_temp = (!REG_P (container)
9013                    && ((needed_intregs && TYPE_ALIGN (type) > 64)
9014                        || TYPE_ALIGN (type) > 128));
9015
9016       /* In case we are passing structure, verify that it is consecutive block
9017          on the register save area.  If not we need to do moves.  */
9018       if (!need_temp && !REG_P (container))
9019         {
9020           /* Verify that all registers are strictly consecutive  */
9021           if (SSE_REGNO_P (REGNO (XEXP (XVECEXP (container, 0, 0), 0))))
9022             {
9023               int i;
9024
9025               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
9026                 {
9027                   rtx slot = XVECEXP (container, 0, i);
9028                   if (REGNO (XEXP (slot, 0)) != FIRST_SSE_REG + (unsigned int) i
9029                       || INTVAL (XEXP (slot, 1)) != i * 16)
9030                     need_temp = true;
9031                 }
9032             }
9033           else
9034             {
9035               int i;
9036
9037               for (i = 0; i < XVECLEN (container, 0) && !need_temp; i++)
9038                 {
9039                   rtx slot = XVECEXP (container, 0, i);
9040                   if (REGNO (XEXP (slot, 0)) != (unsigned int) i
9041                       || INTVAL (XEXP (slot, 1)) != i * 8)
9042                     need_temp = true;
9043                 }
9044             }
9045         }
9046       if (!need_temp)
9047         {
9048           int_addr = addr;
9049           sse_addr = addr;
9050         }
9051       else
9052         {
9053           int_addr = create_tmp_var (ptr_type_node, "int_addr");
9054           sse_addr = create_tmp_var (ptr_type_node, "sse_addr");
9055         }
9056
9057       /* First ensure that we fit completely in registers.  */
9058       if (needed_intregs)
9059         {
9060           t = build_int_cst (TREE_TYPE (gpr),
9061                              (X86_64_REGPARM_MAX - needed_intregs + 1) * 8);
9062           t = build2 (GE_EXPR, boolean_type_node, gpr, t);
9063           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
9064           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
9065           gimplify_and_add (t, pre_p);
9066         }
9067       if (needed_sseregs)
9068         {
9069           t = build_int_cst (TREE_TYPE (fpr),
9070                              (X86_64_SSE_REGPARM_MAX - needed_sseregs + 1) * 16
9071                              + X86_64_REGPARM_MAX * 8);
9072           t = build2 (GE_EXPR, boolean_type_node, fpr, t);
9073           t2 = build1 (GOTO_EXPR, void_type_node, lab_false);
9074           t = build3 (COND_EXPR, void_type_node, t, t2, NULL_TREE);
9075           gimplify_and_add (t, pre_p);
9076         }
9077
9078       /* Compute index to start of area used for integer regs.  */
9079       if (needed_intregs)
9080         {
9081           /* int_addr = gpr + sav; */
9082           t = fold_build_pointer_plus (sav, gpr);
9083           gimplify_assign (int_addr, t, pre_p);
9084         }
9085       if (needed_sseregs)
9086         {
9087           /* sse_addr = fpr + sav; */
9088           t = fold_build_pointer_plus (sav, fpr);
9089           gimplify_assign (sse_addr, t, pre_p);
9090         }
9091       if (need_temp)
9092         {
9093           int i, prev_size = 0;
9094           tree temp = create_tmp_var (type, "va_arg_tmp");
9095
9096           /* addr = &temp; */
9097           t = build1 (ADDR_EXPR, build_pointer_type (type), temp);
9098           gimplify_assign (addr, t, pre_p);
9099
9100           for (i = 0; i < XVECLEN (container, 0); i++)
9101             {
9102               rtx slot = XVECEXP (container, 0, i);
9103               rtx reg = XEXP (slot, 0);
9104               machine_mode mode = GET_MODE (reg);
9105               tree piece_type;
9106               tree addr_type;
9107               tree daddr_type;
9108               tree src_addr, src;
9109               int src_offset;
9110               tree dest_addr, dest;
9111               int cur_size = GET_MODE_SIZE (mode);
9112
9113               gcc_assert (prev_size <= INTVAL (XEXP (slot, 1)));
9114               prev_size = INTVAL (XEXP (slot, 1));
9115               if (prev_size + cur_size > size)
9116                 {
9117                   cur_size = size - prev_size;
9118                   mode = mode_for_size (cur_size * BITS_PER_UNIT, MODE_INT, 1);
9119                   if (mode == BLKmode)
9120                     mode = QImode;
9121                 }
9122               piece_type = lang_hooks.types.type_for_mode (mode, 1);
9123               if (mode == GET_MODE (reg))
9124                 addr_type = build_pointer_type (piece_type);
9125               else
9126                 addr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
9127                                                          true);
9128               daddr_type = build_pointer_type_for_mode (piece_type, ptr_mode,
9129                                                         true);
9130
9131               if (SSE_REGNO_P (REGNO (reg)))
9132                 {
9133                   src_addr = sse_addr;
9134                   src_offset = (REGNO (reg) - FIRST_SSE_REG) * 16;
9135                 }
9136               else
9137                 {
9138                   src_addr = int_addr;
9139                   src_offset = REGNO (reg) * 8;
9140                 }
9141               src_addr = fold_convert (addr_type, src_addr);
9142               src_addr = fold_build_pointer_plus_hwi (src_addr, src_offset);
9143
9144               dest_addr = fold_convert (daddr_type, addr);
9145               dest_addr = fold_build_pointer_plus_hwi (dest_addr, prev_size);
9146               if (cur_size == GET_MODE_SIZE (mode))
9147                 {
9148                   src = build_va_arg_indirect_ref (src_addr);
9149                   dest = build_va_arg_indirect_ref (dest_addr);
9150
9151                   gimplify_assign (dest, src, pre_p);
9152                 }
9153               else
9154                 {
9155                   tree copy
9156                     = build_call_expr (builtin_decl_implicit (BUILT_IN_MEMCPY),
9157                                        3, dest_addr, src_addr,
9158                                        size_int (cur_size));
9159                   gimplify_and_add (copy, pre_p);
9160                 }
9161               prev_size += cur_size;
9162             }
9163         }
9164
9165       if (needed_intregs)
9166         {
9167           t = build2 (PLUS_EXPR, TREE_TYPE (gpr), gpr,
9168                       build_int_cst (TREE_TYPE (gpr), needed_intregs * 8));
9169           gimplify_assign (gpr, t, pre_p);
9170         }
9171
9172       if (needed_sseregs)
9173         {
9174           t = build2 (PLUS_EXPR, TREE_TYPE (fpr), fpr,
9175                       build_int_cst (TREE_TYPE (fpr), needed_sseregs * 16));
9176           gimplify_assign (fpr, t, pre_p);
9177         }
9178
9179       gimple_seq_add_stmt (pre_p, gimple_build_goto (lab_over));
9180
9181       gimple_seq_add_stmt (pre_p, gimple_build_label (lab_false));
9182     }
9183
9184   /* ... otherwise out of the overflow area.  */
9185
9186   /* When we align parameter on stack for caller, if the parameter
9187      alignment is beyond MAX_SUPPORTED_STACK_ALIGNMENT, it will be
9188      aligned at MAX_SUPPORTED_STACK_ALIGNMENT.  We will match callee
9189      here with caller.  */
9190   arg_boundary = ix86_function_arg_boundary (VOIDmode, type);
9191   if ((unsigned int) arg_boundary > MAX_SUPPORTED_STACK_ALIGNMENT)
9192     arg_boundary = MAX_SUPPORTED_STACK_ALIGNMENT;
9193
9194   /* Care for on-stack alignment if needed.  */
9195   if (arg_boundary <= 64 || size == 0)
9196     t = ovf;
9197  else
9198     {
9199       HOST_WIDE_INT align = arg_boundary / 8;
9200       t = fold_build_pointer_plus_hwi (ovf, align - 1);
9201       t = build2 (BIT_AND_EXPR, TREE_TYPE (t), t,
9202                   build_int_cst (TREE_TYPE (t), -align));
9203     }
9204
9205   gimplify_expr (&t, pre_p, NULL, is_gimple_val, fb_rvalue);
9206   gimplify_assign (addr, t, pre_p);
9207
9208   t = fold_build_pointer_plus_hwi (t, rsize * UNITS_PER_WORD);
9209   gimplify_assign (unshare_expr (ovf), t, pre_p);
9210
9211   if (container)
9212     gimple_seq_add_stmt (pre_p, gimple_build_label (lab_over));
9213
9214   ptrtype = build_pointer_type_for_mode (type, ptr_mode, true);
9215   addr = fold_convert (ptrtype, addr);
9216
9217   if (indirect_p)
9218     addr = build_va_arg_indirect_ref (addr);
9219   return build_va_arg_indirect_ref (addr);
9220 }
9221 \f
9222 /* Return true if OPNUM's MEM should be matched
9223    in movabs* patterns.  */
9224
9225 bool
9226 ix86_check_movabs (rtx insn, int opnum)
9227 {
9228   rtx set, mem;
9229
9230   set = PATTERN (insn);
9231   if (GET_CODE (set) == PARALLEL)
9232     set = XVECEXP (set, 0, 0);
9233   gcc_assert (GET_CODE (set) == SET);
9234   mem = XEXP (set, opnum);
9235   while (GET_CODE (mem) == SUBREG)
9236     mem = SUBREG_REG (mem);
9237   gcc_assert (MEM_P (mem));
9238   return volatile_ok || !MEM_VOLATILE_P (mem);
9239 }
9240 \f
9241 /* Initialize the table of extra 80387 mathematical constants.  */
9242
9243 static void
9244 init_ext_80387_constants (void)
9245 {
9246   static const char * cst[5] =
9247   {
9248     "0.3010299956639811952256464283594894482",  /* 0: fldlg2  */
9249     "0.6931471805599453094286904741849753009",  /* 1: fldln2  */
9250     "1.4426950408889634073876517827983434472",  /* 2: fldl2e  */
9251     "3.3219280948873623478083405569094566090",  /* 3: fldl2t  */
9252     "3.1415926535897932385128089594061862044",  /* 4: fldpi   */
9253   };
9254   int i;
9255
9256   for (i = 0; i < 5; i++)
9257     {
9258       real_from_string (&ext_80387_constants_table[i], cst[i]);
9259       /* Ensure each constant is rounded to XFmode precision.  */
9260       real_convert (&ext_80387_constants_table[i],
9261                     XFmode, &ext_80387_constants_table[i]);
9262     }
9263
9264   ext_80387_constants_init = 1;
9265 }
9266
9267 /* Return non-zero if the constant is something that
9268    can be loaded with a special instruction.  */
9269
9270 int
9271 standard_80387_constant_p (rtx x)
9272 {
9273   machine_mode mode = GET_MODE (x);
9274
9275   REAL_VALUE_TYPE r;
9276
9277   if (!(X87_FLOAT_MODE_P (mode) && (GET_CODE (x) == CONST_DOUBLE)))
9278     return -1;
9279
9280   if (x == CONST0_RTX (mode))
9281     return 1;
9282   if (x == CONST1_RTX (mode))
9283     return 2;
9284
9285   REAL_VALUE_FROM_CONST_DOUBLE (r, x);
9286
9287   /* For XFmode constants, try to find a special 80387 instruction when
9288      optimizing for size or on those CPUs that benefit from them.  */
9289   if (mode == XFmode
9290       && (optimize_function_for_size_p (cfun) || TARGET_EXT_80387_CONSTANTS))
9291     {
9292       int i;
9293
9294       if (! ext_80387_constants_init)
9295         init_ext_80387_constants ();
9296
9297       for (i = 0; i < 5; i++)
9298         if (real_identical (&r, &ext_80387_constants_table[i]))
9299           return i + 3;
9300     }
9301
9302   /* Load of the constant -0.0 or -1.0 will be split as
9303      fldz;fchs or fld1;fchs sequence.  */
9304   if (real_isnegzero (&r))
9305     return 8;
9306   if (real_identical (&r, &dconstm1))
9307     return 9;
9308
9309   return 0;
9310 }
9311
9312 /* Return the opcode of the special instruction to be used to load
9313    the constant X.  */
9314
9315 const char *
9316 standard_80387_constant_opcode (rtx x)
9317 {
9318   switch (standard_80387_constant_p (x))
9319     {
9320     case 1:
9321       return "fldz";
9322     case 2:
9323       return "fld1";
9324     case 3:
9325       return "fldlg2";
9326     case 4:
9327       return "fldln2";
9328     case 5:
9329       return "fldl2e";
9330     case 6:
9331       return "fldl2t";
9332     case 7:
9333       return "fldpi";
9334     case 8:
9335     case 9:
9336       return "#";
9337     default:
9338       gcc_unreachable ();
9339     }
9340 }
9341
9342 /* Return the CONST_DOUBLE representing the 80387 constant that is
9343    loaded by the specified special instruction.  The argument IDX
9344    matches the return value from standard_80387_constant_p.  */
9345
9346 rtx
9347 standard_80387_constant_rtx (int idx)
9348 {
9349   int i;
9350
9351   if (! ext_80387_constants_init)
9352     init_ext_80387_constants ();
9353
9354   switch (idx)
9355     {
9356     case 3:
9357     case 4:
9358     case 5:
9359     case 6:
9360     case 7:
9361       i = idx - 3;
9362       break;
9363
9364     default:
9365       gcc_unreachable ();
9366     }
9367
9368   return CONST_DOUBLE_FROM_REAL_VALUE (ext_80387_constants_table[i],
9369                                        XFmode);
9370 }
9371
9372 /* Return 1 if X is all 0s and 2 if x is all 1s
9373    in supported SSE/AVX vector mode.  */
9374
9375 int
9376 standard_sse_constant_p (rtx x)
9377 {
9378   machine_mode mode = GET_MODE (x);
9379
9380   if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
9381     return 1;
9382   if (vector_all_ones_operand (x, mode))
9383     switch (mode)
9384       {
9385       case V16QImode:
9386       case V8HImode:
9387       case V4SImode:
9388       case V2DImode:
9389         if (TARGET_SSE2)
9390           return 2;
9391       case V32QImode:
9392       case V16HImode:
9393       case V8SImode:
9394       case V4DImode:
9395         if (TARGET_AVX2)
9396           return 2;
9397       case V64QImode:
9398       case V32HImode:
9399       case V16SImode:
9400       case V8DImode:
9401         if (TARGET_AVX512F)
9402           return 2;
9403       default:
9404         break;
9405       }
9406
9407   return 0;
9408 }
9409
9410 /* Return the opcode of the special instruction to be used to load
9411    the constant X.  */
9412
9413 const char *
9414 standard_sse_constant_opcode (rtx_insn *insn, rtx x)
9415 {
9416   switch (standard_sse_constant_p (x))
9417     {
9418     case 1:
9419       switch (get_attr_mode (insn))
9420         {
9421         case MODE_XI:
9422           return "vpxord\t%g0, %g0, %g0";
9423         case MODE_V16SF:
9424           return TARGET_AVX512DQ ? "vxorps\t%g0, %g0, %g0"
9425                                  : "vpxord\t%g0, %g0, %g0";
9426         case MODE_V8DF:
9427           return TARGET_AVX512DQ ? "vxorpd\t%g0, %g0, %g0"
9428                                  : "vpxorq\t%g0, %g0, %g0";
9429         case MODE_TI:
9430           return TARGET_AVX512VL ? "vpxord\t%t0, %t0, %t0"
9431                                  : "%vpxor\t%0, %d0";
9432         case MODE_V2DF:
9433           return "%vxorpd\t%0, %d0";
9434         case MODE_V4SF:
9435           return "%vxorps\t%0, %d0";
9436
9437         case MODE_OI:
9438           return TARGET_AVX512VL ? "vpxord\t%x0, %x0, %x0"
9439                                  : "vpxor\t%x0, %x0, %x0";
9440         case MODE_V4DF:
9441           return "vxorpd\t%x0, %x0, %x0";
9442         case MODE_V8SF:
9443           return "vxorps\t%x0, %x0, %x0";
9444
9445         default:
9446           break;
9447         }
9448
9449     case 2:
9450       if (TARGET_AVX512VL
9451           || get_attr_mode (insn) == MODE_XI
9452           || get_attr_mode (insn) == MODE_V8DF
9453           || get_attr_mode (insn) == MODE_V16SF)
9454         return "vpternlogd\t{$0xFF, %g0, %g0, %g0|%g0, %g0, %g0, 0xFF}";
9455       if (TARGET_AVX)
9456         return "vpcmpeqd\t%0, %0, %0";
9457       else
9458         return "pcmpeqd\t%0, %0";
9459
9460     default:
9461       break;
9462     }
9463   gcc_unreachable ();
9464 }
9465
9466 /* Returns true if OP contains a symbol reference */
9467
9468 bool
9469 symbolic_reference_mentioned_p (rtx op)
9470 {
9471   const char *fmt;
9472   int i;
9473
9474   if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF)
9475     return true;
9476
9477   fmt = GET_RTX_FORMAT (GET_CODE (op));
9478   for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--)
9479     {
9480       if (fmt[i] == 'E')
9481         {
9482           int j;
9483
9484           for (j = XVECLEN (op, i) - 1; j >= 0; j--)
9485             if (symbolic_reference_mentioned_p (XVECEXP (op, i, j)))
9486               return true;
9487         }
9488
9489       else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i)))
9490         return true;
9491     }
9492
9493   return false;
9494 }
9495
9496 /* Return true if it is appropriate to emit `ret' instructions in the
9497    body of a function.  Do this only if the epilogue is simple, needing a
9498    couple of insns.  Prior to reloading, we can't tell how many registers
9499    must be saved, so return false then.  Return false if there is no frame
9500    marker to de-allocate.  */
9501
9502 bool
9503 ix86_can_use_return_insn_p (void)
9504 {
9505   struct ix86_frame frame;
9506
9507   if (! reload_completed || frame_pointer_needed)
9508     return 0;
9509
9510   /* Don't allow more than 32k pop, since that's all we can do
9511      with one instruction.  */
9512   if (crtl->args.pops_args && crtl->args.size >= 32768)
9513     return 0;
9514
9515   ix86_compute_frame_layout (&frame);
9516   return (frame.stack_pointer_offset == UNITS_PER_WORD
9517           && (frame.nregs + frame.nsseregs) == 0);
9518 }
9519 \f
9520 /* Value should be nonzero if functions must have frame pointers.
9521    Zero means the frame pointer need not be set up (and parms may
9522    be accessed via the stack pointer) in functions that seem suitable.  */
9523
9524 static bool
9525 ix86_frame_pointer_required (void)
9526 {
9527   /* If we accessed previous frames, then the generated code expects
9528      to be able to access the saved ebp value in our frame.  */
9529   if (cfun->machine->accesses_prev_frame)
9530     return true;
9531
9532   /* Several x86 os'es need a frame pointer for other reasons,
9533      usually pertaining to setjmp.  */
9534   if (SUBTARGET_FRAME_POINTER_REQUIRED)
9535     return true;
9536
9537   /* For older 32-bit runtimes setjmp requires valid frame-pointer.  */
9538   if (TARGET_32BIT_MS_ABI && cfun->calls_setjmp)
9539     return true;
9540
9541   /* Win64 SEH, very large frames need a frame-pointer as maximum stack
9542      allocation is 4GB.  */
9543   if (TARGET_64BIT_MS_ABI && get_frame_size () > SEH_MAX_FRAME_SIZE)
9544     return true;
9545
9546   /* In ix86_option_override_internal, TARGET_OMIT_LEAF_FRAME_POINTER
9547      turns off the frame pointer by default.  Turn it back on now if
9548      we've not got a leaf function.  */
9549   if (TARGET_OMIT_LEAF_FRAME_POINTER
9550       && (!crtl->is_leaf
9551           || ix86_current_function_calls_tls_descriptor))
9552     return true;
9553
9554   if (crtl->profile && !flag_fentry)
9555     return true;
9556
9557   return false;
9558 }
9559
9560 /* Record that the current function accesses previous call frames.  */
9561
9562 void
9563 ix86_setup_frame_addresses (void)
9564 {
9565   cfun->machine->accesses_prev_frame = 1;
9566 }
9567 \f
9568 #ifndef USE_HIDDEN_LINKONCE
9569 # if defined(HAVE_GAS_HIDDEN) && (SUPPORTS_ONE_ONLY - 0)
9570 #  define USE_HIDDEN_LINKONCE 1
9571 # else
9572 #  define USE_HIDDEN_LINKONCE 0
9573 # endif
9574 #endif
9575
9576 static int pic_labels_used;
9577
9578 /* Fills in the label name that should be used for a pc thunk for
9579    the given register.  */
9580
9581 static void
9582 get_pc_thunk_name (char name[32], unsigned int regno)
9583 {
9584   gcc_assert (!TARGET_64BIT);
9585
9586   if (USE_HIDDEN_LINKONCE)
9587     sprintf (name, "__x86.get_pc_thunk.%s", reg_names[regno]);
9588   else
9589     ASM_GENERATE_INTERNAL_LABEL (name, "LPR", regno);
9590 }
9591
9592
9593 /* This function generates code for -fpic that loads %ebx with
9594    the return address of the caller and then returns.  */
9595
9596 static void
9597 ix86_code_end (void)
9598 {
9599   rtx xops[2];
9600   int regno;
9601
9602   for (regno = AX_REG; regno <= SP_REG; regno++)
9603     {
9604       char name[32];
9605       tree decl;
9606
9607       if (!(pic_labels_used & (1 << regno)))
9608         continue;
9609
9610       get_pc_thunk_name (name, regno);
9611
9612       decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL,
9613                          get_identifier (name),
9614                          build_function_type_list (void_type_node, NULL_TREE));
9615       DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL,
9616                                        NULL_TREE, void_type_node);
9617       TREE_PUBLIC (decl) = 1;
9618       TREE_STATIC (decl) = 1;
9619       DECL_IGNORED_P (decl) = 1;
9620
9621 #if TARGET_MACHO
9622       if (TARGET_MACHO)
9623         {
9624           switch_to_section (darwin_sections[text_coal_section]);
9625           fputs ("\t.weak_definition\t", asm_out_file);
9626           assemble_name (asm_out_file, name);
9627           fputs ("\n\t.private_extern\t", asm_out_file);
9628           assemble_name (asm_out_file, name);
9629           putc ('\n', asm_out_file);
9630           ASM_OUTPUT_LABEL (asm_out_file, name);
9631           DECL_WEAK (decl) = 1;
9632         }
9633       else
9634 #endif
9635       if (USE_HIDDEN_LINKONCE)
9636         {
9637           cgraph_node::create (decl)->set_comdat_group (DECL_ASSEMBLER_NAME (decl));
9638
9639           targetm.asm_out.unique_section (decl, 0);
9640           switch_to_section (get_named_section (decl, NULL, 0));
9641
9642           targetm.asm_out.globalize_label (asm_out_file, name);
9643           fputs ("\t.hidden\t", asm_out_file);
9644           assemble_name (asm_out_file, name);
9645           putc ('\n', asm_out_file);
9646           ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl);
9647         }
9648       else
9649         {
9650           switch_to_section (text_section);
9651           ASM_OUTPUT_LABEL (asm_out_file, name);
9652         }
9653
9654       DECL_INITIAL (decl) = make_node (BLOCK);
9655       current_function_decl = decl;
9656       init_function_start (decl);
9657       first_function_block_is_cold = false;
9658       /* Make sure unwind info is emitted for the thunk if needed.  */
9659       final_start_function (emit_barrier (), asm_out_file, 1);
9660
9661       /* Pad stack IP move with 4 instructions (two NOPs count
9662          as one instruction).  */
9663       if (TARGET_PAD_SHORT_FUNCTION)
9664         {
9665           int i = 8;
9666
9667           while (i--)
9668             fputs ("\tnop\n", asm_out_file);
9669         }
9670
9671       xops[0] = gen_rtx_REG (Pmode, regno);
9672       xops[1] = gen_rtx_MEM (Pmode, stack_pointer_rtx);
9673       output_asm_insn ("mov%z0\t{%1, %0|%0, %1}", xops);
9674       output_asm_insn ("%!ret", NULL);
9675       final_end_function ();
9676       init_insn_lengths ();
9677       free_after_compilation (cfun);
9678       set_cfun (NULL);
9679       current_function_decl = NULL;
9680     }
9681
9682   if (flag_split_stack)
9683     file_end_indicate_split_stack ();
9684 }
9685
9686 /* Emit code for the SET_GOT patterns.  */
9687
9688 const char *
9689 output_set_got (rtx dest, rtx label)
9690 {
9691   rtx xops[3];
9692
9693   xops[0] = dest;
9694
9695   if (TARGET_VXWORKS_RTP && flag_pic)
9696     {
9697       /* Load (*VXWORKS_GOTT_BASE) into the PIC register.  */
9698       xops[2] = gen_rtx_MEM (Pmode,
9699                              gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_BASE));
9700       output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops);
9701
9702       /* Load (*VXWORKS_GOTT_BASE)[VXWORKS_GOTT_INDEX] into the PIC register.
9703          Use %P and a local symbol in order to print VXWORKS_GOTT_INDEX as
9704          an unadorned address.  */
9705       xops[2] = gen_rtx_SYMBOL_REF (Pmode, VXWORKS_GOTT_INDEX);
9706       SYMBOL_REF_FLAGS (xops[2]) |= SYMBOL_FLAG_LOCAL;
9707       output_asm_insn ("mov{l}\t{%P2(%0), %0|%0, DWORD PTR %P2[%0]}", xops);
9708       return "";
9709     }
9710
9711   xops[1] = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
9712
9713   if (!flag_pic)
9714     {
9715       if (TARGET_MACHO)
9716         /* We don't need a pic base, we're not producing pic.  */
9717         gcc_unreachable ();
9718
9719       xops[2] = gen_rtx_LABEL_REF (Pmode, label ? label : gen_label_rtx ());
9720       output_asm_insn ("mov%z0\t{%2, %0|%0, %2}", xops);
9721       targetm.asm_out.internal_label (asm_out_file, "L",
9722                                       CODE_LABEL_NUMBER (XEXP (xops[2], 0)));
9723     }
9724   else
9725     {
9726       char name[32];
9727       get_pc_thunk_name (name, REGNO (dest));
9728       pic_labels_used |= 1 << REGNO (dest);
9729
9730       xops[2] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (name));
9731       xops[2] = gen_rtx_MEM (QImode, xops[2]);
9732       output_asm_insn ("%!call\t%X2", xops);
9733
9734 #if TARGET_MACHO
9735       /* Output the Mach-O "canonical" pic base label name ("Lxx$pb") here.
9736          This is what will be referenced by the Mach-O PIC subsystem.  */
9737       if (machopic_should_output_picbase_label () || !label)
9738         ASM_OUTPUT_LABEL (asm_out_file, MACHOPIC_FUNCTION_BASE_NAME);
9739
9740       /* When we are restoring the pic base at the site of a nonlocal label,
9741          and we decided to emit the pic base above, we will still output a
9742          local label used for calculating the correction offset (even though
9743          the offset will be 0 in that case).  */
9744       if (label)
9745         targetm.asm_out.internal_label (asm_out_file, "L",
9746                                            CODE_LABEL_NUMBER (label));
9747 #endif
9748     }
9749
9750   if (!TARGET_MACHO)
9751     output_asm_insn ("add%z0\t{%1, %0|%0, %1}", xops);
9752
9753   return "";
9754 }
9755
9756 /* Generate an "push" pattern for input ARG.  */
9757
9758 static rtx
9759 gen_push (rtx arg)
9760 {
9761   struct machine_function *m = cfun->machine;
9762
9763   if (m->fs.cfa_reg == stack_pointer_rtx)
9764     m->fs.cfa_offset += UNITS_PER_WORD;
9765   m->fs.sp_offset += UNITS_PER_WORD;
9766
9767   if (REG_P (arg) && GET_MODE (arg) != word_mode)
9768     arg = gen_rtx_REG (word_mode, REGNO (arg));
9769
9770   return gen_rtx_SET (VOIDmode,
9771                       gen_rtx_MEM (word_mode,
9772                                    gen_rtx_PRE_DEC (Pmode,
9773                                                     stack_pointer_rtx)),
9774                       arg);
9775 }
9776
9777 /* Generate an "pop" pattern for input ARG.  */
9778
9779 static rtx
9780 gen_pop (rtx arg)
9781 {
9782   if (REG_P (arg) && GET_MODE (arg) != word_mode)
9783     arg = gen_rtx_REG (word_mode, REGNO (arg));
9784
9785   return gen_rtx_SET (VOIDmode,
9786                       arg,
9787                       gen_rtx_MEM (word_mode,
9788                                    gen_rtx_POST_INC (Pmode,
9789                                                      stack_pointer_rtx)));
9790 }
9791
9792 /* Return >= 0 if there is an unused call-clobbered register available
9793    for the entire function.  */
9794
9795 static unsigned int
9796 ix86_select_alt_pic_regnum (void)
9797 {
9798   if (ix86_use_pseudo_pic_reg ())
9799     return INVALID_REGNUM;
9800
9801   if (crtl->is_leaf
9802       && !crtl->profile
9803       && !ix86_current_function_calls_tls_descriptor)
9804     {
9805       int i, drap;
9806       /* Can't use the same register for both PIC and DRAP.  */
9807       if (crtl->drap_reg)
9808         drap = REGNO (crtl->drap_reg);
9809       else
9810         drap = -1;
9811       for (i = 2; i >= 0; --i)
9812         if (i != drap && !df_regs_ever_live_p (i))
9813           return i;
9814     }
9815
9816   return INVALID_REGNUM;
9817 }
9818
9819 /* Return TRUE if we need to save REGNO.  */
9820
9821 static bool
9822 ix86_save_reg (unsigned int regno, bool maybe_eh_return)
9823 {
9824   if (regno == REAL_PIC_OFFSET_TABLE_REGNUM
9825       && pic_offset_table_rtx)
9826     {
9827       if (ix86_use_pseudo_pic_reg ())
9828         {
9829           /* REAL_PIC_OFFSET_TABLE_REGNUM used by call to
9830           _mcount in prologue.  */
9831           if (!TARGET_64BIT && flag_pic && crtl->profile)
9832             return true;
9833         }
9834       else if (df_regs_ever_live_p (REAL_PIC_OFFSET_TABLE_REGNUM)
9835                || crtl->profile
9836                || crtl->calls_eh_return
9837                || crtl->uses_const_pool
9838                || cfun->has_nonlocal_label)
9839         return ix86_select_alt_pic_regnum () == INVALID_REGNUM;
9840     }
9841
9842   if (crtl->calls_eh_return && maybe_eh_return)
9843     {
9844       unsigned i;
9845       for (i = 0; ; i++)
9846         {
9847           unsigned test = EH_RETURN_DATA_REGNO (i);
9848           if (test == INVALID_REGNUM)
9849             break;
9850           if (test == regno)
9851             return true;
9852         }
9853     }
9854
9855   if (crtl->drap_reg
9856       && regno == REGNO (crtl->drap_reg)
9857       && !cfun->machine->no_drap_save_restore)
9858     return true;
9859
9860   return (df_regs_ever_live_p (regno)
9861           && !call_used_regs[regno]
9862           && !fixed_regs[regno]
9863           && (regno != HARD_FRAME_POINTER_REGNUM || !frame_pointer_needed));
9864 }
9865
9866 /* Return number of saved general prupose registers.  */
9867
9868 static int
9869 ix86_nsaved_regs (void)
9870 {
9871   int nregs = 0;
9872   int regno;
9873
9874   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9875     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
9876       nregs ++;
9877   return nregs;
9878 }
9879
9880 /* Return number of saved SSE registrers.  */
9881
9882 static int
9883 ix86_nsaved_sseregs (void)
9884 {
9885   int nregs = 0;
9886   int regno;
9887
9888   if (!TARGET_64BIT_MS_ABI)
9889     return 0;
9890   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
9891     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
9892       nregs ++;
9893   return nregs;
9894 }
9895
9896 /* Given FROM and TO register numbers, say whether this elimination is
9897    allowed.  If stack alignment is needed, we can only replace argument
9898    pointer with hard frame pointer, or replace frame pointer with stack
9899    pointer.  Otherwise, frame pointer elimination is automatically
9900    handled and all other eliminations are valid.  */
9901
9902 static bool
9903 ix86_can_eliminate (const int from, const int to)
9904 {
9905   if (stack_realign_fp)
9906     return ((from == ARG_POINTER_REGNUM
9907              && to == HARD_FRAME_POINTER_REGNUM)
9908             || (from == FRAME_POINTER_REGNUM
9909                 && to == STACK_POINTER_REGNUM));
9910   else
9911     return to == STACK_POINTER_REGNUM ? !frame_pointer_needed : true;
9912 }
9913
9914 /* Return the offset between two registers, one to be eliminated, and the other
9915    its replacement, at the start of a routine.  */
9916
9917 HOST_WIDE_INT
9918 ix86_initial_elimination_offset (int from, int to)
9919 {
9920   struct ix86_frame frame;
9921   ix86_compute_frame_layout (&frame);
9922
9923   if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
9924     return frame.hard_frame_pointer_offset;
9925   else if (from == FRAME_POINTER_REGNUM
9926            && to == HARD_FRAME_POINTER_REGNUM)
9927     return frame.hard_frame_pointer_offset - frame.frame_pointer_offset;
9928   else
9929     {
9930       gcc_assert (to == STACK_POINTER_REGNUM);
9931
9932       if (from == ARG_POINTER_REGNUM)
9933         return frame.stack_pointer_offset;
9934
9935       gcc_assert (from == FRAME_POINTER_REGNUM);
9936       return frame.stack_pointer_offset - frame.frame_pointer_offset;
9937     }
9938 }
9939
9940 /* In a dynamically-aligned function, we can't know the offset from
9941    stack pointer to frame pointer, so we must ensure that setjmp
9942    eliminates fp against the hard fp (%ebp) rather than trying to
9943    index from %esp up to the top of the frame across a gap that is
9944    of unknown (at compile-time) size.  */
9945 static rtx
9946 ix86_builtin_setjmp_frame_value (void)
9947 {
9948   return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx;
9949 }
9950
9951 /* When using -fsplit-stack, the allocation routines set a field in
9952    the TCB to the bottom of the stack plus this much space, measured
9953    in bytes.  */
9954
9955 #define SPLIT_STACK_AVAILABLE 256
9956
9957 /* Fill structure ix86_frame about frame of currently computed function.  */
9958
9959 static void
9960 ix86_compute_frame_layout (struct ix86_frame *frame)
9961 {
9962   unsigned HOST_WIDE_INT stack_alignment_needed;
9963   HOST_WIDE_INT offset;
9964   unsigned HOST_WIDE_INT preferred_alignment;
9965   HOST_WIDE_INT size = get_frame_size ();
9966   HOST_WIDE_INT to_allocate;
9967
9968   frame->nregs = ix86_nsaved_regs ();
9969   frame->nsseregs = ix86_nsaved_sseregs ();
9970
9971   /* 64-bit MS ABI seem to require stack alignment to be always 16 except for
9972      function prologues and leaf.  */
9973   if ((TARGET_64BIT_MS_ABI && crtl->preferred_stack_boundary < 128)
9974       && (!crtl->is_leaf || cfun->calls_alloca != 0
9975           || ix86_current_function_calls_tls_descriptor))
9976     {
9977       crtl->preferred_stack_boundary = 128;
9978       crtl->stack_alignment_needed = 128;
9979     }
9980   /* preferred_stack_boundary is never updated for call
9981      expanded from tls descriptor. Update it here. We don't update it in
9982      expand stage because according to the comments before
9983      ix86_current_function_calls_tls_descriptor, tls calls may be optimized
9984      away.  */
9985   else if (ix86_current_function_calls_tls_descriptor
9986            && crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY)
9987     {
9988       crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY;
9989       if (crtl->stack_alignment_needed < PREFERRED_STACK_BOUNDARY)
9990         crtl->stack_alignment_needed = PREFERRED_STACK_BOUNDARY;
9991     }
9992
9993   stack_alignment_needed = crtl->stack_alignment_needed / BITS_PER_UNIT;
9994   preferred_alignment = crtl->preferred_stack_boundary / BITS_PER_UNIT;
9995
9996   gcc_assert (!size || stack_alignment_needed);
9997   gcc_assert (preferred_alignment >= STACK_BOUNDARY / BITS_PER_UNIT);
9998   gcc_assert (preferred_alignment <= stack_alignment_needed);
9999
10000   /* For SEH we have to limit the amount of code movement into the prologue.
10001      At present we do this via a BLOCKAGE, at which point there's very little
10002      scheduling that can be done, which means that there's very little point
10003      in doing anything except PUSHs.  */
10004   if (TARGET_SEH)
10005     cfun->machine->use_fast_prologue_epilogue = false;
10006
10007   /* During reload iteration the amount of registers saved can change.
10008      Recompute the value as needed.  Do not recompute when amount of registers
10009      didn't change as reload does multiple calls to the function and does not
10010      expect the decision to change within single iteration.  */
10011   else if (!optimize_bb_for_size_p (ENTRY_BLOCK_PTR_FOR_FN (cfun))
10012            && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs)
10013     {
10014       int count = frame->nregs;
10015       struct cgraph_node *node = cgraph_node::get (current_function_decl);
10016
10017       cfun->machine->use_fast_prologue_epilogue_nregs = count;
10018
10019       /* The fast prologue uses move instead of push to save registers.  This
10020          is significantly longer, but also executes faster as modern hardware
10021          can execute the moves in parallel, but can't do that for push/pop.
10022
10023          Be careful about choosing what prologue to emit:  When function takes
10024          many instructions to execute we may use slow version as well as in
10025          case function is known to be outside hot spot (this is known with
10026          feedback only).  Weight the size of function by number of registers
10027          to save as it is cheap to use one or two push instructions but very
10028          slow to use many of them.  */
10029       if (count)
10030         count = (count - 1) * FAST_PROLOGUE_INSN_COUNT;
10031       if (node->frequency < NODE_FREQUENCY_NORMAL
10032           || (flag_branch_probabilities
10033               && node->frequency < NODE_FREQUENCY_HOT))
10034         cfun->machine->use_fast_prologue_epilogue = false;
10035       else
10036         cfun->machine->use_fast_prologue_epilogue
10037            = !expensive_function_p (count);
10038     }
10039
10040   frame->save_regs_using_mov
10041     = (TARGET_PROLOGUE_USING_MOVE && cfun->machine->use_fast_prologue_epilogue
10042        /* If static stack checking is enabled and done with probes,
10043           the registers need to be saved before allocating the frame.  */
10044        && flag_stack_check != STATIC_BUILTIN_STACK_CHECK);
10045
10046   /* Skip return address.  */
10047   offset = UNITS_PER_WORD;
10048
10049   /* Skip pushed static chain.  */
10050   if (ix86_static_chain_on_stack)
10051     offset += UNITS_PER_WORD;
10052
10053   /* Skip saved base pointer.  */
10054   if (frame_pointer_needed)
10055     offset += UNITS_PER_WORD;
10056   frame->hfp_save_offset = offset;
10057
10058   /* The traditional frame pointer location is at the top of the frame.  */
10059   frame->hard_frame_pointer_offset = offset;
10060
10061   /* Register save area */
10062   offset += frame->nregs * UNITS_PER_WORD;
10063   frame->reg_save_offset = offset;
10064
10065   /* On SEH target, registers are pushed just before the frame pointer
10066      location.  */
10067   if (TARGET_SEH)
10068     frame->hard_frame_pointer_offset = offset;
10069
10070   /* Align and set SSE register save area.  */
10071   if (frame->nsseregs)
10072     {
10073       /* The only ABI that has saved SSE registers (Win64) also has a
10074          16-byte aligned default stack, and thus we don't need to be
10075          within the re-aligned local stack frame to save them.  */
10076       gcc_assert (INCOMING_STACK_BOUNDARY >= 128);
10077       offset = (offset + 16 - 1) & -16;
10078       offset += frame->nsseregs * 16;
10079     }
10080   frame->sse_reg_save_offset = offset;
10081
10082   /* The re-aligned stack starts here.  Values before this point are not
10083      directly comparable with values below this point.  In order to make
10084      sure that no value happens to be the same before and after, force
10085      the alignment computation below to add a non-zero value.  */
10086   if (stack_realign_fp)
10087     offset = (offset + stack_alignment_needed) & -stack_alignment_needed;
10088
10089   /* Va-arg area */
10090   frame->va_arg_size = ix86_varargs_gpr_size + ix86_varargs_fpr_size;
10091   offset += frame->va_arg_size;
10092
10093   /* Align start of frame for local function.  */
10094   if (stack_realign_fp
10095       || offset != frame->sse_reg_save_offset
10096       || size != 0
10097       || !crtl->is_leaf
10098       || cfun->calls_alloca
10099       || ix86_current_function_calls_tls_descriptor)
10100     offset = (offset + stack_alignment_needed - 1) & -stack_alignment_needed;
10101
10102   /* Frame pointer points here.  */
10103   frame->frame_pointer_offset = offset;
10104
10105   offset += size;
10106
10107   /* Add outgoing arguments area.  Can be skipped if we eliminated
10108      all the function calls as dead code.
10109      Skipping is however impossible when function calls alloca.  Alloca
10110      expander assumes that last crtl->outgoing_args_size
10111      of stack frame are unused.  */
10112   if (ACCUMULATE_OUTGOING_ARGS
10113       && (!crtl->is_leaf || cfun->calls_alloca
10114           || ix86_current_function_calls_tls_descriptor))
10115     {
10116       offset += crtl->outgoing_args_size;
10117       frame->outgoing_arguments_size = crtl->outgoing_args_size;
10118     }
10119   else
10120     frame->outgoing_arguments_size = 0;
10121
10122   /* Align stack boundary.  Only needed if we're calling another function
10123      or using alloca.  */
10124   if (!crtl->is_leaf || cfun->calls_alloca
10125       || ix86_current_function_calls_tls_descriptor)
10126     offset = (offset + preferred_alignment - 1) & -preferred_alignment;
10127
10128   /* We've reached end of stack frame.  */
10129   frame->stack_pointer_offset = offset;
10130
10131   /* Size prologue needs to allocate.  */
10132   to_allocate = offset - frame->sse_reg_save_offset;
10133
10134   if ((!to_allocate && frame->nregs <= 1)
10135       || (TARGET_64BIT && to_allocate >= (HOST_WIDE_INT) 0x80000000))
10136     frame->save_regs_using_mov = false;
10137
10138   if (ix86_using_red_zone ()
10139       && crtl->sp_is_unchanging
10140       && crtl->is_leaf
10141       && !ix86_current_function_calls_tls_descriptor)
10142     {
10143       frame->red_zone_size = to_allocate;
10144       if (frame->save_regs_using_mov)
10145         frame->red_zone_size += frame->nregs * UNITS_PER_WORD;
10146       if (frame->red_zone_size > RED_ZONE_SIZE - RED_ZONE_RESERVE)
10147         frame->red_zone_size = RED_ZONE_SIZE - RED_ZONE_RESERVE;
10148     }
10149   else
10150     frame->red_zone_size = 0;
10151   frame->stack_pointer_offset -= frame->red_zone_size;
10152
10153   /* The SEH frame pointer location is near the bottom of the frame.
10154      This is enforced by the fact that the difference between the
10155      stack pointer and the frame pointer is limited to 240 bytes in
10156      the unwind data structure.  */
10157   if (TARGET_SEH)
10158     {
10159       HOST_WIDE_INT diff;
10160
10161       /* If we can leave the frame pointer where it is, do so.  Also, returns
10162          the establisher frame for __builtin_frame_address (0).  */
10163       diff = frame->stack_pointer_offset - frame->hard_frame_pointer_offset;
10164       if (diff <= SEH_MAX_FRAME_SIZE
10165           && (diff > 240 || (diff & 15) != 0)
10166           && !crtl->accesses_prior_frames)
10167         {
10168           /* Ideally we'd determine what portion of the local stack frame
10169              (within the constraint of the lowest 240) is most heavily used.
10170              But without that complication, simply bias the frame pointer
10171              by 128 bytes so as to maximize the amount of the local stack
10172              frame that is addressable with 8-bit offsets.  */
10173           frame->hard_frame_pointer_offset = frame->stack_pointer_offset - 128;
10174         }
10175     }
10176 }
10177
10178 /* This is semi-inlined memory_address_length, but simplified
10179    since we know that we're always dealing with reg+offset, and
10180    to avoid having to create and discard all that rtl.  */
10181
10182 static inline int
10183 choose_baseaddr_len (unsigned int regno, HOST_WIDE_INT offset)
10184 {
10185   int len = 4;
10186
10187   if (offset == 0)
10188     {
10189       /* EBP and R13 cannot be encoded without an offset.  */
10190       len = (regno == BP_REG || regno == R13_REG);
10191     }
10192   else if (IN_RANGE (offset, -128, 127))
10193     len = 1;
10194
10195   /* ESP and R12 must be encoded with a SIB byte.  */
10196   if (regno == SP_REG || regno == R12_REG)
10197     len++;
10198
10199   return len;
10200 }
10201
10202 /* Return an RTX that points to CFA_OFFSET within the stack frame.
10203    The valid base registers are taken from CFUN->MACHINE->FS.  */
10204
10205 static rtx
10206 choose_baseaddr (HOST_WIDE_INT cfa_offset)
10207 {
10208   const struct machine_function *m = cfun->machine;
10209   rtx base_reg = NULL;
10210   HOST_WIDE_INT base_offset = 0;
10211
10212   if (m->use_fast_prologue_epilogue)
10213     {
10214       /* Choose the base register most likely to allow the most scheduling
10215          opportunities.  Generally FP is valid throughout the function,
10216          while DRAP must be reloaded within the epilogue.  But choose either
10217          over the SP due to increased encoding size.  */
10218
10219       if (m->fs.fp_valid)
10220         {
10221           base_reg = hard_frame_pointer_rtx;
10222           base_offset = m->fs.fp_offset - cfa_offset;
10223         }
10224       else if (m->fs.drap_valid)
10225         {
10226           base_reg = crtl->drap_reg;
10227           base_offset = 0 - cfa_offset;
10228         }
10229       else if (m->fs.sp_valid)
10230         {
10231           base_reg = stack_pointer_rtx;
10232           base_offset = m->fs.sp_offset - cfa_offset;
10233         }
10234     }
10235   else
10236     {
10237       HOST_WIDE_INT toffset;
10238       int len = 16, tlen;
10239
10240       /* Choose the base register with the smallest address encoding.
10241          With a tie, choose FP > DRAP > SP.  */
10242       if (m->fs.sp_valid)
10243         {
10244           base_reg = stack_pointer_rtx;
10245           base_offset = m->fs.sp_offset - cfa_offset;
10246           len = choose_baseaddr_len (STACK_POINTER_REGNUM, base_offset);
10247         }
10248       if (m->fs.drap_valid)
10249         {
10250           toffset = 0 - cfa_offset;
10251           tlen = choose_baseaddr_len (REGNO (crtl->drap_reg), toffset);
10252           if (tlen <= len)
10253             {
10254               base_reg = crtl->drap_reg;
10255               base_offset = toffset;
10256               len = tlen;
10257             }
10258         }
10259       if (m->fs.fp_valid)
10260         {
10261           toffset = m->fs.fp_offset - cfa_offset;
10262           tlen = choose_baseaddr_len (HARD_FRAME_POINTER_REGNUM, toffset);
10263           if (tlen <= len)
10264             {
10265               base_reg = hard_frame_pointer_rtx;
10266               base_offset = toffset;
10267               len = tlen;
10268             }
10269         }
10270     }
10271   gcc_assert (base_reg != NULL);
10272
10273   return plus_constant (Pmode, base_reg, base_offset);
10274 }
10275
10276 /* Emit code to save registers in the prologue.  */
10277
10278 static void
10279 ix86_emit_save_regs (void)
10280 {
10281   unsigned int regno;
10282   rtx insn;
10283
10284   for (regno = FIRST_PSEUDO_REGISTER - 1; regno-- > 0; )
10285     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10286       {
10287         insn = emit_insn (gen_push (gen_rtx_REG (word_mode, regno)));
10288         RTX_FRAME_RELATED_P (insn) = 1;
10289       }
10290 }
10291
10292 /* Emit a single register save at CFA - CFA_OFFSET.  */
10293
10294 static void
10295 ix86_emit_save_reg_using_mov (machine_mode mode, unsigned int regno,
10296                               HOST_WIDE_INT cfa_offset)
10297 {
10298   struct machine_function *m = cfun->machine;
10299   rtx reg = gen_rtx_REG (mode, regno);
10300   rtx mem, addr, base, insn;
10301
10302   addr = choose_baseaddr (cfa_offset);
10303   mem = gen_frame_mem (mode, addr);
10304
10305   /* For SSE saves, we need to indicate the 128-bit alignment.  */
10306   set_mem_align (mem, GET_MODE_ALIGNMENT (mode));
10307
10308   insn = emit_move_insn (mem, reg);
10309   RTX_FRAME_RELATED_P (insn) = 1;
10310
10311   base = addr;
10312   if (GET_CODE (base) == PLUS)
10313     base = XEXP (base, 0);
10314   gcc_checking_assert (REG_P (base));
10315
10316   /* When saving registers into a re-aligned local stack frame, avoid
10317      any tricky guessing by dwarf2out.  */
10318   if (m->fs.realigned)
10319     {
10320       gcc_checking_assert (stack_realign_drap);
10321
10322       if (regno == REGNO (crtl->drap_reg))
10323         {
10324           /* A bit of a hack.  We force the DRAP register to be saved in
10325              the re-aligned stack frame, which provides us with a copy
10326              of the CFA that will last past the prologue.  Install it.  */
10327           gcc_checking_assert (cfun->machine->fs.fp_valid);
10328           addr = plus_constant (Pmode, hard_frame_pointer_rtx,
10329                                 cfun->machine->fs.fp_offset - cfa_offset);
10330           mem = gen_rtx_MEM (mode, addr);
10331           add_reg_note (insn, REG_CFA_DEF_CFA, mem);
10332         }
10333       else
10334         {
10335           /* The frame pointer is a stable reference within the
10336              aligned frame.  Use it.  */
10337           gcc_checking_assert (cfun->machine->fs.fp_valid);
10338           addr = plus_constant (Pmode, hard_frame_pointer_rtx,
10339                                 cfun->machine->fs.fp_offset - cfa_offset);
10340           mem = gen_rtx_MEM (mode, addr);
10341           add_reg_note (insn, REG_CFA_EXPRESSION,
10342                         gen_rtx_SET (VOIDmode, mem, reg));
10343         }
10344     }
10345
10346   /* The memory may not be relative to the current CFA register,
10347      which means that we may need to generate a new pattern for
10348      use by the unwind info.  */
10349   else if (base != m->fs.cfa_reg)
10350     {
10351       addr = plus_constant (Pmode, m->fs.cfa_reg,
10352                             m->fs.cfa_offset - cfa_offset);
10353       mem = gen_rtx_MEM (mode, addr);
10354       add_reg_note (insn, REG_CFA_OFFSET, gen_rtx_SET (VOIDmode, mem, reg));
10355     }
10356 }
10357
10358 /* Emit code to save registers using MOV insns.
10359    First register is stored at CFA - CFA_OFFSET.  */
10360 static void
10361 ix86_emit_save_regs_using_mov (HOST_WIDE_INT cfa_offset)
10362 {
10363   unsigned int regno;
10364
10365   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
10366     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10367       {
10368         ix86_emit_save_reg_using_mov (word_mode, regno, cfa_offset);
10369         cfa_offset -= UNITS_PER_WORD;
10370       }
10371 }
10372
10373 /* Emit code to save SSE registers using MOV insns.
10374    First register is stored at CFA - CFA_OFFSET.  */
10375 static void
10376 ix86_emit_save_sse_regs_using_mov (HOST_WIDE_INT cfa_offset)
10377 {
10378   unsigned int regno;
10379
10380   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
10381     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, true))
10382       {
10383         ix86_emit_save_reg_using_mov (V4SFmode, regno, cfa_offset);
10384         cfa_offset -= 16;
10385       }
10386 }
10387
10388 static GTY(()) rtx queued_cfa_restores;
10389
10390 /* Add a REG_CFA_RESTORE REG note to INSN or queue them until next stack
10391    manipulation insn.  The value is on the stack at CFA - CFA_OFFSET.
10392    Don't add the note if the previously saved value will be left untouched
10393    within stack red-zone till return, as unwinders can find the same value
10394    in the register and on the stack.  */
10395
10396 static void
10397 ix86_add_cfa_restore_note (rtx insn, rtx reg, HOST_WIDE_INT cfa_offset)
10398 {
10399   if (!crtl->shrink_wrapped
10400       && cfa_offset <= cfun->machine->fs.red_zone_offset)
10401     return;
10402
10403   if (insn)
10404     {
10405       add_reg_note (insn, REG_CFA_RESTORE, reg);
10406       RTX_FRAME_RELATED_P (insn) = 1;
10407     }
10408   else
10409     queued_cfa_restores
10410       = alloc_reg_note (REG_CFA_RESTORE, reg, queued_cfa_restores);
10411 }
10412
10413 /* Add queued REG_CFA_RESTORE notes if any to INSN.  */
10414
10415 static void
10416 ix86_add_queued_cfa_restore_notes (rtx insn)
10417 {
10418   rtx last;
10419   if (!queued_cfa_restores)
10420     return;
10421   for (last = queued_cfa_restores; XEXP (last, 1); last = XEXP (last, 1))
10422     ;
10423   XEXP (last, 1) = REG_NOTES (insn);
10424   REG_NOTES (insn) = queued_cfa_restores;
10425   queued_cfa_restores = NULL_RTX;
10426   RTX_FRAME_RELATED_P (insn) = 1;
10427 }
10428
10429 /* Expand prologue or epilogue stack adjustment.
10430    The pattern exist to put a dependency on all ebp-based memory accesses.
10431    STYLE should be negative if instructions should be marked as frame related,
10432    zero if %r11 register is live and cannot be freely used and positive
10433    otherwise.  */
10434
10435 static void
10436 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset,
10437                            int style, bool set_cfa)
10438 {
10439   struct machine_function *m = cfun->machine;
10440   rtx insn;
10441   bool add_frame_related_expr = false;
10442
10443   if (Pmode == SImode)
10444     insn = gen_pro_epilogue_adjust_stack_si_add (dest, src, offset);
10445   else if (x86_64_immediate_operand (offset, DImode))
10446     insn = gen_pro_epilogue_adjust_stack_di_add (dest, src, offset);
10447   else
10448     {
10449       rtx tmp;
10450       /* r11 is used by indirect sibcall return as well, set before the
10451          epilogue and used after the epilogue.  */
10452       if (style)
10453         tmp = gen_rtx_REG (DImode, R11_REG);
10454       else
10455         {
10456           gcc_assert (src != hard_frame_pointer_rtx
10457                       && dest != hard_frame_pointer_rtx);
10458           tmp = hard_frame_pointer_rtx;
10459         }
10460       insn = emit_insn (gen_rtx_SET (DImode, tmp, offset));
10461       if (style < 0)
10462         add_frame_related_expr = true;
10463
10464       insn = gen_pro_epilogue_adjust_stack_di_add (dest, src, tmp);
10465     }
10466
10467   insn = emit_insn (insn);
10468   if (style >= 0)
10469     ix86_add_queued_cfa_restore_notes (insn);
10470
10471   if (set_cfa)
10472     {
10473       rtx r;
10474
10475       gcc_assert (m->fs.cfa_reg == src);
10476       m->fs.cfa_offset += INTVAL (offset);
10477       m->fs.cfa_reg = dest;
10478
10479       r = gen_rtx_PLUS (Pmode, src, offset);
10480       r = gen_rtx_SET (VOIDmode, dest, r);
10481       add_reg_note (insn, REG_CFA_ADJUST_CFA, r);
10482       RTX_FRAME_RELATED_P (insn) = 1;
10483     }
10484   else if (style < 0)
10485     {
10486       RTX_FRAME_RELATED_P (insn) = 1;
10487       if (add_frame_related_expr)
10488         {
10489           rtx r = gen_rtx_PLUS (Pmode, src, offset);
10490           r = gen_rtx_SET (VOIDmode, dest, r);
10491           add_reg_note (insn, REG_FRAME_RELATED_EXPR, r);
10492         }
10493     }
10494
10495   if (dest == stack_pointer_rtx)
10496     {
10497       HOST_WIDE_INT ooffset = m->fs.sp_offset;
10498       bool valid = m->fs.sp_valid;
10499
10500       if (src == hard_frame_pointer_rtx)
10501         {
10502           valid = m->fs.fp_valid;
10503           ooffset = m->fs.fp_offset;
10504         }
10505       else if (src == crtl->drap_reg)
10506         {
10507           valid = m->fs.drap_valid;
10508           ooffset = 0;
10509         }
10510       else
10511         {
10512           /* Else there are two possibilities: SP itself, which we set
10513              up as the default above.  Or EH_RETURN_STACKADJ_RTX, which is
10514              taken care of this by hand along the eh_return path.  */
10515           gcc_checking_assert (src == stack_pointer_rtx
10516                                || offset == const0_rtx);
10517         }
10518
10519       m->fs.sp_offset = ooffset - INTVAL (offset);
10520       m->fs.sp_valid = valid;
10521     }
10522 }
10523
10524 /* Find an available register to be used as dynamic realign argument
10525    pointer regsiter.  Such a register will be written in prologue and
10526    used in begin of body, so it must not be
10527         1. parameter passing register.
10528         2. GOT pointer.
10529    We reuse static-chain register if it is available.  Otherwise, we
10530    use DI for i386 and R13 for x86-64.  We chose R13 since it has
10531    shorter encoding.
10532
10533    Return: the regno of chosen register.  */
10534
10535 static unsigned int
10536 find_drap_reg (void)
10537 {
10538   tree decl = cfun->decl;
10539
10540   if (TARGET_64BIT)
10541     {
10542       /* Use R13 for nested function or function need static chain.
10543          Since function with tail call may use any caller-saved
10544          registers in epilogue, DRAP must not use caller-saved
10545          register in such case.  */
10546       if (DECL_STATIC_CHAIN (decl) || crtl->tail_call_emit)
10547         return R13_REG;
10548
10549       return R10_REG;
10550     }
10551   else
10552     {
10553       /* Use DI for nested function or function need static chain.
10554          Since function with tail call may use any caller-saved
10555          registers in epilogue, DRAP must not use caller-saved
10556          register in such case.  */
10557       if (DECL_STATIC_CHAIN (decl) || crtl->tail_call_emit)
10558         return DI_REG;
10559
10560       /* Reuse static chain register if it isn't used for parameter
10561          passing.  */
10562       if (ix86_function_regparm (TREE_TYPE (decl), decl) <= 2)
10563         {
10564           unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (decl));
10565           if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) == 0)
10566             return CX_REG;
10567         }
10568       return DI_REG;
10569     }
10570 }
10571
10572 /* Return minimum incoming stack alignment.  */
10573
10574 static unsigned int
10575 ix86_minimum_incoming_stack_boundary (bool sibcall)
10576 {
10577   unsigned int incoming_stack_boundary;
10578
10579   /* Prefer the one specified at command line. */
10580   if (ix86_user_incoming_stack_boundary)
10581     incoming_stack_boundary = ix86_user_incoming_stack_boundary;
10582   /* In 32bit, use MIN_STACK_BOUNDARY for incoming stack boundary
10583      if -mstackrealign is used, it isn't used for sibcall check and
10584      estimated stack alignment is 128bit.  */
10585   else if (!sibcall
10586            && !TARGET_64BIT
10587            && ix86_force_align_arg_pointer
10588            && crtl->stack_alignment_estimated == 128)
10589     incoming_stack_boundary = MIN_STACK_BOUNDARY;
10590   else
10591     incoming_stack_boundary = ix86_default_incoming_stack_boundary;
10592
10593   /* Incoming stack alignment can be changed on individual functions
10594      via force_align_arg_pointer attribute.  We use the smallest
10595      incoming stack boundary.  */
10596   if (incoming_stack_boundary > MIN_STACK_BOUNDARY
10597       && lookup_attribute (ix86_force_align_arg_pointer_string,
10598                            TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
10599     incoming_stack_boundary = MIN_STACK_BOUNDARY;
10600
10601   /* The incoming stack frame has to be aligned at least at
10602      parm_stack_boundary.  */
10603   if (incoming_stack_boundary < crtl->parm_stack_boundary)
10604     incoming_stack_boundary = crtl->parm_stack_boundary;
10605
10606   /* Stack at entrance of main is aligned by runtime.  We use the
10607      smallest incoming stack boundary. */
10608   if (incoming_stack_boundary > MAIN_STACK_BOUNDARY
10609       && DECL_NAME (current_function_decl)
10610       && MAIN_NAME_P (DECL_NAME (current_function_decl))
10611       && DECL_FILE_SCOPE_P (current_function_decl))
10612     incoming_stack_boundary = MAIN_STACK_BOUNDARY;
10613
10614   return incoming_stack_boundary;
10615 }
10616
10617 /* Update incoming stack boundary and estimated stack alignment.  */
10618
10619 static void
10620 ix86_update_stack_boundary (void)
10621 {
10622   ix86_incoming_stack_boundary
10623     = ix86_minimum_incoming_stack_boundary (false);
10624
10625   /* x86_64 vararg needs 16byte stack alignment for register save
10626      area.  */
10627   if (TARGET_64BIT
10628       && cfun->stdarg
10629       && crtl->stack_alignment_estimated < 128)
10630     crtl->stack_alignment_estimated = 128;
10631 }
10632
10633 /* Handle the TARGET_GET_DRAP_RTX hook.  Return NULL if no DRAP is
10634    needed or an rtx for DRAP otherwise.  */
10635
10636 static rtx
10637 ix86_get_drap_rtx (void)
10638 {
10639   if (ix86_force_drap || !ACCUMULATE_OUTGOING_ARGS)
10640     crtl->need_drap = true;
10641
10642   if (stack_realign_drap)
10643     {
10644       /* Assign DRAP to vDRAP and returns vDRAP */
10645       unsigned int regno = find_drap_reg ();
10646       rtx drap_vreg;
10647       rtx arg_ptr;
10648       rtx_insn *seq, *insn;
10649
10650       arg_ptr = gen_rtx_REG (Pmode, regno);
10651       crtl->drap_reg = arg_ptr;
10652
10653       start_sequence ();
10654       drap_vreg = copy_to_reg (arg_ptr);
10655       seq = get_insns ();
10656       end_sequence ();
10657
10658       insn = emit_insn_before (seq, NEXT_INSN (entry_of_function ()));
10659       if (!optimize)
10660         {
10661           add_reg_note (insn, REG_CFA_SET_VDRAP, drap_vreg);
10662           RTX_FRAME_RELATED_P (insn) = 1;
10663         }
10664       return drap_vreg;
10665     }
10666   else
10667     return NULL;
10668 }
10669
10670 /* Handle the TARGET_INTERNAL_ARG_POINTER hook.  */
10671
10672 static rtx
10673 ix86_internal_arg_pointer (void)
10674 {
10675   return virtual_incoming_args_rtx;
10676 }
10677
10678 struct scratch_reg {
10679   rtx reg;
10680   bool saved;
10681 };
10682
10683 /* Return a short-lived scratch register for use on function entry.
10684    In 32-bit mode, it is valid only after the registers are saved
10685    in the prologue.  This register must be released by means of
10686    release_scratch_register_on_entry once it is dead.  */
10687
10688 static void
10689 get_scratch_register_on_entry (struct scratch_reg *sr)
10690 {
10691   int regno;
10692
10693   sr->saved = false;
10694
10695   if (TARGET_64BIT)
10696     {
10697       /* We always use R11 in 64-bit mode.  */
10698       regno = R11_REG;
10699     }
10700   else
10701     {
10702       tree decl = current_function_decl, fntype = TREE_TYPE (decl);
10703       bool fastcall_p
10704         = lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
10705       bool thiscall_p
10706         = lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE;
10707       bool static_chain_p = DECL_STATIC_CHAIN (decl);
10708       int regparm = ix86_function_regparm (fntype, decl);
10709       int drap_regno
10710         = crtl->drap_reg ? REGNO (crtl->drap_reg) : INVALID_REGNUM;
10711
10712       /* 'fastcall' sets regparm to 2, uses ecx/edx for arguments and eax
10713           for the static chain register.  */
10714       if ((regparm < 1 || (fastcall_p && !static_chain_p))
10715           && drap_regno != AX_REG)
10716         regno = AX_REG;
10717       /* 'thiscall' sets regparm to 1, uses ecx for arguments and edx
10718           for the static chain register.  */
10719       else if (thiscall_p && !static_chain_p && drap_regno != AX_REG)
10720         regno = AX_REG;
10721       else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG)
10722         regno = DX_REG;
10723       /* ecx is the static chain register.  */
10724       else if (regparm < 3 && !fastcall_p && !thiscall_p
10725                && !static_chain_p
10726                && drap_regno != CX_REG)
10727         regno = CX_REG;
10728       else if (ix86_save_reg (BX_REG, true))
10729         regno = BX_REG;
10730       /* esi is the static chain register.  */
10731       else if (!(regparm == 3 && static_chain_p)
10732                && ix86_save_reg (SI_REG, true))
10733         regno = SI_REG;
10734       else if (ix86_save_reg (DI_REG, true))
10735         regno = DI_REG;
10736       else
10737         {
10738           regno = (drap_regno == AX_REG ? DX_REG : AX_REG);
10739           sr->saved = true;
10740         }
10741     }
10742
10743   sr->reg = gen_rtx_REG (Pmode, regno);
10744   if (sr->saved)
10745     {
10746       rtx insn = emit_insn (gen_push (sr->reg));
10747       RTX_FRAME_RELATED_P (insn) = 1;
10748     }
10749 }
10750
10751 /* Release a scratch register obtained from the preceding function.  */
10752
10753 static void
10754 release_scratch_register_on_entry (struct scratch_reg *sr)
10755 {
10756   if (sr->saved)
10757     {
10758       struct machine_function *m = cfun->machine;
10759       rtx x, insn = emit_insn (gen_pop (sr->reg));
10760
10761       /* The RTX_FRAME_RELATED_P mechanism doesn't know about pop.  */
10762       RTX_FRAME_RELATED_P (insn) = 1;
10763       x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (UNITS_PER_WORD));
10764       x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
10765       add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
10766       m->fs.sp_offset -= UNITS_PER_WORD;
10767     }
10768 }
10769
10770 #define PROBE_INTERVAL (1 << STACK_CHECK_PROBE_INTERVAL_EXP)
10771
10772 /* Emit code to adjust the stack pointer by SIZE bytes while probing it.  */
10773
10774 static void
10775 ix86_adjust_stack_and_probe (const HOST_WIDE_INT size)
10776 {
10777   /* We skip the probe for the first interval + a small dope of 4 words and
10778      probe that many bytes past the specified size to maintain a protection
10779      area at the botton of the stack.  */
10780   const int dope = 4 * UNITS_PER_WORD;
10781   rtx size_rtx = GEN_INT (size), last;
10782
10783   /* See if we have a constant small number of probes to generate.  If so,
10784      that's the easy case.  The run-time loop is made up of 11 insns in the
10785      generic case while the compile-time loop is made up of 3+2*(n-1) insns
10786      for n # of intervals.  */
10787   if (size <= 5 * PROBE_INTERVAL)
10788     {
10789       HOST_WIDE_INT i, adjust;
10790       bool first_probe = true;
10791
10792       /* Adjust SP and probe at PROBE_INTERVAL + N * PROBE_INTERVAL for
10793          values of N from 1 until it exceeds SIZE.  If only one probe is
10794          needed, this will not generate any code.  Then adjust and probe
10795          to PROBE_INTERVAL + SIZE.  */
10796       for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
10797         {
10798           if (first_probe)
10799             {
10800               adjust = 2 * PROBE_INTERVAL + dope;
10801               first_probe = false;
10802             }
10803           else
10804             adjust = PROBE_INTERVAL;
10805
10806           emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10807                                   plus_constant (Pmode, stack_pointer_rtx,
10808                                                  -adjust)));
10809           emit_stack_probe (stack_pointer_rtx);
10810         }
10811
10812       if (first_probe)
10813         adjust = size + PROBE_INTERVAL + dope;
10814       else
10815         adjust = size + PROBE_INTERVAL - i;
10816
10817       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10818                               plus_constant (Pmode, stack_pointer_rtx,
10819                                              -adjust)));
10820       emit_stack_probe (stack_pointer_rtx);
10821
10822       /* Adjust back to account for the additional first interval.  */
10823       last = emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10824                                      plus_constant (Pmode, stack_pointer_rtx,
10825                                                     PROBE_INTERVAL + dope)));
10826     }
10827
10828   /* Otherwise, do the same as above, but in a loop.  Note that we must be
10829      extra careful with variables wrapping around because we might be at
10830      the very top (or the very bottom) of the address space and we have
10831      to be able to handle this case properly; in particular, we use an
10832      equality test for the loop condition.  */
10833   else
10834     {
10835       HOST_WIDE_INT rounded_size;
10836       struct scratch_reg sr;
10837
10838       get_scratch_register_on_entry (&sr);
10839
10840
10841       /* Step 1: round SIZE to the previous multiple of the interval.  */
10842
10843       rounded_size = size & -PROBE_INTERVAL;
10844
10845
10846       /* Step 2: compute initial and final value of the loop counter.  */
10847
10848       /* SP = SP_0 + PROBE_INTERVAL.  */
10849       emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10850                               plus_constant (Pmode, stack_pointer_rtx,
10851                                              - (PROBE_INTERVAL + dope))));
10852
10853       /* LAST_ADDR = SP_0 + PROBE_INTERVAL + ROUNDED_SIZE.  */
10854       emit_move_insn (sr.reg, GEN_INT (-rounded_size));
10855       emit_insn (gen_rtx_SET (VOIDmode, sr.reg,
10856                               gen_rtx_PLUS (Pmode, sr.reg,
10857                                             stack_pointer_rtx)));
10858
10859
10860       /* Step 3: the loop
10861
10862          while (SP != LAST_ADDR)
10863            {
10864              SP = SP + PROBE_INTERVAL
10865              probe at SP
10866            }
10867
10868          adjusts SP and probes to PROBE_INTERVAL + N * PROBE_INTERVAL for
10869          values of N from 1 until it is equal to ROUNDED_SIZE.  */
10870
10871       emit_insn (ix86_gen_adjust_stack_and_probe (sr.reg, sr.reg, size_rtx));
10872
10873
10874       /* Step 4: adjust SP and probe at PROBE_INTERVAL + SIZE if we cannot
10875          assert at compile-time that SIZE is equal to ROUNDED_SIZE.  */
10876
10877       if (size != rounded_size)
10878         {
10879           emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10880                                   plus_constant (Pmode, stack_pointer_rtx,
10881                                                  rounded_size - size)));
10882           emit_stack_probe (stack_pointer_rtx);
10883         }
10884
10885       /* Adjust back to account for the additional first interval.  */
10886       last = emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10887                                      plus_constant (Pmode, stack_pointer_rtx,
10888                                                     PROBE_INTERVAL + dope)));
10889
10890       release_scratch_register_on_entry (&sr);
10891     }
10892
10893   gcc_assert (cfun->machine->fs.cfa_reg != stack_pointer_rtx);
10894
10895   /* Even if the stack pointer isn't the CFA register, we need to correctly
10896      describe the adjustments made to it, in particular differentiate the
10897      frame-related ones from the frame-unrelated ones.  */
10898   if (size > 0)
10899     {
10900       rtx expr = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (2));
10901       XVECEXP (expr, 0, 0)
10902         = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10903                        plus_constant (Pmode, stack_pointer_rtx, -size));
10904       XVECEXP (expr, 0, 1)
10905         = gen_rtx_SET (VOIDmode, stack_pointer_rtx,
10906                        plus_constant (Pmode, stack_pointer_rtx,
10907                                       PROBE_INTERVAL + dope + size));
10908       add_reg_note (last, REG_FRAME_RELATED_EXPR, expr);
10909       RTX_FRAME_RELATED_P (last) = 1;
10910
10911       cfun->machine->fs.sp_offset += size;
10912     }
10913
10914   /* Make sure nothing is scheduled before we are done.  */
10915   emit_insn (gen_blockage ());
10916 }
10917
10918 /* Adjust the stack pointer up to REG while probing it.  */
10919
10920 const char *
10921 output_adjust_stack_and_probe (rtx reg)
10922 {
10923   static int labelno = 0;
10924   char loop_lab[32], end_lab[32];
10925   rtx xops[2];
10926
10927   ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
10928   ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
10929
10930   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
10931
10932   /* Jump to END_LAB if SP == LAST_ADDR.  */
10933   xops[0] = stack_pointer_rtx;
10934   xops[1] = reg;
10935   output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
10936   fputs ("\tje\t", asm_out_file);
10937   assemble_name_raw (asm_out_file, end_lab);
10938   fputc ('\n', asm_out_file);
10939
10940   /* SP = SP + PROBE_INTERVAL.  */
10941   xops[1] = GEN_INT (PROBE_INTERVAL);
10942   output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
10943
10944   /* Probe at SP.  */
10945   xops[1] = const0_rtx;
10946   output_asm_insn ("or%z0\t{%1, (%0)|DWORD PTR [%0], %1}", xops);
10947
10948   fprintf (asm_out_file, "\tjmp\t");
10949   assemble_name_raw (asm_out_file, loop_lab);
10950   fputc ('\n', asm_out_file);
10951
10952   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
10953
10954   return "";
10955 }
10956
10957 /* Emit code to probe a range of stack addresses from FIRST to FIRST+SIZE,
10958    inclusive.  These are offsets from the current stack pointer.  */
10959
10960 static void
10961 ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size)
10962 {
10963   /* See if we have a constant small number of probes to generate.  If so,
10964      that's the easy case.  The run-time loop is made up of 7 insns in the
10965      generic case while the compile-time loop is made up of n insns for n #
10966      of intervals.  */
10967   if (size <= 7 * PROBE_INTERVAL)
10968     {
10969       HOST_WIDE_INT i;
10970
10971       /* Probe at FIRST + N * PROBE_INTERVAL for values of N from 1 until
10972          it exceeds SIZE.  If only one probe is needed, this will not
10973          generate any code.  Then probe at FIRST + SIZE.  */
10974       for (i = PROBE_INTERVAL; i < size; i += PROBE_INTERVAL)
10975         emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
10976                                          -(first + i)));
10977
10978       emit_stack_probe (plus_constant (Pmode, stack_pointer_rtx,
10979                                        -(first + size)));
10980     }
10981
10982   /* Otherwise, do the same as above, but in a loop.  Note that we must be
10983      extra careful with variables wrapping around because we might be at
10984      the very top (or the very bottom) of the address space and we have
10985      to be able to handle this case properly; in particular, we use an
10986      equality test for the loop condition.  */
10987   else
10988     {
10989       HOST_WIDE_INT rounded_size, last;
10990       struct scratch_reg sr;
10991
10992       get_scratch_register_on_entry (&sr);
10993
10994
10995       /* Step 1: round SIZE to the previous multiple of the interval.  */
10996
10997       rounded_size = size & -PROBE_INTERVAL;
10998
10999
11000       /* Step 2: compute initial and final value of the loop counter.  */
11001
11002       /* TEST_OFFSET = FIRST.  */
11003       emit_move_insn (sr.reg, GEN_INT (-first));
11004
11005       /* LAST_OFFSET = FIRST + ROUNDED_SIZE.  */
11006       last = first + rounded_size;
11007
11008
11009       /* Step 3: the loop
11010
11011          while (TEST_ADDR != LAST_ADDR)
11012            {
11013              TEST_ADDR = TEST_ADDR + PROBE_INTERVAL
11014              probe at TEST_ADDR
11015            }
11016
11017          probes at FIRST + N * PROBE_INTERVAL for values of N from 1
11018          until it is equal to ROUNDED_SIZE.  */
11019
11020       emit_insn (ix86_gen_probe_stack_range (sr.reg, sr.reg, GEN_INT (-last)));
11021
11022
11023       /* Step 4: probe at FIRST + SIZE if we cannot assert at compile-time
11024          that SIZE is equal to ROUNDED_SIZE.  */
11025
11026       if (size != rounded_size)
11027         emit_stack_probe (plus_constant (Pmode,
11028                                          gen_rtx_PLUS (Pmode,
11029                                                        stack_pointer_rtx,
11030                                                        sr.reg),
11031                                          rounded_size - size));
11032
11033       release_scratch_register_on_entry (&sr);
11034     }
11035
11036   /* Make sure nothing is scheduled before we are done.  */
11037   emit_insn (gen_blockage ());
11038 }
11039
11040 /* Probe a range of stack addresses from REG to END, inclusive.  These are
11041    offsets from the current stack pointer.  */
11042
11043 const char *
11044 output_probe_stack_range (rtx reg, rtx end)
11045 {
11046   static int labelno = 0;
11047   char loop_lab[32], end_lab[32];
11048   rtx xops[3];
11049
11050   ASM_GENERATE_INTERNAL_LABEL (loop_lab, "LPSRL", labelno);
11051   ASM_GENERATE_INTERNAL_LABEL (end_lab, "LPSRE", labelno++);
11052
11053   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, loop_lab);
11054
11055   /* Jump to END_LAB if TEST_ADDR == LAST_ADDR.  */
11056   xops[0] = reg;
11057   xops[1] = end;
11058   output_asm_insn ("cmp%z0\t{%1, %0|%0, %1}", xops);
11059   fputs ("\tje\t", asm_out_file);
11060   assemble_name_raw (asm_out_file, end_lab);
11061   fputc ('\n', asm_out_file);
11062
11063   /* TEST_ADDR = TEST_ADDR + PROBE_INTERVAL.  */
11064   xops[1] = GEN_INT (PROBE_INTERVAL);
11065   output_asm_insn ("sub%z0\t{%1, %0|%0, %1}", xops);
11066
11067   /* Probe at TEST_ADDR.  */
11068   xops[0] = stack_pointer_rtx;
11069   xops[1] = reg;
11070   xops[2] = const0_rtx;
11071   output_asm_insn ("or%z0\t{%2, (%0,%1)|DWORD PTR [%0+%1], %2}", xops);
11072
11073   fprintf (asm_out_file, "\tjmp\t");
11074   assemble_name_raw (asm_out_file, loop_lab);
11075   fputc ('\n', asm_out_file);
11076
11077   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, end_lab);
11078
11079   return "";
11080 }
11081
11082 /* Finalize stack_realign_needed flag, which will guide prologue/epilogue
11083    to be generated in correct form.  */
11084 static void
11085 ix86_finalize_stack_realign_flags (void)
11086 {
11087   /* Check if stack realign is really needed after reload, and
11088      stores result in cfun */
11089   unsigned int incoming_stack_boundary
11090     = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary
11091        ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary);
11092   unsigned int stack_realign = (incoming_stack_boundary
11093                                 < (crtl->is_leaf
11094                                    ? crtl->max_used_stack_slot_alignment
11095                                    : crtl->stack_alignment_needed));
11096
11097   if (crtl->stack_realign_finalized)
11098     {
11099       /* After stack_realign_needed is finalized, we can't no longer
11100          change it.  */
11101       gcc_assert (crtl->stack_realign_needed == stack_realign);
11102       return;
11103     }
11104
11105   /* If the only reason for frame_pointer_needed is that we conservatively
11106      assumed stack realignment might be needed, but in the end nothing that
11107      needed the stack alignment had been spilled, clear frame_pointer_needed
11108      and say we don't need stack realignment.  */
11109   if (stack_realign
11110       && frame_pointer_needed
11111       && crtl->is_leaf
11112       && flag_omit_frame_pointer
11113       && crtl->sp_is_unchanging
11114       && !ix86_current_function_calls_tls_descriptor
11115       && !crtl->accesses_prior_frames
11116       && !cfun->calls_alloca
11117       && !crtl->calls_eh_return
11118       && !(flag_stack_check && STACK_CHECK_MOVING_SP)
11119       && !ix86_frame_pointer_required ()
11120       && get_frame_size () == 0
11121       && ix86_nsaved_sseregs () == 0
11122       && ix86_varargs_gpr_size + ix86_varargs_fpr_size == 0)
11123     {
11124       HARD_REG_SET set_up_by_prologue, prologue_used;
11125       basic_block bb;
11126
11127       CLEAR_HARD_REG_SET (prologue_used);
11128       CLEAR_HARD_REG_SET (set_up_by_prologue);
11129       add_to_hard_reg_set (&set_up_by_prologue, Pmode, STACK_POINTER_REGNUM);
11130       add_to_hard_reg_set (&set_up_by_prologue, Pmode, ARG_POINTER_REGNUM);
11131       add_to_hard_reg_set (&set_up_by_prologue, Pmode,
11132                            HARD_FRAME_POINTER_REGNUM);
11133       FOR_EACH_BB_FN (bb, cfun)
11134         {
11135           rtx_insn *insn;
11136           FOR_BB_INSNS (bb, insn)
11137             if (NONDEBUG_INSN_P (insn)
11138                 && requires_stack_frame_p (insn, prologue_used,
11139                                            set_up_by_prologue))
11140               {
11141                 crtl->stack_realign_needed = stack_realign;
11142                 crtl->stack_realign_finalized = true;
11143                 return;
11144               }
11145         }
11146
11147       /* If drap has been set, but it actually isn't live at the start
11148          of the function, there is no reason to set it up.  */
11149       if (crtl->drap_reg)
11150         {
11151           basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
11152           if (! REGNO_REG_SET_P (DF_LR_IN (bb), REGNO (crtl->drap_reg)))
11153             {
11154               crtl->drap_reg = NULL_RTX;
11155               crtl->need_drap = false;
11156             }
11157         }
11158       else
11159         cfun->machine->no_drap_save_restore = true;
11160
11161       frame_pointer_needed = false;
11162       stack_realign = false;
11163       crtl->max_used_stack_slot_alignment = incoming_stack_boundary;
11164       crtl->stack_alignment_needed = incoming_stack_boundary;
11165       crtl->stack_alignment_estimated = incoming_stack_boundary;
11166       if (crtl->preferred_stack_boundary > incoming_stack_boundary)
11167         crtl->preferred_stack_boundary = incoming_stack_boundary;
11168       df_finish_pass (true);
11169       df_scan_alloc (NULL);
11170       df_scan_blocks ();
11171       df_compute_regs_ever_live (true);
11172       df_analyze ();
11173     }
11174
11175   crtl->stack_realign_needed = stack_realign;
11176   crtl->stack_realign_finalized = true;
11177 }
11178
11179 /* Delete SET_GOT right after entry block if it is allocated to reg.  */
11180
11181 static void
11182 ix86_elim_entry_set_got (rtx reg)
11183 {
11184   basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
11185   rtx_insn *c_insn = BB_HEAD (bb);
11186   if (!NONDEBUG_INSN_P (c_insn))
11187     c_insn = next_nonnote_nondebug_insn (c_insn);
11188   if (c_insn && NONJUMP_INSN_P (c_insn))
11189     {
11190       rtx pat = PATTERN (c_insn);
11191       if (GET_CODE (pat) == PARALLEL)
11192         {
11193           rtx vec = XVECEXP (pat, 0, 0);
11194           if (GET_CODE (vec) == SET
11195               && XINT (XEXP (vec, 1), 1) == UNSPEC_SET_GOT
11196               && REGNO (XEXP (vec, 0)) == REGNO (reg))
11197             delete_insn (c_insn);
11198         }
11199     }
11200 }
11201
11202 /* Expand the prologue into a bunch of separate insns.  */
11203
11204 void
11205 ix86_expand_prologue (void)
11206 {
11207   struct machine_function *m = cfun->machine;
11208   rtx insn, t;
11209   struct ix86_frame frame;
11210   HOST_WIDE_INT allocate;
11211   bool int_registers_saved;
11212   bool sse_registers_saved;
11213
11214   ix86_finalize_stack_realign_flags ();
11215
11216   /* DRAP should not coexist with stack_realign_fp */
11217   gcc_assert (!(crtl->drap_reg && stack_realign_fp));
11218
11219   memset (&m->fs, 0, sizeof (m->fs));
11220
11221   /* Initialize CFA state for before the prologue.  */
11222   m->fs.cfa_reg = stack_pointer_rtx;
11223   m->fs.cfa_offset = INCOMING_FRAME_SP_OFFSET;
11224
11225   /* Track SP offset to the CFA.  We continue tracking this after we've
11226      swapped the CFA register away from SP.  In the case of re-alignment
11227      this is fudged; we're interested to offsets within the local frame.  */
11228   m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
11229   m->fs.sp_valid = true;
11230
11231   ix86_compute_frame_layout (&frame);
11232
11233   if (!TARGET_64BIT && ix86_function_ms_hook_prologue (current_function_decl))
11234     {
11235       /* We should have already generated an error for any use of
11236          ms_hook on a nested function.  */
11237       gcc_checking_assert (!ix86_static_chain_on_stack);
11238
11239       /* Check if profiling is active and we shall use profiling before
11240          prologue variant. If so sorry.  */
11241       if (crtl->profile && flag_fentry != 0)
11242         sorry ("ms_hook_prologue attribute isn%'t compatible "
11243                "with -mfentry for 32-bit");
11244
11245       /* In ix86_asm_output_function_label we emitted:
11246          8b ff     movl.s %edi,%edi
11247          55        push   %ebp
11248          8b ec     movl.s %esp,%ebp
11249
11250          This matches the hookable function prologue in Win32 API
11251          functions in Microsoft Windows XP Service Pack 2 and newer.
11252          Wine uses this to enable Windows apps to hook the Win32 API
11253          functions provided by Wine.
11254
11255          What that means is that we've already set up the frame pointer.  */
11256
11257       if (frame_pointer_needed
11258           && !(crtl->drap_reg && crtl->stack_realign_needed))
11259         {
11260           rtx push, mov;
11261
11262           /* We've decided to use the frame pointer already set up.
11263              Describe this to the unwinder by pretending that both
11264              push and mov insns happen right here.
11265
11266              Putting the unwind info here at the end of the ms_hook
11267              is done so that we can make absolutely certain we get
11268              the required byte sequence at the start of the function,
11269              rather than relying on an assembler that can produce
11270              the exact encoding required.
11271
11272              However it does mean (in the unpatched case) that we have
11273              a 1 insn window where the asynchronous unwind info is
11274              incorrect.  However, if we placed the unwind info at
11275              its correct location we would have incorrect unwind info
11276              in the patched case.  Which is probably all moot since
11277              I don't expect Wine generates dwarf2 unwind info for the
11278              system libraries that use this feature.  */
11279
11280           insn = emit_insn (gen_blockage ());
11281
11282           push = gen_push (hard_frame_pointer_rtx);
11283           mov = gen_rtx_SET (VOIDmode, hard_frame_pointer_rtx,
11284                              stack_pointer_rtx);
11285           RTX_FRAME_RELATED_P (push) = 1;
11286           RTX_FRAME_RELATED_P (mov) = 1;
11287
11288           RTX_FRAME_RELATED_P (insn) = 1;
11289           add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11290                         gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, push, mov)));
11291
11292           /* Note that gen_push incremented m->fs.cfa_offset, even
11293              though we didn't emit the push insn here.  */
11294           m->fs.cfa_reg = hard_frame_pointer_rtx;
11295           m->fs.fp_offset = m->fs.cfa_offset;
11296           m->fs.fp_valid = true;
11297         }
11298       else
11299         {
11300           /* The frame pointer is not needed so pop %ebp again.
11301              This leaves us with a pristine state.  */
11302           emit_insn (gen_pop (hard_frame_pointer_rtx));
11303         }
11304     }
11305
11306   /* The first insn of a function that accepts its static chain on the
11307      stack is to push the register that would be filled in by a direct
11308      call.  This insn will be skipped by the trampoline.  */
11309   else if (ix86_static_chain_on_stack)
11310     {
11311       insn = emit_insn (gen_push (ix86_static_chain (cfun->decl, false)));
11312       emit_insn (gen_blockage ());
11313
11314       /* We don't want to interpret this push insn as a register save,
11315          only as a stack adjustment.  The real copy of the register as
11316          a save will be done later, if needed.  */
11317       t = plus_constant (Pmode, stack_pointer_rtx, -UNITS_PER_WORD);
11318       t = gen_rtx_SET (VOIDmode, stack_pointer_rtx, t);
11319       add_reg_note (insn, REG_CFA_ADJUST_CFA, t);
11320       RTX_FRAME_RELATED_P (insn) = 1;
11321     }
11322
11323   /* Emit prologue code to adjust stack alignment and setup DRAP, in case
11324      of DRAP is needed and stack realignment is really needed after reload */
11325   if (stack_realign_drap)
11326     {
11327       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
11328
11329       /* Only need to push parameter pointer reg if it is caller saved.  */
11330       if (!call_used_regs[REGNO (crtl->drap_reg)])
11331         {
11332           /* Push arg pointer reg */
11333           insn = emit_insn (gen_push (crtl->drap_reg));
11334           RTX_FRAME_RELATED_P (insn) = 1;
11335         }
11336
11337       /* Grab the argument pointer.  */
11338       t = plus_constant (Pmode, stack_pointer_rtx, m->fs.sp_offset);
11339       insn = emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, t));
11340       RTX_FRAME_RELATED_P (insn) = 1;
11341       m->fs.cfa_reg = crtl->drap_reg;
11342       m->fs.cfa_offset = 0;
11343
11344       /* Align the stack.  */
11345       insn = emit_insn (ix86_gen_andsp (stack_pointer_rtx,
11346                                         stack_pointer_rtx,
11347                                         GEN_INT (-align_bytes)));
11348       RTX_FRAME_RELATED_P (insn) = 1;
11349
11350       /* Replicate the return address on the stack so that return
11351          address can be reached via (argp - 1) slot.  This is needed
11352          to implement macro RETURN_ADDR_RTX and intrinsic function
11353          expand_builtin_return_addr etc.  */
11354       t = plus_constant (Pmode, crtl->drap_reg, -UNITS_PER_WORD);
11355       t = gen_frame_mem (word_mode, t);
11356       insn = emit_insn (gen_push (t));
11357       RTX_FRAME_RELATED_P (insn) = 1;
11358
11359       /* For the purposes of frame and register save area addressing,
11360          we've started over with a new frame.  */
11361       m->fs.sp_offset = INCOMING_FRAME_SP_OFFSET;
11362       m->fs.realigned = true;
11363     }
11364
11365   int_registers_saved = (frame.nregs == 0);
11366   sse_registers_saved = (frame.nsseregs == 0);
11367
11368   if (frame_pointer_needed && !m->fs.fp_valid)
11369     {
11370       /* Note: AT&T enter does NOT have reversed args.  Enter is probably
11371          slower on all targets.  Also sdb doesn't like it.  */
11372       insn = emit_insn (gen_push (hard_frame_pointer_rtx));
11373       RTX_FRAME_RELATED_P (insn) = 1;
11374
11375       /* Push registers now, before setting the frame pointer
11376          on SEH target.  */
11377       if (!int_registers_saved
11378           && TARGET_SEH
11379           && !frame.save_regs_using_mov)
11380         {
11381           ix86_emit_save_regs ();
11382           int_registers_saved = true;
11383           gcc_assert (m->fs.sp_offset == frame.reg_save_offset);
11384         }
11385
11386       if (m->fs.sp_offset == frame.hard_frame_pointer_offset)
11387         {
11388           insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
11389           RTX_FRAME_RELATED_P (insn) = 1;
11390
11391           if (m->fs.cfa_reg == stack_pointer_rtx)
11392             m->fs.cfa_reg = hard_frame_pointer_rtx;
11393           m->fs.fp_offset = m->fs.sp_offset;
11394           m->fs.fp_valid = true;
11395         }
11396     }
11397
11398   if (!int_registers_saved)
11399     {
11400       /* If saving registers via PUSH, do so now.  */
11401       if (!frame.save_regs_using_mov)
11402         {
11403           ix86_emit_save_regs ();
11404           int_registers_saved = true;
11405           gcc_assert (m->fs.sp_offset == frame.reg_save_offset);
11406         }
11407
11408       /* When using red zone we may start register saving before allocating
11409          the stack frame saving one cycle of the prologue.  However, avoid
11410          doing this if we have to probe the stack; at least on x86_64 the
11411          stack probe can turn into a call that clobbers a red zone location. */
11412       else if (ix86_using_red_zone ()
11413                && (! TARGET_STACK_PROBE
11414                    || frame.stack_pointer_offset < CHECK_STACK_LIMIT))
11415         {
11416           ix86_emit_save_regs_using_mov (frame.reg_save_offset);
11417           int_registers_saved = true;
11418         }
11419     }
11420
11421   if (stack_realign_fp)
11422     {
11423       int align_bytes = crtl->stack_alignment_needed / BITS_PER_UNIT;
11424       gcc_assert (align_bytes > MIN_STACK_BOUNDARY / BITS_PER_UNIT);
11425
11426       /* The computation of the size of the re-aligned stack frame means
11427          that we must allocate the size of the register save area before
11428          performing the actual alignment.  Otherwise we cannot guarantee
11429          that there's enough storage above the realignment point.  */
11430       if (m->fs.sp_offset != frame.sse_reg_save_offset)
11431         pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11432                                    GEN_INT (m->fs.sp_offset
11433                                             - frame.sse_reg_save_offset),
11434                                    -1, false);
11435
11436       /* Align the stack.  */
11437       insn = emit_insn (ix86_gen_andsp (stack_pointer_rtx,
11438                                         stack_pointer_rtx,
11439                                         GEN_INT (-align_bytes)));
11440
11441       /* For the purposes of register save area addressing, the stack
11442          pointer is no longer valid.  As for the value of sp_offset,
11443          see ix86_compute_frame_layout, which we need to match in order
11444          to pass verification of stack_pointer_offset at the end.  */
11445       m->fs.sp_offset = (m->fs.sp_offset + align_bytes) & -align_bytes;
11446       m->fs.sp_valid = false;
11447     }
11448
11449   allocate = frame.stack_pointer_offset - m->fs.sp_offset;
11450
11451   if (flag_stack_usage_info)
11452     {
11453       /* We start to count from ARG_POINTER.  */
11454       HOST_WIDE_INT stack_size = frame.stack_pointer_offset;
11455
11456       /* If it was realigned, take into account the fake frame.  */
11457       if (stack_realign_drap)
11458         {
11459           if (ix86_static_chain_on_stack)
11460             stack_size += UNITS_PER_WORD;
11461
11462           if (!call_used_regs[REGNO (crtl->drap_reg)])
11463             stack_size += UNITS_PER_WORD;
11464
11465           /* This over-estimates by 1 minimal-stack-alignment-unit but
11466              mitigates that by counting in the new return address slot.  */
11467           current_function_dynamic_stack_size
11468             += crtl->stack_alignment_needed / BITS_PER_UNIT;
11469         }
11470
11471       current_function_static_stack_size = stack_size;
11472     }
11473
11474   /* On SEH target with very large frame size, allocate an area to save
11475      SSE registers (as the very large allocation won't be described).  */
11476   if (TARGET_SEH
11477       && frame.stack_pointer_offset > SEH_MAX_FRAME_SIZE
11478       && !sse_registers_saved)
11479     {
11480       HOST_WIDE_INT sse_size =
11481         frame.sse_reg_save_offset - frame.reg_save_offset;
11482
11483       gcc_assert (int_registers_saved);
11484
11485       /* No need to do stack checking as the area will be immediately
11486          written.  */
11487       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11488                                  GEN_INT (-sse_size), -1,
11489                                  m->fs.cfa_reg == stack_pointer_rtx);
11490       allocate -= sse_size;
11491       ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
11492       sse_registers_saved = true;
11493     }
11494
11495   /* The stack has already been decremented by the instruction calling us
11496      so probe if the size is non-negative to preserve the protection area.  */
11497   if (allocate >= 0 && flag_stack_check == STATIC_BUILTIN_STACK_CHECK)
11498     {
11499       /* We expect the registers to be saved when probes are used.  */
11500       gcc_assert (int_registers_saved);
11501
11502       if (STACK_CHECK_MOVING_SP)
11503         {
11504           if (!(crtl->is_leaf && !cfun->calls_alloca
11505                 && allocate <= PROBE_INTERVAL))
11506             {
11507               ix86_adjust_stack_and_probe (allocate);
11508               allocate = 0;
11509             }
11510         }
11511       else
11512         {
11513           HOST_WIDE_INT size = allocate;
11514
11515           if (TARGET_64BIT && size >= (HOST_WIDE_INT) 0x80000000)
11516             size = 0x80000000 - STACK_CHECK_PROTECT - 1;
11517
11518           if (TARGET_STACK_PROBE)
11519             {
11520               if (crtl->is_leaf && !cfun->calls_alloca)
11521                 {
11522                   if (size > PROBE_INTERVAL)
11523                     ix86_emit_probe_stack_range (0, size);
11524                 }
11525               else
11526                 ix86_emit_probe_stack_range (0, size + STACK_CHECK_PROTECT);
11527             }
11528           else
11529             {
11530               if (crtl->is_leaf && !cfun->calls_alloca)
11531                 {
11532                   if (size > PROBE_INTERVAL && size > STACK_CHECK_PROTECT)
11533                     ix86_emit_probe_stack_range (STACK_CHECK_PROTECT,
11534                                                  size - STACK_CHECK_PROTECT);
11535                 }
11536               else
11537                 ix86_emit_probe_stack_range (STACK_CHECK_PROTECT, size);
11538             }
11539         }
11540     }
11541
11542   if (allocate == 0)
11543     ;
11544   else if (!ix86_target_stack_probe ()
11545            || frame.stack_pointer_offset < CHECK_STACK_LIMIT)
11546     {
11547       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11548                                  GEN_INT (-allocate), -1,
11549                                  m->fs.cfa_reg == stack_pointer_rtx);
11550     }
11551   else
11552     {
11553       rtx eax = gen_rtx_REG (Pmode, AX_REG);
11554       rtx r10 = NULL;
11555       rtx (*adjust_stack_insn)(rtx, rtx, rtx);
11556       const bool sp_is_cfa_reg = (m->fs.cfa_reg == stack_pointer_rtx);
11557       bool eax_live = ix86_eax_live_at_start_p ();
11558       bool r10_live = false;
11559
11560       if (TARGET_64BIT)
11561         r10_live = (DECL_STATIC_CHAIN (current_function_decl) != 0);
11562
11563       if (eax_live)
11564         {
11565           insn = emit_insn (gen_push (eax));
11566           allocate -= UNITS_PER_WORD;
11567           /* Note that SEH directives need to continue tracking the stack
11568              pointer even after the frame pointer has been set up.  */
11569           if (sp_is_cfa_reg || TARGET_SEH)
11570             {
11571               if (sp_is_cfa_reg)
11572                 m->fs.cfa_offset += UNITS_PER_WORD;
11573               RTX_FRAME_RELATED_P (insn) = 1;
11574               add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11575                             gen_rtx_SET (VOIDmode, stack_pointer_rtx,
11576                                          plus_constant (Pmode, stack_pointer_rtx,
11577                                                         -UNITS_PER_WORD)));
11578             }
11579         }
11580
11581       if (r10_live)
11582         {
11583           r10 = gen_rtx_REG (Pmode, R10_REG);
11584           insn = emit_insn (gen_push (r10));
11585           allocate -= UNITS_PER_WORD;
11586           if (sp_is_cfa_reg || TARGET_SEH)
11587             {
11588               if (sp_is_cfa_reg)
11589                 m->fs.cfa_offset += UNITS_PER_WORD;
11590               RTX_FRAME_RELATED_P (insn) = 1;
11591               add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11592                             gen_rtx_SET (VOIDmode, stack_pointer_rtx,
11593                                          plus_constant (Pmode, stack_pointer_rtx,
11594                                                         -UNITS_PER_WORD)));
11595             }
11596         }
11597
11598       emit_move_insn (eax, GEN_INT (allocate));
11599       emit_insn (ix86_gen_allocate_stack_worker (eax, eax));
11600
11601       /* Use the fact that AX still contains ALLOCATE.  */
11602       adjust_stack_insn = (Pmode == DImode
11603                            ? gen_pro_epilogue_adjust_stack_di_sub
11604                            : gen_pro_epilogue_adjust_stack_si_sub);
11605
11606       insn = emit_insn (adjust_stack_insn (stack_pointer_rtx,
11607                                            stack_pointer_rtx, eax));
11608
11609       if (sp_is_cfa_reg || TARGET_SEH)
11610         {
11611           if (sp_is_cfa_reg)
11612             m->fs.cfa_offset += allocate;
11613           RTX_FRAME_RELATED_P (insn) = 1;
11614           add_reg_note (insn, REG_FRAME_RELATED_EXPR,
11615                         gen_rtx_SET (VOIDmode, stack_pointer_rtx,
11616                                      plus_constant (Pmode, stack_pointer_rtx,
11617                                                     -allocate)));
11618         }
11619       m->fs.sp_offset += allocate;
11620
11621       /* Use stack_pointer_rtx for relative addressing so that code
11622          works for realigned stack, too.  */
11623       if (r10_live && eax_live)
11624         {
11625           t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
11626           emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
11627                           gen_frame_mem (word_mode, t));
11628           t = plus_constant (Pmode, t, UNITS_PER_WORD);
11629           emit_move_insn (gen_rtx_REG (word_mode, AX_REG),
11630                           gen_frame_mem (word_mode, t));
11631         }
11632       else if (eax_live || r10_live)
11633         {
11634           t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, eax);
11635           emit_move_insn (gen_rtx_REG (word_mode,
11636                                        (eax_live ? AX_REG : R10_REG)),
11637                           gen_frame_mem (word_mode, t));
11638         }
11639     }
11640   gcc_assert (m->fs.sp_offset == frame.stack_pointer_offset);
11641
11642   /* If we havn't already set up the frame pointer, do so now.  */
11643   if (frame_pointer_needed && !m->fs.fp_valid)
11644     {
11645       insn = ix86_gen_add3 (hard_frame_pointer_rtx, stack_pointer_rtx,
11646                             GEN_INT (frame.stack_pointer_offset
11647                                      - frame.hard_frame_pointer_offset));
11648       insn = emit_insn (insn);
11649       RTX_FRAME_RELATED_P (insn) = 1;
11650       add_reg_note (insn, REG_CFA_ADJUST_CFA, NULL);
11651
11652       if (m->fs.cfa_reg == stack_pointer_rtx)
11653         m->fs.cfa_reg = hard_frame_pointer_rtx;
11654       m->fs.fp_offset = frame.hard_frame_pointer_offset;
11655       m->fs.fp_valid = true;
11656     }
11657
11658   if (!int_registers_saved)
11659     ix86_emit_save_regs_using_mov (frame.reg_save_offset);
11660   if (!sse_registers_saved)
11661     ix86_emit_save_sse_regs_using_mov (frame.sse_reg_save_offset);
11662
11663   /* For the mcount profiling on 32 bit PIC mode we need to emit SET_GOT
11664      in PROLOGUE.  */
11665   if (!TARGET_64BIT && pic_offset_table_rtx && crtl->profile && !flag_fentry)
11666     {
11667       rtx pic = gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM);
11668       insn = emit_insn (gen_set_got (pic));
11669       RTX_FRAME_RELATED_P (insn) = 1;
11670       add_reg_note (insn, REG_CFA_FLUSH_QUEUE, NULL_RTX);
11671       emit_insn (gen_prologue_use (pic));
11672       /* Deleting already emmitted SET_GOT if exist and allocated to
11673          REAL_PIC_OFFSET_TABLE_REGNUM.  */
11674       ix86_elim_entry_set_got (pic);
11675     }
11676
11677   if (crtl->drap_reg && !crtl->stack_realign_needed)
11678     {
11679       /* vDRAP is setup but after reload it turns out stack realign
11680          isn't necessary, here we will emit prologue to setup DRAP
11681          without stack realign adjustment */
11682       t = choose_baseaddr (0);
11683       emit_insn (gen_rtx_SET (VOIDmode, crtl->drap_reg, t));
11684     }
11685
11686   /* Prevent instructions from being scheduled into register save push
11687      sequence when access to the redzone area is done through frame pointer.
11688      The offset between the frame pointer and the stack pointer is calculated
11689      relative to the value of the stack pointer at the end of the function
11690      prologue, and moving instructions that access redzone area via frame
11691      pointer inside push sequence violates this assumption.  */
11692   if (frame_pointer_needed && frame.red_zone_size)
11693     emit_insn (gen_memory_blockage ());
11694
11695   /* Emit cld instruction if stringops are used in the function.  */
11696   if (TARGET_CLD && ix86_current_function_needs_cld)
11697     emit_insn (gen_cld ());
11698
11699   /* SEH requires that the prologue end within 256 bytes of the start of
11700      the function.  Prevent instruction schedules that would extend that.
11701      Further, prevent alloca modifications to the stack pointer from being
11702      combined with prologue modifications.  */
11703   if (TARGET_SEH)
11704     emit_insn (gen_prologue_use (stack_pointer_rtx));
11705 }
11706
11707 /* Emit code to restore REG using a POP insn.  */
11708
11709 static void
11710 ix86_emit_restore_reg_using_pop (rtx reg)
11711 {
11712   struct machine_function *m = cfun->machine;
11713   rtx insn = emit_insn (gen_pop (reg));
11714
11715   ix86_add_cfa_restore_note (insn, reg, m->fs.sp_offset);
11716   m->fs.sp_offset -= UNITS_PER_WORD;
11717
11718   if (m->fs.cfa_reg == crtl->drap_reg
11719       && REGNO (reg) == REGNO (crtl->drap_reg))
11720     {
11721       /* Previously we'd represented the CFA as an expression
11722          like *(%ebp - 8).  We've just popped that value from
11723          the stack, which means we need to reset the CFA to
11724          the drap register.  This will remain until we restore
11725          the stack pointer.  */
11726       add_reg_note (insn, REG_CFA_DEF_CFA, reg);
11727       RTX_FRAME_RELATED_P (insn) = 1;
11728
11729       /* This means that the DRAP register is valid for addressing too.  */
11730       m->fs.drap_valid = true;
11731       return;
11732     }
11733
11734   if (m->fs.cfa_reg == stack_pointer_rtx)
11735     {
11736       rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
11737       x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
11738       add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
11739       RTX_FRAME_RELATED_P (insn) = 1;
11740
11741       m->fs.cfa_offset -= UNITS_PER_WORD;
11742     }
11743
11744   /* When the frame pointer is the CFA, and we pop it, we are
11745      swapping back to the stack pointer as the CFA.  This happens
11746      for stack frames that don't allocate other data, so we assume
11747      the stack pointer is now pointing at the return address, i.e.
11748      the function entry state, which makes the offset be 1 word.  */
11749   if (reg == hard_frame_pointer_rtx)
11750     {
11751       m->fs.fp_valid = false;
11752       if (m->fs.cfa_reg == hard_frame_pointer_rtx)
11753         {
11754           m->fs.cfa_reg = stack_pointer_rtx;
11755           m->fs.cfa_offset -= UNITS_PER_WORD;
11756
11757           add_reg_note (insn, REG_CFA_DEF_CFA,
11758                         gen_rtx_PLUS (Pmode, stack_pointer_rtx,
11759                                       GEN_INT (m->fs.cfa_offset)));
11760           RTX_FRAME_RELATED_P (insn) = 1;
11761         }
11762     }
11763 }
11764
11765 /* Emit code to restore saved registers using POP insns.  */
11766
11767 static void
11768 ix86_emit_restore_regs_using_pop (void)
11769 {
11770   unsigned int regno;
11771
11772   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11773     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, false))
11774       ix86_emit_restore_reg_using_pop (gen_rtx_REG (word_mode, regno));
11775 }
11776
11777 /* Emit code and notes for the LEAVE instruction.  */
11778
11779 static void
11780 ix86_emit_leave (void)
11781 {
11782   struct machine_function *m = cfun->machine;
11783   rtx insn = emit_insn (ix86_gen_leave ());
11784
11785   ix86_add_queued_cfa_restore_notes (insn);
11786
11787   gcc_assert (m->fs.fp_valid);
11788   m->fs.sp_valid = true;
11789   m->fs.sp_offset = m->fs.fp_offset - UNITS_PER_WORD;
11790   m->fs.fp_valid = false;
11791
11792   if (m->fs.cfa_reg == hard_frame_pointer_rtx)
11793     {
11794       m->fs.cfa_reg = stack_pointer_rtx;
11795       m->fs.cfa_offset = m->fs.sp_offset;
11796
11797       add_reg_note (insn, REG_CFA_DEF_CFA,
11798                     plus_constant (Pmode, stack_pointer_rtx,
11799                                    m->fs.sp_offset));
11800       RTX_FRAME_RELATED_P (insn) = 1;
11801     }
11802   ix86_add_cfa_restore_note (insn, hard_frame_pointer_rtx,
11803                              m->fs.fp_offset);
11804 }
11805
11806 /* Emit code to restore saved registers using MOV insns.
11807    First register is restored from CFA - CFA_OFFSET.  */
11808 static void
11809 ix86_emit_restore_regs_using_mov (HOST_WIDE_INT cfa_offset,
11810                                   bool maybe_eh_return)
11811 {
11812   struct machine_function *m = cfun->machine;
11813   unsigned int regno;
11814
11815   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11816     if (!SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
11817       {
11818         rtx reg = gen_rtx_REG (word_mode, regno);
11819         rtx insn, mem;
11820
11821         mem = choose_baseaddr (cfa_offset);
11822         mem = gen_frame_mem (word_mode, mem);
11823         insn = emit_move_insn (reg, mem);
11824
11825         if (m->fs.cfa_reg == crtl->drap_reg && regno == REGNO (crtl->drap_reg))
11826           {
11827             /* Previously we'd represented the CFA as an expression
11828                like *(%ebp - 8).  We've just popped that value from
11829                the stack, which means we need to reset the CFA to
11830                the drap register.  This will remain until we restore
11831                the stack pointer.  */
11832             add_reg_note (insn, REG_CFA_DEF_CFA, reg);
11833             RTX_FRAME_RELATED_P (insn) = 1;
11834
11835             /* This means that the DRAP register is valid for addressing.  */
11836             m->fs.drap_valid = true;
11837           }
11838         else
11839           ix86_add_cfa_restore_note (NULL_RTX, reg, cfa_offset);
11840
11841         cfa_offset -= UNITS_PER_WORD;
11842       }
11843 }
11844
11845 /* Emit code to restore saved registers using MOV insns.
11846    First register is restored from CFA - CFA_OFFSET.  */
11847 static void
11848 ix86_emit_restore_sse_regs_using_mov (HOST_WIDE_INT cfa_offset,
11849                                       bool maybe_eh_return)
11850 {
11851   unsigned int regno;
11852
11853   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
11854     if (SSE_REGNO_P (regno) && ix86_save_reg (regno, maybe_eh_return))
11855       {
11856         rtx reg = gen_rtx_REG (V4SFmode, regno);
11857         rtx mem;
11858
11859         mem = choose_baseaddr (cfa_offset);
11860         mem = gen_rtx_MEM (V4SFmode, mem);
11861         set_mem_align (mem, 128);
11862         emit_move_insn (reg, mem);
11863
11864         ix86_add_cfa_restore_note (NULL_RTX, reg, cfa_offset);
11865
11866         cfa_offset -= 16;
11867       }
11868 }
11869
11870 /* Restore function stack, frame, and registers.  */
11871
11872 void
11873 ix86_expand_epilogue (int style)
11874 {
11875   struct machine_function *m = cfun->machine;
11876   struct machine_frame_state frame_state_save = m->fs;
11877   struct ix86_frame frame;
11878   bool restore_regs_via_mov;
11879   bool using_drap;
11880
11881   ix86_finalize_stack_realign_flags ();
11882   ix86_compute_frame_layout (&frame);
11883
11884   m->fs.sp_valid = (!frame_pointer_needed
11885                     || (crtl->sp_is_unchanging
11886                         && !stack_realign_fp));
11887   gcc_assert (!m->fs.sp_valid
11888               || m->fs.sp_offset == frame.stack_pointer_offset);
11889
11890   /* The FP must be valid if the frame pointer is present.  */
11891   gcc_assert (frame_pointer_needed == m->fs.fp_valid);
11892   gcc_assert (!m->fs.fp_valid
11893               || m->fs.fp_offset == frame.hard_frame_pointer_offset);
11894
11895   /* We must have *some* valid pointer to the stack frame.  */
11896   gcc_assert (m->fs.sp_valid || m->fs.fp_valid);
11897
11898   /* The DRAP is never valid at this point.  */
11899   gcc_assert (!m->fs.drap_valid);
11900
11901   /* See the comment about red zone and frame
11902      pointer usage in ix86_expand_prologue.  */
11903   if (frame_pointer_needed && frame.red_zone_size)
11904     emit_insn (gen_memory_blockage ());
11905
11906   using_drap = crtl->drap_reg && crtl->stack_realign_needed;
11907   gcc_assert (!using_drap || m->fs.cfa_reg == crtl->drap_reg);
11908
11909   /* Determine the CFA offset of the end of the red-zone.  */
11910   m->fs.red_zone_offset = 0;
11911   if (ix86_using_red_zone () && crtl->args.pops_args < 65536)
11912     {
11913       /* The red-zone begins below the return address.  */
11914       m->fs.red_zone_offset = RED_ZONE_SIZE + UNITS_PER_WORD;
11915
11916       /* When the register save area is in the aligned portion of
11917          the stack, determine the maximum runtime displacement that
11918          matches up with the aligned frame.  */
11919       if (stack_realign_drap)
11920         m->fs.red_zone_offset -= (crtl->stack_alignment_needed / BITS_PER_UNIT
11921                                   + UNITS_PER_WORD);
11922     }
11923
11924   /* Special care must be taken for the normal return case of a function
11925      using eh_return: the eax and edx registers are marked as saved, but
11926      not restored along this path.  Adjust the save location to match.  */
11927   if (crtl->calls_eh_return && style != 2)
11928     frame.reg_save_offset -= 2 * UNITS_PER_WORD;
11929
11930   /* EH_RETURN requires the use of moves to function properly.  */
11931   if (crtl->calls_eh_return)
11932     restore_regs_via_mov = true;
11933   /* SEH requires the use of pops to identify the epilogue.  */
11934   else if (TARGET_SEH)
11935     restore_regs_via_mov = false;
11936   /* If we're only restoring one register and sp is not valid then
11937      using a move instruction to restore the register since it's
11938      less work than reloading sp and popping the register.  */
11939   else if (!m->fs.sp_valid && frame.nregs <= 1)
11940     restore_regs_via_mov = true;
11941   else if (TARGET_EPILOGUE_USING_MOVE
11942            && cfun->machine->use_fast_prologue_epilogue
11943            && (frame.nregs > 1
11944                || m->fs.sp_offset != frame.reg_save_offset))
11945     restore_regs_via_mov = true;
11946   else if (frame_pointer_needed
11947            && !frame.nregs
11948            && m->fs.sp_offset != frame.reg_save_offset)
11949     restore_regs_via_mov = true;
11950   else if (frame_pointer_needed
11951            && TARGET_USE_LEAVE
11952            && cfun->machine->use_fast_prologue_epilogue
11953            && frame.nregs == 1)
11954     restore_regs_via_mov = true;
11955   else
11956     restore_regs_via_mov = false;
11957
11958   if (restore_regs_via_mov || frame.nsseregs)
11959     {
11960       /* Ensure that the entire register save area is addressable via
11961          the stack pointer, if we will restore via sp.  */
11962       if (TARGET_64BIT
11963           && m->fs.sp_offset > 0x7fffffff
11964           && !(m->fs.fp_valid || m->fs.drap_valid)
11965           && (frame.nsseregs + frame.nregs) != 0)
11966         {
11967           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
11968                                      GEN_INT (m->fs.sp_offset
11969                                               - frame.sse_reg_save_offset),
11970                                      style,
11971                                      m->fs.cfa_reg == stack_pointer_rtx);
11972         }
11973     }
11974
11975   /* If there are any SSE registers to restore, then we have to do it
11976      via moves, since there's obviously no pop for SSE regs.  */
11977   if (frame.nsseregs)
11978     ix86_emit_restore_sse_regs_using_mov (frame.sse_reg_save_offset,
11979                                           style == 2);
11980
11981   if (restore_regs_via_mov)
11982     {
11983       rtx t;
11984
11985       if (frame.nregs)
11986         ix86_emit_restore_regs_using_mov (frame.reg_save_offset, style == 2);
11987
11988       /* eh_return epilogues need %ecx added to the stack pointer.  */
11989       if (style == 2)
11990         {
11991           rtx insn, sa = EH_RETURN_STACKADJ_RTX;
11992
11993           /* Stack align doesn't work with eh_return.  */
11994           gcc_assert (!stack_realign_drap);
11995           /* Neither does regparm nested functions.  */
11996           gcc_assert (!ix86_static_chain_on_stack);
11997
11998           if (frame_pointer_needed)
11999             {
12000               t = gen_rtx_PLUS (Pmode, hard_frame_pointer_rtx, sa);
12001               t = plus_constant (Pmode, t, m->fs.fp_offset - UNITS_PER_WORD);
12002               emit_insn (gen_rtx_SET (VOIDmode, sa, t));
12003
12004               t = gen_frame_mem (Pmode, hard_frame_pointer_rtx);
12005               insn = emit_move_insn (hard_frame_pointer_rtx, t);
12006
12007               /* Note that we use SA as a temporary CFA, as the return
12008                  address is at the proper place relative to it.  We
12009                  pretend this happens at the FP restore insn because
12010                  prior to this insn the FP would be stored at the wrong
12011                  offset relative to SA, and after this insn we have no
12012                  other reasonable register to use for the CFA.  We don't
12013                  bother resetting the CFA to the SP for the duration of
12014                  the return insn.  */
12015               add_reg_note (insn, REG_CFA_DEF_CFA,
12016                             plus_constant (Pmode, sa, UNITS_PER_WORD));
12017               ix86_add_queued_cfa_restore_notes (insn);
12018               add_reg_note (insn, REG_CFA_RESTORE, hard_frame_pointer_rtx);
12019               RTX_FRAME_RELATED_P (insn) = 1;
12020
12021               m->fs.cfa_reg = sa;
12022               m->fs.cfa_offset = UNITS_PER_WORD;
12023               m->fs.fp_valid = false;
12024
12025               pro_epilogue_adjust_stack (stack_pointer_rtx, sa,
12026                                          const0_rtx, style, false);
12027             }
12028           else
12029             {
12030               t = gen_rtx_PLUS (Pmode, stack_pointer_rtx, sa);
12031               t = plus_constant (Pmode, t, m->fs.sp_offset - UNITS_PER_WORD);
12032               insn = emit_insn (gen_rtx_SET (VOIDmode, stack_pointer_rtx, t));
12033               ix86_add_queued_cfa_restore_notes (insn);
12034
12035               gcc_assert (m->fs.cfa_reg == stack_pointer_rtx);
12036               if (m->fs.cfa_offset != UNITS_PER_WORD)
12037                 {
12038                   m->fs.cfa_offset = UNITS_PER_WORD;
12039                   add_reg_note (insn, REG_CFA_DEF_CFA,
12040                                 plus_constant (Pmode, stack_pointer_rtx,
12041                                                UNITS_PER_WORD));
12042                   RTX_FRAME_RELATED_P (insn) = 1;
12043                 }
12044             }
12045           m->fs.sp_offset = UNITS_PER_WORD;
12046           m->fs.sp_valid = true;
12047         }
12048     }
12049   else
12050     {
12051       /* SEH requires that the function end with (1) a stack adjustment
12052          if necessary, (2) a sequence of pops, and (3) a return or
12053          jump instruction.  Prevent insns from the function body from
12054          being scheduled into this sequence.  */
12055       if (TARGET_SEH)
12056         {
12057           /* Prevent a catch region from being adjacent to the standard
12058              epilogue sequence.  Unfortuantely crtl->uses_eh_lsda nor
12059              several other flags that would be interesting to test are
12060              not yet set up.  */
12061           if (flag_non_call_exceptions)
12062             emit_insn (gen_nops (const1_rtx));
12063           else
12064             emit_insn (gen_blockage ());
12065         }
12066
12067       /* First step is to deallocate the stack frame so that we can
12068          pop the registers.  Also do it on SEH target for very large
12069          frame as the emitted instructions aren't allowed by the ABI in
12070          epilogues.  */
12071       if (!m->fs.sp_valid
12072           || (TARGET_SEH
12073               && (m->fs.sp_offset - frame.reg_save_offset
12074                   >= SEH_MAX_FRAME_SIZE)))
12075         {
12076           pro_epilogue_adjust_stack (stack_pointer_rtx, hard_frame_pointer_rtx,
12077                                      GEN_INT (m->fs.fp_offset
12078                                               - frame.reg_save_offset),
12079                                      style, false);
12080         }
12081       else if (m->fs.sp_offset != frame.reg_save_offset)
12082         {
12083           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12084                                      GEN_INT (m->fs.sp_offset
12085                                               - frame.reg_save_offset),
12086                                      style,
12087                                      m->fs.cfa_reg == stack_pointer_rtx);
12088         }
12089
12090       ix86_emit_restore_regs_using_pop ();
12091     }
12092
12093   /* If we used a stack pointer and haven't already got rid of it,
12094      then do so now.  */
12095   if (m->fs.fp_valid)
12096     {
12097       /* If the stack pointer is valid and pointing at the frame
12098          pointer store address, then we only need a pop.  */
12099       if (m->fs.sp_valid && m->fs.sp_offset == frame.hfp_save_offset)
12100         ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
12101       /* Leave results in shorter dependency chains on CPUs that are
12102          able to grok it fast.  */
12103       else if (TARGET_USE_LEAVE
12104                || optimize_bb_for_size_p (EXIT_BLOCK_PTR_FOR_FN (cfun))
12105                || !cfun->machine->use_fast_prologue_epilogue)
12106         ix86_emit_leave ();
12107       else
12108         {
12109           pro_epilogue_adjust_stack (stack_pointer_rtx,
12110                                      hard_frame_pointer_rtx,
12111                                      const0_rtx, style, !using_drap);
12112           ix86_emit_restore_reg_using_pop (hard_frame_pointer_rtx);
12113         }
12114     }
12115
12116   if (using_drap)
12117     {
12118       int param_ptr_offset = UNITS_PER_WORD;
12119       rtx insn;
12120
12121       gcc_assert (stack_realign_drap);
12122
12123       if (ix86_static_chain_on_stack)
12124         param_ptr_offset += UNITS_PER_WORD;
12125       if (!call_used_regs[REGNO (crtl->drap_reg)])
12126         param_ptr_offset += UNITS_PER_WORD;
12127
12128       insn = emit_insn (gen_rtx_SET
12129                         (VOIDmode, stack_pointer_rtx,
12130                          gen_rtx_PLUS (Pmode,
12131                                        crtl->drap_reg,
12132                                        GEN_INT (-param_ptr_offset))));
12133       m->fs.cfa_reg = stack_pointer_rtx;
12134       m->fs.cfa_offset = param_ptr_offset;
12135       m->fs.sp_offset = param_ptr_offset;
12136       m->fs.realigned = false;
12137
12138       add_reg_note (insn, REG_CFA_DEF_CFA,
12139                     gen_rtx_PLUS (Pmode, stack_pointer_rtx,
12140                                   GEN_INT (param_ptr_offset)));
12141       RTX_FRAME_RELATED_P (insn) = 1;
12142
12143       if (!call_used_regs[REGNO (crtl->drap_reg)])
12144         ix86_emit_restore_reg_using_pop (crtl->drap_reg);
12145     }
12146
12147   /* At this point the stack pointer must be valid, and we must have
12148      restored all of the registers.  We may not have deallocated the
12149      entire stack frame.  We've delayed this until now because it may
12150      be possible to merge the local stack deallocation with the
12151      deallocation forced by ix86_static_chain_on_stack.   */
12152   gcc_assert (m->fs.sp_valid);
12153   gcc_assert (!m->fs.fp_valid);
12154   gcc_assert (!m->fs.realigned);
12155   if (m->fs.sp_offset != UNITS_PER_WORD)
12156     {
12157       pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12158                                  GEN_INT (m->fs.sp_offset - UNITS_PER_WORD),
12159                                  style, true);
12160     }
12161   else
12162     ix86_add_queued_cfa_restore_notes (get_last_insn ());
12163
12164   /* Sibcall epilogues don't want a return instruction.  */
12165   if (style == 0)
12166     {
12167       m->fs = frame_state_save;
12168       return;
12169     }
12170
12171   if (crtl->args.pops_args && crtl->args.size)
12172     {
12173       rtx popc = GEN_INT (crtl->args.pops_args);
12174
12175       /* i386 can only pop 64K bytes.  If asked to pop more, pop return
12176          address, do explicit add, and jump indirectly to the caller.  */
12177
12178       if (crtl->args.pops_args >= 65536)
12179         {
12180           rtx ecx = gen_rtx_REG (SImode, CX_REG);
12181           rtx insn;
12182
12183           /* There is no "pascal" calling convention in any 64bit ABI.  */
12184           gcc_assert (!TARGET_64BIT);
12185
12186           insn = emit_insn (gen_pop (ecx));
12187           m->fs.cfa_offset -= UNITS_PER_WORD;
12188           m->fs.sp_offset -= UNITS_PER_WORD;
12189
12190           rtx x = plus_constant (Pmode, stack_pointer_rtx, UNITS_PER_WORD);
12191           x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
12192           add_reg_note (insn, REG_CFA_ADJUST_CFA, x);
12193           add_reg_note (insn, REG_CFA_REGISTER,
12194                         gen_rtx_SET (VOIDmode, ecx, pc_rtx));
12195           RTX_FRAME_RELATED_P (insn) = 1;
12196
12197           pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
12198                                      popc, -1, true);
12199           emit_jump_insn (gen_simple_return_indirect_internal (ecx));
12200         }
12201       else
12202         emit_jump_insn (gen_simple_return_pop_internal (popc));
12203     }
12204   else
12205     emit_jump_insn (gen_simple_return_internal ());
12206
12207   /* Restore the state back to the state from the prologue,
12208      so that it's correct for the next epilogue.  */
12209   m->fs = frame_state_save;
12210 }
12211
12212 /* Reset from the function's potential modifications.  */
12213
12214 static void
12215 ix86_output_function_epilogue (FILE *file ATTRIBUTE_UNUSED, HOST_WIDE_INT)
12216 {
12217   if (pic_offset_table_rtx
12218       && !ix86_use_pseudo_pic_reg ())
12219     SET_REGNO (pic_offset_table_rtx, REAL_PIC_OFFSET_TABLE_REGNUM);
12220 #if TARGET_MACHO
12221   /* Mach-O doesn't support labels at the end of objects, so if
12222      it looks like we might want one, insert a NOP.  */
12223   {
12224     rtx_insn *insn = get_last_insn ();
12225     rtx_insn *deleted_debug_label = NULL;
12226     while (insn
12227            && NOTE_P (insn)
12228            && NOTE_KIND (insn) != NOTE_INSN_DELETED_LABEL)
12229       {
12230         /* Don't insert a nop for NOTE_INSN_DELETED_DEBUG_LABEL
12231            notes only, instead set their CODE_LABEL_NUMBER to -1,
12232            otherwise there would be code generation differences
12233            in between -g and -g0.  */
12234         if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
12235           deleted_debug_label = insn;
12236         insn = PREV_INSN (insn);
12237       }
12238     if (insn
12239         && (LABEL_P (insn)
12240             || (NOTE_P (insn)
12241                 && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL)))
12242       fputs ("\tnop\n", file);
12243     else if (deleted_debug_label)
12244       for (insn = deleted_debug_label; insn; insn = NEXT_INSN (insn))
12245         if (NOTE_KIND (insn) == NOTE_INSN_DELETED_DEBUG_LABEL)
12246           CODE_LABEL_NUMBER (insn) = -1;
12247   }
12248 #endif
12249
12250 }
12251
12252 /* Return a scratch register to use in the split stack prologue.  The
12253    split stack prologue is used for -fsplit-stack.  It is the first
12254    instructions in the function, even before the regular prologue.
12255    The scratch register can be any caller-saved register which is not
12256    used for parameters or for the static chain.  */
12257
12258 static unsigned int
12259 split_stack_prologue_scratch_regno (void)
12260 {
12261   if (TARGET_64BIT)
12262     return R11_REG;
12263   else
12264     {
12265       bool is_fastcall, is_thiscall;
12266       int regparm;
12267
12268       is_fastcall = (lookup_attribute ("fastcall",
12269                                        TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
12270                      != NULL);
12271       is_thiscall = (lookup_attribute ("thiscall",
12272                                        TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
12273                      != NULL);
12274       regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl);
12275
12276       if (is_fastcall)
12277         {
12278           if (DECL_STATIC_CHAIN (cfun->decl))
12279             {
12280               sorry ("-fsplit-stack does not support fastcall with "
12281                      "nested function");
12282               return INVALID_REGNUM;
12283             }
12284           return AX_REG;
12285         }
12286       else if (is_thiscall)
12287         {
12288           if (!DECL_STATIC_CHAIN (cfun->decl))
12289             return DX_REG;
12290           return AX_REG;
12291         }
12292       else if (regparm < 3)
12293         {
12294           if (!DECL_STATIC_CHAIN (cfun->decl))
12295             return CX_REG;
12296           else
12297             {
12298               if (regparm >= 2)
12299                 {
12300                   sorry ("-fsplit-stack does not support 2 register "
12301                          "parameters for a nested function");
12302                   return INVALID_REGNUM;
12303                 }
12304               return DX_REG;
12305             }
12306         }
12307       else
12308         {
12309           /* FIXME: We could make this work by pushing a register
12310              around the addition and comparison.  */
12311           sorry ("-fsplit-stack does not support 3 register parameters");
12312           return INVALID_REGNUM;
12313         }
12314     }
12315 }
12316
12317 /* A SYMBOL_REF for the function which allocates new stackspace for
12318    -fsplit-stack.  */
12319
12320 static GTY(()) rtx split_stack_fn;
12321
12322 /* A SYMBOL_REF for the more stack function when using the large
12323    model.  */
12324
12325 static GTY(()) rtx split_stack_fn_large;
12326
12327 /* Handle -fsplit-stack.  These are the first instructions in the
12328    function, even before the regular prologue.  */
12329
12330 void
12331 ix86_expand_split_stack_prologue (void)
12332 {
12333   struct ix86_frame frame;
12334   HOST_WIDE_INT allocate;
12335   unsigned HOST_WIDE_INT args_size;
12336   rtx_code_label *label;
12337   rtx limit, current, jump_insn, allocate_rtx, call_insn, call_fusage;
12338   rtx scratch_reg = NULL_RTX;
12339   rtx_code_label *varargs_label = NULL;
12340   rtx fn;
12341
12342   gcc_assert (flag_split_stack && reload_completed);
12343
12344   ix86_finalize_stack_realign_flags ();
12345   ix86_compute_frame_layout (&frame);
12346   allocate = frame.stack_pointer_offset - INCOMING_FRAME_SP_OFFSET;
12347
12348   /* This is the label we will branch to if we have enough stack
12349      space.  We expect the basic block reordering pass to reverse this
12350      branch if optimizing, so that we branch in the unlikely case.  */
12351   label = gen_label_rtx ();
12352
12353   /* We need to compare the stack pointer minus the frame size with
12354      the stack boundary in the TCB.  The stack boundary always gives
12355      us SPLIT_STACK_AVAILABLE bytes, so if we need less than that we
12356      can compare directly.  Otherwise we need to do an addition.  */
12357
12358   limit = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
12359                           UNSPEC_STACK_CHECK);
12360   limit = gen_rtx_CONST (Pmode, limit);
12361   limit = gen_rtx_MEM (Pmode, limit);
12362   if (allocate < SPLIT_STACK_AVAILABLE)
12363     current = stack_pointer_rtx;
12364   else
12365     {
12366       unsigned int scratch_regno;
12367       rtx offset;
12368
12369       /* We need a scratch register to hold the stack pointer minus
12370          the required frame size.  Since this is the very start of the
12371          function, the scratch register can be any caller-saved
12372          register which is not used for parameters.  */
12373       offset = GEN_INT (- allocate);
12374       scratch_regno = split_stack_prologue_scratch_regno ();
12375       if (scratch_regno == INVALID_REGNUM)
12376         return;
12377       scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
12378       if (!TARGET_64BIT || x86_64_immediate_operand (offset, Pmode))
12379         {
12380           /* We don't use ix86_gen_add3 in this case because it will
12381              want to split to lea, but when not optimizing the insn
12382              will not be split after this point.  */
12383           emit_insn (gen_rtx_SET (VOIDmode, scratch_reg,
12384                                   gen_rtx_PLUS (Pmode, stack_pointer_rtx,
12385                                                 offset)));
12386         }
12387       else
12388         {
12389           emit_move_insn (scratch_reg, offset);
12390           emit_insn (ix86_gen_add3 (scratch_reg, scratch_reg,
12391                                     stack_pointer_rtx));
12392         }
12393       current = scratch_reg;
12394     }
12395
12396   ix86_expand_branch (GEU, current, limit, label);
12397   jump_insn = get_last_insn ();
12398   JUMP_LABEL (jump_insn) = label;
12399
12400   /* Mark the jump as very likely to be taken.  */
12401   add_int_reg_note (jump_insn, REG_BR_PROB,
12402                     REG_BR_PROB_BASE - REG_BR_PROB_BASE / 100);
12403
12404   if (split_stack_fn == NULL_RTX)
12405     {
12406       split_stack_fn = gen_rtx_SYMBOL_REF (Pmode, "__morestack");
12407       SYMBOL_REF_FLAGS (split_stack_fn) |= SYMBOL_FLAG_LOCAL;
12408     }
12409   fn = split_stack_fn;
12410
12411   /* Get more stack space.  We pass in the desired stack space and the
12412      size of the arguments to copy to the new stack.  In 32-bit mode
12413      we push the parameters; __morestack will return on a new stack
12414      anyhow.  In 64-bit mode we pass the parameters in r10 and
12415      r11.  */
12416   allocate_rtx = GEN_INT (allocate);
12417   args_size = crtl->args.size >= 0 ? crtl->args.size : 0;
12418   call_fusage = NULL_RTX;
12419   if (TARGET_64BIT)
12420     {
12421       rtx reg10, reg11;
12422
12423       reg10 = gen_rtx_REG (Pmode, R10_REG);
12424       reg11 = gen_rtx_REG (Pmode, R11_REG);
12425
12426       /* If this function uses a static chain, it will be in %r10.
12427          Preserve it across the call to __morestack.  */
12428       if (DECL_STATIC_CHAIN (cfun->decl))
12429         {
12430           rtx rax;
12431
12432           rax = gen_rtx_REG (word_mode, AX_REG);
12433           emit_move_insn (rax, gen_rtx_REG (word_mode, R10_REG));
12434           use_reg (&call_fusage, rax);
12435         }
12436
12437       if ((ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC)
12438           && !TARGET_PECOFF)
12439         {
12440           HOST_WIDE_INT argval;
12441
12442           gcc_assert (Pmode == DImode);
12443           /* When using the large model we need to load the address
12444              into a register, and we've run out of registers.  So we
12445              switch to a different calling convention, and we call a
12446              different function: __morestack_large.  We pass the
12447              argument size in the upper 32 bits of r10 and pass the
12448              frame size in the lower 32 bits.  */
12449           gcc_assert ((allocate & (HOST_WIDE_INT) 0xffffffff) == allocate);
12450           gcc_assert ((args_size & 0xffffffff) == args_size);
12451
12452           if (split_stack_fn_large == NULL_RTX)
12453             {
12454               split_stack_fn_large =
12455                 gen_rtx_SYMBOL_REF (Pmode, "__morestack_large_model");
12456               SYMBOL_REF_FLAGS (split_stack_fn_large) |= SYMBOL_FLAG_LOCAL;
12457             }
12458           if (ix86_cmodel == CM_LARGE_PIC)
12459             {
12460               rtx_code_label *label;
12461               rtx x;
12462
12463               label = gen_label_rtx ();
12464               emit_label (label);
12465               LABEL_PRESERVE_P (label) = 1;
12466               emit_insn (gen_set_rip_rex64 (reg10, label));
12467               emit_insn (gen_set_got_offset_rex64 (reg11, label));
12468               emit_insn (ix86_gen_add3 (reg10, reg10, reg11));
12469               x = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, split_stack_fn_large),
12470                                   UNSPEC_GOT);
12471               x = gen_rtx_CONST (Pmode, x);
12472               emit_move_insn (reg11, x);
12473               x = gen_rtx_PLUS (Pmode, reg10, reg11);
12474               x = gen_const_mem (Pmode, x);
12475               emit_move_insn (reg11, x);
12476             }
12477           else
12478             emit_move_insn (reg11, split_stack_fn_large);
12479
12480           fn = reg11;
12481
12482           argval = ((args_size << 16) << 16) + allocate;
12483           emit_move_insn (reg10, GEN_INT (argval));
12484         }
12485       else
12486         {
12487           emit_move_insn (reg10, allocate_rtx);
12488           emit_move_insn (reg11, GEN_INT (args_size));
12489           use_reg (&call_fusage, reg11);
12490         }
12491
12492       use_reg (&call_fusage, reg10);
12493     }
12494   else
12495     {
12496       emit_insn (gen_push (GEN_INT (args_size)));
12497       emit_insn (gen_push (allocate_rtx));
12498     }
12499   call_insn = ix86_expand_call (NULL_RTX, gen_rtx_MEM (QImode, fn),
12500                                 GEN_INT (UNITS_PER_WORD), constm1_rtx,
12501                                 NULL_RTX, false);
12502   add_function_usage_to (call_insn, call_fusage);
12503
12504   /* In order to make call/return prediction work right, we now need
12505      to execute a return instruction.  See
12506      libgcc/config/i386/morestack.S for the details on how this works.
12507
12508      For flow purposes gcc must not see this as a return
12509      instruction--we need control flow to continue at the subsequent
12510      label.  Therefore, we use an unspec.  */
12511   gcc_assert (crtl->args.pops_args < 65536);
12512   emit_insn (gen_split_stack_return (GEN_INT (crtl->args.pops_args)));
12513
12514   /* If we are in 64-bit mode and this function uses a static chain,
12515      we saved %r10 in %rax before calling _morestack.  */
12516   if (TARGET_64BIT && DECL_STATIC_CHAIN (cfun->decl))
12517     emit_move_insn (gen_rtx_REG (word_mode, R10_REG),
12518                     gen_rtx_REG (word_mode, AX_REG));
12519
12520   /* If this function calls va_start, we need to store a pointer to
12521      the arguments on the old stack, because they may not have been
12522      all copied to the new stack.  At this point the old stack can be
12523      found at the frame pointer value used by __morestack, because
12524      __morestack has set that up before calling back to us.  Here we
12525      store that pointer in a scratch register, and in
12526      ix86_expand_prologue we store the scratch register in a stack
12527      slot.  */
12528   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
12529     {
12530       unsigned int scratch_regno;
12531       rtx frame_reg;
12532       int words;
12533
12534       scratch_regno = split_stack_prologue_scratch_regno ();
12535       scratch_reg = gen_rtx_REG (Pmode, scratch_regno);
12536       frame_reg = gen_rtx_REG (Pmode, BP_REG);
12537
12538       /* 64-bit:
12539          fp -> old fp value
12540                return address within this function
12541                return address of caller of this function
12542                stack arguments
12543          So we add three words to get to the stack arguments.
12544
12545          32-bit:
12546          fp -> old fp value
12547                return address within this function
12548                first argument to __morestack
12549                second argument to __morestack
12550                return address of caller of this function
12551                stack arguments
12552          So we add five words to get to the stack arguments.
12553       */
12554       words = TARGET_64BIT ? 3 : 5;
12555       emit_insn (gen_rtx_SET (VOIDmode, scratch_reg,
12556                               gen_rtx_PLUS (Pmode, frame_reg,
12557                                             GEN_INT (words * UNITS_PER_WORD))));
12558
12559       varargs_label = gen_label_rtx ();
12560       emit_jump_insn (gen_jump (varargs_label));
12561       JUMP_LABEL (get_last_insn ()) = varargs_label;
12562
12563       emit_barrier ();
12564     }
12565
12566   emit_label (label);
12567   LABEL_NUSES (label) = 1;
12568
12569   /* If this function calls va_start, we now have to set the scratch
12570      register for the case where we do not call __morestack.  In this
12571      case we need to set it based on the stack pointer.  */
12572   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
12573     {
12574       emit_insn (gen_rtx_SET (VOIDmode, scratch_reg,
12575                               gen_rtx_PLUS (Pmode, stack_pointer_rtx,
12576                                             GEN_INT (UNITS_PER_WORD))));
12577
12578       emit_label (varargs_label);
12579       LABEL_NUSES (varargs_label) = 1;
12580     }
12581 }
12582
12583 /* We may have to tell the dataflow pass that the split stack prologue
12584    is initializing a scratch register.  */
12585
12586 static void
12587 ix86_live_on_entry (bitmap regs)
12588 {
12589   if (cfun->machine->split_stack_varargs_pointer != NULL_RTX)
12590     {
12591       gcc_assert (flag_split_stack);
12592       bitmap_set_bit (regs, split_stack_prologue_scratch_regno ());
12593     }
12594 }
12595 \f
12596 /* Extract the parts of an RTL expression that is a valid memory address
12597    for an instruction.  Return 0 if the structure of the address is
12598    grossly off.  Return -1 if the address contains ASHIFT, so it is not
12599    strictly valid, but still used for computing length of lea instruction.  */
12600
12601 int
12602 ix86_decompose_address (rtx addr, struct ix86_address *out)
12603 {
12604   rtx base = NULL_RTX, index = NULL_RTX, disp = NULL_RTX;
12605   rtx base_reg, index_reg;
12606   HOST_WIDE_INT scale = 1;
12607   rtx scale_rtx = NULL_RTX;
12608   rtx tmp;
12609   int retval = 1;
12610   enum ix86_address_seg seg = SEG_DEFAULT;
12611
12612   /* Allow zero-extended SImode addresses,
12613      they will be emitted with addr32 prefix.  */
12614   if (TARGET_64BIT && GET_MODE (addr) == DImode)
12615     {
12616       if (GET_CODE (addr) == ZERO_EXTEND
12617           && GET_MODE (XEXP (addr, 0)) == SImode)
12618         {
12619           addr = XEXP (addr, 0);
12620           if (CONST_INT_P (addr))
12621             return 0;
12622         }             
12623       else if (GET_CODE (addr) == AND
12624                && const_32bit_mask (XEXP (addr, 1), DImode))
12625         {
12626           addr = simplify_gen_subreg (SImode, XEXP (addr, 0), DImode, 0);
12627           if (addr == NULL_RTX)
12628             return 0;
12629
12630           if (CONST_INT_P (addr))
12631             return 0;
12632         }
12633     }
12634
12635   /* Allow SImode subregs of DImode addresses,
12636      they will be emitted with addr32 prefix.  */
12637   if (TARGET_64BIT && GET_MODE (addr) == SImode)
12638     {
12639       if (GET_CODE (addr) == SUBREG
12640           && GET_MODE (SUBREG_REG (addr)) == DImode)
12641         {
12642           addr = SUBREG_REG (addr);
12643           if (CONST_INT_P (addr))
12644             return 0;
12645         }
12646     }
12647
12648   if (REG_P (addr))
12649     base = addr;
12650   else if (GET_CODE (addr) == SUBREG)
12651     {
12652       if (REG_P (SUBREG_REG (addr)))
12653         base = addr;
12654       else
12655         return 0;
12656     }
12657   else if (GET_CODE (addr) == PLUS)
12658     {
12659       rtx addends[4], op;
12660       int n = 0, i;
12661
12662       op = addr;
12663       do
12664         {
12665           if (n >= 4)
12666             return 0;
12667           addends[n++] = XEXP (op, 1);
12668           op = XEXP (op, 0);
12669         }
12670       while (GET_CODE (op) == PLUS);
12671       if (n >= 4)
12672         return 0;
12673       addends[n] = op;
12674
12675       for (i = n; i >= 0; --i)
12676         {
12677           op = addends[i];
12678           switch (GET_CODE (op))
12679             {
12680             case MULT:
12681               if (index)
12682                 return 0;
12683               index = XEXP (op, 0);
12684               scale_rtx = XEXP (op, 1);
12685               break;
12686
12687             case ASHIFT:
12688               if (index)
12689                 return 0;
12690               index = XEXP (op, 0);
12691               tmp = XEXP (op, 1);
12692               if (!CONST_INT_P (tmp))
12693                 return 0;
12694               scale = INTVAL (tmp);
12695               if ((unsigned HOST_WIDE_INT) scale > 3)
12696                 return 0;
12697               scale = 1 << scale;
12698               break;
12699
12700             case ZERO_EXTEND:
12701               op = XEXP (op, 0);
12702               if (GET_CODE (op) != UNSPEC)
12703                 return 0;
12704               /* FALLTHRU */
12705
12706             case UNSPEC:
12707               if (XINT (op, 1) == UNSPEC_TP
12708                   && TARGET_TLS_DIRECT_SEG_REFS
12709                   && seg == SEG_DEFAULT)
12710                 seg = DEFAULT_TLS_SEG_REG;
12711               else
12712                 return 0;
12713               break;
12714
12715             case SUBREG:
12716               if (!REG_P (SUBREG_REG (op)))
12717                 return 0;
12718               /* FALLTHRU */
12719
12720             case REG:
12721               if (!base)
12722                 base = op;
12723               else if (!index)
12724                 index = op;
12725               else
12726                 return 0;
12727               break;
12728
12729             case CONST:
12730             case CONST_INT:
12731             case SYMBOL_REF:
12732             case LABEL_REF:
12733               if (disp)
12734                 return 0;
12735               disp = op;
12736               break;
12737
12738             default:
12739               return 0;
12740             }
12741         }
12742     }
12743   else if (GET_CODE (addr) == MULT)
12744     {
12745       index = XEXP (addr, 0);           /* index*scale */
12746       scale_rtx = XEXP (addr, 1);
12747     }
12748   else if (GET_CODE (addr) == ASHIFT)
12749     {
12750       /* We're called for lea too, which implements ashift on occasion.  */
12751       index = XEXP (addr, 0);
12752       tmp = XEXP (addr, 1);
12753       if (!CONST_INT_P (tmp))
12754         return 0;
12755       scale = INTVAL (tmp);
12756       if ((unsigned HOST_WIDE_INT) scale > 3)
12757         return 0;
12758       scale = 1 << scale;
12759       retval = -1;
12760     }
12761   else
12762     disp = addr;                        /* displacement */
12763
12764   if (index)
12765     {
12766       if (REG_P (index))
12767         ;
12768       else if (GET_CODE (index) == SUBREG
12769                && REG_P (SUBREG_REG (index)))
12770         ;
12771       else
12772         return 0;
12773     }
12774
12775   /* Extract the integral value of scale.  */
12776   if (scale_rtx)
12777     {
12778       if (!CONST_INT_P (scale_rtx))
12779         return 0;
12780       scale = INTVAL (scale_rtx);
12781     }
12782
12783   base_reg = base && GET_CODE (base) == SUBREG ? SUBREG_REG (base) : base;
12784   index_reg = index && GET_CODE (index) == SUBREG ? SUBREG_REG (index) : index;
12785
12786   /* Avoid useless 0 displacement.  */
12787   if (disp == const0_rtx && (base || index))
12788     disp = NULL_RTX;
12789
12790   /* Allow arg pointer and stack pointer as index if there is not scaling.  */
12791   if (base_reg && index_reg && scale == 1
12792       && (index_reg == arg_pointer_rtx
12793           || index_reg == frame_pointer_rtx
12794           || (REG_P (index_reg) && REGNO (index_reg) == STACK_POINTER_REGNUM)))
12795     {
12796       std::swap (base, index);
12797       std::swap (base_reg, index_reg);
12798     }
12799
12800   /* Special case: %ebp cannot be encoded as a base without a displacement.
12801      Similarly %r13.  */
12802   if (!disp
12803       && base_reg
12804       && (base_reg == hard_frame_pointer_rtx
12805           || base_reg == frame_pointer_rtx
12806           || base_reg == arg_pointer_rtx
12807           || (REG_P (base_reg)
12808               && (REGNO (base_reg) == HARD_FRAME_POINTER_REGNUM
12809                   || REGNO (base_reg) == R13_REG))))
12810     disp = const0_rtx;
12811
12812   /* Special case: on K6, [%esi] makes the instruction vector decoded.
12813      Avoid this by transforming to [%esi+0].
12814      Reload calls address legitimization without cfun defined, so we need
12815      to test cfun for being non-NULL. */
12816   if (TARGET_K6 && cfun && optimize_function_for_speed_p (cfun)
12817       && base_reg && !index_reg && !disp
12818       && REG_P (base_reg) && REGNO (base_reg) == SI_REG)
12819     disp = const0_rtx;
12820
12821   /* Special case: encode reg+reg instead of reg*2.  */
12822   if (!base && index && scale == 2)
12823     base = index, base_reg = index_reg, scale = 1;
12824
12825   /* Special case: scaling cannot be encoded without base or displacement.  */
12826   if (!base && !disp && index && scale != 1)
12827     disp = const0_rtx;
12828
12829   out->base = base;
12830   out->index = index;
12831   out->disp = disp;
12832   out->scale = scale;
12833   out->seg = seg;
12834
12835   return retval;
12836 }
12837 \f
12838 /* Return cost of the memory address x.
12839    For i386, it is better to use a complex address than let gcc copy
12840    the address into a reg and make a new pseudo.  But not if the address
12841    requires to two regs - that would mean more pseudos with longer
12842    lifetimes.  */
12843 static int
12844 ix86_address_cost (rtx x, machine_mode, addr_space_t, bool)
12845 {
12846   struct ix86_address parts;
12847   int cost = 1;
12848   int ok = ix86_decompose_address (x, &parts);
12849
12850   gcc_assert (ok);
12851
12852   if (parts.base && GET_CODE (parts.base) == SUBREG)
12853     parts.base = SUBREG_REG (parts.base);
12854   if (parts.index && GET_CODE (parts.index) == SUBREG)
12855     parts.index = SUBREG_REG (parts.index);
12856
12857   /* Attempt to minimize number of registers in the address.  */
12858   if ((parts.base
12859        && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER))
12860       || (parts.index
12861           && (!REG_P (parts.index)
12862               || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)))
12863     cost++;
12864
12865   /* When address base or index is "pic_offset_table_rtx" we don't increase
12866      address cost.  When a memopt with "pic_offset_table_rtx" is not invariant
12867      itself it most likely means that base or index is not invariant.
12868      Therefore only "pic_offset_table_rtx" could be hoisted out, which is not
12869      profitable for x86.  */
12870   if (parts.base
12871       && (current_pass->type == GIMPLE_PASS
12872           || (!pic_offset_table_rtx
12873               || REGNO (pic_offset_table_rtx) != REGNO(parts.base)))
12874       && (!REG_P (parts.base) || REGNO (parts.base) >= FIRST_PSEUDO_REGISTER)
12875       && parts.index
12876       && (current_pass->type == GIMPLE_PASS
12877           || (!pic_offset_table_rtx
12878               || REGNO (pic_offset_table_rtx) != REGNO(parts.index)))
12879       && (!REG_P (parts.index) || REGNO (parts.index) >= FIRST_PSEUDO_REGISTER)
12880       && parts.base != parts.index)
12881     cost++;
12882
12883   /* AMD-K6 don't like addresses with ModR/M set to 00_xxx_100b,
12884      since it's predecode logic can't detect the length of instructions
12885      and it degenerates to vector decoded.  Increase cost of such
12886      addresses here.  The penalty is minimally 2 cycles.  It may be worthwhile
12887      to split such addresses or even refuse such addresses at all.
12888
12889      Following addressing modes are affected:
12890       [base+scale*index]
12891       [scale*index+disp]
12892       [base+index]
12893
12894      The first and last case  may be avoidable by explicitly coding the zero in
12895      memory address, but I don't have AMD-K6 machine handy to check this
12896      theory.  */
12897
12898   if (TARGET_K6
12899       && ((!parts.disp && parts.base && parts.index && parts.scale != 1)
12900           || (parts.disp && !parts.base && parts.index && parts.scale != 1)
12901           || (!parts.disp && parts.base && parts.index && parts.scale == 1)))
12902     cost += 10;
12903
12904   return cost;
12905 }
12906 \f
12907 /* Allow {LABEL | SYMBOL}_REF - SYMBOL_REF-FOR-PICBASE for Mach-O as
12908    this is used for to form addresses to local data when -fPIC is in
12909    use.  */
12910
12911 static bool
12912 darwin_local_data_pic (rtx disp)
12913 {
12914   return (GET_CODE (disp) == UNSPEC
12915           && XINT (disp, 1) == UNSPEC_MACHOPIC_OFFSET);
12916 }
12917
12918 /* Determine if a given RTX is a valid constant.  We already know this
12919    satisfies CONSTANT_P.  */
12920
12921 static bool
12922 ix86_legitimate_constant_p (machine_mode, rtx x)
12923 {
12924   /* Pointer bounds constants are not valid.  */
12925   if (POINTER_BOUNDS_MODE_P (GET_MODE (x)))
12926     return false;
12927
12928   switch (GET_CODE (x))
12929     {
12930     case CONST:
12931       x = XEXP (x, 0);
12932
12933       if (GET_CODE (x) == PLUS)
12934         {
12935           if (!CONST_INT_P (XEXP (x, 1)))
12936             return false;
12937           x = XEXP (x, 0);
12938         }
12939
12940       if (TARGET_MACHO && darwin_local_data_pic (x))
12941         return true;
12942
12943       /* Only some unspecs are valid as "constants".  */
12944       if (GET_CODE (x) == UNSPEC)
12945         switch (XINT (x, 1))
12946           {
12947           case UNSPEC_GOT:
12948           case UNSPEC_GOTOFF:
12949           case UNSPEC_PLTOFF:
12950             return TARGET_64BIT;
12951           case UNSPEC_TPOFF:
12952           case UNSPEC_NTPOFF:
12953             x = XVECEXP (x, 0, 0);
12954             return (GET_CODE (x) == SYMBOL_REF
12955                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
12956           case UNSPEC_DTPOFF:
12957             x = XVECEXP (x, 0, 0);
12958             return (GET_CODE (x) == SYMBOL_REF
12959                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_DYNAMIC);
12960           default:
12961             return false;
12962           }
12963
12964       /* We must have drilled down to a symbol.  */
12965       if (GET_CODE (x) == LABEL_REF)
12966         return true;
12967       if (GET_CODE (x) != SYMBOL_REF)
12968         return false;
12969       /* FALLTHRU */
12970
12971     case SYMBOL_REF:
12972       /* TLS symbols are never valid.  */
12973       if (SYMBOL_REF_TLS_MODEL (x))
12974         return false;
12975
12976       /* DLLIMPORT symbols are never valid.  */
12977       if (TARGET_DLLIMPORT_DECL_ATTRIBUTES
12978           && SYMBOL_REF_DLLIMPORT_P (x))
12979         return false;
12980
12981 #if TARGET_MACHO
12982       /* mdynamic-no-pic */
12983       if (MACHO_DYNAMIC_NO_PIC_P)
12984         return machopic_symbol_defined_p (x);
12985 #endif
12986       break;
12987
12988     case CONST_DOUBLE:
12989       if (GET_MODE (x) == TImode
12990           && x != CONST0_RTX (TImode)
12991           && !TARGET_64BIT)
12992         return false;
12993       break;
12994
12995     case CONST_VECTOR:
12996       if (!standard_sse_constant_p (x))
12997         return false;
12998
12999     default:
13000       break;
13001     }
13002
13003   /* Otherwise we handle everything else in the move patterns.  */
13004   return true;
13005 }
13006
13007 /* Determine if it's legal to put X into the constant pool.  This
13008    is not possible for the address of thread-local symbols, which
13009    is checked above.  */
13010
13011 static bool
13012 ix86_cannot_force_const_mem (machine_mode mode, rtx x)
13013 {
13014   /* We can always put integral constants and vectors in memory.  */
13015   switch (GET_CODE (x))
13016     {
13017     case CONST_INT:
13018     case CONST_DOUBLE:
13019     case CONST_VECTOR:
13020       return false;
13021
13022     default:
13023       break;
13024     }
13025   return !ix86_legitimate_constant_p (mode, x);
13026 }
13027
13028 /*  Nonzero if the symbol is marked as dllimport, or as stub-variable,
13029     otherwise zero.  */
13030
13031 static bool
13032 is_imported_p (rtx x)
13033 {
13034   if (!TARGET_DLLIMPORT_DECL_ATTRIBUTES
13035       || GET_CODE (x) != SYMBOL_REF)
13036     return false;
13037
13038   return SYMBOL_REF_DLLIMPORT_P (x) || SYMBOL_REF_STUBVAR_P (x);
13039 }
13040
13041
13042 /* Nonzero if the constant value X is a legitimate general operand
13043    when generating PIC code.  It is given that flag_pic is on and
13044    that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
13045
13046 bool
13047 legitimate_pic_operand_p (rtx x)
13048 {
13049   rtx inner;
13050
13051   switch (GET_CODE (x))
13052     {
13053     case CONST:
13054       inner = XEXP (x, 0);
13055       if (GET_CODE (inner) == PLUS
13056           && CONST_INT_P (XEXP (inner, 1)))
13057         inner = XEXP (inner, 0);
13058
13059       /* Only some unspecs are valid as "constants".  */
13060       if (GET_CODE (inner) == UNSPEC)
13061         switch (XINT (inner, 1))
13062           {
13063           case UNSPEC_GOT:
13064           case UNSPEC_GOTOFF:
13065           case UNSPEC_PLTOFF:
13066             return TARGET_64BIT;
13067           case UNSPEC_TPOFF:
13068             x = XVECEXP (inner, 0, 0);
13069             return (GET_CODE (x) == SYMBOL_REF
13070                     && SYMBOL_REF_TLS_MODEL (x) == TLS_MODEL_LOCAL_EXEC);
13071           case UNSPEC_MACHOPIC_OFFSET:
13072             return legitimate_pic_address_disp_p (x);
13073           default:
13074             return false;
13075           }
13076       /* FALLTHRU */
13077
13078     case SYMBOL_REF:
13079     case LABEL_REF:
13080       return legitimate_pic_address_disp_p (x);
13081
13082     default:
13083       return true;
13084     }
13085 }
13086
13087 /* Determine if a given CONST RTX is a valid memory displacement
13088    in PIC mode.  */
13089
13090 bool
13091 legitimate_pic_address_disp_p (rtx disp)
13092 {
13093   bool saw_plus;
13094
13095   /* In 64bit mode we can allow direct addresses of symbols and labels
13096      when they are not dynamic symbols.  */
13097   if (TARGET_64BIT)
13098     {
13099       rtx op0 = disp, op1;
13100
13101       switch (GET_CODE (disp))
13102         {
13103         case LABEL_REF:
13104           return true;
13105
13106         case CONST:
13107           if (GET_CODE (XEXP (disp, 0)) != PLUS)
13108             break;
13109           op0 = XEXP (XEXP (disp, 0), 0);
13110           op1 = XEXP (XEXP (disp, 0), 1);
13111           if (!CONST_INT_P (op1)
13112               || INTVAL (op1) >= 16*1024*1024
13113               || INTVAL (op1) < -16*1024*1024)
13114             break;
13115           if (GET_CODE (op0) == LABEL_REF)
13116             return true;
13117           if (GET_CODE (op0) == CONST
13118               && GET_CODE (XEXP (op0, 0)) == UNSPEC
13119               && XINT (XEXP (op0, 0), 1) == UNSPEC_PCREL)
13120             return true;
13121           if (GET_CODE (op0) == UNSPEC
13122               && XINT (op0, 1) == UNSPEC_PCREL)
13123             return true;
13124           if (GET_CODE (op0) != SYMBOL_REF)
13125             break;
13126           /* FALLTHRU */
13127
13128         case SYMBOL_REF:
13129           /* TLS references should always be enclosed in UNSPEC.
13130              The dllimported symbol needs always to be resolved.  */
13131           if (SYMBOL_REF_TLS_MODEL (op0)
13132               || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op0)))
13133             return false;
13134
13135           if (TARGET_PECOFF)
13136             {
13137               if (is_imported_p (op0))
13138                 return true;
13139
13140               if (SYMBOL_REF_FAR_ADDR_P (op0)
13141                   || !SYMBOL_REF_LOCAL_P (op0))
13142                 break;
13143
13144               /* Function-symbols need to be resolved only for
13145                  large-model.
13146                  For the small-model we don't need to resolve anything
13147                  here.  */
13148               if ((ix86_cmodel != CM_LARGE_PIC
13149                    && SYMBOL_REF_FUNCTION_P (op0))
13150                   || ix86_cmodel == CM_SMALL_PIC)
13151                 return true;
13152               /* Non-external symbols don't need to be resolved for
13153                  large, and medium-model.  */
13154               if ((ix86_cmodel == CM_LARGE_PIC
13155                    || ix86_cmodel == CM_MEDIUM_PIC)
13156                   && !SYMBOL_REF_EXTERNAL_P (op0))
13157                 return true;
13158             }
13159           else if (!SYMBOL_REF_FAR_ADDR_P (op0)
13160                    && (SYMBOL_REF_LOCAL_P (op0)
13161                        || (HAVE_LD_PIE_COPYRELOC
13162                            && flag_pie
13163                            && !SYMBOL_REF_WEAK (op0)
13164                            && !SYMBOL_REF_FUNCTION_P (op0)))
13165                    && ix86_cmodel != CM_LARGE_PIC)
13166             return true;
13167           break;
13168
13169         default:
13170           break;
13171         }
13172     }
13173   if (GET_CODE (disp) != CONST)
13174     return false;
13175   disp = XEXP (disp, 0);
13176
13177   if (TARGET_64BIT)
13178     {
13179       /* We are unsafe to allow PLUS expressions.  This limit allowed distance
13180          of GOT tables.  We should not need these anyway.  */
13181       if (GET_CODE (disp) != UNSPEC
13182           || (XINT (disp, 1) != UNSPEC_GOTPCREL
13183               && XINT (disp, 1) != UNSPEC_GOTOFF
13184               && XINT (disp, 1) != UNSPEC_PCREL
13185               && XINT (disp, 1) != UNSPEC_PLTOFF))
13186         return false;
13187
13188       if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF
13189           && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF)
13190         return false;
13191       return true;
13192     }
13193
13194   saw_plus = false;
13195   if (GET_CODE (disp) == PLUS)
13196     {
13197       if (!CONST_INT_P (XEXP (disp, 1)))
13198         return false;
13199       disp = XEXP (disp, 0);
13200       saw_plus = true;
13201     }
13202
13203   if (TARGET_MACHO && darwin_local_data_pic (disp))
13204     return true;
13205
13206   if (GET_CODE (disp) != UNSPEC)
13207     return false;
13208
13209   switch (XINT (disp, 1))
13210     {
13211     case UNSPEC_GOT:
13212       if (saw_plus)
13213         return false;
13214       /* We need to check for both symbols and labels because VxWorks loads
13215          text labels with @GOT rather than @GOTOFF.  See gotoff_operand for
13216          details.  */
13217       return (GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
13218               || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF);
13219     case UNSPEC_GOTOFF:
13220       /* Refuse GOTOFF in 64bit mode since it is always 64bit when used.
13221          While ABI specify also 32bit relocation but we don't produce it in
13222          small PIC model at all.  */
13223       if ((GET_CODE (XVECEXP (disp, 0, 0)) == SYMBOL_REF
13224            || GET_CODE (XVECEXP (disp, 0, 0)) == LABEL_REF)
13225           && !TARGET_64BIT)
13226         return !TARGET_PECOFF && gotoff_operand (XVECEXP (disp, 0, 0), Pmode);
13227       return false;
13228     case UNSPEC_GOTTPOFF:
13229     case UNSPEC_GOTNTPOFF:
13230     case UNSPEC_INDNTPOFF:
13231       if (saw_plus)
13232         return false;
13233       disp = XVECEXP (disp, 0, 0);
13234       return (GET_CODE (disp) == SYMBOL_REF
13235               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_INITIAL_EXEC);
13236     case UNSPEC_NTPOFF:
13237       disp = XVECEXP (disp, 0, 0);
13238       return (GET_CODE (disp) == SYMBOL_REF
13239               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_EXEC);
13240     case UNSPEC_DTPOFF:
13241       disp = XVECEXP (disp, 0, 0);
13242       return (GET_CODE (disp) == SYMBOL_REF
13243               && SYMBOL_REF_TLS_MODEL (disp) == TLS_MODEL_LOCAL_DYNAMIC);
13244     }
13245
13246   return false;
13247 }
13248
13249 /* Our implementation of LEGITIMIZE_RELOAD_ADDRESS.  Returns a value to
13250    replace the input X, or the original X if no replacement is called for.
13251    The output parameter *WIN is 1 if the calling macro should goto WIN,
13252    0 if it should not.  */
13253
13254 bool
13255 ix86_legitimize_reload_address (rtx x, machine_mode, int opnum, int type,
13256                                 int)
13257 {
13258   /* Reload can generate:
13259
13260      (plus:DI (plus:DI (unspec:DI [(const_int 0 [0])] UNSPEC_TP)
13261                        (reg:DI 97))
13262               (reg:DI 2 cx))
13263
13264      This RTX is rejected from ix86_legitimate_address_p due to
13265      non-strictness of base register 97.  Following this rejection, 
13266      reload pushes all three components into separate registers,
13267      creating invalid memory address RTX.
13268
13269      Following code reloads only the invalid part of the
13270      memory address RTX.  */
13271
13272   if (GET_CODE (x) == PLUS
13273       && REG_P (XEXP (x, 1))
13274       && GET_CODE (XEXP (x, 0)) == PLUS
13275       && REG_P (XEXP (XEXP (x, 0), 1)))
13276     {
13277       rtx base, index;
13278       bool something_reloaded = false;
13279
13280       base = XEXP (XEXP (x, 0), 1);      
13281       if (!REG_OK_FOR_BASE_STRICT_P (base))
13282         {
13283           push_reload (base, NULL_RTX, &XEXP (XEXP (x, 0), 1), NULL,
13284                        BASE_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
13285                        opnum, (enum reload_type) type);
13286           something_reloaded = true;
13287         }
13288
13289       index = XEXP (x, 1);
13290       if (!REG_OK_FOR_INDEX_STRICT_P (index))
13291         {
13292           push_reload (index, NULL_RTX, &XEXP (x, 1), NULL,
13293                        INDEX_REG_CLASS, GET_MODE (x), VOIDmode, 0, 0,
13294                        opnum, (enum reload_type) type);
13295           something_reloaded = true;
13296         }
13297
13298       gcc_assert (something_reloaded);
13299       return true;
13300     }
13301
13302   return false;
13303 }
13304
13305 /* Determine if op is suitable RTX for an address register.
13306    Return naked register if a register or a register subreg is
13307    found, otherwise return NULL_RTX.  */
13308
13309 static rtx
13310 ix86_validate_address_register (rtx op)
13311 {
13312   machine_mode mode = GET_MODE (op);
13313
13314   /* Only SImode or DImode registers can form the address.  */
13315   if (mode != SImode && mode != DImode)
13316     return NULL_RTX;
13317
13318   if (REG_P (op))
13319     return op;
13320   else if (GET_CODE (op) == SUBREG)
13321     {
13322       rtx reg = SUBREG_REG (op);
13323
13324       if (!REG_P (reg))
13325         return NULL_RTX;
13326
13327       mode = GET_MODE (reg);
13328
13329       /* Don't allow SUBREGs that span more than a word.  It can
13330          lead to spill failures when the register is one word out
13331          of a two word structure.  */
13332       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
13333         return NULL_RTX;
13334
13335       /* Allow only SUBREGs of non-eliminable hard registers.  */
13336       if (register_no_elim_operand (reg, mode))
13337         return reg;
13338     }
13339
13340   /* Op is not a register.  */
13341   return NULL_RTX;
13342 }
13343
13344 /* Recognizes RTL expressions that are valid memory addresses for an
13345    instruction.  The MODE argument is the machine mode for the MEM
13346    expression that wants to use this address.
13347
13348    It only recognizes address in canonical form.  LEGITIMIZE_ADDRESS should
13349    convert common non-canonical forms to canonical form so that they will
13350    be recognized.  */
13351
13352 static bool
13353 ix86_legitimate_address_p (machine_mode, rtx addr, bool strict)
13354 {
13355   struct ix86_address parts;
13356   rtx base, index, disp;
13357   HOST_WIDE_INT scale;
13358   enum ix86_address_seg seg;
13359
13360   if (ix86_decompose_address (addr, &parts) <= 0)
13361     /* Decomposition failed.  */
13362     return false;
13363
13364   base = parts.base;
13365   index = parts.index;
13366   disp = parts.disp;
13367   scale = parts.scale;
13368   seg = parts.seg;
13369
13370   /* Validate base register.  */
13371   if (base)
13372     {
13373       rtx reg = ix86_validate_address_register (base);
13374
13375       if (reg == NULL_RTX)
13376         return false;
13377
13378       if ((strict && ! REG_OK_FOR_BASE_STRICT_P (reg))
13379           || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (reg)))
13380         /* Base is not valid.  */
13381         return false;
13382     }
13383
13384   /* Validate index register.  */
13385   if (index)
13386     {
13387       rtx reg = ix86_validate_address_register (index);
13388
13389       if (reg == NULL_RTX)
13390         return false;
13391
13392       if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (reg))
13393           || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (reg)))
13394         /* Index is not valid.  */
13395         return false;
13396     }
13397
13398   /* Index and base should have the same mode.  */
13399   if (base && index
13400       && GET_MODE (base) != GET_MODE (index))
13401     return false;
13402
13403   /* Address override works only on the (%reg) part of %fs:(%reg).  */
13404   if (seg != SEG_DEFAULT
13405       && ((base && GET_MODE (base) != word_mode)
13406           || (index && GET_MODE (index) != word_mode)))
13407     return false;
13408
13409   /* Validate scale factor.  */
13410   if (scale != 1)
13411     {
13412       if (!index)
13413         /* Scale without index.  */
13414         return false;
13415
13416       if (scale != 2 && scale != 4 && scale != 8)
13417         /* Scale is not a valid multiplier.  */
13418         return false;
13419     }
13420
13421   /* Validate displacement.  */
13422   if (disp)
13423     {
13424       if (GET_CODE (disp) == CONST
13425           && GET_CODE (XEXP (disp, 0)) == UNSPEC
13426           && XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
13427         switch (XINT (XEXP (disp, 0), 1))
13428           {
13429           /* Refuse GOTOFF and GOT in 64bit mode since it is always 64bit when
13430              used.  While ABI specify also 32bit relocations, we don't produce
13431              them at all and use IP relative instead.  */
13432           case UNSPEC_GOT:
13433           case UNSPEC_GOTOFF:
13434             gcc_assert (flag_pic);
13435             if (!TARGET_64BIT)
13436               goto is_legitimate_pic;
13437
13438             /* 64bit address unspec.  */
13439             return false;
13440
13441           case UNSPEC_GOTPCREL:
13442           case UNSPEC_PCREL:
13443             gcc_assert (flag_pic);
13444             goto is_legitimate_pic;
13445
13446           case UNSPEC_GOTTPOFF:
13447           case UNSPEC_GOTNTPOFF:
13448           case UNSPEC_INDNTPOFF:
13449           case UNSPEC_NTPOFF:
13450           case UNSPEC_DTPOFF:
13451             break;
13452
13453           case UNSPEC_STACK_CHECK:
13454             gcc_assert (flag_split_stack);
13455             break;
13456
13457           default:
13458             /* Invalid address unspec.  */
13459             return false;
13460           }
13461
13462       else if (SYMBOLIC_CONST (disp)
13463                && (flag_pic
13464                    || (TARGET_MACHO
13465 #if TARGET_MACHO
13466                        && MACHOPIC_INDIRECT
13467                        && !machopic_operand_p (disp)
13468 #endif
13469                )))
13470         {
13471
13472         is_legitimate_pic:
13473           if (TARGET_64BIT && (index || base))
13474             {
13475               /* foo@dtpoff(%rX) is ok.  */
13476               if (GET_CODE (disp) != CONST
13477                   || GET_CODE (XEXP (disp, 0)) != PLUS
13478                   || GET_CODE (XEXP (XEXP (disp, 0), 0)) != UNSPEC
13479                   || !CONST_INT_P (XEXP (XEXP (disp, 0), 1))
13480                   || (XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_DTPOFF
13481                       && XINT (XEXP (XEXP (disp, 0), 0), 1) != UNSPEC_NTPOFF))
13482                 /* Non-constant pic memory reference.  */
13483                 return false;
13484             }
13485           else if ((!TARGET_MACHO || flag_pic)
13486                     && ! legitimate_pic_address_disp_p (disp))
13487             /* Displacement is an invalid pic construct.  */
13488             return false;
13489 #if TARGET_MACHO
13490           else if (MACHO_DYNAMIC_NO_PIC_P
13491                    && !ix86_legitimate_constant_p (Pmode, disp))
13492             /* displacment must be referenced via non_lazy_pointer */
13493             return false;
13494 #endif
13495
13496           /* This code used to verify that a symbolic pic displacement
13497              includes the pic_offset_table_rtx register.
13498
13499              While this is good idea, unfortunately these constructs may
13500              be created by "adds using lea" optimization for incorrect
13501              code like:
13502
13503              int a;
13504              int foo(int i)
13505                {
13506                  return *(&a+i);
13507                }
13508
13509              This code is nonsensical, but results in addressing
13510              GOT table with pic_offset_table_rtx base.  We can't
13511              just refuse it easily, since it gets matched by
13512              "addsi3" pattern, that later gets split to lea in the
13513              case output register differs from input.  While this
13514              can be handled by separate addsi pattern for this case
13515              that never results in lea, this seems to be easier and
13516              correct fix for crash to disable this test.  */
13517         }
13518       else if (GET_CODE (disp) != LABEL_REF
13519                && !CONST_INT_P (disp)
13520                && (GET_CODE (disp) != CONST
13521                    || !ix86_legitimate_constant_p (Pmode, disp))
13522                && (GET_CODE (disp) != SYMBOL_REF
13523                    || !ix86_legitimate_constant_p (Pmode, disp)))
13524         /* Displacement is not constant.  */
13525         return false;
13526       else if (TARGET_64BIT
13527                && !x86_64_immediate_operand (disp, VOIDmode))
13528         /* Displacement is out of range.  */
13529         return false;
13530       /* In x32 mode, constant addresses are sign extended to 64bit, so
13531          we have to prevent addresses from 0x80000000 to 0xffffffff.  */
13532       else if (TARGET_X32 && !(index || base)
13533                && CONST_INT_P (disp)
13534                && val_signbit_known_set_p (SImode, INTVAL (disp)))
13535         return false;
13536     }
13537
13538   /* Everything looks valid.  */
13539   return true;
13540 }
13541
13542 /* Determine if a given RTX is a valid constant address.  */
13543
13544 bool
13545 constant_address_p (rtx x)
13546 {
13547   return CONSTANT_P (x) && ix86_legitimate_address_p (Pmode, x, 1);
13548 }
13549 \f
13550 /* Return a unique alias set for the GOT.  */
13551
13552 static alias_set_type
13553 ix86_GOT_alias_set (void)
13554 {
13555   static alias_set_type set = -1;
13556   if (set == -1)
13557     set = new_alias_set ();
13558   return set;
13559 }
13560
13561 /* Set regs_ever_live for PIC base address register
13562    to true if required.  */
13563 static void
13564 set_pic_reg_ever_live ()
13565 {
13566   if (reload_in_progress)
13567     df_set_regs_ever_live (REGNO (pic_offset_table_rtx), true);
13568 }
13569
13570 /* Return a legitimate reference for ORIG (an address) using the
13571    register REG.  If REG is 0, a new pseudo is generated.
13572
13573    There are two types of references that must be handled:
13574
13575    1. Global data references must load the address from the GOT, via
13576       the PIC reg.  An insn is emitted to do this load, and the reg is
13577       returned.
13578
13579    2. Static data references, constant pool addresses, and code labels
13580       compute the address as an offset from the GOT, whose base is in
13581       the PIC reg.  Static data objects have SYMBOL_FLAG_LOCAL set to
13582       differentiate them from global data objects.  The returned
13583       address is the PIC reg + an unspec constant.
13584
13585    TARGET_LEGITIMATE_ADDRESS_P rejects symbolic references unless the PIC
13586    reg also appears in the address.  */
13587
13588 static rtx
13589 legitimize_pic_address (rtx orig, rtx reg)
13590 {
13591   rtx addr = orig;
13592   rtx new_rtx = orig;
13593
13594 #if TARGET_MACHO
13595   if (TARGET_MACHO && !TARGET_64BIT)
13596     {
13597       if (reg == 0)
13598         reg = gen_reg_rtx (Pmode);
13599       /* Use the generic Mach-O PIC machinery.  */
13600       return machopic_legitimize_pic_address (orig, GET_MODE (orig), reg);
13601     }
13602 #endif
13603
13604   if (TARGET_64BIT && TARGET_DLLIMPORT_DECL_ATTRIBUTES)
13605     {
13606       rtx tmp = legitimize_pe_coff_symbol (addr, true);
13607       if (tmp)
13608         return tmp;
13609     }
13610
13611   if (TARGET_64BIT && legitimate_pic_address_disp_p (addr))
13612     new_rtx = addr;
13613   else if (TARGET_64BIT && !TARGET_PECOFF
13614            && ix86_cmodel != CM_SMALL_PIC && gotoff_operand (addr, Pmode))
13615     {
13616       rtx tmpreg;
13617       /* This symbol may be referenced via a displacement from the PIC
13618          base address (@GOTOFF).  */
13619
13620       set_pic_reg_ever_live ();
13621       if (GET_CODE (addr) == CONST)
13622         addr = XEXP (addr, 0);
13623       if (GET_CODE (addr) == PLUS)
13624           {
13625             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
13626                                       UNSPEC_GOTOFF);
13627             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
13628           }
13629         else
13630           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
13631       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13632       if (!reg)
13633         tmpreg = gen_reg_rtx (Pmode);
13634       else
13635         tmpreg = reg;
13636       emit_move_insn (tmpreg, new_rtx);
13637
13638       if (reg != 0)
13639         {
13640           new_rtx = expand_simple_binop (Pmode, PLUS, reg, pic_offset_table_rtx,
13641                                          tmpreg, 1, OPTAB_DIRECT);
13642           new_rtx = reg;
13643         }
13644       else
13645         new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, tmpreg);
13646     }
13647   else if (!TARGET_64BIT && !TARGET_PECOFF && gotoff_operand (addr, Pmode))
13648     {
13649       /* This symbol may be referenced via a displacement from the PIC
13650          base address (@GOTOFF).  */
13651
13652       set_pic_reg_ever_live ();
13653       if (GET_CODE (addr) == CONST)
13654         addr = XEXP (addr, 0);
13655       if (GET_CODE (addr) == PLUS)
13656           {
13657             new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, XEXP (addr, 0)),
13658                                       UNSPEC_GOTOFF);
13659             new_rtx = gen_rtx_PLUS (Pmode, new_rtx, XEXP (addr, 1));
13660           }
13661         else
13662           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTOFF);
13663       new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13664       new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
13665
13666       if (reg != 0)
13667         {
13668           emit_move_insn (reg, new_rtx);
13669           new_rtx = reg;
13670         }
13671     }
13672   else if ((GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_TLS_MODEL (addr) == 0)
13673            /* We can't use @GOTOFF for text labels on VxWorks;
13674               see gotoff_operand.  */
13675            || (TARGET_VXWORKS_RTP && GET_CODE (addr) == LABEL_REF))
13676     {
13677       rtx tmp = legitimize_pe_coff_symbol (addr, true);
13678       if (tmp)
13679         return tmp;
13680
13681       /* For x64 PE-COFF there is no GOT table.  So we use address
13682          directly.  */
13683       if (TARGET_64BIT && TARGET_PECOFF)
13684         {
13685           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_PCREL);
13686           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13687
13688           if (reg == 0)
13689             reg = gen_reg_rtx (Pmode);
13690           emit_move_insn (reg, new_rtx);
13691           new_rtx = reg;
13692         }
13693       else if (TARGET_64BIT && ix86_cmodel != CM_LARGE_PIC)
13694         {
13695           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOTPCREL);
13696           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13697           new_rtx = gen_const_mem (Pmode, new_rtx);
13698           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
13699
13700           if (reg == 0)
13701             reg = gen_reg_rtx (Pmode);
13702           /* Use directly gen_movsi, otherwise the address is loaded
13703              into register for CSE.  We don't want to CSE this addresses,
13704              instead we CSE addresses from the GOT table, so skip this.  */
13705           emit_insn (gen_movsi (reg, new_rtx));
13706           new_rtx = reg;
13707         }
13708       else
13709         {
13710           /* This symbol must be referenced via a load from the
13711              Global Offset Table (@GOT).  */
13712
13713           set_pic_reg_ever_live ();
13714           new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, addr), UNSPEC_GOT);
13715           new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13716           if (TARGET_64BIT)
13717             new_rtx = force_reg (Pmode, new_rtx);
13718           new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
13719           new_rtx = gen_const_mem (Pmode, new_rtx);
13720           set_mem_alias_set (new_rtx, ix86_GOT_alias_set ());
13721
13722           if (reg == 0)
13723             reg = gen_reg_rtx (Pmode);
13724           emit_move_insn (reg, new_rtx);
13725           new_rtx = reg;
13726         }
13727     }
13728   else
13729     {
13730       if (CONST_INT_P (addr)
13731           && !x86_64_immediate_operand (addr, VOIDmode))
13732         {
13733           if (reg)
13734             {
13735               emit_move_insn (reg, addr);
13736               new_rtx = reg;
13737             }
13738           else
13739             new_rtx = force_reg (Pmode, addr);
13740         }
13741       else if (GET_CODE (addr) == CONST)
13742         {
13743           addr = XEXP (addr, 0);
13744
13745           /* We must match stuff we generate before.  Assume the only
13746              unspecs that can get here are ours.  Not that we could do
13747              anything with them anyway....  */
13748           if (GET_CODE (addr) == UNSPEC
13749               || (GET_CODE (addr) == PLUS
13750                   && GET_CODE (XEXP (addr, 0)) == UNSPEC))
13751             return orig;
13752           gcc_assert (GET_CODE (addr) == PLUS);
13753         }
13754       if (GET_CODE (addr) == PLUS)
13755         {
13756           rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1);
13757
13758           /* Check first to see if this is a constant offset from a @GOTOFF
13759              symbol reference.  */
13760           if (!TARGET_PECOFF && gotoff_operand (op0, Pmode)
13761               && CONST_INT_P (op1))
13762             {
13763               if (!TARGET_64BIT)
13764                 {
13765                   set_pic_reg_ever_live ();
13766                   new_rtx = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op0),
13767                                             UNSPEC_GOTOFF);
13768                   new_rtx = gen_rtx_PLUS (Pmode, new_rtx, op1);
13769                   new_rtx = gen_rtx_CONST (Pmode, new_rtx);
13770                   new_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new_rtx);
13771
13772                   if (reg != 0)
13773                     {
13774                       emit_move_insn (reg, new_rtx);
13775                       new_rtx = reg;
13776                     }
13777                 }
13778               else
13779                 {
13780                   if (INTVAL (op1) < -16*1024*1024
13781                       || INTVAL (op1) >= 16*1024*1024)
13782                     {
13783                       if (!x86_64_immediate_operand (op1, Pmode))
13784                         op1 = force_reg (Pmode, op1);
13785                       new_rtx = gen_rtx_PLUS (Pmode, force_reg (Pmode, op0), op1);
13786                     }
13787                 }
13788             }
13789           else
13790             {
13791               rtx base = legitimize_pic_address (op0, reg);
13792               machine_mode mode = GET_MODE (base);
13793               new_rtx
13794                 = legitimize_pic_address (op1, base == reg ? NULL_RTX : reg);
13795
13796               if (CONST_INT_P (new_rtx))
13797                 {
13798                   if (INTVAL (new_rtx) < -16*1024*1024
13799                       || INTVAL (new_rtx) >= 16*1024*1024)
13800                     {
13801                       if (!x86_64_immediate_operand (new_rtx, mode))
13802                         new_rtx = force_reg (mode, new_rtx);
13803                       new_rtx
13804                         = gen_rtx_PLUS (mode, force_reg (mode, base), new_rtx);
13805                     }
13806                   else
13807                     new_rtx = plus_constant (mode, base, INTVAL (new_rtx));
13808                 }
13809               else
13810                 {
13811                   if (GET_CODE (new_rtx) == PLUS
13812                       && CONSTANT_P (XEXP (new_rtx, 1)))
13813                     {
13814                       base = gen_rtx_PLUS (mode, base, XEXP (new_rtx, 0));
13815                       new_rtx = XEXP (new_rtx, 1);
13816                     }
13817                   new_rtx = gen_rtx_PLUS (mode, base, new_rtx);
13818                 }
13819             }
13820         }
13821     }
13822   return new_rtx;
13823 }
13824 \f
13825 /* Load the thread pointer.  If TO_REG is true, force it into a register.  */
13826
13827 static rtx
13828 get_thread_pointer (machine_mode tp_mode, bool to_reg)
13829 {
13830   rtx tp = gen_rtx_UNSPEC (ptr_mode, gen_rtvec (1, const0_rtx), UNSPEC_TP);
13831
13832   if (GET_MODE (tp) != tp_mode)
13833     {
13834       gcc_assert (GET_MODE (tp) == SImode);
13835       gcc_assert (tp_mode == DImode);
13836
13837       tp = gen_rtx_ZERO_EXTEND (tp_mode, tp);
13838     }
13839
13840   if (to_reg)
13841     tp = copy_to_mode_reg (tp_mode, tp);
13842
13843   return tp;
13844 }
13845
13846 /* Construct the SYMBOL_REF for the tls_get_addr function.  */
13847
13848 static GTY(()) rtx ix86_tls_symbol;
13849
13850 static rtx
13851 ix86_tls_get_addr (void)
13852 {
13853   if (!ix86_tls_symbol)
13854     {
13855       const char *sym
13856         = ((TARGET_ANY_GNU_TLS && !TARGET_64BIT)
13857            ? "___tls_get_addr" : "__tls_get_addr");
13858
13859       ix86_tls_symbol = gen_rtx_SYMBOL_REF (Pmode, sym);
13860     }
13861
13862   if (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF)
13863     {
13864       rtx unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, ix86_tls_symbol),
13865                                    UNSPEC_PLTOFF);
13866       return gen_rtx_PLUS (Pmode, pic_offset_table_rtx,
13867                            gen_rtx_CONST (Pmode, unspec));
13868     }
13869
13870   return ix86_tls_symbol;
13871 }
13872
13873 /* Construct the SYMBOL_REF for the _TLS_MODULE_BASE_ symbol.  */
13874
13875 static GTY(()) rtx ix86_tls_module_base_symbol;
13876
13877 rtx
13878 ix86_tls_module_base (void)
13879 {
13880   if (!ix86_tls_module_base_symbol)
13881     {
13882       ix86_tls_module_base_symbol
13883         = gen_rtx_SYMBOL_REF (Pmode, "_TLS_MODULE_BASE_");
13884
13885       SYMBOL_REF_FLAGS (ix86_tls_module_base_symbol)
13886         |= TLS_MODEL_GLOBAL_DYNAMIC << SYMBOL_FLAG_TLS_SHIFT;
13887     }
13888
13889   return ix86_tls_module_base_symbol;
13890 }
13891
13892 /* A subroutine of ix86_legitimize_address and ix86_expand_move.  FOR_MOV is
13893    false if we expect this to be used for a memory address and true if
13894    we expect to load the address into a register.  */
13895
13896 static rtx
13897 legitimize_tls_address (rtx x, enum tls_model model, bool for_mov)
13898 {
13899   rtx dest, base, off;
13900   rtx pic = NULL_RTX, tp = NULL_RTX;
13901   machine_mode tp_mode = Pmode;
13902   int type;
13903
13904   /* Fall back to global dynamic model if tool chain cannot support local
13905      dynamic.  */
13906   if (TARGET_SUN_TLS && !TARGET_64BIT
13907       && !HAVE_AS_IX86_TLSLDMPLT && !HAVE_AS_IX86_TLSLDM
13908       && model == TLS_MODEL_LOCAL_DYNAMIC)
13909     model = TLS_MODEL_GLOBAL_DYNAMIC;
13910
13911   switch (model)
13912     {
13913     case TLS_MODEL_GLOBAL_DYNAMIC:
13914       dest = gen_reg_rtx (Pmode);
13915
13916       if (!TARGET_64BIT)
13917         {
13918           if (flag_pic && !TARGET_PECOFF)
13919             pic = pic_offset_table_rtx;
13920           else
13921             {
13922               pic = gen_reg_rtx (Pmode);
13923               emit_insn (gen_set_got (pic));
13924             }
13925         }
13926
13927       if (TARGET_GNU2_TLS)
13928         {
13929           if (TARGET_64BIT)
13930             emit_insn (gen_tls_dynamic_gnu2_64 (dest, x));
13931           else
13932             emit_insn (gen_tls_dynamic_gnu2_32 (dest, x, pic));
13933
13934           tp = get_thread_pointer (Pmode, true);
13935           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, tp, dest));
13936
13937           if (GET_MODE (x) != Pmode)
13938             x = gen_rtx_ZERO_EXTEND (Pmode, x);
13939
13940           set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
13941         }
13942       else
13943         {
13944           rtx caddr = ix86_tls_get_addr ();
13945
13946           if (TARGET_64BIT)
13947             {
13948               rtx rax = gen_rtx_REG (Pmode, AX_REG);
13949               rtx_insn *insns;
13950
13951               start_sequence ();
13952               emit_call_insn
13953                 (ix86_gen_tls_global_dynamic_64 (rax, x, caddr));
13954               insns = get_insns ();
13955               end_sequence ();
13956
13957               if (GET_MODE (x) != Pmode)
13958                 x = gen_rtx_ZERO_EXTEND (Pmode, x);
13959
13960               RTL_CONST_CALL_P (insns) = 1;
13961               emit_libcall_block (insns, dest, rax, x);
13962             }
13963           else
13964             emit_insn (gen_tls_global_dynamic_32 (dest, x, pic, caddr));
13965         }
13966       break;
13967
13968     case TLS_MODEL_LOCAL_DYNAMIC:
13969       base = gen_reg_rtx (Pmode);
13970
13971       if (!TARGET_64BIT)
13972         {
13973           if (flag_pic)
13974             pic = pic_offset_table_rtx;
13975           else
13976             {
13977               pic = gen_reg_rtx (Pmode);
13978               emit_insn (gen_set_got (pic));
13979             }
13980         }
13981
13982       if (TARGET_GNU2_TLS)
13983         {
13984           rtx tmp = ix86_tls_module_base ();
13985
13986           if (TARGET_64BIT)
13987             emit_insn (gen_tls_dynamic_gnu2_64 (base, tmp));
13988           else
13989             emit_insn (gen_tls_dynamic_gnu2_32 (base, tmp, pic));
13990
13991           tp = get_thread_pointer (Pmode, true);
13992           set_unique_reg_note (get_last_insn (), REG_EQUAL,
13993                                gen_rtx_MINUS (Pmode, tmp, tp));
13994         }
13995       else
13996         {
13997           rtx caddr = ix86_tls_get_addr ();
13998
13999           if (TARGET_64BIT)
14000             {
14001               rtx rax = gen_rtx_REG (Pmode, AX_REG);
14002               rtx_insn *insns;
14003               rtx eqv;
14004
14005               start_sequence ();
14006               emit_call_insn
14007                 (ix86_gen_tls_local_dynamic_base_64 (rax, caddr));
14008               insns = get_insns ();
14009               end_sequence ();
14010
14011               /* Attach a unique REG_EQUAL, to allow the RTL optimizers to
14012                  share the LD_BASE result with other LD model accesses.  */
14013               eqv = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, const0_rtx),
14014                                     UNSPEC_TLS_LD_BASE);
14015
14016               RTL_CONST_CALL_P (insns) = 1;
14017               emit_libcall_block (insns, base, rax, eqv);
14018             }
14019           else
14020             emit_insn (gen_tls_local_dynamic_base_32 (base, pic, caddr));
14021         }
14022
14023       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x), UNSPEC_DTPOFF);
14024       off = gen_rtx_CONST (Pmode, off);
14025
14026       dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, base, off));
14027
14028       if (TARGET_GNU2_TLS)
14029         {
14030           dest = force_reg (Pmode, gen_rtx_PLUS (Pmode, dest, tp));
14031
14032           if (GET_MODE (x) != Pmode)
14033             x = gen_rtx_ZERO_EXTEND (Pmode, x);
14034
14035           set_unique_reg_note (get_last_insn (), REG_EQUAL, x);
14036         }
14037       break;
14038
14039     case TLS_MODEL_INITIAL_EXEC:
14040       if (TARGET_64BIT)
14041         {
14042           if (TARGET_SUN_TLS && !TARGET_X32)
14043             {
14044               /* The Sun linker took the AMD64 TLS spec literally
14045                  and can only handle %rax as destination of the
14046                  initial executable code sequence.  */
14047
14048               dest = gen_reg_rtx (DImode);
14049               emit_insn (gen_tls_initial_exec_64_sun (dest, x));
14050               return dest;
14051             }
14052
14053           /* Generate DImode references to avoid %fs:(%reg32)
14054              problems and linker IE->LE relaxation bug.  */
14055           tp_mode = DImode;
14056           pic = NULL;
14057           type = UNSPEC_GOTNTPOFF;
14058         }
14059       else if (flag_pic)
14060         {
14061           set_pic_reg_ever_live ();
14062           pic = pic_offset_table_rtx;
14063           type = TARGET_ANY_GNU_TLS ? UNSPEC_GOTNTPOFF : UNSPEC_GOTTPOFF;
14064         }
14065       else if (!TARGET_ANY_GNU_TLS)
14066         {
14067           pic = gen_reg_rtx (Pmode);
14068           emit_insn (gen_set_got (pic));
14069           type = UNSPEC_GOTTPOFF;
14070         }
14071       else
14072         {
14073           pic = NULL;
14074           type = UNSPEC_INDNTPOFF;
14075         }
14076
14077       off = gen_rtx_UNSPEC (tp_mode, gen_rtvec (1, x), type);
14078       off = gen_rtx_CONST (tp_mode, off);
14079       if (pic)
14080         off = gen_rtx_PLUS (tp_mode, pic, off);
14081       off = gen_const_mem (tp_mode, off);
14082       set_mem_alias_set (off, ix86_GOT_alias_set ());
14083
14084       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
14085         {
14086           base = get_thread_pointer (tp_mode,
14087                                      for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
14088           off = force_reg (tp_mode, off);
14089           return gen_rtx_PLUS (tp_mode, base, off);
14090         }
14091       else
14092         {
14093           base = get_thread_pointer (Pmode, true);
14094           dest = gen_reg_rtx (Pmode);
14095           emit_insn (ix86_gen_sub3 (dest, base, off));
14096         }
14097       break;
14098
14099     case TLS_MODEL_LOCAL_EXEC:
14100       off = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, x),
14101                             (TARGET_64BIT || TARGET_ANY_GNU_TLS)
14102                             ? UNSPEC_NTPOFF : UNSPEC_TPOFF);
14103       off = gen_rtx_CONST (Pmode, off);
14104
14105       if (TARGET_64BIT || TARGET_ANY_GNU_TLS)
14106         {
14107           base = get_thread_pointer (Pmode,
14108                                      for_mov || !TARGET_TLS_DIRECT_SEG_REFS);
14109           return gen_rtx_PLUS (Pmode, base, off);
14110         }
14111       else
14112         {
14113           base = get_thread_pointer (Pmode, true);
14114           dest = gen_reg_rtx (Pmode);
14115           emit_insn (ix86_gen_sub3 (dest, base, off));
14116         }
14117       break;
14118
14119     default:
14120       gcc_unreachable ();
14121     }
14122
14123   return dest;
14124 }
14125
14126 /* Create or return the unique __imp_DECL dllimport symbol corresponding
14127    to symbol DECL if BEIMPORT is true.  Otherwise create or return the
14128    unique refptr-DECL symbol corresponding to symbol DECL.  */
14129
14130 struct dllimport_hasher : ggc_cache_hasher<tree_map *>
14131 {
14132   static inline hashval_t hash (tree_map *m) { return m->hash; }
14133   static inline bool
14134   equal (tree_map *a, tree_map *b)
14135   {
14136     return a->base.from == b->base.from;
14137   }
14138
14139   static void
14140   handle_cache_entry (tree_map *&m)
14141   {
14142     extern void gt_ggc_mx (tree_map *&);
14143     if (m == HTAB_EMPTY_ENTRY || m == HTAB_DELETED_ENTRY)
14144       return;
14145     else if (ggc_marked_p (m->base.from))
14146       gt_ggc_mx (m);
14147     else
14148       m = static_cast<tree_map *> (HTAB_DELETED_ENTRY);
14149   }
14150 };
14151
14152 static GTY((cache)) hash_table<dllimport_hasher> *dllimport_map;
14153
14154 static tree
14155 get_dllimport_decl (tree decl, bool beimport)
14156 {
14157   struct tree_map *h, in;
14158   const char *name;
14159   const char *prefix;
14160   size_t namelen, prefixlen;
14161   char *imp_name;
14162   tree to;
14163   rtx rtl;
14164
14165   if (!dllimport_map)
14166     dllimport_map = hash_table<dllimport_hasher>::create_ggc (512);
14167
14168   in.hash = htab_hash_pointer (decl);
14169   in.base.from = decl;
14170   tree_map **loc = dllimport_map->find_slot_with_hash (&in, in.hash, INSERT);
14171   h = *loc;
14172   if (h)
14173     return h->to;
14174
14175   *loc = h = ggc_alloc<tree_map> ();
14176   h->hash = in.hash;
14177   h->base.from = decl;
14178   h->to = to = build_decl (DECL_SOURCE_LOCATION (decl),
14179                            VAR_DECL, NULL, ptr_type_node);
14180   DECL_ARTIFICIAL (to) = 1;
14181   DECL_IGNORED_P (to) = 1;
14182   DECL_EXTERNAL (to) = 1;
14183   TREE_READONLY (to) = 1;
14184
14185   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
14186   name = targetm.strip_name_encoding (name);
14187   if (beimport)
14188     prefix = name[0] == FASTCALL_PREFIX || user_label_prefix[0] == 0
14189       ? "*__imp_" : "*__imp__";
14190   else
14191     prefix = user_label_prefix[0] == 0 ? "*.refptr." : "*refptr.";
14192   namelen = strlen (name);
14193   prefixlen = strlen (prefix);
14194   imp_name = (char *) alloca (namelen + prefixlen + 1);
14195   memcpy (imp_name, prefix, prefixlen);
14196   memcpy (imp_name + prefixlen, name, namelen + 1);
14197
14198   name = ggc_alloc_string (imp_name, namelen + prefixlen);
14199   rtl = gen_rtx_SYMBOL_REF (Pmode, name);
14200   SET_SYMBOL_REF_DECL (rtl, to);
14201   SYMBOL_REF_FLAGS (rtl) = SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_STUBVAR;
14202   if (!beimport)
14203     {
14204       SYMBOL_REF_FLAGS (rtl) |= SYMBOL_FLAG_EXTERNAL;
14205 #ifdef SUB_TARGET_RECORD_STUB
14206       SUB_TARGET_RECORD_STUB (name);
14207 #endif
14208     }      
14209
14210   rtl = gen_const_mem (Pmode, rtl);
14211   set_mem_alias_set (rtl, ix86_GOT_alias_set ());
14212
14213   SET_DECL_RTL (to, rtl);
14214   SET_DECL_ASSEMBLER_NAME (to, get_identifier (name));
14215
14216   return to;
14217 }
14218
14219 /* Expand SYMBOL into its corresponding far-addresse symbol.
14220    WANT_REG is true if we require the result be a register.  */
14221
14222 static rtx
14223 legitimize_pe_coff_extern_decl (rtx symbol, bool want_reg)
14224 {
14225   tree imp_decl;
14226   rtx x;
14227
14228   gcc_assert (SYMBOL_REF_DECL (symbol));
14229   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), false);
14230
14231   x = DECL_RTL (imp_decl);
14232   if (want_reg)
14233     x = force_reg (Pmode, x);
14234   return x;
14235 }
14236
14237 /* Expand SYMBOL into its corresponding dllimport symbol.  WANT_REG is
14238    true if we require the result be a register.  */
14239
14240 static rtx
14241 legitimize_dllimport_symbol (rtx symbol, bool want_reg)
14242 {
14243   tree imp_decl;
14244   rtx x;
14245
14246   gcc_assert (SYMBOL_REF_DECL (symbol));
14247   imp_decl = get_dllimport_decl (SYMBOL_REF_DECL (symbol), true);
14248
14249   x = DECL_RTL (imp_decl);
14250   if (want_reg)
14251     x = force_reg (Pmode, x);
14252   return x;
14253 }
14254
14255 /* Expand SYMBOL into its corresponding dllimport or refptr symbol.  WANT_REG 
14256    is true if we require the result be a register.  */
14257
14258 static rtx
14259 legitimize_pe_coff_symbol (rtx addr, bool inreg)
14260 {
14261   if (!TARGET_PECOFF)
14262     return NULL_RTX;
14263
14264   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
14265     {
14266       if (GET_CODE (addr) == SYMBOL_REF && SYMBOL_REF_DLLIMPORT_P (addr))
14267         return legitimize_dllimport_symbol (addr, inreg);
14268       if (GET_CODE (addr) == CONST
14269           && GET_CODE (XEXP (addr, 0)) == PLUS
14270           && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
14271           && SYMBOL_REF_DLLIMPORT_P (XEXP (XEXP (addr, 0), 0)))
14272         {
14273           rtx t = legitimize_dllimport_symbol (XEXP (XEXP (addr, 0), 0), inreg);
14274           return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
14275         }
14276     }
14277
14278   if (ix86_cmodel != CM_LARGE_PIC && ix86_cmodel != CM_MEDIUM_PIC)
14279     return NULL_RTX;
14280   if (GET_CODE (addr) == SYMBOL_REF
14281       && !is_imported_p (addr)
14282       && SYMBOL_REF_EXTERNAL_P (addr)
14283       && SYMBOL_REF_DECL (addr))
14284     return legitimize_pe_coff_extern_decl (addr, inreg);
14285
14286   if (GET_CODE (addr) == CONST
14287       && GET_CODE (XEXP (addr, 0)) == PLUS
14288       && GET_CODE (XEXP (XEXP (addr, 0), 0)) == SYMBOL_REF
14289       && !is_imported_p (XEXP (XEXP (addr, 0), 0))
14290       && SYMBOL_REF_EXTERNAL_P (XEXP (XEXP (addr, 0), 0))
14291       && SYMBOL_REF_DECL (XEXP (XEXP (addr, 0), 0)))
14292     {
14293       rtx t = legitimize_pe_coff_extern_decl (XEXP (XEXP (addr, 0), 0), inreg);
14294       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (addr, 0), 1));
14295     }
14296   return NULL_RTX;
14297 }
14298
14299 /* Try machine-dependent ways of modifying an illegitimate address
14300    to be legitimate.  If we find one, return the new, valid address.
14301    This macro is used in only one place: `memory_address' in explow.c.
14302
14303    OLDX is the address as it was before break_out_memory_refs was called.
14304    In some cases it is useful to look at this to decide what needs to be done.
14305
14306    It is always safe for this macro to do nothing.  It exists to recognize
14307    opportunities to optimize the output.
14308
14309    For the 80386, we handle X+REG by loading X into a register R and
14310    using R+REG.  R will go in a general reg and indexing will be used.
14311    However, if REG is a broken-out memory address or multiplication,
14312    nothing needs to be done because REG can certainly go in a general reg.
14313
14314    When -fpic is used, special handling is needed for symbolic references.
14315    See comments by legitimize_pic_address in i386.c for details.  */
14316
14317 static rtx
14318 ix86_legitimize_address (rtx x, rtx, machine_mode mode)
14319 {
14320   bool changed = false;
14321   unsigned log;
14322
14323   log = GET_CODE (x) == SYMBOL_REF ? SYMBOL_REF_TLS_MODEL (x) : 0;
14324   if (log)
14325     return legitimize_tls_address (x, (enum tls_model) log, false);
14326   if (GET_CODE (x) == CONST
14327       && GET_CODE (XEXP (x, 0)) == PLUS
14328       && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF
14329       && (log = SYMBOL_REF_TLS_MODEL (XEXP (XEXP (x, 0), 0))))
14330     {
14331       rtx t = legitimize_tls_address (XEXP (XEXP (x, 0), 0),
14332                                       (enum tls_model) log, false);
14333       return gen_rtx_PLUS (Pmode, t, XEXP (XEXP (x, 0), 1));
14334     }
14335
14336   if (TARGET_DLLIMPORT_DECL_ATTRIBUTES)
14337     {
14338       rtx tmp = legitimize_pe_coff_symbol (x, true);
14339       if (tmp)
14340         return tmp;
14341     }
14342
14343   if (flag_pic && SYMBOLIC_CONST (x))
14344     return legitimize_pic_address (x, 0);
14345
14346 #if TARGET_MACHO
14347   if (MACHO_DYNAMIC_NO_PIC_P && SYMBOLIC_CONST (x))
14348     return machopic_indirect_data_reference (x, 0);
14349 #endif
14350
14351   /* Canonicalize shifts by 0, 1, 2, 3 into multiply */
14352   if (GET_CODE (x) == ASHIFT
14353       && CONST_INT_P (XEXP (x, 1))
14354       && (unsigned HOST_WIDE_INT) INTVAL (XEXP (x, 1)) < 4)
14355     {
14356       changed = true;
14357       log = INTVAL (XEXP (x, 1));
14358       x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)),
14359                         GEN_INT (1 << log));
14360     }
14361
14362   if (GET_CODE (x) == PLUS)
14363     {
14364       /* Canonicalize shifts by 0, 1, 2, 3 into multiply.  */
14365
14366       if (GET_CODE (XEXP (x, 0)) == ASHIFT
14367           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
14368           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 0), 1)) < 4)
14369         {
14370           changed = true;
14371           log = INTVAL (XEXP (XEXP (x, 0), 1));
14372           XEXP (x, 0) = gen_rtx_MULT (Pmode,
14373                                       force_reg (Pmode, XEXP (XEXP (x, 0), 0)),
14374                                       GEN_INT (1 << log));
14375         }
14376
14377       if (GET_CODE (XEXP (x, 1)) == ASHIFT
14378           && CONST_INT_P (XEXP (XEXP (x, 1), 1))
14379           && (unsigned HOST_WIDE_INT) INTVAL (XEXP (XEXP (x, 1), 1)) < 4)
14380         {
14381           changed = true;
14382           log = INTVAL (XEXP (XEXP (x, 1), 1));
14383           XEXP (x, 1) = gen_rtx_MULT (Pmode,
14384                                       force_reg (Pmode, XEXP (XEXP (x, 1), 0)),
14385                                       GEN_INT (1 << log));
14386         }
14387
14388       /* Put multiply first if it isn't already.  */
14389       if (GET_CODE (XEXP (x, 1)) == MULT)
14390         {
14391           std::swap (XEXP (x, 0), XEXP (x, 1));
14392           changed = true;
14393         }
14394
14395       /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const)))
14396          into (plus (plus (mult (reg) (const)) (reg)) (const)).  This can be
14397          created by virtual register instantiation, register elimination, and
14398          similar optimizations.  */
14399       if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS)
14400         {
14401           changed = true;
14402           x = gen_rtx_PLUS (Pmode,
14403                             gen_rtx_PLUS (Pmode, XEXP (x, 0),
14404                                           XEXP (XEXP (x, 1), 0)),
14405                             XEXP (XEXP (x, 1), 1));
14406         }
14407
14408       /* Canonicalize
14409          (plus (plus (mult (reg) (const)) (plus (reg) (const))) const)
14410          into (plus (plus (mult (reg) (const)) (reg)) (const)).  */
14411       else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS
14412                && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
14413                && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS
14414                && CONSTANT_P (XEXP (x, 1)))
14415         {
14416           rtx constant;
14417           rtx other = NULL_RTX;
14418
14419           if (CONST_INT_P (XEXP (x, 1)))
14420             {
14421               constant = XEXP (x, 1);
14422               other = XEXP (XEXP (XEXP (x, 0), 1), 1);
14423             }
14424           else if (CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 1), 1)))
14425             {
14426               constant = XEXP (XEXP (XEXP (x, 0), 1), 1);
14427               other = XEXP (x, 1);
14428             }
14429           else
14430             constant = 0;
14431
14432           if (constant)
14433             {
14434               changed = true;
14435               x = gen_rtx_PLUS (Pmode,
14436                                 gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0),
14437                                               XEXP (XEXP (XEXP (x, 0), 1), 0)),
14438                                 plus_constant (Pmode, other,
14439                                                INTVAL (constant)));
14440             }
14441         }
14442
14443       if (changed && ix86_legitimate_address_p (mode, x, false))
14444         return x;
14445
14446       if (GET_CODE (XEXP (x, 0)) == MULT)
14447         {
14448           changed = true;
14449           XEXP (x, 0) = copy_addr_to_reg (XEXP (x, 0));
14450         }
14451
14452       if (GET_CODE (XEXP (x, 1)) == MULT)
14453         {
14454           changed = true;
14455           XEXP (x, 1) = copy_addr_to_reg (XEXP (x, 1));
14456         }
14457
14458       if (changed
14459           && REG_P (XEXP (x, 1))
14460           && REG_P (XEXP (x, 0)))
14461         return x;
14462
14463       if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1)))
14464         {
14465           changed = true;
14466           x = legitimize_pic_address (x, 0);
14467         }
14468
14469       if (changed && ix86_legitimate_address_p (mode, x, false))
14470         return x;
14471
14472       if (REG_P (XEXP (x, 0)))
14473         {
14474           rtx temp = gen_reg_rtx (Pmode);
14475           rtx val  = force_operand (XEXP (x, 1), temp);
14476           if (val != temp)
14477             {
14478               val = convert_to_mode (Pmode, val, 1);
14479               emit_move_insn (temp, val);
14480             }
14481
14482           XEXP (x, 1) = temp;
14483           return x;
14484         }
14485
14486       else if (REG_P (XEXP (x, 1)))
14487         {
14488           rtx temp = gen_reg_rtx (Pmode);
14489           rtx val  = force_operand (XEXP (x, 0), temp);
14490           if (val != temp)
14491             {
14492               val = convert_to_mode (Pmode, val, 1);
14493               emit_move_insn (temp, val);
14494             }
14495
14496           XEXP (x, 0) = temp;
14497           return x;
14498         }
14499     }
14500
14501   return x;
14502 }
14503 \f
14504 /* Print an integer constant expression in assembler syntax.  Addition
14505    and subtraction are the only arithmetic that may appear in these
14506    expressions.  FILE is the stdio stream to write to, X is the rtx, and
14507    CODE is the operand print code from the output string.  */
14508
14509 static void
14510 output_pic_addr_const (FILE *file, rtx x, int code)
14511 {
14512   char buf[256];
14513
14514   switch (GET_CODE (x))
14515     {
14516     case PC:
14517       gcc_assert (flag_pic);
14518       putc ('.', file);
14519       break;
14520
14521     case SYMBOL_REF:
14522       if (TARGET_64BIT || ! TARGET_MACHO_BRANCH_ISLANDS)
14523         output_addr_const (file, x);
14524       else
14525         {
14526           const char *name = XSTR (x, 0);
14527
14528           /* Mark the decl as referenced so that cgraph will
14529              output the function.  */
14530           if (SYMBOL_REF_DECL (x))
14531             mark_decl_referenced (SYMBOL_REF_DECL (x));
14532
14533 #if TARGET_MACHO
14534           if (MACHOPIC_INDIRECT
14535               && machopic_classify_symbol (x) == MACHOPIC_UNDEFINED_FUNCTION)
14536             name = machopic_indirection_name (x, /*stub_p=*/true);
14537 #endif
14538           assemble_name (file, name);
14539         }
14540       if (!TARGET_MACHO && !(TARGET_64BIT && TARGET_PECOFF)
14541           && code == 'P' && ! SYMBOL_REF_LOCAL_P (x))
14542         fputs ("@PLT", file);
14543       break;
14544
14545     case LABEL_REF:
14546       x = XEXP (x, 0);
14547       /* FALLTHRU */
14548     case CODE_LABEL:
14549       ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x));
14550       assemble_name (asm_out_file, buf);
14551       break;
14552
14553     case CONST_INT:
14554       fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
14555       break;
14556
14557     case CONST:
14558       /* This used to output parentheses around the expression,
14559          but that does not work on the 386 (either ATT or BSD assembler).  */
14560       output_pic_addr_const (file, XEXP (x, 0), code);
14561       break;
14562
14563     case CONST_DOUBLE:
14564       if (GET_MODE (x) == VOIDmode)
14565         {
14566           /* We can use %d if the number is <32 bits and positive.  */
14567           if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0)
14568             fprintf (file, "0x%lx%08lx",
14569                      (unsigned long) CONST_DOUBLE_HIGH (x),
14570                      (unsigned long) CONST_DOUBLE_LOW (x));
14571           else
14572             fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x));
14573         }
14574       else
14575         /* We can't handle floating point constants;
14576            TARGET_PRINT_OPERAND must handle them.  */
14577         output_operand_lossage ("floating constant misused");
14578       break;
14579
14580     case PLUS:
14581       /* Some assemblers need integer constants to appear first.  */
14582       if (CONST_INT_P (XEXP (x, 0)))
14583         {
14584           output_pic_addr_const (file, XEXP (x, 0), code);
14585           putc ('+', file);
14586           output_pic_addr_const (file, XEXP (x, 1), code);
14587         }
14588       else
14589         {
14590           gcc_assert (CONST_INT_P (XEXP (x, 1)));
14591           output_pic_addr_const (file, XEXP (x, 1), code);
14592           putc ('+', file);
14593           output_pic_addr_const (file, XEXP (x, 0), code);
14594         }
14595       break;
14596
14597     case MINUS:
14598       if (!TARGET_MACHO)
14599         putc (ASSEMBLER_DIALECT == ASM_INTEL ? '(' : '[', file);
14600       output_pic_addr_const (file, XEXP (x, 0), code);
14601       putc ('-', file);
14602       output_pic_addr_const (file, XEXP (x, 1), code);
14603       if (!TARGET_MACHO)
14604         putc (ASSEMBLER_DIALECT == ASM_INTEL ? ')' : ']', file);
14605       break;
14606
14607      case UNSPEC:
14608        if (XINT (x, 1) == UNSPEC_STACK_CHECK)
14609          {
14610            bool f = i386_asm_output_addr_const_extra (file, x);
14611            gcc_assert (f);
14612            break;
14613          }
14614
14615        gcc_assert (XVECLEN (x, 0) == 1);
14616        output_pic_addr_const (file, XVECEXP (x, 0, 0), code);
14617        switch (XINT (x, 1))
14618         {
14619         case UNSPEC_GOT:
14620           fputs ("@GOT", file);
14621           break;
14622         case UNSPEC_GOTOFF:
14623           fputs ("@GOTOFF", file);
14624           break;
14625         case UNSPEC_PLTOFF:
14626           fputs ("@PLTOFF", file);
14627           break;
14628         case UNSPEC_PCREL:
14629           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14630                  "(%rip)" : "[rip]", file);
14631           break;
14632         case UNSPEC_GOTPCREL:
14633           fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14634                  "@GOTPCREL(%rip)" : "@GOTPCREL[rip]", file);
14635           break;
14636         case UNSPEC_GOTTPOFF:
14637           /* FIXME: This might be @TPOFF in Sun ld too.  */
14638           fputs ("@gottpoff", file);
14639           break;
14640         case UNSPEC_TPOFF:
14641           fputs ("@tpoff", file);
14642           break;
14643         case UNSPEC_NTPOFF:
14644           if (TARGET_64BIT)
14645             fputs ("@tpoff", file);
14646           else
14647             fputs ("@ntpoff", file);
14648           break;
14649         case UNSPEC_DTPOFF:
14650           fputs ("@dtpoff", file);
14651           break;
14652         case UNSPEC_GOTNTPOFF:
14653           if (TARGET_64BIT)
14654             fputs (ASSEMBLER_DIALECT == ASM_ATT ?
14655                    "@gottpoff(%rip)": "@gottpoff[rip]", file);
14656           else
14657             fputs ("@gotntpoff", file);
14658           break;
14659         case UNSPEC_INDNTPOFF:
14660           fputs ("@indntpoff", file);
14661           break;
14662 #if TARGET_MACHO
14663         case UNSPEC_MACHOPIC_OFFSET:
14664           putc ('-', file);
14665           machopic_output_function_base_name (file);
14666           break;
14667 #endif
14668         default:
14669           output_operand_lossage ("invalid UNSPEC as operand");
14670           break;
14671         }
14672        break;
14673
14674     default:
14675       output_operand_lossage ("invalid expression as operand");
14676     }
14677 }
14678
14679 /* This is called from dwarf2out.c via TARGET_ASM_OUTPUT_DWARF_DTPREL.
14680    We need to emit DTP-relative relocations.  */
14681
14682 static void ATTRIBUTE_UNUSED
14683 i386_output_dwarf_dtprel (FILE *file, int size, rtx x)
14684 {
14685   fputs (ASM_LONG, file);
14686   output_addr_const (file, x);
14687   fputs ("@dtpoff", file);
14688   switch (size)
14689     {
14690     case 4:
14691       break;
14692     case 8:
14693       fputs (", 0", file);
14694       break;
14695     default:
14696       gcc_unreachable ();
14697    }
14698 }
14699
14700 /* Return true if X is a representation of the PIC register.  This copes
14701    with calls from ix86_find_base_term, where the register might have
14702    been replaced by a cselib value.  */
14703
14704 static bool
14705 ix86_pic_register_p (rtx x)
14706 {
14707   if (GET_CODE (x) == VALUE && CSELIB_VAL_PTR (x))
14708     return (pic_offset_table_rtx
14709             && rtx_equal_for_cselib_p (x, pic_offset_table_rtx));
14710   else if (!REG_P (x))
14711     return false;
14712   else if (pic_offset_table_rtx)
14713     {
14714       if (REGNO (x) == REGNO (pic_offset_table_rtx))
14715         return true;
14716       if (HARD_REGISTER_P (x)
14717           && !HARD_REGISTER_P (pic_offset_table_rtx)
14718           && ORIGINAL_REGNO (x) == REGNO (pic_offset_table_rtx))
14719         return true;
14720       return false;
14721     }
14722   else
14723     return REGNO (x) == PIC_OFFSET_TABLE_REGNUM;
14724 }
14725
14726 /* Helper function for ix86_delegitimize_address.
14727    Attempt to delegitimize TLS local-exec accesses.  */
14728
14729 static rtx
14730 ix86_delegitimize_tls_address (rtx orig_x)
14731 {
14732   rtx x = orig_x, unspec;
14733   struct ix86_address addr;
14734
14735   if (!TARGET_TLS_DIRECT_SEG_REFS)
14736     return orig_x;
14737   if (MEM_P (x))
14738     x = XEXP (x, 0);
14739   if (GET_CODE (x) != PLUS || GET_MODE (x) != Pmode)
14740     return orig_x;
14741   if (ix86_decompose_address (x, &addr) == 0
14742       || addr.seg != DEFAULT_TLS_SEG_REG
14743       || addr.disp == NULL_RTX
14744       || GET_CODE (addr.disp) != CONST)
14745     return orig_x;
14746   unspec = XEXP (addr.disp, 0);
14747   if (GET_CODE (unspec) == PLUS && CONST_INT_P (XEXP (unspec, 1)))
14748     unspec = XEXP (unspec, 0);
14749   if (GET_CODE (unspec) != UNSPEC || XINT (unspec, 1) != UNSPEC_NTPOFF)
14750     return orig_x;
14751   x = XVECEXP (unspec, 0, 0);
14752   gcc_assert (GET_CODE (x) == SYMBOL_REF);
14753   if (unspec != XEXP (addr.disp, 0))
14754     x = gen_rtx_PLUS (Pmode, x, XEXP (XEXP (addr.disp, 0), 1));
14755   if (addr.index)
14756     {
14757       rtx idx = addr.index;
14758       if (addr.scale != 1)
14759         idx = gen_rtx_MULT (Pmode, idx, GEN_INT (addr.scale));
14760       x = gen_rtx_PLUS (Pmode, idx, x);
14761     }
14762   if (addr.base)
14763     x = gen_rtx_PLUS (Pmode, addr.base, x);
14764   if (MEM_P (orig_x))
14765     x = replace_equiv_address_nv (orig_x, x);
14766   return x;
14767 }
14768
14769 /* In the name of slightly smaller debug output, and to cater to
14770    general assembler lossage, recognize PIC+GOTOFF and turn it back
14771    into a direct symbol reference.
14772
14773    On Darwin, this is necessary to avoid a crash, because Darwin
14774    has a different PIC label for each routine but the DWARF debugging
14775    information is not associated with any particular routine, so it's
14776    necessary to remove references to the PIC label from RTL stored by
14777    the DWARF output code.  */
14778
14779 static rtx
14780 ix86_delegitimize_address (rtx x)
14781 {
14782   rtx orig_x = delegitimize_mem_from_attrs (x);
14783   /* addend is NULL or some rtx if x is something+GOTOFF where
14784      something doesn't include the PIC register.  */
14785   rtx addend = NULL_RTX;
14786   /* reg_addend is NULL or a multiple of some register.  */
14787   rtx reg_addend = NULL_RTX;
14788   /* const_addend is NULL or a const_int.  */
14789   rtx const_addend = NULL_RTX;
14790   /* This is the result, or NULL.  */
14791   rtx result = NULL_RTX;
14792
14793   x = orig_x;
14794
14795   if (MEM_P (x))
14796     x = XEXP (x, 0);
14797
14798   if (TARGET_64BIT)
14799     {
14800       if (GET_CODE (x) == CONST
14801           && GET_CODE (XEXP (x, 0)) == PLUS
14802           && GET_MODE (XEXP (x, 0)) == Pmode
14803           && CONST_INT_P (XEXP (XEXP (x, 0), 1))
14804           && GET_CODE (XEXP (XEXP (x, 0), 0)) == UNSPEC
14805           && XINT (XEXP (XEXP (x, 0), 0), 1) == UNSPEC_PCREL)
14806         {
14807           rtx x2 = XVECEXP (XEXP (XEXP (x, 0), 0), 0, 0);
14808           x = gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 1), x2);
14809           if (MEM_P (orig_x))
14810             x = replace_equiv_address_nv (orig_x, x);
14811           return x;
14812         }
14813
14814       if (GET_CODE (x) == CONST
14815           && GET_CODE (XEXP (x, 0)) == UNSPEC
14816           && (XINT (XEXP (x, 0), 1) == UNSPEC_GOTPCREL
14817               || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL)
14818           && (MEM_P (orig_x) || XINT (XEXP (x, 0), 1) == UNSPEC_PCREL))
14819         {
14820           x = XVECEXP (XEXP (x, 0), 0, 0);
14821           if (GET_MODE (orig_x) != GET_MODE (x) && MEM_P (orig_x))
14822             {
14823               x = simplify_gen_subreg (GET_MODE (orig_x), x,
14824                                        GET_MODE (x), 0);
14825               if (x == NULL_RTX)
14826                 return orig_x;
14827             }
14828           return x;
14829         }
14830
14831       if (ix86_cmodel != CM_MEDIUM_PIC && ix86_cmodel != CM_LARGE_PIC)
14832         return ix86_delegitimize_tls_address (orig_x);
14833
14834       /* Fall thru into the code shared with -m32 for -mcmodel=large -fpic
14835          and -mcmodel=medium -fpic.  */
14836     }
14837
14838   if (GET_CODE (x) != PLUS
14839       || GET_CODE (XEXP (x, 1)) != CONST)
14840     return ix86_delegitimize_tls_address (orig_x);
14841
14842   if (ix86_pic_register_p (XEXP (x, 0)))
14843     /* %ebx + GOT/GOTOFF */
14844     ;
14845   else if (GET_CODE (XEXP (x, 0)) == PLUS)
14846     {
14847       /* %ebx + %reg * scale + GOT/GOTOFF */
14848       reg_addend = XEXP (x, 0);
14849       if (ix86_pic_register_p (XEXP (reg_addend, 0)))
14850         reg_addend = XEXP (reg_addend, 1);
14851       else if (ix86_pic_register_p (XEXP (reg_addend, 1)))
14852         reg_addend = XEXP (reg_addend, 0);
14853       else
14854         {
14855           reg_addend = NULL_RTX;
14856           addend = XEXP (x, 0);
14857         }
14858     }
14859   else
14860     addend = XEXP (x, 0);
14861
14862   x = XEXP (XEXP (x, 1), 0);
14863   if (GET_CODE (x) == PLUS
14864       && CONST_INT_P (XEXP (x, 1)))
14865     {
14866       const_addend = XEXP (x, 1);
14867       x = XEXP (x, 0);
14868     }
14869
14870   if (GET_CODE (x) == UNSPEC
14871       && ((XINT (x, 1) == UNSPEC_GOT && MEM_P (orig_x) && !addend)
14872           || (XINT (x, 1) == UNSPEC_GOTOFF && !MEM_P (orig_x))
14873           || (XINT (x, 1) == UNSPEC_PLTOFF && ix86_cmodel == CM_LARGE_PIC
14874               && !MEM_P (orig_x) && !addend)))
14875     result = XVECEXP (x, 0, 0);
14876
14877   if (!TARGET_64BIT && TARGET_MACHO && darwin_local_data_pic (x)
14878       && !MEM_P (orig_x))
14879     result = XVECEXP (x, 0, 0);
14880
14881   if (! result)
14882     return ix86_delegitimize_tls_address (orig_x);
14883
14884   if (const_addend)
14885     result = gen_rtx_CONST (Pmode, gen_rtx_PLUS (Pmode, result, const_addend));
14886   if (reg_addend)
14887     result = gen_rtx_PLUS (Pmode, reg_addend, result);
14888   if (addend)
14889     {
14890       /* If the rest of original X doesn't involve the PIC register, add
14891          addend and subtract pic_offset_table_rtx.  This can happen e.g.
14892          for code like:
14893          leal (%ebx, %ecx, 4), %ecx
14894          ...
14895          movl foo@GOTOFF(%ecx), %edx
14896          in which case we return (%ecx - %ebx) + foo
14897          or (%ecx - _GLOBAL_OFFSET_TABLE_) + foo if pseudo_pic_reg
14898          and reload has completed.  */
14899       if (pic_offset_table_rtx
14900           && (!reload_completed || !ix86_use_pseudo_pic_reg ()))
14901         result = gen_rtx_PLUS (Pmode, gen_rtx_MINUS (Pmode, copy_rtx (addend),
14902                                                      pic_offset_table_rtx),
14903                                result);
14904       else if (pic_offset_table_rtx && !TARGET_MACHO && !TARGET_VXWORKS_RTP)
14905         {
14906           rtx tmp = gen_rtx_SYMBOL_REF (Pmode, GOT_SYMBOL_NAME);
14907           tmp = gen_rtx_MINUS (Pmode, copy_rtx (addend), tmp);
14908           result = gen_rtx_PLUS (Pmode, tmp, result);
14909         }
14910       else
14911         return orig_x;
14912     }
14913   if (GET_MODE (orig_x) != Pmode && MEM_P (orig_x))
14914     {
14915       result = simplify_gen_subreg (GET_MODE (orig_x), result, Pmode, 0);
14916       if (result == NULL_RTX)
14917         return orig_x;
14918     }
14919   return result;
14920 }
14921
14922 /* If X is a machine specific address (i.e. a symbol or label being
14923    referenced as a displacement from the GOT implemented using an
14924    UNSPEC), then return the base term.  Otherwise return X.  */
14925
14926 rtx
14927 ix86_find_base_term (rtx x)
14928 {
14929   rtx term;
14930
14931   if (TARGET_64BIT)
14932     {
14933       if (GET_CODE (x) != CONST)
14934         return x;
14935       term = XEXP (x, 0);
14936       if (GET_CODE (term) == PLUS
14937           && (CONST_INT_P (XEXP (term, 1))
14938               || GET_CODE (XEXP (term, 1)) == CONST_DOUBLE))
14939         term = XEXP (term, 0);
14940       if (GET_CODE (term) != UNSPEC
14941           || (XINT (term, 1) != UNSPEC_GOTPCREL
14942               && XINT (term, 1) != UNSPEC_PCREL))
14943         return x;
14944
14945       return XVECEXP (term, 0, 0);
14946     }
14947
14948   return ix86_delegitimize_address (x);
14949 }
14950 \f
14951 static void
14952 put_condition_code (enum rtx_code code, machine_mode mode, bool reverse,
14953                     bool fp, FILE *file)
14954 {
14955   const char *suffix;
14956
14957   if (mode == CCFPmode || mode == CCFPUmode)
14958     {
14959       code = ix86_fp_compare_code_to_integer (code);
14960       mode = CCmode;
14961     }
14962   if (reverse)
14963     code = reverse_condition (code);
14964
14965   switch (code)
14966     {
14967     case EQ:
14968       switch (mode)
14969         {
14970         case CCAmode:
14971           suffix = "a";
14972           break;
14973
14974         case CCCmode:
14975           suffix = "c";
14976           break;
14977
14978         case CCOmode:
14979           suffix = "o";
14980           break;
14981
14982         case CCSmode:
14983           suffix = "s";
14984           break;
14985
14986         default:
14987           suffix = "e";
14988         }
14989       break;
14990     case NE:
14991       switch (mode)
14992         {
14993         case CCAmode:
14994           suffix = "na";
14995           break;
14996
14997         case CCCmode:
14998           suffix = "nc";
14999           break;
15000
15001         case CCOmode:
15002           suffix = "no";
15003           break;
15004
15005         case CCSmode:
15006           suffix = "ns";
15007           break;
15008
15009         default:
15010           suffix = "ne";
15011         }
15012       break;
15013     case GT:
15014       gcc_assert (mode == CCmode || mode == CCNOmode || mode == CCGCmode);
15015       suffix = "g";
15016       break;
15017     case GTU:
15018       /* ??? Use "nbe" instead of "a" for fcmov lossage on some assemblers.
15019          Those same assemblers have the same but opposite lossage on cmov.  */
15020       if (mode == CCmode)
15021         suffix = fp ? "nbe" : "a";
15022       else
15023         gcc_unreachable ();
15024       break;
15025     case LT:
15026       switch (mode)
15027         {
15028         case CCNOmode:
15029         case CCGOCmode:
15030           suffix = "s";
15031           break;
15032
15033         case CCmode:
15034         case CCGCmode:
15035           suffix = "l";
15036           break;
15037
15038         default:
15039           gcc_unreachable ();
15040         }
15041       break;
15042     case LTU:
15043       if (mode == CCmode)
15044         suffix = "b";
15045       else if (mode == CCCmode)
15046         suffix = fp ? "b" : "c";
15047       else
15048         gcc_unreachable ();
15049       break;
15050     case GE:
15051       switch (mode)
15052         {
15053         case CCNOmode:
15054         case CCGOCmode:
15055           suffix = "ns";
15056           break;
15057
15058         case CCmode:
15059         case CCGCmode:
15060           suffix = "ge";
15061           break;
15062
15063         default:
15064           gcc_unreachable ();
15065         }
15066       break;
15067     case GEU:
15068       if (mode == CCmode)
15069         suffix = "nb";
15070       else if (mode == CCCmode)
15071         suffix = fp ? "nb" : "nc";
15072       else
15073         gcc_unreachable ();
15074       break;
15075     case LE:
15076       gcc_assert (mode == CCmode || mode == CCGCmode || mode == CCNOmode);
15077       suffix = "le";
15078       break;
15079     case LEU:
15080       if (mode == CCmode)
15081         suffix = "be";
15082       else
15083         gcc_unreachable ();
15084       break;
15085     case UNORDERED:
15086       suffix = fp ? "u" : "p";
15087       break;
15088     case ORDERED:
15089       suffix = fp ? "nu" : "np";
15090       break;
15091     default:
15092       gcc_unreachable ();
15093     }
15094   fputs (suffix, file);
15095 }
15096
15097 /* Print the name of register X to FILE based on its machine mode and number.
15098    If CODE is 'w', pretend the mode is HImode.
15099    If CODE is 'b', pretend the mode is QImode.
15100    If CODE is 'k', pretend the mode is SImode.
15101    If CODE is 'q', pretend the mode is DImode.
15102    If CODE is 'x', pretend the mode is V4SFmode.
15103    If CODE is 't', pretend the mode is V8SFmode.
15104    If CODE is 'g', pretend the mode is V16SFmode.
15105    If CODE is 'h', pretend the reg is the 'high' byte register.
15106    If CODE is 'y', print "st(0)" instead of "st", if the reg is stack op.
15107    If CODE is 'd', duplicate the operand for AVX instruction.
15108  */
15109
15110 void
15111 print_reg (rtx x, int code, FILE *file)
15112 {
15113   const char *reg;
15114   unsigned int regno;
15115   bool duplicated = code == 'd' && TARGET_AVX;
15116
15117   if (ASSEMBLER_DIALECT == ASM_ATT)
15118     putc ('%', file);
15119
15120   if (x == pc_rtx)
15121     {
15122       gcc_assert (TARGET_64BIT);
15123       fputs ("rip", file);
15124       return;
15125     }
15126
15127   regno = true_regnum (x);
15128   gcc_assert (regno != ARG_POINTER_REGNUM
15129               && regno != FRAME_POINTER_REGNUM
15130               && regno != FLAGS_REG
15131               && regno != FPSR_REG
15132               && regno != FPCR_REG);
15133
15134   if (code == 'w' || MMX_REG_P (x))
15135     code = 2;
15136   else if (code == 'b')
15137     code = 1;
15138   else if (code == 'k')
15139     code = 4;
15140   else if (code == 'q')
15141     code = 8;
15142   else if (code == 'y')
15143     code = 3;
15144   else if (code == 'h')
15145     code = 0;
15146   else if (code == 'x')
15147     code = 16;
15148   else if (code == 't')
15149     code = 32;
15150   else if (code == 'g')
15151     code = 64;
15152   else
15153     code = GET_MODE_SIZE (GET_MODE (x));
15154
15155   /* Irritatingly, AMD extended registers use different naming convention
15156      from the normal registers: "r%d[bwd]"  */
15157   if (REX_INT_REGNO_P (regno))
15158     {
15159       gcc_assert (TARGET_64BIT);
15160       putc ('r', file);
15161       fprint_ul (file, regno - FIRST_REX_INT_REG + 8);
15162       switch (code)
15163         {
15164           case 0:
15165             error ("extended registers have no high halves");
15166             break;
15167           case 1:
15168             putc ('b', file);
15169             break;
15170           case 2:
15171             putc ('w', file);
15172             break;
15173           case 4:
15174             putc ('d', file);
15175             break;
15176           case 8:
15177             /* no suffix */
15178             break;
15179           default:
15180             error ("unsupported operand size for extended register");
15181             break;
15182         }
15183       return;
15184     }
15185
15186   reg = NULL;
15187   switch (code)
15188     {
15189     case 3:
15190       if (STACK_TOP_P (x))
15191         {
15192           reg = "st(0)";
15193           break;
15194         }
15195       /* FALLTHRU */
15196     case 8:
15197     case 4:
15198     case 12:
15199       if (! ANY_FP_REG_P (x) && ! ANY_MASK_REG_P (x) && ! ANY_BND_REG_P (x))
15200         putc (code == 8 && TARGET_64BIT ? 'r' : 'e', file);
15201       /* FALLTHRU */
15202     case 16:
15203     case 2:
15204     normal:
15205       reg = hi_reg_name[regno];
15206       break;
15207     case 1:
15208       if (regno >= ARRAY_SIZE (qi_reg_name))
15209         goto normal;
15210       reg = qi_reg_name[regno];
15211       break;
15212     case 0:
15213       if (regno >= ARRAY_SIZE (qi_high_reg_name))
15214         goto normal;
15215       reg = qi_high_reg_name[regno];
15216       break;
15217     case 32:
15218       if (SSE_REG_P (x))
15219         {
15220           gcc_assert (!duplicated);
15221           putc ('y', file);
15222           fputs (hi_reg_name[regno] + 1, file);
15223           return;
15224         }
15225     case 64:
15226       if (SSE_REG_P (x))
15227         {
15228           gcc_assert (!duplicated);
15229           putc ('z', file);
15230           fputs (hi_reg_name[REGNO (x)] + 1, file);
15231           return;
15232         }
15233       break;
15234     default:
15235       gcc_unreachable ();
15236     }
15237
15238   fputs (reg, file);
15239   if (duplicated)
15240     {
15241       if (ASSEMBLER_DIALECT == ASM_ATT)
15242         fprintf (file, ", %%%s", reg);
15243       else
15244         fprintf (file, ", %s", reg);
15245     }
15246 }
15247
15248 /* Meaning of CODE:
15249    L,W,B,Q,S,T -- print the opcode suffix for specified size of operand.
15250    C -- print opcode suffix for set/cmov insn.
15251    c -- like C, but print reversed condition
15252    F,f -- likewise, but for floating-point.
15253    O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
15254         otherwise nothing
15255    R -- print embeded rounding and sae.
15256    r -- print only sae.
15257    z -- print the opcode suffix for the size of the current operand.
15258    Z -- likewise, with special suffixes for x87 instructions.
15259    * -- print a star (in certain assembler syntax)
15260    A -- print an absolute memory reference.
15261    E -- print address with DImode register names if TARGET_64BIT.
15262    w -- print the operand as if it's a "word" (HImode) even if it isn't.
15263    s -- print a shift double count, followed by the assemblers argument
15264         delimiter.
15265    b -- print the QImode name of the register for the indicated operand.
15266         %b0 would print %al if operands[0] is reg 0.
15267    w --  likewise, print the HImode name of the register.
15268    k --  likewise, print the SImode name of the register.
15269    q --  likewise, print the DImode name of the register.
15270    x --  likewise, print the V4SFmode name of the register.
15271    t --  likewise, print the V8SFmode name of the register.
15272    g --  likewise, print the V16SFmode name of the register.
15273    h -- print the QImode name for a "high" register, either ah, bh, ch or dh.
15274    y -- print "st(0)" instead of "st" as a register.
15275    d -- print duplicated register operand for AVX instruction.
15276    D -- print condition for SSE cmp instruction.
15277    P -- if PIC, print an @PLT suffix.
15278    p -- print raw symbol name.
15279    X -- don't print any sort of PIC '@' suffix for a symbol.
15280    & -- print some in-use local-dynamic symbol name.
15281    H -- print a memory address offset by 8; used for sse high-parts
15282    Y -- print condition for XOP pcom* instruction.
15283    + -- print a branch hint as 'cs' or 'ds' prefix
15284    ; -- print a semicolon (after prefixes due to bug in older gas).
15285    ~ -- print "i" if TARGET_AVX2, "f" otherwise.
15286    @ -- print a segment register of thread base pointer load
15287    ^ -- print addr32 prefix if TARGET_64BIT and Pmode != word_mode
15288    ! -- print MPX prefix for jxx/call/ret instructions if required.
15289  */
15290
15291 void
15292 ix86_print_operand (FILE *file, rtx x, int code)
15293 {
15294   if (code)
15295     {
15296       switch (code)
15297         {
15298         case 'A':
15299           switch (ASSEMBLER_DIALECT)
15300             {
15301             case ASM_ATT:
15302               putc ('*', file);
15303               break;
15304
15305             case ASM_INTEL:
15306               /* Intel syntax. For absolute addresses, registers should not
15307                  be surrounded by braces.  */
15308               if (!REG_P (x))
15309                 {
15310                   putc ('[', file);
15311                   ix86_print_operand (file, x, 0);
15312                   putc (']', file);
15313                   return;
15314                 }
15315               break;
15316
15317             default:
15318               gcc_unreachable ();
15319             }
15320
15321           ix86_print_operand (file, x, 0);
15322           return;
15323
15324         case 'E':
15325           /* Wrap address in an UNSPEC to declare special handling.  */
15326           if (TARGET_64BIT)
15327             x = gen_rtx_UNSPEC (DImode, gen_rtvec (1, x), UNSPEC_LEA_ADDR);
15328
15329           output_address (x);
15330           return;
15331
15332         case 'L':
15333           if (ASSEMBLER_DIALECT == ASM_ATT)
15334             putc ('l', file);
15335           return;
15336
15337         case 'W':
15338           if (ASSEMBLER_DIALECT == ASM_ATT)
15339             putc ('w', file);
15340           return;
15341
15342         case 'B':
15343           if (ASSEMBLER_DIALECT == ASM_ATT)
15344             putc ('b', file);
15345           return;
15346
15347         case 'Q':
15348           if (ASSEMBLER_DIALECT == ASM_ATT)
15349             putc ('l', file);
15350           return;
15351
15352         case 'S':
15353           if (ASSEMBLER_DIALECT == ASM_ATT)
15354             putc ('s', file);
15355           return;
15356
15357         case 'T':
15358           if (ASSEMBLER_DIALECT == ASM_ATT)
15359             putc ('t', file);
15360           return;
15361
15362         case 'O':
15363 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
15364           if (ASSEMBLER_DIALECT != ASM_ATT)
15365             return;
15366
15367           switch (GET_MODE_SIZE (GET_MODE (x)))
15368             {
15369             case 2:
15370               putc ('w', file);
15371               break;
15372   
15373             case 4:
15374               putc ('l', file);
15375               break;
15376
15377             case 8:
15378               putc ('q', file);
15379               break;
15380
15381             default:
15382               output_operand_lossage
15383                 ("invalid operand size for operand code 'O'");
15384               return;
15385             }
15386
15387           putc ('.', file);
15388 #endif
15389           return;
15390
15391         case 'z':
15392           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
15393             {
15394               /* Opcodes don't get size suffixes if using Intel opcodes.  */
15395               if (ASSEMBLER_DIALECT == ASM_INTEL)
15396                 return;
15397
15398               switch (GET_MODE_SIZE (GET_MODE (x)))
15399                 {
15400                 case 1:
15401                   putc ('b', file);
15402                   return;
15403
15404                 case 2:
15405                   putc ('w', file);
15406                   return;
15407
15408                 case 4:
15409                   putc ('l', file);
15410                   return;
15411
15412                 case 8:
15413                   putc ('q', file);
15414                   return;
15415
15416                 default:
15417                   output_operand_lossage
15418                     ("invalid operand size for operand code 'z'");
15419                   return;
15420                 }
15421             }
15422
15423           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
15424             warning
15425               (0, "non-integer operand used with operand code 'z'");
15426           /* FALLTHRU */
15427
15428         case 'Z':
15429           /* 387 opcodes don't get size suffixes if using Intel opcodes.  */
15430           if (ASSEMBLER_DIALECT == ASM_INTEL)
15431             return;
15432
15433           if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
15434             {
15435               switch (GET_MODE_SIZE (GET_MODE (x)))
15436                 {
15437                 case 2:
15438 #ifdef HAVE_AS_IX86_FILDS
15439                   putc ('s', file);
15440 #endif
15441                   return;
15442
15443                 case 4:
15444                   putc ('l', file);
15445                   return;
15446
15447                 case 8:
15448 #ifdef HAVE_AS_IX86_FILDQ
15449                   putc ('q', file);
15450 #else
15451                   fputs ("ll", file);
15452 #endif
15453                   return;
15454
15455                 default:
15456                   break;
15457                 }
15458             }
15459           else if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
15460             {
15461               /* 387 opcodes don't get size suffixes
15462                  if the operands are registers.  */
15463               if (STACK_REG_P (x))
15464                 return;
15465
15466               switch (GET_MODE_SIZE (GET_MODE (x)))
15467                 {
15468                 case 4:
15469                   putc ('s', file);
15470                   return;
15471
15472                 case 8:
15473                   putc ('l', file);
15474                   return;
15475
15476                 case 12:
15477                 case 16:
15478                   putc ('t', file);
15479                   return;
15480
15481                 default:
15482                   break;
15483                 }
15484             }
15485           else
15486             {
15487               output_operand_lossage
15488                 ("invalid operand type used with operand code 'Z'");
15489               return;
15490             }
15491
15492           output_operand_lossage
15493             ("invalid operand size for operand code 'Z'");
15494           return;
15495
15496         case 'd':
15497         case 'b':
15498         case 'w':
15499         case 'k':
15500         case 'q':
15501         case 'h':
15502         case 't':
15503         case 'g':
15504         case 'y':
15505         case 'x':
15506         case 'X':
15507         case 'P':
15508         case 'p':
15509           break;
15510
15511         case 's':
15512           if (CONST_INT_P (x) || ! SHIFT_DOUBLE_OMITS_COUNT)
15513             {
15514               ix86_print_operand (file, x, 0);
15515               fputs (", ", file);
15516             }
15517           return;
15518
15519         case 'Y':
15520           switch (GET_CODE (x))
15521             {
15522             case NE:
15523               fputs ("neq", file);
15524               break;
15525             case EQ:
15526               fputs ("eq", file);
15527               break;
15528             case GE:
15529             case GEU:
15530               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
15531               break;
15532             case GT:
15533             case GTU:
15534               fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
15535               break;
15536             case LE:
15537             case LEU:
15538               fputs ("le", file);
15539               break;
15540             case LT:
15541             case LTU:
15542               fputs ("lt", file);
15543               break;
15544             case UNORDERED:
15545               fputs ("unord", file);
15546               break;
15547             case ORDERED:
15548               fputs ("ord", file);
15549               break;
15550             case UNEQ:
15551               fputs ("ueq", file);
15552               break;
15553             case UNGE:
15554               fputs ("nlt", file);
15555               break;
15556             case UNGT:
15557               fputs ("nle", file);
15558               break;
15559             case UNLE:
15560               fputs ("ule", file);
15561               break;
15562             case UNLT:
15563               fputs ("ult", file);
15564               break;
15565             case LTGT:
15566               fputs ("une", file);
15567               break;
15568             default:
15569               output_operand_lossage ("operand is not a condition code, "
15570                                       "invalid operand code 'Y'");
15571               return;
15572             }
15573           return;
15574
15575         case 'D':
15576           /* Little bit of braindamage here.  The SSE compare instructions
15577              does use completely different names for the comparisons that the
15578              fp conditional moves.  */
15579           switch (GET_CODE (x))
15580             {
15581             case UNEQ:
15582               if (TARGET_AVX)
15583                 {
15584                   fputs ("eq_us", file);
15585                   break;
15586                 }
15587             case EQ:
15588               fputs ("eq", file);
15589               break;
15590             case UNLT:
15591               if (TARGET_AVX)
15592                 {
15593                   fputs ("nge", file);
15594                   break;
15595                 }
15596             case LT:
15597               fputs ("lt", file);
15598               break;
15599             case UNLE:
15600               if (TARGET_AVX)
15601                 {
15602                   fputs ("ngt", file);
15603                   break;
15604                 }
15605             case LE:
15606               fputs ("le", file);
15607               break;
15608             case UNORDERED:
15609               fputs ("unord", file);
15610               break;
15611             case LTGT:
15612               if (TARGET_AVX)
15613                 {
15614                   fputs ("neq_oq", file);
15615                   break;
15616                 }
15617             case NE:
15618               fputs ("neq", file);
15619               break;
15620             case GE:
15621               if (TARGET_AVX)
15622                 {
15623                   fputs ("ge", file);
15624                   break;
15625                 }
15626             case UNGE:
15627               fputs ("nlt", file);
15628               break;
15629             case GT:
15630               if (TARGET_AVX)
15631                 {
15632                   fputs ("gt", file);
15633                   break;
15634                 }
15635             case UNGT:
15636               fputs ("nle", file);
15637               break;
15638             case ORDERED:
15639               fputs ("ord", file);
15640               break;
15641             default:
15642               output_operand_lossage ("operand is not a condition code, "
15643                                       "invalid operand code 'D'");
15644               return;
15645             }
15646           return;
15647
15648         case 'F':
15649         case 'f':
15650 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
15651           if (ASSEMBLER_DIALECT == ASM_ATT)
15652             putc ('.', file);
15653 #endif
15654
15655         case 'C':
15656         case 'c':
15657           if (!COMPARISON_P (x))
15658             {
15659               output_operand_lossage ("operand is not a condition code, "
15660                                       "invalid operand code '%c'", code);
15661               return;
15662             }
15663           put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)),
15664                               code == 'c' || code == 'f',
15665                               code == 'F' || code == 'f',
15666                               file);
15667           return;
15668
15669         case 'H':
15670           if (!offsettable_memref_p (x))
15671             {
15672               output_operand_lossage ("operand is not an offsettable memory "
15673                                       "reference, invalid operand code 'H'");
15674               return;
15675             }
15676           /* It doesn't actually matter what mode we use here, as we're
15677              only going to use this for printing.  */
15678           x = adjust_address_nv (x, DImode, 8);
15679           /* Output 'qword ptr' for intel assembler dialect.  */
15680           if (ASSEMBLER_DIALECT == ASM_INTEL)
15681             code = 'q';
15682           break;
15683
15684         case 'K':
15685           gcc_assert (CONST_INT_P (x));
15686
15687           if (INTVAL (x) & IX86_HLE_ACQUIRE)
15688 #ifdef HAVE_AS_IX86_HLE
15689             fputs ("xacquire ", file);
15690 #else
15691             fputs ("\n" ASM_BYTE "0xf2\n\t", file);
15692 #endif
15693           else if (INTVAL (x) & IX86_HLE_RELEASE)
15694 #ifdef HAVE_AS_IX86_HLE
15695             fputs ("xrelease ", file);
15696 #else
15697             fputs ("\n" ASM_BYTE "0xf3\n\t", file);
15698 #endif
15699           /* We do not want to print value of the operand.  */
15700           return;
15701
15702         case 'N':
15703           if (x == const0_rtx || x == CONST0_RTX (GET_MODE (x)))
15704             fputs ("{z}", file);
15705           return;
15706
15707         case 'r':
15708           gcc_assert (CONST_INT_P (x));
15709           gcc_assert (INTVAL (x) == ROUND_SAE);
15710
15711           if (ASSEMBLER_DIALECT == ASM_INTEL)
15712             fputs (", ", file);
15713
15714           fputs ("{sae}", file);
15715
15716           if (ASSEMBLER_DIALECT == ASM_ATT)
15717             fputs (", ", file);
15718
15719           return;
15720
15721         case 'R':
15722           gcc_assert (CONST_INT_P (x));
15723
15724           if (ASSEMBLER_DIALECT == ASM_INTEL)
15725             fputs (", ", file);
15726
15727           switch (INTVAL (x))
15728             {
15729             case ROUND_NEAREST_INT | ROUND_SAE:
15730               fputs ("{rn-sae}", file);
15731               break;
15732             case ROUND_NEG_INF | ROUND_SAE:
15733               fputs ("{rd-sae}", file);
15734               break;
15735             case ROUND_POS_INF | ROUND_SAE:
15736               fputs ("{ru-sae}", file);
15737               break;
15738             case ROUND_ZERO | ROUND_SAE:
15739               fputs ("{rz-sae}", file);
15740               break;
15741             default:
15742               gcc_unreachable ();
15743             }
15744
15745           if (ASSEMBLER_DIALECT == ASM_ATT)
15746             fputs (", ", file);
15747
15748           return;
15749
15750         case '*':
15751           if (ASSEMBLER_DIALECT == ASM_ATT)
15752             putc ('*', file);
15753           return;
15754
15755         case '&':
15756           {
15757             const char *name = get_some_local_dynamic_name ();
15758             if (name == NULL)
15759               output_operand_lossage ("'%%&' used without any "
15760                                       "local dynamic TLS references");
15761             else
15762               assemble_name (file, name);
15763             return;
15764           }
15765
15766         case '+':
15767           {
15768             rtx x;
15769
15770             if (!optimize
15771                 || optimize_function_for_size_p (cfun)
15772                 || !TARGET_BRANCH_PREDICTION_HINTS)
15773               return;
15774
15775             x = find_reg_note (current_output_insn, REG_BR_PROB, 0);
15776             if (x)
15777               {
15778                 int pred_val = XINT (x, 0);
15779
15780                 if (pred_val < REG_BR_PROB_BASE * 45 / 100
15781                     || pred_val > REG_BR_PROB_BASE * 55 / 100)
15782                   {
15783                     bool taken = pred_val > REG_BR_PROB_BASE / 2;
15784                     bool cputaken
15785                       = final_forward_branch_p (current_output_insn) == 0;
15786
15787                     /* Emit hints only in the case default branch prediction
15788                        heuristics would fail.  */
15789                     if (taken != cputaken)
15790                       {
15791                         /* We use 3e (DS) prefix for taken branches and
15792                            2e (CS) prefix for not taken branches.  */
15793                         if (taken)
15794                           fputs ("ds ; ", file);
15795                         else
15796                           fputs ("cs ; ", file);
15797                       }
15798                   }
15799               }
15800             return;
15801           }
15802
15803         case ';':
15804 #ifndef HAVE_AS_IX86_REP_LOCK_PREFIX
15805           putc (';', file);
15806 #endif
15807           return;
15808
15809         case '@':
15810           if (ASSEMBLER_DIALECT == ASM_ATT)
15811             putc ('%', file);
15812
15813           /* The kernel uses a different segment register for performance
15814              reasons; a system call would not have to trash the userspace
15815              segment register, which would be expensive.  */
15816           if (TARGET_64BIT && ix86_cmodel != CM_KERNEL)
15817             fputs ("fs", file);
15818           else
15819             fputs ("gs", file);
15820           return;
15821
15822         case '~':
15823           putc (TARGET_AVX2 ? 'i' : 'f', file);
15824           return;
15825
15826         case '^':
15827           if (TARGET_64BIT && Pmode != word_mode)
15828             fputs ("addr32 ", file);
15829           return;
15830
15831         case '!':
15832           if (ix86_bnd_prefixed_insn_p (current_output_insn))
15833             fputs ("bnd ", file);
15834           return;
15835
15836         default:
15837             output_operand_lossage ("invalid operand code '%c'", code);
15838         }
15839     }
15840
15841   if (REG_P (x))
15842     print_reg (x, code, file);
15843
15844   else if (MEM_P (x))
15845     {
15846       /* No `byte ptr' prefix for call instructions or BLKmode operands.  */
15847       if (ASSEMBLER_DIALECT == ASM_INTEL && code != 'X' && code != 'P'
15848           && GET_MODE (x) != BLKmode)
15849         {
15850           const char * size;
15851           switch (GET_MODE_SIZE (GET_MODE (x)))
15852             {
15853             case 1: size = "BYTE"; break;
15854             case 2: size = "WORD"; break;
15855             case 4: size = "DWORD"; break;
15856             case 8: size = "QWORD"; break;
15857             case 12: size = "TBYTE"; break;
15858             case 16:
15859               if (GET_MODE (x) == XFmode)
15860                 size = "TBYTE";
15861               else
15862                 size = "XMMWORD";
15863               break;
15864             case 32: size = "YMMWORD"; break;
15865             case 64: size = "ZMMWORD"; break;
15866             default:
15867               gcc_unreachable ();
15868             }
15869
15870           /* Check for explicit size override (codes 'b', 'w', 'k',
15871              'q' and 'x')  */
15872           if (code == 'b')
15873             size = "BYTE";
15874           else if (code == 'w')
15875             size = "WORD";
15876           else if (code == 'k')
15877             size = "DWORD";
15878           else if (code == 'q')
15879             size = "QWORD";
15880           else if (code == 'x')
15881             size = "XMMWORD";
15882
15883           fputs (size, file);
15884           fputs (" PTR ", file);
15885         }
15886
15887       x = XEXP (x, 0);
15888       /* Avoid (%rip) for call operands.  */
15889       if (CONSTANT_ADDRESS_P (x) && code == 'P'
15890           && !CONST_INT_P (x))
15891         output_addr_const (file, x);
15892       else if (this_is_asm_operands && ! address_operand (x, VOIDmode))
15893         output_operand_lossage ("invalid constraints for operand");
15894       else
15895         output_address (x);
15896     }
15897
15898   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode)
15899     {
15900       REAL_VALUE_TYPE r;
15901       long l;
15902
15903       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
15904       REAL_VALUE_TO_TARGET_SINGLE (r, l);
15905
15906       if (ASSEMBLER_DIALECT == ASM_ATT)
15907         putc ('$', file);
15908       /* Sign extend 32bit SFmode immediate to 8 bytes.  */
15909       if (code == 'q')
15910         fprintf (file, "0x%08" HOST_LONG_LONG_FORMAT "x",
15911                  (unsigned long long) (int) l);
15912       else
15913         fprintf (file, "0x%08x", (unsigned int) l);
15914     }
15915
15916   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
15917     {
15918       REAL_VALUE_TYPE r;
15919       long l[2];
15920
15921       REAL_VALUE_FROM_CONST_DOUBLE (r, x);
15922       REAL_VALUE_TO_TARGET_DOUBLE (r, l);
15923
15924       if (ASSEMBLER_DIALECT == ASM_ATT)
15925         putc ('$', file);
15926       fprintf (file, "0x%lx%08lx", l[1] & 0xffffffff, l[0] & 0xffffffff);
15927     }
15928
15929   /* These float cases don't actually occur as immediate operands.  */
15930   else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == XFmode)
15931     {
15932       char dstr[30];
15933
15934       real_to_decimal (dstr, CONST_DOUBLE_REAL_VALUE (x), sizeof (dstr), 0, 1);
15935       fputs (dstr, file);
15936     }
15937
15938   else
15939     {
15940       /* We have patterns that allow zero sets of memory, for instance.
15941          In 64-bit mode, we should probably support all 8-byte vectors,
15942          since we can in fact encode that into an immediate.  */
15943       if (GET_CODE (x) == CONST_VECTOR)
15944         {
15945           gcc_assert (x == CONST0_RTX (GET_MODE (x)));
15946           x = const0_rtx;
15947         }
15948
15949       if (code != 'P' && code != 'p')
15950         {
15951           if (CONST_INT_P (x) || GET_CODE (x) == CONST_DOUBLE)
15952             {
15953               if (ASSEMBLER_DIALECT == ASM_ATT)
15954                 putc ('$', file);
15955             }
15956           else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF
15957                    || GET_CODE (x) == LABEL_REF)
15958             {
15959               if (ASSEMBLER_DIALECT == ASM_ATT)
15960                 putc ('$', file);
15961               else
15962                 fputs ("OFFSET FLAT:", file);
15963             }
15964         }
15965       if (CONST_INT_P (x))
15966         fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
15967       else if (flag_pic || MACHOPIC_INDIRECT)
15968         output_pic_addr_const (file, x, code);
15969       else
15970         output_addr_const (file, x);
15971     }
15972 }
15973
15974 static bool
15975 ix86_print_operand_punct_valid_p (unsigned char code)
15976 {
15977   return (code == '@' || code == '*' || code == '+' || code == '&'
15978           || code == ';' || code == '~' || code == '^' || code == '!');
15979 }
15980 \f
15981 /* Print a memory operand whose address is ADDR.  */
15982
15983 static void
15984 ix86_print_operand_address (FILE *file, rtx addr)
15985 {
15986   struct ix86_address parts;
15987   rtx base, index, disp;
15988   int scale;
15989   int ok;
15990   bool vsib = false;
15991   int code = 0;
15992
15993   if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_VSIBADDR)
15994     {
15995       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
15996       gcc_assert (parts.index == NULL_RTX);
15997       parts.index = XVECEXP (addr, 0, 1);
15998       parts.scale = INTVAL (XVECEXP (addr, 0, 2));
15999       addr = XVECEXP (addr, 0, 0);
16000       vsib = true;
16001     }
16002   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_LEA_ADDR)
16003     {
16004       gcc_assert (TARGET_64BIT);
16005       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
16006       code = 'q';
16007     }
16008   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_BNDMK_ADDR)
16009     {
16010       ok = ix86_decompose_address (XVECEXP (addr, 0, 1), &parts);
16011       gcc_assert (parts.base == NULL_RTX || parts.index == NULL_RTX);
16012       if (parts.base != NULL_RTX)
16013         {
16014           parts.index = parts.base;
16015           parts.scale = 1;
16016         }
16017       parts.base = XVECEXP (addr, 0, 0);
16018       addr = XVECEXP (addr, 0, 0);
16019     }
16020   else if (GET_CODE (addr) == UNSPEC && XINT (addr, 1) == UNSPEC_BNDLDX_ADDR)
16021     {
16022       ok = ix86_decompose_address (XVECEXP (addr, 0, 0), &parts);
16023       gcc_assert (parts.index == NULL_RTX);
16024       parts.index = XVECEXP (addr, 0, 1);
16025       addr = XVECEXP (addr, 0, 0);
16026     }
16027   else
16028     ok = ix86_decompose_address (addr, &parts);
16029
16030   gcc_assert (ok);
16031
16032   base = parts.base;
16033   index = parts.index;
16034   disp = parts.disp;
16035   scale = parts.scale;
16036
16037   switch (parts.seg)
16038     {
16039     case SEG_DEFAULT:
16040       break;
16041     case SEG_FS:
16042     case SEG_GS:
16043       if (ASSEMBLER_DIALECT == ASM_ATT)
16044         putc ('%', file);
16045       fputs ((parts.seg == SEG_FS ? "fs:" : "gs:"), file);
16046       break;
16047     default:
16048       gcc_unreachable ();
16049     }
16050
16051   /* Use one byte shorter RIP relative addressing for 64bit mode.  */
16052   if (TARGET_64BIT && !base && !index)
16053     {
16054       rtx symbol = disp;
16055
16056       if (GET_CODE (disp) == CONST
16057           && GET_CODE (XEXP (disp, 0)) == PLUS
16058           && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
16059         symbol = XEXP (XEXP (disp, 0), 0);
16060
16061       if (GET_CODE (symbol) == LABEL_REF
16062           || (GET_CODE (symbol) == SYMBOL_REF
16063               && SYMBOL_REF_TLS_MODEL (symbol) == 0))
16064         base = pc_rtx;
16065     }
16066   if (!base && !index)
16067     {
16068       /* Displacement only requires special attention.  */
16069
16070       if (CONST_INT_P (disp))
16071         {
16072           if (ASSEMBLER_DIALECT == ASM_INTEL && parts.seg == SEG_DEFAULT)
16073             fputs ("ds:", file);
16074           fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (disp));
16075         }
16076       else if (flag_pic)
16077         output_pic_addr_const (file, disp, 0);
16078       else
16079         output_addr_const (file, disp);
16080     }
16081   else
16082     {
16083       /* Print SImode register names to force addr32 prefix.  */
16084       if (SImode_address_operand (addr, VOIDmode))
16085         {
16086 #ifdef ENABLE_CHECKING
16087           gcc_assert (TARGET_64BIT);
16088           switch (GET_CODE (addr))
16089             {
16090             case SUBREG:
16091               gcc_assert (GET_MODE (addr) == SImode);
16092               gcc_assert (GET_MODE (SUBREG_REG (addr)) == DImode);
16093               break;
16094             case ZERO_EXTEND:
16095             case AND:
16096               gcc_assert (GET_MODE (addr) == DImode);
16097               break;
16098             default:
16099               gcc_unreachable ();
16100             }
16101 #endif
16102           gcc_assert (!code);
16103           code = 'k';
16104         }
16105       else if (code == 0
16106                && TARGET_X32
16107                && disp
16108                && CONST_INT_P (disp)
16109                && INTVAL (disp) < -16*1024*1024)
16110         {
16111           /* X32 runs in 64-bit mode, where displacement, DISP, in
16112              address DISP(%r64), is encoded as 32-bit immediate sign-
16113              extended from 32-bit to 64-bit.  For -0x40000300(%r64),
16114              address is %r64 + 0xffffffffbffffd00.  When %r64 <
16115              0x40000300, like 0x37ffe064, address is 0xfffffffff7ffdd64,
16116              which is invalid for x32.  The correct address is %r64
16117              - 0x40000300 == 0xf7ffdd64.  To properly encode
16118              -0x40000300(%r64) for x32, we zero-extend negative
16119              displacement by forcing addr32 prefix which truncates
16120              0xfffffffff7ffdd64 to 0xf7ffdd64.  In theory, we should
16121              zero-extend all negative displacements, including -1(%rsp).
16122              However, for small negative displacements, sign-extension
16123              won't cause overflow.  We only zero-extend negative
16124              displacements if they < -16*1024*1024, which is also used
16125              to check legitimate address displacements for PIC.  */
16126           code = 'k';
16127         }
16128
16129       if (ASSEMBLER_DIALECT == ASM_ATT)
16130         {
16131           if (disp)
16132             {
16133               if (flag_pic)
16134                 output_pic_addr_const (file, disp, 0);
16135               else if (GET_CODE (disp) == LABEL_REF)
16136                 output_asm_label (disp);
16137               else
16138                 output_addr_const (file, disp);
16139             }
16140
16141           putc ('(', file);
16142           if (base)
16143             print_reg (base, code, file);
16144           if (index)
16145             {
16146               putc (',', file);
16147               print_reg (index, vsib ? 0 : code, file);
16148               if (scale != 1 || vsib)
16149                 fprintf (file, ",%d", scale);
16150             }
16151           putc (')', file);
16152         }
16153       else
16154         {
16155           rtx offset = NULL_RTX;
16156
16157           if (disp)
16158             {
16159               /* Pull out the offset of a symbol; print any symbol itself.  */
16160               if (GET_CODE (disp) == CONST
16161                   && GET_CODE (XEXP (disp, 0)) == PLUS
16162                   && CONST_INT_P (XEXP (XEXP (disp, 0), 1)))
16163                 {
16164                   offset = XEXP (XEXP (disp, 0), 1);
16165                   disp = gen_rtx_CONST (VOIDmode,
16166                                         XEXP (XEXP (disp, 0), 0));
16167                 }
16168
16169               if (flag_pic)
16170                 output_pic_addr_const (file, disp, 0);
16171               else if (GET_CODE (disp) == LABEL_REF)
16172                 output_asm_label (disp);
16173               else if (CONST_INT_P (disp))
16174                 offset = disp;
16175               else
16176                 output_addr_const (file, disp);
16177             }
16178
16179           putc ('[', file);
16180           if (base)
16181             {
16182               print_reg (base, code, file);
16183               if (offset)
16184                 {
16185                   if (INTVAL (offset) >= 0)
16186                     putc ('+', file);
16187                   fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
16188                 }
16189             }
16190           else if (offset)
16191             fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset));
16192           else
16193             putc ('0', file);
16194
16195           if (index)
16196             {
16197               putc ('+', file);
16198               print_reg (index, vsib ? 0 : code, file);
16199               if (scale != 1 || vsib)
16200                 fprintf (file, "*%d", scale);
16201             }
16202           putc (']', file);
16203         }
16204     }
16205 }
16206
16207 /* Implementation of TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA.  */
16208
16209 static bool
16210 i386_asm_output_addr_const_extra (FILE *file, rtx x)
16211 {
16212   rtx op;
16213
16214   if (GET_CODE (x) != UNSPEC)
16215     return false;
16216
16217   op = XVECEXP (x, 0, 0);
16218   switch (XINT (x, 1))
16219     {
16220     case UNSPEC_GOTTPOFF:
16221       output_addr_const (file, op);
16222       /* FIXME: This might be @TPOFF in Sun ld.  */
16223       fputs ("@gottpoff", file);
16224       break;
16225     case UNSPEC_TPOFF:
16226       output_addr_const (file, op);
16227       fputs ("@tpoff", file);
16228       break;
16229     case UNSPEC_NTPOFF:
16230       output_addr_const (file, op);
16231       if (TARGET_64BIT)
16232         fputs ("@tpoff", file);
16233       else
16234         fputs ("@ntpoff", file);
16235       break;
16236     case UNSPEC_DTPOFF:
16237       output_addr_const (file, op);
16238       fputs ("@dtpoff", file);
16239       break;
16240     case UNSPEC_GOTNTPOFF:
16241       output_addr_const (file, op);
16242       if (TARGET_64BIT)
16243         fputs (ASSEMBLER_DIALECT == ASM_ATT ?
16244                "@gottpoff(%rip)" : "@gottpoff[rip]", file);
16245       else
16246         fputs ("@gotntpoff", file);
16247       break;
16248     case UNSPEC_INDNTPOFF:
16249       output_addr_const (file, op);
16250       fputs ("@indntpoff", file);
16251       break;
16252 #if TARGET_MACHO
16253     case UNSPEC_MACHOPIC_OFFSET:
16254       output_addr_const (file, op);
16255       putc ('-', file);
16256       machopic_output_function_base_name (file);
16257       break;
16258 #endif
16259
16260     case UNSPEC_STACK_CHECK:
16261       {
16262         int offset;
16263
16264         gcc_assert (flag_split_stack);
16265
16266 #ifdef TARGET_THREAD_SPLIT_STACK_OFFSET
16267         offset = TARGET_THREAD_SPLIT_STACK_OFFSET;
16268 #else
16269         gcc_unreachable ();
16270 #endif
16271
16272         fprintf (file, "%s:%d", TARGET_64BIT ? "%fs" : "%gs", offset);
16273       }
16274       break;
16275
16276     default:
16277       return false;
16278     }
16279
16280   return true;
16281 }
16282 \f
16283 /* Split one or more double-mode RTL references into pairs of half-mode
16284    references.  The RTL can be REG, offsettable MEM, integer constant, or
16285    CONST_DOUBLE.  "operands" is a pointer to an array of double-mode RTLs to
16286    split and "num" is its length.  lo_half and hi_half are output arrays
16287    that parallel "operands".  */
16288
16289 void
16290 split_double_mode (machine_mode mode, rtx operands[],
16291                    int num, rtx lo_half[], rtx hi_half[])
16292 {
16293   machine_mode half_mode;
16294   unsigned int byte;
16295
16296   switch (mode)
16297     {
16298     case TImode:
16299       half_mode = DImode;
16300       break;
16301     case DImode:
16302       half_mode = SImode;
16303       break;
16304     default:
16305       gcc_unreachable ();
16306     }
16307
16308   byte = GET_MODE_SIZE (half_mode);
16309
16310   while (num--)
16311     {
16312       rtx op = operands[num];
16313
16314       /* simplify_subreg refuse to split volatile memory addresses,
16315          but we still have to handle it.  */
16316       if (MEM_P (op))
16317         {
16318           lo_half[num] = adjust_address (op, half_mode, 0);
16319           hi_half[num] = adjust_address (op, half_mode, byte);
16320         }
16321       else
16322         {
16323           lo_half[num] = simplify_gen_subreg (half_mode, op,
16324                                               GET_MODE (op) == VOIDmode
16325                                               ? mode : GET_MODE (op), 0);
16326           hi_half[num] = simplify_gen_subreg (half_mode, op,
16327                                               GET_MODE (op) == VOIDmode
16328                                               ? mode : GET_MODE (op), byte);
16329         }
16330     }
16331 }
16332 \f
16333 /* Output code to perform a 387 binary operation in INSN, one of PLUS,
16334    MINUS, MULT or DIV.  OPERANDS are the insn operands, where operands[3]
16335    is the expression of the binary operation.  The output may either be
16336    emitted here, or returned to the caller, like all output_* functions.
16337
16338    There is no guarantee that the operands are the same mode, as they
16339    might be within FLOAT or FLOAT_EXTEND expressions.  */
16340
16341 #ifndef SYSV386_COMPAT
16342 /* Set to 1 for compatibility with brain-damaged assemblers.  No-one
16343    wants to fix the assemblers because that causes incompatibility
16344    with gcc.  No-one wants to fix gcc because that causes
16345    incompatibility with assemblers...  You can use the option of
16346    -DSYSV386_COMPAT=0 if you recompile both gcc and gas this way.  */
16347 #define SYSV386_COMPAT 1
16348 #endif
16349
16350 const char *
16351 output_387_binary_op (rtx insn, rtx *operands)
16352 {
16353   static char buf[40];
16354   const char *p;
16355   const char *ssep;
16356   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]) || SSE_REG_P (operands[2]);
16357
16358 #ifdef ENABLE_CHECKING
16359   /* Even if we do not want to check the inputs, this documents input
16360      constraints.  Which helps in understanding the following code.  */
16361   if (STACK_REG_P (operands[0])
16362       && ((REG_P (operands[1])
16363            && REGNO (operands[0]) == REGNO (operands[1])
16364            && (STACK_REG_P (operands[2]) || MEM_P (operands[2])))
16365           || (REG_P (operands[2])
16366               && REGNO (operands[0]) == REGNO (operands[2])
16367               && (STACK_REG_P (operands[1]) || MEM_P (operands[1]))))
16368       && (STACK_TOP_P (operands[1]) || STACK_TOP_P (operands[2])))
16369     ; /* ok */
16370   else
16371     gcc_assert (is_sse);
16372 #endif
16373
16374   switch (GET_CODE (operands[3]))
16375     {
16376     case PLUS:
16377       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16378           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16379         p = "fiadd";
16380       else
16381         p = "fadd";
16382       ssep = "vadd";
16383       break;
16384
16385     case MINUS:
16386       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16387           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16388         p = "fisub";
16389       else
16390         p = "fsub";
16391       ssep = "vsub";
16392       break;
16393
16394     case MULT:
16395       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16396           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16397         p = "fimul";
16398       else
16399         p = "fmul";
16400       ssep = "vmul";
16401       break;
16402
16403     case DIV:
16404       if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT
16405           || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT)
16406         p = "fidiv";
16407       else
16408         p = "fdiv";
16409       ssep = "vdiv";
16410       break;
16411
16412     default:
16413       gcc_unreachable ();
16414     }
16415
16416   if (is_sse)
16417    {
16418      if (TARGET_AVX)
16419        {
16420          strcpy (buf, ssep);
16421          if (GET_MODE (operands[0]) == SFmode)
16422            strcat (buf, "ss\t{%2, %1, %0|%0, %1, %2}");
16423          else
16424            strcat (buf, "sd\t{%2, %1, %0|%0, %1, %2}");
16425        }
16426      else
16427        {
16428          strcpy (buf, ssep + 1);
16429          if (GET_MODE (operands[0]) == SFmode)
16430            strcat (buf, "ss\t{%2, %0|%0, %2}");
16431          else
16432            strcat (buf, "sd\t{%2, %0|%0, %2}");
16433        }
16434       return buf;
16435    }
16436   strcpy (buf, p);
16437
16438   switch (GET_CODE (operands[3]))
16439     {
16440     case MULT:
16441     case PLUS:
16442       if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2]))
16443         std::swap (operands[1], operands[2]);
16444
16445       /* know operands[0] == operands[1].  */
16446
16447       if (MEM_P (operands[2]))
16448         {
16449           p = "%Z2\t%2";
16450           break;
16451         }
16452
16453       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
16454         {
16455           if (STACK_TOP_P (operands[0]))
16456             /* How is it that we are storing to a dead operand[2]?
16457                Well, presumably operands[1] is dead too.  We can't
16458                store the result to st(0) as st(0) gets popped on this
16459                instruction.  Instead store to operands[2] (which I
16460                think has to be st(1)).  st(1) will be popped later.
16461                gcc <= 2.8.1 didn't have this check and generated
16462                assembly code that the Unixware assembler rejected.  */
16463             p = "p\t{%0, %2|%2, %0}";   /* st(1) = st(0) op st(1); pop */
16464           else
16465             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
16466           break;
16467         }
16468
16469       if (STACK_TOP_P (operands[0]))
16470         p = "\t{%y2, %0|%0, %y2}";      /* st(0) = st(0) op st(r2) */
16471       else
16472         p = "\t{%2, %0|%0, %2}";        /* st(r1) = st(r1) op st(0) */
16473       break;
16474
16475     case MINUS:
16476     case DIV:
16477       if (MEM_P (operands[1]))
16478         {
16479           p = "r%Z1\t%1";
16480           break;
16481         }
16482
16483       if (MEM_P (operands[2]))
16484         {
16485           p = "%Z2\t%2";
16486           break;
16487         }
16488
16489       if (find_regno_note (insn, REG_DEAD, REGNO (operands[2])))
16490         {
16491 #if SYSV386_COMPAT
16492           /* The SystemV/386 SVR3.2 assembler, and probably all AT&T
16493              derived assemblers, confusingly reverse the direction of
16494              the operation for fsub{r} and fdiv{r} when the
16495              destination register is not st(0).  The Intel assembler
16496              doesn't have this brain damage.  Read !SYSV386_COMPAT to
16497              figure out what the hardware really does.  */
16498           if (STACK_TOP_P (operands[0]))
16499             p = "{p\t%0, %2|rp\t%2, %0}";
16500           else
16501             p = "{rp\t%2, %0|p\t%0, %2}";
16502 #else
16503           if (STACK_TOP_P (operands[0]))
16504             /* As above for fmul/fadd, we can't store to st(0).  */
16505             p = "rp\t{%0, %2|%2, %0}";  /* st(1) = st(0) op st(1); pop */
16506           else
16507             p = "p\t{%2, %0|%0, %2}";   /* st(r1) = st(r1) op st(0); pop */
16508 #endif
16509           break;
16510         }
16511
16512       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
16513         {
16514 #if SYSV386_COMPAT
16515           if (STACK_TOP_P (operands[0]))
16516             p = "{rp\t%0, %1|p\t%1, %0}";
16517           else
16518             p = "{p\t%1, %0|rp\t%0, %1}";
16519 #else
16520           if (STACK_TOP_P (operands[0]))
16521             p = "p\t{%0, %1|%1, %0}";   /* st(1) = st(1) op st(0); pop */
16522           else
16523             p = "rp\t{%1, %0|%0, %1}";  /* st(r2) = st(0) op st(r2); pop */
16524 #endif
16525           break;
16526         }
16527
16528       if (STACK_TOP_P (operands[0]))
16529         {
16530           if (STACK_TOP_P (operands[1]))
16531             p = "\t{%y2, %0|%0, %y2}";  /* st(0) = st(0) op st(r2) */
16532           else
16533             p = "r\t{%y1, %0|%0, %y1}"; /* st(0) = st(r1) op st(0) */
16534           break;
16535         }
16536       else if (STACK_TOP_P (operands[1]))
16537         {
16538 #if SYSV386_COMPAT
16539           p = "{\t%1, %0|r\t%0, %1}";
16540 #else
16541           p = "r\t{%1, %0|%0, %1}";     /* st(r2) = st(0) op st(r2) */
16542 #endif
16543         }
16544       else
16545         {
16546 #if SYSV386_COMPAT
16547           p = "{r\t%2, %0|\t%0, %2}";
16548 #else
16549           p = "\t{%2, %0|%0, %2}";      /* st(r1) = st(r1) op st(0) */
16550 #endif
16551         }
16552       break;
16553
16554     default:
16555       gcc_unreachable ();
16556     }
16557
16558   strcat (buf, p);
16559   return buf;
16560 }
16561
16562 /* Check if a 256bit AVX register is referenced inside of EXP.   */
16563
16564 static bool
16565 ix86_check_avx256_register (const_rtx exp)
16566 {
16567   if (GET_CODE (exp) == SUBREG)
16568     exp = SUBREG_REG (exp);
16569
16570   return (REG_P (exp)
16571           && VALID_AVX256_REG_OR_OI_MODE (GET_MODE (exp)));
16572 }
16573
16574 /* Return needed mode for entity in optimize_mode_switching pass.  */
16575
16576 static int
16577 ix86_avx_u128_mode_needed (rtx_insn *insn)
16578 {
16579   if (CALL_P (insn))
16580     {
16581       rtx link;
16582
16583       /* Needed mode is set to AVX_U128_CLEAN if there are
16584          no 256bit modes used in function arguments.  */
16585       for (link = CALL_INSN_FUNCTION_USAGE (insn);
16586            link;
16587            link = XEXP (link, 1))
16588         {
16589           if (GET_CODE (XEXP (link, 0)) == USE)
16590             {
16591               rtx arg = XEXP (XEXP (link, 0), 0);
16592
16593               if (ix86_check_avx256_register (arg))
16594                 return AVX_U128_DIRTY;
16595             }
16596         }
16597
16598       return AVX_U128_CLEAN;
16599     }
16600
16601   /* Require DIRTY mode if a 256bit AVX register is referenced.  Hardware
16602      changes state only when a 256bit register is written to, but we need
16603      to prevent the compiler from moving optimal insertion point above
16604      eventual read from 256bit register.  */
16605   subrtx_iterator::array_type array;
16606   FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
16607     if (ix86_check_avx256_register (*iter))
16608       return AVX_U128_DIRTY;
16609
16610   return AVX_U128_ANY;
16611 }
16612
16613 /* Return mode that i387 must be switched into
16614    prior to the execution of insn.  */
16615
16616 static int
16617 ix86_i387_mode_needed (int entity, rtx_insn *insn)
16618 {
16619   enum attr_i387_cw mode;
16620
16621   /* The mode UNINITIALIZED is used to store control word after a
16622      function call or ASM pattern.  The mode ANY specify that function
16623      has no requirements on the control word and make no changes in the
16624      bits we are interested in.  */
16625
16626   if (CALL_P (insn)
16627       || (NONJUMP_INSN_P (insn)
16628           && (asm_noperands (PATTERN (insn)) >= 0
16629               || GET_CODE (PATTERN (insn)) == ASM_INPUT)))
16630     return I387_CW_UNINITIALIZED;
16631
16632   if (recog_memoized (insn) < 0)
16633     return I387_CW_ANY;
16634
16635   mode = get_attr_i387_cw (insn);
16636
16637   switch (entity)
16638     {
16639     case I387_TRUNC:
16640       if (mode == I387_CW_TRUNC)
16641         return mode;
16642       break;
16643
16644     case I387_FLOOR:
16645       if (mode == I387_CW_FLOOR)
16646         return mode;
16647       break;
16648
16649     case I387_CEIL:
16650       if (mode == I387_CW_CEIL)
16651         return mode;
16652       break;
16653
16654     case I387_MASK_PM:
16655       if (mode == I387_CW_MASK_PM)
16656         return mode;
16657       break;
16658
16659     default:
16660       gcc_unreachable ();
16661     }
16662
16663   return I387_CW_ANY;
16664 }
16665
16666 /* Return mode that entity must be switched into
16667    prior to the execution of insn.  */
16668
16669 static int
16670 ix86_mode_needed (int entity, rtx_insn *insn)
16671 {
16672   switch (entity)
16673     {
16674     case AVX_U128:
16675       return ix86_avx_u128_mode_needed (insn);
16676     case I387_TRUNC:
16677     case I387_FLOOR:
16678     case I387_CEIL:
16679     case I387_MASK_PM:
16680       return ix86_i387_mode_needed (entity, insn);
16681     default:
16682       gcc_unreachable ();
16683     }
16684   return 0;
16685 }
16686
16687 /* Check if a 256bit AVX register is referenced in stores.   */
16688  
16689 static void
16690 ix86_check_avx256_stores (rtx dest, const_rtx, void *data)
16691  {
16692    if (ix86_check_avx256_register (dest))
16693     {
16694       bool *used = (bool *) data;
16695       *used = true;
16696     }
16697  } 
16698
16699 /* Calculate mode of upper 128bit AVX registers after the insn.  */
16700
16701 static int
16702 ix86_avx_u128_mode_after (int mode, rtx_insn *insn)
16703 {
16704   rtx pat = PATTERN (insn);
16705
16706   if (vzeroupper_operation (pat, VOIDmode)
16707       || vzeroall_operation (pat, VOIDmode))
16708     return AVX_U128_CLEAN;
16709
16710   /* We know that state is clean after CALL insn if there are no
16711      256bit registers used in the function return register.  */
16712   if (CALL_P (insn))
16713     {
16714       bool avx_reg256_found = false;
16715       note_stores (pat, ix86_check_avx256_stores, &avx_reg256_found);
16716
16717       return avx_reg256_found ? AVX_U128_DIRTY : AVX_U128_CLEAN;
16718     }
16719
16720   /* Otherwise, return current mode.  Remember that if insn
16721      references AVX 256bit registers, the mode was already changed
16722      to DIRTY from MODE_NEEDED.  */
16723   return mode;
16724 }
16725
16726 /* Return the mode that an insn results in.  */
16727
16728 int
16729 ix86_mode_after (int entity, int mode, rtx_insn *insn)
16730 {
16731   switch (entity)
16732     {
16733     case AVX_U128:
16734       return ix86_avx_u128_mode_after (mode, insn);
16735     case I387_TRUNC:
16736     case I387_FLOOR:
16737     case I387_CEIL:
16738     case I387_MASK_PM:
16739       return mode;
16740     default:
16741       gcc_unreachable ();
16742     }
16743 }
16744
16745 static int
16746 ix86_avx_u128_mode_entry (void)
16747 {
16748   tree arg;
16749
16750   /* Entry mode is set to AVX_U128_DIRTY if there are
16751      256bit modes used in function arguments.  */
16752   for (arg = DECL_ARGUMENTS (current_function_decl); arg;
16753        arg = TREE_CHAIN (arg))
16754     {
16755       rtx incoming = DECL_INCOMING_RTL (arg);
16756
16757       if (incoming && ix86_check_avx256_register (incoming))
16758         return AVX_U128_DIRTY;
16759     }
16760
16761   return AVX_U128_CLEAN;
16762 }
16763
16764 /* Return a mode that ENTITY is assumed to be
16765    switched to at function entry.  */
16766
16767 static int
16768 ix86_mode_entry (int entity)
16769 {
16770   switch (entity)
16771     {
16772     case AVX_U128:
16773       return ix86_avx_u128_mode_entry ();
16774     case I387_TRUNC:
16775     case I387_FLOOR:
16776     case I387_CEIL:
16777     case I387_MASK_PM:
16778       return I387_CW_ANY;
16779     default:
16780       gcc_unreachable ();
16781     }
16782 }
16783
16784 static int
16785 ix86_avx_u128_mode_exit (void)
16786 {
16787   rtx reg = crtl->return_rtx;
16788
16789   /* Exit mode is set to AVX_U128_DIRTY if there are
16790      256bit modes used in the function return register.  */
16791   if (reg && ix86_check_avx256_register (reg))
16792     return AVX_U128_DIRTY;
16793
16794   return AVX_U128_CLEAN;
16795 }
16796
16797 /* Return a mode that ENTITY is assumed to be
16798    switched to at function exit.  */
16799
16800 static int
16801 ix86_mode_exit (int entity)
16802 {
16803   switch (entity)
16804     {
16805     case AVX_U128:
16806       return ix86_avx_u128_mode_exit ();
16807     case I387_TRUNC:
16808     case I387_FLOOR:
16809     case I387_CEIL:
16810     case I387_MASK_PM:
16811       return I387_CW_ANY;
16812     default:
16813       gcc_unreachable ();
16814     }
16815 }
16816
16817 static int
16818 ix86_mode_priority (int, int n)
16819 {
16820   return n;
16821 }
16822
16823 /* Output code to initialize control word copies used by trunc?f?i and
16824    rounding patterns.  CURRENT_MODE is set to current control word,
16825    while NEW_MODE is set to new control word.  */
16826
16827 static void
16828 emit_i387_cw_initialization (int mode)
16829 {
16830   rtx stored_mode = assign_386_stack_local (HImode, SLOT_CW_STORED);
16831   rtx new_mode;
16832
16833   enum ix86_stack_slot slot;
16834
16835   rtx reg = gen_reg_rtx (HImode);
16836
16837   emit_insn (gen_x86_fnstcw_1 (stored_mode));
16838   emit_move_insn (reg, copy_rtx (stored_mode));
16839
16840   if (TARGET_64BIT || TARGET_PARTIAL_REG_STALL
16841       || optimize_insn_for_size_p ())
16842     {
16843       switch (mode)
16844         {
16845         case I387_CW_TRUNC:
16846           /* round toward zero (truncate) */
16847           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0c00)));
16848           slot = SLOT_CW_TRUNC;
16849           break;
16850
16851         case I387_CW_FLOOR:
16852           /* round down toward -oo */
16853           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
16854           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0400)));
16855           slot = SLOT_CW_FLOOR;
16856           break;
16857
16858         case I387_CW_CEIL:
16859           /* round up toward +oo */
16860           emit_insn (gen_andhi3 (reg, reg, GEN_INT (~0x0c00)));
16861           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0800)));
16862           slot = SLOT_CW_CEIL;
16863           break;
16864
16865         case I387_CW_MASK_PM:
16866           /* mask precision exception for nearbyint() */
16867           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
16868           slot = SLOT_CW_MASK_PM;
16869           break;
16870
16871         default:
16872           gcc_unreachable ();
16873         }
16874     }
16875   else
16876     {
16877       switch (mode)
16878         {
16879         case I387_CW_TRUNC:
16880           /* round toward zero (truncate) */
16881           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0xc)));
16882           slot = SLOT_CW_TRUNC;
16883           break;
16884
16885         case I387_CW_FLOOR:
16886           /* round down toward -oo */
16887           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x4)));
16888           slot = SLOT_CW_FLOOR;
16889           break;
16890
16891         case I387_CW_CEIL:
16892           /* round up toward +oo */
16893           emit_insn (gen_movsi_insv_1 (reg, GEN_INT (0x8)));
16894           slot = SLOT_CW_CEIL;
16895           break;
16896
16897         case I387_CW_MASK_PM:
16898           /* mask precision exception for nearbyint() */
16899           emit_insn (gen_iorhi3 (reg, reg, GEN_INT (0x0020)));
16900           slot = SLOT_CW_MASK_PM;
16901           break;
16902
16903         default:
16904           gcc_unreachable ();
16905         }
16906     }
16907
16908   gcc_assert (slot < MAX_386_STACK_LOCALS);
16909
16910   new_mode = assign_386_stack_local (HImode, slot);
16911   emit_move_insn (new_mode, reg);
16912 }
16913
16914 /* Emit vzeroupper.  */
16915
16916 void
16917 ix86_avx_emit_vzeroupper (HARD_REG_SET regs_live)
16918 {
16919   int i;
16920
16921   /* Cancel automatic vzeroupper insertion if there are
16922      live call-saved SSE registers at the insertion point.  */
16923
16924   for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
16925     if (TEST_HARD_REG_BIT (regs_live, i) && !call_used_regs[i])
16926       return;
16927
16928   if (TARGET_64BIT)
16929     for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
16930       if (TEST_HARD_REG_BIT (regs_live, i) && !call_used_regs[i])
16931         return;
16932
16933   emit_insn (gen_avx_vzeroupper ());
16934 }
16935
16936 /* Generate one or more insns to set ENTITY to MODE.  */
16937
16938 /* Generate one or more insns to set ENTITY to MODE.  HARD_REG_LIVE
16939    is the set of hard registers live at the point where the insn(s)
16940    are to be inserted.  */
16941
16942 static void
16943 ix86_emit_mode_set (int entity, int mode, int prev_mode ATTRIBUTE_UNUSED,
16944                     HARD_REG_SET regs_live)
16945 {
16946   switch (entity)
16947     {
16948     case AVX_U128:
16949       if (mode == AVX_U128_CLEAN)
16950         ix86_avx_emit_vzeroupper (regs_live);
16951       break;
16952     case I387_TRUNC:
16953     case I387_FLOOR:
16954     case I387_CEIL:
16955     case I387_MASK_PM:
16956       if (mode != I387_CW_ANY
16957           && mode != I387_CW_UNINITIALIZED)
16958         emit_i387_cw_initialization (mode);
16959       break;
16960     default:
16961       gcc_unreachable ();
16962     }
16963 }
16964
16965 /* Output code for INSN to convert a float to a signed int.  OPERANDS
16966    are the insn operands.  The output may be [HSD]Imode and the input
16967    operand may be [SDX]Fmode.  */
16968
16969 const char *
16970 output_fix_trunc (rtx_insn *insn, rtx *operands, bool fisttp)
16971 {
16972   int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
16973   int dimode_p = GET_MODE (operands[0]) == DImode;
16974   int round_mode = get_attr_i387_cw (insn);
16975
16976   /* Jump through a hoop or two for DImode, since the hardware has no
16977      non-popping instruction.  We used to do this a different way, but
16978      that was somewhat fragile and broke with post-reload splitters.  */
16979   if ((dimode_p || fisttp) && !stack_top_dies)
16980     output_asm_insn ("fld\t%y1", operands);
16981
16982   gcc_assert (STACK_TOP_P (operands[1]));
16983   gcc_assert (MEM_P (operands[0]));
16984   gcc_assert (GET_MODE (operands[1]) != TFmode);
16985
16986   if (fisttp)
16987       output_asm_insn ("fisttp%Z0\t%0", operands);
16988   else
16989     {
16990       if (round_mode != I387_CW_ANY)
16991         output_asm_insn ("fldcw\t%3", operands);
16992       if (stack_top_dies || dimode_p)
16993         output_asm_insn ("fistp%Z0\t%0", operands);
16994       else
16995         output_asm_insn ("fist%Z0\t%0", operands);
16996       if (round_mode != I387_CW_ANY)
16997         output_asm_insn ("fldcw\t%2", operands);
16998     }
16999
17000   return "";
17001 }
17002
17003 /* Output code for x87 ffreep insn.  The OPNO argument, which may only
17004    have the values zero or one, indicates the ffreep insn's operand
17005    from the OPERANDS array.  */
17006
17007 static const char *
17008 output_387_ffreep (rtx *operands ATTRIBUTE_UNUSED, int opno)
17009 {
17010   if (TARGET_USE_FFREEP)
17011 #ifdef HAVE_AS_IX86_FFREEP
17012     return opno ? "ffreep\t%y1" : "ffreep\t%y0";
17013 #else
17014     {
17015       static char retval[32];
17016       int regno = REGNO (operands[opno]);
17017
17018       gcc_assert (STACK_REGNO_P (regno));
17019
17020       regno -= FIRST_STACK_REG;
17021
17022       snprintf (retval, sizeof (retval), ASM_SHORT "0xc%ddf", regno);
17023       return retval;
17024     }
17025 #endif
17026
17027   return opno ? "fstp\t%y1" : "fstp\t%y0";
17028 }
17029
17030
17031 /* Output code for INSN to compare OPERANDS.  EFLAGS_P is 1 when fcomi
17032    should be used.  UNORDERED_P is true when fucom should be used.  */
17033
17034 const char *
17035 output_fp_compare (rtx insn, rtx *operands, bool eflags_p, bool unordered_p)
17036 {
17037   int stack_top_dies;
17038   rtx cmp_op0, cmp_op1;
17039   int is_sse = SSE_REG_P (operands[0]) || SSE_REG_P (operands[1]);
17040
17041   if (eflags_p)
17042     {
17043       cmp_op0 = operands[0];
17044       cmp_op1 = operands[1];
17045     }
17046   else
17047     {
17048       cmp_op0 = operands[1];
17049       cmp_op1 = operands[2];
17050     }
17051
17052   if (is_sse)
17053     {
17054       if (GET_MODE (operands[0]) == SFmode)
17055         if (unordered_p)
17056           return "%vucomiss\t{%1, %0|%0, %1}";
17057         else
17058           return "%vcomiss\t{%1, %0|%0, %1}";
17059       else
17060         if (unordered_p)
17061           return "%vucomisd\t{%1, %0|%0, %1}";
17062         else
17063           return "%vcomisd\t{%1, %0|%0, %1}";
17064     }
17065
17066   gcc_assert (STACK_TOP_P (cmp_op0));
17067
17068   stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0;
17069
17070   if (cmp_op1 == CONST0_RTX (GET_MODE (cmp_op1)))
17071     {
17072       if (stack_top_dies)
17073         {
17074           output_asm_insn ("ftst\n\tfnstsw\t%0", operands);
17075           return output_387_ffreep (operands, 1);
17076         }
17077       else
17078         return "ftst\n\tfnstsw\t%0";
17079     }
17080
17081   if (STACK_REG_P (cmp_op1)
17082       && stack_top_dies
17083       && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1))
17084       && REGNO (cmp_op1) != FIRST_STACK_REG)
17085     {
17086       /* If both the top of the 387 stack dies, and the other operand
17087          is also a stack register that dies, then this must be a
17088          `fcompp' float compare */
17089
17090       if (eflags_p)
17091         {
17092           /* There is no double popping fcomi variant.  Fortunately,
17093              eflags is immune from the fstp's cc clobbering.  */
17094           if (unordered_p)
17095             output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands);
17096           else
17097             output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands);
17098           return output_387_ffreep (operands, 0);
17099         }
17100       else
17101         {
17102           if (unordered_p)
17103             return "fucompp\n\tfnstsw\t%0";
17104           else
17105             return "fcompp\n\tfnstsw\t%0";
17106         }
17107     }
17108   else
17109     {
17110       /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies.  */
17111
17112       static const char * const alt[16] =
17113       {
17114         "fcom%Z2\t%y2\n\tfnstsw\t%0",
17115         "fcomp%Z2\t%y2\n\tfnstsw\t%0",
17116         "fucom%Z2\t%y2\n\tfnstsw\t%0",
17117         "fucomp%Z2\t%y2\n\tfnstsw\t%0",
17118
17119         "ficom%Z2\t%y2\n\tfnstsw\t%0",
17120         "ficomp%Z2\t%y2\n\tfnstsw\t%0",
17121         NULL,
17122         NULL,
17123
17124         "fcomi\t{%y1, %0|%0, %y1}",
17125         "fcomip\t{%y1, %0|%0, %y1}",
17126         "fucomi\t{%y1, %0|%0, %y1}",
17127         "fucomip\t{%y1, %0|%0, %y1}",
17128
17129         NULL,
17130         NULL,
17131         NULL,
17132         NULL
17133       };
17134
17135       int mask;
17136       const char *ret;
17137
17138       mask  = eflags_p << 3;
17139       mask |= (GET_MODE_CLASS (GET_MODE (cmp_op1)) == MODE_INT) << 2;
17140       mask |= unordered_p << 1;
17141       mask |= stack_top_dies;
17142
17143       gcc_assert (mask < 16);
17144       ret = alt[mask];
17145       gcc_assert (ret);
17146
17147       return ret;
17148     }
17149 }
17150
17151 void
17152 ix86_output_addr_vec_elt (FILE *file, int value)
17153 {
17154   const char *directive = ASM_LONG;
17155
17156 #ifdef ASM_QUAD
17157   if (TARGET_LP64)
17158     directive = ASM_QUAD;
17159 #else
17160   gcc_assert (!TARGET_64BIT);
17161 #endif
17162
17163   fprintf (file, "%s%s%d\n", directive, LPREFIX, value);
17164 }
17165
17166 void
17167 ix86_output_addr_diff_elt (FILE *file, int value, int rel)
17168 {
17169   const char *directive = ASM_LONG;
17170
17171 #ifdef ASM_QUAD
17172   if (TARGET_64BIT && CASE_VECTOR_MODE == DImode)
17173     directive = ASM_QUAD;
17174 #else
17175   gcc_assert (!TARGET_64BIT);
17176 #endif
17177   /* We can't use @GOTOFF for text labels on VxWorks; see gotoff_operand.  */
17178   if (TARGET_64BIT || TARGET_VXWORKS_RTP)
17179     fprintf (file, "%s%s%d-%s%d\n",
17180              directive, LPREFIX, value, LPREFIX, rel);
17181   else if (HAVE_AS_GOTOFF_IN_DATA)
17182     fprintf (file, ASM_LONG "%s%d@GOTOFF\n", LPREFIX, value);
17183 #if TARGET_MACHO
17184   else if (TARGET_MACHO)
17185     {
17186       fprintf (file, ASM_LONG "%s%d-", LPREFIX, value);
17187       machopic_output_function_base_name (file);
17188       putc ('\n', file);
17189     }
17190 #endif
17191   else
17192     asm_fprintf (file, ASM_LONG "%U%s+[.-%s%d]\n",
17193                  GOT_SYMBOL_NAME, LPREFIX, value);
17194 }
17195 \f
17196 /* Generate either "mov $0, reg" or "xor reg, reg", as appropriate
17197    for the target.  */
17198
17199 void
17200 ix86_expand_clear (rtx dest)
17201 {
17202   rtx tmp;
17203
17204   /* We play register width games, which are only valid after reload.  */
17205   gcc_assert (reload_completed);
17206
17207   /* Avoid HImode and its attendant prefix byte.  */
17208   if (GET_MODE_SIZE (GET_MODE (dest)) < 4)
17209     dest = gen_rtx_REG (SImode, REGNO (dest));
17210   tmp = gen_rtx_SET (VOIDmode, dest, const0_rtx);
17211
17212   if (!TARGET_USE_MOV0 || optimize_insn_for_size_p ())
17213     {
17214       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
17215       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
17216     }
17217
17218   emit_insn (tmp);
17219 }
17220
17221 /* X is an unchanging MEM.  If it is a constant pool reference, return
17222    the constant pool rtx, else NULL.  */
17223
17224 rtx
17225 maybe_get_pool_constant (rtx x)
17226 {
17227   x = ix86_delegitimize_address (XEXP (x, 0));
17228
17229   if (GET_CODE (x) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (x))
17230     return get_pool_constant (x);
17231
17232   return NULL_RTX;
17233 }
17234
17235 void
17236 ix86_expand_move (machine_mode mode, rtx operands[])
17237 {
17238   rtx op0, op1;
17239   enum tls_model model;
17240
17241   op0 = operands[0];
17242   op1 = operands[1];
17243
17244   if (GET_CODE (op1) == SYMBOL_REF)
17245     {
17246       rtx tmp;
17247
17248       model = SYMBOL_REF_TLS_MODEL (op1);
17249       if (model)
17250         {
17251           op1 = legitimize_tls_address (op1, model, true);
17252           op1 = force_operand (op1, op0);
17253           if (op1 == op0)
17254             return;
17255           op1 = convert_to_mode (mode, op1, 1);
17256         }
17257       else if ((tmp = legitimize_pe_coff_symbol (op1, false)) != NULL_RTX)
17258         op1 = tmp;
17259     }
17260   else if (GET_CODE (op1) == CONST
17261            && GET_CODE (XEXP (op1, 0)) == PLUS
17262            && GET_CODE (XEXP (XEXP (op1, 0), 0)) == SYMBOL_REF)
17263     {
17264       rtx addend = XEXP (XEXP (op1, 0), 1);
17265       rtx symbol = XEXP (XEXP (op1, 0), 0);
17266       rtx tmp;
17267
17268       model = SYMBOL_REF_TLS_MODEL (symbol);
17269       if (model)
17270         tmp = legitimize_tls_address (symbol, model, true);
17271       else
17272         tmp = legitimize_pe_coff_symbol (symbol, true);
17273
17274       if (tmp)
17275         {
17276           tmp = force_operand (tmp, NULL);
17277           tmp = expand_simple_binop (Pmode, PLUS, tmp, addend,
17278                                      op0, 1, OPTAB_DIRECT);
17279           if (tmp == op0)
17280             return;
17281           op1 = convert_to_mode (mode, tmp, 1);
17282         }
17283     }
17284
17285   if ((flag_pic || MACHOPIC_INDIRECT)
17286       && symbolic_operand (op1, mode))
17287     {
17288       if (TARGET_MACHO && !TARGET_64BIT)
17289         {
17290 #if TARGET_MACHO
17291           /* dynamic-no-pic */
17292           if (MACHOPIC_INDIRECT)
17293             {
17294               rtx temp = ((reload_in_progress
17295                            || ((op0 && REG_P (op0))
17296                                && mode == Pmode))
17297                           ? op0 : gen_reg_rtx (Pmode));
17298               op1 = machopic_indirect_data_reference (op1, temp);
17299               if (MACHOPIC_PURE)
17300                 op1 = machopic_legitimize_pic_address (op1, mode,
17301                                                        temp == op1 ? 0 : temp);
17302             }
17303           if (op0 != op1 && GET_CODE (op0) != MEM)
17304             {
17305               rtx insn = gen_rtx_SET (VOIDmode, op0, op1);
17306               emit_insn (insn);
17307               return;
17308             }
17309           if (GET_CODE (op0) == MEM)
17310             op1 = force_reg (Pmode, op1);
17311           else
17312             {
17313               rtx temp = op0;
17314               if (GET_CODE (temp) != REG)
17315                 temp = gen_reg_rtx (Pmode);
17316               temp = legitimize_pic_address (op1, temp);
17317               if (temp == op0)
17318             return;
17319               op1 = temp;
17320             }
17321       /* dynamic-no-pic */
17322 #endif
17323         }
17324       else
17325         {
17326           if (MEM_P (op0))
17327             op1 = force_reg (mode, op1);
17328           else if (!(TARGET_64BIT && x86_64_movabs_operand (op1, DImode)))
17329             {
17330               rtx reg = can_create_pseudo_p () ? NULL_RTX : op0;
17331               op1 = legitimize_pic_address (op1, reg);
17332               if (op0 == op1)
17333                 return;
17334               op1 = convert_to_mode (mode, op1, 1);
17335             }
17336         }
17337     }
17338   else
17339     {
17340       if (MEM_P (op0)
17341           && (PUSH_ROUNDING (GET_MODE_SIZE (mode)) != GET_MODE_SIZE (mode)
17342               || !push_operand (op0, mode))
17343           && MEM_P (op1))
17344         op1 = force_reg (mode, op1);
17345
17346       if (push_operand (op0, mode)
17347           && ! general_no_elim_operand (op1, mode))
17348         op1 = copy_to_mode_reg (mode, op1);
17349
17350       /* Force large constants in 64bit compilation into register
17351          to get them CSEed.  */
17352       if (can_create_pseudo_p ()
17353           && (mode == DImode) && TARGET_64BIT
17354           && immediate_operand (op1, mode)
17355           && !x86_64_zext_immediate_operand (op1, VOIDmode)
17356           && !register_operand (op0, mode)
17357           && optimize)
17358         op1 = copy_to_mode_reg (mode, op1);
17359
17360       if (can_create_pseudo_p ()
17361           && FLOAT_MODE_P (mode)
17362           && GET_CODE (op1) == CONST_DOUBLE)
17363         {
17364           /* If we are loading a floating point constant to a register,
17365              force the value to memory now, since we'll get better code
17366              out the back end.  */
17367
17368           op1 = validize_mem (force_const_mem (mode, op1));
17369           if (!register_operand (op0, mode))
17370             {
17371               rtx temp = gen_reg_rtx (mode);
17372               emit_insn (gen_rtx_SET (VOIDmode, temp, op1));
17373               emit_move_insn (op0, temp);
17374               return;
17375             }
17376         }
17377     }
17378
17379   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
17380 }
17381
17382 void
17383 ix86_expand_vector_move (machine_mode mode, rtx operands[])
17384 {
17385   rtx op0 = operands[0], op1 = operands[1];
17386   unsigned int align = GET_MODE_ALIGNMENT (mode);
17387
17388   if (push_operand (op0, VOIDmode))
17389     op0 = emit_move_resolve_push (mode, op0);
17390
17391   /* Force constants other than zero into memory.  We do not know how
17392      the instructions used to build constants modify the upper 64 bits
17393      of the register, once we have that information we may be able
17394      to handle some of them more efficiently.  */
17395   if (can_create_pseudo_p ()
17396       && register_operand (op0, mode)
17397       && (CONSTANT_P (op1)
17398           || (GET_CODE (op1) == SUBREG
17399               && CONSTANT_P (SUBREG_REG (op1))))
17400       && !standard_sse_constant_p (op1))
17401     op1 = validize_mem (force_const_mem (mode, op1));
17402
17403   /* We need to check memory alignment for SSE mode since attribute
17404      can make operands unaligned.  */
17405   if (can_create_pseudo_p ()
17406       && SSE_REG_MODE_P (mode)
17407       && ((MEM_P (op0) && (MEM_ALIGN (op0) < align))
17408           || (MEM_P (op1) && (MEM_ALIGN (op1) < align))))
17409     {
17410       rtx tmp[2];
17411
17412       /* ix86_expand_vector_move_misalign() does not like constants ... */
17413       if (CONSTANT_P (op1)
17414           || (GET_CODE (op1) == SUBREG
17415               && CONSTANT_P (SUBREG_REG (op1))))
17416         op1 = validize_mem (force_const_mem (mode, op1));
17417
17418       /* ... nor both arguments in memory.  */
17419       if (!register_operand (op0, mode)
17420           && !register_operand (op1, mode))
17421         op1 = force_reg (mode, op1);
17422
17423       tmp[0] = op0; tmp[1] = op1;
17424       ix86_expand_vector_move_misalign (mode, tmp);
17425       return;
17426     }
17427
17428   /* Make operand1 a register if it isn't already.  */
17429   if (can_create_pseudo_p ()
17430       && !register_operand (op0, mode)
17431       && !register_operand (op1, mode))
17432     {
17433       emit_move_insn (op0, force_reg (GET_MODE (op0), op1));
17434       return;
17435     }
17436
17437   emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
17438 }
17439
17440 /* Split 32-byte AVX unaligned load and store if needed.  */
17441
17442 static void
17443 ix86_avx256_split_vector_move_misalign (rtx op0, rtx op1)
17444 {
17445   rtx m;
17446   rtx (*extract) (rtx, rtx, rtx);
17447   rtx (*load_unaligned) (rtx, rtx);
17448   rtx (*store_unaligned) (rtx, rtx);
17449   machine_mode mode;
17450
17451   switch (GET_MODE (op0))
17452     {
17453     default:
17454       gcc_unreachable ();
17455     case V32QImode:
17456       extract = gen_avx_vextractf128v32qi;
17457       load_unaligned = gen_avx_loaddquv32qi;
17458       store_unaligned = gen_avx_storedquv32qi;
17459       mode = V16QImode;
17460       break;
17461     case V8SFmode:
17462       extract = gen_avx_vextractf128v8sf;
17463       load_unaligned = gen_avx_loadups256;
17464       store_unaligned = gen_avx_storeups256;
17465       mode = V4SFmode;
17466       break;
17467     case V4DFmode:
17468       extract = gen_avx_vextractf128v4df;
17469       load_unaligned = gen_avx_loadupd256;
17470       store_unaligned = gen_avx_storeupd256;
17471       mode = V2DFmode;
17472       break;
17473     }
17474
17475   if (MEM_P (op1))
17476     {
17477       if (TARGET_AVX256_SPLIT_UNALIGNED_LOAD
17478           && optimize_insn_for_speed_p ())
17479         {
17480           rtx r = gen_reg_rtx (mode);
17481           m = adjust_address (op1, mode, 0);
17482           emit_move_insn (r, m);
17483           m = adjust_address (op1, mode, 16);
17484           r = gen_rtx_VEC_CONCAT (GET_MODE (op0), r, m);
17485           emit_move_insn (op0, r);
17486         }
17487       /* Normal *mov<mode>_internal pattern will handle
17488          unaligned loads just fine if misaligned_operand
17489          is true, and without the UNSPEC it can be combined
17490          with arithmetic instructions.  */
17491       else if (misaligned_operand (op1, GET_MODE (op1)))
17492         emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
17493       else
17494         emit_insn (load_unaligned (op0, op1));
17495     }
17496   else if (MEM_P (op0))
17497     {
17498       if (TARGET_AVX256_SPLIT_UNALIGNED_STORE
17499           && optimize_insn_for_speed_p ())
17500         {
17501           m = adjust_address (op0, mode, 0);
17502           emit_insn (extract (m, op1, const0_rtx));
17503           m = adjust_address (op0, mode, 16);
17504           emit_insn (extract (m, op1, const1_rtx));
17505         }
17506       else
17507         emit_insn (store_unaligned (op0, op1));
17508     }
17509   else
17510     gcc_unreachable ();
17511 }
17512
17513 /* Implement the movmisalign patterns for SSE.  Non-SSE modes go
17514    straight to ix86_expand_vector_move.  */
17515 /* Code generation for scalar reg-reg moves of single and double precision data:
17516      if (x86_sse_partial_reg_dependency == true | x86_sse_split_regs == true)
17517        movaps reg, reg
17518      else
17519        movss reg, reg
17520      if (x86_sse_partial_reg_dependency == true)
17521        movapd reg, reg
17522      else
17523        movsd reg, reg
17524
17525    Code generation for scalar loads of double precision data:
17526      if (x86_sse_split_regs == true)
17527        movlpd mem, reg      (gas syntax)
17528      else
17529        movsd mem, reg
17530
17531    Code generation for unaligned packed loads of single precision data
17532    (x86_sse_unaligned_move_optimal overrides x86_sse_partial_reg_dependency):
17533      if (x86_sse_unaligned_move_optimal)
17534        movups mem, reg
17535
17536      if (x86_sse_partial_reg_dependency == true)
17537        {
17538          xorps  reg, reg
17539          movlps mem, reg
17540          movhps mem+8, reg
17541        }
17542      else
17543        {
17544          movlps mem, reg
17545          movhps mem+8, reg
17546        }
17547
17548    Code generation for unaligned packed loads of double precision data
17549    (x86_sse_unaligned_move_optimal overrides x86_sse_split_regs):
17550      if (x86_sse_unaligned_move_optimal)
17551        movupd mem, reg
17552
17553      if (x86_sse_split_regs == true)
17554        {
17555          movlpd mem, reg
17556          movhpd mem+8, reg
17557        }
17558      else
17559        {
17560          movsd  mem, reg
17561          movhpd mem+8, reg
17562        }
17563  */
17564
17565 void
17566 ix86_expand_vector_move_misalign (machine_mode mode, rtx operands[])
17567 {
17568   rtx op0, op1, orig_op0 = NULL_RTX, m;
17569   rtx (*load_unaligned) (rtx, rtx);
17570   rtx (*store_unaligned) (rtx, rtx);
17571
17572   op0 = operands[0];
17573   op1 = operands[1];
17574
17575   if (GET_MODE_SIZE (mode) == 64)
17576     {
17577       switch (GET_MODE_CLASS (mode))
17578         {
17579         case MODE_VECTOR_INT:
17580         case MODE_INT:
17581           if (GET_MODE (op0) != V16SImode)
17582             {
17583               if (!MEM_P (op0))
17584                 {
17585                   orig_op0 = op0;
17586                   op0 = gen_reg_rtx (V16SImode);
17587                 }
17588               else
17589                 op0 = gen_lowpart (V16SImode, op0);
17590             }
17591           op1 = gen_lowpart (V16SImode, op1);
17592           /* FALLTHRU */
17593
17594         case MODE_VECTOR_FLOAT:
17595           switch (GET_MODE (op0))
17596             {
17597             default:
17598               gcc_unreachable ();
17599             case V16SImode:
17600               load_unaligned = gen_avx512f_loaddquv16si;
17601               store_unaligned = gen_avx512f_storedquv16si;
17602               break;
17603             case V16SFmode:
17604               load_unaligned = gen_avx512f_loadups512;
17605               store_unaligned = gen_avx512f_storeups512;
17606               break;
17607             case V8DFmode:
17608               load_unaligned = gen_avx512f_loadupd512;
17609               store_unaligned = gen_avx512f_storeupd512;
17610               break;
17611             }
17612
17613           if (MEM_P (op1))
17614             emit_insn (load_unaligned (op0, op1));
17615           else if (MEM_P (op0))
17616             emit_insn (store_unaligned (op0, op1));
17617           else
17618             gcc_unreachable ();
17619           if (orig_op0)
17620             emit_move_insn (orig_op0, gen_lowpart (GET_MODE (orig_op0), op0));
17621           break;
17622
17623         default:
17624           gcc_unreachable ();
17625         }
17626
17627       return;
17628     }
17629
17630   if (TARGET_AVX
17631       && GET_MODE_SIZE (mode) == 32)
17632     {
17633       switch (GET_MODE_CLASS (mode))
17634         {
17635         case MODE_VECTOR_INT:
17636         case MODE_INT:
17637           if (GET_MODE (op0) != V32QImode)
17638             {
17639               if (!MEM_P (op0))
17640                 {
17641                   orig_op0 = op0;
17642                   op0 = gen_reg_rtx (V32QImode);
17643                 }
17644               else
17645                 op0 = gen_lowpart (V32QImode, op0);
17646             }
17647           op1 = gen_lowpart (V32QImode, op1);
17648           /* FALLTHRU */
17649
17650         case MODE_VECTOR_FLOAT:
17651           ix86_avx256_split_vector_move_misalign (op0, op1);
17652           if (orig_op0)
17653             emit_move_insn (orig_op0, gen_lowpart (GET_MODE (orig_op0), op0));
17654           break;
17655
17656         default:
17657           gcc_unreachable ();
17658         }
17659
17660       return;
17661     }
17662
17663   if (MEM_P (op1))
17664     {
17665       /* Normal *mov<mode>_internal pattern will handle
17666          unaligned loads just fine if misaligned_operand
17667          is true, and without the UNSPEC it can be combined
17668          with arithmetic instructions.  */
17669       if (TARGET_AVX
17670           && (GET_MODE_CLASS (mode) == MODE_VECTOR_INT
17671               || GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
17672           && misaligned_operand (op1, GET_MODE (op1)))
17673         emit_insn (gen_rtx_SET (VOIDmode, op0, op1));
17674       /* ??? If we have typed data, then it would appear that using
17675          movdqu is the only way to get unaligned data loaded with
17676          integer type.  */
17677       else if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
17678         {
17679           if (GET_MODE (op0) != V16QImode)
17680             {
17681               orig_op0 = op0;
17682               op0 = gen_reg_rtx (V16QImode);
17683             }
17684           op1 = gen_lowpart (V16QImode, op1);
17685           /* We will eventually emit movups based on insn attributes.  */
17686           emit_insn (gen_sse2_loaddquv16qi (op0, op1));
17687           if (orig_op0)
17688             emit_move_insn (orig_op0, gen_lowpart (GET_MODE (orig_op0), op0));
17689         }
17690       else if (TARGET_SSE2 && mode == V2DFmode)
17691         {
17692           rtx zero;
17693
17694           if (TARGET_AVX
17695               || TARGET_SSE_UNALIGNED_LOAD_OPTIMAL
17696               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17697               || optimize_insn_for_size_p ())
17698             {
17699               /* We will eventually emit movups based on insn attributes.  */
17700               emit_insn (gen_sse2_loadupd (op0, op1));
17701               return;
17702             }
17703
17704           /* When SSE registers are split into halves, we can avoid
17705              writing to the top half twice.  */
17706           if (TARGET_SSE_SPLIT_REGS)
17707             {
17708               emit_clobber (op0);
17709               zero = op0;
17710             }
17711           else
17712             {
17713               /* ??? Not sure about the best option for the Intel chips.
17714                  The following would seem to satisfy; the register is
17715                  entirely cleared, breaking the dependency chain.  We
17716                  then store to the upper half, with a dependency depth
17717                  of one.  A rumor has it that Intel recommends two movsd
17718                  followed by an unpacklpd, but this is unconfirmed.  And
17719                  given that the dependency depth of the unpacklpd would
17720                  still be one, I'm not sure why this would be better.  */
17721               zero = CONST0_RTX (V2DFmode);
17722             }
17723
17724           m = adjust_address (op1, DFmode, 0);
17725           emit_insn (gen_sse2_loadlpd (op0, zero, m));
17726           m = adjust_address (op1, DFmode, 8);
17727           emit_insn (gen_sse2_loadhpd (op0, op0, m));
17728         }
17729       else
17730         {
17731           rtx t;
17732
17733           if (TARGET_AVX
17734               || TARGET_SSE_UNALIGNED_LOAD_OPTIMAL
17735               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17736               || optimize_insn_for_size_p ())
17737             {
17738               if (GET_MODE (op0) != V4SFmode)
17739                 {
17740                   orig_op0 = op0;
17741                   op0 = gen_reg_rtx (V4SFmode);
17742                 }
17743               op1 = gen_lowpart (V4SFmode, op1);
17744               emit_insn (gen_sse_loadups (op0, op1));
17745               if (orig_op0)
17746                 emit_move_insn (orig_op0,
17747                                 gen_lowpart (GET_MODE (orig_op0), op0));
17748               return;
17749             }
17750
17751           if (mode != V4SFmode)
17752             t = gen_reg_rtx (V4SFmode);
17753           else
17754             t = op0;
17755             
17756           if (TARGET_SSE_PARTIAL_REG_DEPENDENCY)
17757             emit_move_insn (t, CONST0_RTX (V4SFmode));
17758           else
17759             emit_clobber (t);
17760
17761           m = adjust_address (op1, V2SFmode, 0);
17762           emit_insn (gen_sse_loadlps (t, t, m));
17763           m = adjust_address (op1, V2SFmode, 8);
17764           emit_insn (gen_sse_loadhps (t, t, m));
17765           if (mode != V4SFmode)
17766             emit_move_insn (op0, gen_lowpart (mode, t));
17767         }
17768     }
17769   else if (MEM_P (op0))
17770     {
17771       if (TARGET_SSE2 && GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
17772         {
17773           op0 = gen_lowpart (V16QImode, op0);
17774           op1 = gen_lowpart (V16QImode, op1);
17775           /* We will eventually emit movups based on insn attributes.  */
17776           emit_insn (gen_sse2_storedquv16qi (op0, op1));
17777         }
17778       else if (TARGET_SSE2 && mode == V2DFmode)
17779         {
17780           if (TARGET_AVX
17781               || TARGET_SSE_UNALIGNED_STORE_OPTIMAL
17782               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17783               || optimize_insn_for_size_p ())
17784             /* We will eventually emit movups based on insn attributes.  */
17785             emit_insn (gen_sse2_storeupd (op0, op1));
17786           else
17787             {
17788               m = adjust_address (op0, DFmode, 0);
17789               emit_insn (gen_sse2_storelpd (m, op1));
17790               m = adjust_address (op0, DFmode, 8);
17791               emit_insn (gen_sse2_storehpd (m, op1));
17792             }
17793         }
17794       else
17795         {
17796           if (mode != V4SFmode)
17797             op1 = gen_lowpart (V4SFmode, op1);
17798
17799           if (TARGET_AVX
17800               || TARGET_SSE_UNALIGNED_STORE_OPTIMAL
17801               || TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17802               || optimize_insn_for_size_p ())
17803             {
17804               op0 = gen_lowpart (V4SFmode, op0);
17805               emit_insn (gen_sse_storeups (op0, op1));
17806             }
17807           else
17808             {
17809               m = adjust_address (op0, V2SFmode, 0);
17810               emit_insn (gen_sse_storelps (m, op1));
17811               m = adjust_address (op0, V2SFmode, 8);
17812               emit_insn (gen_sse_storehps (m, op1));
17813             }
17814         }
17815     }
17816   else
17817     gcc_unreachable ();
17818 }
17819
17820 /* Helper function of ix86_fixup_binary_operands to canonicalize
17821    operand order.  Returns true if the operands should be swapped.  */
17822
17823 static bool
17824 ix86_swap_binary_operands_p (enum rtx_code code, machine_mode mode,
17825                              rtx operands[])
17826 {
17827   rtx dst = operands[0];
17828   rtx src1 = operands[1];
17829   rtx src2 = operands[2];
17830
17831   /* If the operation is not commutative, we can't do anything.  */
17832   if (GET_RTX_CLASS (code) != RTX_COMM_ARITH)
17833     return false;
17834
17835   /* Highest priority is that src1 should match dst.  */
17836   if (rtx_equal_p (dst, src1))
17837     return false;
17838   if (rtx_equal_p (dst, src2))
17839     return true;
17840
17841   /* Next highest priority is that immediate constants come second.  */
17842   if (immediate_operand (src2, mode))
17843     return false;
17844   if (immediate_operand (src1, mode))
17845     return true;
17846
17847   /* Lowest priority is that memory references should come second.  */
17848   if (MEM_P (src2))
17849     return false;
17850   if (MEM_P (src1))
17851     return true;
17852
17853   return false;
17854 }
17855
17856
17857 /* Fix up OPERANDS to satisfy ix86_binary_operator_ok.  Return the
17858    destination to use for the operation.  If different from the true
17859    destination in operands[0], a copy operation will be required.  */
17860
17861 rtx
17862 ix86_fixup_binary_operands (enum rtx_code code, machine_mode mode,
17863                             rtx operands[])
17864 {
17865   rtx dst = operands[0];
17866   rtx src1 = operands[1];
17867   rtx src2 = operands[2];
17868
17869   /* Canonicalize operand order.  */
17870   if (ix86_swap_binary_operands_p (code, mode, operands))
17871     {
17872       /* It is invalid to swap operands of different modes.  */
17873       gcc_assert (GET_MODE (src1) == GET_MODE (src2));
17874
17875       std::swap (src1, src2);
17876     }
17877
17878   /* Both source operands cannot be in memory.  */
17879   if (MEM_P (src1) && MEM_P (src2))
17880     {
17881       /* Optimization: Only read from memory once.  */
17882       if (rtx_equal_p (src1, src2))
17883         {
17884           src2 = force_reg (mode, src2);
17885           src1 = src2;
17886         }
17887       else if (rtx_equal_p (dst, src1))
17888         src2 = force_reg (mode, src2);
17889       else
17890         src1 = force_reg (mode, src1);
17891     }
17892
17893   /* If the destination is memory, and we do not have matching source
17894      operands, do things in registers.  */
17895   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
17896     dst = gen_reg_rtx (mode);
17897
17898   /* Source 1 cannot be a constant.  */
17899   if (CONSTANT_P (src1))
17900     src1 = force_reg (mode, src1);
17901
17902   /* Source 1 cannot be a non-matching memory.  */
17903   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
17904     src1 = force_reg (mode, src1);
17905
17906   /* Improve address combine.  */
17907   if (code == PLUS
17908       && GET_MODE_CLASS (mode) == MODE_INT
17909       && MEM_P (src2))
17910     src2 = force_reg (mode, src2);
17911
17912   operands[1] = src1;
17913   operands[2] = src2;
17914   return dst;
17915 }
17916
17917 /* Similarly, but assume that the destination has already been
17918    set up properly.  */
17919
17920 void
17921 ix86_fixup_binary_operands_no_copy (enum rtx_code code,
17922                                     machine_mode mode, rtx operands[])
17923 {
17924   rtx dst = ix86_fixup_binary_operands (code, mode, operands);
17925   gcc_assert (dst == operands[0]);
17926 }
17927
17928 /* Attempt to expand a binary operator.  Make the expansion closer to the
17929    actual machine, then just general_operand, which will allow 3 separate
17930    memory references (one output, two input) in a single insn.  */
17931
17932 void
17933 ix86_expand_binary_operator (enum rtx_code code, machine_mode mode,
17934                              rtx operands[])
17935 {
17936   rtx src1, src2, dst, op, clob;
17937
17938   dst = ix86_fixup_binary_operands (code, mode, operands);
17939   src1 = operands[1];
17940   src2 = operands[2];
17941
17942  /* Emit the instruction.  */
17943
17944   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2));
17945   if (reload_in_progress)
17946     {
17947       /* Reload doesn't know about the flags register, and doesn't know that
17948          it doesn't want to clobber it.  We can only do this with PLUS.  */
17949       gcc_assert (code == PLUS);
17950       emit_insn (op);
17951     }
17952   else if (reload_completed
17953            && code == PLUS
17954            && !rtx_equal_p (dst, src1))
17955     {
17956       /* This is going to be an LEA; avoid splitting it later.  */
17957       emit_insn (op);
17958     }
17959   else
17960     {
17961       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
17962       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
17963     }
17964
17965   /* Fix up the destination if needed.  */
17966   if (dst != operands[0])
17967     emit_move_insn (operands[0], dst);
17968 }
17969
17970 /* Expand vector logical operation CODE (AND, IOR, XOR) in MODE with
17971    the given OPERANDS.  */
17972
17973 void
17974 ix86_expand_vector_logical_operator (enum rtx_code code, machine_mode mode,
17975                                      rtx operands[])
17976 {
17977   rtx op1 = NULL_RTX, op2 = NULL_RTX;
17978   if (GET_CODE (operands[1]) == SUBREG)
17979     {
17980       op1 = operands[1];
17981       op2 = operands[2];
17982     }
17983   else if (GET_CODE (operands[2]) == SUBREG)
17984     {
17985       op1 = operands[2];
17986       op2 = operands[1];
17987     }
17988   /* Optimize (__m128i) d | (__m128i) e and similar code
17989      when d and e are float vectors into float vector logical
17990      insn.  In C/C++ without using intrinsics there is no other way
17991      to express vector logical operation on float vectors than
17992      to cast them temporarily to integer vectors.  */
17993   if (op1
17994       && !TARGET_SSE_PACKED_SINGLE_INSN_OPTIMAL
17995       && ((GET_CODE (op2) == SUBREG || GET_CODE (op2) == CONST_VECTOR))
17996       && GET_MODE_CLASS (GET_MODE (SUBREG_REG (op1))) == MODE_VECTOR_FLOAT
17997       && GET_MODE_SIZE (GET_MODE (SUBREG_REG (op1))) == GET_MODE_SIZE (mode)
17998       && SUBREG_BYTE (op1) == 0
17999       && (GET_CODE (op2) == CONST_VECTOR
18000           || (GET_MODE (SUBREG_REG (op1)) == GET_MODE (SUBREG_REG (op2))
18001               && SUBREG_BYTE (op2) == 0))
18002       && can_create_pseudo_p ())
18003     {
18004       rtx dst;
18005       switch (GET_MODE (SUBREG_REG (op1)))
18006         {
18007         case V4SFmode:
18008         case V8SFmode:
18009         case V16SFmode:
18010         case V2DFmode:
18011         case V4DFmode:
18012         case V8DFmode:
18013           dst = gen_reg_rtx (GET_MODE (SUBREG_REG (op1)));
18014           if (GET_CODE (op2) == CONST_VECTOR)
18015             {
18016               op2 = gen_lowpart (GET_MODE (dst), op2);
18017               op2 = force_reg (GET_MODE (dst), op2);
18018             }
18019           else
18020             {
18021               op1 = operands[1];
18022               op2 = SUBREG_REG (operands[2]);
18023               if (!nonimmediate_operand (op2, GET_MODE (dst)))
18024                 op2 = force_reg (GET_MODE (dst), op2);
18025             }
18026           op1 = SUBREG_REG (op1);
18027           if (!nonimmediate_operand (op1, GET_MODE (dst)))
18028             op1 = force_reg (GET_MODE (dst), op1);
18029           emit_insn (gen_rtx_SET (VOIDmode, dst,
18030                                   gen_rtx_fmt_ee (code, GET_MODE (dst),
18031                                                   op1, op2)));
18032           emit_move_insn (operands[0], gen_lowpart (mode, dst));
18033           return;
18034         default:
18035           break;
18036         }
18037     }
18038   if (!nonimmediate_operand (operands[1], mode))
18039     operands[1] = force_reg (mode, operands[1]);
18040   if (!nonimmediate_operand (operands[2], mode))
18041     operands[2] = force_reg (mode, operands[2]);
18042   ix86_fixup_binary_operands_no_copy (code, mode, operands);
18043   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
18044                           gen_rtx_fmt_ee (code, mode, operands[1],
18045                                           operands[2])));
18046 }
18047
18048 /* Return TRUE or FALSE depending on whether the binary operator meets the
18049    appropriate constraints.  */
18050
18051 bool
18052 ix86_binary_operator_ok (enum rtx_code code, machine_mode mode,
18053                          rtx operands[3])
18054 {
18055   rtx dst = operands[0];
18056   rtx src1 = operands[1];
18057   rtx src2 = operands[2];
18058
18059   /* Both source operands cannot be in memory.  */
18060   if (MEM_P (src1) && MEM_P (src2))
18061     return false;
18062
18063   /* Canonicalize operand order for commutative operators.  */
18064   if (ix86_swap_binary_operands_p (code, mode, operands))
18065     std::swap (src1, src2);
18066
18067   /* If the destination is memory, we must have a matching source operand.  */
18068   if (MEM_P (dst) && !rtx_equal_p (dst, src1))
18069       return false;
18070
18071   /* Source 1 cannot be a constant.  */
18072   if (CONSTANT_P (src1))
18073     return false;
18074
18075   /* Source 1 cannot be a non-matching memory.  */
18076   if (MEM_P (src1) && !rtx_equal_p (dst, src1))
18077     /* Support "andhi/andsi/anddi" as a zero-extending move.  */
18078     return (code == AND
18079             && (mode == HImode
18080                 || mode == SImode
18081                 || (TARGET_64BIT && mode == DImode))
18082             && satisfies_constraint_L (src2));
18083
18084   return true;
18085 }
18086
18087 /* Attempt to expand a unary operator.  Make the expansion closer to the
18088    actual machine, then just general_operand, which will allow 2 separate
18089    memory references (one output, one input) in a single insn.  */
18090
18091 void
18092 ix86_expand_unary_operator (enum rtx_code code, machine_mode mode,
18093                             rtx operands[])
18094 {
18095   bool matching_memory = false;
18096   rtx src, dst, op, clob;
18097
18098   dst = operands[0];
18099   src = operands[1];
18100
18101   /* If the destination is memory, and we do not have matching source
18102      operands, do things in registers.  */
18103   if (MEM_P (dst))
18104     {
18105       if (rtx_equal_p (dst, src))
18106         matching_memory = true;
18107       else
18108         dst = gen_reg_rtx (mode);
18109     }
18110
18111   /* When source operand is memory, destination must match.  */
18112   if (MEM_P (src) && !matching_memory)
18113     src = force_reg (mode, src);
18114
18115   /* Emit the instruction.  */
18116
18117   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src));
18118   if (reload_in_progress || code == NOT)
18119     {
18120       /* Reload doesn't know about the flags register, and doesn't know that
18121          it doesn't want to clobber it.  */
18122       gcc_assert (code == NOT);
18123       emit_insn (op);
18124     }
18125   else
18126     {
18127       clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
18128       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
18129     }
18130
18131   /* Fix up the destination if needed.  */
18132   if (dst != operands[0])
18133     emit_move_insn (operands[0], dst);
18134 }
18135
18136 /* Split 32bit/64bit divmod with 8bit unsigned divmod if dividend and
18137    divisor are within the range [0-255].  */
18138
18139 void
18140 ix86_split_idivmod (machine_mode mode, rtx operands[],
18141                     bool signed_p)
18142 {
18143   rtx_code_label *end_label, *qimode_label;
18144   rtx insn, div, mod;
18145   rtx scratch, tmp0, tmp1, tmp2;
18146   rtx (*gen_divmod4_1) (rtx, rtx, rtx, rtx);
18147   rtx (*gen_zero_extend) (rtx, rtx);
18148   rtx (*gen_test_ccno_1) (rtx, rtx);
18149
18150   switch (mode)
18151     {
18152     case SImode:
18153       gen_divmod4_1 = signed_p ? gen_divmodsi4_1 : gen_udivmodsi4_1;
18154       gen_test_ccno_1 = gen_testsi_ccno_1;
18155       gen_zero_extend = gen_zero_extendqisi2;
18156       break;
18157     case DImode:
18158       gen_divmod4_1 = signed_p ? gen_divmoddi4_1 : gen_udivmoddi4_1;
18159       gen_test_ccno_1 = gen_testdi_ccno_1;
18160       gen_zero_extend = gen_zero_extendqidi2;
18161       break;
18162     default:
18163       gcc_unreachable ();
18164     }
18165
18166   end_label = gen_label_rtx ();
18167   qimode_label = gen_label_rtx ();
18168
18169   scratch = gen_reg_rtx (mode);
18170
18171   /* Use 8bit unsigned divimod if dividend and divisor are within
18172      the range [0-255].  */
18173   emit_move_insn (scratch, operands[2]);
18174   scratch = expand_simple_binop (mode, IOR, scratch, operands[3],
18175                                  scratch, 1, OPTAB_DIRECT);
18176   emit_insn (gen_test_ccno_1 (scratch, GEN_INT (-0x100)));
18177   tmp0 = gen_rtx_REG (CCNOmode, FLAGS_REG);
18178   tmp0 = gen_rtx_EQ (VOIDmode, tmp0, const0_rtx);
18179   tmp0 = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp0,
18180                                gen_rtx_LABEL_REF (VOIDmode, qimode_label),
18181                                pc_rtx);
18182   insn = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp0));
18183   predict_jump (REG_BR_PROB_BASE * 50 / 100);
18184   JUMP_LABEL (insn) = qimode_label;
18185
18186   /* Generate original signed/unsigned divimod.  */
18187   div = gen_divmod4_1 (operands[0], operands[1],
18188                        operands[2], operands[3]);
18189   emit_insn (div);
18190
18191   /* Branch to the end.  */
18192   emit_jump_insn (gen_jump (end_label));
18193   emit_barrier ();
18194
18195   /* Generate 8bit unsigned divide.  */
18196   emit_label (qimode_label);
18197   /* Don't use operands[0] for result of 8bit divide since not all
18198      registers support QImode ZERO_EXTRACT.  */
18199   tmp0 = simplify_gen_subreg (HImode, scratch, mode, 0);
18200   tmp1 = simplify_gen_subreg (HImode, operands[2], mode, 0);
18201   tmp2 = simplify_gen_subreg (QImode, operands[3], mode, 0);
18202   emit_insn (gen_udivmodhiqi3 (tmp0, tmp1, tmp2));
18203
18204   if (signed_p)
18205     {
18206       div = gen_rtx_DIV (SImode, operands[2], operands[3]);
18207       mod = gen_rtx_MOD (SImode, operands[2], operands[3]);
18208     }
18209   else
18210     {
18211       div = gen_rtx_UDIV (SImode, operands[2], operands[3]);
18212       mod = gen_rtx_UMOD (SImode, operands[2], operands[3]);
18213     }
18214
18215   /* Extract remainder from AH.  */
18216   tmp1 = gen_rtx_ZERO_EXTRACT (mode, tmp0, GEN_INT (8), GEN_INT (8));
18217   if (REG_P (operands[1]))
18218     insn = emit_move_insn (operands[1], tmp1);
18219   else
18220     {
18221       /* Need a new scratch register since the old one has result
18222          of 8bit divide.  */
18223       scratch = gen_reg_rtx (mode);
18224       emit_move_insn (scratch, tmp1);
18225       insn = emit_move_insn (operands[1], scratch);
18226     }
18227   set_unique_reg_note (insn, REG_EQUAL, mod);
18228
18229   /* Zero extend quotient from AL.  */
18230   tmp1 = gen_lowpart (QImode, tmp0);
18231   insn = emit_insn (gen_zero_extend (operands[0], tmp1));
18232   set_unique_reg_note (insn, REG_EQUAL, div);
18233
18234   emit_label (end_label);
18235 }
18236
18237 #define LEA_MAX_STALL (3)
18238 #define LEA_SEARCH_THRESHOLD (LEA_MAX_STALL << 1)
18239
18240 /* Increase given DISTANCE in half-cycles according to
18241    dependencies between PREV and NEXT instructions.
18242    Add 1 half-cycle if there is no dependency and
18243    go to next cycle if there is some dependecy.  */
18244
18245 static unsigned int
18246 increase_distance (rtx_insn *prev, rtx_insn *next, unsigned int distance)
18247 {
18248   df_ref def, use;
18249
18250   if (!prev || !next)
18251     return distance + (distance & 1) + 2;
18252
18253   if (!DF_INSN_USES (next) || !DF_INSN_DEFS (prev))
18254     return distance + 1;
18255
18256   FOR_EACH_INSN_USE (use, next)
18257     FOR_EACH_INSN_DEF (def, prev)
18258       if (!DF_REF_IS_ARTIFICIAL (def)
18259           && DF_REF_REGNO (use) == DF_REF_REGNO (def))
18260         return distance + (distance & 1) + 2;
18261
18262   return distance + 1;
18263 }
18264
18265 /* Function checks if instruction INSN defines register number
18266    REGNO1 or REGNO2.  */
18267
18268 static bool
18269 insn_defines_reg (unsigned int regno1, unsigned int regno2,
18270                   rtx insn)
18271 {
18272   df_ref def;
18273
18274   FOR_EACH_INSN_DEF (def, insn)
18275     if (DF_REF_REG_DEF_P (def)
18276         && !DF_REF_IS_ARTIFICIAL (def)
18277         && (regno1 == DF_REF_REGNO (def)
18278             || regno2 == DF_REF_REGNO (def)))
18279       return true;
18280
18281   return false;
18282 }
18283
18284 /* Function checks if instruction INSN uses register number
18285    REGNO as a part of address expression.  */
18286
18287 static bool
18288 insn_uses_reg_mem (unsigned int regno, rtx insn)
18289 {
18290   df_ref use;
18291
18292   FOR_EACH_INSN_USE (use, insn)
18293     if (DF_REF_REG_MEM_P (use) && regno == DF_REF_REGNO (use))
18294       return true;
18295
18296   return false;
18297 }
18298
18299 /* Search backward for non-agu definition of register number REGNO1
18300    or register number REGNO2 in basic block starting from instruction
18301    START up to head of basic block or instruction INSN.
18302
18303    Function puts true value into *FOUND var if definition was found
18304    and false otherwise.
18305
18306    Distance in half-cycles between START and found instruction or head
18307    of BB is added to DISTANCE and returned.  */
18308
18309 static int
18310 distance_non_agu_define_in_bb (unsigned int regno1, unsigned int regno2,
18311                                rtx_insn *insn, int distance,
18312                                rtx_insn *start, bool *found)
18313 {
18314   basic_block bb = start ? BLOCK_FOR_INSN (start) : NULL;
18315   rtx_insn *prev = start;
18316   rtx_insn *next = NULL;
18317
18318   *found = false;
18319
18320   while (prev
18321          && prev != insn
18322          && distance < LEA_SEARCH_THRESHOLD)
18323     {
18324       if (NONDEBUG_INSN_P (prev) && NONJUMP_INSN_P (prev))
18325         {
18326           distance = increase_distance (prev, next, distance);
18327           if (insn_defines_reg (regno1, regno2, prev))
18328             {
18329               if (recog_memoized (prev) < 0
18330                   || get_attr_type (prev) != TYPE_LEA)
18331                 {
18332                   *found = true;
18333                   return distance;
18334                 }
18335             }
18336
18337           next = prev;
18338         }
18339       if (prev == BB_HEAD (bb))
18340         break;
18341
18342       prev = PREV_INSN (prev);
18343     }
18344
18345   return distance;
18346 }
18347
18348 /* Search backward for non-agu definition of register number REGNO1
18349    or register number REGNO2 in INSN's basic block until
18350    1. Pass LEA_SEARCH_THRESHOLD instructions, or
18351    2. Reach neighbour BBs boundary, or
18352    3. Reach agu definition.
18353    Returns the distance between the non-agu definition point and INSN.
18354    If no definition point, returns -1.  */
18355
18356 static int
18357 distance_non_agu_define (unsigned int regno1, unsigned int regno2,
18358                          rtx_insn *insn)
18359 {
18360   basic_block bb = BLOCK_FOR_INSN (insn);
18361   int distance = 0;
18362   bool found = false;
18363
18364   if (insn != BB_HEAD (bb))
18365     distance = distance_non_agu_define_in_bb (regno1, regno2, insn,
18366                                               distance, PREV_INSN (insn),
18367                                               &found);
18368
18369   if (!found && distance < LEA_SEARCH_THRESHOLD)
18370     {
18371       edge e;
18372       edge_iterator ei;
18373       bool simple_loop = false;
18374
18375       FOR_EACH_EDGE (e, ei, bb->preds)
18376         if (e->src == bb)
18377           {
18378             simple_loop = true;
18379             break;
18380           }
18381
18382       if (simple_loop)
18383         distance = distance_non_agu_define_in_bb (regno1, regno2,
18384                                                   insn, distance,
18385                                                   BB_END (bb), &found);
18386       else
18387         {
18388           int shortest_dist = -1;
18389           bool found_in_bb = false;
18390
18391           FOR_EACH_EDGE (e, ei, bb->preds)
18392             {
18393               int bb_dist
18394                 = distance_non_agu_define_in_bb (regno1, regno2,
18395                                                  insn, distance,
18396                                                  BB_END (e->src),
18397                                                  &found_in_bb);
18398               if (found_in_bb)
18399                 {
18400                   if (shortest_dist < 0)
18401                     shortest_dist = bb_dist;
18402                   else if (bb_dist > 0)
18403                     shortest_dist = MIN (bb_dist, shortest_dist);
18404
18405                   found = true;
18406                 }
18407             }
18408
18409           distance = shortest_dist;
18410         }
18411     }
18412
18413   /* get_attr_type may modify recog data.  We want to make sure
18414      that recog data is valid for instruction INSN, on which
18415      distance_non_agu_define is called.  INSN is unchanged here.  */
18416   extract_insn_cached (insn);
18417
18418   if (!found)
18419     return -1;
18420
18421   return distance >> 1;
18422 }
18423
18424 /* Return the distance in half-cycles between INSN and the next
18425    insn that uses register number REGNO in memory address added
18426    to DISTANCE.  Return -1 if REGNO0 is set.
18427
18428    Put true value into *FOUND if register usage was found and
18429    false otherwise.
18430    Put true value into *REDEFINED if register redefinition was
18431    found and false otherwise.  */
18432
18433 static int
18434 distance_agu_use_in_bb (unsigned int regno,
18435                         rtx_insn *insn, int distance, rtx_insn *start,
18436                         bool *found, bool *redefined)
18437 {
18438   basic_block bb = NULL;
18439   rtx_insn *next = start;
18440   rtx_insn *prev = NULL;
18441
18442   *found = false;
18443   *redefined = false;
18444
18445   if (start != NULL_RTX)
18446     {
18447       bb = BLOCK_FOR_INSN (start);
18448       if (start != BB_HEAD (bb))
18449         /* If insn and start belong to the same bb, set prev to insn,
18450            so the call to increase_distance will increase the distance
18451            between insns by 1.  */
18452         prev = insn;
18453     }
18454
18455   while (next
18456          && next != insn
18457          && distance < LEA_SEARCH_THRESHOLD)
18458     {
18459       if (NONDEBUG_INSN_P (next) && NONJUMP_INSN_P (next))
18460         {
18461           distance = increase_distance(prev, next, distance);
18462           if (insn_uses_reg_mem (regno, next))
18463             {
18464               /* Return DISTANCE if OP0 is used in memory
18465                  address in NEXT.  */
18466               *found = true;
18467               return distance;
18468             }
18469
18470           if (insn_defines_reg (regno, INVALID_REGNUM, next))
18471             {
18472               /* Return -1 if OP0 is set in NEXT.  */
18473               *redefined = true;
18474               return -1;
18475             }
18476
18477           prev = next;
18478         }
18479
18480       if (next == BB_END (bb))
18481         break;
18482
18483       next = NEXT_INSN (next);
18484     }
18485
18486   return distance;
18487 }
18488
18489 /* Return the distance between INSN and the next insn that uses
18490    register number REGNO0 in memory address.  Return -1 if no such
18491    a use is found within LEA_SEARCH_THRESHOLD or REGNO0 is set.  */
18492
18493 static int
18494 distance_agu_use (unsigned int regno0, rtx_insn *insn)
18495 {
18496   basic_block bb = BLOCK_FOR_INSN (insn);
18497   int distance = 0;
18498   bool found = false;
18499   bool redefined = false;
18500
18501   if (insn != BB_END (bb))
18502     distance = distance_agu_use_in_bb (regno0, insn, distance,
18503                                        NEXT_INSN (insn),
18504                                        &found, &redefined);
18505
18506   if (!found && !redefined && distance < LEA_SEARCH_THRESHOLD)
18507     {
18508       edge e;
18509       edge_iterator ei;
18510       bool simple_loop = false;
18511
18512       FOR_EACH_EDGE (e, ei, bb->succs)
18513         if (e->dest == bb)
18514           {
18515             simple_loop = true;
18516             break;
18517           }
18518
18519       if (simple_loop)
18520         distance = distance_agu_use_in_bb (regno0, insn,
18521                                            distance, BB_HEAD (bb),
18522                                            &found, &redefined);
18523       else
18524         {
18525           int shortest_dist = -1;
18526           bool found_in_bb = false;
18527           bool redefined_in_bb = false;
18528
18529           FOR_EACH_EDGE (e, ei, bb->succs)
18530             {
18531               int bb_dist
18532                 = distance_agu_use_in_bb (regno0, insn,
18533                                           distance, BB_HEAD (e->dest),
18534                                           &found_in_bb, &redefined_in_bb);
18535               if (found_in_bb)
18536                 {
18537                   if (shortest_dist < 0)
18538                     shortest_dist = bb_dist;
18539                   else if (bb_dist > 0)
18540                     shortest_dist = MIN (bb_dist, shortest_dist);
18541
18542                   found = true;
18543                 }
18544             }
18545
18546           distance = shortest_dist;
18547         }
18548     }
18549
18550   if (!found || redefined)
18551     return -1;
18552
18553   return distance >> 1;
18554 }
18555
18556 /* Define this macro to tune LEA priority vs ADD, it take effect when
18557    there is a dilemma of choicing LEA or ADD
18558    Negative value: ADD is more preferred than LEA
18559    Zero: Netrual
18560    Positive value: LEA is more preferred than ADD*/
18561 #define IX86_LEA_PRIORITY 0
18562
18563 /* Return true if usage of lea INSN has performance advantage
18564    over a sequence of instructions.  Instructions sequence has
18565    SPLIT_COST cycles higher latency than lea latency.  */
18566
18567 static bool
18568 ix86_lea_outperforms (rtx_insn *insn, unsigned int regno0, unsigned int regno1,
18569                       unsigned int regno2, int split_cost, bool has_scale)
18570 {
18571   int dist_define, dist_use;
18572
18573   /* For Silvermont if using a 2-source or 3-source LEA for
18574      non-destructive destination purposes, or due to wanting
18575      ability to use SCALE, the use of LEA is justified.  */
18576   if (TARGET_SILVERMONT || TARGET_INTEL)
18577     {
18578       if (has_scale)
18579         return true;
18580       if (split_cost < 1)
18581         return false;
18582       if (regno0 == regno1 || regno0 == regno2)
18583         return false;
18584       return true;
18585     }
18586
18587   dist_define = distance_non_agu_define (regno1, regno2, insn);
18588   dist_use = distance_agu_use (regno0, insn);
18589
18590   if (dist_define < 0 || dist_define >= LEA_MAX_STALL)
18591     {
18592       /* If there is no non AGU operand definition, no AGU
18593          operand usage and split cost is 0 then both lea
18594          and non lea variants have same priority.  Currently
18595          we prefer lea for 64 bit code and non lea on 32 bit
18596          code.  */
18597       if (dist_use < 0 && split_cost == 0)
18598         return TARGET_64BIT || IX86_LEA_PRIORITY;
18599       else
18600         return true;
18601     }
18602
18603   /* With longer definitions distance lea is more preferable.
18604      Here we change it to take into account splitting cost and
18605      lea priority.  */
18606   dist_define += split_cost + IX86_LEA_PRIORITY;
18607
18608   /* If there is no use in memory addess then we just check
18609      that split cost exceeds AGU stall.  */
18610   if (dist_use < 0)
18611     return dist_define > LEA_MAX_STALL;
18612
18613   /* If this insn has both backward non-agu dependence and forward
18614      agu dependence, the one with short distance takes effect.  */
18615   return dist_define >= dist_use;
18616 }
18617
18618 /* Return true if it is legal to clobber flags by INSN and
18619    false otherwise.  */
18620
18621 static bool
18622 ix86_ok_to_clobber_flags (rtx_insn *insn)
18623 {
18624   basic_block bb = BLOCK_FOR_INSN (insn);
18625   df_ref use;
18626   bitmap live;
18627
18628   while (insn)
18629     {
18630       if (NONDEBUG_INSN_P (insn))
18631         {
18632           FOR_EACH_INSN_USE (use, insn)
18633             if (DF_REF_REG_USE_P (use) && DF_REF_REGNO (use) == FLAGS_REG)
18634               return false;
18635
18636           if (insn_defines_reg (FLAGS_REG, INVALID_REGNUM, insn))
18637             return true;
18638         }
18639
18640       if (insn == BB_END (bb))
18641         break;
18642
18643       insn = NEXT_INSN (insn);
18644     }
18645
18646   live = df_get_live_out(bb);
18647   return !REGNO_REG_SET_P (live, FLAGS_REG);
18648 }
18649
18650 /* Return true if we need to split op0 = op1 + op2 into a sequence of
18651    move and add to avoid AGU stalls.  */
18652
18653 bool
18654 ix86_avoid_lea_for_add (rtx_insn *insn, rtx operands[])
18655 {
18656   unsigned int regno0, regno1, regno2;
18657
18658   /* Check if we need to optimize.  */
18659   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
18660     return false;
18661
18662   /* Check it is correct to split here.  */
18663   if (!ix86_ok_to_clobber_flags(insn))
18664     return false;
18665
18666   regno0 = true_regnum (operands[0]);
18667   regno1 = true_regnum (operands[1]);
18668   regno2 = true_regnum (operands[2]);
18669
18670   /* We need to split only adds with non destructive
18671      destination operand.  */
18672   if (regno0 == regno1 || regno0 == regno2)
18673     return false;
18674   else
18675     return !ix86_lea_outperforms (insn, regno0, regno1, regno2, 1, false);
18676 }
18677
18678 /* Return true if we should emit lea instruction instead of mov
18679    instruction.  */
18680
18681 bool
18682 ix86_use_lea_for_mov (rtx_insn *insn, rtx operands[])
18683 {
18684   unsigned int regno0, regno1;
18685
18686   /* Check if we need to optimize.  */
18687   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
18688     return false;
18689
18690   /* Use lea for reg to reg moves only.  */
18691   if (!REG_P (operands[0]) || !REG_P (operands[1]))
18692     return false;
18693
18694   regno0 = true_regnum (operands[0]);
18695   regno1 = true_regnum (operands[1]);
18696
18697   return ix86_lea_outperforms (insn, regno0, regno1, INVALID_REGNUM, 0, false);
18698 }
18699
18700 /* Return true if we need to split lea into a sequence of
18701    instructions to avoid AGU stalls. */
18702
18703 bool
18704 ix86_avoid_lea_for_addr (rtx_insn *insn, rtx operands[])
18705 {
18706   unsigned int regno0, regno1, regno2;
18707   int split_cost;
18708   struct ix86_address parts;
18709   int ok;
18710
18711   /* Check we need to optimize.  */
18712   if (!TARGET_AVOID_LEA_FOR_ADDR || optimize_function_for_size_p (cfun))
18713     return false;
18714
18715   /* The "at least two components" test below might not catch simple
18716      move or zero extension insns if parts.base is non-NULL and parts.disp
18717      is const0_rtx as the only components in the address, e.g. if the
18718      register is %rbp or %r13.  As this test is much cheaper and moves or
18719      zero extensions are the common case, do this check first.  */
18720   if (REG_P (operands[1])
18721       || (SImode_address_operand (operands[1], VOIDmode)
18722           && REG_P (XEXP (operands[1], 0))))
18723     return false;
18724
18725   /* Check if it is OK to split here.  */
18726   if (!ix86_ok_to_clobber_flags (insn))
18727     return false;
18728
18729   ok = ix86_decompose_address (operands[1], &parts);
18730   gcc_assert (ok);
18731
18732   /* There should be at least two components in the address.  */
18733   if ((parts.base != NULL_RTX) + (parts.index != NULL_RTX)
18734       + (parts.disp != NULL_RTX) + (parts.scale > 1) < 2)
18735     return false;
18736
18737   /* We should not split into add if non legitimate pic
18738      operand is used as displacement. */
18739   if (parts.disp && flag_pic && !LEGITIMATE_PIC_OPERAND_P (parts.disp))
18740     return false;
18741
18742   regno0 = true_regnum (operands[0]) ;
18743   regno1 = INVALID_REGNUM;
18744   regno2 = INVALID_REGNUM;
18745
18746   if (parts.base)
18747     regno1 = true_regnum (parts.base);
18748   if (parts.index)
18749     regno2 = true_regnum (parts.index);
18750
18751   split_cost = 0;
18752
18753   /* Compute how many cycles we will add to execution time
18754      if split lea into a sequence of instructions.  */
18755   if (parts.base || parts.index)
18756     {
18757       /* Have to use mov instruction if non desctructive
18758          destination form is used.  */
18759       if (regno1 != regno0 && regno2 != regno0)
18760         split_cost += 1;
18761
18762       /* Have to add index to base if both exist.  */
18763       if (parts.base && parts.index)
18764         split_cost += 1;
18765
18766       /* Have to use shift and adds if scale is 2 or greater.  */
18767       if (parts.scale > 1)
18768         {
18769           if (regno0 != regno1)
18770             split_cost += 1;
18771           else if (regno2 == regno0)
18772             split_cost += 4;
18773           else
18774             split_cost += parts.scale;
18775         }
18776
18777       /* Have to use add instruction with immediate if
18778          disp is non zero.  */
18779       if (parts.disp && parts.disp != const0_rtx)
18780         split_cost += 1;
18781
18782       /* Subtract the price of lea.  */
18783       split_cost -= 1;
18784     }
18785
18786   return !ix86_lea_outperforms (insn, regno0, regno1, regno2, split_cost,
18787                                 parts.scale > 1);
18788 }
18789
18790 /* Emit x86 binary operand CODE in mode MODE, where the first operand
18791    matches destination.  RTX includes clobber of FLAGS_REG.  */
18792
18793 static void
18794 ix86_emit_binop (enum rtx_code code, machine_mode mode,
18795                  rtx dst, rtx src)
18796 {
18797   rtx op, clob;
18798
18799   op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, dst, src));
18800   clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
18801   
18802   emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob)));
18803 }
18804
18805 /* Return true if regno1 def is nearest to the insn.  */
18806
18807 static bool
18808 find_nearest_reg_def (rtx_insn *insn, int regno1, int regno2)
18809 {
18810   rtx_insn *prev = insn;
18811   rtx_insn *start = BB_HEAD (BLOCK_FOR_INSN (insn));
18812
18813   if (insn == start)
18814     return false;
18815   while (prev && prev != start)
18816     {
18817       if (!INSN_P (prev) || !NONDEBUG_INSN_P (prev))
18818         {
18819           prev = PREV_INSN (prev);
18820           continue;
18821         }
18822       if (insn_defines_reg (regno1, INVALID_REGNUM, prev))
18823         return true;
18824       else if (insn_defines_reg (regno2, INVALID_REGNUM, prev))
18825         return false;
18826       prev = PREV_INSN (prev);
18827     }
18828
18829   /* None of the regs is defined in the bb.  */
18830   return false;
18831 }
18832
18833 /* Split lea instructions into a sequence of instructions
18834    which are executed on ALU to avoid AGU stalls.
18835    It is assumed that it is allowed to clobber flags register
18836    at lea position.  */
18837
18838 void
18839 ix86_split_lea_for_addr (rtx_insn *insn, rtx operands[], machine_mode mode)
18840 {
18841   unsigned int regno0, regno1, regno2;
18842   struct ix86_address parts;
18843   rtx target, tmp;
18844   int ok, adds;
18845
18846   ok = ix86_decompose_address (operands[1], &parts);
18847   gcc_assert (ok);
18848
18849   target = gen_lowpart (mode, operands[0]);
18850
18851   regno0 = true_regnum (target);
18852   regno1 = INVALID_REGNUM;
18853   regno2 = INVALID_REGNUM;
18854
18855   if (parts.base)
18856     {
18857       parts.base = gen_lowpart (mode, parts.base);
18858       regno1 = true_regnum (parts.base);
18859     }
18860
18861   if (parts.index)
18862     {
18863       parts.index = gen_lowpart (mode, parts.index);
18864       regno2 = true_regnum (parts.index);
18865     }
18866
18867   if (parts.disp)
18868     parts.disp = gen_lowpart (mode, parts.disp);
18869
18870   if (parts.scale > 1)
18871     {
18872       /* Case r1 = r1 + ...  */
18873       if (regno1 == regno0)
18874         {
18875           /* If we have a case r1 = r1 + C * r2 then we
18876              should use multiplication which is very
18877              expensive.  Assume cost model is wrong if we
18878              have such case here.  */
18879           gcc_assert (regno2 != regno0);
18880
18881           for (adds = parts.scale; adds > 0; adds--)
18882             ix86_emit_binop (PLUS, mode, target, parts.index);
18883         }
18884       else
18885         {
18886           /* r1 = r2 + r3 * C case.  Need to move r3 into r1.  */
18887           if (regno0 != regno2)
18888             emit_insn (gen_rtx_SET (VOIDmode, target, parts.index));
18889
18890           /* Use shift for scaling.  */
18891           ix86_emit_binop (ASHIFT, mode, target,
18892                            GEN_INT (exact_log2 (parts.scale)));
18893
18894           if (parts.base)
18895             ix86_emit_binop (PLUS, mode, target, parts.base);
18896
18897           if (parts.disp && parts.disp != const0_rtx)
18898             ix86_emit_binop (PLUS, mode, target, parts.disp);
18899         }
18900     }
18901   else if (!parts.base && !parts.index)
18902     {
18903       gcc_assert(parts.disp);
18904       emit_insn (gen_rtx_SET (VOIDmode, target, parts.disp));
18905     }
18906   else
18907     {
18908       if (!parts.base)
18909         {
18910           if (regno0 != regno2)
18911             emit_insn (gen_rtx_SET (VOIDmode, target, parts.index));
18912         }
18913       else if (!parts.index)
18914         {
18915           if (regno0 != regno1)
18916             emit_insn (gen_rtx_SET (VOIDmode, target, parts.base));
18917         }
18918       else
18919         {
18920           if (regno0 == regno1)
18921             tmp = parts.index;
18922           else if (regno0 == regno2)
18923             tmp = parts.base;
18924           else
18925             {
18926               rtx tmp1;
18927
18928               /* Find better operand for SET instruction, depending
18929                  on which definition is farther from the insn.  */
18930               if (find_nearest_reg_def (insn, regno1, regno2))
18931                 tmp = parts.index, tmp1 = parts.base;
18932               else
18933                 tmp = parts.base, tmp1 = parts.index;
18934
18935               emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
18936
18937               if (parts.disp && parts.disp != const0_rtx)
18938                 ix86_emit_binop (PLUS, mode, target, parts.disp);
18939
18940               ix86_emit_binop (PLUS, mode, target, tmp1);
18941               return;
18942             }
18943
18944           ix86_emit_binop (PLUS, mode, target, tmp);
18945         }
18946
18947       if (parts.disp && parts.disp != const0_rtx)
18948         ix86_emit_binop (PLUS, mode, target, parts.disp);
18949     }
18950 }
18951
18952 /* Return true if it is ok to optimize an ADD operation to LEA
18953    operation to avoid flag register consumation.  For most processors,
18954    ADD is faster than LEA.  For the processors like BONNELL, if the
18955    destination register of LEA holds an actual address which will be
18956    used soon, LEA is better and otherwise ADD is better.  */
18957
18958 bool
18959 ix86_lea_for_add_ok (rtx_insn *insn, rtx operands[])
18960 {
18961   unsigned int regno0 = true_regnum (operands[0]);
18962   unsigned int regno1 = true_regnum (operands[1]);
18963   unsigned int regno2 = true_regnum (operands[2]);
18964
18965   /* If a = b + c, (a!=b && a!=c), must use lea form. */
18966   if (regno0 != regno1 && regno0 != regno2)
18967     return true;
18968
18969   if (!TARGET_OPT_AGU || optimize_function_for_size_p (cfun))
18970     return false;
18971
18972   return ix86_lea_outperforms (insn, regno0, regno1, regno2, 0, false);
18973 }
18974
18975 /* Return true if destination reg of SET_BODY is shift count of
18976    USE_BODY.  */
18977
18978 static bool
18979 ix86_dep_by_shift_count_body (const_rtx set_body, const_rtx use_body)
18980 {
18981   rtx set_dest;
18982   rtx shift_rtx;
18983   int i;
18984
18985   /* Retrieve destination of SET_BODY.  */
18986   switch (GET_CODE (set_body))
18987     {
18988     case SET:
18989       set_dest = SET_DEST (set_body);
18990       if (!set_dest || !REG_P (set_dest))
18991         return false;
18992       break;
18993     case PARALLEL:
18994       for (i = XVECLEN (set_body, 0) - 1; i >= 0; i--)
18995         if (ix86_dep_by_shift_count_body (XVECEXP (set_body, 0, i),
18996                                           use_body))
18997           return true;
18998     default:
18999       return false;
19000       break;
19001     }
19002
19003   /* Retrieve shift count of USE_BODY.  */
19004   switch (GET_CODE (use_body))
19005     {
19006     case SET:
19007       shift_rtx = XEXP (use_body, 1);
19008       break;
19009     case PARALLEL:
19010       for (i = XVECLEN (use_body, 0) - 1; i >= 0; i--)
19011         if (ix86_dep_by_shift_count_body (set_body,
19012                                           XVECEXP (use_body, 0, i)))
19013           return true;
19014     default:
19015       return false;
19016       break;
19017     }
19018
19019   if (shift_rtx
19020       && (GET_CODE (shift_rtx) == ASHIFT
19021           || GET_CODE (shift_rtx) == LSHIFTRT
19022           || GET_CODE (shift_rtx) == ASHIFTRT
19023           || GET_CODE (shift_rtx) == ROTATE
19024           || GET_CODE (shift_rtx) == ROTATERT))
19025     {
19026       rtx shift_count = XEXP (shift_rtx, 1);
19027
19028       /* Return true if shift count is dest of SET_BODY.  */
19029       if (REG_P (shift_count))
19030         {
19031           /* Add check since it can be invoked before register
19032              allocation in pre-reload schedule.  */
19033           if (reload_completed
19034               && true_regnum (set_dest) == true_regnum (shift_count))
19035             return true;
19036           else if (REGNO(set_dest) == REGNO(shift_count))
19037             return true;
19038         }
19039     }
19040
19041   return false;
19042 }
19043
19044 /* Return true if destination reg of SET_INSN is shift count of
19045    USE_INSN.  */
19046
19047 bool
19048 ix86_dep_by_shift_count (const_rtx set_insn, const_rtx use_insn)
19049 {
19050   return ix86_dep_by_shift_count_body (PATTERN (set_insn),
19051                                        PATTERN (use_insn));
19052 }
19053
19054 /* Return TRUE or FALSE depending on whether the unary operator meets the
19055    appropriate constraints.  */
19056
19057 bool
19058 ix86_unary_operator_ok (enum rtx_code,
19059                         machine_mode,
19060                         rtx operands[2])
19061 {
19062   /* If one of operands is memory, source and destination must match.  */
19063   if ((MEM_P (operands[0])
19064        || MEM_P (operands[1]))
19065       && ! rtx_equal_p (operands[0], operands[1]))
19066     return false;
19067   return true;
19068 }
19069
19070 /* Return TRUE if the operands to a vec_interleave_{high,low}v2df
19071    are ok, keeping in mind the possible movddup alternative.  */
19072
19073 bool
19074 ix86_vec_interleave_v2df_operator_ok (rtx operands[3], bool high)
19075 {
19076   if (MEM_P (operands[0]))
19077     return rtx_equal_p (operands[0], operands[1 + high]);
19078   if (MEM_P (operands[1]) && MEM_P (operands[2]))
19079     return TARGET_SSE3 && rtx_equal_p (operands[1], operands[2]);
19080   return true;
19081 }
19082
19083 /* Post-reload splitter for converting an SF or DFmode value in an
19084    SSE register into an unsigned SImode.  */
19085
19086 void
19087 ix86_split_convert_uns_si_sse (rtx operands[])
19088 {
19089   machine_mode vecmode;
19090   rtx value, large, zero_or_two31, input, two31, x;
19091
19092   large = operands[1];
19093   zero_or_two31 = operands[2];
19094   input = operands[3];
19095   two31 = operands[4];
19096   vecmode = GET_MODE (large);
19097   value = gen_rtx_REG (vecmode, REGNO (operands[0]));
19098
19099   /* Load up the value into the low element.  We must ensure that the other
19100      elements are valid floats -- zero is the easiest such value.  */
19101   if (MEM_P (input))
19102     {
19103       if (vecmode == V4SFmode)
19104         emit_insn (gen_vec_setv4sf_0 (value, CONST0_RTX (V4SFmode), input));
19105       else
19106         emit_insn (gen_sse2_loadlpd (value, CONST0_RTX (V2DFmode), input));
19107     }
19108   else
19109     {
19110       input = gen_rtx_REG (vecmode, REGNO (input));
19111       emit_move_insn (value, CONST0_RTX (vecmode));
19112       if (vecmode == V4SFmode)
19113         emit_insn (gen_sse_movss (value, value, input));
19114       else
19115         emit_insn (gen_sse2_movsd (value, value, input));
19116     }
19117
19118   emit_move_insn (large, two31);
19119   emit_move_insn (zero_or_two31, MEM_P (two31) ? large : two31);
19120
19121   x = gen_rtx_fmt_ee (LE, vecmode, large, value);
19122   emit_insn (gen_rtx_SET (VOIDmode, large, x));
19123
19124   x = gen_rtx_AND (vecmode, zero_or_two31, large);
19125   emit_insn (gen_rtx_SET (VOIDmode, zero_or_two31, x));
19126
19127   x = gen_rtx_MINUS (vecmode, value, zero_or_two31);
19128   emit_insn (gen_rtx_SET (VOIDmode, value, x));
19129
19130   large = gen_rtx_REG (V4SImode, REGNO (large));
19131   emit_insn (gen_ashlv4si3 (large, large, GEN_INT (31)));
19132
19133   x = gen_rtx_REG (V4SImode, REGNO (value));
19134   if (vecmode == V4SFmode)
19135     emit_insn (gen_fix_truncv4sfv4si2 (x, value));
19136   else
19137     emit_insn (gen_sse2_cvttpd2dq (x, value));
19138   value = x;
19139
19140   emit_insn (gen_xorv4si3 (value, value, large));
19141 }
19142
19143 /* Convert an unsigned DImode value into a DFmode, using only SSE.
19144    Expects the 64-bit DImode to be supplied in a pair of integral
19145    registers.  Requires SSE2; will use SSE3 if available.  For x86_32,
19146    -mfpmath=sse, !optimize_size only.  */
19147
19148 void
19149 ix86_expand_convert_uns_didf_sse (rtx target, rtx input)
19150 {
19151   REAL_VALUE_TYPE bias_lo_rvt, bias_hi_rvt;
19152   rtx int_xmm, fp_xmm;
19153   rtx biases, exponents;
19154   rtx x;
19155
19156   int_xmm = gen_reg_rtx (V4SImode);
19157   if (TARGET_INTER_UNIT_MOVES_TO_VEC)
19158     emit_insn (gen_movdi_to_sse (int_xmm, input));
19159   else if (TARGET_SSE_SPLIT_REGS)
19160     {
19161       emit_clobber (int_xmm);
19162       emit_move_insn (gen_lowpart (DImode, int_xmm), input);
19163     }
19164   else
19165     {
19166       x = gen_reg_rtx (V2DImode);
19167       ix86_expand_vector_init_one_nonzero (false, V2DImode, x, input, 0);
19168       emit_move_insn (int_xmm, gen_lowpart (V4SImode, x));
19169     }
19170
19171   x = gen_rtx_CONST_VECTOR (V4SImode,
19172                             gen_rtvec (4, GEN_INT (0x43300000UL),
19173                                        GEN_INT (0x45300000UL),
19174                                        const0_rtx, const0_rtx));
19175   exponents = validize_mem (force_const_mem (V4SImode, x));
19176
19177   /* int_xmm = {0x45300000UL, fp_xmm/hi, 0x43300000, fp_xmm/lo } */
19178   emit_insn (gen_vec_interleave_lowv4si (int_xmm, int_xmm, exponents));
19179
19180   /* Concatenating (juxtaposing) (0x43300000UL ## fp_value_low_xmm)
19181      yields a valid DF value equal to (0x1.0p52 + double(fp_value_lo_xmm)).
19182      Similarly (0x45300000UL ## fp_value_hi_xmm) yields
19183      (0x1.0p84 + double(fp_value_hi_xmm)).
19184      Note these exponents differ by 32.  */
19185
19186   fp_xmm = copy_to_mode_reg (V2DFmode, gen_lowpart (V2DFmode, int_xmm));
19187
19188   /* Subtract off those 0x1.0p52 and 0x1.0p84 biases, to produce values
19189      in [0,2**32-1] and [0]+[2**32,2**64-1] respectively.  */
19190   real_ldexp (&bias_lo_rvt, &dconst1, 52);
19191   real_ldexp (&bias_hi_rvt, &dconst1, 84);
19192   biases = const_double_from_real_value (bias_lo_rvt, DFmode);
19193   x = const_double_from_real_value (bias_hi_rvt, DFmode);
19194   biases = gen_rtx_CONST_VECTOR (V2DFmode, gen_rtvec (2, biases, x));
19195   biases = validize_mem (force_const_mem (V2DFmode, biases));
19196   emit_insn (gen_subv2df3 (fp_xmm, fp_xmm, biases));
19197
19198   /* Add the upper and lower DFmode values together.  */
19199   if (TARGET_SSE3)
19200     emit_insn (gen_sse3_haddv2df3 (fp_xmm, fp_xmm, fp_xmm));
19201   else
19202     {
19203       x = copy_to_mode_reg (V2DFmode, fp_xmm);
19204       emit_insn (gen_vec_interleave_highv2df (fp_xmm, fp_xmm, fp_xmm));
19205       emit_insn (gen_addv2df3 (fp_xmm, fp_xmm, x));
19206     }
19207
19208   ix86_expand_vector_extract (false, target, fp_xmm, 0);
19209 }
19210
19211 /* Not used, but eases macroization of patterns.  */
19212 void
19213 ix86_expand_convert_uns_sixf_sse (rtx, rtx)
19214 {
19215   gcc_unreachable ();
19216 }
19217
19218 /* Convert an unsigned SImode value into a DFmode.  Only currently used
19219    for SSE, but applicable anywhere.  */
19220
19221 void
19222 ix86_expand_convert_uns_sidf_sse (rtx target, rtx input)
19223 {
19224   REAL_VALUE_TYPE TWO31r;
19225   rtx x, fp;
19226
19227   x = expand_simple_binop (SImode, PLUS, input, GEN_INT (-2147483647 - 1),
19228                            NULL, 1, OPTAB_DIRECT);
19229
19230   fp = gen_reg_rtx (DFmode);
19231   emit_insn (gen_floatsidf2 (fp, x));
19232
19233   real_ldexp (&TWO31r, &dconst1, 31);
19234   x = const_double_from_real_value (TWO31r, DFmode);
19235
19236   x = expand_simple_binop (DFmode, PLUS, fp, x, target, 0, OPTAB_DIRECT);
19237   if (x != target)
19238     emit_move_insn (target, x);
19239 }
19240
19241 /* Convert a signed DImode value into a DFmode.  Only used for SSE in
19242    32-bit mode; otherwise we have a direct convert instruction.  */
19243
19244 void
19245 ix86_expand_convert_sign_didf_sse (rtx target, rtx input)
19246 {
19247   REAL_VALUE_TYPE TWO32r;
19248   rtx fp_lo, fp_hi, x;
19249
19250   fp_lo = gen_reg_rtx (DFmode);
19251   fp_hi = gen_reg_rtx (DFmode);
19252
19253   emit_insn (gen_floatsidf2 (fp_hi, gen_highpart (SImode, input)));
19254
19255   real_ldexp (&TWO32r, &dconst1, 32);
19256   x = const_double_from_real_value (TWO32r, DFmode);
19257   fp_hi = expand_simple_binop (DFmode, MULT, fp_hi, x, fp_hi, 0, OPTAB_DIRECT);
19258
19259   ix86_expand_convert_uns_sidf_sse (fp_lo, gen_lowpart (SImode, input));
19260
19261   x = expand_simple_binop (DFmode, PLUS, fp_hi, fp_lo, target,
19262                            0, OPTAB_DIRECT);
19263   if (x != target)
19264     emit_move_insn (target, x);
19265 }
19266
19267 /* Convert an unsigned SImode value into a SFmode, using only SSE.
19268    For x86_32, -mfpmath=sse, !optimize_size only.  */
19269 void
19270 ix86_expand_convert_uns_sisf_sse (rtx target, rtx input)
19271 {
19272   REAL_VALUE_TYPE ONE16r;
19273   rtx fp_hi, fp_lo, int_hi, int_lo, x;
19274
19275   real_ldexp (&ONE16r, &dconst1, 16);
19276   x = const_double_from_real_value (ONE16r, SFmode);
19277   int_lo = expand_simple_binop (SImode, AND, input, GEN_INT(0xffff),
19278                                       NULL, 0, OPTAB_DIRECT);
19279   int_hi = expand_simple_binop (SImode, LSHIFTRT, input, GEN_INT(16),
19280                                       NULL, 0, OPTAB_DIRECT);
19281   fp_hi = gen_reg_rtx (SFmode);
19282   fp_lo = gen_reg_rtx (SFmode);
19283   emit_insn (gen_floatsisf2 (fp_hi, int_hi));
19284   emit_insn (gen_floatsisf2 (fp_lo, int_lo));
19285   fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi,
19286                                0, OPTAB_DIRECT);
19287   fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target,
19288                                0, OPTAB_DIRECT);
19289   if (!rtx_equal_p (target, fp_hi))
19290     emit_move_insn (target, fp_hi);
19291 }
19292
19293 /* floatunsv{4,8}siv{4,8}sf2 expander.  Expand code to convert
19294    a vector of unsigned ints VAL to vector of floats TARGET.  */
19295
19296 void
19297 ix86_expand_vector_convert_uns_vsivsf (rtx target, rtx val)
19298 {
19299   rtx tmp[8];
19300   REAL_VALUE_TYPE TWO16r;
19301   machine_mode intmode = GET_MODE (val);
19302   machine_mode fltmode = GET_MODE (target);
19303   rtx (*cvt) (rtx, rtx);
19304
19305   if (intmode == V4SImode)
19306     cvt = gen_floatv4siv4sf2;
19307   else
19308     cvt = gen_floatv8siv8sf2;
19309   tmp[0] = ix86_build_const_vector (intmode, 1, GEN_INT (0xffff));
19310   tmp[0] = force_reg (intmode, tmp[0]);
19311   tmp[1] = expand_simple_binop (intmode, AND, val, tmp[0], NULL_RTX, 1,
19312                                 OPTAB_DIRECT);
19313   tmp[2] = expand_simple_binop (intmode, LSHIFTRT, val, GEN_INT (16),
19314                                 NULL_RTX, 1, OPTAB_DIRECT);
19315   tmp[3] = gen_reg_rtx (fltmode);
19316   emit_insn (cvt (tmp[3], tmp[1]));
19317   tmp[4] = gen_reg_rtx (fltmode);
19318   emit_insn (cvt (tmp[4], tmp[2]));
19319   real_ldexp (&TWO16r, &dconst1, 16);
19320   tmp[5] = const_double_from_real_value (TWO16r, SFmode);
19321   tmp[5] = force_reg (fltmode, ix86_build_const_vector (fltmode, 1, tmp[5]));
19322   tmp[6] = expand_simple_binop (fltmode, MULT, tmp[4], tmp[5], NULL_RTX, 1,
19323                                 OPTAB_DIRECT);
19324   tmp[7] = expand_simple_binop (fltmode, PLUS, tmp[3], tmp[6], target, 1,
19325                                 OPTAB_DIRECT);
19326   if (tmp[7] != target)
19327     emit_move_insn (target, tmp[7]);
19328 }
19329
19330 /* Adjust a V*SFmode/V*DFmode value VAL so that *sfix_trunc* resp. fix_trunc*
19331    pattern can be used on it instead of *ufix_trunc* resp. fixuns_trunc*.
19332    This is done by doing just signed conversion if < 0x1p31, and otherwise by
19333    subtracting 0x1p31 first and xoring in 0x80000000 from *XORP afterwards.  */
19334
19335 rtx
19336 ix86_expand_adjust_ufix_to_sfix_si (rtx val, rtx *xorp)
19337 {
19338   REAL_VALUE_TYPE TWO31r;
19339   rtx two31r, tmp[4];
19340   machine_mode mode = GET_MODE (val);
19341   machine_mode scalarmode = GET_MODE_INNER (mode);
19342   machine_mode intmode = GET_MODE_SIZE (mode) == 32 ? V8SImode : V4SImode;
19343   rtx (*cmp) (rtx, rtx, rtx, rtx);
19344   int i;
19345
19346   for (i = 0; i < 3; i++)
19347     tmp[i] = gen_reg_rtx (mode);
19348   real_ldexp (&TWO31r, &dconst1, 31);
19349   two31r = const_double_from_real_value (TWO31r, scalarmode);
19350   two31r = ix86_build_const_vector (mode, 1, two31r);
19351   two31r = force_reg (mode, two31r);
19352   switch (mode)
19353     {
19354     case V8SFmode: cmp = gen_avx_maskcmpv8sf3; break;
19355     case V4SFmode: cmp = gen_sse_maskcmpv4sf3; break;
19356     case V4DFmode: cmp = gen_avx_maskcmpv4df3; break;
19357     case V2DFmode: cmp = gen_sse2_maskcmpv2df3; break;
19358     default: gcc_unreachable ();
19359     }
19360   tmp[3] = gen_rtx_LE (mode, two31r, val);
19361   emit_insn (cmp (tmp[0], two31r, val, tmp[3]));
19362   tmp[1] = expand_simple_binop (mode, AND, tmp[0], two31r, tmp[1],
19363                                 0, OPTAB_DIRECT);
19364   if (intmode == V4SImode || TARGET_AVX2)
19365     *xorp = expand_simple_binop (intmode, ASHIFT,
19366                                  gen_lowpart (intmode, tmp[0]),
19367                                  GEN_INT (31), NULL_RTX, 0,
19368                                  OPTAB_DIRECT);
19369   else
19370     {
19371       rtx two31 = GEN_INT ((unsigned HOST_WIDE_INT) 1 << 31);
19372       two31 = ix86_build_const_vector (intmode, 1, two31);
19373       *xorp = expand_simple_binop (intmode, AND,
19374                                    gen_lowpart (intmode, tmp[0]),
19375                                    two31, NULL_RTX, 0,
19376                                    OPTAB_DIRECT);
19377     }
19378   return expand_simple_binop (mode, MINUS, val, tmp[1], tmp[2],
19379                               0, OPTAB_DIRECT);
19380 }
19381
19382 /* A subroutine of ix86_build_signbit_mask.  If VECT is true,
19383    then replicate the value for all elements of the vector
19384    register.  */
19385
19386 rtx
19387 ix86_build_const_vector (machine_mode mode, bool vect, rtx value)
19388 {
19389   int i, n_elt;
19390   rtvec v;
19391   machine_mode scalar_mode;
19392
19393   switch (mode)
19394     {
19395     case V64QImode:
19396     case V32QImode:
19397     case V16QImode:
19398     case V32HImode:
19399     case V16HImode:
19400     case V8HImode:
19401     case V16SImode:
19402     case V8SImode:
19403     case V4SImode:
19404     case V8DImode:
19405     case V4DImode:
19406     case V2DImode:
19407       gcc_assert (vect);
19408     case V16SFmode:
19409     case V8SFmode:
19410     case V4SFmode:
19411     case V8DFmode:
19412     case V4DFmode:
19413     case V2DFmode:
19414       n_elt = GET_MODE_NUNITS (mode);
19415       v = rtvec_alloc (n_elt);
19416       scalar_mode = GET_MODE_INNER (mode);
19417
19418       RTVEC_ELT (v, 0) = value;
19419
19420       for (i = 1; i < n_elt; ++i)
19421         RTVEC_ELT (v, i) = vect ? value : CONST0_RTX (scalar_mode);
19422
19423       return gen_rtx_CONST_VECTOR (mode, v);
19424
19425     default:
19426       gcc_unreachable ();
19427     }
19428 }
19429
19430 /* A subroutine of ix86_expand_fp_absneg_operator, copysign expanders
19431    and ix86_expand_int_vcond.  Create a mask for the sign bit in MODE
19432    for an SSE register.  If VECT is true, then replicate the mask for
19433    all elements of the vector register.  If INVERT is true, then create
19434    a mask excluding the sign bit.  */
19435
19436 rtx
19437 ix86_build_signbit_mask (machine_mode mode, bool vect, bool invert)
19438 {
19439   machine_mode vec_mode, imode;
19440   HOST_WIDE_INT hi, lo;
19441   int shift = 63;
19442   rtx v;
19443   rtx mask;
19444
19445   /* Find the sign bit, sign extended to 2*HWI.  */
19446   switch (mode)
19447     {
19448     case V16SImode:
19449     case V16SFmode:
19450     case V8SImode:
19451     case V4SImode:
19452     case V8SFmode:
19453     case V4SFmode:
19454       vec_mode = mode;
19455       mode = GET_MODE_INNER (mode);
19456       imode = SImode;
19457       lo = 0x80000000, hi = lo < 0;
19458       break;
19459
19460     case V8DImode:
19461     case V4DImode:
19462     case V2DImode:
19463     case V8DFmode:
19464     case V4DFmode:
19465     case V2DFmode:
19466       vec_mode = mode;
19467       mode = GET_MODE_INNER (mode);
19468       imode = DImode;
19469       if (HOST_BITS_PER_WIDE_INT >= 64)
19470         lo = (HOST_WIDE_INT)1 << shift, hi = -1;
19471       else
19472         lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
19473       break;
19474
19475     case TImode:
19476     case TFmode:
19477       vec_mode = VOIDmode;
19478       if (HOST_BITS_PER_WIDE_INT >= 64)
19479         {
19480           imode = TImode;
19481           lo = 0, hi = (HOST_WIDE_INT)1 << shift;
19482         }
19483       else
19484         {
19485           rtvec vec;
19486
19487           imode = DImode;
19488           lo = 0, hi = (HOST_WIDE_INT)1 << (shift - HOST_BITS_PER_WIDE_INT);
19489
19490           if (invert)
19491             {
19492               lo = ~lo, hi = ~hi;
19493               v = constm1_rtx;
19494             }
19495           else
19496             v = const0_rtx;
19497
19498           mask = immed_double_const (lo, hi, imode);
19499
19500           vec = gen_rtvec (2, v, mask);
19501           v = gen_rtx_CONST_VECTOR (V2DImode, vec);
19502           v = copy_to_mode_reg (mode, gen_lowpart (mode, v));
19503
19504           return v;
19505         }
19506      break;
19507
19508     default:
19509       gcc_unreachable ();
19510     }
19511
19512   if (invert)
19513     lo = ~lo, hi = ~hi;
19514
19515   /* Force this value into the low part of a fp vector constant.  */
19516   mask = immed_double_const (lo, hi, imode);
19517   mask = gen_lowpart (mode, mask);
19518
19519   if (vec_mode == VOIDmode)
19520     return force_reg (mode, mask);
19521
19522   v = ix86_build_const_vector (vec_mode, vect, mask);
19523   return force_reg (vec_mode, v);
19524 }
19525
19526 /* Generate code for floating point ABS or NEG.  */
19527
19528 void
19529 ix86_expand_fp_absneg_operator (enum rtx_code code, machine_mode mode,
19530                                 rtx operands[])
19531 {
19532   rtx mask, set, dst, src;
19533   bool use_sse = false;
19534   bool vector_mode = VECTOR_MODE_P (mode);
19535   machine_mode vmode = mode;
19536
19537   if (vector_mode)
19538     use_sse = true;
19539   else if (mode == TFmode)
19540     use_sse = true;
19541   else if (TARGET_SSE_MATH)
19542     {
19543       use_sse = SSE_FLOAT_MODE_P (mode);
19544       if (mode == SFmode)
19545         vmode = V4SFmode;
19546       else if (mode == DFmode)
19547         vmode = V2DFmode;
19548     }
19549
19550   /* NEG and ABS performed with SSE use bitwise mask operations.
19551      Create the appropriate mask now.  */
19552   if (use_sse)
19553     mask = ix86_build_signbit_mask (vmode, vector_mode, code == ABS);
19554   else
19555     mask = NULL_RTX;
19556
19557   dst = operands[0];
19558   src = operands[1];
19559
19560   set = gen_rtx_fmt_e (code, mode, src);
19561   set = gen_rtx_SET (VOIDmode, dst, set);
19562
19563   if (mask)
19564     {
19565       rtx use, clob;
19566       rtvec par;
19567
19568       use = gen_rtx_USE (VOIDmode, mask);
19569       if (vector_mode)
19570         par = gen_rtvec (2, set, use);
19571       else
19572         {
19573           clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
19574           par = gen_rtvec (3, set, use, clob);
19575         }
19576       emit_insn (gen_rtx_PARALLEL (VOIDmode, par));
19577     }
19578   else
19579     emit_insn (set);
19580 }
19581
19582 /* Expand a copysign operation.  Special case operand 0 being a constant.  */
19583
19584 void
19585 ix86_expand_copysign (rtx operands[])
19586 {
19587   machine_mode mode, vmode;
19588   rtx dest, op0, op1, mask, nmask;
19589
19590   dest = operands[0];
19591   op0 = operands[1];
19592   op1 = operands[2];
19593
19594   mode = GET_MODE (dest);
19595
19596   if (mode == SFmode)
19597     vmode = V4SFmode;
19598   else if (mode == DFmode)
19599     vmode = V2DFmode;
19600   else
19601     vmode = mode;
19602
19603   if (GET_CODE (op0) == CONST_DOUBLE)
19604     {
19605       rtx (*copysign_insn)(rtx, rtx, rtx, rtx);
19606
19607       if (real_isneg (CONST_DOUBLE_REAL_VALUE (op0)))
19608         op0 = simplify_unary_operation (ABS, mode, op0, mode);
19609
19610       if (mode == SFmode || mode == DFmode)
19611         {
19612           if (op0 == CONST0_RTX (mode))
19613             op0 = CONST0_RTX (vmode);
19614           else
19615             {
19616               rtx v = ix86_build_const_vector (vmode, false, op0);
19617
19618               op0 = force_reg (vmode, v);
19619             }
19620         }
19621       else if (op0 != CONST0_RTX (mode))
19622         op0 = force_reg (mode, op0);
19623
19624       mask = ix86_build_signbit_mask (vmode, 0, 0);
19625
19626       if (mode == SFmode)
19627         copysign_insn = gen_copysignsf3_const;
19628       else if (mode == DFmode)
19629         copysign_insn = gen_copysigndf3_const;
19630       else
19631         copysign_insn = gen_copysigntf3_const;
19632
19633         emit_insn (copysign_insn (dest, op0, op1, mask));
19634     }
19635   else
19636     {
19637       rtx (*copysign_insn)(rtx, rtx, rtx, rtx, rtx, rtx);
19638
19639       nmask = ix86_build_signbit_mask (vmode, 0, 1);
19640       mask = ix86_build_signbit_mask (vmode, 0, 0);
19641
19642       if (mode == SFmode)
19643         copysign_insn = gen_copysignsf3_var;
19644       else if (mode == DFmode)
19645         copysign_insn = gen_copysigndf3_var;
19646       else
19647         copysign_insn = gen_copysigntf3_var;
19648
19649       emit_insn (copysign_insn (dest, NULL_RTX, op0, op1, nmask, mask));
19650     }
19651 }
19652
19653 /* Deconstruct a copysign operation into bit masks.  Operand 0 is known to
19654    be a constant, and so has already been expanded into a vector constant.  */
19655
19656 void
19657 ix86_split_copysign_const (rtx operands[])
19658 {
19659   machine_mode mode, vmode;
19660   rtx dest, op0, mask, x;
19661
19662   dest = operands[0];
19663   op0 = operands[1];
19664   mask = operands[3];
19665
19666   mode = GET_MODE (dest);
19667   vmode = GET_MODE (mask);
19668
19669   dest = simplify_gen_subreg (vmode, dest, mode, 0);
19670   x = gen_rtx_AND (vmode, dest, mask);
19671   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19672
19673   if (op0 != CONST0_RTX (vmode))
19674     {
19675       x = gen_rtx_IOR (vmode, dest, op0);
19676       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19677     }
19678 }
19679
19680 /* Deconstruct a copysign operation into bit masks.  Operand 0 is variable,
19681    so we have to do two masks.  */
19682
19683 void
19684 ix86_split_copysign_var (rtx operands[])
19685 {
19686   machine_mode mode, vmode;
19687   rtx dest, scratch, op0, op1, mask, nmask, x;
19688
19689   dest = operands[0];
19690   scratch = operands[1];
19691   op0 = operands[2];
19692   op1 = operands[3];
19693   nmask = operands[4];
19694   mask = operands[5];
19695
19696   mode = GET_MODE (dest);
19697   vmode = GET_MODE (mask);
19698
19699   if (rtx_equal_p (op0, op1))
19700     {
19701       /* Shouldn't happen often (it's useless, obviously), but when it does
19702          we'd generate incorrect code if we continue below.  */
19703       emit_move_insn (dest, op0);
19704       return;
19705     }
19706
19707   if (REG_P (mask) && REGNO (dest) == REGNO (mask))     /* alternative 0 */
19708     {
19709       gcc_assert (REGNO (op1) == REGNO (scratch));
19710
19711       x = gen_rtx_AND (vmode, scratch, mask);
19712       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
19713
19714       dest = mask;
19715       op0 = simplify_gen_subreg (vmode, op0, mode, 0);
19716       x = gen_rtx_NOT (vmode, dest);
19717       x = gen_rtx_AND (vmode, x, op0);
19718       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19719     }
19720   else
19721     {
19722       if (REGNO (op1) == REGNO (scratch))               /* alternative 1,3 */
19723         {
19724           x = gen_rtx_AND (vmode, scratch, mask);
19725         }
19726       else                                              /* alternative 2,4 */
19727         {
19728           gcc_assert (REGNO (mask) == REGNO (scratch));
19729           op1 = simplify_gen_subreg (vmode, op1, mode, 0);
19730           x = gen_rtx_AND (vmode, scratch, op1);
19731         }
19732       emit_insn (gen_rtx_SET (VOIDmode, scratch, x));
19733
19734       if (REGNO (op0) == REGNO (dest))                  /* alternative 1,2 */
19735         {
19736           dest = simplify_gen_subreg (vmode, op0, mode, 0);
19737           x = gen_rtx_AND (vmode, dest, nmask);
19738         }
19739       else                                              /* alternative 3,4 */
19740         {
19741           gcc_assert (REGNO (nmask) == REGNO (dest));
19742           dest = nmask;
19743           op0 = simplify_gen_subreg (vmode, op0, mode, 0);
19744           x = gen_rtx_AND (vmode, dest, op0);
19745         }
19746       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19747     }
19748
19749   x = gen_rtx_IOR (vmode, dest, scratch);
19750   emit_insn (gen_rtx_SET (VOIDmode, dest, x));
19751 }
19752
19753 /* Return TRUE or FALSE depending on whether the first SET in INSN
19754    has source and destination with matching CC modes, and that the
19755    CC mode is at least as constrained as REQ_MODE.  */
19756
19757 bool
19758 ix86_match_ccmode (rtx insn, machine_mode req_mode)
19759 {
19760   rtx set;
19761   machine_mode set_mode;
19762
19763   set = PATTERN (insn);
19764   if (GET_CODE (set) == PARALLEL)
19765     set = XVECEXP (set, 0, 0);
19766   gcc_assert (GET_CODE (set) == SET);
19767   gcc_assert (GET_CODE (SET_SRC (set)) == COMPARE);
19768
19769   set_mode = GET_MODE (SET_DEST (set));
19770   switch (set_mode)
19771     {
19772     case CCNOmode:
19773       if (req_mode != CCNOmode
19774           && (req_mode != CCmode
19775               || XEXP (SET_SRC (set), 1) != const0_rtx))
19776         return false;
19777       break;
19778     case CCmode:
19779       if (req_mode == CCGCmode)
19780         return false;
19781       /* FALLTHRU */
19782     case CCGCmode:
19783       if (req_mode == CCGOCmode || req_mode == CCNOmode)
19784         return false;
19785       /* FALLTHRU */
19786     case CCGOCmode:
19787       if (req_mode == CCZmode)
19788         return false;
19789       /* FALLTHRU */
19790     case CCZmode:
19791       break;
19792
19793     case CCAmode:
19794     case CCCmode:
19795     case CCOmode:
19796     case CCSmode:
19797       if (set_mode != req_mode)
19798         return false;
19799       break;
19800
19801     default:
19802       gcc_unreachable ();
19803     }
19804
19805   return GET_MODE (SET_SRC (set)) == set_mode;
19806 }
19807
19808 /* Generate insn patterns to do an integer compare of OPERANDS.  */
19809
19810 static rtx
19811 ix86_expand_int_compare (enum rtx_code code, rtx op0, rtx op1)
19812 {
19813   machine_mode cmpmode;
19814   rtx tmp, flags;
19815
19816   cmpmode = SELECT_CC_MODE (code, op0, op1);
19817   flags = gen_rtx_REG (cmpmode, FLAGS_REG);
19818
19819   /* This is very simple, but making the interface the same as in the
19820      FP case makes the rest of the code easier.  */
19821   tmp = gen_rtx_COMPARE (cmpmode, op0, op1);
19822   emit_insn (gen_rtx_SET (VOIDmode, flags, tmp));
19823
19824   /* Return the test that should be put into the flags user, i.e.
19825      the bcc, scc, or cmov instruction.  */
19826   return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx);
19827 }
19828
19829 /* Figure out whether to use ordered or unordered fp comparisons.
19830    Return the appropriate mode to use.  */
19831
19832 machine_mode
19833 ix86_fp_compare_mode (enum rtx_code)
19834 {
19835   /* ??? In order to make all comparisons reversible, we do all comparisons
19836      non-trapping when compiling for IEEE.  Once gcc is able to distinguish
19837      all forms trapping and nontrapping comparisons, we can make inequality
19838      comparisons trapping again, since it results in better code when using
19839      FCOM based compares.  */
19840   return TARGET_IEEE_FP ? CCFPUmode : CCFPmode;
19841 }
19842
19843 machine_mode
19844 ix86_cc_mode (enum rtx_code code, rtx op0, rtx op1)
19845 {
19846   machine_mode mode = GET_MODE (op0);
19847
19848   if (SCALAR_FLOAT_MODE_P (mode))
19849     {
19850       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
19851       return ix86_fp_compare_mode (code);
19852     }
19853
19854   switch (code)
19855     {
19856       /* Only zero flag is needed.  */
19857     case EQ:                    /* ZF=0 */
19858     case NE:                    /* ZF!=0 */
19859       return CCZmode;
19860       /* Codes needing carry flag.  */
19861     case GEU:                   /* CF=0 */
19862     case LTU:                   /* CF=1 */
19863       /* Detect overflow checks.  They need just the carry flag.  */
19864       if (GET_CODE (op0) == PLUS
19865           && rtx_equal_p (op1, XEXP (op0, 0)))
19866         return CCCmode;
19867       else
19868         return CCmode;
19869     case GTU:                   /* CF=0 & ZF=0 */
19870     case LEU:                   /* CF=1 | ZF=1 */
19871       return CCmode;
19872       /* Codes possibly doable only with sign flag when
19873          comparing against zero.  */
19874     case GE:                    /* SF=OF   or   SF=0 */
19875     case LT:                    /* SF<>OF  or   SF=1 */
19876       if (op1 == const0_rtx)
19877         return CCGOCmode;
19878       else
19879         /* For other cases Carry flag is not required.  */
19880         return CCGCmode;
19881       /* Codes doable only with sign flag when comparing
19882          against zero, but we miss jump instruction for it
19883          so we need to use relational tests against overflow
19884          that thus needs to be zero.  */
19885     case GT:                    /* ZF=0 & SF=OF */
19886     case LE:                    /* ZF=1 | SF<>OF */
19887       if (op1 == const0_rtx)
19888         return CCNOmode;
19889       else
19890         return CCGCmode;
19891       /* strcmp pattern do (use flags) and combine may ask us for proper
19892          mode.  */
19893     case USE:
19894       return CCmode;
19895     default:
19896       gcc_unreachable ();
19897     }
19898 }
19899
19900 /* Return the fixed registers used for condition codes.  */
19901
19902 static bool
19903 ix86_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
19904 {
19905   *p1 = FLAGS_REG;
19906   *p2 = FPSR_REG;
19907   return true;
19908 }
19909
19910 /* If two condition code modes are compatible, return a condition code
19911    mode which is compatible with both.  Otherwise, return
19912    VOIDmode.  */
19913
19914 static machine_mode
19915 ix86_cc_modes_compatible (machine_mode m1, machine_mode m2)
19916 {
19917   if (m1 == m2)
19918     return m1;
19919
19920   if (GET_MODE_CLASS (m1) != MODE_CC || GET_MODE_CLASS (m2) != MODE_CC)
19921     return VOIDmode;
19922
19923   if ((m1 == CCGCmode && m2 == CCGOCmode)
19924       || (m1 == CCGOCmode && m2 == CCGCmode))
19925     return CCGCmode;
19926
19927   if (m1 == CCZmode && (m2 == CCGCmode || m2 == CCGOCmode))
19928     return m2;
19929   else if (m2 == CCZmode && (m1 == CCGCmode || m1 == CCGOCmode))
19930     return m1;
19931
19932   switch (m1)
19933     {
19934     default:
19935       gcc_unreachable ();
19936
19937     case CCmode:
19938     case CCGCmode:
19939     case CCGOCmode:
19940     case CCNOmode:
19941     case CCAmode:
19942     case CCCmode:
19943     case CCOmode:
19944     case CCSmode:
19945     case CCZmode:
19946       switch (m2)
19947         {
19948         default:
19949           return VOIDmode;
19950
19951         case CCmode:
19952         case CCGCmode:
19953         case CCGOCmode:
19954         case CCNOmode:
19955         case CCAmode:
19956         case CCCmode:
19957         case CCOmode:
19958         case CCSmode:
19959         case CCZmode:
19960           return CCmode;
19961         }
19962
19963     case CCFPmode:
19964     case CCFPUmode:
19965       /* These are only compatible with themselves, which we already
19966          checked above.  */
19967       return VOIDmode;
19968     }
19969 }
19970
19971
19972 /* Return a comparison we can do and that it is equivalent to
19973    swap_condition (code) apart possibly from orderedness.
19974    But, never change orderedness if TARGET_IEEE_FP, returning
19975    UNKNOWN in that case if necessary.  */
19976
19977 static enum rtx_code
19978 ix86_fp_swap_condition (enum rtx_code code)
19979 {
19980   switch (code)
19981     {
19982     case GT:                   /* GTU - CF=0 & ZF=0 */
19983       return TARGET_IEEE_FP ? UNKNOWN : UNLT;
19984     case GE:                   /* GEU - CF=0 */
19985       return TARGET_IEEE_FP ? UNKNOWN : UNLE;
19986     case UNLT:                 /* LTU - CF=1 */
19987       return TARGET_IEEE_FP ? UNKNOWN : GT;
19988     case UNLE:                 /* LEU - CF=1 | ZF=1 */
19989       return TARGET_IEEE_FP ? UNKNOWN : GE;
19990     default:
19991       return swap_condition (code);
19992     }
19993 }
19994
19995 /* Return cost of comparison CODE using the best strategy for performance.
19996    All following functions do use number of instructions as a cost metrics.
19997    In future this should be tweaked to compute bytes for optimize_size and
19998    take into account performance of various instructions on various CPUs.  */
19999
20000 static int
20001 ix86_fp_comparison_cost (enum rtx_code code)
20002 {
20003   int arith_cost;
20004
20005   /* The cost of code using bit-twiddling on %ah.  */
20006   switch (code)
20007     {
20008     case UNLE:
20009     case UNLT:
20010     case LTGT:
20011     case GT:
20012     case GE:
20013     case UNORDERED:
20014     case ORDERED:
20015     case UNEQ:
20016       arith_cost = 4;
20017       break;
20018     case LT:
20019     case NE:
20020     case EQ:
20021     case UNGE:
20022       arith_cost = TARGET_IEEE_FP ? 5 : 4;
20023       break;
20024     case LE:
20025     case UNGT:
20026       arith_cost = TARGET_IEEE_FP ? 6 : 4;
20027       break;
20028     default:
20029       gcc_unreachable ();
20030     }
20031
20032   switch (ix86_fp_comparison_strategy (code))
20033     {
20034     case IX86_FPCMP_COMI:
20035       return arith_cost > 4 ? 3 : 2;
20036     case IX86_FPCMP_SAHF:
20037       return arith_cost > 4 ? 4 : 3;
20038     default:
20039       return arith_cost;
20040     }
20041 }
20042
20043 /* Return strategy to use for floating-point.  We assume that fcomi is always
20044    preferrable where available, since that is also true when looking at size
20045    (2 bytes, vs. 3 for fnstsw+sahf and at least 5 for fnstsw+test).  */
20046
20047 enum ix86_fpcmp_strategy
20048 ix86_fp_comparison_strategy (enum rtx_code)
20049 {
20050   /* Do fcomi/sahf based test when profitable.  */
20051
20052   if (TARGET_CMOVE)
20053     return IX86_FPCMP_COMI;
20054
20055   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
20056     return IX86_FPCMP_SAHF;
20057
20058   return IX86_FPCMP_ARITH;
20059 }
20060
20061 /* Swap, force into registers, or otherwise massage the two operands
20062    to a fp comparison.  The operands are updated in place; the new
20063    comparison code is returned.  */
20064
20065 static enum rtx_code
20066 ix86_prepare_fp_compare_args (enum rtx_code code, rtx *pop0, rtx *pop1)
20067 {
20068   machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
20069   rtx op0 = *pop0, op1 = *pop1;
20070   machine_mode op_mode = GET_MODE (op0);
20071   int is_sse = TARGET_SSE_MATH && SSE_FLOAT_MODE_P (op_mode);
20072
20073   /* All of the unordered compare instructions only work on registers.
20074      The same is true of the fcomi compare instructions.  The XFmode
20075      compare instructions require registers except when comparing
20076      against zero or when converting operand 1 from fixed point to
20077      floating point.  */
20078
20079   if (!is_sse
20080       && (fpcmp_mode == CCFPUmode
20081           || (op_mode == XFmode
20082               && ! (standard_80387_constant_p (op0) == 1
20083                     || standard_80387_constant_p (op1) == 1)
20084               && GET_CODE (op1) != FLOAT)
20085           || ix86_fp_comparison_strategy (code) == IX86_FPCMP_COMI))
20086     {
20087       op0 = force_reg (op_mode, op0);
20088       op1 = force_reg (op_mode, op1);
20089     }
20090   else
20091     {
20092       /* %%% We only allow op1 in memory; op0 must be st(0).  So swap
20093          things around if they appear profitable, otherwise force op0
20094          into a register.  */
20095
20096       if (standard_80387_constant_p (op0) == 0
20097           || (MEM_P (op0)
20098               && ! (standard_80387_constant_p (op1) == 0
20099                     || MEM_P (op1))))
20100         {
20101           enum rtx_code new_code = ix86_fp_swap_condition (code);
20102           if (new_code != UNKNOWN)
20103             {
20104               std::swap (op0, op1);
20105               code = new_code;
20106             }
20107         }
20108
20109       if (!REG_P (op0))
20110         op0 = force_reg (op_mode, op0);
20111
20112       if (CONSTANT_P (op1))
20113         {
20114           int tmp = standard_80387_constant_p (op1);
20115           if (tmp == 0)
20116             op1 = validize_mem (force_const_mem (op_mode, op1));
20117           else if (tmp == 1)
20118             {
20119               if (TARGET_CMOVE)
20120                 op1 = force_reg (op_mode, op1);
20121             }
20122           else
20123             op1 = force_reg (op_mode, op1);
20124         }
20125     }
20126
20127   /* Try to rearrange the comparison to make it cheaper.  */
20128   if (ix86_fp_comparison_cost (code)
20129       > ix86_fp_comparison_cost (swap_condition (code))
20130       && (REG_P (op1) || can_create_pseudo_p ()))
20131     {
20132       std::swap (op0, op1);
20133       code = swap_condition (code);
20134       if (!REG_P (op0))
20135         op0 = force_reg (op_mode, op0);
20136     }
20137
20138   *pop0 = op0;
20139   *pop1 = op1;
20140   return code;
20141 }
20142
20143 /* Convert comparison codes we use to represent FP comparison to integer
20144    code that will result in proper branch.  Return UNKNOWN if no such code
20145    is available.  */
20146
20147 enum rtx_code
20148 ix86_fp_compare_code_to_integer (enum rtx_code code)
20149 {
20150   switch (code)
20151     {
20152     case GT:
20153       return GTU;
20154     case GE:
20155       return GEU;
20156     case ORDERED:
20157     case UNORDERED:
20158       return code;
20159       break;
20160     case UNEQ:
20161       return EQ;
20162       break;
20163     case UNLT:
20164       return LTU;
20165       break;
20166     case UNLE:
20167       return LEU;
20168       break;
20169     case LTGT:
20170       return NE;
20171       break;
20172     default:
20173       return UNKNOWN;
20174     }
20175 }
20176
20177 /* Generate insn patterns to do a floating point compare of OPERANDS.  */
20178
20179 static rtx
20180 ix86_expand_fp_compare (enum rtx_code code, rtx op0, rtx op1, rtx scratch)
20181 {
20182   machine_mode fpcmp_mode, intcmp_mode;
20183   rtx tmp, tmp2;
20184
20185   fpcmp_mode = ix86_fp_compare_mode (code);
20186   code = ix86_prepare_fp_compare_args (code, &op0, &op1);
20187
20188   /* Do fcomi/sahf based test when profitable.  */
20189   switch (ix86_fp_comparison_strategy (code))
20190     {
20191     case IX86_FPCMP_COMI:
20192       intcmp_mode = fpcmp_mode;
20193       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
20194       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
20195                          tmp);
20196       emit_insn (tmp);
20197       break;
20198
20199     case IX86_FPCMP_SAHF:
20200       intcmp_mode = fpcmp_mode;
20201       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
20202       tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG),
20203                          tmp);
20204
20205       if (!scratch)
20206         scratch = gen_reg_rtx (HImode);
20207       tmp2 = gen_rtx_CLOBBER (VOIDmode, scratch);
20208       emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, tmp2)));
20209       break;
20210
20211     case IX86_FPCMP_ARITH:
20212       /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first.  */
20213       tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1);
20214       tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), UNSPEC_FNSTSW);
20215       if (!scratch)
20216         scratch = gen_reg_rtx (HImode);
20217       emit_insn (gen_rtx_SET (VOIDmode, scratch, tmp2));
20218
20219       /* In the unordered case, we have to check C2 for NaN's, which
20220          doesn't happen to work out to anything nice combination-wise.
20221          So do some bit twiddling on the value we've got in AH to come
20222          up with an appropriate set of condition codes.  */
20223
20224       intcmp_mode = CCNOmode;
20225       switch (code)
20226         {
20227         case GT:
20228         case UNGT:
20229           if (code == GT || !TARGET_IEEE_FP)
20230             {
20231               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
20232               code = EQ;
20233             }
20234           else
20235             {
20236               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20237               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
20238               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x44)));
20239               intcmp_mode = CCmode;
20240               code = GEU;
20241             }
20242           break;
20243         case LT:
20244         case UNLT:
20245           if (code == LT && TARGET_IEEE_FP)
20246             {
20247               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20248               emit_insn (gen_cmpqi_ext_3 (scratch, const1_rtx));
20249               intcmp_mode = CCmode;
20250               code = EQ;
20251             }
20252           else
20253             {
20254               emit_insn (gen_testqi_ext_ccno_0 (scratch, const1_rtx));
20255               code = NE;
20256             }
20257           break;
20258         case GE:
20259         case UNGE:
20260           if (code == GE || !TARGET_IEEE_FP)
20261             {
20262               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x05)));
20263               code = EQ;
20264             }
20265           else
20266             {
20267               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20268               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch, const1_rtx));
20269               code = NE;
20270             }
20271           break;
20272         case LE:
20273         case UNLE:
20274           if (code == LE && TARGET_IEEE_FP)
20275             {
20276               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20277               emit_insn (gen_addqi_ext_1 (scratch, scratch, constm1_rtx));
20278               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
20279               intcmp_mode = CCmode;
20280               code = LTU;
20281             }
20282           else
20283             {
20284               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x45)));
20285               code = NE;
20286             }
20287           break;
20288         case EQ:
20289         case UNEQ:
20290           if (code == EQ && TARGET_IEEE_FP)
20291             {
20292               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20293               emit_insn (gen_cmpqi_ext_3 (scratch, GEN_INT (0x40)));
20294               intcmp_mode = CCmode;
20295               code = EQ;
20296             }
20297           else
20298             {
20299               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
20300               code = NE;
20301             }
20302           break;
20303         case NE:
20304         case LTGT:
20305           if (code == NE && TARGET_IEEE_FP)
20306             {
20307               emit_insn (gen_andqi_ext_0 (scratch, scratch, GEN_INT (0x45)));
20308               emit_insn (gen_xorqi_cc_ext_1 (scratch, scratch,
20309                                              GEN_INT (0x40)));
20310               code = NE;
20311             }
20312           else
20313             {
20314               emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x40)));
20315               code = EQ;
20316             }
20317           break;
20318
20319         case UNORDERED:
20320           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
20321           code = NE;
20322           break;
20323         case ORDERED:
20324           emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x04)));
20325           code = EQ;
20326           break;
20327
20328         default:
20329           gcc_unreachable ();
20330         }
20331         break;
20332
20333     default:
20334       gcc_unreachable();
20335     }
20336
20337   /* Return the test that should be put into the flags user, i.e.
20338      the bcc, scc, or cmov instruction.  */
20339   return gen_rtx_fmt_ee (code, VOIDmode,
20340                          gen_rtx_REG (intcmp_mode, FLAGS_REG),
20341                          const0_rtx);
20342 }
20343
20344 static rtx
20345 ix86_expand_compare (enum rtx_code code, rtx op0, rtx op1)
20346 {
20347   rtx ret;
20348
20349   if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC)
20350     ret = gen_rtx_fmt_ee (code, VOIDmode, op0, op1);
20351
20352   else if (SCALAR_FLOAT_MODE_P (GET_MODE (op0)))
20353     {
20354       gcc_assert (!DECIMAL_FLOAT_MODE_P (GET_MODE (op0)));
20355       ret = ix86_expand_fp_compare (code, op0, op1, NULL_RTX);
20356     }
20357   else
20358     ret = ix86_expand_int_compare (code, op0, op1);
20359
20360   return ret;
20361 }
20362
20363 void
20364 ix86_expand_branch (enum rtx_code code, rtx op0, rtx op1, rtx label)
20365 {
20366   machine_mode mode = GET_MODE (op0);
20367   rtx tmp;
20368
20369   switch (mode)
20370     {
20371     case SFmode:
20372     case DFmode:
20373     case XFmode:
20374     case QImode:
20375     case HImode:
20376     case SImode:
20377       simple:
20378       tmp = ix86_expand_compare (code, op0, op1);
20379       tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
20380                                   gen_rtx_LABEL_REF (VOIDmode, label),
20381                                   pc_rtx);
20382       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
20383       return;
20384
20385     case DImode:
20386       if (TARGET_64BIT)
20387         goto simple;
20388     case TImode:
20389       /* Expand DImode branch into multiple compare+branch.  */
20390       {
20391         rtx lo[2], hi[2];
20392         rtx_code_label *label2;
20393         enum rtx_code code1, code2, code3;
20394         machine_mode submode;
20395
20396         if (CONSTANT_P (op0) && !CONSTANT_P (op1))
20397           {
20398             std::swap (op0, op1);
20399             code = swap_condition (code);
20400           }
20401
20402         split_double_mode (mode, &op0, 1, lo+0, hi+0);
20403         split_double_mode (mode, &op1, 1, lo+1, hi+1);
20404
20405         submode = mode == DImode ? SImode : DImode;
20406
20407         /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to
20408            avoid two branches.  This costs one extra insn, so disable when
20409            optimizing for size.  */
20410
20411         if ((code == EQ || code == NE)
20412             && (!optimize_insn_for_size_p ()
20413                 || hi[1] == const0_rtx || lo[1] == const0_rtx))
20414           {
20415             rtx xor0, xor1;
20416
20417             xor1 = hi[0];
20418             if (hi[1] != const0_rtx)
20419               xor1 = expand_binop (submode, xor_optab, xor1, hi[1],
20420                                    NULL_RTX, 0, OPTAB_WIDEN);
20421
20422             xor0 = lo[0];
20423             if (lo[1] != const0_rtx)
20424               xor0 = expand_binop (submode, xor_optab, xor0, lo[1],
20425                                    NULL_RTX, 0, OPTAB_WIDEN);
20426
20427             tmp = expand_binop (submode, ior_optab, xor1, xor0,
20428                                 NULL_RTX, 0, OPTAB_WIDEN);
20429
20430             ix86_expand_branch (code, tmp, const0_rtx, label);
20431             return;
20432           }
20433
20434         /* Otherwise, if we are doing less-than or greater-or-equal-than,
20435            op1 is a constant and the low word is zero, then we can just
20436            examine the high word.  Similarly for low word -1 and
20437            less-or-equal-than or greater-than.  */
20438
20439         if (CONST_INT_P (hi[1]))
20440           switch (code)
20441             {
20442             case LT: case LTU: case GE: case GEU:
20443               if (lo[1] == const0_rtx)
20444                 {
20445                   ix86_expand_branch (code, hi[0], hi[1], label);
20446                   return;
20447                 }
20448               break;
20449             case LE: case LEU: case GT: case GTU:
20450               if (lo[1] == constm1_rtx)
20451                 {
20452                   ix86_expand_branch (code, hi[0], hi[1], label);
20453                   return;
20454                 }
20455               break;
20456             default:
20457               break;
20458             }
20459
20460         /* Otherwise, we need two or three jumps.  */
20461
20462         label2 = gen_label_rtx ();
20463
20464         code1 = code;
20465         code2 = swap_condition (code);
20466         code3 = unsigned_condition (code);
20467
20468         switch (code)
20469           {
20470           case LT: case GT: case LTU: case GTU:
20471             break;
20472
20473           case LE:   code1 = LT;  code2 = GT;  break;
20474           case GE:   code1 = GT;  code2 = LT;  break;
20475           case LEU:  code1 = LTU; code2 = GTU; break;
20476           case GEU:  code1 = GTU; code2 = LTU; break;
20477
20478           case EQ:   code1 = UNKNOWN; code2 = NE;  break;
20479           case NE:   code2 = UNKNOWN; break;
20480
20481           default:
20482             gcc_unreachable ();
20483           }
20484
20485         /*
20486          * a < b =>
20487          *    if (hi(a) < hi(b)) goto true;
20488          *    if (hi(a) > hi(b)) goto false;
20489          *    if (lo(a) < lo(b)) goto true;
20490          *  false:
20491          */
20492
20493         if (code1 != UNKNOWN)
20494           ix86_expand_branch (code1, hi[0], hi[1], label);
20495         if (code2 != UNKNOWN)
20496           ix86_expand_branch (code2, hi[0], hi[1], label2);
20497
20498         ix86_expand_branch (code3, lo[0], lo[1], label);
20499
20500         if (code2 != UNKNOWN)
20501           emit_label (label2);
20502         return;
20503       }
20504
20505     default:
20506       gcc_assert (GET_MODE_CLASS (GET_MODE (op0)) == MODE_CC);
20507       goto simple;
20508     }
20509 }
20510
20511 /* Split branch based on floating point condition.  */
20512 void
20513 ix86_split_fp_branch (enum rtx_code code, rtx op1, rtx op2,
20514                       rtx target1, rtx target2, rtx tmp)
20515 {
20516   rtx condition;
20517   rtx i;
20518
20519   if (target2 != pc_rtx)
20520     {
20521       std::swap (target1, target2);
20522       code = reverse_condition_maybe_unordered (code);
20523     }
20524
20525   condition = ix86_expand_fp_compare (code, op1, op2,
20526                                       tmp);
20527
20528   i = emit_jump_insn (gen_rtx_SET
20529                       (VOIDmode, pc_rtx,
20530                        gen_rtx_IF_THEN_ELSE (VOIDmode,
20531                                              condition, target1, target2)));
20532   if (split_branch_probability >= 0)
20533     add_int_reg_note (i, REG_BR_PROB, split_branch_probability);
20534 }
20535
20536 void
20537 ix86_expand_setcc (rtx dest, enum rtx_code code, rtx op0, rtx op1)
20538 {
20539   rtx ret;
20540
20541   gcc_assert (GET_MODE (dest) == QImode);
20542
20543   ret = ix86_expand_compare (code, op0, op1);
20544   PUT_MODE (ret, QImode);
20545   emit_insn (gen_rtx_SET (VOIDmode, dest, ret));
20546 }
20547
20548 /* Expand comparison setting or clearing carry flag.  Return true when
20549    successful and set pop for the operation.  */
20550 static bool
20551 ix86_expand_carry_flag_compare (enum rtx_code code, rtx op0, rtx op1, rtx *pop)
20552 {
20553   machine_mode mode =
20554     GET_MODE (op0) != VOIDmode ? GET_MODE (op0) : GET_MODE (op1);
20555
20556   /* Do not handle double-mode compares that go through special path.  */
20557   if (mode == (TARGET_64BIT ? TImode : DImode))
20558     return false;
20559
20560   if (SCALAR_FLOAT_MODE_P (mode))
20561     {
20562       rtx compare_op;
20563       rtx_insn *compare_seq;
20564
20565       gcc_assert (!DECIMAL_FLOAT_MODE_P (mode));
20566
20567       /* Shortcut:  following common codes never translate
20568          into carry flag compares.  */
20569       if (code == EQ || code == NE || code == UNEQ || code == LTGT
20570           || code == ORDERED || code == UNORDERED)
20571         return false;
20572
20573       /* These comparisons require zero flag; swap operands so they won't.  */
20574       if ((code == GT || code == UNLE || code == LE || code == UNGT)
20575           && !TARGET_IEEE_FP)
20576         {
20577           std::swap (op0, op1);
20578           code = swap_condition (code);
20579         }
20580
20581       /* Try to expand the comparison and verify that we end up with
20582          carry flag based comparison.  This fails to be true only when
20583          we decide to expand comparison using arithmetic that is not
20584          too common scenario.  */
20585       start_sequence ();
20586       compare_op = ix86_expand_fp_compare (code, op0, op1, NULL_RTX);
20587       compare_seq = get_insns ();
20588       end_sequence ();
20589
20590       if (GET_MODE (XEXP (compare_op, 0)) == CCFPmode
20591           || GET_MODE (XEXP (compare_op, 0)) == CCFPUmode)
20592         code = ix86_fp_compare_code_to_integer (GET_CODE (compare_op));
20593       else
20594         code = GET_CODE (compare_op);
20595
20596       if (code != LTU && code != GEU)
20597         return false;
20598
20599       emit_insn (compare_seq);
20600       *pop = compare_op;
20601       return true;
20602     }
20603
20604   if (!INTEGRAL_MODE_P (mode))
20605     return false;
20606
20607   switch (code)
20608     {
20609     case LTU:
20610     case GEU:
20611       break;
20612
20613     /* Convert a==0 into (unsigned)a<1.  */
20614     case EQ:
20615     case NE:
20616       if (op1 != const0_rtx)
20617         return false;
20618       op1 = const1_rtx;
20619       code = (code == EQ ? LTU : GEU);
20620       break;
20621
20622     /* Convert a>b into b<a or a>=b-1.  */
20623     case GTU:
20624     case LEU:
20625       if (CONST_INT_P (op1))
20626         {
20627           op1 = gen_int_mode (INTVAL (op1) + 1, GET_MODE (op0));
20628           /* Bail out on overflow.  We still can swap operands but that
20629              would force loading of the constant into register.  */
20630           if (op1 == const0_rtx
20631               || !x86_64_immediate_operand (op1, GET_MODE (op1)))
20632             return false;
20633           code = (code == GTU ? GEU : LTU);
20634         }
20635       else
20636         {
20637           std::swap (op0, op1);
20638           code = (code == GTU ? LTU : GEU);
20639         }
20640       break;
20641
20642     /* Convert a>=0 into (unsigned)a<0x80000000.  */
20643     case LT:
20644     case GE:
20645       if (mode == DImode || op1 != const0_rtx)
20646         return false;
20647       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
20648       code = (code == LT ? GEU : LTU);
20649       break;
20650     case LE:
20651     case GT:
20652       if (mode == DImode || op1 != constm1_rtx)
20653         return false;
20654       op1 = gen_int_mode (1 << (GET_MODE_BITSIZE (mode) - 1), mode);
20655       code = (code == LE ? GEU : LTU);
20656       break;
20657
20658     default:
20659       return false;
20660     }
20661   /* Swapping operands may cause constant to appear as first operand.  */
20662   if (!nonimmediate_operand (op0, VOIDmode))
20663     {
20664       if (!can_create_pseudo_p ())
20665         return false;
20666       op0 = force_reg (mode, op0);
20667     }
20668   *pop = ix86_expand_compare (code, op0, op1);
20669   gcc_assert (GET_CODE (*pop) == LTU || GET_CODE (*pop) == GEU);
20670   return true;
20671 }
20672
20673 bool
20674 ix86_expand_int_movcc (rtx operands[])
20675 {
20676   enum rtx_code code = GET_CODE (operands[1]), compare_code;
20677   rtx_insn *compare_seq;
20678   rtx compare_op;
20679   machine_mode mode = GET_MODE (operands[0]);
20680   bool sign_bit_compare_p = false;
20681   rtx op0 = XEXP (operands[1], 0);
20682   rtx op1 = XEXP (operands[1], 1);
20683
20684   if (GET_MODE (op0) == TImode
20685       || (GET_MODE (op0) == DImode
20686           && !TARGET_64BIT))
20687     return false;
20688
20689   start_sequence ();
20690   compare_op = ix86_expand_compare (code, op0, op1);
20691   compare_seq = get_insns ();
20692   end_sequence ();
20693
20694   compare_code = GET_CODE (compare_op);
20695
20696   if ((op1 == const0_rtx && (code == GE || code == LT))
20697       || (op1 == constm1_rtx && (code == GT || code == LE)))
20698     sign_bit_compare_p = true;
20699
20700   /* Don't attempt mode expansion here -- if we had to expand 5 or 6
20701      HImode insns, we'd be swallowed in word prefix ops.  */
20702
20703   if ((mode != HImode || TARGET_FAST_PREFIX)
20704       && (mode != (TARGET_64BIT ? TImode : DImode))
20705       && CONST_INT_P (operands[2])
20706       && CONST_INT_P (operands[3]))
20707     {
20708       rtx out = operands[0];
20709       HOST_WIDE_INT ct = INTVAL (operands[2]);
20710       HOST_WIDE_INT cf = INTVAL (operands[3]);
20711       HOST_WIDE_INT diff;
20712
20713       diff = ct - cf;
20714       /*  Sign bit compares are better done using shifts than we do by using
20715           sbb.  */
20716       if (sign_bit_compare_p
20717           || ix86_expand_carry_flag_compare (code, op0, op1, &compare_op))
20718         {
20719           /* Detect overlap between destination and compare sources.  */
20720           rtx tmp = out;
20721
20722           if (!sign_bit_compare_p)
20723             {
20724               rtx flags;
20725               bool fpcmp = false;
20726
20727               compare_code = GET_CODE (compare_op);
20728
20729               flags = XEXP (compare_op, 0);
20730
20731               if (GET_MODE (flags) == CCFPmode
20732                   || GET_MODE (flags) == CCFPUmode)
20733                 {
20734                   fpcmp = true;
20735                   compare_code
20736                     = ix86_fp_compare_code_to_integer (compare_code);
20737                 }
20738
20739               /* To simplify rest of code, restrict to the GEU case.  */
20740               if (compare_code == LTU)
20741                 {
20742                   std::swap (ct, cf);
20743                   compare_code = reverse_condition (compare_code);
20744                   code = reverse_condition (code);
20745                 }
20746               else
20747                 {
20748                   if (fpcmp)
20749                     PUT_CODE (compare_op,
20750                               reverse_condition_maybe_unordered
20751                                 (GET_CODE (compare_op)));
20752                   else
20753                     PUT_CODE (compare_op,
20754                               reverse_condition (GET_CODE (compare_op)));
20755                 }
20756               diff = ct - cf;
20757
20758               if (reg_overlap_mentioned_p (out, op0)
20759                   || reg_overlap_mentioned_p (out, op1))
20760                 tmp = gen_reg_rtx (mode);
20761
20762               if (mode == DImode)
20763                 emit_insn (gen_x86_movdicc_0_m1 (tmp, flags, compare_op));
20764               else
20765                 emit_insn (gen_x86_movsicc_0_m1 (gen_lowpart (SImode, tmp),
20766                                                  flags, compare_op));
20767             }
20768           else
20769             {
20770               if (code == GT || code == GE)
20771                 code = reverse_condition (code);
20772               else
20773                 {
20774                   std::swap (ct, cf);
20775                   diff = ct - cf;
20776                 }
20777               tmp = emit_store_flag (tmp, code, op0, op1, VOIDmode, 0, -1);
20778             }
20779
20780           if (diff == 1)
20781             {
20782               /*
20783                * cmpl op0,op1
20784                * sbbl dest,dest
20785                * [addl dest, ct]
20786                *
20787                * Size 5 - 8.
20788                */
20789               if (ct)
20790                 tmp = expand_simple_binop (mode, PLUS,
20791                                            tmp, GEN_INT (ct),
20792                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
20793             }
20794           else if (cf == -1)
20795             {
20796               /*
20797                * cmpl op0,op1
20798                * sbbl dest,dest
20799                * orl $ct, dest
20800                *
20801                * Size 8.
20802                */
20803               tmp = expand_simple_binop (mode, IOR,
20804                                          tmp, GEN_INT (ct),
20805                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
20806             }
20807           else if (diff == -1 && ct)
20808             {
20809               /*
20810                * cmpl op0,op1
20811                * sbbl dest,dest
20812                * notl dest
20813                * [addl dest, cf]
20814                *
20815                * Size 8 - 11.
20816                */
20817               tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
20818               if (cf)
20819                 tmp = expand_simple_binop (mode, PLUS,
20820                                            copy_rtx (tmp), GEN_INT (cf),
20821                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
20822             }
20823           else
20824             {
20825               /*
20826                * cmpl op0,op1
20827                * sbbl dest,dest
20828                * [notl dest]
20829                * andl cf - ct, dest
20830                * [addl dest, ct]
20831                *
20832                * Size 8 - 11.
20833                */
20834
20835               if (cf == 0)
20836                 {
20837                   cf = ct;
20838                   ct = 0;
20839                   tmp = expand_simple_unop (mode, NOT, tmp, copy_rtx (tmp), 1);
20840                 }
20841
20842               tmp = expand_simple_binop (mode, AND,
20843                                          copy_rtx (tmp),
20844                                          gen_int_mode (cf - ct, mode),
20845                                          copy_rtx (tmp), 1, OPTAB_DIRECT);
20846               if (ct)
20847                 tmp = expand_simple_binop (mode, PLUS,
20848                                            copy_rtx (tmp), GEN_INT (ct),
20849                                            copy_rtx (tmp), 1, OPTAB_DIRECT);
20850             }
20851
20852           if (!rtx_equal_p (tmp, out))
20853             emit_move_insn (copy_rtx (out), copy_rtx (tmp));
20854
20855           return true;
20856         }
20857
20858       if (diff < 0)
20859         {
20860           machine_mode cmp_mode = GET_MODE (op0);
20861           enum rtx_code new_code;
20862
20863           if (SCALAR_FLOAT_MODE_P (cmp_mode))
20864             {
20865               gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
20866
20867               /* We may be reversing unordered compare to normal compare, that
20868                  is not valid in general (we may convert non-trapping condition
20869                  to trapping one), however on i386 we currently emit all
20870                  comparisons unordered.  */
20871               new_code = reverse_condition_maybe_unordered (code);
20872             }
20873           else
20874             new_code = ix86_reverse_condition (code, cmp_mode);
20875           if (new_code != UNKNOWN)
20876             {
20877               std::swap (ct, cf);
20878               diff = -diff;
20879               code = new_code;
20880             }
20881         }
20882
20883       compare_code = UNKNOWN;
20884       if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_INT
20885           && CONST_INT_P (op1))
20886         {
20887           if (op1 == const0_rtx
20888               && (code == LT || code == GE))
20889             compare_code = code;
20890           else if (op1 == constm1_rtx)
20891             {
20892               if (code == LE)
20893                 compare_code = LT;
20894               else if (code == GT)
20895                 compare_code = GE;
20896             }
20897         }
20898
20899       /* Optimize dest = (op0 < 0) ? -1 : cf.  */
20900       if (compare_code != UNKNOWN
20901           && GET_MODE (op0) == GET_MODE (out)
20902           && (cf == -1 || ct == -1))
20903         {
20904           /* If lea code below could be used, only optimize
20905              if it results in a 2 insn sequence.  */
20906
20907           if (! (diff == 1 || diff == 2 || diff == 4 || diff == 8
20908                  || diff == 3 || diff == 5 || diff == 9)
20909               || (compare_code == LT && ct == -1)
20910               || (compare_code == GE && cf == -1))
20911             {
20912               /*
20913                * notl op1       (if necessary)
20914                * sarl $31, op1
20915                * orl cf, op1
20916                */
20917               if (ct != -1)
20918                 {
20919                   cf = ct;
20920                   ct = -1;
20921                   code = reverse_condition (code);
20922                 }
20923
20924               out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, -1);
20925
20926               out = expand_simple_binop (mode, IOR,
20927                                          out, GEN_INT (cf),
20928                                          out, 1, OPTAB_DIRECT);
20929               if (out != operands[0])
20930                 emit_move_insn (operands[0], out);
20931
20932               return true;
20933             }
20934         }
20935
20936
20937       if ((diff == 1 || diff == 2 || diff == 4 || diff == 8
20938            || diff == 3 || diff == 5 || diff == 9)
20939           && ((mode != QImode && mode != HImode) || !TARGET_PARTIAL_REG_STALL)
20940           && (mode != DImode
20941               || x86_64_immediate_operand (GEN_INT (cf), VOIDmode)))
20942         {
20943           /*
20944            * xorl dest,dest
20945            * cmpl op1,op2
20946            * setcc dest
20947            * lea cf(dest*(ct-cf)),dest
20948            *
20949            * Size 14.
20950            *
20951            * This also catches the degenerate setcc-only case.
20952            */
20953
20954           rtx tmp;
20955           int nops;
20956
20957           out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, 1);
20958
20959           nops = 0;
20960           /* On x86_64 the lea instruction operates on Pmode, so we need
20961              to get arithmetics done in proper mode to match.  */
20962           if (diff == 1)
20963             tmp = copy_rtx (out);
20964           else
20965             {
20966               rtx out1;
20967               out1 = copy_rtx (out);
20968               tmp = gen_rtx_MULT (mode, out1, GEN_INT (diff & ~1));
20969               nops++;
20970               if (diff & 1)
20971                 {
20972                   tmp = gen_rtx_PLUS (mode, tmp, out1);
20973                   nops++;
20974                 }
20975             }
20976           if (cf != 0)
20977             {
20978               tmp = gen_rtx_PLUS (mode, tmp, GEN_INT (cf));
20979               nops++;
20980             }
20981           if (!rtx_equal_p (tmp, out))
20982             {
20983               if (nops == 1)
20984                 out = force_operand (tmp, copy_rtx (out));
20985               else
20986                 emit_insn (gen_rtx_SET (VOIDmode, copy_rtx (out), copy_rtx (tmp)));
20987             }
20988           if (!rtx_equal_p (out, operands[0]))
20989             emit_move_insn (operands[0], copy_rtx (out));
20990
20991           return true;
20992         }
20993
20994       /*
20995        * General case:                  Jumpful:
20996        *   xorl dest,dest               cmpl op1, op2
20997        *   cmpl op1, op2                movl ct, dest
20998        *   setcc dest                   jcc 1f
20999        *   decl dest                    movl cf, dest
21000        *   andl (cf-ct),dest            1:
21001        *   addl ct,dest
21002        *
21003        * Size 20.                       Size 14.
21004        *
21005        * This is reasonably steep, but branch mispredict costs are
21006        * high on modern cpus, so consider failing only if optimizing
21007        * for space.
21008        */
21009
21010       if ((!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
21011           && BRANCH_COST (optimize_insn_for_speed_p (),
21012                           false) >= 2)
21013         {
21014           if (cf == 0)
21015             {
21016               machine_mode cmp_mode = GET_MODE (op0);
21017               enum rtx_code new_code;
21018
21019               if (SCALAR_FLOAT_MODE_P (cmp_mode))
21020                 {
21021                   gcc_assert (!DECIMAL_FLOAT_MODE_P (cmp_mode));
21022
21023                   /* We may be reversing unordered compare to normal compare,
21024                      that is not valid in general (we may convert non-trapping
21025                      condition to trapping one), however on i386 we currently
21026                      emit all comparisons unordered.  */
21027                   new_code = reverse_condition_maybe_unordered (code);
21028                 }
21029               else
21030                 {
21031                   new_code = ix86_reverse_condition (code, cmp_mode);
21032                   if (compare_code != UNKNOWN && new_code != UNKNOWN)
21033                     compare_code = reverse_condition (compare_code);
21034                 }
21035
21036               if (new_code != UNKNOWN)
21037                 {
21038                   cf = ct;
21039                   ct = 0;
21040                   code = new_code;
21041                 }
21042             }
21043
21044           if (compare_code != UNKNOWN)
21045             {
21046               /* notl op1       (if needed)
21047                  sarl $31, op1
21048                  andl (cf-ct), op1
21049                  addl ct, op1
21050
21051                  For x < 0 (resp. x <= -1) there will be no notl,
21052                  so if possible swap the constants to get rid of the
21053                  complement.
21054                  True/false will be -1/0 while code below (store flag
21055                  followed by decrement) is 0/-1, so the constants need
21056                  to be exchanged once more.  */
21057
21058               if (compare_code == GE || !cf)
21059                 {
21060                   code = reverse_condition (code);
21061                   compare_code = LT;
21062                 }
21063               else
21064                 std::swap (ct, cf);
21065
21066               out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, -1);
21067             }
21068           else
21069             {
21070               out = emit_store_flag (out, code, op0, op1, VOIDmode, 0, 1);
21071
21072               out = expand_simple_binop (mode, PLUS, copy_rtx (out),
21073                                          constm1_rtx,
21074                                          copy_rtx (out), 1, OPTAB_DIRECT);
21075             }
21076
21077           out = expand_simple_binop (mode, AND, copy_rtx (out),
21078                                      gen_int_mode (cf - ct, mode),
21079                                      copy_rtx (out), 1, OPTAB_DIRECT);
21080           if (ct)
21081             out = expand_simple_binop (mode, PLUS, copy_rtx (out), GEN_INT (ct),
21082                                        copy_rtx (out), 1, OPTAB_DIRECT);
21083           if (!rtx_equal_p (out, operands[0]))
21084             emit_move_insn (operands[0], copy_rtx (out));
21085
21086           return true;
21087         }
21088     }
21089
21090   if (!TARGET_CMOVE || (mode == QImode && TARGET_PARTIAL_REG_STALL))
21091     {
21092       /* Try a few things more with specific constants and a variable.  */
21093
21094       optab op;
21095       rtx var, orig_out, out, tmp;
21096
21097       if (BRANCH_COST (optimize_insn_for_speed_p (), false) <= 2)
21098         return false;
21099
21100       /* If one of the two operands is an interesting constant, load a
21101          constant with the above and mask it in with a logical operation.  */
21102
21103       if (CONST_INT_P (operands[2]))
21104         {
21105           var = operands[3];
21106           if (INTVAL (operands[2]) == 0 && operands[3] != constm1_rtx)
21107             operands[3] = constm1_rtx, op = and_optab;
21108           else if (INTVAL (operands[2]) == -1 && operands[3] != const0_rtx)
21109             operands[3] = const0_rtx, op = ior_optab;
21110           else
21111             return false;
21112         }
21113       else if (CONST_INT_P (operands[3]))
21114         {
21115           var = operands[2];
21116           if (INTVAL (operands[3]) == 0 && operands[2] != constm1_rtx)
21117             operands[2] = constm1_rtx, op = and_optab;
21118           else if (INTVAL (operands[3]) == -1 && operands[3] != const0_rtx)
21119             operands[2] = const0_rtx, op = ior_optab;
21120           else
21121             return false;
21122         }
21123       else
21124         return false;
21125
21126       orig_out = operands[0];
21127       tmp = gen_reg_rtx (mode);
21128       operands[0] = tmp;
21129
21130       /* Recurse to get the constant loaded.  */
21131       if (ix86_expand_int_movcc (operands) == 0)
21132         return false;
21133
21134       /* Mask in the interesting variable.  */
21135       out = expand_binop (mode, op, var, tmp, orig_out, 0,
21136                           OPTAB_WIDEN);
21137       if (!rtx_equal_p (out, orig_out))
21138         emit_move_insn (copy_rtx (orig_out), copy_rtx (out));
21139
21140       return true;
21141     }
21142
21143   /*
21144    * For comparison with above,
21145    *
21146    * movl cf,dest
21147    * movl ct,tmp
21148    * cmpl op1,op2
21149    * cmovcc tmp,dest
21150    *
21151    * Size 15.
21152    */
21153
21154   if (! nonimmediate_operand (operands[2], mode))
21155     operands[2] = force_reg (mode, operands[2]);
21156   if (! nonimmediate_operand (operands[3], mode))
21157     operands[3] = force_reg (mode, operands[3]);
21158
21159   if (! register_operand (operands[2], VOIDmode)
21160       && (mode == QImode
21161           || ! register_operand (operands[3], VOIDmode)))
21162     operands[2] = force_reg (mode, operands[2]);
21163
21164   if (mode == QImode
21165       && ! register_operand (operands[3], VOIDmode))
21166     operands[3] = force_reg (mode, operands[3]);
21167
21168   emit_insn (compare_seq);
21169   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
21170                           gen_rtx_IF_THEN_ELSE (mode,
21171                                                 compare_op, operands[2],
21172                                                 operands[3])));
21173   return true;
21174 }
21175
21176 /* Swap, force into registers, or otherwise massage the two operands
21177    to an sse comparison with a mask result.  Thus we differ a bit from
21178    ix86_prepare_fp_compare_args which expects to produce a flags result.
21179
21180    The DEST operand exists to help determine whether to commute commutative
21181    operators.  The POP0/POP1 operands are updated in place.  The new
21182    comparison code is returned, or UNKNOWN if not implementable.  */
21183
21184 static enum rtx_code
21185 ix86_prepare_sse_fp_compare_args (rtx dest, enum rtx_code code,
21186                                   rtx *pop0, rtx *pop1)
21187 {
21188   switch (code)
21189     {
21190     case LTGT:
21191     case UNEQ:
21192       /* AVX supports all the needed comparisons.  */
21193       if (TARGET_AVX)
21194         break;
21195       /* We have no LTGT as an operator.  We could implement it with
21196          NE & ORDERED, but this requires an extra temporary.  It's
21197          not clear that it's worth it.  */
21198       return UNKNOWN;
21199
21200     case LT:
21201     case LE:
21202     case UNGT:
21203     case UNGE:
21204       /* These are supported directly.  */
21205       break;
21206
21207     case EQ:
21208     case NE:
21209     case UNORDERED:
21210     case ORDERED:
21211       /* AVX has 3 operand comparisons, no need to swap anything.  */
21212       if (TARGET_AVX)
21213         break;
21214       /* For commutative operators, try to canonicalize the destination
21215          operand to be first in the comparison - this helps reload to
21216          avoid extra moves.  */
21217       if (!dest || !rtx_equal_p (dest, *pop1))
21218         break;
21219       /* FALLTHRU */
21220
21221     case GE:
21222     case GT:
21223     case UNLE:
21224     case UNLT:
21225       /* These are not supported directly before AVX, and furthermore
21226          ix86_expand_sse_fp_minmax only optimizes LT/UNGE.  Swap the
21227          comparison operands to transform into something that is
21228          supported.  */
21229       std::swap (*pop0, *pop1);
21230       code = swap_condition (code);
21231       break;
21232
21233     default:
21234       gcc_unreachable ();
21235     }
21236
21237   return code;
21238 }
21239
21240 /* Detect conditional moves that exactly match min/max operational
21241    semantics.  Note that this is IEEE safe, as long as we don't
21242    interchange the operands.
21243
21244    Returns FALSE if this conditional move doesn't match a MIN/MAX,
21245    and TRUE if the operation is successful and instructions are emitted.  */
21246
21247 static bool
21248 ix86_expand_sse_fp_minmax (rtx dest, enum rtx_code code, rtx cmp_op0,
21249                            rtx cmp_op1, rtx if_true, rtx if_false)
21250 {
21251   machine_mode mode;
21252   bool is_min;
21253   rtx tmp;
21254
21255   if (code == LT)
21256     ;
21257   else if (code == UNGE)
21258     std::swap (if_true, if_false);
21259   else
21260     return false;
21261
21262   if (rtx_equal_p (cmp_op0, if_true) && rtx_equal_p (cmp_op1, if_false))
21263     is_min = true;
21264   else if (rtx_equal_p (cmp_op1, if_true) && rtx_equal_p (cmp_op0, if_false))
21265     is_min = false;
21266   else
21267     return false;
21268
21269   mode = GET_MODE (dest);
21270
21271   /* We want to check HONOR_NANS and HONOR_SIGNED_ZEROS here,
21272      but MODE may be a vector mode and thus not appropriate.  */
21273   if (!flag_finite_math_only || !flag_unsafe_math_optimizations)
21274     {
21275       int u = is_min ? UNSPEC_IEEE_MIN : UNSPEC_IEEE_MAX;
21276       rtvec v;
21277
21278       if_true = force_reg (mode, if_true);
21279       v = gen_rtvec (2, if_true, if_false);
21280       tmp = gen_rtx_UNSPEC (mode, v, u);
21281     }
21282   else
21283     {
21284       code = is_min ? SMIN : SMAX;
21285       tmp = gen_rtx_fmt_ee (code, mode, if_true, if_false);
21286     }
21287
21288   emit_insn (gen_rtx_SET (VOIDmode, dest, tmp));
21289   return true;
21290 }
21291
21292 /* Expand an sse vector comparison.  Return the register with the result.  */
21293
21294 static rtx
21295 ix86_expand_sse_cmp (rtx dest, enum rtx_code code, rtx cmp_op0, rtx cmp_op1,
21296                      rtx op_true, rtx op_false)
21297 {
21298   machine_mode mode = GET_MODE (dest);
21299   machine_mode cmp_ops_mode = GET_MODE (cmp_op0);
21300
21301   /* In general case result of comparison can differ from operands' type.  */
21302   machine_mode cmp_mode;
21303
21304   /* In AVX512F the result of comparison is an integer mask.  */
21305   bool maskcmp = false;
21306   rtx x;
21307
21308   if (GET_MODE_SIZE (cmp_ops_mode) == 64)
21309     {
21310       cmp_mode = mode_for_size (GET_MODE_NUNITS (cmp_ops_mode), MODE_INT, 0);
21311       gcc_assert (cmp_mode != BLKmode);
21312
21313       maskcmp = true;
21314     }
21315   else
21316     cmp_mode = cmp_ops_mode;
21317
21318
21319   cmp_op0 = force_reg (cmp_ops_mode, cmp_op0);
21320   if (!nonimmediate_operand (cmp_op1, cmp_ops_mode))
21321     cmp_op1 = force_reg (cmp_ops_mode, cmp_op1);
21322
21323   if (optimize
21324       || reg_overlap_mentioned_p (dest, op_true)
21325       || reg_overlap_mentioned_p (dest, op_false))
21326     dest = gen_reg_rtx (maskcmp ? cmp_mode : mode);
21327
21328   /* Compare patterns for int modes are unspec in AVX512F only.  */
21329   if (maskcmp && (code == GT || code == EQ))
21330     {
21331       rtx (*gen)(rtx, rtx, rtx);
21332
21333       switch (cmp_ops_mode)
21334         {
21335         case V64QImode:
21336           gcc_assert (TARGET_AVX512BW);
21337           gen = code == GT ? gen_avx512bw_gtv64qi3 : gen_avx512bw_eqv64qi3_1;
21338           break;
21339         case V32HImode:
21340           gcc_assert (TARGET_AVX512BW);
21341           gen = code == GT ? gen_avx512bw_gtv32hi3 : gen_avx512bw_eqv32hi3_1;
21342           break;
21343         case V16SImode:
21344           gen = code == GT ? gen_avx512f_gtv16si3 : gen_avx512f_eqv16si3_1;
21345           break;
21346         case V8DImode:
21347           gen = code == GT ? gen_avx512f_gtv8di3 : gen_avx512f_eqv8di3_1;
21348           break;
21349         default:
21350           gen = NULL;
21351         }
21352
21353       if (gen)
21354         {
21355           emit_insn (gen (dest, cmp_op0, cmp_op1));
21356           return dest;
21357         }
21358     }
21359   x = gen_rtx_fmt_ee (code, cmp_mode, cmp_op0, cmp_op1);
21360
21361   if (cmp_mode != mode && !maskcmp)
21362     {
21363       x = force_reg (cmp_ops_mode, x);
21364       convert_move (dest, x, false);
21365     }
21366   else
21367     emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21368
21369   return dest;
21370 }
21371
21372 /* Expand DEST = CMP ? OP_TRUE : OP_FALSE into a sequence of logical
21373    operations.  This is used for both scalar and vector conditional moves.  */
21374
21375 static void
21376 ix86_expand_sse_movcc (rtx dest, rtx cmp, rtx op_true, rtx op_false)
21377 {
21378   machine_mode mode = GET_MODE (dest);
21379   machine_mode cmpmode = GET_MODE (cmp);
21380
21381   /* In AVX512F the result of comparison is an integer mask.  */
21382   bool maskcmp = (mode != cmpmode && TARGET_AVX512F);
21383
21384   rtx t2, t3, x;
21385
21386   if (vector_all_ones_operand (op_true, mode)
21387       && rtx_equal_p (op_false, CONST0_RTX (mode))
21388       && !maskcmp)
21389     {
21390       emit_insn (gen_rtx_SET (VOIDmode, dest, cmp));
21391     }
21392   else if (op_false == CONST0_RTX (mode)
21393       && !maskcmp)
21394     {
21395       op_true = force_reg (mode, op_true);
21396       x = gen_rtx_AND (mode, cmp, op_true);
21397       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21398     }
21399   else if (op_true == CONST0_RTX (mode)
21400       && !maskcmp)
21401     {
21402       op_false = force_reg (mode, op_false);
21403       x = gen_rtx_NOT (mode, cmp);
21404       x = gen_rtx_AND (mode, x, op_false);
21405       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21406     }
21407   else if (INTEGRAL_MODE_P (mode) && op_true == CONSTM1_RTX (mode)
21408       && !maskcmp)
21409     {
21410       op_false = force_reg (mode, op_false);
21411       x = gen_rtx_IOR (mode, cmp, op_false);
21412       emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21413     }
21414   else if (TARGET_XOP
21415       && !maskcmp)
21416     {
21417       op_true = force_reg (mode, op_true);
21418
21419       if (!nonimmediate_operand (op_false, mode))
21420         op_false = force_reg (mode, op_false);
21421
21422       emit_insn (gen_rtx_SET (mode, dest,
21423                               gen_rtx_IF_THEN_ELSE (mode, cmp,
21424                                                     op_true,
21425                                                     op_false)));
21426     }
21427   else
21428     {
21429       rtx (*gen) (rtx, rtx, rtx, rtx) = NULL;
21430       rtx d = dest;
21431
21432       if (!nonimmediate_operand (op_true, mode))
21433         op_true = force_reg (mode, op_true);
21434
21435       op_false = force_reg (mode, op_false);
21436
21437       switch (mode)
21438         {
21439         case V4SFmode:
21440           if (TARGET_SSE4_1)
21441             gen = gen_sse4_1_blendvps;
21442           break;
21443         case V2DFmode:
21444           if (TARGET_SSE4_1)
21445             gen = gen_sse4_1_blendvpd;
21446           break;
21447         case V16QImode:
21448         case V8HImode:
21449         case V4SImode:
21450         case V2DImode:
21451           if (TARGET_SSE4_1)
21452             {
21453               gen = gen_sse4_1_pblendvb;
21454               if (mode != V16QImode)
21455                 d = gen_reg_rtx (V16QImode);
21456               op_false = gen_lowpart (V16QImode, op_false);
21457               op_true = gen_lowpart (V16QImode, op_true);
21458               cmp = gen_lowpart (V16QImode, cmp);
21459             }
21460           break;
21461         case V8SFmode:
21462           if (TARGET_AVX)
21463             gen = gen_avx_blendvps256;
21464           break;
21465         case V4DFmode:
21466           if (TARGET_AVX)
21467             gen = gen_avx_blendvpd256;
21468           break;
21469         case V32QImode:
21470         case V16HImode:
21471         case V8SImode:
21472         case V4DImode:
21473           if (TARGET_AVX2)
21474             {
21475               gen = gen_avx2_pblendvb;
21476               if (mode != V32QImode)
21477                 d = gen_reg_rtx (V32QImode);
21478               op_false = gen_lowpart (V32QImode, op_false);
21479               op_true = gen_lowpart (V32QImode, op_true);
21480               cmp = gen_lowpart (V32QImode, cmp);
21481             }
21482           break;
21483
21484         case V64QImode:
21485           gen = gen_avx512bw_blendmv64qi;
21486           break;
21487         case V32HImode:
21488           gen = gen_avx512bw_blendmv32hi;
21489           break;
21490         case V16SImode:
21491           gen = gen_avx512f_blendmv16si;
21492           break;
21493         case V8DImode:
21494           gen = gen_avx512f_blendmv8di;
21495           break;
21496         case V8DFmode:
21497           gen = gen_avx512f_blendmv8df;
21498           break;
21499         case V16SFmode:
21500           gen = gen_avx512f_blendmv16sf;
21501           break;
21502
21503         default:
21504           break;
21505         }
21506
21507       if (gen != NULL)
21508         {
21509           emit_insn (gen (d, op_false, op_true, cmp));
21510           if (d != dest)
21511             emit_move_insn (dest, gen_lowpart (GET_MODE (dest), d));
21512         }
21513       else
21514         {
21515           op_true = force_reg (mode, op_true);
21516
21517           t2 = gen_reg_rtx (mode);
21518           if (optimize)
21519             t3 = gen_reg_rtx (mode);
21520           else
21521             t3 = dest;
21522
21523           x = gen_rtx_AND (mode, op_true, cmp);
21524           emit_insn (gen_rtx_SET (VOIDmode, t2, x));
21525
21526           x = gen_rtx_NOT (mode, cmp);
21527           x = gen_rtx_AND (mode, x, op_false);
21528           emit_insn (gen_rtx_SET (VOIDmode, t3, x));
21529
21530           x = gen_rtx_IOR (mode, t3, t2);
21531           emit_insn (gen_rtx_SET (VOIDmode, dest, x));
21532         }
21533     }
21534 }
21535
21536 /* Expand a floating-point conditional move.  Return true if successful.  */
21537
21538 bool
21539 ix86_expand_fp_movcc (rtx operands[])
21540 {
21541   machine_mode mode = GET_MODE (operands[0]);
21542   enum rtx_code code = GET_CODE (operands[1]);
21543   rtx tmp, compare_op;
21544   rtx op0 = XEXP (operands[1], 0);
21545   rtx op1 = XEXP (operands[1], 1);
21546
21547   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
21548     {
21549       machine_mode cmode;
21550
21551       /* Since we've no cmove for sse registers, don't force bad register
21552          allocation just to gain access to it.  Deny movcc when the
21553          comparison mode doesn't match the move mode.  */
21554       cmode = GET_MODE (op0);
21555       if (cmode == VOIDmode)
21556         cmode = GET_MODE (op1);
21557       if (cmode != mode)
21558         return false;
21559
21560       code = ix86_prepare_sse_fp_compare_args (operands[0], code, &op0, &op1);
21561       if (code == UNKNOWN)
21562         return false;
21563
21564       if (ix86_expand_sse_fp_minmax (operands[0], code, op0, op1,
21565                                      operands[2], operands[3]))
21566         return true;
21567
21568       tmp = ix86_expand_sse_cmp (operands[0], code, op0, op1,
21569                                  operands[2], operands[3]);
21570       ix86_expand_sse_movcc (operands[0], tmp, operands[2], operands[3]);
21571       return true;
21572     }
21573
21574   if (GET_MODE (op0) == TImode
21575       || (GET_MODE (op0) == DImode
21576           && !TARGET_64BIT))
21577     return false;
21578
21579   /* The floating point conditional move instructions don't directly
21580      support conditions resulting from a signed integer comparison.  */
21581
21582   compare_op = ix86_expand_compare (code, op0, op1);
21583   if (!fcmov_comparison_operator (compare_op, VOIDmode))
21584     {
21585       tmp = gen_reg_rtx (QImode);
21586       ix86_expand_setcc (tmp, code, op0, op1);
21587
21588       compare_op = ix86_expand_compare (NE, tmp, const0_rtx);
21589     }
21590
21591   emit_insn (gen_rtx_SET (VOIDmode, operands[0],
21592                           gen_rtx_IF_THEN_ELSE (mode, compare_op,
21593                                                 operands[2], operands[3])));
21594
21595   return true;
21596 }
21597
21598 /* Expand a floating-point vector conditional move; a vcond operation
21599    rather than a movcc operation.  */
21600
21601 bool
21602 ix86_expand_fp_vcond (rtx operands[])
21603 {
21604   enum rtx_code code = GET_CODE (operands[3]);
21605   rtx cmp;
21606
21607   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
21608                                            &operands[4], &operands[5]);
21609   if (code == UNKNOWN)
21610     {
21611       rtx temp;
21612       switch (GET_CODE (operands[3]))
21613         {
21614         case LTGT:
21615           temp = ix86_expand_sse_cmp (operands[0], ORDERED, operands[4],
21616                                       operands[5], operands[0], operands[0]);
21617           cmp = ix86_expand_sse_cmp (operands[0], NE, operands[4],
21618                                      operands[5], operands[1], operands[2]);
21619           code = AND;
21620           break;
21621         case UNEQ:
21622           temp = ix86_expand_sse_cmp (operands[0], UNORDERED, operands[4],
21623                                       operands[5], operands[0], operands[0]);
21624           cmp = ix86_expand_sse_cmp (operands[0], EQ, operands[4],
21625                                      operands[5], operands[1], operands[2]);
21626           code = IOR;
21627           break;
21628         default:
21629           gcc_unreachable ();
21630         }
21631       cmp = expand_simple_binop (GET_MODE (cmp), code, temp, cmp, cmp, 1,
21632                                  OPTAB_DIRECT);
21633       ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
21634       return true;
21635     }
21636
21637   if (ix86_expand_sse_fp_minmax (operands[0], code, operands[4],
21638                                  operands[5], operands[1], operands[2]))
21639     return true;
21640
21641   cmp = ix86_expand_sse_cmp (operands[0], code, operands[4], operands[5],
21642                              operands[1], operands[2]);
21643   ix86_expand_sse_movcc (operands[0], cmp, operands[1], operands[2]);
21644   return true;
21645 }
21646
21647 /* Expand a signed/unsigned integral vector conditional move.  */
21648
21649 bool
21650 ix86_expand_int_vcond (rtx operands[])
21651 {
21652   machine_mode data_mode = GET_MODE (operands[0]);
21653   machine_mode mode = GET_MODE (operands[4]);
21654   enum rtx_code code = GET_CODE (operands[3]);
21655   bool negate = false;
21656   rtx x, cop0, cop1;
21657
21658   cop0 = operands[4];
21659   cop1 = operands[5];
21660
21661   /* Try to optimize x < 0 ? -1 : 0 into (signed) x >> 31
21662      and x < 0 ? 1 : 0 into (unsigned) x >> 31.  */
21663   if ((code == LT || code == GE)
21664       && data_mode == mode
21665       && cop1 == CONST0_RTX (mode)
21666       && operands[1 + (code == LT)] == CONST0_RTX (data_mode)
21667       && GET_MODE_SIZE (GET_MODE_INNER (data_mode)) > 1
21668       && GET_MODE_SIZE (GET_MODE_INNER (data_mode)) <= 8
21669       && (GET_MODE_SIZE (data_mode) == 16
21670           || (TARGET_AVX2 && GET_MODE_SIZE (data_mode) == 32)))
21671     {
21672       rtx negop = operands[2 - (code == LT)];
21673       int shift = GET_MODE_BITSIZE (GET_MODE_INNER (data_mode)) - 1;
21674       if (negop == CONST1_RTX (data_mode))
21675         {
21676           rtx res = expand_simple_binop (mode, LSHIFTRT, cop0, GEN_INT (shift),
21677                                          operands[0], 1, OPTAB_DIRECT);
21678           if (res != operands[0])
21679             emit_move_insn (operands[0], res);
21680           return true;
21681         }
21682       else if (GET_MODE_INNER (data_mode) != DImode
21683                && vector_all_ones_operand (negop, data_mode))
21684         {
21685           rtx res = expand_simple_binop (mode, ASHIFTRT, cop0, GEN_INT (shift),
21686                                          operands[0], 0, OPTAB_DIRECT);
21687           if (res != operands[0])
21688             emit_move_insn (operands[0], res);
21689           return true;
21690         }
21691     }
21692
21693   if (!nonimmediate_operand (cop1, mode))
21694     cop1 = force_reg (mode, cop1);
21695   if (!general_operand (operands[1], data_mode))
21696     operands[1] = force_reg (data_mode, operands[1]);
21697   if (!general_operand (operands[2], data_mode))
21698     operands[2] = force_reg (data_mode, operands[2]);
21699
21700   /* XOP supports all of the comparisons on all 128-bit vector int types.  */
21701   if (TARGET_XOP
21702       && (mode == V16QImode || mode == V8HImode
21703           || mode == V4SImode || mode == V2DImode))
21704     ;
21705   else
21706     {
21707       /* Canonicalize the comparison to EQ, GT, GTU.  */
21708       switch (code)
21709         {
21710         case EQ:
21711         case GT:
21712         case GTU:
21713           break;
21714
21715         case NE:
21716         case LE:
21717         case LEU:
21718           code = reverse_condition (code);
21719           negate = true;
21720           break;
21721
21722         case GE:
21723         case GEU:
21724           code = reverse_condition (code);
21725           negate = true;
21726           /* FALLTHRU */
21727
21728         case LT:
21729         case LTU:
21730           std::swap (cop0, cop1);
21731           code = swap_condition (code);
21732           break;
21733
21734         default:
21735           gcc_unreachable ();
21736         }
21737
21738       /* Only SSE4.1/SSE4.2 supports V2DImode.  */
21739       if (mode == V2DImode)
21740         {
21741           switch (code)
21742             {
21743             case EQ:
21744               /* SSE4.1 supports EQ.  */
21745               if (!TARGET_SSE4_1)
21746                 return false;
21747               break;
21748
21749             case GT:
21750             case GTU:
21751               /* SSE4.2 supports GT/GTU.  */
21752               if (!TARGET_SSE4_2)
21753                 return false;
21754               break;
21755
21756             default:
21757               gcc_unreachable ();
21758             }
21759         }
21760
21761       /* Unsigned parallel compare is not supported by the hardware.
21762          Play some tricks to turn this into a signed comparison
21763          against 0.  */
21764       if (code == GTU)
21765         {
21766           cop0 = force_reg (mode, cop0);
21767
21768           switch (mode)
21769             {
21770             case V16SImode:
21771             case V8DImode:
21772             case V8SImode:
21773             case V4DImode:
21774             case V4SImode:
21775             case V2DImode:
21776                 {
21777                   rtx t1, t2, mask;
21778                   rtx (*gen_sub3) (rtx, rtx, rtx);
21779
21780                   switch (mode)
21781                     {
21782                     case V16SImode: gen_sub3 = gen_subv16si3; break;
21783                     case V8DImode: gen_sub3 = gen_subv8di3; break;
21784                     case V8SImode: gen_sub3 = gen_subv8si3; break;
21785                     case V4DImode: gen_sub3 = gen_subv4di3; break;
21786                     case V4SImode: gen_sub3 = gen_subv4si3; break;
21787                     case V2DImode: gen_sub3 = gen_subv2di3; break;
21788                     default:
21789                       gcc_unreachable ();
21790                     }
21791                   /* Subtract (-(INT MAX) - 1) from both operands to make
21792                      them signed.  */
21793                   mask = ix86_build_signbit_mask (mode, true, false);
21794                   t1 = gen_reg_rtx (mode);
21795                   emit_insn (gen_sub3 (t1, cop0, mask));
21796
21797                   t2 = gen_reg_rtx (mode);
21798                   emit_insn (gen_sub3 (t2, cop1, mask));
21799
21800                   cop0 = t1;
21801                   cop1 = t2;
21802                   code = GT;
21803                 }
21804               break;
21805
21806             case V64QImode:
21807             case V32HImode:
21808             case V32QImode:
21809             case V16HImode:
21810             case V16QImode:
21811             case V8HImode:
21812               /* Perform a parallel unsigned saturating subtraction.  */
21813               x = gen_reg_rtx (mode);
21814               emit_insn (gen_rtx_SET (VOIDmode, x,
21815                                       gen_rtx_US_MINUS (mode, cop0, cop1)));
21816
21817               cop0 = x;
21818               cop1 = CONST0_RTX (mode);
21819               code = EQ;
21820               negate = !negate;
21821               break;
21822
21823             default:
21824               gcc_unreachable ();
21825             }
21826         }
21827     }
21828
21829   /* Allow the comparison to be done in one mode, but the movcc to
21830      happen in another mode.  */
21831   if (data_mode == mode)
21832     {
21833       x = ix86_expand_sse_cmp (operands[0], code, cop0, cop1,
21834                                operands[1+negate], operands[2-negate]);
21835     }
21836   else
21837     {
21838       gcc_assert (GET_MODE_SIZE (data_mode) == GET_MODE_SIZE (mode));
21839       x = ix86_expand_sse_cmp (gen_reg_rtx (mode), code, cop0, cop1,
21840                                operands[1+negate], operands[2-negate]);
21841       if (GET_MODE (x) == mode)
21842         x = gen_lowpart (data_mode, x);
21843     }
21844
21845   ix86_expand_sse_movcc (operands[0], x, operands[1+negate],
21846                          operands[2-negate]);
21847   return true;
21848 }
21849
21850 /* AVX512F does support 64-byte integer vector operations,
21851    thus the longest vector we are faced with is V64QImode.  */
21852 #define MAX_VECT_LEN    64
21853
21854 struct expand_vec_perm_d
21855 {
21856   rtx target, op0, op1;
21857   unsigned char perm[MAX_VECT_LEN];
21858   machine_mode vmode;
21859   unsigned char nelt;
21860   bool one_operand_p;
21861   bool testing_p;
21862 };
21863
21864 static bool
21865 ix86_expand_vec_perm_vpermi2 (rtx target, rtx op0, rtx mask, rtx op1,
21866                               struct expand_vec_perm_d *d)
21867 {
21868   /* ix86_expand_vec_perm_vpermi2 is called from both const and non-const
21869      expander, so args are either in d, or in op0, op1 etc.  */
21870   machine_mode mode = GET_MODE (d ? d->op0 : op0);
21871   machine_mode maskmode = mode;
21872   rtx (*gen) (rtx, rtx, rtx, rtx) = NULL;
21873
21874   switch (mode)
21875     {
21876     case V8HImode:
21877       if (TARGET_AVX512VL && TARGET_AVX512BW)
21878         gen = gen_avx512vl_vpermi2varv8hi3;
21879       break;
21880     case V16HImode:
21881       if (TARGET_AVX512VL && TARGET_AVX512BW)
21882         gen = gen_avx512vl_vpermi2varv16hi3;
21883       break;
21884     case V64QImode:
21885       if (TARGET_AVX512VBMI)
21886         gen = gen_avx512bw_vpermi2varv64qi3;
21887       break;
21888     case V32HImode:
21889       if (TARGET_AVX512BW)
21890         gen = gen_avx512bw_vpermi2varv32hi3;
21891       break;
21892     case V4SImode:
21893       if (TARGET_AVX512VL)
21894         gen = gen_avx512vl_vpermi2varv4si3;
21895       break;
21896     case V8SImode:
21897       if (TARGET_AVX512VL)
21898         gen = gen_avx512vl_vpermi2varv8si3;
21899       break;
21900     case V16SImode:
21901       if (TARGET_AVX512F)
21902         gen = gen_avx512f_vpermi2varv16si3;
21903       break;
21904     case V4SFmode:
21905       if (TARGET_AVX512VL)
21906         {
21907           gen = gen_avx512vl_vpermi2varv4sf3;
21908           maskmode = V4SImode;
21909         }
21910       break;
21911     case V8SFmode:
21912       if (TARGET_AVX512VL)
21913         {
21914           gen = gen_avx512vl_vpermi2varv8sf3;
21915           maskmode = V8SImode;
21916         }
21917       break;
21918     case V16SFmode:
21919       if (TARGET_AVX512F)
21920         {
21921           gen = gen_avx512f_vpermi2varv16sf3;
21922           maskmode = V16SImode;
21923         }
21924       break;
21925     case V2DImode:
21926       if (TARGET_AVX512VL)
21927         gen = gen_avx512vl_vpermi2varv2di3;
21928       break;
21929     case V4DImode:
21930       if (TARGET_AVX512VL)
21931         gen = gen_avx512vl_vpermi2varv4di3;
21932       break;
21933     case V8DImode:
21934       if (TARGET_AVX512F)
21935         gen = gen_avx512f_vpermi2varv8di3;
21936       break;
21937     case V2DFmode:
21938       if (TARGET_AVX512VL)
21939         {
21940           gen = gen_avx512vl_vpermi2varv2df3;
21941           maskmode = V2DImode;
21942         }
21943       break;
21944     case V4DFmode:
21945       if (TARGET_AVX512VL)
21946         {
21947           gen = gen_avx512vl_vpermi2varv4df3;
21948           maskmode = V4DImode;
21949         }
21950       break;
21951     case V8DFmode:
21952       if (TARGET_AVX512F)
21953         {
21954           gen = gen_avx512f_vpermi2varv8df3;
21955           maskmode = V8DImode;
21956         }
21957       break;
21958     default:
21959       break;
21960     }
21961
21962   if (gen == NULL)
21963     return false;
21964
21965   /* ix86_expand_vec_perm_vpermi2 is called from both const and non-const
21966      expander, so args are either in d, or in op0, op1 etc.  */
21967   if (d)
21968     {
21969       rtx vec[64];
21970       target = d->target;
21971       op0 = d->op0;
21972       op1 = d->op1;
21973       for (int i = 0; i < d->nelt; ++i)
21974         vec[i] = GEN_INT (d->perm[i]);
21975       mask = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (d->nelt, vec));
21976     }
21977
21978   emit_insn (gen (target, op0, force_reg (maskmode, mask), op1));
21979   return true;
21980 }
21981
21982 /* Expand a variable vector permutation.  */
21983
21984 void
21985 ix86_expand_vec_perm (rtx operands[])
21986 {
21987   rtx target = operands[0];
21988   rtx op0 = operands[1];
21989   rtx op1 = operands[2];
21990   rtx mask = operands[3];
21991   rtx t1, t2, t3, t4, t5, t6, t7, t8, vt, vt2, vec[32];
21992   machine_mode mode = GET_MODE (op0);
21993   machine_mode maskmode = GET_MODE (mask);
21994   int w, e, i;
21995   bool one_operand_shuffle = rtx_equal_p (op0, op1);
21996
21997   /* Number of elements in the vector.  */
21998   w = GET_MODE_NUNITS (mode);
21999   e = GET_MODE_UNIT_SIZE (mode);
22000   gcc_assert (w <= 64);
22001
22002   if (ix86_expand_vec_perm_vpermi2 (target, op0, mask, op1, NULL))
22003     return;
22004
22005   if (TARGET_AVX2)
22006     {
22007       if (mode == V4DImode || mode == V4DFmode || mode == V16HImode)
22008         {
22009           /* Unfortunately, the VPERMQ and VPERMPD instructions only support
22010              an constant shuffle operand.  With a tiny bit of effort we can
22011              use VPERMD instead.  A re-interpretation stall for V4DFmode is
22012              unfortunate but there's no avoiding it.
22013              Similarly for V16HImode we don't have instructions for variable
22014              shuffling, while for V32QImode we can use after preparing suitable
22015              masks vpshufb; vpshufb; vpermq; vpor.  */
22016
22017           if (mode == V16HImode)
22018             {
22019               maskmode = mode = V32QImode;
22020               w = 32;
22021               e = 1;
22022             }
22023           else
22024             {
22025               maskmode = mode = V8SImode;
22026               w = 8;
22027               e = 4;
22028             }
22029           t1 = gen_reg_rtx (maskmode);
22030
22031           /* Replicate the low bits of the V4DImode mask into V8SImode:
22032                mask = { A B C D }
22033                t1 = { A A B B C C D D }.  */
22034           for (i = 0; i < w / 2; ++i)
22035             vec[i*2 + 1] = vec[i*2] = GEN_INT (i * 2);
22036           vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22037           vt = force_reg (maskmode, vt);
22038           mask = gen_lowpart (maskmode, mask);
22039           if (maskmode == V8SImode)
22040             emit_insn (gen_avx2_permvarv8si (t1, mask, vt));
22041           else
22042             emit_insn (gen_avx2_pshufbv32qi3 (t1, mask, vt));
22043
22044           /* Multiply the shuffle indicies by two.  */
22045           t1 = expand_simple_binop (maskmode, PLUS, t1, t1, t1, 1,
22046                                     OPTAB_DIRECT);
22047
22048           /* Add one to the odd shuffle indicies:
22049                 t1 = { A*2, A*2+1, B*2, B*2+1, ... }.  */
22050           for (i = 0; i < w / 2; ++i)
22051             {
22052               vec[i * 2] = const0_rtx;
22053               vec[i * 2 + 1] = const1_rtx;
22054             }
22055           vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22056           vt = validize_mem (force_const_mem (maskmode, vt));
22057           t1 = expand_simple_binop (maskmode, PLUS, t1, vt, t1, 1,
22058                                     OPTAB_DIRECT);
22059
22060           /* Continue as if V8SImode (resp. V32QImode) was used initially.  */
22061           operands[3] = mask = t1;
22062           target = gen_reg_rtx (mode);
22063           op0 = gen_lowpart (mode, op0);
22064           op1 = gen_lowpart (mode, op1);
22065         }
22066
22067       switch (mode)
22068         {
22069         case V8SImode:
22070           /* The VPERMD and VPERMPS instructions already properly ignore
22071              the high bits of the shuffle elements.  No need for us to
22072              perform an AND ourselves.  */
22073           if (one_operand_shuffle)
22074             {
22075               emit_insn (gen_avx2_permvarv8si (target, op0, mask));
22076               if (target != operands[0])
22077                 emit_move_insn (operands[0],
22078                                 gen_lowpart (GET_MODE (operands[0]), target));
22079             }
22080           else
22081             {
22082               t1 = gen_reg_rtx (V8SImode);
22083               t2 = gen_reg_rtx (V8SImode);
22084               emit_insn (gen_avx2_permvarv8si (t1, op0, mask));
22085               emit_insn (gen_avx2_permvarv8si (t2, op1, mask));
22086               goto merge_two;
22087             }
22088           return;
22089
22090         case V8SFmode:
22091           mask = gen_lowpart (V8SImode, mask);
22092           if (one_operand_shuffle)
22093             emit_insn (gen_avx2_permvarv8sf (target, op0, mask));
22094           else
22095             {
22096               t1 = gen_reg_rtx (V8SFmode);
22097               t2 = gen_reg_rtx (V8SFmode);
22098               emit_insn (gen_avx2_permvarv8sf (t1, op0, mask));
22099               emit_insn (gen_avx2_permvarv8sf (t2, op1, mask));
22100               goto merge_two;
22101             }
22102           return;
22103
22104         case V4SImode:
22105           /* By combining the two 128-bit input vectors into one 256-bit
22106              input vector, we can use VPERMD and VPERMPS for the full
22107              two-operand shuffle.  */
22108           t1 = gen_reg_rtx (V8SImode);
22109           t2 = gen_reg_rtx (V8SImode);
22110           emit_insn (gen_avx_vec_concatv8si (t1, op0, op1));
22111           emit_insn (gen_avx_vec_concatv8si (t2, mask, mask));
22112           emit_insn (gen_avx2_permvarv8si (t1, t1, t2));
22113           emit_insn (gen_avx_vextractf128v8si (target, t1, const0_rtx));
22114           return;
22115
22116         case V4SFmode:
22117           t1 = gen_reg_rtx (V8SFmode);
22118           t2 = gen_reg_rtx (V8SImode);
22119           mask = gen_lowpart (V4SImode, mask);
22120           emit_insn (gen_avx_vec_concatv8sf (t1, op0, op1));
22121           emit_insn (gen_avx_vec_concatv8si (t2, mask, mask));
22122           emit_insn (gen_avx2_permvarv8sf (t1, t1, t2));
22123           emit_insn (gen_avx_vextractf128v8sf (target, t1, const0_rtx));
22124           return;
22125
22126         case V32QImode:
22127           t1 = gen_reg_rtx (V32QImode);
22128           t2 = gen_reg_rtx (V32QImode);
22129           t3 = gen_reg_rtx (V32QImode);
22130           vt2 = GEN_INT (-128);
22131           for (i = 0; i < 32; i++)
22132             vec[i] = vt2;
22133           vt = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, vec));
22134           vt = force_reg (V32QImode, vt);
22135           for (i = 0; i < 32; i++)
22136             vec[i] = i < 16 ? vt2 : const0_rtx;
22137           vt2 = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, vec));
22138           vt2 = force_reg (V32QImode, vt2);
22139           /* From mask create two adjusted masks, which contain the same
22140              bits as mask in the low 7 bits of each vector element.
22141              The first mask will have the most significant bit clear
22142              if it requests element from the same 128-bit lane
22143              and MSB set if it requests element from the other 128-bit lane.
22144              The second mask will have the opposite values of the MSB,
22145              and additionally will have its 128-bit lanes swapped.
22146              E.g. { 07 12 1e 09 ... | 17 19 05 1f ... } mask vector will have
22147              t1   { 07 92 9e 09 ... | 17 19 85 1f ... } and
22148              t3   { 97 99 05 9f ... | 87 12 1e 89 ... } where each ...
22149              stands for other 12 bytes.  */
22150           /* The bit whether element is from the same lane or the other
22151              lane is bit 4, so shift it up by 3 to the MSB position.  */
22152           t5 = gen_reg_rtx (V4DImode);
22153           emit_insn (gen_ashlv4di3 (t5, gen_lowpart (V4DImode, mask),
22154                                     GEN_INT (3)));
22155           /* Clear MSB bits from the mask just in case it had them set.  */
22156           emit_insn (gen_avx2_andnotv32qi3 (t2, vt, mask));
22157           /* After this t1 will have MSB set for elements from other lane.  */
22158           emit_insn (gen_xorv32qi3 (t1, gen_lowpart (V32QImode, t5), vt2));
22159           /* Clear bits other than MSB.  */
22160           emit_insn (gen_andv32qi3 (t1, t1, vt));
22161           /* Or in the lower bits from mask into t3.  */
22162           emit_insn (gen_iorv32qi3 (t3, t1, t2));
22163           /* And invert MSB bits in t1, so MSB is set for elements from the same
22164              lane.  */
22165           emit_insn (gen_xorv32qi3 (t1, t1, vt));
22166           /* Swap 128-bit lanes in t3.  */
22167           t6 = gen_reg_rtx (V4DImode);
22168           emit_insn (gen_avx2_permv4di_1 (t6, gen_lowpart (V4DImode, t3),
22169                                           const2_rtx, GEN_INT (3),
22170                                           const0_rtx, const1_rtx));
22171           /* And or in the lower bits from mask into t1.  */
22172           emit_insn (gen_iorv32qi3 (t1, t1, t2));
22173           if (one_operand_shuffle)
22174             {
22175               /* Each of these shuffles will put 0s in places where
22176                  element from the other 128-bit lane is needed, otherwise
22177                  will shuffle in the requested value.  */
22178               emit_insn (gen_avx2_pshufbv32qi3 (t3, op0,
22179                                                 gen_lowpart (V32QImode, t6)));
22180               emit_insn (gen_avx2_pshufbv32qi3 (t1, op0, t1));
22181               /* For t3 the 128-bit lanes are swapped again.  */
22182               t7 = gen_reg_rtx (V4DImode);
22183               emit_insn (gen_avx2_permv4di_1 (t7, gen_lowpart (V4DImode, t3),
22184                                               const2_rtx, GEN_INT (3),
22185                                               const0_rtx, const1_rtx));
22186               /* And oring both together leads to the result.  */
22187               emit_insn (gen_iorv32qi3 (target, t1,
22188                                         gen_lowpart (V32QImode, t7)));
22189               if (target != operands[0])
22190                 emit_move_insn (operands[0],
22191                                 gen_lowpart (GET_MODE (operands[0]), target));
22192               return;
22193             }
22194
22195           t4 = gen_reg_rtx (V32QImode);
22196           /* Similarly to the above one_operand_shuffle code,
22197              just for repeated twice for each operand.  merge_two:
22198              code will merge the two results together.  */
22199           emit_insn (gen_avx2_pshufbv32qi3 (t4, op0,
22200                                             gen_lowpart (V32QImode, t6)));
22201           emit_insn (gen_avx2_pshufbv32qi3 (t3, op1,
22202                                             gen_lowpart (V32QImode, t6)));
22203           emit_insn (gen_avx2_pshufbv32qi3 (t2, op0, t1));
22204           emit_insn (gen_avx2_pshufbv32qi3 (t1, op1, t1));
22205           t7 = gen_reg_rtx (V4DImode);
22206           emit_insn (gen_avx2_permv4di_1 (t7, gen_lowpart (V4DImode, t4),
22207                                           const2_rtx, GEN_INT (3),
22208                                           const0_rtx, const1_rtx));
22209           t8 = gen_reg_rtx (V4DImode);
22210           emit_insn (gen_avx2_permv4di_1 (t8, gen_lowpart (V4DImode, t3),
22211                                           const2_rtx, GEN_INT (3),
22212                                           const0_rtx, const1_rtx));
22213           emit_insn (gen_iorv32qi3 (t4, t2, gen_lowpart (V32QImode, t7)));
22214           emit_insn (gen_iorv32qi3 (t3, t1, gen_lowpart (V32QImode, t8)));
22215           t1 = t4;
22216           t2 = t3;
22217           goto merge_two;
22218
22219         default:
22220           gcc_assert (GET_MODE_SIZE (mode) <= 16);
22221           break;
22222         }
22223     }
22224
22225   if (TARGET_XOP)
22226     {
22227       /* The XOP VPPERM insn supports three inputs.  By ignoring the 
22228          one_operand_shuffle special case, we avoid creating another
22229          set of constant vectors in memory.  */
22230       one_operand_shuffle = false;
22231
22232       /* mask = mask & {2*w-1, ...} */
22233       vt = GEN_INT (2*w - 1);
22234     }
22235   else
22236     {
22237       /* mask = mask & {w-1, ...} */
22238       vt = GEN_INT (w - 1);
22239     }
22240
22241   for (i = 0; i < w; i++)
22242     vec[i] = vt;
22243   vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22244   mask = expand_simple_binop (maskmode, AND, mask, vt,
22245                               NULL_RTX, 0, OPTAB_DIRECT);
22246
22247   /* For non-QImode operations, convert the word permutation control
22248      into a byte permutation control.  */
22249   if (mode != V16QImode)
22250     {
22251       mask = expand_simple_binop (maskmode, ASHIFT, mask,
22252                                   GEN_INT (exact_log2 (e)),
22253                                   NULL_RTX, 0, OPTAB_DIRECT);
22254
22255       /* Convert mask to vector of chars.  */
22256       mask = force_reg (V16QImode, gen_lowpart (V16QImode, mask));
22257
22258       /* Replicate each of the input bytes into byte positions:
22259          (v2di) --> {0,0,0,0,0,0,0,0, 8,8,8,8,8,8,8,8}
22260          (v4si) --> {0,0,0,0, 4,4,4,4, 8,8,8,8, 12,12,12,12}
22261          (v8hi) --> {0,0, 2,2, 4,4, 6,6, ...}.  */
22262       for (i = 0; i < 16; ++i)
22263         vec[i] = GEN_INT (i/e * e);
22264       vt = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, vec));
22265       vt = validize_mem (force_const_mem (V16QImode, vt));
22266       if (TARGET_XOP)
22267         emit_insn (gen_xop_pperm (mask, mask, mask, vt));
22268       else
22269         emit_insn (gen_ssse3_pshufbv16qi3 (mask, mask, vt));
22270
22271       /* Convert it into the byte positions by doing
22272          mask = mask + {0,1,..,16/w, 0,1,..,16/w, ...}  */
22273       for (i = 0; i < 16; ++i)
22274         vec[i] = GEN_INT (i % e);
22275       vt = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, vec));
22276       vt = validize_mem (force_const_mem (V16QImode, vt));
22277       emit_insn (gen_addv16qi3 (mask, mask, vt));
22278     }
22279
22280   /* The actual shuffle operations all operate on V16QImode.  */
22281   op0 = gen_lowpart (V16QImode, op0);
22282   op1 = gen_lowpart (V16QImode, op1);
22283
22284   if (TARGET_XOP)
22285     {
22286       if (GET_MODE (target) != V16QImode)
22287         target = gen_reg_rtx (V16QImode);
22288       emit_insn (gen_xop_pperm (target, op0, op1, mask));
22289       if (target != operands[0])
22290         emit_move_insn (operands[0],
22291                         gen_lowpart (GET_MODE (operands[0]), target));
22292     }
22293   else if (one_operand_shuffle)
22294     {
22295       if (GET_MODE (target) != V16QImode)
22296         target = gen_reg_rtx (V16QImode);
22297       emit_insn (gen_ssse3_pshufbv16qi3 (target, op0, mask));
22298       if (target != operands[0])
22299         emit_move_insn (operands[0],
22300                         gen_lowpart (GET_MODE (operands[0]), target));
22301     }
22302   else
22303     {
22304       rtx xops[6];
22305       bool ok;
22306
22307       /* Shuffle the two input vectors independently.  */
22308       t1 = gen_reg_rtx (V16QImode);
22309       t2 = gen_reg_rtx (V16QImode);
22310       emit_insn (gen_ssse3_pshufbv16qi3 (t1, op0, mask));
22311       emit_insn (gen_ssse3_pshufbv16qi3 (t2, op1, mask));
22312
22313  merge_two:
22314       /* Then merge them together.  The key is whether any given control
22315          element contained a bit set that indicates the second word.  */
22316       mask = operands[3];
22317       vt = GEN_INT (w);
22318       if (maskmode == V2DImode && !TARGET_SSE4_1)
22319         {
22320           /* Without SSE4.1, we don't have V2DImode EQ.  Perform one
22321              more shuffle to convert the V2DI input mask into a V4SI
22322              input mask.  At which point the masking that expand_int_vcond
22323              will work as desired.  */
22324           rtx t3 = gen_reg_rtx (V4SImode);
22325           emit_insn (gen_sse2_pshufd_1 (t3, gen_lowpart (V4SImode, mask),
22326                                         const0_rtx, const0_rtx,
22327                                         const2_rtx, const2_rtx));
22328           mask = t3;
22329           maskmode = V4SImode;
22330           e = w = 4;
22331         }
22332
22333       for (i = 0; i < w; i++)
22334         vec[i] = vt;
22335       vt = gen_rtx_CONST_VECTOR (maskmode, gen_rtvec_v (w, vec));
22336       vt = force_reg (maskmode, vt);
22337       mask = expand_simple_binop (maskmode, AND, mask, vt,
22338                                   NULL_RTX, 0, OPTAB_DIRECT);
22339
22340       if (GET_MODE (target) != mode)
22341         target = gen_reg_rtx (mode);
22342       xops[0] = target;
22343       xops[1] = gen_lowpart (mode, t2);
22344       xops[2] = gen_lowpart (mode, t1);
22345       xops[3] = gen_rtx_EQ (maskmode, mask, vt);
22346       xops[4] = mask;
22347       xops[5] = vt;
22348       ok = ix86_expand_int_vcond (xops);
22349       gcc_assert (ok);
22350       if (target != operands[0])
22351         emit_move_insn (operands[0],
22352                         gen_lowpart (GET_MODE (operands[0]), target));
22353     }
22354 }
22355
22356 /* Unpack OP[1] into the next wider integer vector type.  UNSIGNED_P is
22357    true if we should do zero extension, else sign extension.  HIGH_P is
22358    true if we want the N/2 high elements, else the low elements.  */
22359
22360 void
22361 ix86_expand_sse_unpack (rtx dest, rtx src, bool unsigned_p, bool high_p)
22362 {
22363   machine_mode imode = GET_MODE (src);
22364   rtx tmp;
22365
22366   if (TARGET_SSE4_1)
22367     {
22368       rtx (*unpack)(rtx, rtx);
22369       rtx (*extract)(rtx, rtx) = NULL;
22370       machine_mode halfmode = BLKmode;
22371
22372       switch (imode)
22373         {
22374         case V64QImode:
22375           if (unsigned_p)
22376             unpack = gen_avx512bw_zero_extendv32qiv32hi2;
22377           else
22378             unpack = gen_avx512bw_sign_extendv32qiv32hi2;
22379           halfmode = V32QImode;
22380           extract
22381             = high_p ? gen_vec_extract_hi_v64qi : gen_vec_extract_lo_v64qi;
22382           break;
22383         case V32QImode:
22384           if (unsigned_p)
22385             unpack = gen_avx2_zero_extendv16qiv16hi2;
22386           else
22387             unpack = gen_avx2_sign_extendv16qiv16hi2;
22388           halfmode = V16QImode;
22389           extract
22390             = high_p ? gen_vec_extract_hi_v32qi : gen_vec_extract_lo_v32qi;
22391           break;
22392         case V32HImode:
22393           if (unsigned_p)
22394             unpack = gen_avx512f_zero_extendv16hiv16si2;
22395           else
22396             unpack = gen_avx512f_sign_extendv16hiv16si2;
22397           halfmode = V16HImode;
22398           extract
22399             = high_p ? gen_vec_extract_hi_v32hi : gen_vec_extract_lo_v32hi;
22400           break;
22401         case V16HImode:
22402           if (unsigned_p)
22403             unpack = gen_avx2_zero_extendv8hiv8si2;
22404           else
22405             unpack = gen_avx2_sign_extendv8hiv8si2;
22406           halfmode = V8HImode;
22407           extract
22408             = high_p ? gen_vec_extract_hi_v16hi : gen_vec_extract_lo_v16hi;
22409           break;
22410         case V16SImode:
22411           if (unsigned_p)
22412             unpack = gen_avx512f_zero_extendv8siv8di2;
22413           else
22414             unpack = gen_avx512f_sign_extendv8siv8di2;
22415           halfmode = V8SImode;
22416           extract
22417             = high_p ? gen_vec_extract_hi_v16si : gen_vec_extract_lo_v16si;
22418           break;
22419         case V8SImode:
22420           if (unsigned_p)
22421             unpack = gen_avx2_zero_extendv4siv4di2;
22422           else
22423             unpack = gen_avx2_sign_extendv4siv4di2;
22424           halfmode = V4SImode;
22425           extract
22426             = high_p ? gen_vec_extract_hi_v8si : gen_vec_extract_lo_v8si;
22427           break;
22428         case V16QImode:
22429           if (unsigned_p)
22430             unpack = gen_sse4_1_zero_extendv8qiv8hi2;
22431           else
22432             unpack = gen_sse4_1_sign_extendv8qiv8hi2;
22433           break;
22434         case V8HImode:
22435           if (unsigned_p)
22436             unpack = gen_sse4_1_zero_extendv4hiv4si2;
22437           else
22438             unpack = gen_sse4_1_sign_extendv4hiv4si2;
22439           break;
22440         case V4SImode:
22441           if (unsigned_p)
22442             unpack = gen_sse4_1_zero_extendv2siv2di2;
22443           else
22444             unpack = gen_sse4_1_sign_extendv2siv2di2;
22445           break;
22446         default:
22447           gcc_unreachable ();
22448         }
22449
22450       if (GET_MODE_SIZE (imode) >= 32)
22451         {
22452           tmp = gen_reg_rtx (halfmode);
22453           emit_insn (extract (tmp, src));
22454         }
22455       else if (high_p)
22456         {
22457           /* Shift higher 8 bytes to lower 8 bytes.  */
22458           tmp = gen_reg_rtx (V1TImode);
22459           emit_insn (gen_sse2_lshrv1ti3 (tmp, gen_lowpart (V1TImode, src),
22460                                          GEN_INT (64)));
22461           tmp = gen_lowpart (imode, tmp);
22462         }
22463       else
22464         tmp = src;
22465
22466       emit_insn (unpack (dest, tmp));
22467     }
22468   else
22469     {
22470       rtx (*unpack)(rtx, rtx, rtx);
22471
22472       switch (imode)
22473         {
22474         case V16QImode:
22475           if (high_p)
22476             unpack = gen_vec_interleave_highv16qi;
22477           else
22478             unpack = gen_vec_interleave_lowv16qi;
22479           break;
22480         case V8HImode:
22481           if (high_p)
22482             unpack = gen_vec_interleave_highv8hi;
22483           else
22484             unpack = gen_vec_interleave_lowv8hi;
22485           break;
22486         case V4SImode:
22487           if (high_p)
22488             unpack = gen_vec_interleave_highv4si;
22489           else
22490             unpack = gen_vec_interleave_lowv4si;
22491           break;
22492         default:
22493           gcc_unreachable ();
22494         }
22495
22496       if (unsigned_p)
22497         tmp = force_reg (imode, CONST0_RTX (imode));
22498       else
22499         tmp = ix86_expand_sse_cmp (gen_reg_rtx (imode), GT, CONST0_RTX (imode),
22500                                    src, pc_rtx, pc_rtx);
22501
22502       rtx tmp2 = gen_reg_rtx (imode);
22503       emit_insn (unpack (tmp2, src, tmp));
22504       emit_move_insn (dest, gen_lowpart (GET_MODE (dest), tmp2));
22505     }
22506 }
22507
22508 /* Expand conditional increment or decrement using adb/sbb instructions.
22509    The default case using setcc followed by the conditional move can be
22510    done by generic code.  */
22511 bool
22512 ix86_expand_int_addcc (rtx operands[])
22513 {
22514   enum rtx_code code = GET_CODE (operands[1]);
22515   rtx flags;
22516   rtx (*insn)(rtx, rtx, rtx, rtx, rtx);
22517   rtx compare_op;
22518   rtx val = const0_rtx;
22519   bool fpcmp = false;
22520   machine_mode mode;
22521   rtx op0 = XEXP (operands[1], 0);
22522   rtx op1 = XEXP (operands[1], 1);
22523
22524   if (operands[3] != const1_rtx
22525       && operands[3] != constm1_rtx)
22526     return false;
22527   if (!ix86_expand_carry_flag_compare (code, op0, op1, &compare_op))
22528      return false;
22529   code = GET_CODE (compare_op);
22530
22531   flags = XEXP (compare_op, 0);
22532
22533   if (GET_MODE (flags) == CCFPmode
22534       || GET_MODE (flags) == CCFPUmode)
22535     {
22536       fpcmp = true;
22537       code = ix86_fp_compare_code_to_integer (code);
22538     }
22539
22540   if (code != LTU)
22541     {
22542       val = constm1_rtx;
22543       if (fpcmp)
22544         PUT_CODE (compare_op,
22545                   reverse_condition_maybe_unordered
22546                     (GET_CODE (compare_op)));
22547       else
22548         PUT_CODE (compare_op, reverse_condition (GET_CODE (compare_op)));
22549     }
22550
22551   mode = GET_MODE (operands[0]);
22552
22553   /* Construct either adc or sbb insn.  */
22554   if ((code == LTU) == (operands[3] == constm1_rtx))
22555     {
22556       switch (mode)
22557         {
22558           case QImode:
22559             insn = gen_subqi3_carry;
22560             break;
22561           case HImode:
22562             insn = gen_subhi3_carry;
22563             break;
22564           case SImode:
22565             insn = gen_subsi3_carry;
22566             break;
22567           case DImode:
22568             insn = gen_subdi3_carry;
22569             break;
22570           default:
22571             gcc_unreachable ();
22572         }
22573     }
22574   else
22575     {
22576       switch (mode)
22577         {
22578           case QImode:
22579             insn = gen_addqi3_carry;
22580             break;
22581           case HImode:
22582             insn = gen_addhi3_carry;
22583             break;
22584           case SImode:
22585             insn = gen_addsi3_carry;
22586             break;
22587           case DImode:
22588             insn = gen_adddi3_carry;
22589             break;
22590           default:
22591             gcc_unreachable ();
22592         }
22593     }
22594   emit_insn (insn (operands[0], operands[2], val, flags, compare_op));
22595
22596   return true;
22597 }
22598
22599
22600 /* Split operands 0 and 1 into half-mode parts.  Similar to split_double_mode,
22601    but works for floating pointer parameters and nonoffsetable memories.
22602    For pushes, it returns just stack offsets; the values will be saved
22603    in the right order.  Maximally three parts are generated.  */
22604
22605 static int
22606 ix86_split_to_parts (rtx operand, rtx *parts, machine_mode mode)
22607 {
22608   int size;
22609
22610   if (!TARGET_64BIT)
22611     size = mode==XFmode ? 3 : GET_MODE_SIZE (mode) / 4;
22612   else
22613     size = (GET_MODE_SIZE (mode) + 4) / 8;
22614
22615   gcc_assert (!REG_P (operand) || !MMX_REGNO_P (REGNO (operand)));
22616   gcc_assert (size >= 2 && size <= 4);
22617
22618   /* Optimize constant pool reference to immediates.  This is used by fp
22619      moves, that force all constants to memory to allow combining.  */
22620   if (MEM_P (operand) && MEM_READONLY_P (operand))
22621     {
22622       rtx tmp = maybe_get_pool_constant (operand);
22623       if (tmp)
22624         operand = tmp;
22625     }
22626
22627   if (MEM_P (operand) && !offsettable_memref_p (operand))
22628     {
22629       /* The only non-offsetable memories we handle are pushes.  */
22630       int ok = push_operand (operand, VOIDmode);
22631
22632       gcc_assert (ok);
22633
22634       operand = copy_rtx (operand);
22635       PUT_MODE (operand, word_mode);
22636       parts[0] = parts[1] = parts[2] = parts[3] = operand;
22637       return size;
22638     }
22639
22640   if (GET_CODE (operand) == CONST_VECTOR)
22641     {
22642       machine_mode imode = int_mode_for_mode (mode);
22643       /* Caution: if we looked through a constant pool memory above,
22644          the operand may actually have a different mode now.  That's
22645          ok, since we want to pun this all the way back to an integer.  */
22646       operand = simplify_subreg (imode, operand, GET_MODE (operand), 0);
22647       gcc_assert (operand != NULL);
22648       mode = imode;
22649     }
22650
22651   if (!TARGET_64BIT)
22652     {
22653       if (mode == DImode)
22654         split_double_mode (mode, &operand, 1, &parts[0], &parts[1]);
22655       else
22656         {
22657           int i;
22658
22659           if (REG_P (operand))
22660             {
22661               gcc_assert (reload_completed);
22662               for (i = 0; i < size; i++)
22663                 parts[i] = gen_rtx_REG (SImode, REGNO (operand) + i);
22664             }
22665           else if (offsettable_memref_p (operand))
22666             {
22667               operand = adjust_address (operand, SImode, 0);
22668               parts[0] = operand;
22669               for (i = 1; i < size; i++)
22670                 parts[i] = adjust_address (operand, SImode, 4 * i);
22671             }
22672           else if (GET_CODE (operand) == CONST_DOUBLE)
22673             {
22674               REAL_VALUE_TYPE r;
22675               long l[4];
22676
22677               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
22678               switch (mode)
22679                 {
22680                 case TFmode:
22681                   real_to_target (l, &r, mode);
22682                   parts[3] = gen_int_mode (l[3], SImode);
22683                   parts[2] = gen_int_mode (l[2], SImode);
22684                   break;
22685                 case XFmode:
22686                   /* We can't use REAL_VALUE_TO_TARGET_LONG_DOUBLE since
22687                      long double may not be 80-bit.  */
22688                   real_to_target (l, &r, mode);
22689                   parts[2] = gen_int_mode (l[2], SImode);
22690                   break;
22691                 case DFmode:
22692                   REAL_VALUE_TO_TARGET_DOUBLE (r, l);
22693                   break;
22694                 default:
22695                   gcc_unreachable ();
22696                 }
22697               parts[1] = gen_int_mode (l[1], SImode);
22698               parts[0] = gen_int_mode (l[0], SImode);
22699             }
22700           else
22701             gcc_unreachable ();
22702         }
22703     }
22704   else
22705     {
22706       if (mode == TImode)
22707         split_double_mode (mode, &operand, 1, &parts[0], &parts[1]);
22708       if (mode == XFmode || mode == TFmode)
22709         {
22710           machine_mode upper_mode = mode==XFmode ? SImode : DImode;
22711           if (REG_P (operand))
22712             {
22713               gcc_assert (reload_completed);
22714               parts[0] = gen_rtx_REG (DImode, REGNO (operand) + 0);
22715               parts[1] = gen_rtx_REG (upper_mode, REGNO (operand) + 1);
22716             }
22717           else if (offsettable_memref_p (operand))
22718             {
22719               operand = adjust_address (operand, DImode, 0);
22720               parts[0] = operand;
22721               parts[1] = adjust_address (operand, upper_mode, 8);
22722             }
22723           else if (GET_CODE (operand) == CONST_DOUBLE)
22724             {
22725               REAL_VALUE_TYPE r;
22726               long l[4];
22727
22728               REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
22729               real_to_target (l, &r, mode);
22730
22731               /* Do not use shift by 32 to avoid warning on 32bit systems.  */
22732               if (HOST_BITS_PER_WIDE_INT >= 64)
22733                 parts[0]
22734                   = gen_int_mode
22735                       ((l[0] & (((HOST_WIDE_INT) 2 << 31) - 1))
22736                        + ((((HOST_WIDE_INT) l[1]) << 31) << 1),
22737                        DImode);
22738               else
22739                 parts[0] = immed_double_const (l[0], l[1], DImode);
22740
22741               if (upper_mode == SImode)
22742                 parts[1] = gen_int_mode (l[2], SImode);
22743               else if (HOST_BITS_PER_WIDE_INT >= 64)
22744                 parts[1]
22745                   = gen_int_mode
22746                       ((l[2] & (((HOST_WIDE_INT) 2 << 31) - 1))
22747                        + ((((HOST_WIDE_INT) l[3]) << 31) << 1),
22748                        DImode);
22749               else
22750                 parts[1] = immed_double_const (l[2], l[3], DImode);
22751             }
22752           else
22753             gcc_unreachable ();
22754         }
22755     }
22756
22757   return size;
22758 }
22759
22760 /* Emit insns to perform a move or push of DI, DF, XF, and TF values.
22761    Return false when normal moves are needed; true when all required
22762    insns have been emitted.  Operands 2-4 contain the input values
22763    int the correct order; operands 5-7 contain the output values.  */
22764
22765 void
22766 ix86_split_long_move (rtx operands[])
22767 {
22768   rtx part[2][4];
22769   int nparts, i, j;
22770   int push = 0;
22771   int collisions = 0;
22772   machine_mode mode = GET_MODE (operands[0]);
22773   bool collisionparts[4];
22774
22775   /* The DFmode expanders may ask us to move double.
22776      For 64bit target this is single move.  By hiding the fact
22777      here we simplify i386.md splitters.  */
22778   if (TARGET_64BIT && GET_MODE_SIZE (GET_MODE (operands[0])) == 8)
22779     {
22780       /* Optimize constant pool reference to immediates.  This is used by
22781          fp moves, that force all constants to memory to allow combining.  */
22782
22783       if (MEM_P (operands[1])
22784           && GET_CODE (XEXP (operands[1], 0)) == SYMBOL_REF
22785           && CONSTANT_POOL_ADDRESS_P (XEXP (operands[1], 0)))
22786         operands[1] = get_pool_constant (XEXP (operands[1], 0));
22787       if (push_operand (operands[0], VOIDmode))
22788         {
22789           operands[0] = copy_rtx (operands[0]);
22790           PUT_MODE (operands[0], word_mode);
22791         }
22792       else
22793         operands[0] = gen_lowpart (DImode, operands[0]);
22794       operands[1] = gen_lowpart (DImode, operands[1]);
22795       emit_move_insn (operands[0], operands[1]);
22796       return;
22797     }
22798
22799   /* The only non-offsettable memory we handle is push.  */
22800   if (push_operand (operands[0], VOIDmode))
22801     push = 1;
22802   else
22803     gcc_assert (!MEM_P (operands[0])
22804                 || offsettable_memref_p (operands[0]));
22805
22806   nparts = ix86_split_to_parts (operands[1], part[1], GET_MODE (operands[0]));
22807   ix86_split_to_parts (operands[0], part[0], GET_MODE (operands[0]));
22808
22809   /* When emitting push, take care for source operands on the stack.  */
22810   if (push && MEM_P (operands[1])
22811       && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1]))
22812     {
22813       rtx src_base = XEXP (part[1][nparts - 1], 0);
22814
22815       /* Compensate for the stack decrement by 4.  */
22816       if (!TARGET_64BIT && nparts == 3
22817           && mode == XFmode && TARGET_128BIT_LONG_DOUBLE)
22818         src_base = plus_constant (Pmode, src_base, 4);
22819
22820       /* src_base refers to the stack pointer and is
22821          automatically decreased by emitted push.  */
22822       for (i = 0; i < nparts; i++)
22823         part[1][i] = change_address (part[1][i],
22824                                      GET_MODE (part[1][i]), src_base);
22825     }
22826
22827   /* We need to do copy in the right order in case an address register
22828      of the source overlaps the destination.  */
22829   if (REG_P (part[0][0]) && MEM_P (part[1][0]))
22830     {
22831       rtx tmp;
22832
22833       for (i = 0; i < nparts; i++)
22834         {
22835           collisionparts[i]
22836             = reg_overlap_mentioned_p (part[0][i], XEXP (part[1][0], 0));
22837           if (collisionparts[i])
22838             collisions++;
22839         }
22840
22841       /* Collision in the middle part can be handled by reordering.  */
22842       if (collisions == 1 && nparts == 3 && collisionparts [1])
22843         {
22844           std::swap (part[0][1], part[0][2]);
22845           std::swap (part[1][1], part[1][2]);
22846         }
22847       else if (collisions == 1
22848                && nparts == 4
22849                && (collisionparts [1] || collisionparts [2]))
22850         {
22851           if (collisionparts [1])
22852             {
22853               std::swap (part[0][1], part[0][2]);
22854               std::swap (part[1][1], part[1][2]);
22855             }
22856           else
22857             {
22858               std::swap (part[0][2], part[0][3]);
22859               std::swap (part[1][2], part[1][3]);
22860             }
22861         }
22862
22863       /* If there are more collisions, we can't handle it by reordering.
22864          Do an lea to the last part and use only one colliding move.  */
22865       else if (collisions > 1)
22866         {
22867           rtx base;
22868
22869           collisions = 1;
22870
22871           base = part[0][nparts - 1];
22872
22873           /* Handle the case when the last part isn't valid for lea.
22874              Happens in 64-bit mode storing the 12-byte XFmode.  */
22875           if (GET_MODE (base) != Pmode)
22876             base = gen_rtx_REG (Pmode, REGNO (base));
22877
22878           emit_insn (gen_rtx_SET (VOIDmode, base, XEXP (part[1][0], 0)));
22879           part[1][0] = replace_equiv_address (part[1][0], base);
22880           for (i = 1; i < nparts; i++)
22881             {
22882               tmp = plus_constant (Pmode, base, UNITS_PER_WORD * i);
22883               part[1][i] = replace_equiv_address (part[1][i], tmp);
22884             }
22885         }
22886     }
22887
22888   if (push)
22889     {
22890       if (!TARGET_64BIT)
22891         {
22892           if (nparts == 3)
22893             {
22894               if (TARGET_128BIT_LONG_DOUBLE && mode == XFmode)
22895                 emit_insn (ix86_gen_add3 (stack_pointer_rtx,
22896                                           stack_pointer_rtx, GEN_INT (-4)));
22897               emit_move_insn (part[0][2], part[1][2]);
22898             }
22899           else if (nparts == 4)
22900             {
22901               emit_move_insn (part[0][3], part[1][3]);
22902               emit_move_insn (part[0][2], part[1][2]);
22903             }
22904         }
22905       else
22906         {
22907           /* In 64bit mode we don't have 32bit push available.  In case this is
22908              register, it is OK - we will just use larger counterpart.  We also
22909              retype memory - these comes from attempt to avoid REX prefix on
22910              moving of second half of TFmode value.  */
22911           if (GET_MODE (part[1][1]) == SImode)
22912             {
22913               switch (GET_CODE (part[1][1]))
22914                 {
22915                 case MEM:
22916                   part[1][1] = adjust_address (part[1][1], DImode, 0);
22917                   break;
22918
22919                 case REG:
22920                   part[1][1] = gen_rtx_REG (DImode, REGNO (part[1][1]));
22921                   break;
22922
22923                 default:
22924                   gcc_unreachable ();
22925                 }
22926
22927               if (GET_MODE (part[1][0]) == SImode)
22928                 part[1][0] = part[1][1];
22929             }
22930         }
22931       emit_move_insn (part[0][1], part[1][1]);
22932       emit_move_insn (part[0][0], part[1][0]);
22933       return;
22934     }
22935
22936   /* Choose correct order to not overwrite the source before it is copied.  */
22937   if ((REG_P (part[0][0])
22938        && REG_P (part[1][1])
22939        && (REGNO (part[0][0]) == REGNO (part[1][1])
22940            || (nparts == 3
22941                && REGNO (part[0][0]) == REGNO (part[1][2]))
22942            || (nparts == 4
22943                && REGNO (part[0][0]) == REGNO (part[1][3]))))
22944       || (collisions > 0
22945           && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))))
22946     {
22947       for (i = 0, j = nparts - 1; i < nparts; i++, j--)
22948         {
22949           operands[2 + i] = part[0][j];
22950           operands[6 + i] = part[1][j];
22951         }
22952     }
22953   else
22954     {
22955       for (i = 0; i < nparts; i++)
22956         {
22957           operands[2 + i] = part[0][i];
22958           operands[6 + i] = part[1][i];
22959         }
22960     }
22961
22962   /* If optimizing for size, attempt to locally unCSE nonzero constants.  */
22963   if (optimize_insn_for_size_p ())
22964     {
22965       for (j = 0; j < nparts - 1; j++)
22966         if (CONST_INT_P (operands[6 + j])
22967             && operands[6 + j] != const0_rtx
22968             && REG_P (operands[2 + j]))
22969           for (i = j; i < nparts - 1; i++)
22970             if (CONST_INT_P (operands[7 + i])
22971                 && INTVAL (operands[7 + i]) == INTVAL (operands[6 + j]))
22972               operands[7 + i] = operands[2 + j];
22973     }
22974
22975   for (i = 0; i < nparts; i++)
22976     emit_move_insn (operands[2 + i], operands[6 + i]);
22977
22978   return;
22979 }
22980
22981 /* Helper function of ix86_split_ashl used to generate an SImode/DImode
22982    left shift by a constant, either using a single shift or
22983    a sequence of add instructions.  */
22984
22985 static void
22986 ix86_expand_ashl_const (rtx operand, int count, machine_mode mode)
22987 {
22988   rtx (*insn)(rtx, rtx, rtx);
22989
22990   if (count == 1
22991       || (count * ix86_cost->add <= ix86_cost->shift_const
22992           && !optimize_insn_for_size_p ()))
22993     {
22994       insn = mode == DImode ? gen_addsi3 : gen_adddi3;
22995       while (count-- > 0)
22996         emit_insn (insn (operand, operand, operand));
22997     }
22998   else
22999     {
23000       insn = mode == DImode ? gen_ashlsi3 : gen_ashldi3;
23001       emit_insn (insn (operand, operand, GEN_INT (count)));
23002     }
23003 }
23004
23005 void
23006 ix86_split_ashl (rtx *operands, rtx scratch, machine_mode mode)
23007 {
23008   rtx (*gen_ashl3)(rtx, rtx, rtx);
23009   rtx (*gen_shld)(rtx, rtx, rtx);
23010   int half_width = GET_MODE_BITSIZE (mode) >> 1;
23011
23012   rtx low[2], high[2];
23013   int count;
23014
23015   if (CONST_INT_P (operands[2]))
23016     {
23017       split_double_mode (mode, operands, 2, low, high);
23018       count = INTVAL (operands[2]) & (GET_MODE_BITSIZE (mode) - 1);
23019
23020       if (count >= half_width)
23021         {
23022           emit_move_insn (high[0], low[1]);
23023           emit_move_insn (low[0], const0_rtx);
23024
23025           if (count > half_width)
23026             ix86_expand_ashl_const (high[0], count - half_width, mode);
23027         }
23028       else
23029         {
23030           gen_shld = mode == DImode ? gen_x86_shld : gen_x86_64_shld;
23031
23032           if (!rtx_equal_p (operands[0], operands[1]))
23033             emit_move_insn (operands[0], operands[1]);
23034
23035           emit_insn (gen_shld (high[0], low[0], GEN_INT (count)));
23036           ix86_expand_ashl_const (low[0], count, mode);
23037         }
23038       return;
23039     }
23040
23041   split_double_mode (mode, operands, 1, low, high);
23042
23043   gen_ashl3 = mode == DImode ? gen_ashlsi3 : gen_ashldi3;
23044
23045   if (operands[1] == const1_rtx)
23046     {
23047       /* Assuming we've chosen a QImode capable registers, then 1 << N
23048          can be done with two 32/64-bit shifts, no branches, no cmoves.  */
23049       if (ANY_QI_REG_P (low[0]) && ANY_QI_REG_P (high[0]))
23050         {
23051           rtx s, d, flags = gen_rtx_REG (CCZmode, FLAGS_REG);
23052
23053           ix86_expand_clear (low[0]);
23054           ix86_expand_clear (high[0]);
23055           emit_insn (gen_testqi_ccz_1 (operands[2], GEN_INT (half_width)));
23056
23057           d = gen_lowpart (QImode, low[0]);
23058           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
23059           s = gen_rtx_EQ (QImode, flags, const0_rtx);
23060           emit_insn (gen_rtx_SET (VOIDmode, d, s));
23061
23062           d = gen_lowpart (QImode, high[0]);
23063           d = gen_rtx_STRICT_LOW_PART (VOIDmode, d);
23064           s = gen_rtx_NE (QImode, flags, const0_rtx);
23065           emit_insn (gen_rtx_SET (VOIDmode, d, s));
23066         }
23067
23068       /* Otherwise, we can get the same results by manually performing
23069          a bit extract operation on bit 5/6, and then performing the two
23070          shifts.  The two methods of getting 0/1 into low/high are exactly
23071          the same size.  Avoiding the shift in the bit extract case helps
23072          pentium4 a bit; no one else seems to care much either way.  */
23073       else
23074         {
23075           machine_mode half_mode;
23076           rtx (*gen_lshr3)(rtx, rtx, rtx);
23077           rtx (*gen_and3)(rtx, rtx, rtx);
23078           rtx (*gen_xor3)(rtx, rtx, rtx);
23079           HOST_WIDE_INT bits;
23080           rtx x;
23081
23082           if (mode == DImode)
23083             {
23084               half_mode = SImode;
23085               gen_lshr3 = gen_lshrsi3;
23086               gen_and3 = gen_andsi3;
23087               gen_xor3 = gen_xorsi3;
23088               bits = 5;
23089             }
23090           else
23091             {
23092               half_mode = DImode;
23093               gen_lshr3 = gen_lshrdi3;
23094               gen_and3 = gen_anddi3;
23095               gen_xor3 = gen_xordi3;
23096               bits = 6;
23097             }
23098
23099           if (TARGET_PARTIAL_REG_STALL && !optimize_insn_for_size_p ())
23100             x = gen_rtx_ZERO_EXTEND (half_mode, operands[2]);
23101           else
23102             x = gen_lowpart (half_mode, operands[2]);
23103           emit_insn (gen_rtx_SET (VOIDmode, high[0], x));
23104
23105           emit_insn (gen_lshr3 (high[0], high[0], GEN_INT (bits)));
23106           emit_insn (gen_and3 (high[0], high[0], const1_rtx));
23107           emit_move_insn (low[0], high[0]);
23108           emit_insn (gen_xor3 (low[0], low[0], const1_rtx));
23109         }
23110
23111       emit_insn (gen_ashl3 (low[0], low[0], operands[2]));
23112       emit_insn (gen_ashl3 (high[0], high[0], operands[2]));
23113       return;
23114     }
23115
23116   if (operands[1] == constm1_rtx)
23117     {
23118       /* For -1 << N, we can avoid the shld instruction, because we
23119          know that we're shifting 0...31/63 ones into a -1.  */
23120       emit_move_insn (low[0], constm1_rtx);
23121       if (optimize_insn_for_size_p ())
23122         emit_move_insn (high[0], low[0]);
23123       else
23124         emit_move_insn (high[0], constm1_rtx);
23125     }
23126   else
23127     {
23128       gen_shld = mode == DImode ? gen_x86_shld : gen_x86_64_shld;
23129
23130       if (!rtx_equal_p (operands[0], operands[1]))
23131         emit_move_insn (operands[0], operands[1]);
23132
23133       split_double_mode (mode, operands, 1, low, high);
23134       emit_insn (gen_shld (high[0], low[0], operands[2]));
23135     }
23136
23137   emit_insn (gen_ashl3 (low[0], low[0], operands[2]));
23138
23139   if (TARGET_CMOVE && scratch)
23140     {
23141       rtx (*gen_x86_shift_adj_1)(rtx, rtx, rtx, rtx)
23142         = mode == DImode ? gen_x86_shiftsi_adj_1 : gen_x86_shiftdi_adj_1;
23143
23144       ix86_expand_clear (scratch);
23145       emit_insn (gen_x86_shift_adj_1 (high[0], low[0], operands[2], scratch));
23146     }
23147   else
23148     {
23149       rtx (*gen_x86_shift_adj_2)(rtx, rtx, rtx)
23150         = mode == DImode ? gen_x86_shiftsi_adj_2 : gen_x86_shiftdi_adj_2;
23151
23152       emit_insn (gen_x86_shift_adj_2 (high[0], low[0], operands[2]));
23153     }
23154 }
23155
23156 void
23157 ix86_split_ashr (rtx *operands, rtx scratch, machine_mode mode)
23158 {
23159   rtx (*gen_ashr3)(rtx, rtx, rtx)
23160     = mode == DImode ? gen_ashrsi3 : gen_ashrdi3;
23161   rtx (*gen_shrd)(rtx, rtx, rtx);
23162   int half_width = GET_MODE_BITSIZE (mode) >> 1;
23163
23164   rtx low[2], high[2];
23165   int count;
23166
23167   if (CONST_INT_P (operands[2]))
23168     {
23169       split_double_mode (mode, operands, 2, low, high);
23170       count = INTVAL (operands[2]) & (GET_MODE_BITSIZE (mode) - 1);
23171
23172       if (count == GET_MODE_BITSIZE (mode) - 1)
23173         {
23174           emit_move_insn (high[0], high[1]);
23175           emit_insn (gen_ashr3 (high[0], high[0],
23176                                 GEN_INT (half_width - 1)));
23177           emit_move_insn (low[0], high[0]);
23178
23179         }
23180       else if (count >= half_width)
23181         {
23182           emit_move_insn (low[0], high[1]);
23183           emit_move_insn (high[0], low[0]);
23184           emit_insn (gen_ashr3 (high[0], high[0],
23185                                 GEN_INT (half_width - 1)));
23186
23187           if (count > half_width)
23188             emit_insn (gen_ashr3 (low[0], low[0],
23189                                   GEN_INT (count - half_width)));
23190         }
23191       else
23192         {
23193           gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23194
23195           if (!rtx_equal_p (operands[0], operands[1]))
23196             emit_move_insn (operands[0], operands[1]);
23197
23198           emit_insn (gen_shrd (low[0], high[0], GEN_INT (count)));
23199           emit_insn (gen_ashr3 (high[0], high[0], GEN_INT (count)));
23200         }
23201     }
23202   else
23203     {
23204       gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23205
23206      if (!rtx_equal_p (operands[0], operands[1]))
23207         emit_move_insn (operands[0], operands[1]);
23208
23209       split_double_mode (mode, operands, 1, low, high);
23210
23211       emit_insn (gen_shrd (low[0], high[0], operands[2]));
23212       emit_insn (gen_ashr3 (high[0], high[0], operands[2]));
23213
23214       if (TARGET_CMOVE && scratch)
23215         {
23216           rtx (*gen_x86_shift_adj_1)(rtx, rtx, rtx, rtx)
23217             = mode == DImode ? gen_x86_shiftsi_adj_1 : gen_x86_shiftdi_adj_1;
23218
23219           emit_move_insn (scratch, high[0]);
23220           emit_insn (gen_ashr3 (scratch, scratch,
23221                                 GEN_INT (half_width - 1)));
23222           emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2],
23223                                           scratch));
23224         }
23225       else
23226         {
23227           rtx (*gen_x86_shift_adj_3)(rtx, rtx, rtx)
23228             = mode == DImode ? gen_x86_shiftsi_adj_3 : gen_x86_shiftdi_adj_3;
23229
23230           emit_insn (gen_x86_shift_adj_3 (low[0], high[0], operands[2]));
23231         }
23232     }
23233 }
23234
23235 void
23236 ix86_split_lshr (rtx *operands, rtx scratch, machine_mode mode)
23237 {
23238   rtx (*gen_lshr3)(rtx, rtx, rtx)
23239     = mode == DImode ? gen_lshrsi3 : gen_lshrdi3;
23240   rtx (*gen_shrd)(rtx, rtx, rtx);
23241   int half_width = GET_MODE_BITSIZE (mode) >> 1;
23242
23243   rtx low[2], high[2];
23244   int count;
23245
23246   if (CONST_INT_P (operands[2]))
23247     {
23248       split_double_mode (mode, operands, 2, low, high);
23249       count = INTVAL (operands[2]) & (GET_MODE_BITSIZE (mode) - 1);
23250
23251       if (count >= half_width)
23252         {
23253           emit_move_insn (low[0], high[1]);
23254           ix86_expand_clear (high[0]);
23255
23256           if (count > half_width)
23257             emit_insn (gen_lshr3 (low[0], low[0],
23258                                   GEN_INT (count - half_width)));
23259         }
23260       else
23261         {
23262           gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23263
23264           if (!rtx_equal_p (operands[0], operands[1]))
23265             emit_move_insn (operands[0], operands[1]);
23266
23267           emit_insn (gen_shrd (low[0], high[0], GEN_INT (count)));
23268           emit_insn (gen_lshr3 (high[0], high[0], GEN_INT (count)));
23269         }
23270     }
23271   else
23272     {
23273       gen_shrd = mode == DImode ? gen_x86_shrd : gen_x86_64_shrd;
23274
23275       if (!rtx_equal_p (operands[0], operands[1]))
23276         emit_move_insn (operands[0], operands[1]);
23277
23278       split_double_mode (mode, operands, 1, low, high);
23279
23280       emit_insn (gen_shrd (low[0], high[0], operands[2]));
23281       emit_insn (gen_lshr3 (high[0], high[0], operands[2]));
23282
23283       if (TARGET_CMOVE && scratch)
23284         {
23285           rtx (*gen_x86_shift_adj_1)(rtx, rtx, rtx, rtx)
23286             = mode == DImode ? gen_x86_shiftsi_adj_1 : gen_x86_shiftdi_adj_1;
23287
23288           ix86_expand_clear (scratch);
23289           emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2],
23290                                           scratch));
23291         }
23292       else
23293         {
23294           rtx (*gen_x86_shift_adj_2)(rtx, rtx, rtx)
23295             = mode == DImode ? gen_x86_shiftsi_adj_2 : gen_x86_shiftdi_adj_2;
23296
23297           emit_insn (gen_x86_shift_adj_2 (low[0], high[0], operands[2]));
23298         }
23299     }
23300 }
23301
23302 /* Predict just emitted jump instruction to be taken with probability PROB.  */
23303 static void
23304 predict_jump (int prob)
23305 {
23306   rtx insn = get_last_insn ();
23307   gcc_assert (JUMP_P (insn));
23308   add_int_reg_note (insn, REG_BR_PROB, prob);
23309 }
23310
23311 /* Helper function for the string operations below.  Dest VARIABLE whether
23312    it is aligned to VALUE bytes.  If true, jump to the label.  */
23313 static rtx_code_label *
23314 ix86_expand_aligntest (rtx variable, int value, bool epilogue)
23315 {
23316   rtx_code_label *label = gen_label_rtx ();
23317   rtx tmpcount = gen_reg_rtx (GET_MODE (variable));
23318   if (GET_MODE (variable) == DImode)
23319     emit_insn (gen_anddi3 (tmpcount, variable, GEN_INT (value)));
23320   else
23321     emit_insn (gen_andsi3 (tmpcount, variable, GEN_INT (value)));
23322   emit_cmp_and_jump_insns (tmpcount, const0_rtx, EQ, 0, GET_MODE (variable),
23323                            1, label);
23324   if (epilogue)
23325     predict_jump (REG_BR_PROB_BASE * 50 / 100);
23326   else
23327     predict_jump (REG_BR_PROB_BASE * 90 / 100);
23328   return label;
23329 }
23330
23331 /* Adjust COUNTER by the VALUE.  */
23332 static void
23333 ix86_adjust_counter (rtx countreg, HOST_WIDE_INT value)
23334 {
23335   rtx (*gen_add)(rtx, rtx, rtx)
23336     = GET_MODE (countreg) == DImode ? gen_adddi3 : gen_addsi3;
23337
23338   emit_insn (gen_add (countreg, countreg, GEN_INT (-value)));
23339 }
23340
23341 /* Zero extend possibly SImode EXP to Pmode register.  */
23342 rtx
23343 ix86_zero_extend_to_Pmode (rtx exp)
23344 {
23345   return force_reg (Pmode, convert_to_mode (Pmode, exp, 1));
23346 }
23347
23348 /* Divide COUNTREG by SCALE.  */
23349 static rtx
23350 scale_counter (rtx countreg, int scale)
23351 {
23352   rtx sc;
23353
23354   if (scale == 1)
23355     return countreg;
23356   if (CONST_INT_P (countreg))
23357     return GEN_INT (INTVAL (countreg) / scale);
23358   gcc_assert (REG_P (countreg));
23359
23360   sc = expand_simple_binop (GET_MODE (countreg), LSHIFTRT, countreg,
23361                             GEN_INT (exact_log2 (scale)),
23362                             NULL, 1, OPTAB_DIRECT);
23363   return sc;
23364 }
23365
23366 /* Return mode for the memcpy/memset loop counter.  Prefer SImode over
23367    DImode for constant loop counts.  */
23368
23369 static machine_mode
23370 counter_mode (rtx count_exp)
23371 {
23372   if (GET_MODE (count_exp) != VOIDmode)
23373     return GET_MODE (count_exp);
23374   if (!CONST_INT_P (count_exp))
23375     return Pmode;
23376   if (TARGET_64BIT && (INTVAL (count_exp) & ~0xffffffff))
23377     return DImode;
23378   return SImode;
23379 }
23380
23381 /* Copy the address to a Pmode register.  This is used for x32 to
23382    truncate DImode TLS address to a SImode register. */
23383
23384 static rtx
23385 ix86_copy_addr_to_reg (rtx addr)
23386 {
23387   if (GET_MODE (addr) == Pmode || GET_MODE (addr) == VOIDmode)
23388     return copy_addr_to_reg (addr);
23389   else
23390     {
23391       gcc_assert (GET_MODE (addr) == DImode && Pmode == SImode);
23392       return gen_rtx_SUBREG (SImode, copy_to_mode_reg (DImode, addr), 0);
23393     }
23394 }
23395
23396 /* When ISSETMEM is FALSE, output simple loop to move memory pointer to SRCPTR
23397    to DESTPTR via chunks of MODE unrolled UNROLL times, overall size is COUNT
23398    specified in bytes.  When ISSETMEM is TRUE, output the equivalent loop to set
23399    memory by VALUE (supposed to be in MODE).
23400
23401    The size is rounded down to whole number of chunk size moved at once.
23402    SRCMEM and DESTMEM provide MEMrtx to feed proper aliasing info.  */
23403
23404
23405 static void
23406 expand_set_or_movmem_via_loop (rtx destmem, rtx srcmem,
23407                                rtx destptr, rtx srcptr, rtx value,
23408                                rtx count, machine_mode mode, int unroll,
23409                                int expected_size, bool issetmem)
23410 {
23411   rtx_code_label *out_label, *top_label;
23412   rtx iter, tmp;
23413   machine_mode iter_mode = counter_mode (count);
23414   int piece_size_n = GET_MODE_SIZE (mode) * unroll;
23415   rtx piece_size = GEN_INT (piece_size_n);
23416   rtx piece_size_mask = GEN_INT (~((GET_MODE_SIZE (mode) * unroll) - 1));
23417   rtx size;
23418   int i;
23419
23420   top_label = gen_label_rtx ();
23421   out_label = gen_label_rtx ();
23422   iter = gen_reg_rtx (iter_mode);
23423
23424   size = expand_simple_binop (iter_mode, AND, count, piece_size_mask,
23425                               NULL, 1, OPTAB_DIRECT);
23426   /* Those two should combine.  */
23427   if (piece_size == const1_rtx)
23428     {
23429       emit_cmp_and_jump_insns (size, const0_rtx, EQ, NULL_RTX, iter_mode,
23430                                true, out_label);
23431       predict_jump (REG_BR_PROB_BASE * 10 / 100);
23432     }
23433   emit_move_insn (iter, const0_rtx);
23434
23435   emit_label (top_label);
23436
23437   tmp = convert_modes (Pmode, iter_mode, iter, true);
23438
23439   /* This assert could be relaxed - in this case we'll need to compute
23440      smallest power of two, containing in PIECE_SIZE_N and pass it to
23441      offset_address.  */
23442   gcc_assert ((piece_size_n & (piece_size_n - 1)) == 0);
23443   destmem = offset_address (destmem, tmp, piece_size_n);
23444   destmem = adjust_address (destmem, mode, 0);
23445
23446   if (!issetmem)
23447     {
23448       srcmem = offset_address (srcmem, copy_rtx (tmp), piece_size_n);
23449       srcmem = adjust_address (srcmem, mode, 0);
23450
23451       /* When unrolling for chips that reorder memory reads and writes,
23452          we can save registers by using single temporary.
23453          Also using 4 temporaries is overkill in 32bit mode.  */
23454       if (!TARGET_64BIT && 0)
23455         {
23456           for (i = 0; i < unroll; i++)
23457             {
23458               if (i)
23459                 {
23460                   destmem =
23461                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
23462                   srcmem =
23463                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
23464                 }
23465               emit_move_insn (destmem, srcmem);
23466             }
23467         }
23468       else
23469         {
23470           rtx tmpreg[4];
23471           gcc_assert (unroll <= 4);
23472           for (i = 0; i < unroll; i++)
23473             {
23474               tmpreg[i] = gen_reg_rtx (mode);
23475               if (i)
23476                 {
23477                   srcmem =
23478                     adjust_address (copy_rtx (srcmem), mode, GET_MODE_SIZE (mode));
23479                 }
23480               emit_move_insn (tmpreg[i], srcmem);
23481             }
23482           for (i = 0; i < unroll; i++)
23483             {
23484               if (i)
23485                 {
23486                   destmem =
23487                     adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
23488                 }
23489               emit_move_insn (destmem, tmpreg[i]);
23490             }
23491         }
23492     }
23493   else
23494     for (i = 0; i < unroll; i++)
23495       {
23496         if (i)
23497           destmem =
23498             adjust_address (copy_rtx (destmem), mode, GET_MODE_SIZE (mode));
23499         emit_move_insn (destmem, value);
23500       }
23501
23502   tmp = expand_simple_binop (iter_mode, PLUS, iter, piece_size, iter,
23503                              true, OPTAB_LIB_WIDEN);
23504   if (tmp != iter)
23505     emit_move_insn (iter, tmp);
23506
23507   emit_cmp_and_jump_insns (iter, size, LT, NULL_RTX, iter_mode,
23508                            true, top_label);
23509   if (expected_size != -1)
23510     {
23511       expected_size /= GET_MODE_SIZE (mode) * unroll;
23512       if (expected_size == 0)
23513         predict_jump (0);
23514       else if (expected_size > REG_BR_PROB_BASE)
23515         predict_jump (REG_BR_PROB_BASE - 1);
23516       else
23517         predict_jump (REG_BR_PROB_BASE - (REG_BR_PROB_BASE + expected_size / 2) / expected_size);
23518     }
23519   else
23520     predict_jump (REG_BR_PROB_BASE * 80 / 100);
23521   iter = ix86_zero_extend_to_Pmode (iter);
23522   tmp = expand_simple_binop (Pmode, PLUS, destptr, iter, destptr,
23523                              true, OPTAB_LIB_WIDEN);
23524   if (tmp != destptr)
23525     emit_move_insn (destptr, tmp);
23526   if (!issetmem)
23527     {
23528       tmp = expand_simple_binop (Pmode, PLUS, srcptr, iter, srcptr,
23529                                  true, OPTAB_LIB_WIDEN);
23530       if (tmp != srcptr)
23531         emit_move_insn (srcptr, tmp);
23532     }
23533   emit_label (out_label);
23534 }
23535
23536 /* Output "rep; mov" or "rep; stos" instruction depending on ISSETMEM argument.
23537    When ISSETMEM is true, arguments SRCMEM and SRCPTR are ignored.
23538    When ISSETMEM is false, arguments VALUE and ORIG_VALUE are ignored.
23539    For setmem case, VALUE is a promoted to a wider size ORIG_VALUE.
23540    ORIG_VALUE is the original value passed to memset to fill the memory with.
23541    Other arguments have same meaning as for previous function.  */
23542
23543 static void
23544 expand_set_or_movmem_via_rep (rtx destmem, rtx srcmem,
23545                            rtx destptr, rtx srcptr, rtx value, rtx orig_value,
23546                            rtx count,
23547                            machine_mode mode, bool issetmem)
23548 {
23549   rtx destexp;
23550   rtx srcexp;
23551   rtx countreg;
23552   HOST_WIDE_INT rounded_count;
23553
23554   /* If possible, it is shorter to use rep movs.
23555      TODO: Maybe it is better to move this logic to decide_alg.  */
23556   if (mode == QImode && CONST_INT_P (count) && !(INTVAL (count) & 3)
23557       && (!issetmem || orig_value == const0_rtx))
23558     mode = SImode;
23559
23560   if (destptr != XEXP (destmem, 0) || GET_MODE (destmem) != BLKmode)
23561     destmem = adjust_automodify_address_nv (destmem, BLKmode, destptr, 0);
23562
23563   countreg = ix86_zero_extend_to_Pmode (scale_counter (count,
23564                                                        GET_MODE_SIZE (mode)));
23565   if (mode != QImode)
23566     {
23567       destexp = gen_rtx_ASHIFT (Pmode, countreg,
23568                                 GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
23569       destexp = gen_rtx_PLUS (Pmode, destexp, destptr);
23570     }
23571   else
23572     destexp = gen_rtx_PLUS (Pmode, destptr, countreg);
23573   if ((!issetmem || orig_value == const0_rtx) && CONST_INT_P (count))
23574     {
23575       rounded_count = (INTVAL (count)
23576                        & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
23577       destmem = shallow_copy_rtx (destmem);
23578       set_mem_size (destmem, rounded_count);
23579     }
23580   else if (MEM_SIZE_KNOWN_P (destmem))
23581     clear_mem_size (destmem);
23582
23583   if (issetmem)
23584     {
23585       value = force_reg (mode, gen_lowpart (mode, value));
23586       emit_insn (gen_rep_stos (destptr, countreg, destmem, value, destexp));
23587     }
23588   else
23589     {
23590       if (srcptr != XEXP (srcmem, 0) || GET_MODE (srcmem) != BLKmode)
23591         srcmem = adjust_automodify_address_nv (srcmem, BLKmode, srcptr, 0);
23592       if (mode != QImode)
23593         {
23594           srcexp = gen_rtx_ASHIFT (Pmode, countreg,
23595                                    GEN_INT (exact_log2 (GET_MODE_SIZE (mode))));
23596           srcexp = gen_rtx_PLUS (Pmode, srcexp, srcptr);
23597         }
23598       else
23599         srcexp = gen_rtx_PLUS (Pmode, srcptr, countreg);
23600       if (CONST_INT_P (count))
23601         {
23602           rounded_count = (INTVAL (count)
23603                            & ~((HOST_WIDE_INT) GET_MODE_SIZE (mode) - 1));
23604           srcmem = shallow_copy_rtx (srcmem);
23605           set_mem_size (srcmem, rounded_count);
23606         }
23607       else
23608         {
23609           if (MEM_SIZE_KNOWN_P (srcmem))
23610             clear_mem_size (srcmem);
23611         }
23612       emit_insn (gen_rep_mov (destptr, destmem, srcptr, srcmem, countreg,
23613                               destexp, srcexp));
23614     }
23615 }
23616
23617 /* This function emits moves to copy SIZE_TO_MOVE bytes from SRCMEM to
23618    DESTMEM.
23619    SRC is passed by pointer to be updated on return.
23620    Return value is updated DST.  */
23621 static rtx
23622 emit_memmov (rtx destmem, rtx *srcmem, rtx destptr, rtx srcptr,
23623              HOST_WIDE_INT size_to_move)
23624 {
23625   rtx dst = destmem, src = *srcmem, adjust, tempreg;
23626   enum insn_code code;
23627   machine_mode move_mode;
23628   int piece_size, i;
23629
23630   /* Find the widest mode in which we could perform moves.
23631      Start with the biggest power of 2 less than SIZE_TO_MOVE and half
23632      it until move of such size is supported.  */
23633   piece_size = 1 << floor_log2 (size_to_move);
23634   move_mode = mode_for_size (piece_size * BITS_PER_UNIT, MODE_INT, 0);
23635   code = optab_handler (mov_optab, move_mode);
23636   while (code == CODE_FOR_nothing && piece_size > 1)
23637     {
23638       piece_size >>= 1;
23639       move_mode = mode_for_size (piece_size * BITS_PER_UNIT, MODE_INT, 0);
23640       code = optab_handler (mov_optab, move_mode);
23641     }
23642
23643   /* Find the corresponding vector mode with the same size as MOVE_MODE.
23644      MOVE_MODE is an integer mode at the moment (SI, DI, TI, etc.).  */
23645   if (GET_MODE_SIZE (move_mode) > GET_MODE_SIZE (word_mode))
23646     {
23647       int nunits = GET_MODE_SIZE (move_mode) / GET_MODE_SIZE (word_mode);
23648       move_mode = mode_for_vector (word_mode, nunits);
23649       code = optab_handler (mov_optab, move_mode);
23650       if (code == CODE_FOR_nothing)
23651         {
23652           move_mode = word_mode;
23653           piece_size = GET_MODE_SIZE (move_mode);
23654           code = optab_handler (mov_optab, move_mode);
23655         }
23656     }
23657   gcc_assert (code != CODE_FOR_nothing);
23658
23659   dst = adjust_automodify_address_nv (dst, move_mode, destptr, 0);
23660   src = adjust_automodify_address_nv (src, move_mode, srcptr, 0);
23661
23662   /* Emit moves.  We'll need SIZE_TO_MOVE/PIECE_SIZES moves.  */
23663   gcc_assert (size_to_move % piece_size == 0);
23664   adjust = GEN_INT (piece_size);
23665   for (i = 0; i < size_to_move; i += piece_size)
23666     {
23667       /* We move from memory to memory, so we'll need to do it via
23668          a temporary register.  */
23669       tempreg = gen_reg_rtx (move_mode);
23670       emit_insn (GEN_FCN (code) (tempreg, src));
23671       emit_insn (GEN_FCN (code) (dst, tempreg));
23672
23673       emit_move_insn (destptr,
23674                       gen_rtx_PLUS (Pmode, copy_rtx (destptr), adjust));
23675       emit_move_insn (srcptr,
23676                       gen_rtx_PLUS (Pmode, copy_rtx (srcptr), adjust));
23677
23678       dst = adjust_automodify_address_nv (dst, move_mode, destptr,
23679                                           piece_size);
23680       src = adjust_automodify_address_nv (src, move_mode, srcptr,
23681                                           piece_size);
23682     }
23683
23684   /* Update DST and SRC rtx.  */
23685   *srcmem = src;
23686   return dst;
23687 }
23688
23689 /* Output code to copy at most count & (max_size - 1) bytes from SRC to DEST.  */
23690 static void
23691 expand_movmem_epilogue (rtx destmem, rtx srcmem,
23692                         rtx destptr, rtx srcptr, rtx count, int max_size)
23693 {
23694   rtx src, dest;
23695   if (CONST_INT_P (count))
23696     {
23697       HOST_WIDE_INT countval = INTVAL (count);
23698       HOST_WIDE_INT epilogue_size = countval % max_size;
23699       int i;
23700
23701       /* For now MAX_SIZE should be a power of 2.  This assert could be
23702          relaxed, but it'll require a bit more complicated epilogue
23703          expanding.  */
23704       gcc_assert ((max_size & (max_size - 1)) == 0);
23705       for (i = max_size; i >= 1; i >>= 1)
23706         {
23707           if (epilogue_size & i)
23708             destmem = emit_memmov (destmem, &srcmem, destptr, srcptr, i);
23709         }
23710       return;
23711     }
23712   if (max_size > 8)
23713     {
23714       count = expand_simple_binop (GET_MODE (count), AND, count, GEN_INT (max_size - 1),
23715                                     count, 1, OPTAB_DIRECT);
23716       expand_set_or_movmem_via_loop (destmem, srcmem, destptr, srcptr, NULL,
23717                                      count, QImode, 1, 4, false);
23718       return;
23719     }
23720
23721   /* When there are stringops, we can cheaply increase dest and src pointers.
23722      Otherwise we save code size by maintaining offset (zero is readily
23723      available from preceding rep operation) and using x86 addressing modes.
23724    */
23725   if (TARGET_SINGLE_STRINGOP)
23726     {
23727       if (max_size > 4)
23728         {
23729           rtx_code_label *label = ix86_expand_aligntest (count, 4, true);
23730           src = change_address (srcmem, SImode, srcptr);
23731           dest = change_address (destmem, SImode, destptr);
23732           emit_insn (gen_strmov (destptr, dest, srcptr, src));
23733           emit_label (label);
23734           LABEL_NUSES (label) = 1;
23735         }
23736       if (max_size > 2)
23737         {
23738           rtx_code_label *label = ix86_expand_aligntest (count, 2, true);
23739           src = change_address (srcmem, HImode, srcptr);
23740           dest = change_address (destmem, HImode, destptr);
23741           emit_insn (gen_strmov (destptr, dest, srcptr, src));
23742           emit_label (label);
23743           LABEL_NUSES (label) = 1;
23744         }
23745       if (max_size > 1)
23746         {
23747           rtx_code_label *label = ix86_expand_aligntest (count, 1, true);
23748           src = change_address (srcmem, QImode, srcptr);
23749           dest = change_address (destmem, QImode, destptr);
23750           emit_insn (gen_strmov (destptr, dest, srcptr, src));
23751           emit_label (label);
23752           LABEL_NUSES (label) = 1;
23753         }
23754     }
23755   else
23756     {
23757       rtx offset = force_reg (Pmode, const0_rtx);
23758       rtx tmp;
23759
23760       if (max_size > 4)
23761         {
23762           rtx_code_label *label = ix86_expand_aligntest (count, 4, true);
23763           src = change_address (srcmem, SImode, srcptr);
23764           dest = change_address (destmem, SImode, destptr);
23765           emit_move_insn (dest, src);
23766           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (4), NULL,
23767                                      true, OPTAB_LIB_WIDEN);
23768           if (tmp != offset)
23769             emit_move_insn (offset, tmp);
23770           emit_label (label);
23771           LABEL_NUSES (label) = 1;
23772         }
23773       if (max_size > 2)
23774         {
23775           rtx_code_label *label = ix86_expand_aligntest (count, 2, true);
23776           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
23777           src = change_address (srcmem, HImode, tmp);
23778           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
23779           dest = change_address (destmem, HImode, tmp);
23780           emit_move_insn (dest, src);
23781           tmp = expand_simple_binop (Pmode, PLUS, offset, GEN_INT (2), tmp,
23782                                      true, OPTAB_LIB_WIDEN);
23783           if (tmp != offset)
23784             emit_move_insn (offset, tmp);
23785           emit_label (label);
23786           LABEL_NUSES (label) = 1;
23787         }
23788       if (max_size > 1)
23789         {
23790           rtx_code_label *label = ix86_expand_aligntest (count, 1, true);
23791           tmp = gen_rtx_PLUS (Pmode, srcptr, offset);
23792           src = change_address (srcmem, QImode, tmp);
23793           tmp = gen_rtx_PLUS (Pmode, destptr, offset);
23794           dest = change_address (destmem, QImode, tmp);
23795           emit_move_insn (dest, src);
23796           emit_label (label);
23797           LABEL_NUSES (label) = 1;
23798         }
23799     }
23800 }
23801
23802 /* This function emits moves to fill SIZE_TO_MOVE bytes starting from DESTMEM
23803    with value PROMOTED_VAL.
23804    SRC is passed by pointer to be updated on return.
23805    Return value is updated DST.  */
23806 static rtx
23807 emit_memset (rtx destmem, rtx destptr, rtx promoted_val,
23808              HOST_WIDE_INT size_to_move)
23809 {
23810   rtx dst = destmem, adjust;
23811   enum insn_code code;
23812   machine_mode move_mode;
23813   int piece_size, i;
23814
23815   /* Find the widest mode in which we could perform moves.
23816      Start with the biggest power of 2 less than SIZE_TO_MOVE and half
23817      it until move of such size is supported.  */
23818   move_mode = GET_MODE (promoted_val);
23819   if (move_mode == VOIDmode)
23820     move_mode = QImode;
23821   if (size_to_move < GET_MODE_SIZE (move_mode))
23822     {
23823       move_mode = mode_for_size (size_to_move * BITS_PER_UNIT, MODE_INT, 0);
23824       promoted_val = gen_lowpart (move_mode, promoted_val);
23825     }
23826   piece_size = GET_MODE_SIZE (move_mode);
23827   code = optab_handler (mov_optab, move_mode);
23828   gcc_assert (code != CODE_FOR_nothing && promoted_val != NULL_RTX);
23829
23830   dst = adjust_automodify_address_nv (dst, move_mode, destptr, 0);
23831
23832   /* Emit moves.  We'll need SIZE_TO_MOVE/PIECE_SIZES moves.  */
23833   gcc_assert (size_to_move % piece_size == 0);
23834   adjust = GEN_INT (piece_size);
23835   for (i = 0; i < size_to_move; i += piece_size)
23836     {
23837       if (piece_size <= GET_MODE_SIZE (word_mode))
23838         {
23839           emit_insn (gen_strset (destptr, dst, promoted_val));
23840           dst = adjust_automodify_address_nv (dst, move_mode, destptr,
23841                                               piece_size);
23842           continue;
23843         }
23844
23845       emit_insn (GEN_FCN (code) (dst, promoted_val));
23846
23847       emit_move_insn (destptr,
23848                       gen_rtx_PLUS (Pmode, copy_rtx (destptr), adjust));
23849
23850       dst = adjust_automodify_address_nv (dst, move_mode, destptr,
23851                                           piece_size);
23852     }
23853
23854   /* Update DST rtx.  */
23855   return dst;
23856 }
23857 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
23858 static void
23859 expand_setmem_epilogue_via_loop (rtx destmem, rtx destptr, rtx value,
23860                                  rtx count, int max_size)
23861 {
23862   count =
23863     expand_simple_binop (counter_mode (count), AND, count,
23864                          GEN_INT (max_size - 1), count, 1, OPTAB_DIRECT);
23865   expand_set_or_movmem_via_loop (destmem, NULL, destptr, NULL,
23866                                  gen_lowpart (QImode, value), count, QImode,
23867                                  1, max_size / 2, true);
23868 }
23869
23870 /* Output code to set at most count & (max_size - 1) bytes starting by DEST.  */
23871 static void
23872 expand_setmem_epilogue (rtx destmem, rtx destptr, rtx value, rtx vec_value,
23873                         rtx count, int max_size)
23874 {
23875   rtx dest;
23876
23877   if (CONST_INT_P (count))
23878     {
23879       HOST_WIDE_INT countval = INTVAL (count);
23880       HOST_WIDE_INT epilogue_size = countval % max_size;
23881       int i;
23882
23883       /* For now MAX_SIZE should be a power of 2.  This assert could be
23884          relaxed, but it'll require a bit more complicated epilogue
23885          expanding.  */
23886       gcc_assert ((max_size & (max_size - 1)) == 0);
23887       for (i = max_size; i >= 1; i >>= 1)
23888         {
23889           if (epilogue_size & i)
23890             {
23891               if (vec_value && i > GET_MODE_SIZE (GET_MODE (value)))
23892                 destmem = emit_memset (destmem, destptr, vec_value, i);
23893               else
23894                 destmem = emit_memset (destmem, destptr, value, i);
23895             }
23896         }
23897       return;
23898     }
23899   if (max_size > 32)
23900     {
23901       expand_setmem_epilogue_via_loop (destmem, destptr, value, count, max_size);
23902       return;
23903     }
23904   if (max_size > 16)
23905     {
23906       rtx_code_label *label = ix86_expand_aligntest (count, 16, true);
23907       if (TARGET_64BIT)
23908         {
23909           dest = change_address (destmem, DImode, destptr);
23910           emit_insn (gen_strset (destptr, dest, value));
23911           dest = adjust_automodify_address_nv (dest, DImode, destptr, 8);
23912           emit_insn (gen_strset (destptr, dest, value));
23913         }
23914       else
23915         {
23916           dest = change_address (destmem, SImode, destptr);
23917           emit_insn (gen_strset (destptr, dest, value));
23918           dest = adjust_automodify_address_nv (dest, SImode, destptr, 4);
23919           emit_insn (gen_strset (destptr, dest, value));
23920           dest = adjust_automodify_address_nv (dest, SImode, destptr, 8);
23921           emit_insn (gen_strset (destptr, dest, value));
23922           dest = adjust_automodify_address_nv (dest, SImode, destptr, 12);
23923           emit_insn (gen_strset (destptr, dest, value));
23924         }
23925       emit_label (label);
23926       LABEL_NUSES (label) = 1;
23927     }
23928   if (max_size > 8)
23929     {
23930       rtx_code_label *label = ix86_expand_aligntest (count, 8, true);
23931       if (TARGET_64BIT)
23932         {
23933           dest = change_address (destmem, DImode, destptr);
23934           emit_insn (gen_strset (destptr, dest, value));
23935         }
23936       else
23937         {
23938           dest = change_address (destmem, SImode, destptr);
23939           emit_insn (gen_strset (destptr, dest, value));
23940           dest = adjust_automodify_address_nv (dest, SImode, destptr, 4);
23941           emit_insn (gen_strset (destptr, dest, value));
23942         }
23943       emit_label (label);
23944       LABEL_NUSES (label) = 1;
23945     }
23946   if (max_size > 4)
23947     {
23948       rtx_code_label *label = ix86_expand_aligntest (count, 4, true);
23949       dest = change_address (destmem, SImode, destptr);
23950       emit_insn (gen_strset (destptr, dest, gen_lowpart (SImode, value)));
23951       emit_label (label);
23952       LABEL_NUSES (label) = 1;
23953     }
23954   if (max_size > 2)
23955     {
23956       rtx_code_label *label = ix86_expand_aligntest (count, 2, true);
23957       dest = change_address (destmem, HImode, destptr);
23958       emit_insn (gen_strset (destptr, dest, gen_lowpart (HImode, value)));
23959       emit_label (label);
23960       LABEL_NUSES (label) = 1;
23961     }
23962   if (max_size > 1)
23963     {
23964       rtx_code_label *label = ix86_expand_aligntest (count, 1, true);
23965       dest = change_address (destmem, QImode, destptr);
23966       emit_insn (gen_strset (destptr, dest, gen_lowpart (QImode, value)));
23967       emit_label (label);
23968       LABEL_NUSES (label) = 1;
23969     }
23970 }
23971
23972 /* Depending on ISSETMEM, copy enough from SRCMEM to DESTMEM or set enough to
23973    DESTMEM to align it to DESIRED_ALIGNMENT.  Original alignment is ALIGN.
23974    Depending on ISSETMEM, either arguments SRCMEM/SRCPTR or VALUE/VEC_VALUE are
23975    ignored.
23976    Return value is updated DESTMEM.  */
23977 static rtx
23978 expand_set_or_movmem_prologue (rtx destmem, rtx srcmem,
23979                                   rtx destptr, rtx srcptr, rtx value,
23980                                   rtx vec_value, rtx count, int align,
23981                                   int desired_alignment, bool issetmem)
23982 {
23983   int i;
23984   for (i = 1; i < desired_alignment; i <<= 1)
23985     {
23986       if (align <= i)
23987         {
23988           rtx_code_label *label = ix86_expand_aligntest (destptr, i, false);
23989           if (issetmem)
23990             {
23991               if (vec_value && i > GET_MODE_SIZE (GET_MODE (value)))
23992                 destmem = emit_memset (destmem, destptr, vec_value, i);
23993               else
23994                 destmem = emit_memset (destmem, destptr, value, i);
23995             }
23996           else
23997             destmem = emit_memmov (destmem, &srcmem, destptr, srcptr, i);
23998           ix86_adjust_counter (count, i);
23999           emit_label (label);
24000           LABEL_NUSES (label) = 1;
24001           set_mem_align (destmem, i * 2 * BITS_PER_UNIT);
24002         }
24003     }
24004   return destmem;
24005 }
24006
24007 /* Test if COUNT&SIZE is nonzero and if so, expand movme
24008    or setmem sequence that is valid for SIZE..2*SIZE-1 bytes
24009    and jump to DONE_LABEL.  */
24010 static void
24011 expand_small_movmem_or_setmem (rtx destmem, rtx srcmem,
24012                                rtx destptr, rtx srcptr,
24013                                rtx value, rtx vec_value,
24014                                rtx count, int size,
24015                                rtx done_label, bool issetmem)
24016 {
24017   rtx_code_label *label = ix86_expand_aligntest (count, size, false);
24018   machine_mode mode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 1);
24019   rtx modesize;
24020   int n;
24021
24022   /* If we do not have vector value to copy, we must reduce size.  */
24023   if (issetmem)
24024     {
24025       if (!vec_value)
24026         {
24027           if (GET_MODE (value) == VOIDmode && size > 8)
24028             mode = Pmode;
24029           else if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (value)))
24030             mode = GET_MODE (value);
24031         }
24032       else
24033         mode = GET_MODE (vec_value), value = vec_value;
24034     }
24035   else
24036     {
24037       /* Choose appropriate vector mode.  */
24038       if (size >= 32)
24039         mode = TARGET_AVX ? V32QImode : TARGET_SSE ? V16QImode : DImode;
24040       else if (size >= 16)
24041         mode = TARGET_SSE ? V16QImode : DImode;
24042       srcmem = change_address (srcmem, mode, srcptr);
24043     }
24044   destmem = change_address (destmem, mode, destptr);
24045   modesize = GEN_INT (GET_MODE_SIZE (mode));
24046   gcc_assert (GET_MODE_SIZE (mode) <= size);
24047   for (n = 0; n * GET_MODE_SIZE (mode) < size; n++)
24048     {
24049       if (issetmem)
24050         emit_move_insn (destmem, gen_lowpart (mode, value));
24051       else
24052         {
24053           emit_move_insn (destmem, srcmem);
24054           srcmem = offset_address (srcmem, modesize, GET_MODE_SIZE (mode));
24055         }
24056       destmem = offset_address (destmem, modesize, GET_MODE_SIZE (mode));
24057     }
24058
24059   destmem = offset_address (destmem, count, 1);
24060   destmem = offset_address (destmem, GEN_INT (-2 * size),
24061                             GET_MODE_SIZE (mode));
24062   if (!issetmem)
24063     {
24064       srcmem = offset_address (srcmem, count, 1);
24065       srcmem = offset_address (srcmem, GEN_INT (-2 * size),
24066                                GET_MODE_SIZE (mode));
24067     }
24068   for (n = 0; n * GET_MODE_SIZE (mode) < size; n++)
24069     {
24070       if (issetmem)
24071         emit_move_insn (destmem, gen_lowpart (mode, value));
24072       else
24073         {
24074           emit_move_insn (destmem, srcmem);
24075           srcmem = offset_address (srcmem, modesize, GET_MODE_SIZE (mode));
24076         }
24077       destmem = offset_address (destmem, modesize, GET_MODE_SIZE (mode));
24078     }
24079   emit_jump_insn (gen_jump (done_label));
24080   emit_barrier ();
24081
24082   emit_label (label);
24083   LABEL_NUSES (label) = 1;
24084 }
24085
24086 /* Handle small memcpy (up to SIZE that is supposed to be small power of 2.
24087    and get ready for the main memcpy loop by copying iniital DESIRED_ALIGN-ALIGN
24088    bytes and last SIZE bytes adjusitng DESTPTR/SRCPTR/COUNT in a way we can
24089    proceed with an loop copying SIZE bytes at once. Do moves in MODE.
24090    DONE_LABEL is a label after the whole copying sequence. The label is created
24091    on demand if *DONE_LABEL is NULL.
24092    MIN_SIZE is minimal size of block copied.  This value gets adjusted for new
24093    bounds after the initial copies. 
24094
24095    DESTMEM/SRCMEM are memory expressions pointing to the copies block,
24096    DESTPTR/SRCPTR are pointers to the block. DYNAMIC_CHECK indicate whether
24097    we will dispatch to a library call for large blocks.
24098
24099    In pseudocode we do:
24100
24101    if (COUNT < SIZE)
24102      {
24103        Assume that SIZE is 4. Bigger sizes are handled analogously
24104        if (COUNT & 4)
24105          {
24106             copy 4 bytes from SRCPTR to DESTPTR
24107             copy 4 bytes from SRCPTR + COUNT - 4 to DESTPTR + COUNT - 4
24108             goto done_label
24109          }
24110        if (!COUNT)
24111          goto done_label;
24112        copy 1 byte from SRCPTR to DESTPTR
24113        if (COUNT & 2)
24114          {
24115             copy 2 bytes from SRCPTR to DESTPTR
24116             copy 2 bytes from SRCPTR + COUNT - 2 to DESTPTR + COUNT - 2
24117          }
24118      }
24119    else
24120      {
24121        copy at least DESIRED_ALIGN-ALIGN bytes from SRCPTR to DESTPTR
24122        copy SIZE bytes from SRCPTR + COUNT - SIZE to DESTPTR + COUNT -SIZE
24123
24124        OLD_DESPTR = DESTPTR;
24125        Align DESTPTR up to DESIRED_ALIGN
24126        SRCPTR += DESTPTR - OLD_DESTPTR
24127        COUNT -= DEST_PTR - OLD_DESTPTR
24128        if (DYNAMIC_CHECK)
24129          Round COUNT down to multiple of SIZE
24130        << optional caller supplied zero size guard is here >>
24131        << optional caller suppplied dynamic check is here >>
24132        << caller supplied main copy loop is here >>
24133      }
24134    done_label:
24135   */
24136 static void
24137 expand_set_or_movmem_prologue_epilogue_by_misaligned_moves (rtx destmem, rtx srcmem,
24138                                                             rtx *destptr, rtx *srcptr,
24139                                                             machine_mode mode,
24140                                                             rtx value, rtx vec_value,
24141                                                             rtx *count,
24142                                                             rtx_code_label **done_label,
24143                                                             int size,
24144                                                             int desired_align,
24145                                                             int align,
24146                                                             unsigned HOST_WIDE_INT *min_size,
24147                                                             bool dynamic_check,
24148                                                             bool issetmem)
24149 {
24150   rtx_code_label *loop_label = NULL, *label;
24151   int n;
24152   rtx modesize;
24153   int prolog_size = 0;
24154   rtx mode_value;
24155
24156   /* Chose proper value to copy.  */
24157   if (issetmem && VECTOR_MODE_P (mode))
24158     mode_value = vec_value;
24159   else
24160     mode_value = value;
24161   gcc_assert (GET_MODE_SIZE (mode) <= size);
24162
24163   /* See if block is big or small, handle small blocks.  */
24164   if (!CONST_INT_P (*count) && *min_size < (unsigned HOST_WIDE_INT)size)
24165     {
24166       int size2 = size;
24167       loop_label = gen_label_rtx ();
24168
24169       if (!*done_label)
24170         *done_label = gen_label_rtx ();
24171
24172       emit_cmp_and_jump_insns (*count, GEN_INT (size2), GE, 0, GET_MODE (*count),
24173                                1, loop_label);
24174       size2 >>= 1;
24175
24176       /* Handle sizes > 3.  */
24177       for (;size2 > 2; size2 >>= 1)
24178         expand_small_movmem_or_setmem (destmem, srcmem,
24179                                        *destptr, *srcptr,
24180                                        value, vec_value,
24181                                        *count,
24182                                        size2, *done_label, issetmem);
24183       /* Nothing to copy?  Jump to DONE_LABEL if so */
24184       emit_cmp_and_jump_insns (*count, const0_rtx, EQ, 0, GET_MODE (*count),
24185                                1, *done_label);
24186
24187       /* Do a byte copy.  */
24188       destmem = change_address (destmem, QImode, *destptr);
24189       if (issetmem)
24190         emit_move_insn (destmem, gen_lowpart (QImode, value));
24191       else
24192         {
24193           srcmem = change_address (srcmem, QImode, *srcptr);
24194           emit_move_insn (destmem, srcmem);
24195         }
24196
24197       /* Handle sizes 2 and 3.  */
24198       label = ix86_expand_aligntest (*count, 2, false);
24199       destmem = change_address (destmem, HImode, *destptr);
24200       destmem = offset_address (destmem, *count, 1);
24201       destmem = offset_address (destmem, GEN_INT (-2), 2);
24202       if (issetmem)
24203         emit_move_insn (destmem, gen_lowpart (HImode, value));
24204       else
24205         {
24206           srcmem = change_address (srcmem, HImode, *srcptr);
24207           srcmem = offset_address (srcmem, *count, 1);
24208           srcmem = offset_address (srcmem, GEN_INT (-2), 2);
24209           emit_move_insn (destmem, srcmem);
24210         }
24211
24212       emit_label (label);
24213       LABEL_NUSES (label) = 1;
24214       emit_jump_insn (gen_jump (*done_label));
24215       emit_barrier ();
24216     }
24217   else
24218     gcc_assert (*min_size >= (unsigned HOST_WIDE_INT)size
24219                 || UINTVAL (*count) >= (unsigned HOST_WIDE_INT)size);
24220
24221   /* Start memcpy for COUNT >= SIZE.  */
24222   if (loop_label)
24223     {
24224        emit_label (loop_label);
24225        LABEL_NUSES (loop_label) = 1;
24226     }
24227
24228   /* Copy first desired_align bytes.  */
24229   if (!issetmem)
24230     srcmem = change_address (srcmem, mode, *srcptr);
24231   destmem = change_address (destmem, mode, *destptr);
24232   modesize = GEN_INT (GET_MODE_SIZE (mode));
24233   for (n = 0; prolog_size < desired_align - align; n++)
24234     {
24235       if (issetmem)
24236         emit_move_insn (destmem, mode_value);
24237       else
24238         {
24239           emit_move_insn (destmem, srcmem);
24240           srcmem = offset_address (srcmem, modesize, GET_MODE_SIZE (mode));
24241         }
24242       destmem = offset_address (destmem, modesize, GET_MODE_SIZE (mode));
24243       prolog_size += GET_MODE_SIZE (mode);
24244     }
24245
24246
24247   /* Copy last SIZE bytes.  */
24248   destmem = offset_address (destmem, *count, 1);
24249   destmem = offset_address (destmem,
24250                             GEN_INT (-size - prolog_size),
24251                             1);
24252   if (issetmem)
24253     emit_move_insn (destmem, mode_value);
24254   else
24255     {
24256       srcmem = offset_address (srcmem, *count, 1);
24257       srcmem = offset_address (srcmem,
24258                                GEN_INT (-size - prolog_size),
24259                                1);
24260       emit_move_insn (destmem, srcmem);
24261     }
24262   for (n = 1; n * GET_MODE_SIZE (mode) < size; n++)
24263     {
24264       destmem = offset_address (destmem, modesize, 1);
24265       if (issetmem)
24266         emit_move_insn (destmem, mode_value);
24267       else
24268         {
24269           srcmem = offset_address (srcmem, modesize, 1);
24270           emit_move_insn (destmem, srcmem);
24271         }
24272     }
24273
24274   /* Align destination.  */
24275   if (desired_align > 1 && desired_align > align)
24276     {
24277       rtx saveddest = *destptr;
24278
24279       gcc_assert (desired_align <= size);
24280       /* Align destptr up, place it to new register.  */
24281       *destptr = expand_simple_binop (GET_MODE (*destptr), PLUS, *destptr,
24282                                       GEN_INT (prolog_size),
24283                                       NULL_RTX, 1, OPTAB_DIRECT);
24284       *destptr = expand_simple_binop (GET_MODE (*destptr), AND, *destptr,
24285                                       GEN_INT (-desired_align),
24286                                       *destptr, 1, OPTAB_DIRECT);
24287       /* See how many bytes we skipped.  */
24288       saveddest = expand_simple_binop (GET_MODE (*destptr), MINUS, saveddest,
24289                                        *destptr,
24290                                        saveddest, 1, OPTAB_DIRECT);
24291       /* Adjust srcptr and count.  */
24292       if (!issetmem)
24293         *srcptr = expand_simple_binop (GET_MODE (*srcptr), MINUS, *srcptr, saveddest,
24294                                         *srcptr, 1, OPTAB_DIRECT);
24295       *count = expand_simple_binop (GET_MODE (*count), PLUS, *count,
24296                                     saveddest, *count, 1, OPTAB_DIRECT);
24297       /* We copied at most size + prolog_size.  */
24298       if (*min_size > (unsigned HOST_WIDE_INT)(size + prolog_size))
24299         *min_size = (*min_size - size) & ~(unsigned HOST_WIDE_INT)(size - 1);
24300       else
24301         *min_size = 0;
24302
24303       /* Our loops always round down the bock size, but for dispatch to library
24304          we need precise value.  */
24305       if (dynamic_check)
24306         *count = expand_simple_binop (GET_MODE (*count), AND, *count,
24307                                       GEN_INT (-size), *count, 1, OPTAB_DIRECT);
24308     }
24309   else
24310     {
24311       gcc_assert (prolog_size == 0);
24312       /* Decrease count, so we won't end up copying last word twice.  */
24313       if (!CONST_INT_P (*count))
24314         *count = expand_simple_binop (GET_MODE (*count), PLUS, *count,
24315                                       constm1_rtx, *count, 1, OPTAB_DIRECT);
24316       else
24317         *count = GEN_INT ((UINTVAL (*count) - 1) & ~(unsigned HOST_WIDE_INT)(size - 1));
24318       if (*min_size)
24319         *min_size = (*min_size - 1) & ~(unsigned HOST_WIDE_INT)(size - 1);
24320     }
24321 }
24322
24323
24324 /* This function is like the previous one, except here we know how many bytes
24325    need to be copied.  That allows us to update alignment not only of DST, which
24326    is returned, but also of SRC, which is passed as a pointer for that
24327    reason.  */
24328 static rtx
24329 expand_set_or_movmem_constant_prologue (rtx dst, rtx *srcp, rtx destreg,
24330                                            rtx srcreg, rtx value, rtx vec_value,
24331                                            int desired_align, int align_bytes,
24332                                            bool issetmem)
24333 {
24334   rtx src = NULL;
24335   rtx orig_dst = dst;
24336   rtx orig_src = NULL;
24337   int piece_size = 1;
24338   int copied_bytes = 0;
24339
24340   if (!issetmem)
24341     {
24342       gcc_assert (srcp != NULL);
24343       src = *srcp;
24344       orig_src = src;
24345     }
24346
24347   for (piece_size = 1;
24348        piece_size <= desired_align && copied_bytes < align_bytes;
24349        piece_size <<= 1)
24350     {
24351       if (align_bytes & piece_size)
24352         {
24353           if (issetmem)
24354             {
24355               if (vec_value && piece_size > GET_MODE_SIZE (GET_MODE (value)))
24356                 dst = emit_memset (dst, destreg, vec_value, piece_size);
24357               else
24358                 dst = emit_memset (dst, destreg, value, piece_size);
24359             }
24360           else
24361             dst = emit_memmov (dst, &src, destreg, srcreg, piece_size);
24362           copied_bytes += piece_size;
24363         }
24364     }
24365   if (MEM_ALIGN (dst) < (unsigned int) desired_align * BITS_PER_UNIT)
24366     set_mem_align (dst, desired_align * BITS_PER_UNIT);
24367   if (MEM_SIZE_KNOWN_P (orig_dst))
24368     set_mem_size (dst, MEM_SIZE (orig_dst) - align_bytes);
24369
24370   if (!issetmem)
24371     {
24372       int src_align_bytes = get_mem_align_offset (src, desired_align
24373                                                        * BITS_PER_UNIT);
24374       if (src_align_bytes >= 0)
24375         src_align_bytes = desired_align - src_align_bytes;
24376       if (src_align_bytes >= 0)
24377         {
24378           unsigned int src_align;
24379           for (src_align = desired_align; src_align >= 2; src_align >>= 1)
24380             {
24381               if ((src_align_bytes & (src_align - 1))
24382                    == (align_bytes & (src_align - 1)))
24383                 break;
24384             }
24385           if (src_align > (unsigned int) desired_align)
24386             src_align = desired_align;
24387           if (MEM_ALIGN (src) < src_align * BITS_PER_UNIT)
24388             set_mem_align (src, src_align * BITS_PER_UNIT);
24389         }
24390       if (MEM_SIZE_KNOWN_P (orig_src))
24391         set_mem_size (src, MEM_SIZE (orig_src) - align_bytes);
24392       *srcp = src;
24393     }
24394
24395   return dst;
24396 }
24397
24398 /* Return true if ALG can be used in current context.  
24399    Assume we expand memset if MEMSET is true.  */
24400 static bool
24401 alg_usable_p (enum stringop_alg alg, bool memset)
24402 {
24403   if (alg == no_stringop)
24404     return false;
24405   if (alg == vector_loop)
24406     return TARGET_SSE || TARGET_AVX;
24407   /* Algorithms using the rep prefix want at least edi and ecx;
24408      additionally, memset wants eax and memcpy wants esi.  Don't
24409      consider such algorithms if the user has appropriated those
24410      registers for their own purposes.  */
24411   if (alg == rep_prefix_1_byte
24412       || alg == rep_prefix_4_byte
24413       || alg == rep_prefix_8_byte)
24414     return !(fixed_regs[CX_REG] || fixed_regs[DI_REG]
24415              || (memset ? fixed_regs[AX_REG] : fixed_regs[SI_REG]));
24416   return true;
24417 }
24418
24419 /* Given COUNT and EXPECTED_SIZE, decide on codegen of string operation.  */
24420 static enum stringop_alg
24421 decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size,
24422             unsigned HOST_WIDE_INT min_size, unsigned HOST_WIDE_INT max_size,
24423             bool memset, bool zero_memset, int *dynamic_check, bool *noalign)
24424 {
24425   const struct stringop_algs * algs;
24426   bool optimize_for_speed;
24427   int max = 0;
24428   const struct processor_costs *cost;
24429   int i;
24430   bool any_alg_usable_p = false;
24431
24432   *noalign = false;
24433   *dynamic_check = -1;
24434
24435   /* Even if the string operation call is cold, we still might spend a lot
24436      of time processing large blocks.  */
24437   if (optimize_function_for_size_p (cfun)
24438       || (optimize_insn_for_size_p ()
24439           && (max_size < 256
24440               || (expected_size != -1 && expected_size < 256))))
24441     optimize_for_speed = false;
24442   else
24443     optimize_for_speed = true;
24444
24445   cost = optimize_for_speed ? ix86_cost : &ix86_size_cost;
24446   if (memset)
24447     algs = &cost->memset[TARGET_64BIT != 0];
24448   else
24449     algs = &cost->memcpy[TARGET_64BIT != 0];
24450
24451   /* See maximal size for user defined algorithm.  */
24452   for (i = 0; i < MAX_STRINGOP_ALGS; i++)
24453     {
24454       enum stringop_alg candidate = algs->size[i].alg;
24455       bool usable = alg_usable_p (candidate, memset);
24456       any_alg_usable_p |= usable;
24457
24458       if (candidate != libcall && candidate && usable)
24459           max = algs->size[i].max;
24460     }
24461
24462   /* If expected size is not known but max size is small enough
24463      so inline version is a win, set expected size into
24464      the range.  */
24465   if (((max > 1 && (unsigned HOST_WIDE_INT) max >= max_size) || max == -1)
24466       && expected_size == -1)
24467     expected_size = min_size / 2 + max_size / 2;
24468
24469   /* If user specified the algorithm, honnor it if possible.  */
24470   if (ix86_stringop_alg != no_stringop
24471       && alg_usable_p (ix86_stringop_alg, memset))
24472     return ix86_stringop_alg;
24473   /* rep; movq or rep; movl is the smallest variant.  */
24474   else if (!optimize_for_speed)
24475     {
24476       *noalign = true;
24477       if (!count || (count & 3) || (memset && !zero_memset))
24478         return alg_usable_p (rep_prefix_1_byte, memset)
24479                ? rep_prefix_1_byte : loop_1_byte;
24480       else
24481         return alg_usable_p (rep_prefix_4_byte, memset)
24482                ? rep_prefix_4_byte : loop;
24483     }
24484   /* Very tiny blocks are best handled via the loop, REP is expensive to
24485      setup.  */
24486   else if (expected_size != -1 && expected_size < 4)
24487     return loop_1_byte;
24488   else if (expected_size != -1)
24489     {
24490       enum stringop_alg alg = libcall;
24491       bool alg_noalign = false;
24492       for (i = 0; i < MAX_STRINGOP_ALGS; i++)
24493         {
24494           /* We get here if the algorithms that were not libcall-based
24495              were rep-prefix based and we are unable to use rep prefixes
24496              based on global register usage.  Break out of the loop and
24497              use the heuristic below.  */
24498           if (algs->size[i].max == 0)
24499             break;
24500           if (algs->size[i].max >= expected_size || algs->size[i].max == -1)
24501             {
24502               enum stringop_alg candidate = algs->size[i].alg;
24503
24504               if (candidate != libcall && alg_usable_p (candidate, memset))
24505                 {
24506                   alg = candidate;
24507                   alg_noalign = algs->size[i].noalign;
24508                 }
24509               /* Honor TARGET_INLINE_ALL_STRINGOPS by picking
24510                  last non-libcall inline algorithm.  */
24511               if (TARGET_INLINE_ALL_STRINGOPS)
24512                 {
24513                   /* When the current size is best to be copied by a libcall,
24514                      but we are still forced to inline, run the heuristic below
24515                      that will pick code for medium sized blocks.  */
24516                   if (alg != libcall)
24517                     {
24518                       *noalign = alg_noalign;
24519                       return alg;
24520                     }
24521                   else if (!any_alg_usable_p)
24522                     break;
24523                 }
24524               else if (alg_usable_p (candidate, memset))
24525                 {
24526                   *noalign = algs->size[i].noalign;
24527                   return candidate;
24528                 }
24529             }
24530         }
24531     }
24532   /* When asked to inline the call anyway, try to pick meaningful choice.
24533      We look for maximal size of block that is faster to copy by hand and
24534      take blocks of at most of that size guessing that average size will
24535      be roughly half of the block.
24536
24537      If this turns out to be bad, we might simply specify the preferred
24538      choice in ix86_costs.  */
24539   if ((TARGET_INLINE_ALL_STRINGOPS || TARGET_INLINE_STRINGOPS_DYNAMICALLY)
24540       && (algs->unknown_size == libcall
24541           || !alg_usable_p (algs->unknown_size, memset)))
24542     {
24543       enum stringop_alg alg;
24544
24545       /* If there aren't any usable algorithms, then recursing on
24546          smaller sizes isn't going to find anything.  Just return the
24547          simple byte-at-a-time copy loop.  */
24548       if (!any_alg_usable_p)
24549         {
24550           /* Pick something reasonable.  */
24551           if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
24552             *dynamic_check = 128;
24553           return loop_1_byte;
24554         }
24555       if (max <= 0)
24556         max = 4096;
24557       alg = decide_alg (count, max / 2, min_size, max_size, memset,
24558                         zero_memset, dynamic_check, noalign);
24559       gcc_assert (*dynamic_check == -1);
24560       if (TARGET_INLINE_STRINGOPS_DYNAMICALLY)
24561         *dynamic_check = max;
24562       else
24563         gcc_assert (alg != libcall);
24564       return alg;
24565     }
24566   return (alg_usable_p (algs->unknown_size, memset)
24567           ? algs->unknown_size : libcall);
24568 }
24569
24570 /* Decide on alignment.  We know that the operand is already aligned to ALIGN
24571    (ALIGN can be based on profile feedback and thus it is not 100% guaranteed).  */
24572 static int
24573 decide_alignment (int align,
24574                   enum stringop_alg alg,
24575                   int expected_size,
24576                   machine_mode move_mode)
24577 {
24578   int desired_align = 0;
24579
24580   gcc_assert (alg != no_stringop);
24581
24582   if (alg == libcall)
24583     return 0;
24584   if (move_mode == VOIDmode)
24585     return 0;
24586
24587   desired_align = GET_MODE_SIZE (move_mode);
24588   /* PentiumPro has special logic triggering for 8 byte aligned blocks.
24589      copying whole cacheline at once.  */
24590   if (TARGET_PENTIUMPRO
24591       && (alg == rep_prefix_4_byte || alg == rep_prefix_1_byte))
24592     desired_align = 8;
24593
24594   if (optimize_size)
24595     desired_align = 1;
24596   if (desired_align < align)
24597     desired_align = align;
24598   if (expected_size != -1 && expected_size < 4)
24599     desired_align = align;
24600
24601   return desired_align;
24602 }
24603
24604
24605 /* Helper function for memcpy.  For QImode value 0xXY produce
24606    0xXYXYXYXY of wide specified by MODE.  This is essentially
24607    a * 0x10101010, but we can do slightly better than
24608    synth_mult by unwinding the sequence by hand on CPUs with
24609    slow multiply.  */
24610 static rtx
24611 promote_duplicated_reg (machine_mode mode, rtx val)
24612 {
24613   machine_mode valmode = GET_MODE (val);
24614   rtx tmp;
24615   int nops = mode == DImode ? 3 : 2;
24616
24617   gcc_assert (mode == SImode || mode == DImode || val == const0_rtx);
24618   if (val == const0_rtx)
24619     return copy_to_mode_reg (mode, CONST0_RTX (mode));
24620   if (CONST_INT_P (val))
24621     {
24622       HOST_WIDE_INT v = INTVAL (val) & 255;
24623
24624       v |= v << 8;
24625       v |= v << 16;
24626       if (mode == DImode)
24627         v |= (v << 16) << 16;
24628       return copy_to_mode_reg (mode, gen_int_mode (v, mode));
24629     }
24630
24631   if (valmode == VOIDmode)
24632     valmode = QImode;
24633   if (valmode != QImode)
24634     val = gen_lowpart (QImode, val);
24635   if (mode == QImode)
24636     return val;
24637   if (!TARGET_PARTIAL_REG_STALL)
24638     nops--;
24639   if (ix86_cost->mult_init[mode == DImode ? 3 : 2]
24640       + ix86_cost->mult_bit * (mode == DImode ? 8 : 4)
24641       <= (ix86_cost->shift_const + ix86_cost->add) * nops
24642           + (COSTS_N_INSNS (TARGET_PARTIAL_REG_STALL == 0)))
24643     {
24644       rtx reg = convert_modes (mode, QImode, val, true);
24645       tmp = promote_duplicated_reg (mode, const1_rtx);
24646       return expand_simple_binop (mode, MULT, reg, tmp, NULL, 1,
24647                                   OPTAB_DIRECT);
24648     }
24649   else
24650     {
24651       rtx reg = convert_modes (mode, QImode, val, true);
24652
24653       if (!TARGET_PARTIAL_REG_STALL)
24654         if (mode == SImode)
24655           emit_insn (gen_movsi_insv_1 (reg, reg));
24656         else
24657           emit_insn (gen_movdi_insv_1 (reg, reg));
24658       else
24659         {
24660           tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (8),
24661                                      NULL, 1, OPTAB_DIRECT);
24662           reg =
24663             expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
24664         }
24665       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (16),
24666                                  NULL, 1, OPTAB_DIRECT);
24667       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
24668       if (mode == SImode)
24669         return reg;
24670       tmp = expand_simple_binop (mode, ASHIFT, reg, GEN_INT (32),
24671                                  NULL, 1, OPTAB_DIRECT);
24672       reg = expand_simple_binop (mode, IOR, reg, tmp, reg, 1, OPTAB_DIRECT);
24673       return reg;
24674     }
24675 }
24676
24677 /* Duplicate value VAL using promote_duplicated_reg into maximal size that will
24678    be needed by main loop copying SIZE_NEEDED chunks and prologue getting
24679    alignment from ALIGN to DESIRED_ALIGN.  */
24680 static rtx
24681 promote_duplicated_reg_to_size (rtx val, int size_needed, int desired_align,
24682                                 int align)
24683 {
24684   rtx promoted_val;
24685
24686   if (TARGET_64BIT
24687       && (size_needed > 4 || (desired_align > align && desired_align > 4)))
24688     promoted_val = promote_duplicated_reg (DImode, val);
24689   else if (size_needed > 2 || (desired_align > align && desired_align > 2))
24690     promoted_val = promote_duplicated_reg (SImode, val);
24691   else if (size_needed > 1 || (desired_align > align && desired_align > 1))
24692     promoted_val = promote_duplicated_reg (HImode, val);
24693   else
24694     promoted_val = val;
24695
24696   return promoted_val;
24697 }
24698
24699 /* Expand string move (memcpy) ot store (memset) operation.  Use i386 string
24700    operations when profitable.  The code depends upon architecture, block size
24701    and alignment, but always has one of the following overall structures:
24702
24703    Aligned move sequence:
24704
24705      1) Prologue guard: Conditional that jumps up to epilogues for small
24706         blocks that can be handled by epilogue alone.  This is faster
24707         but also needed for correctness, since prologue assume the block
24708         is larger than the desired alignment.
24709
24710         Optional dynamic check for size and libcall for large
24711         blocks is emitted here too, with -minline-stringops-dynamically.
24712
24713      2) Prologue: copy first few bytes in order to get destination
24714         aligned to DESIRED_ALIGN.  It is emitted only when ALIGN is less
24715         than DESIRED_ALIGN and up to DESIRED_ALIGN - ALIGN bytes can be
24716         copied.  We emit either a jump tree on power of two sized
24717         blocks, or a byte loop.
24718
24719      3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
24720         with specified algorithm.
24721
24722      4) Epilogue: code copying tail of the block that is too small to be
24723         handled by main body (or up to size guarded by prologue guard). 
24724
24725   Misaligned move sequence
24726
24727      1) missaligned move prologue/epilogue containing:
24728         a) Prologue handling small memory blocks and jumping to done_label
24729            (skipped if blocks are known to be large enough)
24730         b) Signle move copying first DESIRED_ALIGN-ALIGN bytes if alignment is
24731            needed by single possibly misaligned move
24732            (skipped if alignment is not needed)
24733         c) Copy of last SIZE_NEEDED bytes by possibly misaligned moves
24734
24735      2) Zero size guard dispatching to done_label, if needed
24736
24737      3) dispatch to library call, if needed,
24738
24739      3) Main body: the copying loop itself, copying in SIZE_NEEDED chunks
24740         with specified algorithm.  */
24741 bool
24742 ix86_expand_set_or_movmem (rtx dst, rtx src, rtx count_exp, rtx val_exp,
24743                            rtx align_exp, rtx expected_align_exp,
24744                            rtx expected_size_exp, rtx min_size_exp,
24745                            rtx max_size_exp, rtx probable_max_size_exp,
24746                            bool issetmem)
24747 {
24748   rtx destreg;
24749   rtx srcreg = NULL;
24750   rtx_code_label *label = NULL;
24751   rtx tmp;
24752   rtx_code_label *jump_around_label = NULL;
24753   HOST_WIDE_INT align = 1;
24754   unsigned HOST_WIDE_INT count = 0;
24755   HOST_WIDE_INT expected_size = -1;
24756   int size_needed = 0, epilogue_size_needed;
24757   int desired_align = 0, align_bytes = 0;
24758   enum stringop_alg alg;
24759   rtx promoted_val = NULL;
24760   rtx vec_promoted_val = NULL;
24761   bool force_loopy_epilogue = false;
24762   int dynamic_check;
24763   bool need_zero_guard = false;
24764   bool noalign;
24765   machine_mode move_mode = VOIDmode;
24766   int unroll_factor = 1;
24767   /* TODO: Once value ranges are available, fill in proper data.  */
24768   unsigned HOST_WIDE_INT min_size = 0;
24769   unsigned HOST_WIDE_INT max_size = -1;
24770   unsigned HOST_WIDE_INT probable_max_size = -1;
24771   bool misaligned_prologue_used = false;
24772
24773   if (CONST_INT_P (align_exp))
24774     align = INTVAL (align_exp);
24775   /* i386 can do misaligned access on reasonably increased cost.  */
24776   if (CONST_INT_P (expected_align_exp)
24777       && INTVAL (expected_align_exp) > align)
24778     align = INTVAL (expected_align_exp);
24779   /* ALIGN is the minimum of destination and source alignment, but we care here
24780      just about destination alignment.  */
24781   else if (!issetmem
24782            && MEM_ALIGN (dst) > (unsigned HOST_WIDE_INT) align * BITS_PER_UNIT)
24783     align = MEM_ALIGN (dst) / BITS_PER_UNIT;
24784
24785   if (CONST_INT_P (count_exp))
24786     {
24787       min_size = max_size = probable_max_size = count = expected_size
24788         = INTVAL (count_exp);
24789       /* When COUNT is 0, there is nothing to do.  */
24790       if (!count)
24791         return true;
24792     }
24793   else
24794     {
24795       if (min_size_exp)
24796         min_size = INTVAL (min_size_exp);
24797       if (max_size_exp)
24798         max_size = INTVAL (max_size_exp);
24799       if (probable_max_size_exp)
24800         probable_max_size = INTVAL (probable_max_size_exp);
24801       if (CONST_INT_P (expected_size_exp))
24802         expected_size = INTVAL (expected_size_exp);
24803      }
24804
24805   /* Make sure we don't need to care about overflow later on.  */
24806   if (count > ((unsigned HOST_WIDE_INT) 1 << 30))
24807     return false;
24808
24809   /* Step 0: Decide on preferred algorithm, desired alignment and
24810      size of chunks to be copied by main loop.  */
24811   alg = decide_alg (count, expected_size, min_size, probable_max_size,
24812                     issetmem,
24813                     issetmem && val_exp == const0_rtx,
24814                     &dynamic_check, &noalign);
24815   if (alg == libcall)
24816     return false;
24817   gcc_assert (alg != no_stringop);
24818
24819   /* For now vector-version of memset is generated only for memory zeroing, as
24820      creating of promoted vector value is very cheap in this case.  */
24821   if (issetmem && alg == vector_loop && val_exp != const0_rtx)
24822     alg = unrolled_loop;
24823
24824   if (!count)
24825     count_exp = copy_to_mode_reg (GET_MODE (count_exp), count_exp);
24826   destreg = ix86_copy_addr_to_reg (XEXP (dst, 0));
24827   if (!issetmem)
24828     srcreg = ix86_copy_addr_to_reg (XEXP (src, 0));
24829
24830   unroll_factor = 1;
24831   move_mode = word_mode;
24832   switch (alg)
24833     {
24834     case libcall:
24835     case no_stringop:
24836     case last_alg:
24837       gcc_unreachable ();
24838     case loop_1_byte:
24839       need_zero_guard = true;
24840       move_mode = QImode;
24841       break;
24842     case loop:
24843       need_zero_guard = true;
24844       break;
24845     case unrolled_loop:
24846       need_zero_guard = true;
24847       unroll_factor = (TARGET_64BIT ? 4 : 2);
24848       break;
24849     case vector_loop:
24850       need_zero_guard = true;
24851       unroll_factor = 4;
24852       /* Find the widest supported mode.  */
24853       move_mode = word_mode;
24854       while (optab_handler (mov_optab, GET_MODE_WIDER_MODE (move_mode))
24855              != CODE_FOR_nothing)
24856           move_mode = GET_MODE_WIDER_MODE (move_mode);
24857
24858       /* Find the corresponding vector mode with the same size as MOVE_MODE.
24859          MOVE_MODE is an integer mode at the moment (SI, DI, TI, etc.).  */
24860       if (GET_MODE_SIZE (move_mode) > GET_MODE_SIZE (word_mode))
24861         {
24862           int nunits = GET_MODE_SIZE (move_mode) / GET_MODE_SIZE (word_mode);
24863           move_mode = mode_for_vector (word_mode, nunits);
24864           if (optab_handler (mov_optab, move_mode) == CODE_FOR_nothing)
24865             move_mode = word_mode;
24866         }
24867       gcc_assert (optab_handler (mov_optab, move_mode) != CODE_FOR_nothing);
24868       break;
24869     case rep_prefix_8_byte:
24870       move_mode = DImode;
24871       break;
24872     case rep_prefix_4_byte:
24873       move_mode = SImode;
24874       break;
24875     case rep_prefix_1_byte:
24876       move_mode = QImode;
24877       break;
24878     }
24879   size_needed = GET_MODE_SIZE (move_mode) * unroll_factor;
24880   epilogue_size_needed = size_needed;
24881
24882   desired_align = decide_alignment (align, alg, expected_size, move_mode);
24883   if (!TARGET_ALIGN_STRINGOPS || noalign)
24884     align = desired_align;
24885
24886   /* Step 1: Prologue guard.  */
24887
24888   /* Alignment code needs count to be in register.  */
24889   if (CONST_INT_P (count_exp) && desired_align > align)
24890     {
24891       if (INTVAL (count_exp) > desired_align
24892           && INTVAL (count_exp) > size_needed)
24893         {
24894           align_bytes
24895             = get_mem_align_offset (dst, desired_align * BITS_PER_UNIT);
24896           if (align_bytes <= 0)
24897             align_bytes = 0;
24898           else
24899             align_bytes = desired_align - align_bytes;
24900         }
24901       if (align_bytes == 0)
24902         count_exp = force_reg (counter_mode (count_exp), count_exp);
24903     }
24904   gcc_assert (desired_align >= 1 && align >= 1);
24905
24906   /* Misaligned move sequences handle both prologue and epilogue at once.
24907      Default code generation results in a smaller code for large alignments
24908      and also avoids redundant job when sizes are known precisely.  */
24909   misaligned_prologue_used
24910     = (TARGET_MISALIGNED_MOVE_STRING_PRO_EPILOGUES
24911        && MAX (desired_align, epilogue_size_needed) <= 32
24912        && desired_align <= epilogue_size_needed
24913        && ((desired_align > align && !align_bytes)
24914            || (!count && epilogue_size_needed > 1)));
24915
24916   /* Do the cheap promotion to allow better CSE across the
24917      main loop and epilogue (ie one load of the big constant in the
24918      front of all code.  
24919      For now the misaligned move sequences do not have fast path
24920      without broadcasting.  */
24921   if (issetmem && ((CONST_INT_P (val_exp) || misaligned_prologue_used)))
24922     {
24923       if (alg == vector_loop)
24924         {
24925           gcc_assert (val_exp == const0_rtx);
24926           vec_promoted_val = promote_duplicated_reg (move_mode, val_exp);
24927           promoted_val = promote_duplicated_reg_to_size (val_exp,
24928                                                          GET_MODE_SIZE (word_mode),
24929                                                          desired_align, align);
24930         }
24931       else
24932         {
24933           promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
24934                                                          desired_align, align);
24935         }
24936     }
24937   /* Misaligned move sequences handles both prologues and epilogues at once.
24938      Default code generation results in smaller code for large alignments and
24939      also avoids redundant job when sizes are known precisely.  */
24940   if (misaligned_prologue_used)
24941     {
24942       /* Misaligned move prologue handled small blocks by itself.  */
24943       expand_set_or_movmem_prologue_epilogue_by_misaligned_moves
24944            (dst, src, &destreg, &srcreg,
24945             move_mode, promoted_val, vec_promoted_val,
24946             &count_exp,
24947             &jump_around_label,
24948             desired_align < align
24949             ? MAX (desired_align, epilogue_size_needed) : epilogue_size_needed,
24950             desired_align, align, &min_size, dynamic_check, issetmem);
24951       if (!issetmem)
24952         src = change_address (src, BLKmode, srcreg);
24953       dst = change_address (dst, BLKmode, destreg);
24954       set_mem_align (dst, desired_align * BITS_PER_UNIT);
24955       epilogue_size_needed = 0;
24956       if (need_zero_guard && !min_size)
24957         {
24958           /* It is possible that we copied enough so the main loop will not
24959              execute.  */
24960           gcc_assert (size_needed > 1);
24961           if (jump_around_label == NULL_RTX)
24962             jump_around_label = gen_label_rtx ();
24963           emit_cmp_and_jump_insns (count_exp,
24964                                    GEN_INT (size_needed),
24965                                    LTU, 0, counter_mode (count_exp), 1, jump_around_label);
24966           if (expected_size == -1
24967               || expected_size < (desired_align - align) / 2 + size_needed)
24968             predict_jump (REG_BR_PROB_BASE * 20 / 100);
24969           else
24970             predict_jump (REG_BR_PROB_BASE * 60 / 100);
24971         }
24972     }
24973   /* Ensure that alignment prologue won't copy past end of block.  */
24974   else if (size_needed > 1 || (desired_align > 1 && desired_align > align))
24975     {
24976       epilogue_size_needed = MAX (size_needed - 1, desired_align - align);
24977       /* Epilogue always copies COUNT_EXP & EPILOGUE_SIZE_NEEDED bytes.
24978          Make sure it is power of 2.  */
24979       epilogue_size_needed = 1 << (floor_log2 (epilogue_size_needed) + 1);
24980
24981       /* To improve performance of small blocks, we jump around the VAL
24982          promoting mode.  This mean that if the promoted VAL is not constant,
24983          we might not use it in the epilogue and have to use byte
24984          loop variant.  */
24985       if (issetmem && epilogue_size_needed > 2 && !promoted_val)
24986         force_loopy_epilogue = true;
24987       if ((count && count < (unsigned HOST_WIDE_INT) epilogue_size_needed)
24988           || max_size < (unsigned HOST_WIDE_INT) epilogue_size_needed)
24989         {
24990           /* If main algorithm works on QImode, no epilogue is needed.
24991              For small sizes just don't align anything.  */
24992           if (size_needed == 1)
24993             desired_align = align;
24994           else
24995             goto epilogue;
24996         }
24997       else if (!count
24998                && min_size < (unsigned HOST_WIDE_INT) epilogue_size_needed)
24999         {
25000           label = gen_label_rtx ();
25001           emit_cmp_and_jump_insns (count_exp,
25002                                    GEN_INT (epilogue_size_needed),
25003                                    LTU, 0, counter_mode (count_exp), 1, label);
25004           if (expected_size == -1 || expected_size < epilogue_size_needed)
25005             predict_jump (REG_BR_PROB_BASE * 60 / 100);
25006           else
25007             predict_jump (REG_BR_PROB_BASE * 20 / 100);
25008         }
25009     }
25010
25011   /* Emit code to decide on runtime whether library call or inline should be
25012      used.  */
25013   if (dynamic_check != -1)
25014     {
25015       if (!issetmem && CONST_INT_P (count_exp))
25016         {
25017           if (UINTVAL (count_exp) >= (unsigned HOST_WIDE_INT)dynamic_check)
25018             {
25019               emit_block_move_via_libcall (dst, src, count_exp, false);
25020               count_exp = const0_rtx;
25021               goto epilogue;
25022             }
25023         }
25024       else
25025         {
25026           rtx_code_label *hot_label = gen_label_rtx ();
25027           if (jump_around_label == NULL_RTX)
25028             jump_around_label = gen_label_rtx ();
25029           emit_cmp_and_jump_insns (count_exp, GEN_INT (dynamic_check - 1),
25030                                    LEU, 0, counter_mode (count_exp),
25031                                    1, hot_label);
25032           predict_jump (REG_BR_PROB_BASE * 90 / 100);
25033           if (issetmem)
25034             set_storage_via_libcall (dst, count_exp, val_exp, false);
25035           else
25036             emit_block_move_via_libcall (dst, src, count_exp, false);
25037           emit_jump (jump_around_label);
25038           emit_label (hot_label);
25039         }
25040     }
25041
25042   /* Step 2: Alignment prologue.  */
25043   /* Do the expensive promotion once we branched off the small blocks.  */
25044   if (issetmem && !promoted_val)
25045     promoted_val = promote_duplicated_reg_to_size (val_exp, size_needed,
25046                                                    desired_align, align);
25047
25048   if (desired_align > align && !misaligned_prologue_used)
25049     {
25050       if (align_bytes == 0)
25051         {
25052           /* Except for the first move in prologue, we no longer know
25053              constant offset in aliasing info.  It don't seems to worth
25054              the pain to maintain it for the first move, so throw away
25055              the info early.  */
25056           dst = change_address (dst, BLKmode, destreg);
25057           if (!issetmem)
25058             src = change_address (src, BLKmode, srcreg);
25059           dst = expand_set_or_movmem_prologue (dst, src, destreg, srcreg,
25060                                             promoted_val, vec_promoted_val,
25061                                             count_exp, align, desired_align,
25062                                             issetmem);
25063           /* At most desired_align - align bytes are copied.  */
25064           if (min_size < (unsigned)(desired_align - align))
25065             min_size = 0;
25066           else
25067             min_size -= desired_align - align;
25068         }
25069       else
25070         {
25071           /* If we know how many bytes need to be stored before dst is
25072              sufficiently aligned, maintain aliasing info accurately.  */
25073           dst = expand_set_or_movmem_constant_prologue (dst, &src, destreg,
25074                                                            srcreg,
25075                                                            promoted_val,
25076                                                            vec_promoted_val,
25077                                                            desired_align,
25078                                                            align_bytes,
25079                                                            issetmem);
25080
25081           count_exp = plus_constant (counter_mode (count_exp),
25082                                      count_exp, -align_bytes);
25083           count -= align_bytes;
25084           min_size -= align_bytes;
25085           max_size -= align_bytes;
25086         }
25087       if (need_zero_guard
25088           && !min_size
25089           && (count < (unsigned HOST_WIDE_INT) size_needed
25090               || (align_bytes == 0
25091                   && count < ((unsigned HOST_WIDE_INT) size_needed
25092                               + desired_align - align))))
25093         {
25094           /* It is possible that we copied enough so the main loop will not
25095              execute.  */
25096           gcc_assert (size_needed > 1);
25097           if (label == NULL_RTX)
25098             label = gen_label_rtx ();
25099           emit_cmp_and_jump_insns (count_exp,
25100                                    GEN_INT (size_needed),
25101                                    LTU, 0, counter_mode (count_exp), 1, label);
25102           if (expected_size == -1
25103               || expected_size < (desired_align - align) / 2 + size_needed)
25104             predict_jump (REG_BR_PROB_BASE * 20 / 100);
25105           else
25106             predict_jump (REG_BR_PROB_BASE * 60 / 100);
25107         }
25108     }
25109   if (label && size_needed == 1)
25110     {
25111       emit_label (label);
25112       LABEL_NUSES (label) = 1;
25113       label = NULL;
25114       epilogue_size_needed = 1;
25115       if (issetmem)
25116         promoted_val = val_exp;
25117     }
25118   else if (label == NULL_RTX && !misaligned_prologue_used)
25119     epilogue_size_needed = size_needed;
25120
25121   /* Step 3: Main loop.  */
25122
25123   switch (alg)
25124     {
25125     case libcall:
25126     case no_stringop:
25127     case last_alg:
25128       gcc_unreachable ();
25129     case loop_1_byte:
25130     case loop:
25131     case unrolled_loop:
25132       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg, promoted_val,
25133                                      count_exp, move_mode, unroll_factor,
25134                                      expected_size, issetmem);
25135       break;
25136     case vector_loop:
25137       expand_set_or_movmem_via_loop (dst, src, destreg, srcreg,
25138                                      vec_promoted_val, count_exp, move_mode,
25139                                      unroll_factor, expected_size, issetmem);
25140       break;
25141     case rep_prefix_8_byte:
25142     case rep_prefix_4_byte:
25143     case rep_prefix_1_byte:
25144       expand_set_or_movmem_via_rep (dst, src, destreg, srcreg, promoted_val,
25145                                        val_exp, count_exp, move_mode, issetmem);
25146       break;
25147     }
25148   /* Adjust properly the offset of src and dest memory for aliasing.  */
25149   if (CONST_INT_P (count_exp))
25150     {
25151       if (!issetmem)
25152         src = adjust_automodify_address_nv (src, BLKmode, srcreg,
25153                                             (count / size_needed) * size_needed);
25154       dst = adjust_automodify_address_nv (dst, BLKmode, destreg,
25155                                           (count / size_needed) * size_needed);
25156     }
25157   else
25158     {
25159       if (!issetmem)
25160         src = change_address (src, BLKmode, srcreg);
25161       dst = change_address (dst, BLKmode, destreg);
25162     }
25163
25164   /* Step 4: Epilogue to copy the remaining bytes.  */
25165  epilogue:
25166   if (label)
25167     {
25168       /* When the main loop is done, COUNT_EXP might hold original count,
25169          while we want to copy only COUNT_EXP & SIZE_NEEDED bytes.
25170          Epilogue code will actually copy COUNT_EXP & EPILOGUE_SIZE_NEEDED
25171          bytes. Compensate if needed.  */
25172
25173       if (size_needed < epilogue_size_needed)
25174         {
25175           tmp =
25176             expand_simple_binop (counter_mode (count_exp), AND, count_exp,
25177                                  GEN_INT (size_needed - 1), count_exp, 1,
25178                                  OPTAB_DIRECT);
25179           if (tmp != count_exp)
25180             emit_move_insn (count_exp, tmp);
25181         }
25182       emit_label (label);
25183       LABEL_NUSES (label) = 1;
25184     }
25185
25186   if (count_exp != const0_rtx && epilogue_size_needed > 1)
25187     {
25188       if (force_loopy_epilogue)
25189         expand_setmem_epilogue_via_loop (dst, destreg, val_exp, count_exp,
25190                                          epilogue_size_needed);
25191       else
25192         {
25193           if (issetmem)
25194             expand_setmem_epilogue (dst, destreg, promoted_val,
25195                                     vec_promoted_val, count_exp,
25196                                     epilogue_size_needed);
25197           else
25198             expand_movmem_epilogue (dst, src, destreg, srcreg, count_exp,
25199                                     epilogue_size_needed);
25200         }
25201     }
25202   if (jump_around_label)
25203     emit_label (jump_around_label);
25204   return true;
25205 }
25206
25207
25208 /* Expand the appropriate insns for doing strlen if not just doing
25209    repnz; scasb
25210
25211    out = result, initialized with the start address
25212    align_rtx = alignment of the address.
25213    scratch = scratch register, initialized with the startaddress when
25214         not aligned, otherwise undefined
25215
25216    This is just the body. It needs the initializations mentioned above and
25217    some address computing at the end.  These things are done in i386.md.  */
25218
25219 static void
25220 ix86_expand_strlensi_unroll_1 (rtx out, rtx src, rtx align_rtx)
25221 {
25222   int align;
25223   rtx tmp;
25224   rtx_code_label *align_2_label = NULL;
25225   rtx_code_label *align_3_label = NULL;
25226   rtx_code_label *align_4_label = gen_label_rtx ();
25227   rtx_code_label *end_0_label = gen_label_rtx ();
25228   rtx mem;
25229   rtx tmpreg = gen_reg_rtx (SImode);
25230   rtx scratch = gen_reg_rtx (SImode);
25231   rtx cmp;
25232
25233   align = 0;
25234   if (CONST_INT_P (align_rtx))
25235     align = INTVAL (align_rtx);
25236
25237   /* Loop to check 1..3 bytes for null to get an aligned pointer.  */
25238
25239   /* Is there a known alignment and is it less than 4?  */
25240   if (align < 4)
25241     {
25242       rtx scratch1 = gen_reg_rtx (Pmode);
25243       emit_move_insn (scratch1, out);
25244       /* Is there a known alignment and is it not 2? */
25245       if (align != 2)
25246         {
25247           align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */
25248           align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */
25249
25250           /* Leave just the 3 lower bits.  */
25251           align_rtx = expand_binop (Pmode, and_optab, scratch1, GEN_INT (3),
25252                                     NULL_RTX, 0, OPTAB_WIDEN);
25253
25254           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
25255                                    Pmode, 1, align_4_label);
25256           emit_cmp_and_jump_insns (align_rtx, const2_rtx, EQ, NULL,
25257                                    Pmode, 1, align_2_label);
25258           emit_cmp_and_jump_insns (align_rtx, const2_rtx, GTU, NULL,
25259                                    Pmode, 1, align_3_label);
25260         }
25261       else
25262         {
25263           /* Since the alignment is 2, we have to check 2 or 0 bytes;
25264              check if is aligned to 4 - byte.  */
25265
25266           align_rtx = expand_binop (Pmode, and_optab, scratch1, const2_rtx,
25267                                     NULL_RTX, 0, OPTAB_WIDEN);
25268
25269           emit_cmp_and_jump_insns (align_rtx, const0_rtx, EQ, NULL,
25270                                    Pmode, 1, align_4_label);
25271         }
25272
25273       mem = change_address (src, QImode, out);
25274
25275       /* Now compare the bytes.  */
25276
25277       /* Compare the first n unaligned byte on a byte per byte basis.  */
25278       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL,
25279                                QImode, 1, end_0_label);
25280
25281       /* Increment the address.  */
25282       emit_insn (ix86_gen_add3 (out, out, const1_rtx));
25283
25284       /* Not needed with an alignment of 2 */
25285       if (align != 2)
25286         {
25287           emit_label (align_2_label);
25288
25289           emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
25290                                    end_0_label);
25291
25292           emit_insn (ix86_gen_add3 (out, out, const1_rtx));
25293
25294           emit_label (align_3_label);
25295         }
25296
25297       emit_cmp_and_jump_insns (mem, const0_rtx, EQ, NULL, QImode, 1,
25298                                end_0_label);
25299
25300       emit_insn (ix86_gen_add3 (out, out, const1_rtx));
25301     }
25302
25303   /* Generate loop to check 4 bytes at a time.  It is not a good idea to
25304      align this loop.  It gives only huge programs, but does not help to
25305      speed up.  */
25306   emit_label (align_4_label);
25307
25308   mem = change_address (src, SImode, out);
25309   emit_move_insn (scratch, mem);
25310   emit_insn (ix86_gen_add3 (out, out, GEN_INT (4)));
25311
25312   /* This formula yields a nonzero result iff one of the bytes is zero.
25313      This saves three branches inside loop and many cycles.  */
25314
25315   emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101)));
25316   emit_insn (gen_one_cmplsi2 (scratch, scratch));
25317   emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch));
25318   emit_insn (gen_andsi3 (tmpreg, tmpreg,
25319                          gen_int_mode (0x80808080, SImode)));
25320   emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1,
25321                            align_4_label);
25322
25323   if (TARGET_CMOVE)
25324     {
25325        rtx reg = gen_reg_rtx (SImode);
25326        rtx reg2 = gen_reg_rtx (Pmode);
25327        emit_move_insn (reg, tmpreg);
25328        emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16)));
25329
25330        /* If zero is not in the first two bytes, move two bytes forward.  */
25331        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
25332        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
25333        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
25334        emit_insn (gen_rtx_SET (VOIDmode, tmpreg,
25335                                gen_rtx_IF_THEN_ELSE (SImode, tmp,
25336                                                      reg,
25337                                                      tmpreg)));
25338        /* Emit lea manually to avoid clobbering of flags.  */
25339        emit_insn (gen_rtx_SET (SImode, reg2,
25340                                gen_rtx_PLUS (Pmode, out, const2_rtx)));
25341
25342        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
25343        tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx);
25344        emit_insn (gen_rtx_SET (VOIDmode, out,
25345                                gen_rtx_IF_THEN_ELSE (Pmode, tmp,
25346                                                      reg2,
25347                                                      out)));
25348     }
25349   else
25350     {
25351        rtx_code_label *end_2_label = gen_label_rtx ();
25352        /* Is zero in the first two bytes? */
25353
25354        emit_insn (gen_testsi_ccno_1 (tmpreg, GEN_INT (0x8080)));
25355        tmp = gen_rtx_REG (CCNOmode, FLAGS_REG);
25356        tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx);
25357        tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
25358                             gen_rtx_LABEL_REF (VOIDmode, end_2_label),
25359                             pc_rtx);
25360        tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
25361        JUMP_LABEL (tmp) = end_2_label;
25362
25363        /* Not in the first two.  Move two bytes forward.  */
25364        emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16)));
25365        emit_insn (ix86_gen_add3 (out, out, const2_rtx));
25366
25367        emit_label (end_2_label);
25368
25369     }
25370
25371   /* Avoid branch in fixing the byte.  */
25372   tmpreg = gen_lowpart (QImode, tmpreg);
25373   emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg));
25374   tmp = gen_rtx_REG (CCmode, FLAGS_REG);
25375   cmp = gen_rtx_LTU (VOIDmode, tmp, const0_rtx);
25376   emit_insn (ix86_gen_sub3_carry (out, out, GEN_INT (3), tmp, cmp));
25377
25378   emit_label (end_0_label);
25379 }
25380
25381 /* Expand strlen.  */
25382
25383 bool
25384 ix86_expand_strlen (rtx out, rtx src, rtx eoschar, rtx align)
25385 {
25386   rtx addr, scratch1, scratch2, scratch3, scratch4;
25387
25388   /* The generic case of strlen expander is long.  Avoid it's
25389      expanding unless TARGET_INLINE_ALL_STRINGOPS.  */
25390
25391   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
25392       && !TARGET_INLINE_ALL_STRINGOPS
25393       && !optimize_insn_for_size_p ()
25394       && (!CONST_INT_P (align) || INTVAL (align) < 4))
25395     return false;
25396
25397   addr = force_reg (Pmode, XEXP (src, 0));
25398   scratch1 = gen_reg_rtx (Pmode);
25399
25400   if (TARGET_UNROLL_STRLEN && eoschar == const0_rtx && optimize > 1
25401       && !optimize_insn_for_size_p ())
25402     {
25403       /* Well it seems that some optimizer does not combine a call like
25404          foo(strlen(bar), strlen(bar));
25405          when the move and the subtraction is done here.  It does calculate
25406          the length just once when these instructions are done inside of
25407          output_strlen_unroll().  But I think since &bar[strlen(bar)] is
25408          often used and I use one fewer register for the lifetime of
25409          output_strlen_unroll() this is better.  */
25410
25411       emit_move_insn (out, addr);
25412
25413       ix86_expand_strlensi_unroll_1 (out, src, align);
25414
25415       /* strlensi_unroll_1 returns the address of the zero at the end of
25416          the string, like memchr(), so compute the length by subtracting
25417          the start address.  */
25418       emit_insn (ix86_gen_sub3 (out, out, addr));
25419     }
25420   else
25421     {
25422       rtx unspec;
25423
25424       /* Can't use this if the user has appropriated eax, ecx, or edi.  */
25425       if (fixed_regs[AX_REG] || fixed_regs[CX_REG] || fixed_regs[DI_REG])
25426         return false;
25427
25428       scratch2 = gen_reg_rtx (Pmode);
25429       scratch3 = gen_reg_rtx (Pmode);
25430       scratch4 = force_reg (Pmode, constm1_rtx);
25431
25432       emit_move_insn (scratch3, addr);
25433       eoschar = force_reg (QImode, eoschar);
25434
25435       src = replace_equiv_address_nv (src, scratch3);
25436
25437       /* If .md starts supporting :P, this can be done in .md.  */
25438       unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (4, src, eoschar, align,
25439                                                  scratch4), UNSPEC_SCAS);
25440       emit_insn (gen_strlenqi_1 (scratch1, scratch3, unspec));
25441       emit_insn (ix86_gen_one_cmpl2 (scratch2, scratch1));
25442       emit_insn (ix86_gen_add3 (out, scratch2, constm1_rtx));
25443     }
25444   return true;
25445 }
25446
25447 /* For given symbol (function) construct code to compute address of it's PLT
25448    entry in large x86-64 PIC model.  */
25449 static rtx
25450 construct_plt_address (rtx symbol)
25451 {
25452   rtx tmp, unspec;
25453
25454   gcc_assert (GET_CODE (symbol) == SYMBOL_REF);
25455   gcc_assert (ix86_cmodel == CM_LARGE_PIC && !TARGET_PECOFF);
25456   gcc_assert (Pmode == DImode);
25457
25458   tmp = gen_reg_rtx (Pmode);
25459   unspec = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, symbol), UNSPEC_PLTOFF);
25460
25461   emit_move_insn (tmp, gen_rtx_CONST (Pmode, unspec));
25462   emit_insn (ix86_gen_add3 (tmp, tmp, pic_offset_table_rtx));
25463   return tmp;
25464 }
25465
25466 rtx
25467 ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
25468                   rtx callarg2,
25469                   rtx pop, bool sibcall)
25470 {
25471   rtx vec[3];
25472   rtx use = NULL, call;
25473   unsigned int vec_len = 0;
25474
25475   if (pop == const0_rtx)
25476     pop = NULL;
25477   gcc_assert (!TARGET_64BIT || !pop);
25478
25479   if (TARGET_MACHO && !TARGET_64BIT)
25480     {
25481 #if TARGET_MACHO
25482       if (flag_pic && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF)
25483         fnaddr = machopic_indirect_call_target (fnaddr);
25484 #endif
25485     }
25486   else
25487     {
25488       /* Static functions and indirect calls don't need the pic register.  */
25489       if (flag_pic
25490           && (!TARGET_64BIT
25491               || (ix86_cmodel == CM_LARGE_PIC
25492                   && DEFAULT_ABI != MS_ABI))
25493           && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
25494           && ! SYMBOL_REF_LOCAL_P (XEXP (fnaddr, 0)))
25495         {
25496           use_reg (&use, gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM));
25497           if (ix86_use_pseudo_pic_reg ())
25498             emit_move_insn (gen_rtx_REG (Pmode, REAL_PIC_OFFSET_TABLE_REGNUM),
25499                             pic_offset_table_rtx);
25500         }
25501     }
25502
25503   /* Skip setting up RAX register for -mskip-rax-setup when there are no
25504      parameters passed in vector registers.  */
25505   if (TARGET_64BIT
25506       && (INTVAL (callarg2) > 0
25507           || (INTVAL (callarg2) == 0
25508               && (TARGET_SSE || !flag_skip_rax_setup))))
25509     {
25510       rtx al = gen_rtx_REG (QImode, AX_REG);
25511       emit_move_insn (al, callarg2);
25512       use_reg (&use, al);
25513     }
25514
25515   if (ix86_cmodel == CM_LARGE_PIC
25516       && !TARGET_PECOFF
25517       && MEM_P (fnaddr)
25518       && GET_CODE (XEXP (fnaddr, 0)) == SYMBOL_REF
25519       && !local_symbolic_operand (XEXP (fnaddr, 0), VOIDmode))
25520     fnaddr = gen_rtx_MEM (QImode, construct_plt_address (XEXP (fnaddr, 0)));
25521   else if (sibcall
25522            ? !sibcall_insn_operand (XEXP (fnaddr, 0), word_mode)
25523            : !call_insn_operand (XEXP (fnaddr, 0), word_mode))
25524     {
25525       fnaddr = convert_to_mode (word_mode, XEXP (fnaddr, 0), 1);
25526       fnaddr = gen_rtx_MEM (QImode, copy_to_mode_reg (word_mode, fnaddr));
25527     }
25528
25529   call = gen_rtx_CALL (VOIDmode, fnaddr, callarg1);
25530
25531   if (retval)
25532     {
25533       /* We should add bounds as destination register in case
25534          pointer with bounds may be returned.  */
25535       if (TARGET_MPX && SCALAR_INT_MODE_P (GET_MODE (retval)))
25536         {
25537           rtx b0 = gen_rtx_REG (BND64mode, FIRST_BND_REG);
25538           rtx b1 = gen_rtx_REG (BND64mode, FIRST_BND_REG + 1);
25539           retval = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (3, retval, b0, b1));
25540           chkp_put_regs_to_expr_list (retval);
25541         }
25542
25543       call = gen_rtx_SET (VOIDmode, retval, call);
25544     }
25545   vec[vec_len++] = call;
25546
25547   if (pop)
25548     {
25549       pop = gen_rtx_PLUS (Pmode, stack_pointer_rtx, pop);
25550       pop = gen_rtx_SET (VOIDmode, stack_pointer_rtx, pop);
25551       vec[vec_len++] = pop;
25552     }
25553
25554   if (TARGET_64BIT_MS_ABI
25555       && (!callarg2 || INTVAL (callarg2) != -2))
25556     {
25557       int const cregs_size
25558         = ARRAY_SIZE (x86_64_ms_sysv_extra_clobbered_registers);
25559       int i;
25560
25561       for (i = 0; i < cregs_size; i++)
25562         {
25563           int regno = x86_64_ms_sysv_extra_clobbered_registers[i];
25564           machine_mode mode = SSE_REGNO_P (regno) ? TImode : DImode;
25565
25566           clobber_reg (&use, gen_rtx_REG (mode, regno));
25567         }
25568     }
25569
25570   if (vec_len > 1)
25571     call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (vec_len, vec));
25572   call = emit_call_insn (call);
25573   if (use)
25574     CALL_INSN_FUNCTION_USAGE (call) = use;
25575
25576   return call;
25577 }
25578
25579 /* Output the assembly for a call instruction.  */
25580
25581 const char *
25582 ix86_output_call_insn (rtx_insn *insn, rtx call_op)
25583 {
25584   bool direct_p = constant_call_address_operand (call_op, VOIDmode);
25585   bool seh_nop_p = false;
25586   const char *xasm;
25587
25588   if (SIBLING_CALL_P (insn))
25589     {
25590       if (direct_p)
25591         xasm = "%!jmp\t%P0";
25592       /* SEH epilogue detection requires the indirect branch case
25593          to include REX.W.  */
25594       else if (TARGET_SEH)
25595         xasm = "%!rex.W jmp %A0";
25596       else
25597         xasm = "%!jmp\t%A0";
25598
25599       output_asm_insn (xasm, &call_op);
25600       return "";
25601     }
25602
25603   /* SEH unwinding can require an extra nop to be emitted in several
25604      circumstances.  Determine if we have one of those.  */
25605   if (TARGET_SEH)
25606     {
25607       rtx_insn *i;
25608
25609       for (i = NEXT_INSN (insn); i ; i = NEXT_INSN (i))
25610         {
25611           /* If we get to another real insn, we don't need the nop.  */
25612           if (INSN_P (i))
25613             break;
25614
25615           /* If we get to the epilogue note, prevent a catch region from
25616              being adjacent to the standard epilogue sequence.  If non-
25617              call-exceptions, we'll have done this during epilogue emission. */
25618           if (NOTE_P (i) && NOTE_KIND (i) == NOTE_INSN_EPILOGUE_BEG
25619               && !flag_non_call_exceptions
25620               && !can_throw_internal (insn))
25621             {
25622               seh_nop_p = true;
25623               break;
25624             }
25625         }
25626
25627       /* If we didn't find a real insn following the call, prevent the
25628          unwinder from looking into the next function.  */
25629       if (i == NULL)
25630         seh_nop_p = true;
25631     }
25632
25633   if (direct_p)
25634     xasm = "%!call\t%P0";
25635   else
25636     xasm = "%!call\t%A0";
25637
25638   output_asm_insn (xasm, &call_op);
25639
25640   if (seh_nop_p)
25641     return "nop";
25642
25643   return "";
25644 }
25645 \f
25646 /* Clear stack slot assignments remembered from previous functions.
25647    This is called from INIT_EXPANDERS once before RTL is emitted for each
25648    function.  */
25649
25650 static struct machine_function *
25651 ix86_init_machine_status (void)
25652 {
25653   struct machine_function *f;
25654
25655   f = ggc_cleared_alloc<machine_function> ();
25656   f->use_fast_prologue_epilogue_nregs = -1;
25657   f->call_abi = ix86_abi;
25658
25659   return f;
25660 }
25661
25662 /* Return a MEM corresponding to a stack slot with mode MODE.
25663    Allocate a new slot if necessary.
25664
25665    The RTL for a function can have several slots available: N is
25666    which slot to use.  */
25667
25668 rtx
25669 assign_386_stack_local (machine_mode mode, enum ix86_stack_slot n)
25670 {
25671   struct stack_local_entry *s;
25672
25673   gcc_assert (n < MAX_386_STACK_LOCALS);
25674
25675   for (s = ix86_stack_locals; s; s = s->next)
25676     if (s->mode == mode && s->n == n)
25677       return validize_mem (copy_rtx (s->rtl));
25678
25679   s = ggc_alloc<stack_local_entry> ();
25680   s->n = n;
25681   s->mode = mode;
25682   s->rtl = assign_stack_local (mode, GET_MODE_SIZE (mode), 0);
25683
25684   s->next = ix86_stack_locals;
25685   ix86_stack_locals = s;
25686   return validize_mem (copy_rtx (s->rtl));
25687 }
25688
25689 static void
25690 ix86_instantiate_decls (void)
25691 {
25692   struct stack_local_entry *s;
25693
25694   for (s = ix86_stack_locals; s; s = s->next)
25695     if (s->rtl != NULL_RTX)
25696       instantiate_decl_rtl (s->rtl);
25697 }
25698 \f
25699 /* Check whether x86 address PARTS is a pc-relative address.  */
25700
25701 static bool
25702 rip_relative_addr_p (struct ix86_address *parts)
25703 {
25704   rtx base, index, disp;
25705
25706   base = parts->base;
25707   index = parts->index;
25708   disp = parts->disp;
25709
25710   if (disp && !base && !index)
25711     {
25712       if (TARGET_64BIT)
25713         {
25714           rtx symbol = disp;
25715
25716           if (GET_CODE (disp) == CONST)
25717             symbol = XEXP (disp, 0);
25718           if (GET_CODE (symbol) == PLUS
25719               && CONST_INT_P (XEXP (symbol, 1)))
25720             symbol = XEXP (symbol, 0);
25721
25722           if (GET_CODE (symbol) == LABEL_REF
25723               || (GET_CODE (symbol) == SYMBOL_REF
25724                   && SYMBOL_REF_TLS_MODEL (symbol) == 0)
25725               || (GET_CODE (symbol) == UNSPEC
25726                   && (XINT (symbol, 1) == UNSPEC_GOTPCREL
25727                       || XINT (symbol, 1) == UNSPEC_PCREL
25728                       || XINT (symbol, 1) == UNSPEC_GOTNTPOFF)))
25729             return true;
25730         }
25731     }
25732   return false;
25733 }
25734
25735 /* Calculate the length of the memory address in the instruction encoding.
25736    Includes addr32 prefix, does not include the one-byte modrm, opcode,
25737    or other prefixes.  We never generate addr32 prefix for LEA insn.  */
25738
25739 int
25740 memory_address_length (rtx addr, bool lea)
25741 {
25742   struct ix86_address parts;
25743   rtx base, index, disp;
25744   int len;
25745   int ok;
25746
25747   if (GET_CODE (addr) == PRE_DEC
25748       || GET_CODE (addr) == POST_INC
25749       || GET_CODE (addr) == PRE_MODIFY
25750       || GET_CODE (addr) == POST_MODIFY)
25751     return 0;
25752
25753   ok = ix86_decompose_address (addr, &parts);
25754   gcc_assert (ok);
25755
25756   len = (parts.seg == SEG_DEFAULT) ? 0 : 1;
25757
25758   /*  If this is not LEA instruction, add the length of addr32 prefix.  */
25759   if (TARGET_64BIT && !lea
25760       && (SImode_address_operand (addr, VOIDmode)
25761           || (parts.base && GET_MODE (parts.base) == SImode)
25762           || (parts.index && GET_MODE (parts.index) == SImode)))
25763     len++;
25764
25765   base = parts.base;
25766   index = parts.index;
25767   disp = parts.disp;
25768
25769   if (base && GET_CODE (base) == SUBREG)
25770     base = SUBREG_REG (base);
25771   if (index && GET_CODE (index) == SUBREG)
25772     index = SUBREG_REG (index);
25773
25774   gcc_assert (base == NULL_RTX || REG_P (base));
25775   gcc_assert (index == NULL_RTX || REG_P (index));
25776
25777   /* Rule of thumb:
25778        - esp as the base always wants an index,
25779        - ebp as the base always wants a displacement,
25780        - r12 as the base always wants an index,
25781        - r13 as the base always wants a displacement.  */
25782
25783   /* Register Indirect.  */
25784   if (base && !index && !disp)
25785     {
25786       /* esp (for its index) and ebp (for its displacement) need
25787          the two-byte modrm form.  Similarly for r12 and r13 in 64-bit
25788          code.  */
25789       if (base == arg_pointer_rtx
25790           || base == frame_pointer_rtx
25791           || REGNO (base) == SP_REG
25792           || REGNO (base) == BP_REG
25793           || REGNO (base) == R12_REG
25794           || REGNO (base) == R13_REG)
25795         len++;
25796     }
25797
25798   /* Direct Addressing.  In 64-bit mode mod 00 r/m 5
25799      is not disp32, but disp32(%rip), so for disp32
25800      SIB byte is needed, unless print_operand_address
25801      optimizes it into disp32(%rip) or (%rip) is implied
25802      by UNSPEC.  */
25803   else if (disp && !base && !index)
25804     {
25805       len += 4;
25806       if (rip_relative_addr_p (&parts))
25807         len++;
25808     }
25809   else
25810     {
25811       /* Find the length of the displacement constant.  */
25812       if (disp)
25813         {
25814           if (base && satisfies_constraint_K (disp))
25815             len += 1;
25816           else
25817             len += 4;
25818         }
25819       /* ebp always wants a displacement.  Similarly r13.  */
25820       else if (base && (REGNO (base) == BP_REG || REGNO (base) == R13_REG))
25821         len++;
25822
25823       /* An index requires the two-byte modrm form....  */
25824       if (index
25825           /* ...like esp (or r12), which always wants an index.  */
25826           || base == arg_pointer_rtx
25827           || base == frame_pointer_rtx
25828           || (base && (REGNO (base) == SP_REG || REGNO (base) == R12_REG)))
25829         len++;
25830     }
25831
25832   return len;
25833 }
25834
25835 /* Compute default value for "length_immediate" attribute.  When SHORTFORM
25836    is set, expect that insn have 8bit immediate alternative.  */
25837 int
25838 ix86_attr_length_immediate_default (rtx_insn *insn, bool shortform)
25839 {
25840   int len = 0;
25841   int i;
25842   extract_insn_cached (insn);
25843   for (i = recog_data.n_operands - 1; i >= 0; --i)
25844     if (CONSTANT_P (recog_data.operand[i]))
25845       {
25846         enum attr_mode mode = get_attr_mode (insn);
25847
25848         gcc_assert (!len);
25849         if (shortform && CONST_INT_P (recog_data.operand[i]))
25850           {
25851             HOST_WIDE_INT ival = INTVAL (recog_data.operand[i]);
25852             switch (mode)
25853               {
25854               case MODE_QI:
25855                 len = 1;
25856                 continue;
25857               case MODE_HI:
25858                 ival = trunc_int_for_mode (ival, HImode);
25859                 break;
25860               case MODE_SI:
25861                 ival = trunc_int_for_mode (ival, SImode);
25862                 break;
25863               default:
25864                 break;
25865               }
25866             if (IN_RANGE (ival, -128, 127))
25867               {
25868                 len = 1;
25869                 continue;
25870               }
25871           }
25872         switch (mode)
25873           {
25874           case MODE_QI:
25875             len = 1;
25876             break;
25877           case MODE_HI:
25878             len = 2;
25879             break;
25880           case MODE_SI:
25881             len = 4;
25882             break;
25883           /* Immediates for DImode instructions are encoded
25884              as 32bit sign extended values.  */
25885           case MODE_DI:
25886             len = 4;
25887             break;
25888           default:
25889             fatal_insn ("unknown insn mode", insn);
25890         }
25891       }
25892   return len;
25893 }
25894
25895 /* Compute default value for "length_address" attribute.  */
25896 int
25897 ix86_attr_length_address_default (rtx_insn *insn)
25898 {
25899   int i;
25900
25901   if (get_attr_type (insn) == TYPE_LEA)
25902     {
25903       rtx set = PATTERN (insn), addr;
25904
25905       if (GET_CODE (set) == PARALLEL)
25906         set = XVECEXP (set, 0, 0);
25907
25908       gcc_assert (GET_CODE (set) == SET);
25909
25910       addr = SET_SRC (set);
25911
25912       return memory_address_length (addr, true);
25913     }
25914
25915   extract_insn_cached (insn);
25916   for (i = recog_data.n_operands - 1; i >= 0; --i)
25917     if (MEM_P (recog_data.operand[i]))
25918       {
25919         constrain_operands_cached (insn, reload_completed);
25920         if (which_alternative != -1)
25921           {
25922             const char *constraints = recog_data.constraints[i];
25923             int alt = which_alternative;
25924
25925             while (*constraints == '=' || *constraints == '+')
25926               constraints++;
25927             while (alt-- > 0)
25928               while (*constraints++ != ',')
25929                 ;
25930             /* Skip ignored operands.  */
25931             if (*constraints == 'X')
25932               continue;
25933           }
25934         return memory_address_length (XEXP (recog_data.operand[i], 0), false);
25935       }
25936   return 0;
25937 }
25938
25939 /* Compute default value for "length_vex" attribute. It includes
25940    2 or 3 byte VEX prefix and 1 opcode byte.  */
25941
25942 int
25943 ix86_attr_length_vex_default (rtx_insn *insn, bool has_0f_opcode,
25944                               bool has_vex_w)
25945 {
25946   int i;
25947
25948   /* Only 0f opcode can use 2 byte VEX prefix and  VEX W bit uses 3
25949      byte VEX prefix.  */
25950   if (!has_0f_opcode || has_vex_w)
25951     return 3 + 1;
25952
25953  /* We can always use 2 byte VEX prefix in 32bit.  */
25954   if (!TARGET_64BIT)
25955     return 2 + 1;
25956
25957   extract_insn_cached (insn);
25958
25959   for (i = recog_data.n_operands - 1; i >= 0; --i)
25960     if (REG_P (recog_data.operand[i]))
25961       {
25962         /* REX.W bit uses 3 byte VEX prefix.  */
25963         if (GET_MODE (recog_data.operand[i]) == DImode
25964             && GENERAL_REG_P (recog_data.operand[i]))
25965           return 3 + 1;
25966       }
25967     else
25968       {
25969         /* REX.X or REX.B bits use 3 byte VEX prefix.  */
25970         if (MEM_P (recog_data.operand[i])
25971             && x86_extended_reg_mentioned_p (recog_data.operand[i]))
25972           return 3 + 1;
25973       }
25974
25975   return 2 + 1;
25976 }
25977 \f
25978 /* Return the maximum number of instructions a cpu can issue.  */
25979
25980 static int
25981 ix86_issue_rate (void)
25982 {
25983   switch (ix86_tune)
25984     {
25985     case PROCESSOR_PENTIUM:
25986     case PROCESSOR_BONNELL:
25987     case PROCESSOR_SILVERMONT:
25988     case PROCESSOR_KNL:
25989     case PROCESSOR_INTEL:
25990     case PROCESSOR_K6:
25991     case PROCESSOR_BTVER2:
25992     case PROCESSOR_PENTIUM4:
25993     case PROCESSOR_NOCONA:
25994       return 2;
25995
25996     case PROCESSOR_PENTIUMPRO:
25997     case PROCESSOR_ATHLON:
25998     case PROCESSOR_K8:
25999     case PROCESSOR_AMDFAM10:
26000     case PROCESSOR_GENERIC:
26001     case PROCESSOR_BTVER1:
26002       return 3;
26003
26004     case PROCESSOR_BDVER1:
26005     case PROCESSOR_BDVER2:
26006     case PROCESSOR_BDVER3:
26007     case PROCESSOR_BDVER4:
26008     case PROCESSOR_CORE2:
26009     case PROCESSOR_NEHALEM:
26010     case PROCESSOR_SANDYBRIDGE:
26011     case PROCESSOR_HASWELL:
26012       return 4;
26013
26014     default:
26015       return 1;
26016     }
26017 }
26018
26019 /* A subroutine of ix86_adjust_cost -- return TRUE iff INSN reads flags set
26020    by DEP_INSN and nothing set by DEP_INSN.  */
26021
26022 static bool
26023 ix86_flags_dependent (rtx_insn *insn, rtx_insn *dep_insn, enum attr_type insn_type)
26024 {
26025   rtx set, set2;
26026
26027   /* Simplify the test for uninteresting insns.  */
26028   if (insn_type != TYPE_SETCC
26029       && insn_type != TYPE_ICMOV
26030       && insn_type != TYPE_FCMOV
26031       && insn_type != TYPE_IBR)
26032     return false;
26033
26034   if ((set = single_set (dep_insn)) != 0)
26035     {
26036       set = SET_DEST (set);
26037       set2 = NULL_RTX;
26038     }
26039   else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL
26040            && XVECLEN (PATTERN (dep_insn), 0) == 2
26041            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET
26042            && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET)
26043     {
26044       set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
26045       set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0));
26046     }
26047   else
26048     return false;
26049
26050   if (!REG_P (set) || REGNO (set) != FLAGS_REG)
26051     return false;
26052
26053   /* This test is true if the dependent insn reads the flags but
26054      not any other potentially set register.  */
26055   if (!reg_overlap_mentioned_p (set, PATTERN (insn)))
26056     return false;
26057
26058   if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn)))
26059     return false;
26060
26061   return true;
26062 }
26063
26064 /* Return true iff USE_INSN has a memory address with operands set by
26065    SET_INSN.  */
26066
26067 bool
26068 ix86_agi_dependent (rtx_insn *set_insn, rtx_insn *use_insn)
26069 {
26070   int i;
26071   extract_insn_cached (use_insn);
26072   for (i = recog_data.n_operands - 1; i >= 0; --i)
26073     if (MEM_P (recog_data.operand[i]))
26074       {
26075         rtx addr = XEXP (recog_data.operand[i], 0);
26076         return modified_in_p (addr, set_insn) != 0;
26077       }
26078   return false;
26079 }
26080
26081 /* Helper function for exact_store_load_dependency.
26082    Return true if addr is found in insn.  */
26083 static bool
26084 exact_dependency_1 (rtx addr, rtx insn)
26085 {
26086   enum rtx_code code;
26087   const char *format_ptr;
26088   int i, j;
26089
26090   code = GET_CODE (insn);
26091   switch (code)
26092     {
26093     case MEM:
26094       if (rtx_equal_p (addr, insn))
26095         return true;
26096       break;
26097     case REG:
26098     CASE_CONST_ANY:
26099     case SYMBOL_REF:
26100     case CODE_LABEL:
26101     case PC:
26102     case CC0:
26103     case EXPR_LIST:
26104       return false;
26105     default:
26106       break;
26107     }
26108
26109   format_ptr = GET_RTX_FORMAT (code);
26110   for (i = 0; i < GET_RTX_LENGTH (code); i++)
26111     {
26112       switch (*format_ptr++)
26113         {
26114         case 'e':
26115           if (exact_dependency_1 (addr, XEXP (insn, i)))
26116             return true;
26117           break;
26118         case 'E':
26119           for (j = 0; j < XVECLEN (insn, i); j++)
26120             if (exact_dependency_1 (addr, XVECEXP (insn, i, j)))
26121               return true;
26122             break;
26123         }
26124     }
26125   return false;
26126 }
26127
26128 /* Return true if there exists exact dependency for store & load, i.e.
26129    the same memory address is used in them.  */
26130 static bool
26131 exact_store_load_dependency (rtx_insn *store, rtx_insn *load)
26132 {
26133   rtx set1, set2;
26134
26135   set1 = single_set (store);
26136   if (!set1)
26137     return false;
26138   if (!MEM_P (SET_DEST (set1)))
26139     return false;
26140   set2 = single_set (load);
26141   if (!set2)
26142     return false;
26143   if (exact_dependency_1 (SET_DEST (set1), SET_SRC (set2)))
26144     return true;
26145   return false;
26146 }
26147
26148 static int
26149 ix86_adjust_cost (rtx_insn *insn, rtx link, rtx_insn *dep_insn, int cost)
26150 {
26151   enum attr_type insn_type, dep_insn_type;
26152   enum attr_memory memory;
26153   rtx set, set2;
26154   int dep_insn_code_number;
26155
26156   /* Anti and output dependencies have zero cost on all CPUs.  */
26157   if (REG_NOTE_KIND (link) != 0)
26158     return 0;
26159
26160   dep_insn_code_number = recog_memoized (dep_insn);
26161
26162   /* If we can't recognize the insns, we can't really do anything.  */
26163   if (dep_insn_code_number < 0 || recog_memoized (insn) < 0)
26164     return cost;
26165
26166   insn_type = get_attr_type (insn);
26167   dep_insn_type = get_attr_type (dep_insn);
26168
26169   switch (ix86_tune)
26170     {
26171     case PROCESSOR_PENTIUM:
26172       /* Address Generation Interlock adds a cycle of latency.  */
26173       if (insn_type == TYPE_LEA)
26174         {
26175           rtx addr = PATTERN (insn);
26176
26177           if (GET_CODE (addr) == PARALLEL)
26178             addr = XVECEXP (addr, 0, 0);
26179
26180           gcc_assert (GET_CODE (addr) == SET);
26181
26182           addr = SET_SRC (addr);
26183           if (modified_in_p (addr, dep_insn))
26184             cost += 1;
26185         }
26186       else if (ix86_agi_dependent (dep_insn, insn))
26187         cost += 1;
26188
26189       /* ??? Compares pair with jump/setcc.  */
26190       if (ix86_flags_dependent (insn, dep_insn, insn_type))
26191         cost = 0;
26192
26193       /* Floating point stores require value to be ready one cycle earlier.  */
26194       if (insn_type == TYPE_FMOV
26195           && get_attr_memory (insn) == MEMORY_STORE
26196           && !ix86_agi_dependent (dep_insn, insn))
26197         cost += 1;
26198       break;
26199
26200     case PROCESSOR_PENTIUMPRO:
26201       /* INT->FP conversion is expensive.  */
26202       if (get_attr_fp_int_src (dep_insn))
26203         cost += 5;
26204
26205       /* There is one cycle extra latency between an FP op and a store.  */
26206       if (insn_type == TYPE_FMOV
26207           && (set = single_set (dep_insn)) != NULL_RTX
26208           && (set2 = single_set (insn)) != NULL_RTX
26209           && rtx_equal_p (SET_DEST (set), SET_SRC (set2))
26210           && MEM_P (SET_DEST (set2)))
26211         cost += 1;
26212
26213       memory = get_attr_memory (insn);
26214
26215       /* Show ability of reorder buffer to hide latency of load by executing
26216          in parallel with previous instruction in case
26217          previous instruction is not needed to compute the address.  */
26218       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26219           && !ix86_agi_dependent (dep_insn, insn))
26220         {
26221           /* Claim moves to take one cycle, as core can issue one load
26222              at time and the next load can start cycle later.  */
26223           if (dep_insn_type == TYPE_IMOV
26224               || dep_insn_type == TYPE_FMOV)
26225             cost = 1;
26226           else if (cost > 1)
26227             cost--;
26228         }
26229       break;
26230
26231     case PROCESSOR_K6:
26232      /* The esp dependency is resolved before
26233         the instruction is really finished.  */
26234       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
26235           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
26236         return 1;
26237
26238       /* INT->FP conversion is expensive.  */
26239       if (get_attr_fp_int_src (dep_insn))
26240         cost += 5;
26241
26242       memory = get_attr_memory (insn);
26243
26244       /* Show ability of reorder buffer to hide latency of load by executing
26245          in parallel with previous instruction in case
26246          previous instruction is not needed to compute the address.  */
26247       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26248           && !ix86_agi_dependent (dep_insn, insn))
26249         {
26250           /* Claim moves to take one cycle, as core can issue one load
26251              at time and the next load can start cycle later.  */
26252           if (dep_insn_type == TYPE_IMOV
26253               || dep_insn_type == TYPE_FMOV)
26254             cost = 1;
26255           else if (cost > 2)
26256             cost -= 2;
26257           else
26258             cost = 1;
26259         }
26260       break;
26261
26262     case PROCESSOR_AMDFAM10:
26263     case PROCESSOR_BDVER1:
26264     case PROCESSOR_BDVER2:
26265     case PROCESSOR_BDVER3:
26266     case PROCESSOR_BDVER4:
26267     case PROCESSOR_BTVER1:
26268     case PROCESSOR_BTVER2:
26269     case PROCESSOR_GENERIC:
26270       /* Stack engine allows to execute push&pop instructions in parall.  */
26271       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
26272           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
26273         return 0;
26274       /* FALLTHRU */
26275
26276     case PROCESSOR_ATHLON:
26277     case PROCESSOR_K8:
26278       memory = get_attr_memory (insn);
26279
26280       /* Show ability of reorder buffer to hide latency of load by executing
26281          in parallel with previous instruction in case
26282          previous instruction is not needed to compute the address.  */
26283       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26284           && !ix86_agi_dependent (dep_insn, insn))
26285         {
26286           enum attr_unit unit = get_attr_unit (insn);
26287           int loadcost = 3;
26288
26289           /* Because of the difference between the length of integer and
26290              floating unit pipeline preparation stages, the memory operands
26291              for floating point are cheaper.
26292
26293              ??? For Athlon it the difference is most probably 2.  */
26294           if (unit == UNIT_INTEGER || unit == UNIT_UNKNOWN)
26295             loadcost = 3;
26296           else
26297             loadcost = TARGET_ATHLON ? 2 : 0;
26298
26299           if (cost >= loadcost)
26300             cost -= loadcost;
26301           else
26302             cost = 0;
26303         }
26304       break;
26305
26306     case PROCESSOR_CORE2:
26307     case PROCESSOR_NEHALEM:
26308     case PROCESSOR_SANDYBRIDGE:
26309     case PROCESSOR_HASWELL:
26310       /* Stack engine allows to execute push&pop instructions in parall.  */
26311       if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP)
26312           && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP))
26313         return 0;
26314
26315       memory = get_attr_memory (insn);
26316
26317       /* Show ability of reorder buffer to hide latency of load by executing
26318          in parallel with previous instruction in case
26319          previous instruction is not needed to compute the address.  */
26320       if ((memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26321           && !ix86_agi_dependent (dep_insn, insn))
26322         {
26323           if (cost >= 4)
26324             cost -= 4;
26325           else
26326             cost = 0;
26327         }
26328       break;
26329
26330     case PROCESSOR_SILVERMONT:
26331     case PROCESSOR_KNL:
26332     case PROCESSOR_INTEL:
26333       if (!reload_completed)
26334         return cost;
26335
26336       /* Increase cost of integer loads.  */
26337       memory = get_attr_memory (dep_insn);
26338       if (memory == MEMORY_LOAD || memory == MEMORY_BOTH)
26339         {
26340           enum attr_unit unit = get_attr_unit (dep_insn);
26341           if (unit == UNIT_INTEGER && cost == 1)
26342             {
26343               if (memory == MEMORY_LOAD)
26344                 cost = 3;
26345               else
26346                 {
26347                   /* Increase cost of ld/st for short int types only
26348                      because of store forwarding issue.  */
26349                   rtx set = single_set (dep_insn);
26350                   if (set && (GET_MODE (SET_DEST (set)) == QImode
26351                               || GET_MODE (SET_DEST (set)) == HImode))
26352                     {
26353                       /* Increase cost of store/load insn if exact
26354                          dependence exists and it is load insn.  */
26355                       enum attr_memory insn_memory = get_attr_memory (insn);
26356                       if (insn_memory == MEMORY_LOAD
26357                           && exact_store_load_dependency (dep_insn, insn))
26358                         cost = 3;
26359                     }
26360                 }
26361             }
26362         }
26363
26364     default:
26365       break;
26366     }
26367
26368   return cost;
26369 }
26370
26371 /* How many alternative schedules to try.  This should be as wide as the
26372    scheduling freedom in the DFA, but no wider.  Making this value too
26373    large results extra work for the scheduler.  */
26374
26375 static int
26376 ia32_multipass_dfa_lookahead (void)
26377 {
26378   switch (ix86_tune)
26379     {
26380     case PROCESSOR_PENTIUM:
26381       return 2;
26382
26383     case PROCESSOR_PENTIUMPRO:
26384     case PROCESSOR_K6:
26385       return 1;
26386
26387     case PROCESSOR_BDVER1:
26388     case PROCESSOR_BDVER2:
26389     case PROCESSOR_BDVER3:
26390     case PROCESSOR_BDVER4:
26391       /* We use lookahead value 4 for BD both before and after reload
26392          schedules. Plan is to have value 8 included for O3. */
26393         return 4;
26394
26395     case PROCESSOR_CORE2:
26396     case PROCESSOR_NEHALEM:
26397     case PROCESSOR_SANDYBRIDGE:
26398     case PROCESSOR_HASWELL:
26399     case PROCESSOR_BONNELL:
26400     case PROCESSOR_SILVERMONT:
26401     case PROCESSOR_KNL:
26402     case PROCESSOR_INTEL:
26403       /* Generally, we want haifa-sched:max_issue() to look ahead as far
26404          as many instructions can be executed on a cycle, i.e.,
26405          issue_rate.  I wonder why tuning for many CPUs does not do this.  */
26406       if (reload_completed)
26407         return ix86_issue_rate ();
26408       /* Don't use lookahead for pre-reload schedule to save compile time.  */
26409       return 0;
26410
26411     default:
26412       return 0;
26413     }
26414 }
26415
26416 /* Return true if target platform supports macro-fusion.  */
26417
26418 static bool
26419 ix86_macro_fusion_p ()
26420 {
26421   return TARGET_FUSE_CMP_AND_BRANCH;
26422 }
26423
26424 /* Check whether current microarchitecture support macro fusion
26425    for insn pair "CONDGEN + CONDJMP". Refer to
26426    "Intel Architectures Optimization Reference Manual". */
26427
26428 static bool
26429 ix86_macro_fusion_pair_p (rtx_insn *condgen, rtx_insn *condjmp)
26430 {
26431   rtx src, dest;
26432   enum rtx_code ccode;
26433   rtx compare_set = NULL_RTX, test_if, cond;
26434   rtx alu_set = NULL_RTX, addr = NULL_RTX;
26435
26436   if (!any_condjump_p (condjmp))
26437     return false;
26438
26439   if (get_attr_type (condgen) != TYPE_TEST
26440       && get_attr_type (condgen) != TYPE_ICMP
26441       && get_attr_type (condgen) != TYPE_INCDEC
26442       && get_attr_type (condgen) != TYPE_ALU)
26443     return false;
26444
26445   compare_set = single_set (condgen);
26446   if (compare_set == NULL_RTX
26447       && !TARGET_FUSE_ALU_AND_BRANCH)
26448     return false;
26449
26450   if (compare_set == NULL_RTX)
26451     {
26452       int i;
26453       rtx pat = PATTERN (condgen);
26454       for (i = 0; i < XVECLEN (pat, 0); i++)
26455         if (GET_CODE (XVECEXP (pat, 0, i)) == SET)
26456           {
26457             rtx set_src = SET_SRC (XVECEXP (pat, 0, i));
26458             if (GET_CODE (set_src) == COMPARE)
26459               compare_set = XVECEXP (pat, 0, i);
26460             else
26461               alu_set = XVECEXP (pat, 0, i);
26462           }
26463     }
26464   if (compare_set == NULL_RTX)
26465     return false;
26466   src = SET_SRC (compare_set);
26467   if (GET_CODE (src) != COMPARE)
26468     return false;
26469
26470   /* Macro-fusion for cmp/test MEM-IMM + conditional jmp is not
26471      supported.  */
26472   if ((MEM_P (XEXP (src, 0))
26473        && CONST_INT_P (XEXP (src, 1)))
26474       || (MEM_P (XEXP (src, 1))
26475           && CONST_INT_P (XEXP (src, 0))))
26476     return false;
26477
26478   /* No fusion for RIP-relative address.  */
26479   if (MEM_P (XEXP (src, 0)))
26480     addr = XEXP (XEXP (src, 0), 0);
26481   else if (MEM_P (XEXP (src, 1)))
26482     addr = XEXP (XEXP (src, 1), 0);
26483
26484   if (addr) {
26485     ix86_address parts;
26486     int ok = ix86_decompose_address (addr, &parts);
26487     gcc_assert (ok);
26488
26489     if (rip_relative_addr_p (&parts))
26490       return false;
26491   }
26492
26493   test_if = SET_SRC (pc_set (condjmp));
26494   cond = XEXP (test_if, 0);
26495   ccode = GET_CODE (cond);
26496   /* Check whether conditional jump use Sign or Overflow Flags.  */
26497   if (!TARGET_FUSE_CMP_AND_BRANCH_SOFLAGS
26498       && (ccode == GE
26499           || ccode == GT
26500           || ccode == LE
26501           || ccode == LT))
26502     return false;
26503
26504   /* Return true for TYPE_TEST and TYPE_ICMP.  */
26505   if (get_attr_type (condgen) == TYPE_TEST
26506       || get_attr_type (condgen) == TYPE_ICMP)
26507     return true;
26508
26509   /* The following is the case that macro-fusion for alu + jmp.  */
26510   if (!TARGET_FUSE_ALU_AND_BRANCH || !alu_set)
26511     return false;
26512
26513   /* No fusion for alu op with memory destination operand.  */
26514   dest = SET_DEST (alu_set);
26515   if (MEM_P (dest))
26516     return false;
26517
26518   /* Macro-fusion for inc/dec + unsigned conditional jump is not
26519      supported.  */
26520   if (get_attr_type (condgen) == TYPE_INCDEC
26521       && (ccode == GEU
26522           || ccode == GTU
26523           || ccode == LEU
26524           || ccode == LTU))
26525     return false;
26526
26527   return true;
26528 }
26529
26530 /* Try to reorder ready list to take advantage of Atom pipelined IMUL
26531    execution. It is applied if
26532    (1) IMUL instruction is on the top of list;
26533    (2) There exists the only producer of independent IMUL instruction in
26534        ready list.
26535    Return index of IMUL producer if it was found and -1 otherwise.  */
26536 static int
26537 do_reorder_for_imul (rtx_insn **ready, int n_ready)
26538 {
26539   rtx_insn *insn;
26540   rtx set, insn1, insn2;
26541   sd_iterator_def sd_it;
26542   dep_t dep;
26543   int index = -1;
26544   int i;
26545
26546   if (!TARGET_BONNELL)
26547     return index;
26548
26549   /* Check that IMUL instruction is on the top of ready list.  */
26550   insn = ready[n_ready - 1];
26551   set = single_set (insn);
26552   if (!set)
26553     return index;
26554   if (!(GET_CODE (SET_SRC (set)) == MULT
26555       && GET_MODE (SET_SRC (set)) == SImode))
26556     return index;
26557
26558   /* Search for producer of independent IMUL instruction.  */
26559   for (i = n_ready - 2; i >= 0; i--)
26560     {
26561       insn = ready[i];
26562       if (!NONDEBUG_INSN_P (insn))
26563         continue;
26564       /* Skip IMUL instruction.  */
26565       insn2 = PATTERN (insn);
26566       if (GET_CODE (insn2) == PARALLEL)
26567         insn2 = XVECEXP (insn2, 0, 0);
26568       if (GET_CODE (insn2) == SET
26569           && GET_CODE (SET_SRC (insn2)) == MULT
26570           && GET_MODE (SET_SRC (insn2)) == SImode)
26571         continue;
26572
26573       FOR_EACH_DEP (insn, SD_LIST_FORW, sd_it, dep)
26574         {
26575           rtx con;
26576           con = DEP_CON (dep);
26577           if (!NONDEBUG_INSN_P (con))
26578             continue;
26579           insn1 = PATTERN (con);
26580           if (GET_CODE (insn1) == PARALLEL)
26581             insn1 = XVECEXP (insn1, 0, 0);
26582
26583           if (GET_CODE (insn1) == SET
26584               && GET_CODE (SET_SRC (insn1)) == MULT
26585               && GET_MODE (SET_SRC (insn1)) == SImode)
26586             {
26587               sd_iterator_def sd_it1;
26588               dep_t dep1;
26589               /* Check if there is no other dependee for IMUL.  */
26590               index = i;
26591               FOR_EACH_DEP (con, SD_LIST_BACK, sd_it1, dep1)
26592                 {
26593                   rtx pro;
26594                   pro = DEP_PRO (dep1);
26595                   if (!NONDEBUG_INSN_P (pro))
26596                     continue;
26597                   if (pro != insn)
26598                     index = -1;
26599                 }
26600               if (index >= 0)
26601                 break;
26602             }
26603         }
26604       if (index >= 0)
26605         break;
26606     }
26607   return index;
26608 }
26609
26610 /* Try to find the best candidate on the top of ready list if two insns
26611    have the same priority - candidate is best if its dependees were
26612    scheduled earlier. Applied for Silvermont only.
26613    Return true if top 2 insns must be interchanged.  */
26614 static bool
26615 swap_top_of_ready_list (rtx_insn **ready, int n_ready)
26616 {
26617   rtx_insn *top = ready[n_ready - 1];
26618   rtx_insn *next = ready[n_ready - 2];
26619   rtx set;
26620   sd_iterator_def sd_it;
26621   dep_t dep;
26622   int clock1 = -1;
26623   int clock2 = -1;
26624   #define INSN_TICK(INSN) (HID (INSN)->tick)
26625
26626   if (!TARGET_SILVERMONT && !TARGET_INTEL)
26627     return false;
26628
26629   if (!NONDEBUG_INSN_P (top))
26630     return false;
26631   if (!NONJUMP_INSN_P (top))
26632     return false;
26633   if (!NONDEBUG_INSN_P (next))
26634     return false;
26635   if (!NONJUMP_INSN_P (next))
26636     return false;
26637   set = single_set (top);
26638   if (!set)
26639     return false;
26640   set = single_set (next);
26641   if (!set)
26642     return false;
26643
26644   if (INSN_PRIORITY_KNOWN (top) && INSN_PRIORITY_KNOWN (next))
26645     {
26646       if (INSN_PRIORITY (top) != INSN_PRIORITY (next))
26647         return false;
26648       /* Determine winner more precise.  */
26649       FOR_EACH_DEP (top, SD_LIST_RES_BACK, sd_it, dep)
26650         {
26651           rtx pro;
26652           pro = DEP_PRO (dep);
26653           if (!NONDEBUG_INSN_P (pro))
26654             continue;
26655           if (INSN_TICK (pro) > clock1)
26656             clock1 = INSN_TICK (pro);
26657         }
26658       FOR_EACH_DEP (next, SD_LIST_RES_BACK, sd_it, dep)
26659         {
26660           rtx pro;
26661           pro = DEP_PRO (dep);
26662           if (!NONDEBUG_INSN_P (pro))
26663             continue;
26664           if (INSN_TICK (pro) > clock2)
26665             clock2 = INSN_TICK (pro);
26666         }
26667
26668       if (clock1 == clock2)
26669         {
26670           /* Determine winner - load must win. */
26671           enum attr_memory memory1, memory2;
26672           memory1 = get_attr_memory (top);
26673           memory2 = get_attr_memory (next);
26674           if (memory2 == MEMORY_LOAD && memory1 != MEMORY_LOAD)
26675             return true;
26676         }
26677         return (bool) (clock2 < clock1);
26678     }
26679   return false;
26680   #undef INSN_TICK
26681 }
26682
26683 /* Perform possible reodering of ready list for Atom/Silvermont only.
26684    Return issue rate.  */
26685 static int
26686 ix86_sched_reorder (FILE *dump, int sched_verbose, rtx_insn **ready,
26687                     int *pn_ready, int clock_var)
26688 {
26689   int issue_rate = -1;
26690   int n_ready = *pn_ready;
26691   int i;
26692   rtx_insn *insn;
26693   int index = -1;
26694
26695   /* Set up issue rate.  */
26696   issue_rate = ix86_issue_rate ();
26697
26698   /* Do reodering for BONNELL/SILVERMONT only.  */
26699   if (!TARGET_BONNELL && !TARGET_SILVERMONT && !TARGET_INTEL)
26700     return issue_rate;
26701
26702   /* Nothing to do if ready list contains only 1 instruction.  */
26703   if (n_ready <= 1)
26704     return issue_rate;
26705
26706   /* Do reodering for post-reload scheduler only.  */
26707   if (!reload_completed)
26708     return issue_rate;
26709
26710   if ((index = do_reorder_for_imul (ready, n_ready)) >= 0)
26711     {
26712       if (sched_verbose > 1)
26713         fprintf (dump, ";;\tatom sched_reorder: put %d insn on top\n",
26714                  INSN_UID (ready[index]));
26715
26716       /* Put IMUL producer (ready[index]) at the top of ready list.  */
26717       insn = ready[index];
26718       for (i = index; i < n_ready - 1; i++)
26719         ready[i] = ready[i + 1];
26720       ready[n_ready - 1] = insn;
26721       return issue_rate;
26722     }
26723   if (clock_var != 0 && swap_top_of_ready_list (ready, n_ready))
26724     {
26725       if (sched_verbose > 1)
26726         fprintf (dump, ";;\tslm sched_reorder: swap %d and %d insns\n",
26727                  INSN_UID (ready[n_ready - 1]), INSN_UID (ready[n_ready - 2]));
26728       /* Swap 2 top elements of ready list.  */
26729       insn = ready[n_ready - 1];
26730       ready[n_ready - 1] = ready[n_ready - 2];
26731       ready[n_ready - 2] = insn;
26732     }
26733   return issue_rate;
26734 }
26735
26736 static bool
26737 ix86_class_likely_spilled_p (reg_class_t);
26738
26739 /* Returns true if lhs of insn is HW function argument register and set up
26740    is_spilled to true if it is likely spilled HW register.  */
26741 static bool
26742 insn_is_function_arg (rtx insn, bool* is_spilled)
26743 {
26744   rtx dst;
26745
26746   if (!NONDEBUG_INSN_P (insn))
26747     return false;
26748   /* Call instructions are not movable, ignore it.  */
26749   if (CALL_P (insn))
26750     return false;
26751   insn = PATTERN (insn);
26752   if (GET_CODE (insn) == PARALLEL)
26753     insn = XVECEXP (insn, 0, 0);
26754   if (GET_CODE (insn) != SET)
26755     return false;
26756   dst = SET_DEST (insn);
26757   if (REG_P (dst) && HARD_REGISTER_P (dst)
26758       && ix86_function_arg_regno_p (REGNO (dst)))
26759     {
26760       /* Is it likely spilled HW register?  */
26761       if (!TEST_HARD_REG_BIT (fixed_reg_set, REGNO (dst))
26762           && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (dst))))
26763         *is_spilled = true;
26764       return true;
26765     }
26766   return false;
26767 }
26768
26769 /* Add output dependencies for chain of function adjacent arguments if only
26770    there is a move to likely spilled HW register.  Return first argument
26771    if at least one dependence was added or NULL otherwise.  */
26772 static rtx_insn *
26773 add_parameter_dependencies (rtx_insn *call, rtx_insn *head)
26774 {
26775   rtx_insn *insn;
26776   rtx_insn *last = call;
26777   rtx_insn *first_arg = NULL;
26778   bool is_spilled = false;
26779
26780   head = PREV_INSN (head);
26781
26782   /* Find nearest to call argument passing instruction.  */
26783   while (true)
26784     {
26785       last = PREV_INSN (last);
26786       if (last == head)
26787         return NULL;
26788       if (!NONDEBUG_INSN_P (last))
26789         continue;
26790       if (insn_is_function_arg (last, &is_spilled))
26791         break;
26792       return NULL;
26793     }
26794
26795   first_arg = last;
26796   while (true)
26797     {
26798       insn = PREV_INSN (last);
26799       if (!INSN_P (insn))
26800         break;
26801       if (insn == head)
26802         break;
26803       if (!NONDEBUG_INSN_P (insn))
26804         {
26805           last = insn;
26806           continue;
26807         }
26808       if (insn_is_function_arg (insn, &is_spilled))
26809         {
26810           /* Add output depdendence between two function arguments if chain
26811              of output arguments contains likely spilled HW registers.  */
26812           if (is_spilled)
26813             add_dependence (first_arg, insn, REG_DEP_OUTPUT);
26814           first_arg = last = insn;
26815         }
26816       else
26817         break;
26818     }
26819   if (!is_spilled)
26820     return NULL;
26821   return first_arg;
26822 }
26823
26824 /* Add output or anti dependency from insn to first_arg to restrict its code
26825    motion.  */
26826 static void
26827 avoid_func_arg_motion (rtx_insn *first_arg, rtx_insn *insn)
26828 {
26829   rtx set;
26830   rtx tmp;
26831
26832   set = single_set (insn);
26833   if (!set)
26834     return;
26835   tmp = SET_DEST (set);
26836   if (REG_P (tmp))
26837     {
26838       /* Add output dependency to the first function argument.  */
26839       add_dependence (first_arg, insn, REG_DEP_OUTPUT);
26840       return;
26841     }
26842   /* Add anti dependency.  */
26843   add_dependence (first_arg, insn, REG_DEP_ANTI);
26844 }
26845
26846 /* Avoid cross block motion of function argument through adding dependency
26847    from the first non-jump instruction in bb.  */
26848 static void
26849 add_dependee_for_func_arg (rtx_insn *arg, basic_block bb)
26850 {
26851   rtx_insn *insn = BB_END (bb);
26852
26853   while (insn)
26854     {
26855       if (NONDEBUG_INSN_P (insn) && NONJUMP_INSN_P (insn))
26856         {
26857           rtx set = single_set (insn);
26858           if (set)
26859             {
26860               avoid_func_arg_motion (arg, insn);
26861               return;
26862             }
26863         }
26864       if (insn == BB_HEAD (bb))
26865         return;
26866       insn = PREV_INSN (insn);
26867     }
26868 }
26869
26870 /* Hook for pre-reload schedule - avoid motion of function arguments
26871    passed in likely spilled HW registers.  */
26872 static void
26873 ix86_dependencies_evaluation_hook (rtx_insn *head, rtx_insn *tail)
26874 {
26875   rtx_insn *insn;
26876   rtx_insn *first_arg = NULL;
26877   if (reload_completed)
26878     return;
26879   while (head != tail && DEBUG_INSN_P (head))
26880     head = NEXT_INSN (head);
26881   for (insn = tail; insn != head; insn = PREV_INSN (insn))
26882     if (INSN_P (insn) && CALL_P (insn))
26883       {
26884         first_arg = add_parameter_dependencies (insn, head);
26885         if (first_arg)
26886           {
26887             /* Add dependee for first argument to predecessors if only
26888                region contains more than one block.  */
26889             basic_block bb =  BLOCK_FOR_INSN (insn);
26890             int rgn = CONTAINING_RGN (bb->index);
26891             int nr_blks = RGN_NR_BLOCKS (rgn);
26892             /* Skip trivial regions and region head blocks that can have
26893                predecessors outside of region.  */
26894             if (nr_blks > 1 && BLOCK_TO_BB (bb->index) != 0)
26895               {
26896                 edge e;
26897                 edge_iterator ei;
26898
26899                 /* Regions are SCCs with the exception of selective
26900                    scheduling with pipelining of outer blocks enabled.
26901                    So also check that immediate predecessors of a non-head
26902                    block are in the same region.  */
26903                 FOR_EACH_EDGE (e, ei, bb->preds)
26904                   {
26905                     /* Avoid creating of loop-carried dependencies through
26906                        using topological ordering in the region.  */
26907                     if (rgn == CONTAINING_RGN (e->src->index)
26908                         && BLOCK_TO_BB (bb->index) > BLOCK_TO_BB (e->src->index))
26909                       add_dependee_for_func_arg (first_arg, e->src); 
26910                   }
26911               }
26912             insn = first_arg;
26913             if (insn == head)
26914               break;
26915           }
26916       }
26917     else if (first_arg)
26918       avoid_func_arg_motion (first_arg, insn);
26919 }
26920
26921 /* Hook for pre-reload schedule - set priority of moves from likely spilled
26922    HW registers to maximum, to schedule them at soon as possible. These are
26923    moves from function argument registers at the top of the function entry
26924    and moves from function return value registers after call.  */
26925 static int
26926 ix86_adjust_priority (rtx_insn *insn, int priority)
26927 {
26928   rtx set;
26929
26930   if (reload_completed)
26931     return priority;
26932
26933   if (!NONDEBUG_INSN_P (insn))
26934     return priority;
26935
26936   set = single_set (insn);
26937   if (set)
26938     {
26939       rtx tmp = SET_SRC (set);
26940       if (REG_P (tmp)
26941           && HARD_REGISTER_P (tmp)
26942           && !TEST_HARD_REG_BIT (fixed_reg_set, REGNO (tmp))
26943           && ix86_class_likely_spilled_p (REGNO_REG_CLASS (REGNO (tmp))))
26944         return current_sched_info->sched_max_insns_priority;
26945     }
26946
26947   return priority;
26948 }
26949
26950 /* Model decoder of Core 2/i7.
26951    Below hooks for multipass scheduling (see haifa-sched.c:max_issue)
26952    track the instruction fetch block boundaries and make sure that long
26953    (9+ bytes) instructions are assigned to D0.  */
26954
26955 /* Maximum length of an insn that can be handled by
26956    a secondary decoder unit.  '8' for Core 2/i7.  */
26957 static int core2i7_secondary_decoder_max_insn_size;
26958
26959 /* Ifetch block size, i.e., number of bytes decoder reads per cycle.
26960    '16' for Core 2/i7.  */
26961 static int core2i7_ifetch_block_size;
26962
26963 /* Maximum number of instructions decoder can handle per cycle.
26964    '6' for Core 2/i7.  */
26965 static int core2i7_ifetch_block_max_insns;
26966
26967 typedef struct ix86_first_cycle_multipass_data_ *
26968   ix86_first_cycle_multipass_data_t;
26969 typedef const struct ix86_first_cycle_multipass_data_ *
26970   const_ix86_first_cycle_multipass_data_t;
26971
26972 /* A variable to store target state across calls to max_issue within
26973    one cycle.  */
26974 static struct ix86_first_cycle_multipass_data_ _ix86_first_cycle_multipass_data,
26975   *ix86_first_cycle_multipass_data = &_ix86_first_cycle_multipass_data;
26976
26977 /* Initialize DATA.  */
26978 static void
26979 core2i7_first_cycle_multipass_init (void *_data)
26980 {
26981   ix86_first_cycle_multipass_data_t data
26982     = (ix86_first_cycle_multipass_data_t) _data;
26983
26984   data->ifetch_block_len = 0;
26985   data->ifetch_block_n_insns = 0;
26986   data->ready_try_change = NULL;
26987   data->ready_try_change_size = 0;
26988 }
26989
26990 /* Advancing the cycle; reset ifetch block counts.  */
26991 static void
26992 core2i7_dfa_post_advance_cycle (void)
26993 {
26994   ix86_first_cycle_multipass_data_t data = ix86_first_cycle_multipass_data;
26995
26996   gcc_assert (data->ifetch_block_n_insns <= core2i7_ifetch_block_max_insns);
26997
26998   data->ifetch_block_len = 0;
26999   data->ifetch_block_n_insns = 0;
27000 }
27001
27002 static int min_insn_size (rtx_insn *);
27003
27004 /* Filter out insns from ready_try that the core will not be able to issue
27005    on current cycle due to decoder.  */
27006 static void
27007 core2i7_first_cycle_multipass_filter_ready_try
27008 (const_ix86_first_cycle_multipass_data_t data,
27009  signed char *ready_try, int n_ready, bool first_cycle_insn_p)
27010 {
27011   while (n_ready--)
27012     {
27013       rtx_insn *insn;
27014       int insn_size;
27015
27016       if (ready_try[n_ready])
27017         continue;
27018
27019       insn = get_ready_element (n_ready);
27020       insn_size = min_insn_size (insn);
27021
27022       if (/* If this is a too long an insn for a secondary decoder ...  */
27023           (!first_cycle_insn_p
27024            && insn_size > core2i7_secondary_decoder_max_insn_size)
27025           /* ... or it would not fit into the ifetch block ...  */
27026           || data->ifetch_block_len + insn_size > core2i7_ifetch_block_size
27027           /* ... or the decoder is full already ...  */
27028           || data->ifetch_block_n_insns + 1 > core2i7_ifetch_block_max_insns)
27029         /* ... mask the insn out.  */
27030         {
27031           ready_try[n_ready] = 1;
27032
27033           if (data->ready_try_change)
27034             bitmap_set_bit (data->ready_try_change, n_ready);
27035         }
27036     }
27037 }
27038
27039 /* Prepare for a new round of multipass lookahead scheduling.  */
27040 static void
27041 core2i7_first_cycle_multipass_begin (void *_data,
27042                                      signed char *ready_try, int n_ready,
27043                                      bool first_cycle_insn_p)
27044 {
27045   ix86_first_cycle_multipass_data_t data
27046     = (ix86_first_cycle_multipass_data_t) _data;
27047   const_ix86_first_cycle_multipass_data_t prev_data
27048     = ix86_first_cycle_multipass_data;
27049
27050   /* Restore the state from the end of the previous round.  */
27051   data->ifetch_block_len = prev_data->ifetch_block_len;
27052   data->ifetch_block_n_insns = prev_data->ifetch_block_n_insns;
27053
27054   /* Filter instructions that cannot be issued on current cycle due to
27055      decoder restrictions.  */
27056   core2i7_first_cycle_multipass_filter_ready_try (data, ready_try, n_ready,
27057                                                   first_cycle_insn_p);
27058 }
27059
27060 /* INSN is being issued in current solution.  Account for its impact on
27061    the decoder model.  */
27062 static void
27063 core2i7_first_cycle_multipass_issue (void *_data,
27064                                      signed char *ready_try, int n_ready,
27065                                      rtx_insn *insn, const void *_prev_data)
27066 {
27067   ix86_first_cycle_multipass_data_t data
27068     = (ix86_first_cycle_multipass_data_t) _data;
27069   const_ix86_first_cycle_multipass_data_t prev_data
27070     = (const_ix86_first_cycle_multipass_data_t) _prev_data;
27071
27072   int insn_size = min_insn_size (insn);
27073
27074   data->ifetch_block_len = prev_data->ifetch_block_len + insn_size;
27075   data->ifetch_block_n_insns = prev_data->ifetch_block_n_insns + 1;
27076   gcc_assert (data->ifetch_block_len <= core2i7_ifetch_block_size
27077               && data->ifetch_block_n_insns <= core2i7_ifetch_block_max_insns);
27078
27079   /* Allocate or resize the bitmap for storing INSN's effect on ready_try.  */
27080   if (!data->ready_try_change)
27081     {
27082       data->ready_try_change = sbitmap_alloc (n_ready);
27083       data->ready_try_change_size = n_ready;
27084     }
27085   else if (data->ready_try_change_size < n_ready)
27086     {
27087       data->ready_try_change = sbitmap_resize (data->ready_try_change,
27088                                                n_ready, 0);
27089       data->ready_try_change_size = n_ready;
27090     }
27091   bitmap_clear (data->ready_try_change);
27092
27093   /* Filter out insns from ready_try that the core will not be able to issue
27094      on current cycle due to decoder.  */
27095   core2i7_first_cycle_multipass_filter_ready_try (data, ready_try, n_ready,
27096                                                   false);
27097 }
27098
27099 /* Revert the effect on ready_try.  */
27100 static void
27101 core2i7_first_cycle_multipass_backtrack (const void *_data,
27102                                          signed char *ready_try,
27103                                          int n_ready ATTRIBUTE_UNUSED)
27104 {
27105   const_ix86_first_cycle_multipass_data_t data
27106     = (const_ix86_first_cycle_multipass_data_t) _data;
27107   unsigned int i = 0;
27108   sbitmap_iterator sbi;
27109
27110   gcc_assert (bitmap_last_set_bit (data->ready_try_change) < n_ready);
27111   EXECUTE_IF_SET_IN_BITMAP (data->ready_try_change, 0, i, sbi)
27112     {
27113       ready_try[i] = 0;
27114     }
27115 }
27116
27117 /* Save the result of multipass lookahead scheduling for the next round.  */
27118 static void
27119 core2i7_first_cycle_multipass_end (const void *_data)
27120 {
27121   const_ix86_first_cycle_multipass_data_t data
27122     = (const_ix86_first_cycle_multipass_data_t) _data;
27123   ix86_first_cycle_multipass_data_t next_data
27124     = ix86_first_cycle_multipass_data;
27125
27126   if (data != NULL)
27127     {
27128       next_data->ifetch_block_len = data->ifetch_block_len;
27129       next_data->ifetch_block_n_insns = data->ifetch_block_n_insns;
27130     }
27131 }
27132
27133 /* Deallocate target data.  */
27134 static void
27135 core2i7_first_cycle_multipass_fini (void *_data)
27136 {
27137   ix86_first_cycle_multipass_data_t data
27138     = (ix86_first_cycle_multipass_data_t) _data;
27139
27140   if (data->ready_try_change)
27141     {
27142       sbitmap_free (data->ready_try_change);
27143       data->ready_try_change = NULL;
27144       data->ready_try_change_size = 0;
27145     }
27146 }
27147
27148 /* Prepare for scheduling pass.  */
27149 static void
27150 ix86_sched_init_global (FILE *, int, int)
27151 {
27152   /* Install scheduling hooks for current CPU.  Some of these hooks are used
27153      in time-critical parts of the scheduler, so we only set them up when
27154      they are actually used.  */
27155   switch (ix86_tune)
27156     {
27157     case PROCESSOR_CORE2:
27158     case PROCESSOR_NEHALEM:
27159     case PROCESSOR_SANDYBRIDGE:
27160     case PROCESSOR_HASWELL:
27161       /* Do not perform multipass scheduling for pre-reload schedule
27162          to save compile time.  */
27163       if (reload_completed)
27164         {
27165           targetm.sched.dfa_post_advance_cycle
27166             = core2i7_dfa_post_advance_cycle;
27167           targetm.sched.first_cycle_multipass_init
27168             = core2i7_first_cycle_multipass_init;
27169           targetm.sched.first_cycle_multipass_begin
27170             = core2i7_first_cycle_multipass_begin;
27171           targetm.sched.first_cycle_multipass_issue
27172             = core2i7_first_cycle_multipass_issue;
27173           targetm.sched.first_cycle_multipass_backtrack
27174             = core2i7_first_cycle_multipass_backtrack;
27175           targetm.sched.first_cycle_multipass_end
27176             = core2i7_first_cycle_multipass_end;
27177           targetm.sched.first_cycle_multipass_fini
27178             = core2i7_first_cycle_multipass_fini;
27179
27180           /* Set decoder parameters.  */
27181           core2i7_secondary_decoder_max_insn_size = 8;
27182           core2i7_ifetch_block_size = 16;
27183           core2i7_ifetch_block_max_insns = 6;
27184           break;
27185         }
27186       /* ... Fall through ...  */
27187     default:
27188       targetm.sched.dfa_post_advance_cycle = NULL;
27189       targetm.sched.first_cycle_multipass_init = NULL;
27190       targetm.sched.first_cycle_multipass_begin = NULL;
27191       targetm.sched.first_cycle_multipass_issue = NULL;
27192       targetm.sched.first_cycle_multipass_backtrack = NULL;
27193       targetm.sched.first_cycle_multipass_end = NULL;
27194       targetm.sched.first_cycle_multipass_fini = NULL;
27195       break;
27196     }
27197 }
27198
27199 \f
27200 /* Compute the alignment given to a constant that is being placed in memory.
27201    EXP is the constant and ALIGN is the alignment that the object would
27202    ordinarily have.
27203    The value of this function is used instead of that alignment to align
27204    the object.  */
27205
27206 int
27207 ix86_constant_alignment (tree exp, int align)
27208 {
27209   if (TREE_CODE (exp) == REAL_CST || TREE_CODE (exp) == VECTOR_CST
27210       || TREE_CODE (exp) == INTEGER_CST)
27211     {
27212       if (TYPE_MODE (TREE_TYPE (exp)) == DFmode && align < 64)
27213         return 64;
27214       else if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (exp))) && align < 128)
27215         return 128;
27216     }
27217   else if (!optimize_size && TREE_CODE (exp) == STRING_CST
27218            && TREE_STRING_LENGTH (exp) >= 31 && align < BITS_PER_WORD)
27219     return BITS_PER_WORD;
27220
27221   return align;
27222 }
27223
27224 /* Compute the alignment for a static variable.
27225    TYPE is the data type, and ALIGN is the alignment that
27226    the object would ordinarily have.  The value of this function is used
27227    instead of that alignment to align the object.  */
27228
27229 int
27230 ix86_data_alignment (tree type, int align, bool opt)
27231 {
27232   /* GCC 4.8 and earlier used to incorrectly assume this alignment even
27233      for symbols from other compilation units or symbols that don't need
27234      to bind locally.  In order to preserve some ABI compatibility with
27235      those compilers, ensure we don't decrease alignment from what we
27236      used to assume.  */
27237
27238   int max_align_compat = MIN (256, MAX_OFILE_ALIGNMENT);
27239
27240   /* A data structure, equal or greater than the size of a cache line
27241      (64 bytes in the Pentium 4 and other recent Intel processors, including
27242      processors based on Intel Core microarchitecture) should be aligned
27243      so that its base address is a multiple of a cache line size.  */
27244
27245   int max_align
27246     = MIN ((unsigned) ix86_tune_cost->prefetch_block * 8, MAX_OFILE_ALIGNMENT);
27247
27248   if (max_align < BITS_PER_WORD)
27249     max_align = BITS_PER_WORD;
27250
27251   switch (ix86_align_data_type)
27252     {
27253     case ix86_align_data_type_abi: opt = false; break;
27254     case ix86_align_data_type_compat: max_align = BITS_PER_WORD; break;
27255     case ix86_align_data_type_cacheline: break;
27256     }
27257
27258   if (opt
27259       && AGGREGATE_TYPE_P (type)
27260       && TYPE_SIZE (type)
27261       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
27262     {
27263       if (wi::geu_p (TYPE_SIZE (type), max_align_compat)
27264           && align < max_align_compat)
27265         align = max_align_compat;
27266        if (wi::geu_p (TYPE_SIZE (type), max_align)
27267            && align < max_align)
27268          align = max_align;
27269     }
27270
27271   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
27272      to 16byte boundary.  */
27273   if (TARGET_64BIT)
27274     {
27275       if ((opt ? AGGREGATE_TYPE_P (type) : TREE_CODE (type) == ARRAY_TYPE)
27276           && TYPE_SIZE (type)
27277           && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
27278           && wi::geu_p (TYPE_SIZE (type), 128)
27279           && align < 128)
27280         return 128;
27281     }
27282
27283   if (!opt)
27284     return align;
27285
27286   if (TREE_CODE (type) == ARRAY_TYPE)
27287     {
27288       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
27289         return 64;
27290       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
27291         return 128;
27292     }
27293   else if (TREE_CODE (type) == COMPLEX_TYPE)
27294     {
27295
27296       if (TYPE_MODE (type) == DCmode && align < 64)
27297         return 64;
27298       if ((TYPE_MODE (type) == XCmode
27299            || TYPE_MODE (type) == TCmode) && align < 128)
27300         return 128;
27301     }
27302   else if ((TREE_CODE (type) == RECORD_TYPE
27303             || TREE_CODE (type) == UNION_TYPE
27304             || TREE_CODE (type) == QUAL_UNION_TYPE)
27305            && TYPE_FIELDS (type))
27306     {
27307       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
27308         return 64;
27309       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
27310         return 128;
27311     }
27312   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
27313            || TREE_CODE (type) == INTEGER_TYPE)
27314     {
27315       if (TYPE_MODE (type) == DFmode && align < 64)
27316         return 64;
27317       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
27318         return 128;
27319     }
27320
27321   return align;
27322 }
27323
27324 /* Compute the alignment for a local variable or a stack slot.  EXP is
27325    the data type or decl itself, MODE is the widest mode available and
27326    ALIGN is the alignment that the object would ordinarily have.  The
27327    value of this macro is used instead of that alignment to align the
27328    object.  */
27329
27330 unsigned int
27331 ix86_local_alignment (tree exp, machine_mode mode,
27332                       unsigned int align)
27333 {
27334   tree type, decl;
27335
27336   if (exp && DECL_P (exp))
27337     {
27338       type = TREE_TYPE (exp);
27339       decl = exp;
27340     }
27341   else
27342     {
27343       type = exp;
27344       decl = NULL;
27345     }
27346
27347   /* Don't do dynamic stack realignment for long long objects with
27348      -mpreferred-stack-boundary=2.  */
27349   if (!TARGET_64BIT
27350       && align == 64
27351       && ix86_preferred_stack_boundary < 64
27352       && (mode == DImode || (type && TYPE_MODE (type) == DImode))
27353       && (!type || !TYPE_USER_ALIGN (type))
27354       && (!decl || !DECL_USER_ALIGN (decl)))
27355     align = 32;
27356
27357   /* If TYPE is NULL, we are allocating a stack slot for caller-save
27358      register in MODE.  We will return the largest alignment of XF
27359      and DF.  */
27360   if (!type)
27361     {
27362       if (mode == XFmode && align < GET_MODE_ALIGNMENT (DFmode))
27363         align = GET_MODE_ALIGNMENT (DFmode);
27364       return align;
27365     }
27366
27367   /* x86-64 ABI requires arrays greater than 16 bytes to be aligned
27368      to 16byte boundary.  Exact wording is:
27369
27370      An array uses the same alignment as its elements, except that a local or
27371      global array variable of length at least 16 bytes or
27372      a C99 variable-length array variable always has alignment of at least 16 bytes.
27373
27374      This was added to allow use of aligned SSE instructions at arrays.  This
27375      rule is meant for static storage (where compiler can not do the analysis
27376      by itself).  We follow it for automatic variables only when convenient.
27377      We fully control everything in the function compiled and functions from
27378      other unit can not rely on the alignment.
27379
27380      Exclude va_list type.  It is the common case of local array where
27381      we can not benefit from the alignment.  
27382
27383      TODO: Probably one should optimize for size only when var is not escaping.  */
27384   if (TARGET_64BIT && optimize_function_for_speed_p (cfun)
27385       && TARGET_SSE)
27386     {
27387       if (AGGREGATE_TYPE_P (type)
27388           && (va_list_type_node == NULL_TREE
27389               || (TYPE_MAIN_VARIANT (type)
27390                   != TYPE_MAIN_VARIANT (va_list_type_node)))
27391           && TYPE_SIZE (type)
27392           && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
27393           && wi::geu_p (TYPE_SIZE (type), 16)
27394           && align < 128)
27395         return 128;
27396     }
27397   if (TREE_CODE (type) == ARRAY_TYPE)
27398     {
27399       if (TYPE_MODE (TREE_TYPE (type)) == DFmode && align < 64)
27400         return 64;
27401       if (ALIGN_MODE_128 (TYPE_MODE (TREE_TYPE (type))) && align < 128)
27402         return 128;
27403     }
27404   else if (TREE_CODE (type) == COMPLEX_TYPE)
27405     {
27406       if (TYPE_MODE (type) == DCmode && align < 64)
27407         return 64;
27408       if ((TYPE_MODE (type) == XCmode
27409            || TYPE_MODE (type) == TCmode) && align < 128)
27410         return 128;
27411     }
27412   else if ((TREE_CODE (type) == RECORD_TYPE
27413             || TREE_CODE (type) == UNION_TYPE
27414             || TREE_CODE (type) == QUAL_UNION_TYPE)
27415            && TYPE_FIELDS (type))
27416     {
27417       if (DECL_MODE (TYPE_FIELDS (type)) == DFmode && align < 64)
27418         return 64;
27419       if (ALIGN_MODE_128 (DECL_MODE (TYPE_FIELDS (type))) && align < 128)
27420         return 128;
27421     }
27422   else if (TREE_CODE (type) == REAL_TYPE || TREE_CODE (type) == VECTOR_TYPE
27423            || TREE_CODE (type) == INTEGER_TYPE)
27424     {
27425
27426       if (TYPE_MODE (type) == DFmode && align < 64)
27427         return 64;
27428       if (ALIGN_MODE_128 (TYPE_MODE (type)) && align < 128)
27429         return 128;
27430     }
27431   return align;
27432 }
27433
27434 /* Compute the minimum required alignment for dynamic stack realignment
27435    purposes for a local variable, parameter or a stack slot.  EXP is
27436    the data type or decl itself, MODE is its mode and ALIGN is the
27437    alignment that the object would ordinarily have.  */
27438
27439 unsigned int
27440 ix86_minimum_alignment (tree exp, machine_mode mode,
27441                         unsigned int align)
27442 {
27443   tree type, decl;
27444
27445   if (exp && DECL_P (exp))
27446     {
27447       type = TREE_TYPE (exp);
27448       decl = exp;
27449     }
27450   else
27451     {
27452       type = exp;
27453       decl = NULL;
27454     }
27455
27456   if (TARGET_64BIT || align != 64 || ix86_preferred_stack_boundary >= 64)
27457     return align;
27458
27459   /* Don't do dynamic stack realignment for long long objects with
27460      -mpreferred-stack-boundary=2.  */
27461   if ((mode == DImode || (type && TYPE_MODE (type) == DImode))
27462       && (!type || !TYPE_USER_ALIGN (type))
27463       && (!decl || !DECL_USER_ALIGN (decl)))
27464     return 32;
27465
27466   return align;
27467 }
27468 \f
27469 /* Find a location for the static chain incoming to a nested function.
27470    This is a register, unless all free registers are used by arguments.  */
27471
27472 static rtx
27473 ix86_static_chain (const_tree fndecl_or_type, bool incoming_p)
27474 {
27475   unsigned regno;
27476
27477   /* While this function won't be called by the middle-end when a static
27478      chain isn't needed, it's also used throughout the backend so it's
27479      easiest to keep this check centralized.  */
27480   if (DECL_P (fndecl_or_type) && !DECL_STATIC_CHAIN (fndecl_or_type))
27481     return NULL;
27482
27483   if (TARGET_64BIT)
27484     {
27485       /* We always use R10 in 64-bit mode.  */
27486       regno = R10_REG;
27487     }
27488   else
27489     {
27490       const_tree fntype, fndecl;
27491       unsigned int ccvt;
27492
27493       /* By default in 32-bit mode we use ECX to pass the static chain.  */
27494       regno = CX_REG;
27495
27496       if (TREE_CODE (fndecl_or_type) == FUNCTION_DECL)
27497         {
27498           fntype = TREE_TYPE (fndecl_or_type);
27499           fndecl = fndecl_or_type;
27500         }
27501       else
27502         {
27503           fntype = fndecl_or_type;
27504           fndecl = NULL;
27505         }
27506
27507       ccvt = ix86_get_callcvt (fntype);
27508       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
27509         {
27510           /* Fastcall functions use ecx/edx for arguments, which leaves
27511              us with EAX for the static chain.
27512              Thiscall functions use ecx for arguments, which also
27513              leaves us with EAX for the static chain.  */
27514           regno = AX_REG;
27515         }
27516       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
27517         {
27518           /* Thiscall functions use ecx for arguments, which leaves
27519              us with EAX and EDX for the static chain.
27520              We are using for abi-compatibility EAX.  */
27521           regno = AX_REG;
27522         }
27523       else if (ix86_function_regparm (fntype, fndecl) == 3)
27524         {
27525           /* For regparm 3, we have no free call-clobbered registers in
27526              which to store the static chain.  In order to implement this,
27527              we have the trampoline push the static chain to the stack.
27528              However, we can't push a value below the return address when
27529              we call the nested function directly, so we have to use an
27530              alternate entry point.  For this we use ESI, and have the
27531              alternate entry point push ESI, so that things appear the
27532              same once we're executing the nested function.  */
27533           if (incoming_p)
27534             {
27535               if (fndecl == current_function_decl)
27536                 ix86_static_chain_on_stack = true;
27537               return gen_frame_mem (SImode,
27538                                     plus_constant (Pmode,
27539                                                    arg_pointer_rtx, -8));
27540             }
27541           regno = SI_REG;
27542         }
27543     }
27544
27545   return gen_rtx_REG (Pmode, regno);
27546 }
27547
27548 /* Emit RTL insns to initialize the variable parts of a trampoline.
27549    FNDECL is the decl of the target address; M_TRAMP is a MEM for
27550    the trampoline, and CHAIN_VALUE is an RTX for the static chain
27551    to be passed to the target function.  */
27552
27553 static void
27554 ix86_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value)
27555 {
27556   rtx mem, fnaddr;
27557   int opcode;
27558   int offset = 0;
27559
27560   fnaddr = XEXP (DECL_RTL (fndecl), 0);
27561
27562   if (TARGET_64BIT)
27563     {
27564       int size;
27565
27566       /* Load the function address to r11.  Try to load address using
27567          the shorter movl instead of movabs.  We may want to support
27568          movq for kernel mode, but kernel does not use trampolines at
27569          the moment.  FNADDR is a 32bit address and may not be in
27570          DImode when ptr_mode == SImode.  Always use movl in this
27571          case.  */
27572       if (ptr_mode == SImode
27573           || x86_64_zext_immediate_operand (fnaddr, VOIDmode))
27574         {
27575           fnaddr = copy_addr_to_reg (fnaddr);
27576
27577           mem = adjust_address (m_tramp, HImode, offset);
27578           emit_move_insn (mem, gen_int_mode (0xbb41, HImode));
27579
27580           mem = adjust_address (m_tramp, SImode, offset + 2);
27581           emit_move_insn (mem, gen_lowpart (SImode, fnaddr));
27582           offset += 6;
27583         }
27584       else
27585         {
27586           mem = adjust_address (m_tramp, HImode, offset);
27587           emit_move_insn (mem, gen_int_mode (0xbb49, HImode));
27588
27589           mem = adjust_address (m_tramp, DImode, offset + 2);
27590           emit_move_insn (mem, fnaddr);
27591           offset += 10;
27592         }
27593
27594       /* Load static chain using movabs to r10.  Use the shorter movl
27595          instead of movabs when ptr_mode == SImode.  */
27596       if (ptr_mode == SImode)
27597         {
27598           opcode = 0xba41;
27599           size = 6;
27600         }
27601       else
27602         {
27603           opcode = 0xba49;
27604           size = 10;
27605         }
27606
27607       mem = adjust_address (m_tramp, HImode, offset);
27608       emit_move_insn (mem, gen_int_mode (opcode, HImode));
27609
27610       mem = adjust_address (m_tramp, ptr_mode, offset + 2);
27611       emit_move_insn (mem, chain_value);
27612       offset += size;
27613
27614       /* Jump to r11; the last (unused) byte is a nop, only there to
27615          pad the write out to a single 32-bit store.  */
27616       mem = adjust_address (m_tramp, SImode, offset);
27617       emit_move_insn (mem, gen_int_mode (0x90e3ff49, SImode));
27618       offset += 4;
27619     }
27620   else
27621     {
27622       rtx disp, chain;
27623
27624       /* Depending on the static chain location, either load a register
27625          with a constant, or push the constant to the stack.  All of the
27626          instructions are the same size.  */
27627       chain = ix86_static_chain (fndecl, true);
27628       if (REG_P (chain))
27629         {
27630           switch (REGNO (chain))
27631             {
27632             case AX_REG:
27633               opcode = 0xb8; break;
27634             case CX_REG:
27635               opcode = 0xb9; break;
27636             default:
27637               gcc_unreachable ();
27638             }
27639         }
27640       else
27641         opcode = 0x68;
27642
27643       mem = adjust_address (m_tramp, QImode, offset);
27644       emit_move_insn (mem, gen_int_mode (opcode, QImode));
27645
27646       mem = adjust_address (m_tramp, SImode, offset + 1);
27647       emit_move_insn (mem, chain_value);
27648       offset += 5;
27649
27650       mem = adjust_address (m_tramp, QImode, offset);
27651       emit_move_insn (mem, gen_int_mode (0xe9, QImode));
27652
27653       mem = adjust_address (m_tramp, SImode, offset + 1);
27654
27655       /* Compute offset from the end of the jmp to the target function.
27656          In the case in which the trampoline stores the static chain on
27657          the stack, we need to skip the first insn which pushes the
27658          (call-saved) register static chain; this push is 1 byte.  */
27659       offset += 5;
27660       disp = expand_binop (SImode, sub_optab, fnaddr,
27661                            plus_constant (Pmode, XEXP (m_tramp, 0),
27662                                           offset - (MEM_P (chain) ? 1 : 0)),
27663                            NULL_RTX, 1, OPTAB_DIRECT);
27664       emit_move_insn (mem, disp);
27665     }
27666
27667   gcc_assert (offset <= TRAMPOLINE_SIZE);
27668
27669 #ifdef HAVE_ENABLE_EXECUTE_STACK
27670 #ifdef CHECK_EXECUTE_STACK_ENABLED
27671   if (CHECK_EXECUTE_STACK_ENABLED)
27672 #endif
27673   emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__enable_execute_stack"),
27674                      LCT_NORMAL, VOIDmode, 1, XEXP (m_tramp, 0), Pmode);
27675 #endif
27676 }
27677 \f
27678 /* The following file contains several enumerations and data structures
27679    built from the definitions in i386-builtin-types.def.  */
27680
27681 #include "i386-builtin-types.inc"
27682
27683 /* Table for the ix86 builtin non-function types.  */
27684 static GTY(()) tree ix86_builtin_type_tab[(int) IX86_BT_LAST_CPTR + 1];
27685
27686 /* Retrieve an element from the above table, building some of
27687    the types lazily.  */
27688
27689 static tree
27690 ix86_get_builtin_type (enum ix86_builtin_type tcode)
27691 {
27692   unsigned int index;
27693   tree type, itype;
27694
27695   gcc_assert ((unsigned)tcode < ARRAY_SIZE(ix86_builtin_type_tab));
27696
27697   type = ix86_builtin_type_tab[(int) tcode];
27698   if (type != NULL)
27699     return type;
27700
27701   gcc_assert (tcode > IX86_BT_LAST_PRIM);
27702   if (tcode <= IX86_BT_LAST_VECT)
27703     {
27704       machine_mode mode;
27705
27706       index = tcode - IX86_BT_LAST_PRIM - 1;
27707       itype = ix86_get_builtin_type (ix86_builtin_type_vect_base[index]);
27708       mode = ix86_builtin_type_vect_mode[index];
27709
27710       type = build_vector_type_for_mode (itype, mode);
27711     }
27712   else
27713     {
27714       int quals;
27715
27716       index = tcode - IX86_BT_LAST_VECT - 1;
27717       if (tcode <= IX86_BT_LAST_PTR)
27718         quals = TYPE_UNQUALIFIED;
27719       else
27720         quals = TYPE_QUAL_CONST;
27721
27722       itype = ix86_get_builtin_type (ix86_builtin_type_ptr_base[index]);
27723       if (quals != TYPE_UNQUALIFIED)
27724         itype = build_qualified_type (itype, quals);
27725
27726       type = build_pointer_type (itype);
27727     }
27728
27729   ix86_builtin_type_tab[(int) tcode] = type;
27730   return type;
27731 }
27732
27733 /* Table for the ix86 builtin function types.  */
27734 static GTY(()) tree ix86_builtin_func_type_tab[(int) IX86_BT_LAST_ALIAS + 1];
27735
27736 /* Retrieve an element from the above table, building some of
27737    the types lazily.  */
27738
27739 static tree
27740 ix86_get_builtin_func_type (enum ix86_builtin_func_type tcode)
27741 {
27742   tree type;
27743
27744   gcc_assert ((unsigned)tcode < ARRAY_SIZE (ix86_builtin_func_type_tab));
27745
27746   type = ix86_builtin_func_type_tab[(int) tcode];
27747   if (type != NULL)
27748     return type;
27749
27750   if (tcode <= IX86_BT_LAST_FUNC)
27751     {
27752       unsigned start = ix86_builtin_func_start[(int) tcode];
27753       unsigned after = ix86_builtin_func_start[(int) tcode + 1];
27754       tree rtype, atype, args = void_list_node;
27755       unsigned i;
27756
27757       rtype = ix86_get_builtin_type (ix86_builtin_func_args[start]);
27758       for (i = after - 1; i > start; --i)
27759         {
27760           atype = ix86_get_builtin_type (ix86_builtin_func_args[i]);
27761           args = tree_cons (NULL, atype, args);
27762         }
27763
27764       type = build_function_type (rtype, args);
27765     }
27766   else
27767     {
27768       unsigned index = tcode - IX86_BT_LAST_FUNC - 1;
27769       enum ix86_builtin_func_type icode;
27770
27771       icode = ix86_builtin_func_alias_base[index];
27772       type = ix86_get_builtin_func_type (icode);
27773     }
27774
27775   ix86_builtin_func_type_tab[(int) tcode] = type;
27776   return type;
27777 }
27778
27779
27780 /* Codes for all the SSE/MMX builtins.  */
27781 enum ix86_builtins
27782 {
27783   IX86_BUILTIN_ADDPS,
27784   IX86_BUILTIN_ADDSS,
27785   IX86_BUILTIN_DIVPS,
27786   IX86_BUILTIN_DIVSS,
27787   IX86_BUILTIN_MULPS,
27788   IX86_BUILTIN_MULSS,
27789   IX86_BUILTIN_SUBPS,
27790   IX86_BUILTIN_SUBSS,
27791
27792   IX86_BUILTIN_CMPEQPS,
27793   IX86_BUILTIN_CMPLTPS,
27794   IX86_BUILTIN_CMPLEPS,
27795   IX86_BUILTIN_CMPGTPS,
27796   IX86_BUILTIN_CMPGEPS,
27797   IX86_BUILTIN_CMPNEQPS,
27798   IX86_BUILTIN_CMPNLTPS,
27799   IX86_BUILTIN_CMPNLEPS,
27800   IX86_BUILTIN_CMPNGTPS,
27801   IX86_BUILTIN_CMPNGEPS,
27802   IX86_BUILTIN_CMPORDPS,
27803   IX86_BUILTIN_CMPUNORDPS,
27804   IX86_BUILTIN_CMPEQSS,
27805   IX86_BUILTIN_CMPLTSS,
27806   IX86_BUILTIN_CMPLESS,
27807   IX86_BUILTIN_CMPNEQSS,
27808   IX86_BUILTIN_CMPNLTSS,
27809   IX86_BUILTIN_CMPNLESS,
27810   IX86_BUILTIN_CMPORDSS,
27811   IX86_BUILTIN_CMPUNORDSS,
27812
27813   IX86_BUILTIN_COMIEQSS,
27814   IX86_BUILTIN_COMILTSS,
27815   IX86_BUILTIN_COMILESS,
27816   IX86_BUILTIN_COMIGTSS,
27817   IX86_BUILTIN_COMIGESS,
27818   IX86_BUILTIN_COMINEQSS,
27819   IX86_BUILTIN_UCOMIEQSS,
27820   IX86_BUILTIN_UCOMILTSS,
27821   IX86_BUILTIN_UCOMILESS,
27822   IX86_BUILTIN_UCOMIGTSS,
27823   IX86_BUILTIN_UCOMIGESS,
27824   IX86_BUILTIN_UCOMINEQSS,
27825
27826   IX86_BUILTIN_CVTPI2PS,
27827   IX86_BUILTIN_CVTPS2PI,
27828   IX86_BUILTIN_CVTSI2SS,
27829   IX86_BUILTIN_CVTSI642SS,
27830   IX86_BUILTIN_CVTSS2SI,
27831   IX86_BUILTIN_CVTSS2SI64,
27832   IX86_BUILTIN_CVTTPS2PI,
27833   IX86_BUILTIN_CVTTSS2SI,
27834   IX86_BUILTIN_CVTTSS2SI64,
27835
27836   IX86_BUILTIN_MAXPS,
27837   IX86_BUILTIN_MAXSS,
27838   IX86_BUILTIN_MINPS,
27839   IX86_BUILTIN_MINSS,
27840
27841   IX86_BUILTIN_LOADUPS,
27842   IX86_BUILTIN_STOREUPS,
27843   IX86_BUILTIN_MOVSS,
27844
27845   IX86_BUILTIN_MOVHLPS,
27846   IX86_BUILTIN_MOVLHPS,
27847   IX86_BUILTIN_LOADHPS,
27848   IX86_BUILTIN_LOADLPS,
27849   IX86_BUILTIN_STOREHPS,
27850   IX86_BUILTIN_STORELPS,
27851
27852   IX86_BUILTIN_MASKMOVQ,
27853   IX86_BUILTIN_MOVMSKPS,
27854   IX86_BUILTIN_PMOVMSKB,
27855
27856   IX86_BUILTIN_MOVNTPS,
27857   IX86_BUILTIN_MOVNTQ,
27858
27859   IX86_BUILTIN_LOADDQU,
27860   IX86_BUILTIN_STOREDQU,
27861
27862   IX86_BUILTIN_PACKSSWB,
27863   IX86_BUILTIN_PACKSSDW,
27864   IX86_BUILTIN_PACKUSWB,
27865
27866   IX86_BUILTIN_PADDB,
27867   IX86_BUILTIN_PADDW,
27868   IX86_BUILTIN_PADDD,
27869   IX86_BUILTIN_PADDQ,
27870   IX86_BUILTIN_PADDSB,
27871   IX86_BUILTIN_PADDSW,
27872   IX86_BUILTIN_PADDUSB,
27873   IX86_BUILTIN_PADDUSW,
27874   IX86_BUILTIN_PSUBB,
27875   IX86_BUILTIN_PSUBW,
27876   IX86_BUILTIN_PSUBD,
27877   IX86_BUILTIN_PSUBQ,
27878   IX86_BUILTIN_PSUBSB,
27879   IX86_BUILTIN_PSUBSW,
27880   IX86_BUILTIN_PSUBUSB,
27881   IX86_BUILTIN_PSUBUSW,
27882
27883   IX86_BUILTIN_PAND,
27884   IX86_BUILTIN_PANDN,
27885   IX86_BUILTIN_POR,
27886   IX86_BUILTIN_PXOR,
27887
27888   IX86_BUILTIN_PAVGB,
27889   IX86_BUILTIN_PAVGW,
27890
27891   IX86_BUILTIN_PCMPEQB,
27892   IX86_BUILTIN_PCMPEQW,
27893   IX86_BUILTIN_PCMPEQD,
27894   IX86_BUILTIN_PCMPGTB,
27895   IX86_BUILTIN_PCMPGTW,
27896   IX86_BUILTIN_PCMPGTD,
27897
27898   IX86_BUILTIN_PMADDWD,
27899
27900   IX86_BUILTIN_PMAXSW,
27901   IX86_BUILTIN_PMAXUB,
27902   IX86_BUILTIN_PMINSW,
27903   IX86_BUILTIN_PMINUB,
27904
27905   IX86_BUILTIN_PMULHUW,
27906   IX86_BUILTIN_PMULHW,
27907   IX86_BUILTIN_PMULLW,
27908
27909   IX86_BUILTIN_PSADBW,
27910   IX86_BUILTIN_PSHUFW,
27911
27912   IX86_BUILTIN_PSLLW,
27913   IX86_BUILTIN_PSLLD,
27914   IX86_BUILTIN_PSLLQ,
27915   IX86_BUILTIN_PSRAW,
27916   IX86_BUILTIN_PSRAD,
27917   IX86_BUILTIN_PSRLW,
27918   IX86_BUILTIN_PSRLD,
27919   IX86_BUILTIN_PSRLQ,
27920   IX86_BUILTIN_PSLLWI,
27921   IX86_BUILTIN_PSLLDI,
27922   IX86_BUILTIN_PSLLQI,
27923   IX86_BUILTIN_PSRAWI,
27924   IX86_BUILTIN_PSRADI,
27925   IX86_BUILTIN_PSRLWI,
27926   IX86_BUILTIN_PSRLDI,
27927   IX86_BUILTIN_PSRLQI,
27928
27929   IX86_BUILTIN_PUNPCKHBW,
27930   IX86_BUILTIN_PUNPCKHWD,
27931   IX86_BUILTIN_PUNPCKHDQ,
27932   IX86_BUILTIN_PUNPCKLBW,
27933   IX86_BUILTIN_PUNPCKLWD,
27934   IX86_BUILTIN_PUNPCKLDQ,
27935
27936   IX86_BUILTIN_SHUFPS,
27937
27938   IX86_BUILTIN_RCPPS,
27939   IX86_BUILTIN_RCPSS,
27940   IX86_BUILTIN_RSQRTPS,
27941   IX86_BUILTIN_RSQRTPS_NR,
27942   IX86_BUILTIN_RSQRTSS,
27943   IX86_BUILTIN_RSQRTF,
27944   IX86_BUILTIN_SQRTPS,
27945   IX86_BUILTIN_SQRTPS_NR,
27946   IX86_BUILTIN_SQRTSS,
27947
27948   IX86_BUILTIN_UNPCKHPS,
27949   IX86_BUILTIN_UNPCKLPS,
27950
27951   IX86_BUILTIN_ANDPS,
27952   IX86_BUILTIN_ANDNPS,
27953   IX86_BUILTIN_ORPS,
27954   IX86_BUILTIN_XORPS,
27955
27956   IX86_BUILTIN_EMMS,
27957   IX86_BUILTIN_LDMXCSR,
27958   IX86_BUILTIN_STMXCSR,
27959   IX86_BUILTIN_SFENCE,
27960
27961   IX86_BUILTIN_FXSAVE,
27962   IX86_BUILTIN_FXRSTOR,
27963   IX86_BUILTIN_FXSAVE64,
27964   IX86_BUILTIN_FXRSTOR64,
27965
27966   IX86_BUILTIN_XSAVE,
27967   IX86_BUILTIN_XRSTOR,
27968   IX86_BUILTIN_XSAVE64,
27969   IX86_BUILTIN_XRSTOR64,
27970
27971   IX86_BUILTIN_XSAVEOPT,
27972   IX86_BUILTIN_XSAVEOPT64,
27973
27974   IX86_BUILTIN_XSAVEC,
27975   IX86_BUILTIN_XSAVEC64,
27976
27977   IX86_BUILTIN_XSAVES,
27978   IX86_BUILTIN_XRSTORS,
27979   IX86_BUILTIN_XSAVES64,
27980   IX86_BUILTIN_XRSTORS64,
27981
27982   /* 3DNow! Original */
27983   IX86_BUILTIN_FEMMS,
27984   IX86_BUILTIN_PAVGUSB,
27985   IX86_BUILTIN_PF2ID,
27986   IX86_BUILTIN_PFACC,
27987   IX86_BUILTIN_PFADD,
27988   IX86_BUILTIN_PFCMPEQ,
27989   IX86_BUILTIN_PFCMPGE,
27990   IX86_BUILTIN_PFCMPGT,
27991   IX86_BUILTIN_PFMAX,
27992   IX86_BUILTIN_PFMIN,
27993   IX86_BUILTIN_PFMUL,
27994   IX86_BUILTIN_PFRCP,
27995   IX86_BUILTIN_PFRCPIT1,
27996   IX86_BUILTIN_PFRCPIT2,
27997   IX86_BUILTIN_PFRSQIT1,
27998   IX86_BUILTIN_PFRSQRT,
27999   IX86_BUILTIN_PFSUB,
28000   IX86_BUILTIN_PFSUBR,
28001   IX86_BUILTIN_PI2FD,
28002   IX86_BUILTIN_PMULHRW,
28003
28004   /* 3DNow! Athlon Extensions */
28005   IX86_BUILTIN_PF2IW,
28006   IX86_BUILTIN_PFNACC,
28007   IX86_BUILTIN_PFPNACC,
28008   IX86_BUILTIN_PI2FW,
28009   IX86_BUILTIN_PSWAPDSI,
28010   IX86_BUILTIN_PSWAPDSF,
28011
28012   /* SSE2 */
28013   IX86_BUILTIN_ADDPD,
28014   IX86_BUILTIN_ADDSD,
28015   IX86_BUILTIN_DIVPD,
28016   IX86_BUILTIN_DIVSD,
28017   IX86_BUILTIN_MULPD,
28018   IX86_BUILTIN_MULSD,
28019   IX86_BUILTIN_SUBPD,
28020   IX86_BUILTIN_SUBSD,
28021
28022   IX86_BUILTIN_CMPEQPD,
28023   IX86_BUILTIN_CMPLTPD,
28024   IX86_BUILTIN_CMPLEPD,
28025   IX86_BUILTIN_CMPGTPD,
28026   IX86_BUILTIN_CMPGEPD,
28027   IX86_BUILTIN_CMPNEQPD,
28028   IX86_BUILTIN_CMPNLTPD,
28029   IX86_BUILTIN_CMPNLEPD,
28030   IX86_BUILTIN_CMPNGTPD,
28031   IX86_BUILTIN_CMPNGEPD,
28032   IX86_BUILTIN_CMPORDPD,
28033   IX86_BUILTIN_CMPUNORDPD,
28034   IX86_BUILTIN_CMPEQSD,
28035   IX86_BUILTIN_CMPLTSD,
28036   IX86_BUILTIN_CMPLESD,
28037   IX86_BUILTIN_CMPNEQSD,
28038   IX86_BUILTIN_CMPNLTSD,
28039   IX86_BUILTIN_CMPNLESD,
28040   IX86_BUILTIN_CMPORDSD,
28041   IX86_BUILTIN_CMPUNORDSD,
28042
28043   IX86_BUILTIN_COMIEQSD,
28044   IX86_BUILTIN_COMILTSD,
28045   IX86_BUILTIN_COMILESD,
28046   IX86_BUILTIN_COMIGTSD,
28047   IX86_BUILTIN_COMIGESD,
28048   IX86_BUILTIN_COMINEQSD,
28049   IX86_BUILTIN_UCOMIEQSD,
28050   IX86_BUILTIN_UCOMILTSD,
28051   IX86_BUILTIN_UCOMILESD,
28052   IX86_BUILTIN_UCOMIGTSD,
28053   IX86_BUILTIN_UCOMIGESD,
28054   IX86_BUILTIN_UCOMINEQSD,
28055
28056   IX86_BUILTIN_MAXPD,
28057   IX86_BUILTIN_MAXSD,
28058   IX86_BUILTIN_MINPD,
28059   IX86_BUILTIN_MINSD,
28060
28061   IX86_BUILTIN_ANDPD,
28062   IX86_BUILTIN_ANDNPD,
28063   IX86_BUILTIN_ORPD,
28064   IX86_BUILTIN_XORPD,
28065
28066   IX86_BUILTIN_SQRTPD,
28067   IX86_BUILTIN_SQRTSD,
28068
28069   IX86_BUILTIN_UNPCKHPD,
28070   IX86_BUILTIN_UNPCKLPD,
28071
28072   IX86_BUILTIN_SHUFPD,
28073
28074   IX86_BUILTIN_LOADUPD,
28075   IX86_BUILTIN_STOREUPD,
28076   IX86_BUILTIN_MOVSD,
28077
28078   IX86_BUILTIN_LOADHPD,
28079   IX86_BUILTIN_LOADLPD,
28080
28081   IX86_BUILTIN_CVTDQ2PD,
28082   IX86_BUILTIN_CVTDQ2PS,
28083
28084   IX86_BUILTIN_CVTPD2DQ,
28085   IX86_BUILTIN_CVTPD2PI,
28086   IX86_BUILTIN_CVTPD2PS,
28087   IX86_BUILTIN_CVTTPD2DQ,
28088   IX86_BUILTIN_CVTTPD2PI,
28089
28090   IX86_BUILTIN_CVTPI2PD,
28091   IX86_BUILTIN_CVTSI2SD,
28092   IX86_BUILTIN_CVTSI642SD,
28093
28094   IX86_BUILTIN_CVTSD2SI,
28095   IX86_BUILTIN_CVTSD2SI64,
28096   IX86_BUILTIN_CVTSD2SS,
28097   IX86_BUILTIN_CVTSS2SD,
28098   IX86_BUILTIN_CVTTSD2SI,
28099   IX86_BUILTIN_CVTTSD2SI64,
28100
28101   IX86_BUILTIN_CVTPS2DQ,
28102   IX86_BUILTIN_CVTPS2PD,
28103   IX86_BUILTIN_CVTTPS2DQ,
28104
28105   IX86_BUILTIN_MOVNTI,
28106   IX86_BUILTIN_MOVNTI64,
28107   IX86_BUILTIN_MOVNTPD,
28108   IX86_BUILTIN_MOVNTDQ,
28109
28110   IX86_BUILTIN_MOVQ128,
28111
28112   /* SSE2 MMX */
28113   IX86_BUILTIN_MASKMOVDQU,
28114   IX86_BUILTIN_MOVMSKPD,
28115   IX86_BUILTIN_PMOVMSKB128,
28116
28117   IX86_BUILTIN_PACKSSWB128,
28118   IX86_BUILTIN_PACKSSDW128,
28119   IX86_BUILTIN_PACKUSWB128,
28120
28121   IX86_BUILTIN_PADDB128,
28122   IX86_BUILTIN_PADDW128,
28123   IX86_BUILTIN_PADDD128,
28124   IX86_BUILTIN_PADDQ128,
28125   IX86_BUILTIN_PADDSB128,
28126   IX86_BUILTIN_PADDSW128,
28127   IX86_BUILTIN_PADDUSB128,
28128   IX86_BUILTIN_PADDUSW128,
28129   IX86_BUILTIN_PSUBB128,
28130   IX86_BUILTIN_PSUBW128,
28131   IX86_BUILTIN_PSUBD128,
28132   IX86_BUILTIN_PSUBQ128,
28133   IX86_BUILTIN_PSUBSB128,
28134   IX86_BUILTIN_PSUBSW128,
28135   IX86_BUILTIN_PSUBUSB128,
28136   IX86_BUILTIN_PSUBUSW128,
28137
28138   IX86_BUILTIN_PAND128,
28139   IX86_BUILTIN_PANDN128,
28140   IX86_BUILTIN_POR128,
28141   IX86_BUILTIN_PXOR128,
28142
28143   IX86_BUILTIN_PAVGB128,
28144   IX86_BUILTIN_PAVGW128,
28145
28146   IX86_BUILTIN_PCMPEQB128,
28147   IX86_BUILTIN_PCMPEQW128,
28148   IX86_BUILTIN_PCMPEQD128,
28149   IX86_BUILTIN_PCMPGTB128,
28150   IX86_BUILTIN_PCMPGTW128,
28151   IX86_BUILTIN_PCMPGTD128,
28152
28153   IX86_BUILTIN_PMADDWD128,
28154
28155   IX86_BUILTIN_PMAXSW128,
28156   IX86_BUILTIN_PMAXUB128,
28157   IX86_BUILTIN_PMINSW128,
28158   IX86_BUILTIN_PMINUB128,
28159
28160   IX86_BUILTIN_PMULUDQ,
28161   IX86_BUILTIN_PMULUDQ128,
28162   IX86_BUILTIN_PMULHUW128,
28163   IX86_BUILTIN_PMULHW128,
28164   IX86_BUILTIN_PMULLW128,
28165
28166   IX86_BUILTIN_PSADBW128,
28167   IX86_BUILTIN_PSHUFHW,
28168   IX86_BUILTIN_PSHUFLW,
28169   IX86_BUILTIN_PSHUFD,
28170
28171   IX86_BUILTIN_PSLLDQI128,
28172   IX86_BUILTIN_PSLLWI128,
28173   IX86_BUILTIN_PSLLDI128,
28174   IX86_BUILTIN_PSLLQI128,
28175   IX86_BUILTIN_PSRAWI128,
28176   IX86_BUILTIN_PSRADI128,
28177   IX86_BUILTIN_PSRLDQI128,
28178   IX86_BUILTIN_PSRLWI128,
28179   IX86_BUILTIN_PSRLDI128,
28180   IX86_BUILTIN_PSRLQI128,
28181
28182   IX86_BUILTIN_PSLLDQ128,
28183   IX86_BUILTIN_PSLLW128,
28184   IX86_BUILTIN_PSLLD128,
28185   IX86_BUILTIN_PSLLQ128,
28186   IX86_BUILTIN_PSRAW128,
28187   IX86_BUILTIN_PSRAD128,
28188   IX86_BUILTIN_PSRLW128,
28189   IX86_BUILTIN_PSRLD128,
28190   IX86_BUILTIN_PSRLQ128,
28191
28192   IX86_BUILTIN_PUNPCKHBW128,
28193   IX86_BUILTIN_PUNPCKHWD128,
28194   IX86_BUILTIN_PUNPCKHDQ128,
28195   IX86_BUILTIN_PUNPCKHQDQ128,
28196   IX86_BUILTIN_PUNPCKLBW128,
28197   IX86_BUILTIN_PUNPCKLWD128,
28198   IX86_BUILTIN_PUNPCKLDQ128,
28199   IX86_BUILTIN_PUNPCKLQDQ128,
28200
28201   IX86_BUILTIN_CLFLUSH,
28202   IX86_BUILTIN_MFENCE,
28203   IX86_BUILTIN_LFENCE,
28204   IX86_BUILTIN_PAUSE,
28205
28206   IX86_BUILTIN_FNSTENV,
28207   IX86_BUILTIN_FLDENV,
28208   IX86_BUILTIN_FNSTSW,
28209   IX86_BUILTIN_FNCLEX,
28210
28211   IX86_BUILTIN_BSRSI,
28212   IX86_BUILTIN_BSRDI,
28213   IX86_BUILTIN_RDPMC,
28214   IX86_BUILTIN_RDTSC,
28215   IX86_BUILTIN_RDTSCP,
28216   IX86_BUILTIN_ROLQI,
28217   IX86_BUILTIN_ROLHI,
28218   IX86_BUILTIN_RORQI,
28219   IX86_BUILTIN_RORHI,
28220
28221   /* SSE3.  */
28222   IX86_BUILTIN_ADDSUBPS,
28223   IX86_BUILTIN_HADDPS,
28224   IX86_BUILTIN_HSUBPS,
28225   IX86_BUILTIN_MOVSHDUP,
28226   IX86_BUILTIN_MOVSLDUP,
28227   IX86_BUILTIN_ADDSUBPD,
28228   IX86_BUILTIN_HADDPD,
28229   IX86_BUILTIN_HSUBPD,
28230   IX86_BUILTIN_LDDQU,
28231
28232   IX86_BUILTIN_MONITOR,
28233   IX86_BUILTIN_MWAIT,
28234
28235   /* SSSE3.  */
28236   IX86_BUILTIN_PHADDW,
28237   IX86_BUILTIN_PHADDD,
28238   IX86_BUILTIN_PHADDSW,
28239   IX86_BUILTIN_PHSUBW,
28240   IX86_BUILTIN_PHSUBD,
28241   IX86_BUILTIN_PHSUBSW,
28242   IX86_BUILTIN_PMADDUBSW,
28243   IX86_BUILTIN_PMULHRSW,
28244   IX86_BUILTIN_PSHUFB,
28245   IX86_BUILTIN_PSIGNB,
28246   IX86_BUILTIN_PSIGNW,
28247   IX86_BUILTIN_PSIGND,
28248   IX86_BUILTIN_PALIGNR,
28249   IX86_BUILTIN_PABSB,
28250   IX86_BUILTIN_PABSW,
28251   IX86_BUILTIN_PABSD,
28252
28253   IX86_BUILTIN_PHADDW128,
28254   IX86_BUILTIN_PHADDD128,
28255   IX86_BUILTIN_PHADDSW128,
28256   IX86_BUILTIN_PHSUBW128,
28257   IX86_BUILTIN_PHSUBD128,
28258   IX86_BUILTIN_PHSUBSW128,
28259   IX86_BUILTIN_PMADDUBSW128,
28260   IX86_BUILTIN_PMULHRSW128,
28261   IX86_BUILTIN_PSHUFB128,
28262   IX86_BUILTIN_PSIGNB128,
28263   IX86_BUILTIN_PSIGNW128,
28264   IX86_BUILTIN_PSIGND128,
28265   IX86_BUILTIN_PALIGNR128,
28266   IX86_BUILTIN_PABSB128,
28267   IX86_BUILTIN_PABSW128,
28268   IX86_BUILTIN_PABSD128,
28269
28270   /* AMDFAM10 - SSE4A New Instructions.  */
28271   IX86_BUILTIN_MOVNTSD,
28272   IX86_BUILTIN_MOVNTSS,
28273   IX86_BUILTIN_EXTRQI,
28274   IX86_BUILTIN_EXTRQ,
28275   IX86_BUILTIN_INSERTQI,
28276   IX86_BUILTIN_INSERTQ,
28277
28278   /* SSE4.1.  */
28279   IX86_BUILTIN_BLENDPD,
28280   IX86_BUILTIN_BLENDPS,
28281   IX86_BUILTIN_BLENDVPD,
28282   IX86_BUILTIN_BLENDVPS,
28283   IX86_BUILTIN_PBLENDVB128,
28284   IX86_BUILTIN_PBLENDW128,
28285
28286   IX86_BUILTIN_DPPD,
28287   IX86_BUILTIN_DPPS,
28288
28289   IX86_BUILTIN_INSERTPS128,
28290
28291   IX86_BUILTIN_MOVNTDQA,
28292   IX86_BUILTIN_MPSADBW128,
28293   IX86_BUILTIN_PACKUSDW128,
28294   IX86_BUILTIN_PCMPEQQ,
28295   IX86_BUILTIN_PHMINPOSUW128,
28296
28297   IX86_BUILTIN_PMAXSB128,
28298   IX86_BUILTIN_PMAXSD128,
28299   IX86_BUILTIN_PMAXUD128,
28300   IX86_BUILTIN_PMAXUW128,
28301
28302   IX86_BUILTIN_PMINSB128,
28303   IX86_BUILTIN_PMINSD128,
28304   IX86_BUILTIN_PMINUD128,
28305   IX86_BUILTIN_PMINUW128,
28306
28307   IX86_BUILTIN_PMOVSXBW128,
28308   IX86_BUILTIN_PMOVSXBD128,
28309   IX86_BUILTIN_PMOVSXBQ128,
28310   IX86_BUILTIN_PMOVSXWD128,
28311   IX86_BUILTIN_PMOVSXWQ128,
28312   IX86_BUILTIN_PMOVSXDQ128,
28313
28314   IX86_BUILTIN_PMOVZXBW128,
28315   IX86_BUILTIN_PMOVZXBD128,
28316   IX86_BUILTIN_PMOVZXBQ128,
28317   IX86_BUILTIN_PMOVZXWD128,
28318   IX86_BUILTIN_PMOVZXWQ128,
28319   IX86_BUILTIN_PMOVZXDQ128,
28320
28321   IX86_BUILTIN_PMULDQ128,
28322   IX86_BUILTIN_PMULLD128,
28323
28324   IX86_BUILTIN_ROUNDSD,
28325   IX86_BUILTIN_ROUNDSS,
28326
28327   IX86_BUILTIN_ROUNDPD,
28328   IX86_BUILTIN_ROUNDPS,
28329
28330   IX86_BUILTIN_FLOORPD,
28331   IX86_BUILTIN_CEILPD,
28332   IX86_BUILTIN_TRUNCPD,
28333   IX86_BUILTIN_RINTPD,
28334   IX86_BUILTIN_ROUNDPD_AZ,
28335
28336   IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX,
28337   IX86_BUILTIN_CEILPD_VEC_PACK_SFIX,
28338   IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX,
28339
28340   IX86_BUILTIN_FLOORPS,
28341   IX86_BUILTIN_CEILPS,
28342   IX86_BUILTIN_TRUNCPS,
28343   IX86_BUILTIN_RINTPS,
28344   IX86_BUILTIN_ROUNDPS_AZ,
28345
28346   IX86_BUILTIN_FLOORPS_SFIX,
28347   IX86_BUILTIN_CEILPS_SFIX,
28348   IX86_BUILTIN_ROUNDPS_AZ_SFIX,
28349
28350   IX86_BUILTIN_PTESTZ,
28351   IX86_BUILTIN_PTESTC,
28352   IX86_BUILTIN_PTESTNZC,
28353
28354   IX86_BUILTIN_VEC_INIT_V2SI,
28355   IX86_BUILTIN_VEC_INIT_V4HI,
28356   IX86_BUILTIN_VEC_INIT_V8QI,
28357   IX86_BUILTIN_VEC_EXT_V2DF,
28358   IX86_BUILTIN_VEC_EXT_V2DI,
28359   IX86_BUILTIN_VEC_EXT_V4SF,
28360   IX86_BUILTIN_VEC_EXT_V4SI,
28361   IX86_BUILTIN_VEC_EXT_V8HI,
28362   IX86_BUILTIN_VEC_EXT_V2SI,
28363   IX86_BUILTIN_VEC_EXT_V4HI,
28364   IX86_BUILTIN_VEC_EXT_V16QI,
28365   IX86_BUILTIN_VEC_SET_V2DI,
28366   IX86_BUILTIN_VEC_SET_V4SF,
28367   IX86_BUILTIN_VEC_SET_V4SI,
28368   IX86_BUILTIN_VEC_SET_V8HI,
28369   IX86_BUILTIN_VEC_SET_V4HI,
28370   IX86_BUILTIN_VEC_SET_V16QI,
28371
28372   IX86_BUILTIN_VEC_PACK_SFIX,
28373   IX86_BUILTIN_VEC_PACK_SFIX256,
28374
28375   /* SSE4.2.  */
28376   IX86_BUILTIN_CRC32QI,
28377   IX86_BUILTIN_CRC32HI,
28378   IX86_BUILTIN_CRC32SI,
28379   IX86_BUILTIN_CRC32DI,
28380
28381   IX86_BUILTIN_PCMPESTRI128,
28382   IX86_BUILTIN_PCMPESTRM128,
28383   IX86_BUILTIN_PCMPESTRA128,
28384   IX86_BUILTIN_PCMPESTRC128,
28385   IX86_BUILTIN_PCMPESTRO128,
28386   IX86_BUILTIN_PCMPESTRS128,
28387   IX86_BUILTIN_PCMPESTRZ128,
28388   IX86_BUILTIN_PCMPISTRI128,
28389   IX86_BUILTIN_PCMPISTRM128,
28390   IX86_BUILTIN_PCMPISTRA128,
28391   IX86_BUILTIN_PCMPISTRC128,
28392   IX86_BUILTIN_PCMPISTRO128,
28393   IX86_BUILTIN_PCMPISTRS128,
28394   IX86_BUILTIN_PCMPISTRZ128,
28395
28396   IX86_BUILTIN_PCMPGTQ,
28397
28398   /* AES instructions */
28399   IX86_BUILTIN_AESENC128,
28400   IX86_BUILTIN_AESENCLAST128,
28401   IX86_BUILTIN_AESDEC128,
28402   IX86_BUILTIN_AESDECLAST128,
28403   IX86_BUILTIN_AESIMC128,
28404   IX86_BUILTIN_AESKEYGENASSIST128,
28405
28406   /* PCLMUL instruction */
28407   IX86_BUILTIN_PCLMULQDQ128,
28408
28409   /* AVX */
28410   IX86_BUILTIN_ADDPD256,
28411   IX86_BUILTIN_ADDPS256,
28412   IX86_BUILTIN_ADDSUBPD256,
28413   IX86_BUILTIN_ADDSUBPS256,
28414   IX86_BUILTIN_ANDPD256,
28415   IX86_BUILTIN_ANDPS256,
28416   IX86_BUILTIN_ANDNPD256,
28417   IX86_BUILTIN_ANDNPS256,
28418   IX86_BUILTIN_BLENDPD256,
28419   IX86_BUILTIN_BLENDPS256,
28420   IX86_BUILTIN_BLENDVPD256,
28421   IX86_BUILTIN_BLENDVPS256,
28422   IX86_BUILTIN_DIVPD256,
28423   IX86_BUILTIN_DIVPS256,
28424   IX86_BUILTIN_DPPS256,
28425   IX86_BUILTIN_HADDPD256,
28426   IX86_BUILTIN_HADDPS256,
28427   IX86_BUILTIN_HSUBPD256,
28428   IX86_BUILTIN_HSUBPS256,
28429   IX86_BUILTIN_MAXPD256,
28430   IX86_BUILTIN_MAXPS256,
28431   IX86_BUILTIN_MINPD256,
28432   IX86_BUILTIN_MINPS256,
28433   IX86_BUILTIN_MULPD256,
28434   IX86_BUILTIN_MULPS256,
28435   IX86_BUILTIN_ORPD256,
28436   IX86_BUILTIN_ORPS256,
28437   IX86_BUILTIN_SHUFPD256,
28438   IX86_BUILTIN_SHUFPS256,
28439   IX86_BUILTIN_SUBPD256,
28440   IX86_BUILTIN_SUBPS256,
28441   IX86_BUILTIN_XORPD256,
28442   IX86_BUILTIN_XORPS256,
28443   IX86_BUILTIN_CMPSD,
28444   IX86_BUILTIN_CMPSS,
28445   IX86_BUILTIN_CMPPD,
28446   IX86_BUILTIN_CMPPS,
28447   IX86_BUILTIN_CMPPD256,
28448   IX86_BUILTIN_CMPPS256,
28449   IX86_BUILTIN_CVTDQ2PD256,
28450   IX86_BUILTIN_CVTDQ2PS256,
28451   IX86_BUILTIN_CVTPD2PS256,
28452   IX86_BUILTIN_CVTPS2DQ256,
28453   IX86_BUILTIN_CVTPS2PD256,
28454   IX86_BUILTIN_CVTTPD2DQ256,
28455   IX86_BUILTIN_CVTPD2DQ256,
28456   IX86_BUILTIN_CVTTPS2DQ256,
28457   IX86_BUILTIN_EXTRACTF128PD256,
28458   IX86_BUILTIN_EXTRACTF128PS256,
28459   IX86_BUILTIN_EXTRACTF128SI256,
28460   IX86_BUILTIN_VZEROALL,
28461   IX86_BUILTIN_VZEROUPPER,
28462   IX86_BUILTIN_VPERMILVARPD,
28463   IX86_BUILTIN_VPERMILVARPS,
28464   IX86_BUILTIN_VPERMILVARPD256,
28465   IX86_BUILTIN_VPERMILVARPS256,
28466   IX86_BUILTIN_VPERMILPD,
28467   IX86_BUILTIN_VPERMILPS,
28468   IX86_BUILTIN_VPERMILPD256,
28469   IX86_BUILTIN_VPERMILPS256,
28470   IX86_BUILTIN_VPERMIL2PD,
28471   IX86_BUILTIN_VPERMIL2PS,
28472   IX86_BUILTIN_VPERMIL2PD256,
28473   IX86_BUILTIN_VPERMIL2PS256,
28474   IX86_BUILTIN_VPERM2F128PD256,
28475   IX86_BUILTIN_VPERM2F128PS256,
28476   IX86_BUILTIN_VPERM2F128SI256,
28477   IX86_BUILTIN_VBROADCASTSS,
28478   IX86_BUILTIN_VBROADCASTSD256,
28479   IX86_BUILTIN_VBROADCASTSS256,
28480   IX86_BUILTIN_VBROADCASTPD256,
28481   IX86_BUILTIN_VBROADCASTPS256,
28482   IX86_BUILTIN_VINSERTF128PD256,
28483   IX86_BUILTIN_VINSERTF128PS256,
28484   IX86_BUILTIN_VINSERTF128SI256,
28485   IX86_BUILTIN_LOADUPD256,
28486   IX86_BUILTIN_LOADUPS256,
28487   IX86_BUILTIN_STOREUPD256,
28488   IX86_BUILTIN_STOREUPS256,
28489   IX86_BUILTIN_LDDQU256,
28490   IX86_BUILTIN_MOVNTDQ256,
28491   IX86_BUILTIN_MOVNTPD256,
28492   IX86_BUILTIN_MOVNTPS256,
28493   IX86_BUILTIN_LOADDQU256,
28494   IX86_BUILTIN_STOREDQU256,
28495   IX86_BUILTIN_MASKLOADPD,
28496   IX86_BUILTIN_MASKLOADPS,
28497   IX86_BUILTIN_MASKSTOREPD,
28498   IX86_BUILTIN_MASKSTOREPS,
28499   IX86_BUILTIN_MASKLOADPD256,
28500   IX86_BUILTIN_MASKLOADPS256,
28501   IX86_BUILTIN_MASKSTOREPD256,
28502   IX86_BUILTIN_MASKSTOREPS256,
28503   IX86_BUILTIN_MOVSHDUP256,
28504   IX86_BUILTIN_MOVSLDUP256,
28505   IX86_BUILTIN_MOVDDUP256,
28506
28507   IX86_BUILTIN_SQRTPD256,
28508   IX86_BUILTIN_SQRTPS256,
28509   IX86_BUILTIN_SQRTPS_NR256,
28510   IX86_BUILTIN_RSQRTPS256,
28511   IX86_BUILTIN_RSQRTPS_NR256,
28512
28513   IX86_BUILTIN_RCPPS256,
28514
28515   IX86_BUILTIN_ROUNDPD256,
28516   IX86_BUILTIN_ROUNDPS256,
28517
28518   IX86_BUILTIN_FLOORPD256,
28519   IX86_BUILTIN_CEILPD256,
28520   IX86_BUILTIN_TRUNCPD256,
28521   IX86_BUILTIN_RINTPD256,
28522   IX86_BUILTIN_ROUNDPD_AZ256,
28523
28524   IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX256,
28525   IX86_BUILTIN_CEILPD_VEC_PACK_SFIX256,
28526   IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX256,
28527
28528   IX86_BUILTIN_FLOORPS256,
28529   IX86_BUILTIN_CEILPS256,
28530   IX86_BUILTIN_TRUNCPS256,
28531   IX86_BUILTIN_RINTPS256,
28532   IX86_BUILTIN_ROUNDPS_AZ256,
28533
28534   IX86_BUILTIN_FLOORPS_SFIX256,
28535   IX86_BUILTIN_CEILPS_SFIX256,
28536   IX86_BUILTIN_ROUNDPS_AZ_SFIX256,
28537
28538   IX86_BUILTIN_UNPCKHPD256,
28539   IX86_BUILTIN_UNPCKLPD256,
28540   IX86_BUILTIN_UNPCKHPS256,
28541   IX86_BUILTIN_UNPCKLPS256,
28542
28543   IX86_BUILTIN_SI256_SI,
28544   IX86_BUILTIN_PS256_PS,
28545   IX86_BUILTIN_PD256_PD,
28546   IX86_BUILTIN_SI_SI256,
28547   IX86_BUILTIN_PS_PS256,
28548   IX86_BUILTIN_PD_PD256,
28549
28550   IX86_BUILTIN_VTESTZPD,
28551   IX86_BUILTIN_VTESTCPD,
28552   IX86_BUILTIN_VTESTNZCPD,
28553   IX86_BUILTIN_VTESTZPS,
28554   IX86_BUILTIN_VTESTCPS,
28555   IX86_BUILTIN_VTESTNZCPS,
28556   IX86_BUILTIN_VTESTZPD256,
28557   IX86_BUILTIN_VTESTCPD256,
28558   IX86_BUILTIN_VTESTNZCPD256,
28559   IX86_BUILTIN_VTESTZPS256,
28560   IX86_BUILTIN_VTESTCPS256,
28561   IX86_BUILTIN_VTESTNZCPS256,
28562   IX86_BUILTIN_PTESTZ256,
28563   IX86_BUILTIN_PTESTC256,
28564   IX86_BUILTIN_PTESTNZC256,
28565
28566   IX86_BUILTIN_MOVMSKPD256,
28567   IX86_BUILTIN_MOVMSKPS256,
28568
28569   /* AVX2 */
28570   IX86_BUILTIN_MPSADBW256,
28571   IX86_BUILTIN_PABSB256,
28572   IX86_BUILTIN_PABSW256,
28573   IX86_BUILTIN_PABSD256,
28574   IX86_BUILTIN_PACKSSDW256,
28575   IX86_BUILTIN_PACKSSWB256,
28576   IX86_BUILTIN_PACKUSDW256,
28577   IX86_BUILTIN_PACKUSWB256,
28578   IX86_BUILTIN_PADDB256,
28579   IX86_BUILTIN_PADDW256,
28580   IX86_BUILTIN_PADDD256,
28581   IX86_BUILTIN_PADDQ256,
28582   IX86_BUILTIN_PADDSB256,
28583   IX86_BUILTIN_PADDSW256,
28584   IX86_BUILTIN_PADDUSB256,
28585   IX86_BUILTIN_PADDUSW256,
28586   IX86_BUILTIN_PALIGNR256,
28587   IX86_BUILTIN_AND256I,
28588   IX86_BUILTIN_ANDNOT256I,
28589   IX86_BUILTIN_PAVGB256,
28590   IX86_BUILTIN_PAVGW256,
28591   IX86_BUILTIN_PBLENDVB256,
28592   IX86_BUILTIN_PBLENDVW256,
28593   IX86_BUILTIN_PCMPEQB256,
28594   IX86_BUILTIN_PCMPEQW256,
28595   IX86_BUILTIN_PCMPEQD256,
28596   IX86_BUILTIN_PCMPEQQ256,
28597   IX86_BUILTIN_PCMPGTB256,
28598   IX86_BUILTIN_PCMPGTW256,
28599   IX86_BUILTIN_PCMPGTD256,
28600   IX86_BUILTIN_PCMPGTQ256,
28601   IX86_BUILTIN_PHADDW256,
28602   IX86_BUILTIN_PHADDD256,
28603   IX86_BUILTIN_PHADDSW256,
28604   IX86_BUILTIN_PHSUBW256,
28605   IX86_BUILTIN_PHSUBD256,
28606   IX86_BUILTIN_PHSUBSW256,
28607   IX86_BUILTIN_PMADDUBSW256,
28608   IX86_BUILTIN_PMADDWD256,
28609   IX86_BUILTIN_PMAXSB256,
28610   IX86_BUILTIN_PMAXSW256,
28611   IX86_BUILTIN_PMAXSD256,
28612   IX86_BUILTIN_PMAXUB256,
28613   IX86_BUILTIN_PMAXUW256,
28614   IX86_BUILTIN_PMAXUD256,
28615   IX86_BUILTIN_PMINSB256,
28616   IX86_BUILTIN_PMINSW256,
28617   IX86_BUILTIN_PMINSD256,
28618   IX86_BUILTIN_PMINUB256,
28619   IX86_BUILTIN_PMINUW256,
28620   IX86_BUILTIN_PMINUD256,
28621   IX86_BUILTIN_PMOVMSKB256,
28622   IX86_BUILTIN_PMOVSXBW256,
28623   IX86_BUILTIN_PMOVSXBD256,
28624   IX86_BUILTIN_PMOVSXBQ256,
28625   IX86_BUILTIN_PMOVSXWD256,
28626   IX86_BUILTIN_PMOVSXWQ256,
28627   IX86_BUILTIN_PMOVSXDQ256,
28628   IX86_BUILTIN_PMOVZXBW256,
28629   IX86_BUILTIN_PMOVZXBD256,
28630   IX86_BUILTIN_PMOVZXBQ256,
28631   IX86_BUILTIN_PMOVZXWD256,
28632   IX86_BUILTIN_PMOVZXWQ256,
28633   IX86_BUILTIN_PMOVZXDQ256,
28634   IX86_BUILTIN_PMULDQ256,
28635   IX86_BUILTIN_PMULHRSW256,
28636   IX86_BUILTIN_PMULHUW256,
28637   IX86_BUILTIN_PMULHW256,
28638   IX86_BUILTIN_PMULLW256,
28639   IX86_BUILTIN_PMULLD256,
28640   IX86_BUILTIN_PMULUDQ256,
28641   IX86_BUILTIN_POR256,
28642   IX86_BUILTIN_PSADBW256,
28643   IX86_BUILTIN_PSHUFB256,
28644   IX86_BUILTIN_PSHUFD256,
28645   IX86_BUILTIN_PSHUFHW256,
28646   IX86_BUILTIN_PSHUFLW256,
28647   IX86_BUILTIN_PSIGNB256,
28648   IX86_BUILTIN_PSIGNW256,
28649   IX86_BUILTIN_PSIGND256,
28650   IX86_BUILTIN_PSLLDQI256,
28651   IX86_BUILTIN_PSLLWI256,
28652   IX86_BUILTIN_PSLLW256,
28653   IX86_BUILTIN_PSLLDI256,
28654   IX86_BUILTIN_PSLLD256,
28655   IX86_BUILTIN_PSLLQI256,
28656   IX86_BUILTIN_PSLLQ256,
28657   IX86_BUILTIN_PSRAWI256,
28658   IX86_BUILTIN_PSRAW256,
28659   IX86_BUILTIN_PSRADI256,
28660   IX86_BUILTIN_PSRAD256,
28661   IX86_BUILTIN_PSRLDQI256,
28662   IX86_BUILTIN_PSRLWI256,
28663   IX86_BUILTIN_PSRLW256,
28664   IX86_BUILTIN_PSRLDI256,
28665   IX86_BUILTIN_PSRLD256,
28666   IX86_BUILTIN_PSRLQI256,
28667   IX86_BUILTIN_PSRLQ256,
28668   IX86_BUILTIN_PSUBB256,
28669   IX86_BUILTIN_PSUBW256,
28670   IX86_BUILTIN_PSUBD256,
28671   IX86_BUILTIN_PSUBQ256,
28672   IX86_BUILTIN_PSUBSB256,
28673   IX86_BUILTIN_PSUBSW256,
28674   IX86_BUILTIN_PSUBUSB256,
28675   IX86_BUILTIN_PSUBUSW256,
28676   IX86_BUILTIN_PUNPCKHBW256,
28677   IX86_BUILTIN_PUNPCKHWD256,
28678   IX86_BUILTIN_PUNPCKHDQ256,
28679   IX86_BUILTIN_PUNPCKHQDQ256,
28680   IX86_BUILTIN_PUNPCKLBW256,
28681   IX86_BUILTIN_PUNPCKLWD256,
28682   IX86_BUILTIN_PUNPCKLDQ256,
28683   IX86_BUILTIN_PUNPCKLQDQ256,
28684   IX86_BUILTIN_PXOR256,
28685   IX86_BUILTIN_MOVNTDQA256,
28686   IX86_BUILTIN_VBROADCASTSS_PS,
28687   IX86_BUILTIN_VBROADCASTSS_PS256,
28688   IX86_BUILTIN_VBROADCASTSD_PD256,
28689   IX86_BUILTIN_VBROADCASTSI256,
28690   IX86_BUILTIN_PBLENDD256,
28691   IX86_BUILTIN_PBLENDD128,
28692   IX86_BUILTIN_PBROADCASTB256,
28693   IX86_BUILTIN_PBROADCASTW256,
28694   IX86_BUILTIN_PBROADCASTD256,
28695   IX86_BUILTIN_PBROADCASTQ256,
28696   IX86_BUILTIN_PBROADCASTB128,
28697   IX86_BUILTIN_PBROADCASTW128,
28698   IX86_BUILTIN_PBROADCASTD128,
28699   IX86_BUILTIN_PBROADCASTQ128,
28700   IX86_BUILTIN_VPERMVARSI256,
28701   IX86_BUILTIN_VPERMDF256,
28702   IX86_BUILTIN_VPERMVARSF256,
28703   IX86_BUILTIN_VPERMDI256,
28704   IX86_BUILTIN_VPERMTI256,
28705   IX86_BUILTIN_VEXTRACT128I256,
28706   IX86_BUILTIN_VINSERT128I256,
28707   IX86_BUILTIN_MASKLOADD,
28708   IX86_BUILTIN_MASKLOADQ,
28709   IX86_BUILTIN_MASKLOADD256,
28710   IX86_BUILTIN_MASKLOADQ256,
28711   IX86_BUILTIN_MASKSTORED,
28712   IX86_BUILTIN_MASKSTOREQ,
28713   IX86_BUILTIN_MASKSTORED256,
28714   IX86_BUILTIN_MASKSTOREQ256,
28715   IX86_BUILTIN_PSLLVV4DI,
28716   IX86_BUILTIN_PSLLVV2DI,
28717   IX86_BUILTIN_PSLLVV8SI,
28718   IX86_BUILTIN_PSLLVV4SI,
28719   IX86_BUILTIN_PSRAVV8SI,
28720   IX86_BUILTIN_PSRAVV4SI,
28721   IX86_BUILTIN_PSRLVV4DI,
28722   IX86_BUILTIN_PSRLVV2DI,
28723   IX86_BUILTIN_PSRLVV8SI,
28724   IX86_BUILTIN_PSRLVV4SI,
28725
28726   IX86_BUILTIN_GATHERSIV2DF,
28727   IX86_BUILTIN_GATHERSIV4DF,
28728   IX86_BUILTIN_GATHERDIV2DF,
28729   IX86_BUILTIN_GATHERDIV4DF,
28730   IX86_BUILTIN_GATHERSIV4SF,
28731   IX86_BUILTIN_GATHERSIV8SF,
28732   IX86_BUILTIN_GATHERDIV4SF,
28733   IX86_BUILTIN_GATHERDIV8SF,
28734   IX86_BUILTIN_GATHERSIV2DI,
28735   IX86_BUILTIN_GATHERSIV4DI,
28736   IX86_BUILTIN_GATHERDIV2DI,
28737   IX86_BUILTIN_GATHERDIV4DI,
28738   IX86_BUILTIN_GATHERSIV4SI,
28739   IX86_BUILTIN_GATHERSIV8SI,
28740   IX86_BUILTIN_GATHERDIV4SI,
28741   IX86_BUILTIN_GATHERDIV8SI,
28742
28743   /* AVX512F */
28744   IX86_BUILTIN_SI512_SI256,
28745   IX86_BUILTIN_PD512_PD256,
28746   IX86_BUILTIN_PS512_PS256,
28747   IX86_BUILTIN_SI512_SI,
28748   IX86_BUILTIN_PD512_PD,
28749   IX86_BUILTIN_PS512_PS,
28750   IX86_BUILTIN_ADDPD512,
28751   IX86_BUILTIN_ADDPS512,
28752   IX86_BUILTIN_ADDSD_ROUND,
28753   IX86_BUILTIN_ADDSS_ROUND,
28754   IX86_BUILTIN_ALIGND512,
28755   IX86_BUILTIN_ALIGNQ512,
28756   IX86_BUILTIN_BLENDMD512,
28757   IX86_BUILTIN_BLENDMPD512,
28758   IX86_BUILTIN_BLENDMPS512,
28759   IX86_BUILTIN_BLENDMQ512,
28760   IX86_BUILTIN_BROADCASTF32X4_512,
28761   IX86_BUILTIN_BROADCASTF64X4_512,
28762   IX86_BUILTIN_BROADCASTI32X4_512,
28763   IX86_BUILTIN_BROADCASTI64X4_512,
28764   IX86_BUILTIN_BROADCASTSD512,
28765   IX86_BUILTIN_BROADCASTSS512,
28766   IX86_BUILTIN_CMPD512,
28767   IX86_BUILTIN_CMPPD512,
28768   IX86_BUILTIN_CMPPS512,
28769   IX86_BUILTIN_CMPQ512,
28770   IX86_BUILTIN_CMPSD_MASK,
28771   IX86_BUILTIN_CMPSS_MASK,
28772   IX86_BUILTIN_COMIDF,
28773   IX86_BUILTIN_COMISF,
28774   IX86_BUILTIN_COMPRESSPD512,
28775   IX86_BUILTIN_COMPRESSPDSTORE512,
28776   IX86_BUILTIN_COMPRESSPS512,
28777   IX86_BUILTIN_COMPRESSPSSTORE512,
28778   IX86_BUILTIN_CVTDQ2PD512,
28779   IX86_BUILTIN_CVTDQ2PS512,
28780   IX86_BUILTIN_CVTPD2DQ512,
28781   IX86_BUILTIN_CVTPD2PS512,
28782   IX86_BUILTIN_CVTPD2UDQ512,
28783   IX86_BUILTIN_CVTPH2PS512,
28784   IX86_BUILTIN_CVTPS2DQ512,
28785   IX86_BUILTIN_CVTPS2PD512,
28786   IX86_BUILTIN_CVTPS2PH512,
28787   IX86_BUILTIN_CVTPS2UDQ512,
28788   IX86_BUILTIN_CVTSD2SS_ROUND,
28789   IX86_BUILTIN_CVTSI2SD64,
28790   IX86_BUILTIN_CVTSI2SS32,
28791   IX86_BUILTIN_CVTSI2SS64,
28792   IX86_BUILTIN_CVTSS2SD_ROUND,
28793   IX86_BUILTIN_CVTTPD2DQ512,
28794   IX86_BUILTIN_CVTTPD2UDQ512,
28795   IX86_BUILTIN_CVTTPS2DQ512,
28796   IX86_BUILTIN_CVTTPS2UDQ512,
28797   IX86_BUILTIN_CVTUDQ2PD512,
28798   IX86_BUILTIN_CVTUDQ2PS512,
28799   IX86_BUILTIN_CVTUSI2SD32,
28800   IX86_BUILTIN_CVTUSI2SD64,
28801   IX86_BUILTIN_CVTUSI2SS32,
28802   IX86_BUILTIN_CVTUSI2SS64,
28803   IX86_BUILTIN_DIVPD512,
28804   IX86_BUILTIN_DIVPS512,
28805   IX86_BUILTIN_DIVSD_ROUND,
28806   IX86_BUILTIN_DIVSS_ROUND,
28807   IX86_BUILTIN_EXPANDPD512,
28808   IX86_BUILTIN_EXPANDPD512Z,
28809   IX86_BUILTIN_EXPANDPDLOAD512,
28810   IX86_BUILTIN_EXPANDPDLOAD512Z,
28811   IX86_BUILTIN_EXPANDPS512,
28812   IX86_BUILTIN_EXPANDPS512Z,
28813   IX86_BUILTIN_EXPANDPSLOAD512,
28814   IX86_BUILTIN_EXPANDPSLOAD512Z,
28815   IX86_BUILTIN_EXTRACTF32X4,
28816   IX86_BUILTIN_EXTRACTF64X4,
28817   IX86_BUILTIN_EXTRACTI32X4,
28818   IX86_BUILTIN_EXTRACTI64X4,
28819   IX86_BUILTIN_FIXUPIMMPD512_MASK,
28820   IX86_BUILTIN_FIXUPIMMPD512_MASKZ,
28821   IX86_BUILTIN_FIXUPIMMPS512_MASK,
28822   IX86_BUILTIN_FIXUPIMMPS512_MASKZ,
28823   IX86_BUILTIN_FIXUPIMMSD128_MASK,
28824   IX86_BUILTIN_FIXUPIMMSD128_MASKZ,
28825   IX86_BUILTIN_FIXUPIMMSS128_MASK,
28826   IX86_BUILTIN_FIXUPIMMSS128_MASKZ,
28827   IX86_BUILTIN_GETEXPPD512,
28828   IX86_BUILTIN_GETEXPPS512,
28829   IX86_BUILTIN_GETEXPSD128,
28830   IX86_BUILTIN_GETEXPSS128,
28831   IX86_BUILTIN_GETMANTPD512,
28832   IX86_BUILTIN_GETMANTPS512,
28833   IX86_BUILTIN_GETMANTSD128,
28834   IX86_BUILTIN_GETMANTSS128,
28835   IX86_BUILTIN_INSERTF32X4,
28836   IX86_BUILTIN_INSERTF64X4,
28837   IX86_BUILTIN_INSERTI32X4,
28838   IX86_BUILTIN_INSERTI64X4,
28839   IX86_BUILTIN_LOADAPD512,
28840   IX86_BUILTIN_LOADAPS512,
28841   IX86_BUILTIN_LOADDQUDI512,
28842   IX86_BUILTIN_LOADDQUSI512,
28843   IX86_BUILTIN_LOADUPD512,
28844   IX86_BUILTIN_LOADUPS512,
28845   IX86_BUILTIN_MAXPD512,
28846   IX86_BUILTIN_MAXPS512,
28847   IX86_BUILTIN_MAXSD_ROUND,
28848   IX86_BUILTIN_MAXSS_ROUND,
28849   IX86_BUILTIN_MINPD512,
28850   IX86_BUILTIN_MINPS512,
28851   IX86_BUILTIN_MINSD_ROUND,
28852   IX86_BUILTIN_MINSS_ROUND,
28853   IX86_BUILTIN_MOVAPD512,
28854   IX86_BUILTIN_MOVAPS512,
28855   IX86_BUILTIN_MOVDDUP512,
28856   IX86_BUILTIN_MOVDQA32LOAD512,
28857   IX86_BUILTIN_MOVDQA32STORE512,
28858   IX86_BUILTIN_MOVDQA32_512,
28859   IX86_BUILTIN_MOVDQA64LOAD512,
28860   IX86_BUILTIN_MOVDQA64STORE512,
28861   IX86_BUILTIN_MOVDQA64_512,
28862   IX86_BUILTIN_MOVNTDQ512,
28863   IX86_BUILTIN_MOVNTDQA512,
28864   IX86_BUILTIN_MOVNTPD512,
28865   IX86_BUILTIN_MOVNTPS512,
28866   IX86_BUILTIN_MOVSHDUP512,
28867   IX86_BUILTIN_MOVSLDUP512,
28868   IX86_BUILTIN_MULPD512,
28869   IX86_BUILTIN_MULPS512,
28870   IX86_BUILTIN_MULSD_ROUND,
28871   IX86_BUILTIN_MULSS_ROUND,
28872   IX86_BUILTIN_PABSD512,
28873   IX86_BUILTIN_PABSQ512,
28874   IX86_BUILTIN_PADDD512,
28875   IX86_BUILTIN_PADDQ512,
28876   IX86_BUILTIN_PANDD512,
28877   IX86_BUILTIN_PANDND512,
28878   IX86_BUILTIN_PANDNQ512,
28879   IX86_BUILTIN_PANDQ512,
28880   IX86_BUILTIN_PBROADCASTD512,
28881   IX86_BUILTIN_PBROADCASTD512_GPR,
28882   IX86_BUILTIN_PBROADCASTMB512,
28883   IX86_BUILTIN_PBROADCASTMW512,
28884   IX86_BUILTIN_PBROADCASTQ512,
28885   IX86_BUILTIN_PBROADCASTQ512_GPR,
28886   IX86_BUILTIN_PCMPEQD512_MASK,
28887   IX86_BUILTIN_PCMPEQQ512_MASK,
28888   IX86_BUILTIN_PCMPGTD512_MASK,
28889   IX86_BUILTIN_PCMPGTQ512_MASK,
28890   IX86_BUILTIN_PCOMPRESSD512,
28891   IX86_BUILTIN_PCOMPRESSDSTORE512,
28892   IX86_BUILTIN_PCOMPRESSQ512,
28893   IX86_BUILTIN_PCOMPRESSQSTORE512,
28894   IX86_BUILTIN_PEXPANDD512,
28895   IX86_BUILTIN_PEXPANDD512Z,
28896   IX86_BUILTIN_PEXPANDDLOAD512,
28897   IX86_BUILTIN_PEXPANDDLOAD512Z,
28898   IX86_BUILTIN_PEXPANDQ512,
28899   IX86_BUILTIN_PEXPANDQ512Z,
28900   IX86_BUILTIN_PEXPANDQLOAD512,
28901   IX86_BUILTIN_PEXPANDQLOAD512Z,
28902   IX86_BUILTIN_PMAXSD512,
28903   IX86_BUILTIN_PMAXSQ512,
28904   IX86_BUILTIN_PMAXUD512,
28905   IX86_BUILTIN_PMAXUQ512,
28906   IX86_BUILTIN_PMINSD512,
28907   IX86_BUILTIN_PMINSQ512,
28908   IX86_BUILTIN_PMINUD512,
28909   IX86_BUILTIN_PMINUQ512,
28910   IX86_BUILTIN_PMOVDB512,
28911   IX86_BUILTIN_PMOVDB512_MEM,
28912   IX86_BUILTIN_PMOVDW512,
28913   IX86_BUILTIN_PMOVDW512_MEM,
28914   IX86_BUILTIN_PMOVQB512,
28915   IX86_BUILTIN_PMOVQB512_MEM,
28916   IX86_BUILTIN_PMOVQD512,
28917   IX86_BUILTIN_PMOVQD512_MEM,
28918   IX86_BUILTIN_PMOVQW512,
28919   IX86_BUILTIN_PMOVQW512_MEM,
28920   IX86_BUILTIN_PMOVSDB512,
28921   IX86_BUILTIN_PMOVSDB512_MEM,
28922   IX86_BUILTIN_PMOVSDW512,
28923   IX86_BUILTIN_PMOVSDW512_MEM,
28924   IX86_BUILTIN_PMOVSQB512,
28925   IX86_BUILTIN_PMOVSQB512_MEM,
28926   IX86_BUILTIN_PMOVSQD512,
28927   IX86_BUILTIN_PMOVSQD512_MEM,
28928   IX86_BUILTIN_PMOVSQW512,
28929   IX86_BUILTIN_PMOVSQW512_MEM,
28930   IX86_BUILTIN_PMOVSXBD512,
28931   IX86_BUILTIN_PMOVSXBQ512,
28932   IX86_BUILTIN_PMOVSXDQ512,
28933   IX86_BUILTIN_PMOVSXWD512,
28934   IX86_BUILTIN_PMOVSXWQ512,
28935   IX86_BUILTIN_PMOVUSDB512,
28936   IX86_BUILTIN_PMOVUSDB512_MEM,
28937   IX86_BUILTIN_PMOVUSDW512,
28938   IX86_BUILTIN_PMOVUSDW512_MEM,
28939   IX86_BUILTIN_PMOVUSQB512,
28940   IX86_BUILTIN_PMOVUSQB512_MEM,
28941   IX86_BUILTIN_PMOVUSQD512,
28942   IX86_BUILTIN_PMOVUSQD512_MEM,
28943   IX86_BUILTIN_PMOVUSQW512,
28944   IX86_BUILTIN_PMOVUSQW512_MEM,
28945   IX86_BUILTIN_PMOVZXBD512,
28946   IX86_BUILTIN_PMOVZXBQ512,
28947   IX86_BUILTIN_PMOVZXDQ512,
28948   IX86_BUILTIN_PMOVZXWD512,
28949   IX86_BUILTIN_PMOVZXWQ512,
28950   IX86_BUILTIN_PMULDQ512,
28951   IX86_BUILTIN_PMULLD512,
28952   IX86_BUILTIN_PMULUDQ512,
28953   IX86_BUILTIN_PORD512,
28954   IX86_BUILTIN_PORQ512,
28955   IX86_BUILTIN_PROLD512,
28956   IX86_BUILTIN_PROLQ512,
28957   IX86_BUILTIN_PROLVD512,
28958   IX86_BUILTIN_PROLVQ512,
28959   IX86_BUILTIN_PRORD512,
28960   IX86_BUILTIN_PRORQ512,
28961   IX86_BUILTIN_PRORVD512,
28962   IX86_BUILTIN_PRORVQ512,
28963   IX86_BUILTIN_PSHUFD512,
28964   IX86_BUILTIN_PSLLD512,
28965   IX86_BUILTIN_PSLLDI512,
28966   IX86_BUILTIN_PSLLQ512,
28967   IX86_BUILTIN_PSLLQI512,
28968   IX86_BUILTIN_PSLLVV16SI,
28969   IX86_BUILTIN_PSLLVV8DI,
28970   IX86_BUILTIN_PSRAD512,
28971   IX86_BUILTIN_PSRADI512,
28972   IX86_BUILTIN_PSRAQ512,
28973   IX86_BUILTIN_PSRAQI512,
28974   IX86_BUILTIN_PSRAVV16SI,
28975   IX86_BUILTIN_PSRAVV8DI,
28976   IX86_BUILTIN_PSRLD512,
28977   IX86_BUILTIN_PSRLDI512,
28978   IX86_BUILTIN_PSRLQ512,
28979   IX86_BUILTIN_PSRLQI512,
28980   IX86_BUILTIN_PSRLVV16SI,
28981   IX86_BUILTIN_PSRLVV8DI,
28982   IX86_BUILTIN_PSUBD512,
28983   IX86_BUILTIN_PSUBQ512,
28984   IX86_BUILTIN_PTESTMD512,
28985   IX86_BUILTIN_PTESTMQ512,
28986   IX86_BUILTIN_PTESTNMD512,
28987   IX86_BUILTIN_PTESTNMQ512,
28988   IX86_BUILTIN_PUNPCKHDQ512,
28989   IX86_BUILTIN_PUNPCKHQDQ512,
28990   IX86_BUILTIN_PUNPCKLDQ512,
28991   IX86_BUILTIN_PUNPCKLQDQ512,
28992   IX86_BUILTIN_PXORD512,
28993   IX86_BUILTIN_PXORQ512,
28994   IX86_BUILTIN_RCP14PD512,
28995   IX86_BUILTIN_RCP14PS512,
28996   IX86_BUILTIN_RCP14SD,
28997   IX86_BUILTIN_RCP14SS,
28998   IX86_BUILTIN_RNDSCALEPD,
28999   IX86_BUILTIN_RNDSCALEPS,
29000   IX86_BUILTIN_RNDSCALESD,
29001   IX86_BUILTIN_RNDSCALESS,
29002   IX86_BUILTIN_RSQRT14PD512,
29003   IX86_BUILTIN_RSQRT14PS512,
29004   IX86_BUILTIN_RSQRT14SD,
29005   IX86_BUILTIN_RSQRT14SS,
29006   IX86_BUILTIN_SCALEFPD512,
29007   IX86_BUILTIN_SCALEFPS512,
29008   IX86_BUILTIN_SCALEFSD,
29009   IX86_BUILTIN_SCALEFSS,
29010   IX86_BUILTIN_SHUFPD512,
29011   IX86_BUILTIN_SHUFPS512,
29012   IX86_BUILTIN_SHUF_F32x4,
29013   IX86_BUILTIN_SHUF_F64x2,
29014   IX86_BUILTIN_SHUF_I32x4,
29015   IX86_BUILTIN_SHUF_I64x2,
29016   IX86_BUILTIN_SQRTPD512,
29017   IX86_BUILTIN_SQRTPD512_MASK,
29018   IX86_BUILTIN_SQRTPS512_MASK,
29019   IX86_BUILTIN_SQRTPS_NR512,
29020   IX86_BUILTIN_SQRTSD_ROUND,
29021   IX86_BUILTIN_SQRTSS_ROUND,
29022   IX86_BUILTIN_STOREAPD512,
29023   IX86_BUILTIN_STOREAPS512,
29024   IX86_BUILTIN_STOREDQUDI512,
29025   IX86_BUILTIN_STOREDQUSI512,
29026   IX86_BUILTIN_STOREUPD512,
29027   IX86_BUILTIN_STOREUPS512,
29028   IX86_BUILTIN_SUBPD512,
29029   IX86_BUILTIN_SUBPS512,
29030   IX86_BUILTIN_SUBSD_ROUND,
29031   IX86_BUILTIN_SUBSS_ROUND,
29032   IX86_BUILTIN_UCMPD512,
29033   IX86_BUILTIN_UCMPQ512,
29034   IX86_BUILTIN_UNPCKHPD512,
29035   IX86_BUILTIN_UNPCKHPS512,
29036   IX86_BUILTIN_UNPCKLPD512,
29037   IX86_BUILTIN_UNPCKLPS512,
29038   IX86_BUILTIN_VCVTSD2SI32,
29039   IX86_BUILTIN_VCVTSD2SI64,
29040   IX86_BUILTIN_VCVTSD2USI32,
29041   IX86_BUILTIN_VCVTSD2USI64,
29042   IX86_BUILTIN_VCVTSS2SI32,
29043   IX86_BUILTIN_VCVTSS2SI64,
29044   IX86_BUILTIN_VCVTSS2USI32,
29045   IX86_BUILTIN_VCVTSS2USI64,
29046   IX86_BUILTIN_VCVTTSD2SI32,
29047   IX86_BUILTIN_VCVTTSD2SI64,
29048   IX86_BUILTIN_VCVTTSD2USI32,
29049   IX86_BUILTIN_VCVTTSD2USI64,
29050   IX86_BUILTIN_VCVTTSS2SI32,
29051   IX86_BUILTIN_VCVTTSS2SI64,
29052   IX86_BUILTIN_VCVTTSS2USI32,
29053   IX86_BUILTIN_VCVTTSS2USI64,
29054   IX86_BUILTIN_VFMADDPD512_MASK,
29055   IX86_BUILTIN_VFMADDPD512_MASK3,
29056   IX86_BUILTIN_VFMADDPD512_MASKZ,
29057   IX86_BUILTIN_VFMADDPS512_MASK,
29058   IX86_BUILTIN_VFMADDPS512_MASK3,
29059   IX86_BUILTIN_VFMADDPS512_MASKZ,
29060   IX86_BUILTIN_VFMADDSD3_ROUND,
29061   IX86_BUILTIN_VFMADDSS3_ROUND,
29062   IX86_BUILTIN_VFMADDSUBPD512_MASK,
29063   IX86_BUILTIN_VFMADDSUBPD512_MASK3,
29064   IX86_BUILTIN_VFMADDSUBPD512_MASKZ,
29065   IX86_BUILTIN_VFMADDSUBPS512_MASK,
29066   IX86_BUILTIN_VFMADDSUBPS512_MASK3,
29067   IX86_BUILTIN_VFMADDSUBPS512_MASKZ,
29068   IX86_BUILTIN_VFMSUBADDPD512_MASK3,
29069   IX86_BUILTIN_VFMSUBADDPS512_MASK3,
29070   IX86_BUILTIN_VFMSUBPD512_MASK3,
29071   IX86_BUILTIN_VFMSUBPS512_MASK3,
29072   IX86_BUILTIN_VFMSUBSD3_MASK3,
29073   IX86_BUILTIN_VFMSUBSS3_MASK3,
29074   IX86_BUILTIN_VFNMADDPD512_MASK,
29075   IX86_BUILTIN_VFNMADDPS512_MASK,
29076   IX86_BUILTIN_VFNMSUBPD512_MASK,
29077   IX86_BUILTIN_VFNMSUBPD512_MASK3,
29078   IX86_BUILTIN_VFNMSUBPS512_MASK,
29079   IX86_BUILTIN_VFNMSUBPS512_MASK3,
29080   IX86_BUILTIN_VPCLZCNTD512,
29081   IX86_BUILTIN_VPCLZCNTQ512,
29082   IX86_BUILTIN_VPCONFLICTD512,
29083   IX86_BUILTIN_VPCONFLICTQ512,
29084   IX86_BUILTIN_VPERMDF512,
29085   IX86_BUILTIN_VPERMDI512,
29086   IX86_BUILTIN_VPERMI2VARD512,
29087   IX86_BUILTIN_VPERMI2VARPD512,
29088   IX86_BUILTIN_VPERMI2VARPS512,
29089   IX86_BUILTIN_VPERMI2VARQ512,
29090   IX86_BUILTIN_VPERMILPD512,
29091   IX86_BUILTIN_VPERMILPS512,
29092   IX86_BUILTIN_VPERMILVARPD512,
29093   IX86_BUILTIN_VPERMILVARPS512,
29094   IX86_BUILTIN_VPERMT2VARD512,
29095   IX86_BUILTIN_VPERMT2VARD512_MASKZ,
29096   IX86_BUILTIN_VPERMT2VARPD512,
29097   IX86_BUILTIN_VPERMT2VARPD512_MASKZ,
29098   IX86_BUILTIN_VPERMT2VARPS512,
29099   IX86_BUILTIN_VPERMT2VARPS512_MASKZ,
29100   IX86_BUILTIN_VPERMT2VARQ512,
29101   IX86_BUILTIN_VPERMT2VARQ512_MASKZ,
29102   IX86_BUILTIN_VPERMVARDF512,
29103   IX86_BUILTIN_VPERMVARDI512,
29104   IX86_BUILTIN_VPERMVARSF512,
29105   IX86_BUILTIN_VPERMVARSI512,
29106   IX86_BUILTIN_VTERNLOGD512_MASK,
29107   IX86_BUILTIN_VTERNLOGD512_MASKZ,
29108   IX86_BUILTIN_VTERNLOGQ512_MASK,
29109   IX86_BUILTIN_VTERNLOGQ512_MASKZ,
29110
29111   /* Mask arithmetic operations */
29112   IX86_BUILTIN_KAND16,
29113   IX86_BUILTIN_KANDN16,
29114   IX86_BUILTIN_KNOT16,
29115   IX86_BUILTIN_KOR16,
29116   IX86_BUILTIN_KORTESTC16,
29117   IX86_BUILTIN_KORTESTZ16,
29118   IX86_BUILTIN_KUNPCKBW,
29119   IX86_BUILTIN_KXNOR16,
29120   IX86_BUILTIN_KXOR16,
29121   IX86_BUILTIN_KMOV16,
29122
29123   /* AVX512VL.  */
29124   IX86_BUILTIN_PMOVUSQD256_MEM,
29125   IX86_BUILTIN_PMOVUSQD128_MEM,
29126   IX86_BUILTIN_PMOVSQD256_MEM,
29127   IX86_BUILTIN_PMOVSQD128_MEM,
29128   IX86_BUILTIN_PMOVQD256_MEM,
29129   IX86_BUILTIN_PMOVQD128_MEM,
29130   IX86_BUILTIN_PMOVUSQW256_MEM,
29131   IX86_BUILTIN_PMOVUSQW128_MEM,
29132   IX86_BUILTIN_PMOVSQW256_MEM,
29133   IX86_BUILTIN_PMOVSQW128_MEM,
29134   IX86_BUILTIN_PMOVQW256_MEM,
29135   IX86_BUILTIN_PMOVQW128_MEM,
29136   IX86_BUILTIN_PMOVUSQB256_MEM,
29137   IX86_BUILTIN_PMOVUSQB128_MEM,
29138   IX86_BUILTIN_PMOVSQB256_MEM,
29139   IX86_BUILTIN_PMOVSQB128_MEM,
29140   IX86_BUILTIN_PMOVQB256_MEM,
29141   IX86_BUILTIN_PMOVQB128_MEM,
29142   IX86_BUILTIN_PMOVUSDW256_MEM,
29143   IX86_BUILTIN_PMOVUSDW128_MEM,
29144   IX86_BUILTIN_PMOVSDW256_MEM,
29145   IX86_BUILTIN_PMOVSDW128_MEM,
29146   IX86_BUILTIN_PMOVDW256_MEM,
29147   IX86_BUILTIN_PMOVDW128_MEM,
29148   IX86_BUILTIN_PMOVUSDB256_MEM,
29149   IX86_BUILTIN_PMOVUSDB128_MEM,
29150   IX86_BUILTIN_PMOVSDB256_MEM,
29151   IX86_BUILTIN_PMOVSDB128_MEM,
29152   IX86_BUILTIN_PMOVDB256_MEM,
29153   IX86_BUILTIN_PMOVDB128_MEM,
29154   IX86_BUILTIN_MOVDQA64LOAD256_MASK,
29155   IX86_BUILTIN_MOVDQA64LOAD128_MASK,
29156   IX86_BUILTIN_MOVDQA32LOAD256_MASK,
29157   IX86_BUILTIN_MOVDQA32LOAD128_MASK,
29158   IX86_BUILTIN_MOVDQA64STORE256_MASK,
29159   IX86_BUILTIN_MOVDQA64STORE128_MASK,
29160   IX86_BUILTIN_MOVDQA32STORE256_MASK,
29161   IX86_BUILTIN_MOVDQA32STORE128_MASK,
29162   IX86_BUILTIN_LOADAPD256_MASK,
29163   IX86_BUILTIN_LOADAPD128_MASK,
29164   IX86_BUILTIN_LOADAPS256_MASK,
29165   IX86_BUILTIN_LOADAPS128_MASK,
29166   IX86_BUILTIN_STOREAPD256_MASK,
29167   IX86_BUILTIN_STOREAPD128_MASK,
29168   IX86_BUILTIN_STOREAPS256_MASK,
29169   IX86_BUILTIN_STOREAPS128_MASK,
29170   IX86_BUILTIN_LOADUPD256_MASK,
29171   IX86_BUILTIN_LOADUPD128_MASK,
29172   IX86_BUILTIN_LOADUPS256_MASK,
29173   IX86_BUILTIN_LOADUPS128_MASK,
29174   IX86_BUILTIN_STOREUPD256_MASK,
29175   IX86_BUILTIN_STOREUPD128_MASK,
29176   IX86_BUILTIN_STOREUPS256_MASK,
29177   IX86_BUILTIN_STOREUPS128_MASK,
29178   IX86_BUILTIN_LOADDQUDI256_MASK,
29179   IX86_BUILTIN_LOADDQUDI128_MASK,
29180   IX86_BUILTIN_LOADDQUSI256_MASK,
29181   IX86_BUILTIN_LOADDQUSI128_MASK,
29182   IX86_BUILTIN_LOADDQUHI256_MASK,
29183   IX86_BUILTIN_LOADDQUHI128_MASK,
29184   IX86_BUILTIN_LOADDQUQI256_MASK,
29185   IX86_BUILTIN_LOADDQUQI128_MASK,
29186   IX86_BUILTIN_STOREDQUDI256_MASK,
29187   IX86_BUILTIN_STOREDQUDI128_MASK,
29188   IX86_BUILTIN_STOREDQUSI256_MASK,
29189   IX86_BUILTIN_STOREDQUSI128_MASK,
29190   IX86_BUILTIN_STOREDQUHI256_MASK,
29191   IX86_BUILTIN_STOREDQUHI128_MASK,
29192   IX86_BUILTIN_STOREDQUQI256_MASK,
29193   IX86_BUILTIN_STOREDQUQI128_MASK,
29194   IX86_BUILTIN_COMPRESSPDSTORE256,
29195   IX86_BUILTIN_COMPRESSPDSTORE128,
29196   IX86_BUILTIN_COMPRESSPSSTORE256,
29197   IX86_BUILTIN_COMPRESSPSSTORE128,
29198   IX86_BUILTIN_PCOMPRESSQSTORE256,
29199   IX86_BUILTIN_PCOMPRESSQSTORE128,
29200   IX86_BUILTIN_PCOMPRESSDSTORE256,
29201   IX86_BUILTIN_PCOMPRESSDSTORE128,
29202   IX86_BUILTIN_EXPANDPDLOAD256,
29203   IX86_BUILTIN_EXPANDPDLOAD128,
29204   IX86_BUILTIN_EXPANDPSLOAD256,
29205   IX86_BUILTIN_EXPANDPSLOAD128,
29206   IX86_BUILTIN_PEXPANDQLOAD256,
29207   IX86_BUILTIN_PEXPANDQLOAD128,
29208   IX86_BUILTIN_PEXPANDDLOAD256,
29209   IX86_BUILTIN_PEXPANDDLOAD128,
29210   IX86_BUILTIN_EXPANDPDLOAD256Z,
29211   IX86_BUILTIN_EXPANDPDLOAD128Z,
29212   IX86_BUILTIN_EXPANDPSLOAD256Z,
29213   IX86_BUILTIN_EXPANDPSLOAD128Z,
29214   IX86_BUILTIN_PEXPANDQLOAD256Z,
29215   IX86_BUILTIN_PEXPANDQLOAD128Z,
29216   IX86_BUILTIN_PEXPANDDLOAD256Z,
29217   IX86_BUILTIN_PEXPANDDLOAD128Z,
29218   IX86_BUILTIN_PALIGNR256_MASK,
29219   IX86_BUILTIN_PALIGNR128_MASK,
29220   IX86_BUILTIN_MOVDQA64_256_MASK,
29221   IX86_BUILTIN_MOVDQA64_128_MASK,
29222   IX86_BUILTIN_MOVDQA32_256_MASK,
29223   IX86_BUILTIN_MOVDQA32_128_MASK,
29224   IX86_BUILTIN_MOVAPD256_MASK,
29225   IX86_BUILTIN_MOVAPD128_MASK,
29226   IX86_BUILTIN_MOVAPS256_MASK,
29227   IX86_BUILTIN_MOVAPS128_MASK,
29228   IX86_BUILTIN_MOVDQUHI256_MASK,
29229   IX86_BUILTIN_MOVDQUHI128_MASK,
29230   IX86_BUILTIN_MOVDQUQI256_MASK,
29231   IX86_BUILTIN_MOVDQUQI128_MASK,
29232   IX86_BUILTIN_MINPS128_MASK,
29233   IX86_BUILTIN_MAXPS128_MASK,
29234   IX86_BUILTIN_MINPD128_MASK,
29235   IX86_BUILTIN_MAXPD128_MASK,
29236   IX86_BUILTIN_MAXPD256_MASK,
29237   IX86_BUILTIN_MAXPS256_MASK,
29238   IX86_BUILTIN_MINPD256_MASK,
29239   IX86_BUILTIN_MINPS256_MASK,
29240   IX86_BUILTIN_MULPS128_MASK,
29241   IX86_BUILTIN_DIVPS128_MASK,
29242   IX86_BUILTIN_MULPD128_MASK,
29243   IX86_BUILTIN_DIVPD128_MASK,
29244   IX86_BUILTIN_DIVPD256_MASK,
29245   IX86_BUILTIN_DIVPS256_MASK,
29246   IX86_BUILTIN_MULPD256_MASK,
29247   IX86_BUILTIN_MULPS256_MASK,
29248   IX86_BUILTIN_ADDPD128_MASK,
29249   IX86_BUILTIN_ADDPD256_MASK,
29250   IX86_BUILTIN_ADDPS128_MASK,
29251   IX86_BUILTIN_ADDPS256_MASK,
29252   IX86_BUILTIN_SUBPD128_MASK,
29253   IX86_BUILTIN_SUBPD256_MASK,
29254   IX86_BUILTIN_SUBPS128_MASK,
29255   IX86_BUILTIN_SUBPS256_MASK,
29256   IX86_BUILTIN_XORPD256_MASK,
29257   IX86_BUILTIN_XORPD128_MASK,
29258   IX86_BUILTIN_XORPS256_MASK,
29259   IX86_BUILTIN_XORPS128_MASK,
29260   IX86_BUILTIN_ORPD256_MASK,
29261   IX86_BUILTIN_ORPD128_MASK,
29262   IX86_BUILTIN_ORPS256_MASK,
29263   IX86_BUILTIN_ORPS128_MASK,
29264   IX86_BUILTIN_BROADCASTF32x2_256,
29265   IX86_BUILTIN_BROADCASTI32x2_256,
29266   IX86_BUILTIN_BROADCASTI32x2_128,
29267   IX86_BUILTIN_BROADCASTF64X2_256,
29268   IX86_BUILTIN_BROADCASTI64X2_256,
29269   IX86_BUILTIN_BROADCASTF32X4_256,
29270   IX86_BUILTIN_BROADCASTI32X4_256,
29271   IX86_BUILTIN_EXTRACTF32X4_256,
29272   IX86_BUILTIN_EXTRACTI32X4_256,
29273   IX86_BUILTIN_DBPSADBW256,
29274   IX86_BUILTIN_DBPSADBW128,
29275   IX86_BUILTIN_CVTTPD2QQ256,
29276   IX86_BUILTIN_CVTTPD2QQ128,
29277   IX86_BUILTIN_CVTTPD2UQQ256,
29278   IX86_BUILTIN_CVTTPD2UQQ128,
29279   IX86_BUILTIN_CVTPD2QQ256,
29280   IX86_BUILTIN_CVTPD2QQ128,
29281   IX86_BUILTIN_CVTPD2UQQ256,
29282   IX86_BUILTIN_CVTPD2UQQ128,
29283   IX86_BUILTIN_CVTPD2UDQ256_MASK,
29284   IX86_BUILTIN_CVTPD2UDQ128_MASK,
29285   IX86_BUILTIN_CVTTPS2QQ256,
29286   IX86_BUILTIN_CVTTPS2QQ128,
29287   IX86_BUILTIN_CVTTPS2UQQ256,
29288   IX86_BUILTIN_CVTTPS2UQQ128,
29289   IX86_BUILTIN_CVTTPS2DQ256_MASK,
29290   IX86_BUILTIN_CVTTPS2DQ128_MASK,
29291   IX86_BUILTIN_CVTTPS2UDQ256,
29292   IX86_BUILTIN_CVTTPS2UDQ128,
29293   IX86_BUILTIN_CVTTPD2DQ256_MASK,
29294   IX86_BUILTIN_CVTTPD2DQ128_MASK,
29295   IX86_BUILTIN_CVTTPD2UDQ256_MASK,
29296   IX86_BUILTIN_CVTTPD2UDQ128_MASK,
29297   IX86_BUILTIN_CVTPD2DQ256_MASK,
29298   IX86_BUILTIN_CVTPD2DQ128_MASK,
29299   IX86_BUILTIN_CVTDQ2PD256_MASK,
29300   IX86_BUILTIN_CVTDQ2PD128_MASK,
29301   IX86_BUILTIN_CVTUDQ2PD256_MASK,
29302   IX86_BUILTIN_CVTUDQ2PD128_MASK,
29303   IX86_BUILTIN_CVTDQ2PS256_MASK,
29304   IX86_BUILTIN_CVTDQ2PS128_MASK,
29305   IX86_BUILTIN_CVTUDQ2PS256_MASK,
29306   IX86_BUILTIN_CVTUDQ2PS128_MASK,
29307   IX86_BUILTIN_CVTPS2PD256_MASK,
29308   IX86_BUILTIN_CVTPS2PD128_MASK,
29309   IX86_BUILTIN_PBROADCASTB256_MASK,
29310   IX86_BUILTIN_PBROADCASTB256_GPR_MASK,
29311   IX86_BUILTIN_PBROADCASTB128_MASK,
29312   IX86_BUILTIN_PBROADCASTB128_GPR_MASK,
29313   IX86_BUILTIN_PBROADCASTW256_MASK,
29314   IX86_BUILTIN_PBROADCASTW256_GPR_MASK,
29315   IX86_BUILTIN_PBROADCASTW128_MASK,
29316   IX86_BUILTIN_PBROADCASTW128_GPR_MASK,
29317   IX86_BUILTIN_PBROADCASTD256_MASK,
29318   IX86_BUILTIN_PBROADCASTD256_GPR_MASK,
29319   IX86_BUILTIN_PBROADCASTD128_MASK,
29320   IX86_BUILTIN_PBROADCASTD128_GPR_MASK,
29321   IX86_BUILTIN_PBROADCASTQ256_MASK,
29322   IX86_BUILTIN_PBROADCASTQ256_GPR_MASK,
29323   IX86_BUILTIN_PBROADCASTQ128_MASK,
29324   IX86_BUILTIN_PBROADCASTQ128_GPR_MASK,
29325   IX86_BUILTIN_BROADCASTSS256,
29326   IX86_BUILTIN_BROADCASTSS128,
29327   IX86_BUILTIN_BROADCASTSD256,
29328   IX86_BUILTIN_EXTRACTF64X2_256,
29329   IX86_BUILTIN_EXTRACTI64X2_256,
29330   IX86_BUILTIN_INSERTF32X4_256,
29331   IX86_BUILTIN_INSERTI32X4_256,
29332   IX86_BUILTIN_PMOVSXBW256_MASK,
29333   IX86_BUILTIN_PMOVSXBW128_MASK,
29334   IX86_BUILTIN_PMOVSXBD256_MASK,
29335   IX86_BUILTIN_PMOVSXBD128_MASK,
29336   IX86_BUILTIN_PMOVSXBQ256_MASK,
29337   IX86_BUILTIN_PMOVSXBQ128_MASK,
29338   IX86_BUILTIN_PMOVSXWD256_MASK,
29339   IX86_BUILTIN_PMOVSXWD128_MASK,
29340   IX86_BUILTIN_PMOVSXWQ256_MASK,
29341   IX86_BUILTIN_PMOVSXWQ128_MASK,
29342   IX86_BUILTIN_PMOVSXDQ256_MASK,
29343   IX86_BUILTIN_PMOVSXDQ128_MASK,
29344   IX86_BUILTIN_PMOVZXBW256_MASK,
29345   IX86_BUILTIN_PMOVZXBW128_MASK,
29346   IX86_BUILTIN_PMOVZXBD256_MASK,
29347   IX86_BUILTIN_PMOVZXBD128_MASK,
29348   IX86_BUILTIN_PMOVZXBQ256_MASK,
29349   IX86_BUILTIN_PMOVZXBQ128_MASK,
29350   IX86_BUILTIN_PMOVZXWD256_MASK,
29351   IX86_BUILTIN_PMOVZXWD128_MASK,
29352   IX86_BUILTIN_PMOVZXWQ256_MASK,
29353   IX86_BUILTIN_PMOVZXWQ128_MASK,
29354   IX86_BUILTIN_PMOVZXDQ256_MASK,
29355   IX86_BUILTIN_PMOVZXDQ128_MASK,
29356   IX86_BUILTIN_REDUCEPD256_MASK,
29357   IX86_BUILTIN_REDUCEPD128_MASK,
29358   IX86_BUILTIN_REDUCEPS256_MASK,
29359   IX86_BUILTIN_REDUCEPS128_MASK,
29360   IX86_BUILTIN_REDUCESD_MASK,
29361   IX86_BUILTIN_REDUCESS_MASK,
29362   IX86_BUILTIN_VPERMVARHI256_MASK,
29363   IX86_BUILTIN_VPERMVARHI128_MASK,
29364   IX86_BUILTIN_VPERMT2VARHI256,
29365   IX86_BUILTIN_VPERMT2VARHI256_MASKZ,
29366   IX86_BUILTIN_VPERMT2VARHI128,
29367   IX86_BUILTIN_VPERMT2VARHI128_MASKZ,
29368   IX86_BUILTIN_VPERMI2VARHI256,
29369   IX86_BUILTIN_VPERMI2VARHI128,
29370   IX86_BUILTIN_RCP14PD256,
29371   IX86_BUILTIN_RCP14PD128,
29372   IX86_BUILTIN_RCP14PS256,
29373   IX86_BUILTIN_RCP14PS128,
29374   IX86_BUILTIN_RSQRT14PD256_MASK,
29375   IX86_BUILTIN_RSQRT14PD128_MASK,
29376   IX86_BUILTIN_RSQRT14PS256_MASK,
29377   IX86_BUILTIN_RSQRT14PS128_MASK,
29378   IX86_BUILTIN_SQRTPD256_MASK,
29379   IX86_BUILTIN_SQRTPD128_MASK,
29380   IX86_BUILTIN_SQRTPS256_MASK,
29381   IX86_BUILTIN_SQRTPS128_MASK,
29382   IX86_BUILTIN_PADDB128_MASK,
29383   IX86_BUILTIN_PADDW128_MASK,
29384   IX86_BUILTIN_PADDD128_MASK,
29385   IX86_BUILTIN_PADDQ128_MASK,
29386   IX86_BUILTIN_PSUBB128_MASK,
29387   IX86_BUILTIN_PSUBW128_MASK,
29388   IX86_BUILTIN_PSUBD128_MASK,
29389   IX86_BUILTIN_PSUBQ128_MASK,
29390   IX86_BUILTIN_PADDSB128_MASK,
29391   IX86_BUILTIN_PADDSW128_MASK,
29392   IX86_BUILTIN_PSUBSB128_MASK,
29393   IX86_BUILTIN_PSUBSW128_MASK,
29394   IX86_BUILTIN_PADDUSB128_MASK,
29395   IX86_BUILTIN_PADDUSW128_MASK,
29396   IX86_BUILTIN_PSUBUSB128_MASK,
29397   IX86_BUILTIN_PSUBUSW128_MASK,
29398   IX86_BUILTIN_PADDB256_MASK,
29399   IX86_BUILTIN_PADDW256_MASK,
29400   IX86_BUILTIN_PADDD256_MASK,
29401   IX86_BUILTIN_PADDQ256_MASK,
29402   IX86_BUILTIN_PADDSB256_MASK,
29403   IX86_BUILTIN_PADDSW256_MASK,
29404   IX86_BUILTIN_PADDUSB256_MASK,
29405   IX86_BUILTIN_PADDUSW256_MASK,
29406   IX86_BUILTIN_PSUBB256_MASK,
29407   IX86_BUILTIN_PSUBW256_MASK,
29408   IX86_BUILTIN_PSUBD256_MASK,
29409   IX86_BUILTIN_PSUBQ256_MASK,
29410   IX86_BUILTIN_PSUBSB256_MASK,
29411   IX86_BUILTIN_PSUBSW256_MASK,
29412   IX86_BUILTIN_PSUBUSB256_MASK,
29413   IX86_BUILTIN_PSUBUSW256_MASK,
29414   IX86_BUILTIN_SHUF_F64x2_256,
29415   IX86_BUILTIN_SHUF_I64x2_256,
29416   IX86_BUILTIN_SHUF_I32x4_256,
29417   IX86_BUILTIN_SHUF_F32x4_256,
29418   IX86_BUILTIN_PMOVWB128,
29419   IX86_BUILTIN_PMOVWB256,
29420   IX86_BUILTIN_PMOVSWB128,
29421   IX86_BUILTIN_PMOVSWB256,
29422   IX86_BUILTIN_PMOVUSWB128,
29423   IX86_BUILTIN_PMOVUSWB256,
29424   IX86_BUILTIN_PMOVDB128,
29425   IX86_BUILTIN_PMOVDB256,
29426   IX86_BUILTIN_PMOVSDB128,
29427   IX86_BUILTIN_PMOVSDB256,
29428   IX86_BUILTIN_PMOVUSDB128,
29429   IX86_BUILTIN_PMOVUSDB256,
29430   IX86_BUILTIN_PMOVDW128,
29431   IX86_BUILTIN_PMOVDW256,
29432   IX86_BUILTIN_PMOVSDW128,
29433   IX86_BUILTIN_PMOVSDW256,
29434   IX86_BUILTIN_PMOVUSDW128,
29435   IX86_BUILTIN_PMOVUSDW256,
29436   IX86_BUILTIN_PMOVQB128,
29437   IX86_BUILTIN_PMOVQB256,
29438   IX86_BUILTIN_PMOVSQB128,
29439   IX86_BUILTIN_PMOVSQB256,
29440   IX86_BUILTIN_PMOVUSQB128,
29441   IX86_BUILTIN_PMOVUSQB256,
29442   IX86_BUILTIN_PMOVQW128,
29443   IX86_BUILTIN_PMOVQW256,
29444   IX86_BUILTIN_PMOVSQW128,
29445   IX86_BUILTIN_PMOVSQW256,
29446   IX86_BUILTIN_PMOVUSQW128,
29447   IX86_BUILTIN_PMOVUSQW256,
29448   IX86_BUILTIN_PMOVQD128,
29449   IX86_BUILTIN_PMOVQD256,
29450   IX86_BUILTIN_PMOVSQD128,
29451   IX86_BUILTIN_PMOVSQD256,
29452   IX86_BUILTIN_PMOVUSQD128,
29453   IX86_BUILTIN_PMOVUSQD256,
29454   IX86_BUILTIN_RANGEPD256,
29455   IX86_BUILTIN_RANGEPD128,
29456   IX86_BUILTIN_RANGEPS256,
29457   IX86_BUILTIN_RANGEPS128,
29458   IX86_BUILTIN_GETEXPPS256,
29459   IX86_BUILTIN_GETEXPPD256,
29460   IX86_BUILTIN_GETEXPPS128,
29461   IX86_BUILTIN_GETEXPPD128,
29462   IX86_BUILTIN_FIXUPIMMPD256_MASK,
29463   IX86_BUILTIN_FIXUPIMMPD256_MASKZ,
29464   IX86_BUILTIN_FIXUPIMMPS256_MASK,
29465   IX86_BUILTIN_FIXUPIMMPS256_MASKZ,
29466   IX86_BUILTIN_FIXUPIMMPD128_MASK,
29467   IX86_BUILTIN_FIXUPIMMPD128_MASKZ,
29468   IX86_BUILTIN_FIXUPIMMPS128_MASK,
29469   IX86_BUILTIN_FIXUPIMMPS128_MASKZ,
29470   IX86_BUILTIN_PABSQ256,
29471   IX86_BUILTIN_PABSQ128,
29472   IX86_BUILTIN_PABSD256_MASK,
29473   IX86_BUILTIN_PABSD128_MASK,
29474   IX86_BUILTIN_PMULHRSW256_MASK,
29475   IX86_BUILTIN_PMULHRSW128_MASK,
29476   IX86_BUILTIN_PMULHUW128_MASK,
29477   IX86_BUILTIN_PMULHUW256_MASK,
29478   IX86_BUILTIN_PMULHW256_MASK,
29479   IX86_BUILTIN_PMULHW128_MASK,
29480   IX86_BUILTIN_PMULLW256_MASK,
29481   IX86_BUILTIN_PMULLW128_MASK,
29482   IX86_BUILTIN_PMULLQ256,
29483   IX86_BUILTIN_PMULLQ128,
29484   IX86_BUILTIN_ANDPD256_MASK,
29485   IX86_BUILTIN_ANDPD128_MASK,
29486   IX86_BUILTIN_ANDPS256_MASK,
29487   IX86_BUILTIN_ANDPS128_MASK,
29488   IX86_BUILTIN_ANDNPD256_MASK,
29489   IX86_BUILTIN_ANDNPD128_MASK,
29490   IX86_BUILTIN_ANDNPS256_MASK,
29491   IX86_BUILTIN_ANDNPS128_MASK,
29492   IX86_BUILTIN_PSLLWI128_MASK,
29493   IX86_BUILTIN_PSLLDI128_MASK,
29494   IX86_BUILTIN_PSLLQI128_MASK,
29495   IX86_BUILTIN_PSLLW128_MASK,
29496   IX86_BUILTIN_PSLLD128_MASK,
29497   IX86_BUILTIN_PSLLQ128_MASK,
29498   IX86_BUILTIN_PSLLWI256_MASK ,
29499   IX86_BUILTIN_PSLLW256_MASK,
29500   IX86_BUILTIN_PSLLDI256_MASK,
29501   IX86_BUILTIN_PSLLD256_MASK,
29502   IX86_BUILTIN_PSLLQI256_MASK,
29503   IX86_BUILTIN_PSLLQ256_MASK,
29504   IX86_BUILTIN_PSRADI128_MASK,
29505   IX86_BUILTIN_PSRAD128_MASK,
29506   IX86_BUILTIN_PSRADI256_MASK,
29507   IX86_BUILTIN_PSRAD256_MASK,
29508   IX86_BUILTIN_PSRAQI128_MASK,
29509   IX86_BUILTIN_PSRAQ128_MASK,
29510   IX86_BUILTIN_PSRAQI256_MASK,
29511   IX86_BUILTIN_PSRAQ256_MASK,
29512   IX86_BUILTIN_PANDD256,
29513   IX86_BUILTIN_PANDD128,
29514   IX86_BUILTIN_PSRLDI128_MASK,
29515   IX86_BUILTIN_PSRLD128_MASK,
29516   IX86_BUILTIN_PSRLDI256_MASK,
29517   IX86_BUILTIN_PSRLD256_MASK,
29518   IX86_BUILTIN_PSRLQI128_MASK,
29519   IX86_BUILTIN_PSRLQ128_MASK,
29520   IX86_BUILTIN_PSRLQI256_MASK,
29521   IX86_BUILTIN_PSRLQ256_MASK,
29522   IX86_BUILTIN_PANDQ256,
29523   IX86_BUILTIN_PANDQ128,
29524   IX86_BUILTIN_PANDND256,
29525   IX86_BUILTIN_PANDND128,
29526   IX86_BUILTIN_PANDNQ256,
29527   IX86_BUILTIN_PANDNQ128,
29528   IX86_BUILTIN_PORD256,
29529   IX86_BUILTIN_PORD128,
29530   IX86_BUILTIN_PORQ256,
29531   IX86_BUILTIN_PORQ128,
29532   IX86_BUILTIN_PXORD256,
29533   IX86_BUILTIN_PXORD128,
29534   IX86_BUILTIN_PXORQ256,
29535   IX86_BUILTIN_PXORQ128,
29536   IX86_BUILTIN_PACKSSWB256_MASK,
29537   IX86_BUILTIN_PACKSSWB128_MASK,
29538   IX86_BUILTIN_PACKUSWB256_MASK,
29539   IX86_BUILTIN_PACKUSWB128_MASK,
29540   IX86_BUILTIN_RNDSCALEPS256,
29541   IX86_BUILTIN_RNDSCALEPD256,
29542   IX86_BUILTIN_RNDSCALEPS128,
29543   IX86_BUILTIN_RNDSCALEPD128,
29544   IX86_BUILTIN_VTERNLOGQ256_MASK,
29545   IX86_BUILTIN_VTERNLOGQ256_MASKZ,
29546   IX86_BUILTIN_VTERNLOGD256_MASK,
29547   IX86_BUILTIN_VTERNLOGD256_MASKZ,
29548   IX86_BUILTIN_VTERNLOGQ128_MASK,
29549   IX86_BUILTIN_VTERNLOGQ128_MASKZ,
29550   IX86_BUILTIN_VTERNLOGD128_MASK,
29551   IX86_BUILTIN_VTERNLOGD128_MASKZ,
29552   IX86_BUILTIN_SCALEFPD256,
29553   IX86_BUILTIN_SCALEFPS256,
29554   IX86_BUILTIN_SCALEFPD128,
29555   IX86_BUILTIN_SCALEFPS128,
29556   IX86_BUILTIN_VFMADDPD256_MASK,
29557   IX86_BUILTIN_VFMADDPD256_MASK3,
29558   IX86_BUILTIN_VFMADDPD256_MASKZ,
29559   IX86_BUILTIN_VFMADDPD128_MASK,
29560   IX86_BUILTIN_VFMADDPD128_MASK3,
29561   IX86_BUILTIN_VFMADDPD128_MASKZ,
29562   IX86_BUILTIN_VFMADDPS256_MASK,
29563   IX86_BUILTIN_VFMADDPS256_MASK3,
29564   IX86_BUILTIN_VFMADDPS256_MASKZ,
29565   IX86_BUILTIN_VFMADDPS128_MASK,
29566   IX86_BUILTIN_VFMADDPS128_MASK3,
29567   IX86_BUILTIN_VFMADDPS128_MASKZ,
29568   IX86_BUILTIN_VFMSUBPD256_MASK3,
29569   IX86_BUILTIN_VFMSUBPD128_MASK3,
29570   IX86_BUILTIN_VFMSUBPS256_MASK3,
29571   IX86_BUILTIN_VFMSUBPS128_MASK3,
29572   IX86_BUILTIN_VFNMADDPD256_MASK,
29573   IX86_BUILTIN_VFNMADDPD128_MASK,
29574   IX86_BUILTIN_VFNMADDPS256_MASK,
29575   IX86_BUILTIN_VFNMADDPS128_MASK,
29576   IX86_BUILTIN_VFNMSUBPD256_MASK,
29577   IX86_BUILTIN_VFNMSUBPD256_MASK3,
29578   IX86_BUILTIN_VFNMSUBPD128_MASK,
29579   IX86_BUILTIN_VFNMSUBPD128_MASK3,
29580   IX86_BUILTIN_VFNMSUBPS256_MASK,
29581   IX86_BUILTIN_VFNMSUBPS256_MASK3,
29582   IX86_BUILTIN_VFNMSUBPS128_MASK,
29583   IX86_BUILTIN_VFNMSUBPS128_MASK3,
29584   IX86_BUILTIN_VFMADDSUBPD256_MASK,
29585   IX86_BUILTIN_VFMADDSUBPD256_MASK3,
29586   IX86_BUILTIN_VFMADDSUBPD256_MASKZ,
29587   IX86_BUILTIN_VFMADDSUBPD128_MASK,
29588   IX86_BUILTIN_VFMADDSUBPD128_MASK3,
29589   IX86_BUILTIN_VFMADDSUBPD128_MASKZ,
29590   IX86_BUILTIN_VFMADDSUBPS256_MASK,
29591   IX86_BUILTIN_VFMADDSUBPS256_MASK3,
29592   IX86_BUILTIN_VFMADDSUBPS256_MASKZ,
29593   IX86_BUILTIN_VFMADDSUBPS128_MASK,
29594   IX86_BUILTIN_VFMADDSUBPS128_MASK3,
29595   IX86_BUILTIN_VFMADDSUBPS128_MASKZ,
29596   IX86_BUILTIN_VFMSUBADDPD256_MASK3,
29597   IX86_BUILTIN_VFMSUBADDPD128_MASK3,
29598   IX86_BUILTIN_VFMSUBADDPS256_MASK3,
29599   IX86_BUILTIN_VFMSUBADDPS128_MASK3,
29600   IX86_BUILTIN_INSERTF64X2_256,
29601   IX86_BUILTIN_INSERTI64X2_256,
29602   IX86_BUILTIN_PSRAVV16HI,
29603   IX86_BUILTIN_PSRAVV8HI,
29604   IX86_BUILTIN_PMADDUBSW256_MASK,
29605   IX86_BUILTIN_PMADDUBSW128_MASK,
29606   IX86_BUILTIN_PMADDWD256_MASK,
29607   IX86_BUILTIN_PMADDWD128_MASK,
29608   IX86_BUILTIN_PSRLVV16HI,
29609   IX86_BUILTIN_PSRLVV8HI,
29610   IX86_BUILTIN_CVTPS2DQ256_MASK,
29611   IX86_BUILTIN_CVTPS2DQ128_MASK,
29612   IX86_BUILTIN_CVTPS2UDQ256,
29613   IX86_BUILTIN_CVTPS2UDQ128,
29614   IX86_BUILTIN_CVTPS2QQ256,
29615   IX86_BUILTIN_CVTPS2QQ128,
29616   IX86_BUILTIN_CVTPS2UQQ256,
29617   IX86_BUILTIN_CVTPS2UQQ128,
29618   IX86_BUILTIN_GETMANTPS256,
29619   IX86_BUILTIN_GETMANTPS128,
29620   IX86_BUILTIN_GETMANTPD256,
29621   IX86_BUILTIN_GETMANTPD128,
29622   IX86_BUILTIN_MOVDDUP256_MASK,
29623   IX86_BUILTIN_MOVDDUP128_MASK,
29624   IX86_BUILTIN_MOVSHDUP256_MASK,
29625   IX86_BUILTIN_MOVSHDUP128_MASK,
29626   IX86_BUILTIN_MOVSLDUP256_MASK,
29627   IX86_BUILTIN_MOVSLDUP128_MASK,
29628   IX86_BUILTIN_CVTQQ2PS256,
29629   IX86_BUILTIN_CVTQQ2PS128,
29630   IX86_BUILTIN_CVTUQQ2PS256,
29631   IX86_BUILTIN_CVTUQQ2PS128,
29632   IX86_BUILTIN_CVTQQ2PD256,
29633   IX86_BUILTIN_CVTQQ2PD128,
29634   IX86_BUILTIN_CVTUQQ2PD256,
29635   IX86_BUILTIN_CVTUQQ2PD128,
29636   IX86_BUILTIN_VPERMT2VARQ256,
29637   IX86_BUILTIN_VPERMT2VARQ256_MASKZ,
29638   IX86_BUILTIN_VPERMT2VARD256,
29639   IX86_BUILTIN_VPERMT2VARD256_MASKZ,
29640   IX86_BUILTIN_VPERMI2VARQ256,
29641   IX86_BUILTIN_VPERMI2VARD256,
29642   IX86_BUILTIN_VPERMT2VARPD256,
29643   IX86_BUILTIN_VPERMT2VARPD256_MASKZ,
29644   IX86_BUILTIN_VPERMT2VARPS256,
29645   IX86_BUILTIN_VPERMT2VARPS256_MASKZ,
29646   IX86_BUILTIN_VPERMI2VARPD256,
29647   IX86_BUILTIN_VPERMI2VARPS256,
29648   IX86_BUILTIN_VPERMT2VARQ128,
29649   IX86_BUILTIN_VPERMT2VARQ128_MASKZ,
29650   IX86_BUILTIN_VPERMT2VARD128,
29651   IX86_BUILTIN_VPERMT2VARD128_MASKZ,
29652   IX86_BUILTIN_VPERMI2VARQ128,
29653   IX86_BUILTIN_VPERMI2VARD128,
29654   IX86_BUILTIN_VPERMT2VARPD128,
29655   IX86_BUILTIN_VPERMT2VARPD128_MASKZ,
29656   IX86_BUILTIN_VPERMT2VARPS128,
29657   IX86_BUILTIN_VPERMT2VARPS128_MASKZ,
29658   IX86_BUILTIN_VPERMI2VARPD128,
29659   IX86_BUILTIN_VPERMI2VARPS128,
29660   IX86_BUILTIN_PSHUFB256_MASK,
29661   IX86_BUILTIN_PSHUFB128_MASK,
29662   IX86_BUILTIN_PSHUFHW256_MASK,
29663   IX86_BUILTIN_PSHUFHW128_MASK,
29664   IX86_BUILTIN_PSHUFLW256_MASK,
29665   IX86_BUILTIN_PSHUFLW128_MASK,
29666   IX86_BUILTIN_PSHUFD256_MASK,
29667   IX86_BUILTIN_PSHUFD128_MASK,
29668   IX86_BUILTIN_SHUFPD256_MASK,
29669   IX86_BUILTIN_SHUFPD128_MASK,
29670   IX86_BUILTIN_SHUFPS256_MASK,
29671   IX86_BUILTIN_SHUFPS128_MASK,
29672   IX86_BUILTIN_PROLVQ256,
29673   IX86_BUILTIN_PROLVQ128,
29674   IX86_BUILTIN_PROLQ256,
29675   IX86_BUILTIN_PROLQ128,
29676   IX86_BUILTIN_PRORVQ256,
29677   IX86_BUILTIN_PRORVQ128,
29678   IX86_BUILTIN_PRORQ256,
29679   IX86_BUILTIN_PRORQ128,
29680   IX86_BUILTIN_PSRAVQ128,
29681   IX86_BUILTIN_PSRAVQ256,
29682   IX86_BUILTIN_PSLLVV4DI_MASK,
29683   IX86_BUILTIN_PSLLVV2DI_MASK,
29684   IX86_BUILTIN_PSLLVV8SI_MASK,
29685   IX86_BUILTIN_PSLLVV4SI_MASK,
29686   IX86_BUILTIN_PSRAVV8SI_MASK,
29687   IX86_BUILTIN_PSRAVV4SI_MASK,
29688   IX86_BUILTIN_PSRLVV4DI_MASK,
29689   IX86_BUILTIN_PSRLVV2DI_MASK,
29690   IX86_BUILTIN_PSRLVV8SI_MASK,
29691   IX86_BUILTIN_PSRLVV4SI_MASK,
29692   IX86_BUILTIN_PSRAWI256_MASK,
29693   IX86_BUILTIN_PSRAW256_MASK,
29694   IX86_BUILTIN_PSRAWI128_MASK,
29695   IX86_BUILTIN_PSRAW128_MASK,
29696   IX86_BUILTIN_PSRLWI256_MASK,
29697   IX86_BUILTIN_PSRLW256_MASK,
29698   IX86_BUILTIN_PSRLWI128_MASK,
29699   IX86_BUILTIN_PSRLW128_MASK,
29700   IX86_BUILTIN_PRORVD256,
29701   IX86_BUILTIN_PROLVD256,
29702   IX86_BUILTIN_PRORD256,
29703   IX86_BUILTIN_PROLD256,
29704   IX86_BUILTIN_PRORVD128,
29705   IX86_BUILTIN_PROLVD128,
29706   IX86_BUILTIN_PRORD128,
29707   IX86_BUILTIN_PROLD128,
29708   IX86_BUILTIN_FPCLASSPD256,
29709   IX86_BUILTIN_FPCLASSPD128,
29710   IX86_BUILTIN_FPCLASSSD,
29711   IX86_BUILTIN_FPCLASSPS256,
29712   IX86_BUILTIN_FPCLASSPS128,
29713   IX86_BUILTIN_FPCLASSSS,
29714   IX86_BUILTIN_CVTB2MASK128,
29715   IX86_BUILTIN_CVTB2MASK256,
29716   IX86_BUILTIN_CVTW2MASK128,
29717   IX86_BUILTIN_CVTW2MASK256,
29718   IX86_BUILTIN_CVTD2MASK128,
29719   IX86_BUILTIN_CVTD2MASK256,
29720   IX86_BUILTIN_CVTQ2MASK128,
29721   IX86_BUILTIN_CVTQ2MASK256,
29722   IX86_BUILTIN_CVTMASK2B128,
29723   IX86_BUILTIN_CVTMASK2B256,
29724   IX86_BUILTIN_CVTMASK2W128,
29725   IX86_BUILTIN_CVTMASK2W256,
29726   IX86_BUILTIN_CVTMASK2D128,
29727   IX86_BUILTIN_CVTMASK2D256,
29728   IX86_BUILTIN_CVTMASK2Q128,
29729   IX86_BUILTIN_CVTMASK2Q256,
29730   IX86_BUILTIN_PCMPEQB128_MASK,
29731   IX86_BUILTIN_PCMPEQB256_MASK,
29732   IX86_BUILTIN_PCMPEQW128_MASK,
29733   IX86_BUILTIN_PCMPEQW256_MASK,
29734   IX86_BUILTIN_PCMPEQD128_MASK,
29735   IX86_BUILTIN_PCMPEQD256_MASK,
29736   IX86_BUILTIN_PCMPEQQ128_MASK,
29737   IX86_BUILTIN_PCMPEQQ256_MASK,
29738   IX86_BUILTIN_PCMPGTB128_MASK,
29739   IX86_BUILTIN_PCMPGTB256_MASK,
29740   IX86_BUILTIN_PCMPGTW128_MASK,
29741   IX86_BUILTIN_PCMPGTW256_MASK,
29742   IX86_BUILTIN_PCMPGTD128_MASK,
29743   IX86_BUILTIN_PCMPGTD256_MASK,
29744   IX86_BUILTIN_PCMPGTQ128_MASK,
29745   IX86_BUILTIN_PCMPGTQ256_MASK,
29746   IX86_BUILTIN_PTESTMB128,
29747   IX86_BUILTIN_PTESTMB256,
29748   IX86_BUILTIN_PTESTMW128,
29749   IX86_BUILTIN_PTESTMW256,
29750   IX86_BUILTIN_PTESTMD128,
29751   IX86_BUILTIN_PTESTMD256,
29752   IX86_BUILTIN_PTESTMQ128,
29753   IX86_BUILTIN_PTESTMQ256,
29754   IX86_BUILTIN_PTESTNMB128,
29755   IX86_BUILTIN_PTESTNMB256,
29756   IX86_BUILTIN_PTESTNMW128,
29757   IX86_BUILTIN_PTESTNMW256,
29758   IX86_BUILTIN_PTESTNMD128,
29759   IX86_BUILTIN_PTESTNMD256,
29760   IX86_BUILTIN_PTESTNMQ128,
29761   IX86_BUILTIN_PTESTNMQ256,
29762   IX86_BUILTIN_PBROADCASTMB128,
29763   IX86_BUILTIN_PBROADCASTMB256,
29764   IX86_BUILTIN_PBROADCASTMW128,
29765   IX86_BUILTIN_PBROADCASTMW256,
29766   IX86_BUILTIN_COMPRESSPD256,
29767   IX86_BUILTIN_COMPRESSPD128,
29768   IX86_BUILTIN_COMPRESSPS256,
29769   IX86_BUILTIN_COMPRESSPS128,
29770   IX86_BUILTIN_PCOMPRESSQ256,
29771   IX86_BUILTIN_PCOMPRESSQ128,
29772   IX86_BUILTIN_PCOMPRESSD256,
29773   IX86_BUILTIN_PCOMPRESSD128,
29774   IX86_BUILTIN_EXPANDPD256,
29775   IX86_BUILTIN_EXPANDPD128,
29776   IX86_BUILTIN_EXPANDPS256,
29777   IX86_BUILTIN_EXPANDPS128,
29778   IX86_BUILTIN_PEXPANDQ256,
29779   IX86_BUILTIN_PEXPANDQ128,
29780   IX86_BUILTIN_PEXPANDD256,
29781   IX86_BUILTIN_PEXPANDD128,
29782   IX86_BUILTIN_EXPANDPD256Z,
29783   IX86_BUILTIN_EXPANDPD128Z,
29784   IX86_BUILTIN_EXPANDPS256Z,
29785   IX86_BUILTIN_EXPANDPS128Z,
29786   IX86_BUILTIN_PEXPANDQ256Z,
29787   IX86_BUILTIN_PEXPANDQ128Z,
29788   IX86_BUILTIN_PEXPANDD256Z,
29789   IX86_BUILTIN_PEXPANDD128Z,
29790   IX86_BUILTIN_PMAXSD256_MASK,
29791   IX86_BUILTIN_PMINSD256_MASK,
29792   IX86_BUILTIN_PMAXUD256_MASK,
29793   IX86_BUILTIN_PMINUD256_MASK,
29794   IX86_BUILTIN_PMAXSD128_MASK,
29795   IX86_BUILTIN_PMINSD128_MASK,
29796   IX86_BUILTIN_PMAXUD128_MASK,
29797   IX86_BUILTIN_PMINUD128_MASK,
29798   IX86_BUILTIN_PMAXSQ256_MASK,
29799   IX86_BUILTIN_PMINSQ256_MASK,
29800   IX86_BUILTIN_PMAXUQ256_MASK,
29801   IX86_BUILTIN_PMINUQ256_MASK,
29802   IX86_BUILTIN_PMAXSQ128_MASK,
29803   IX86_BUILTIN_PMINSQ128_MASK,
29804   IX86_BUILTIN_PMAXUQ128_MASK,
29805   IX86_BUILTIN_PMINUQ128_MASK,
29806   IX86_BUILTIN_PMINSB256_MASK,
29807   IX86_BUILTIN_PMINUB256_MASK,
29808   IX86_BUILTIN_PMAXSB256_MASK,
29809   IX86_BUILTIN_PMAXUB256_MASK,
29810   IX86_BUILTIN_PMINSB128_MASK,
29811   IX86_BUILTIN_PMINUB128_MASK,
29812   IX86_BUILTIN_PMAXSB128_MASK,
29813   IX86_BUILTIN_PMAXUB128_MASK,
29814   IX86_BUILTIN_PMINSW256_MASK,
29815   IX86_BUILTIN_PMINUW256_MASK,
29816   IX86_BUILTIN_PMAXSW256_MASK,
29817   IX86_BUILTIN_PMAXUW256_MASK,
29818   IX86_BUILTIN_PMINSW128_MASK,
29819   IX86_BUILTIN_PMINUW128_MASK,
29820   IX86_BUILTIN_PMAXSW128_MASK,
29821   IX86_BUILTIN_PMAXUW128_MASK,
29822   IX86_BUILTIN_VPCONFLICTQ256,
29823   IX86_BUILTIN_VPCONFLICTD256,
29824   IX86_BUILTIN_VPCLZCNTQ256,
29825   IX86_BUILTIN_VPCLZCNTD256,
29826   IX86_BUILTIN_UNPCKHPD256_MASK,
29827   IX86_BUILTIN_UNPCKHPD128_MASK,
29828   IX86_BUILTIN_UNPCKHPS256_MASK,
29829   IX86_BUILTIN_UNPCKHPS128_MASK,
29830   IX86_BUILTIN_UNPCKLPD256_MASK,
29831   IX86_BUILTIN_UNPCKLPD128_MASK,
29832   IX86_BUILTIN_UNPCKLPS256_MASK,
29833   IX86_BUILTIN_VPCONFLICTQ128,
29834   IX86_BUILTIN_VPCONFLICTD128,
29835   IX86_BUILTIN_VPCLZCNTQ128,
29836   IX86_BUILTIN_VPCLZCNTD128,
29837   IX86_BUILTIN_UNPCKLPS128_MASK,
29838   IX86_BUILTIN_ALIGND256,
29839   IX86_BUILTIN_ALIGNQ256,
29840   IX86_BUILTIN_ALIGND128,
29841   IX86_BUILTIN_ALIGNQ128,
29842   IX86_BUILTIN_CVTPS2PH256_MASK,
29843   IX86_BUILTIN_CVTPS2PH_MASK,
29844   IX86_BUILTIN_CVTPH2PS_MASK,
29845   IX86_BUILTIN_CVTPH2PS256_MASK,
29846   IX86_BUILTIN_PUNPCKHDQ128_MASK,
29847   IX86_BUILTIN_PUNPCKHDQ256_MASK,
29848   IX86_BUILTIN_PUNPCKHQDQ128_MASK,
29849   IX86_BUILTIN_PUNPCKHQDQ256_MASK,
29850   IX86_BUILTIN_PUNPCKLDQ128_MASK,
29851   IX86_BUILTIN_PUNPCKLDQ256_MASK,
29852   IX86_BUILTIN_PUNPCKLQDQ128_MASK,
29853   IX86_BUILTIN_PUNPCKLQDQ256_MASK,
29854   IX86_BUILTIN_PUNPCKHBW128_MASK,
29855   IX86_BUILTIN_PUNPCKHBW256_MASK,
29856   IX86_BUILTIN_PUNPCKHWD128_MASK,
29857   IX86_BUILTIN_PUNPCKHWD256_MASK,
29858   IX86_BUILTIN_PUNPCKLBW128_MASK,
29859   IX86_BUILTIN_PUNPCKLBW256_MASK,
29860   IX86_BUILTIN_PUNPCKLWD128_MASK,
29861   IX86_BUILTIN_PUNPCKLWD256_MASK,
29862   IX86_BUILTIN_PSLLVV16HI,
29863   IX86_BUILTIN_PSLLVV8HI,
29864   IX86_BUILTIN_PACKSSDW256_MASK,
29865   IX86_BUILTIN_PACKSSDW128_MASK,
29866   IX86_BUILTIN_PACKUSDW256_MASK,
29867   IX86_BUILTIN_PACKUSDW128_MASK,
29868   IX86_BUILTIN_PAVGB256_MASK,
29869   IX86_BUILTIN_PAVGW256_MASK,
29870   IX86_BUILTIN_PAVGB128_MASK,
29871   IX86_BUILTIN_PAVGW128_MASK,
29872   IX86_BUILTIN_VPERMVARSF256_MASK,
29873   IX86_BUILTIN_VPERMVARDF256_MASK,
29874   IX86_BUILTIN_VPERMDF256_MASK,
29875   IX86_BUILTIN_PABSB256_MASK,
29876   IX86_BUILTIN_PABSB128_MASK,
29877   IX86_BUILTIN_PABSW256_MASK,
29878   IX86_BUILTIN_PABSW128_MASK,
29879   IX86_BUILTIN_VPERMILVARPD_MASK,
29880   IX86_BUILTIN_VPERMILVARPS_MASK,
29881   IX86_BUILTIN_VPERMILVARPD256_MASK,
29882   IX86_BUILTIN_VPERMILVARPS256_MASK,
29883   IX86_BUILTIN_VPERMILPD_MASK,
29884   IX86_BUILTIN_VPERMILPS_MASK,
29885   IX86_BUILTIN_VPERMILPD256_MASK,
29886   IX86_BUILTIN_VPERMILPS256_MASK,
29887   IX86_BUILTIN_BLENDMQ256,
29888   IX86_BUILTIN_BLENDMD256,
29889   IX86_BUILTIN_BLENDMPD256,
29890   IX86_BUILTIN_BLENDMPS256,
29891   IX86_BUILTIN_BLENDMQ128,
29892   IX86_BUILTIN_BLENDMD128,
29893   IX86_BUILTIN_BLENDMPD128,
29894   IX86_BUILTIN_BLENDMPS128,
29895   IX86_BUILTIN_BLENDMW256,
29896   IX86_BUILTIN_BLENDMB256,
29897   IX86_BUILTIN_BLENDMW128,
29898   IX86_BUILTIN_BLENDMB128,
29899   IX86_BUILTIN_PMULLD256_MASK,
29900   IX86_BUILTIN_PMULLD128_MASK,
29901   IX86_BUILTIN_PMULUDQ256_MASK,
29902   IX86_BUILTIN_PMULDQ256_MASK,
29903   IX86_BUILTIN_PMULDQ128_MASK,
29904   IX86_BUILTIN_PMULUDQ128_MASK,
29905   IX86_BUILTIN_CVTPD2PS256_MASK,
29906   IX86_BUILTIN_CVTPD2PS_MASK,
29907   IX86_BUILTIN_VPERMVARSI256_MASK,
29908   IX86_BUILTIN_VPERMVARDI256_MASK,
29909   IX86_BUILTIN_VPERMDI256_MASK,
29910   IX86_BUILTIN_CMPQ256,
29911   IX86_BUILTIN_CMPD256,
29912   IX86_BUILTIN_UCMPQ256,
29913   IX86_BUILTIN_UCMPD256,
29914   IX86_BUILTIN_CMPB256,
29915   IX86_BUILTIN_CMPW256,
29916   IX86_BUILTIN_UCMPB256,
29917   IX86_BUILTIN_UCMPW256,
29918   IX86_BUILTIN_CMPPD256_MASK,
29919   IX86_BUILTIN_CMPPS256_MASK,
29920   IX86_BUILTIN_CMPQ128,
29921   IX86_BUILTIN_CMPD128,
29922   IX86_BUILTIN_UCMPQ128,
29923   IX86_BUILTIN_UCMPD128,
29924   IX86_BUILTIN_CMPB128,
29925   IX86_BUILTIN_CMPW128,
29926   IX86_BUILTIN_UCMPB128,
29927   IX86_BUILTIN_UCMPW128,
29928   IX86_BUILTIN_CMPPD128_MASK,
29929   IX86_BUILTIN_CMPPS128_MASK,
29930
29931   IX86_BUILTIN_GATHER3SIV8SF,
29932   IX86_BUILTIN_GATHER3SIV4SF,
29933   IX86_BUILTIN_GATHER3SIV4DF,
29934   IX86_BUILTIN_GATHER3SIV2DF,
29935   IX86_BUILTIN_GATHER3DIV8SF,
29936   IX86_BUILTIN_GATHER3DIV4SF,
29937   IX86_BUILTIN_GATHER3DIV4DF,
29938   IX86_BUILTIN_GATHER3DIV2DF,
29939   IX86_BUILTIN_GATHER3SIV8SI,
29940   IX86_BUILTIN_GATHER3SIV4SI,
29941   IX86_BUILTIN_GATHER3SIV4DI,
29942   IX86_BUILTIN_GATHER3SIV2DI,
29943   IX86_BUILTIN_GATHER3DIV8SI,
29944   IX86_BUILTIN_GATHER3DIV4SI,
29945   IX86_BUILTIN_GATHER3DIV4DI,
29946   IX86_BUILTIN_GATHER3DIV2DI,
29947   IX86_BUILTIN_SCATTERSIV8SF,
29948   IX86_BUILTIN_SCATTERSIV4SF,
29949   IX86_BUILTIN_SCATTERSIV4DF,
29950   IX86_BUILTIN_SCATTERSIV2DF,
29951   IX86_BUILTIN_SCATTERDIV8SF,
29952   IX86_BUILTIN_SCATTERDIV4SF,
29953   IX86_BUILTIN_SCATTERDIV4DF,
29954   IX86_BUILTIN_SCATTERDIV2DF,
29955   IX86_BUILTIN_SCATTERSIV8SI,
29956   IX86_BUILTIN_SCATTERSIV4SI,
29957   IX86_BUILTIN_SCATTERSIV4DI,
29958   IX86_BUILTIN_SCATTERSIV2DI,
29959   IX86_BUILTIN_SCATTERDIV8SI,
29960   IX86_BUILTIN_SCATTERDIV4SI,
29961   IX86_BUILTIN_SCATTERDIV4DI,
29962   IX86_BUILTIN_SCATTERDIV2DI,
29963
29964   /* AVX512DQ.  */
29965   IX86_BUILTIN_RANGESD128,
29966   IX86_BUILTIN_RANGESS128,
29967   IX86_BUILTIN_KUNPCKWD,
29968   IX86_BUILTIN_KUNPCKDQ,
29969   IX86_BUILTIN_BROADCASTF32x2_512,
29970   IX86_BUILTIN_BROADCASTI32x2_512,
29971   IX86_BUILTIN_BROADCASTF64X2_512,
29972   IX86_BUILTIN_BROADCASTI64X2_512,
29973   IX86_BUILTIN_BROADCASTF32X8_512,
29974   IX86_BUILTIN_BROADCASTI32X8_512,
29975   IX86_BUILTIN_EXTRACTF64X2_512,
29976   IX86_BUILTIN_EXTRACTF32X8,
29977   IX86_BUILTIN_EXTRACTI64X2_512,
29978   IX86_BUILTIN_EXTRACTI32X8,
29979   IX86_BUILTIN_REDUCEPD512_MASK,
29980   IX86_BUILTIN_REDUCEPS512_MASK,
29981   IX86_BUILTIN_PMULLQ512,
29982   IX86_BUILTIN_XORPD512,
29983   IX86_BUILTIN_XORPS512,
29984   IX86_BUILTIN_ORPD512,
29985   IX86_BUILTIN_ORPS512,
29986   IX86_BUILTIN_ANDPD512,
29987   IX86_BUILTIN_ANDPS512,
29988   IX86_BUILTIN_ANDNPD512,
29989   IX86_BUILTIN_ANDNPS512,
29990   IX86_BUILTIN_INSERTF32X8,
29991   IX86_BUILTIN_INSERTI32X8,
29992   IX86_BUILTIN_INSERTF64X2_512,
29993   IX86_BUILTIN_INSERTI64X2_512,
29994   IX86_BUILTIN_FPCLASSPD512,
29995   IX86_BUILTIN_FPCLASSPS512,
29996   IX86_BUILTIN_CVTD2MASK512,
29997   IX86_BUILTIN_CVTQ2MASK512,
29998   IX86_BUILTIN_CVTMASK2D512,
29999   IX86_BUILTIN_CVTMASK2Q512,
30000   IX86_BUILTIN_CVTPD2QQ512,
30001   IX86_BUILTIN_CVTPS2QQ512,
30002   IX86_BUILTIN_CVTPD2UQQ512,
30003   IX86_BUILTIN_CVTPS2UQQ512,
30004   IX86_BUILTIN_CVTQQ2PS512,
30005   IX86_BUILTIN_CVTUQQ2PS512,
30006   IX86_BUILTIN_CVTQQ2PD512,
30007   IX86_BUILTIN_CVTUQQ2PD512,
30008   IX86_BUILTIN_CVTTPS2QQ512,
30009   IX86_BUILTIN_CVTTPS2UQQ512,
30010   IX86_BUILTIN_CVTTPD2QQ512,
30011   IX86_BUILTIN_CVTTPD2UQQ512,
30012   IX86_BUILTIN_RANGEPS512,
30013   IX86_BUILTIN_RANGEPD512,
30014
30015   /* AVX512BW.  */
30016   IX86_BUILTIN_PACKUSDW512,
30017   IX86_BUILTIN_PACKSSDW512,
30018   IX86_BUILTIN_LOADDQUHI512_MASK,
30019   IX86_BUILTIN_LOADDQUQI512_MASK,
30020   IX86_BUILTIN_PSLLDQ512,
30021   IX86_BUILTIN_PSRLDQ512,
30022   IX86_BUILTIN_STOREDQUHI512_MASK,
30023   IX86_BUILTIN_STOREDQUQI512_MASK,
30024   IX86_BUILTIN_PALIGNR512,
30025   IX86_BUILTIN_PALIGNR512_MASK,
30026   IX86_BUILTIN_MOVDQUHI512_MASK,
30027   IX86_BUILTIN_MOVDQUQI512_MASK,
30028   IX86_BUILTIN_PSADBW512,
30029   IX86_BUILTIN_DBPSADBW512,
30030   IX86_BUILTIN_PBROADCASTB512,
30031   IX86_BUILTIN_PBROADCASTB512_GPR,
30032   IX86_BUILTIN_PBROADCASTW512,
30033   IX86_BUILTIN_PBROADCASTW512_GPR,
30034   IX86_BUILTIN_PMOVSXBW512_MASK,
30035   IX86_BUILTIN_PMOVZXBW512_MASK,
30036   IX86_BUILTIN_VPERMVARHI512_MASK,
30037   IX86_BUILTIN_VPERMT2VARHI512,
30038   IX86_BUILTIN_VPERMT2VARHI512_MASKZ,
30039   IX86_BUILTIN_VPERMI2VARHI512,
30040   IX86_BUILTIN_PAVGB512,
30041   IX86_BUILTIN_PAVGW512,
30042   IX86_BUILTIN_PADDB512,
30043   IX86_BUILTIN_PSUBB512,
30044   IX86_BUILTIN_PSUBSB512,
30045   IX86_BUILTIN_PADDSB512,
30046   IX86_BUILTIN_PSUBUSB512,
30047   IX86_BUILTIN_PADDUSB512,
30048   IX86_BUILTIN_PSUBW512,
30049   IX86_BUILTIN_PADDW512,
30050   IX86_BUILTIN_PSUBSW512,
30051   IX86_BUILTIN_PADDSW512,
30052   IX86_BUILTIN_PSUBUSW512,
30053   IX86_BUILTIN_PADDUSW512,
30054   IX86_BUILTIN_PMAXUW512,
30055   IX86_BUILTIN_PMAXSW512,
30056   IX86_BUILTIN_PMINUW512,
30057   IX86_BUILTIN_PMINSW512,
30058   IX86_BUILTIN_PMAXUB512,
30059   IX86_BUILTIN_PMAXSB512,
30060   IX86_BUILTIN_PMINUB512,
30061   IX86_BUILTIN_PMINSB512,
30062   IX86_BUILTIN_PMOVWB512,
30063   IX86_BUILTIN_PMOVSWB512,
30064   IX86_BUILTIN_PMOVUSWB512,
30065   IX86_BUILTIN_PMULHRSW512_MASK,
30066   IX86_BUILTIN_PMULHUW512_MASK,
30067   IX86_BUILTIN_PMULHW512_MASK,
30068   IX86_BUILTIN_PMULLW512_MASK,
30069   IX86_BUILTIN_PSLLWI512_MASK,
30070   IX86_BUILTIN_PSLLW512_MASK,
30071   IX86_BUILTIN_PACKSSWB512,
30072   IX86_BUILTIN_PACKUSWB512,
30073   IX86_BUILTIN_PSRAVV32HI,
30074   IX86_BUILTIN_PMADDUBSW512_MASK,
30075   IX86_BUILTIN_PMADDWD512_MASK,
30076   IX86_BUILTIN_PSRLVV32HI,
30077   IX86_BUILTIN_PUNPCKHBW512,
30078   IX86_BUILTIN_PUNPCKHWD512,
30079   IX86_BUILTIN_PUNPCKLBW512,
30080   IX86_BUILTIN_PUNPCKLWD512,
30081   IX86_BUILTIN_PSHUFB512,
30082   IX86_BUILTIN_PSHUFHW512,
30083   IX86_BUILTIN_PSHUFLW512,
30084   IX86_BUILTIN_PSRAWI512,
30085   IX86_BUILTIN_PSRAW512,
30086   IX86_BUILTIN_PSRLWI512,
30087   IX86_BUILTIN_PSRLW512,
30088   IX86_BUILTIN_CVTB2MASK512,
30089   IX86_BUILTIN_CVTW2MASK512,
30090   IX86_BUILTIN_CVTMASK2B512,
30091   IX86_BUILTIN_CVTMASK2W512,
30092   IX86_BUILTIN_PCMPEQB512_MASK,
30093   IX86_BUILTIN_PCMPEQW512_MASK,
30094   IX86_BUILTIN_PCMPGTB512_MASK,
30095   IX86_BUILTIN_PCMPGTW512_MASK,
30096   IX86_BUILTIN_PTESTMB512,
30097   IX86_BUILTIN_PTESTMW512,
30098   IX86_BUILTIN_PTESTNMB512,
30099   IX86_BUILTIN_PTESTNMW512,
30100   IX86_BUILTIN_PSLLVV32HI,
30101   IX86_BUILTIN_PABSB512,
30102   IX86_BUILTIN_PABSW512,
30103   IX86_BUILTIN_BLENDMW512,
30104   IX86_BUILTIN_BLENDMB512,
30105   IX86_BUILTIN_CMPB512,
30106   IX86_BUILTIN_CMPW512,
30107   IX86_BUILTIN_UCMPB512,
30108   IX86_BUILTIN_UCMPW512,
30109
30110   /* Alternate 4 and 8 element gather/scatter for the vectorizer
30111      where all operands are 32-byte or 64-byte wide respectively.  */
30112   IX86_BUILTIN_GATHERALTSIV4DF,
30113   IX86_BUILTIN_GATHERALTDIV8SF,
30114   IX86_BUILTIN_GATHERALTSIV4DI,
30115   IX86_BUILTIN_GATHERALTDIV8SI,
30116   IX86_BUILTIN_GATHER3ALTDIV16SF,
30117   IX86_BUILTIN_GATHER3ALTDIV16SI,
30118   IX86_BUILTIN_GATHER3ALTSIV4DF,
30119   IX86_BUILTIN_GATHER3ALTDIV8SF,
30120   IX86_BUILTIN_GATHER3ALTSIV4DI,
30121   IX86_BUILTIN_GATHER3ALTDIV8SI,
30122   IX86_BUILTIN_GATHER3ALTSIV8DF,
30123   IX86_BUILTIN_GATHER3ALTSIV8DI,
30124   IX86_BUILTIN_GATHER3DIV16SF,
30125   IX86_BUILTIN_GATHER3DIV16SI,
30126   IX86_BUILTIN_GATHER3DIV8DF,
30127   IX86_BUILTIN_GATHER3DIV8DI,
30128   IX86_BUILTIN_GATHER3SIV16SF,
30129   IX86_BUILTIN_GATHER3SIV16SI,
30130   IX86_BUILTIN_GATHER3SIV8DF,
30131   IX86_BUILTIN_GATHER3SIV8DI,
30132   IX86_BUILTIN_SCATTERDIV16SF,
30133   IX86_BUILTIN_SCATTERDIV16SI,
30134   IX86_BUILTIN_SCATTERDIV8DF,
30135   IX86_BUILTIN_SCATTERDIV8DI,
30136   IX86_BUILTIN_SCATTERSIV16SF,
30137   IX86_BUILTIN_SCATTERSIV16SI,
30138   IX86_BUILTIN_SCATTERSIV8DF,
30139   IX86_BUILTIN_SCATTERSIV8DI,
30140
30141   /* AVX512PF */
30142   IX86_BUILTIN_GATHERPFQPD,
30143   IX86_BUILTIN_GATHERPFDPS,
30144   IX86_BUILTIN_GATHERPFDPD,
30145   IX86_BUILTIN_GATHERPFQPS,
30146   IX86_BUILTIN_SCATTERPFDPD,
30147   IX86_BUILTIN_SCATTERPFDPS,
30148   IX86_BUILTIN_SCATTERPFQPD,
30149   IX86_BUILTIN_SCATTERPFQPS,
30150
30151   /* AVX-512ER */
30152   IX86_BUILTIN_EXP2PD_MASK,
30153   IX86_BUILTIN_EXP2PS_MASK,
30154   IX86_BUILTIN_EXP2PS,
30155   IX86_BUILTIN_RCP28PD,
30156   IX86_BUILTIN_RCP28PS,
30157   IX86_BUILTIN_RCP28SD,
30158   IX86_BUILTIN_RCP28SS,
30159   IX86_BUILTIN_RSQRT28PD,
30160   IX86_BUILTIN_RSQRT28PS,
30161   IX86_BUILTIN_RSQRT28SD,
30162   IX86_BUILTIN_RSQRT28SS,
30163
30164   /* AVX-512IFMA */
30165   IX86_BUILTIN_VPMADD52LUQ512,
30166   IX86_BUILTIN_VPMADD52HUQ512,
30167   IX86_BUILTIN_VPMADD52LUQ256,
30168   IX86_BUILTIN_VPMADD52HUQ256,
30169   IX86_BUILTIN_VPMADD52LUQ128,
30170   IX86_BUILTIN_VPMADD52HUQ128,
30171   IX86_BUILTIN_VPMADD52LUQ512_MASKZ,
30172   IX86_BUILTIN_VPMADD52HUQ512_MASKZ,
30173   IX86_BUILTIN_VPMADD52LUQ256_MASKZ,
30174   IX86_BUILTIN_VPMADD52HUQ256_MASKZ,
30175   IX86_BUILTIN_VPMADD52LUQ128_MASKZ,
30176   IX86_BUILTIN_VPMADD52HUQ128_MASKZ,
30177
30178   /* AVX-512VBMI */
30179   IX86_BUILTIN_VPMULTISHIFTQB512,
30180   IX86_BUILTIN_VPMULTISHIFTQB256,
30181   IX86_BUILTIN_VPMULTISHIFTQB128,
30182   IX86_BUILTIN_VPERMVARQI512_MASK,
30183   IX86_BUILTIN_VPERMT2VARQI512,
30184   IX86_BUILTIN_VPERMT2VARQI512_MASKZ,
30185   IX86_BUILTIN_VPERMI2VARQI512,
30186   IX86_BUILTIN_VPERMVARQI256_MASK,
30187   IX86_BUILTIN_VPERMVARQI128_MASK,
30188   IX86_BUILTIN_VPERMT2VARQI256,
30189   IX86_BUILTIN_VPERMT2VARQI256_MASKZ,
30190   IX86_BUILTIN_VPERMT2VARQI128,
30191   IX86_BUILTIN_VPERMT2VARQI128_MASKZ,
30192   IX86_BUILTIN_VPERMI2VARQI256,
30193   IX86_BUILTIN_VPERMI2VARQI128,
30194
30195   /* SHA builtins.  */
30196   IX86_BUILTIN_SHA1MSG1,
30197   IX86_BUILTIN_SHA1MSG2,
30198   IX86_BUILTIN_SHA1NEXTE,
30199   IX86_BUILTIN_SHA1RNDS4,
30200   IX86_BUILTIN_SHA256MSG1,
30201   IX86_BUILTIN_SHA256MSG2,
30202   IX86_BUILTIN_SHA256RNDS2,
30203
30204   /* CLWB instructions.  */
30205   IX86_BUILTIN_CLWB,
30206
30207   /* PCOMMIT instructions.  */
30208   IX86_BUILTIN_PCOMMIT,
30209
30210   /* CLFLUSHOPT instructions.  */
30211   IX86_BUILTIN_CLFLUSHOPT,
30212
30213   /* TFmode support builtins.  */
30214   IX86_BUILTIN_INFQ,
30215   IX86_BUILTIN_HUGE_VALQ,
30216   IX86_BUILTIN_FABSQ,
30217   IX86_BUILTIN_COPYSIGNQ,
30218
30219   /* Vectorizer support builtins.  */
30220   IX86_BUILTIN_CEILPD_VEC_PACK_SFIX512,
30221   IX86_BUILTIN_CPYSGNPS,
30222   IX86_BUILTIN_CPYSGNPD,
30223   IX86_BUILTIN_CPYSGNPS256,
30224   IX86_BUILTIN_CPYSGNPS512,
30225   IX86_BUILTIN_CPYSGNPD256,
30226   IX86_BUILTIN_CPYSGNPD512,
30227   IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX512,
30228   IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX512,
30229
30230
30231   /* FMA4 instructions.  */
30232   IX86_BUILTIN_VFMADDSS,
30233   IX86_BUILTIN_VFMADDSD,
30234   IX86_BUILTIN_VFMADDPS,
30235   IX86_BUILTIN_VFMADDPD,
30236   IX86_BUILTIN_VFMADDPS256,
30237   IX86_BUILTIN_VFMADDPD256,
30238   IX86_BUILTIN_VFMADDSUBPS,
30239   IX86_BUILTIN_VFMADDSUBPD,
30240   IX86_BUILTIN_VFMADDSUBPS256,
30241   IX86_BUILTIN_VFMADDSUBPD256,
30242
30243   /* FMA3 instructions.  */
30244   IX86_BUILTIN_VFMADDSS3,
30245   IX86_BUILTIN_VFMADDSD3,
30246
30247   /* XOP instructions.  */
30248   IX86_BUILTIN_VPCMOV,
30249   IX86_BUILTIN_VPCMOV_V2DI,
30250   IX86_BUILTIN_VPCMOV_V4SI,
30251   IX86_BUILTIN_VPCMOV_V8HI,
30252   IX86_BUILTIN_VPCMOV_V16QI,
30253   IX86_BUILTIN_VPCMOV_V4SF,
30254   IX86_BUILTIN_VPCMOV_V2DF,
30255   IX86_BUILTIN_VPCMOV256,
30256   IX86_BUILTIN_VPCMOV_V4DI256,
30257   IX86_BUILTIN_VPCMOV_V8SI256,
30258   IX86_BUILTIN_VPCMOV_V16HI256,
30259   IX86_BUILTIN_VPCMOV_V32QI256,
30260   IX86_BUILTIN_VPCMOV_V8SF256,
30261   IX86_BUILTIN_VPCMOV_V4DF256,
30262
30263   IX86_BUILTIN_VPPERM,
30264
30265   IX86_BUILTIN_VPMACSSWW,
30266   IX86_BUILTIN_VPMACSWW,
30267   IX86_BUILTIN_VPMACSSWD,
30268   IX86_BUILTIN_VPMACSWD,
30269   IX86_BUILTIN_VPMACSSDD,
30270   IX86_BUILTIN_VPMACSDD,
30271   IX86_BUILTIN_VPMACSSDQL,
30272   IX86_BUILTIN_VPMACSSDQH,
30273   IX86_BUILTIN_VPMACSDQL,
30274   IX86_BUILTIN_VPMACSDQH,
30275   IX86_BUILTIN_VPMADCSSWD,
30276   IX86_BUILTIN_VPMADCSWD,
30277
30278   IX86_BUILTIN_VPHADDBW,
30279   IX86_BUILTIN_VPHADDBD,
30280   IX86_BUILTIN_VPHADDBQ,
30281   IX86_BUILTIN_VPHADDWD,
30282   IX86_BUILTIN_VPHADDWQ,
30283   IX86_BUILTIN_VPHADDDQ,
30284   IX86_BUILTIN_VPHADDUBW,
30285   IX86_BUILTIN_VPHADDUBD,
30286   IX86_BUILTIN_VPHADDUBQ,
30287   IX86_BUILTIN_VPHADDUWD,
30288   IX86_BUILTIN_VPHADDUWQ,
30289   IX86_BUILTIN_VPHADDUDQ,
30290   IX86_BUILTIN_VPHSUBBW,
30291   IX86_BUILTIN_VPHSUBWD,
30292   IX86_BUILTIN_VPHSUBDQ,
30293
30294   IX86_BUILTIN_VPROTB,
30295   IX86_BUILTIN_VPROTW,
30296   IX86_BUILTIN_VPROTD,
30297   IX86_BUILTIN_VPROTQ,
30298   IX86_BUILTIN_VPROTB_IMM,
30299   IX86_BUILTIN_VPROTW_IMM,
30300   IX86_BUILTIN_VPROTD_IMM,
30301   IX86_BUILTIN_VPROTQ_IMM,
30302
30303   IX86_BUILTIN_VPSHLB,
30304   IX86_BUILTIN_VPSHLW,
30305   IX86_BUILTIN_VPSHLD,
30306   IX86_BUILTIN_VPSHLQ,
30307   IX86_BUILTIN_VPSHAB,
30308   IX86_BUILTIN_VPSHAW,
30309   IX86_BUILTIN_VPSHAD,
30310   IX86_BUILTIN_VPSHAQ,
30311
30312   IX86_BUILTIN_VFRCZSS,
30313   IX86_BUILTIN_VFRCZSD,
30314   IX86_BUILTIN_VFRCZPS,
30315   IX86_BUILTIN_VFRCZPD,
30316   IX86_BUILTIN_VFRCZPS256,
30317   IX86_BUILTIN_VFRCZPD256,
30318
30319   IX86_BUILTIN_VPCOMEQUB,
30320   IX86_BUILTIN_VPCOMNEUB,
30321   IX86_BUILTIN_VPCOMLTUB,
30322   IX86_BUILTIN_VPCOMLEUB,
30323   IX86_BUILTIN_VPCOMGTUB,
30324   IX86_BUILTIN_VPCOMGEUB,
30325   IX86_BUILTIN_VPCOMFALSEUB,
30326   IX86_BUILTIN_VPCOMTRUEUB,
30327
30328   IX86_BUILTIN_VPCOMEQUW,
30329   IX86_BUILTIN_VPCOMNEUW,
30330   IX86_BUILTIN_VPCOMLTUW,
30331   IX86_BUILTIN_VPCOMLEUW,
30332   IX86_BUILTIN_VPCOMGTUW,
30333   IX86_BUILTIN_VPCOMGEUW,
30334   IX86_BUILTIN_VPCOMFALSEUW,
30335   IX86_BUILTIN_VPCOMTRUEUW,
30336
30337   IX86_BUILTIN_VPCOMEQUD,
30338   IX86_BUILTIN_VPCOMNEUD,
30339   IX86_BUILTIN_VPCOMLTUD,
30340   IX86_BUILTIN_VPCOMLEUD,
30341   IX86_BUILTIN_VPCOMGTUD,
30342   IX86_BUILTIN_VPCOMGEUD,
30343   IX86_BUILTIN_VPCOMFALSEUD,
30344   IX86_BUILTIN_VPCOMTRUEUD,
30345
30346   IX86_BUILTIN_VPCOMEQUQ,
30347   IX86_BUILTIN_VPCOMNEUQ,
30348   IX86_BUILTIN_VPCOMLTUQ,
30349   IX86_BUILTIN_VPCOMLEUQ,
30350   IX86_BUILTIN_VPCOMGTUQ,
30351   IX86_BUILTIN_VPCOMGEUQ,
30352   IX86_BUILTIN_VPCOMFALSEUQ,
30353   IX86_BUILTIN_VPCOMTRUEUQ,
30354
30355   IX86_BUILTIN_VPCOMEQB,
30356   IX86_BUILTIN_VPCOMNEB,
30357   IX86_BUILTIN_VPCOMLTB,
30358   IX86_BUILTIN_VPCOMLEB,
30359   IX86_BUILTIN_VPCOMGTB,
30360   IX86_BUILTIN_VPCOMGEB,
30361   IX86_BUILTIN_VPCOMFALSEB,
30362   IX86_BUILTIN_VPCOMTRUEB,
30363
30364   IX86_BUILTIN_VPCOMEQW,
30365   IX86_BUILTIN_VPCOMNEW,
30366   IX86_BUILTIN_VPCOMLTW,
30367   IX86_BUILTIN_VPCOMLEW,
30368   IX86_BUILTIN_VPCOMGTW,
30369   IX86_BUILTIN_VPCOMGEW,
30370   IX86_BUILTIN_VPCOMFALSEW,
30371   IX86_BUILTIN_VPCOMTRUEW,
30372
30373   IX86_BUILTIN_VPCOMEQD,
30374   IX86_BUILTIN_VPCOMNED,
30375   IX86_BUILTIN_VPCOMLTD,
30376   IX86_BUILTIN_VPCOMLED,
30377   IX86_BUILTIN_VPCOMGTD,
30378   IX86_BUILTIN_VPCOMGED,
30379   IX86_BUILTIN_VPCOMFALSED,
30380   IX86_BUILTIN_VPCOMTRUED,
30381
30382   IX86_BUILTIN_VPCOMEQQ,
30383   IX86_BUILTIN_VPCOMNEQ,
30384   IX86_BUILTIN_VPCOMLTQ,
30385   IX86_BUILTIN_VPCOMLEQ,
30386   IX86_BUILTIN_VPCOMGTQ,
30387   IX86_BUILTIN_VPCOMGEQ,
30388   IX86_BUILTIN_VPCOMFALSEQ,
30389   IX86_BUILTIN_VPCOMTRUEQ,
30390
30391   /* LWP instructions.  */
30392   IX86_BUILTIN_LLWPCB,
30393   IX86_BUILTIN_SLWPCB,
30394   IX86_BUILTIN_LWPVAL32,
30395   IX86_BUILTIN_LWPVAL64,
30396   IX86_BUILTIN_LWPINS32,
30397   IX86_BUILTIN_LWPINS64,
30398
30399   IX86_BUILTIN_CLZS,
30400
30401   /* RTM */
30402   IX86_BUILTIN_XBEGIN,
30403   IX86_BUILTIN_XEND,
30404   IX86_BUILTIN_XABORT,
30405   IX86_BUILTIN_XTEST,
30406
30407   /* MPX */
30408   IX86_BUILTIN_BNDMK,
30409   IX86_BUILTIN_BNDSTX,
30410   IX86_BUILTIN_BNDLDX,
30411   IX86_BUILTIN_BNDCL,
30412   IX86_BUILTIN_BNDCU,
30413   IX86_BUILTIN_BNDRET,
30414   IX86_BUILTIN_BNDNARROW,
30415   IX86_BUILTIN_BNDINT,
30416   IX86_BUILTIN_SIZEOF,
30417   IX86_BUILTIN_BNDLOWER,
30418   IX86_BUILTIN_BNDUPPER,
30419
30420   /* BMI instructions.  */
30421   IX86_BUILTIN_BEXTR32,
30422   IX86_BUILTIN_BEXTR64,
30423   IX86_BUILTIN_CTZS,
30424
30425   /* TBM instructions.  */
30426   IX86_BUILTIN_BEXTRI32,
30427   IX86_BUILTIN_BEXTRI64,
30428
30429   /* BMI2 instructions. */
30430   IX86_BUILTIN_BZHI32,
30431   IX86_BUILTIN_BZHI64,
30432   IX86_BUILTIN_PDEP32,
30433   IX86_BUILTIN_PDEP64,
30434   IX86_BUILTIN_PEXT32,
30435   IX86_BUILTIN_PEXT64,
30436
30437   /* ADX instructions.  */
30438   IX86_BUILTIN_ADDCARRYX32,
30439   IX86_BUILTIN_ADDCARRYX64,
30440
30441   /* SBB instructions.  */
30442   IX86_BUILTIN_SBB32,
30443   IX86_BUILTIN_SBB64,
30444
30445   /* FSGSBASE instructions.  */
30446   IX86_BUILTIN_RDFSBASE32,
30447   IX86_BUILTIN_RDFSBASE64,
30448   IX86_BUILTIN_RDGSBASE32,
30449   IX86_BUILTIN_RDGSBASE64,
30450   IX86_BUILTIN_WRFSBASE32,
30451   IX86_BUILTIN_WRFSBASE64,
30452   IX86_BUILTIN_WRGSBASE32,
30453   IX86_BUILTIN_WRGSBASE64,
30454
30455   /* RDRND instructions.  */
30456   IX86_BUILTIN_RDRAND16_STEP,
30457   IX86_BUILTIN_RDRAND32_STEP,
30458   IX86_BUILTIN_RDRAND64_STEP,
30459
30460   /* RDSEED instructions.  */
30461   IX86_BUILTIN_RDSEED16_STEP,
30462   IX86_BUILTIN_RDSEED32_STEP,
30463   IX86_BUILTIN_RDSEED64_STEP,
30464
30465   /* F16C instructions.  */
30466   IX86_BUILTIN_CVTPH2PS,
30467   IX86_BUILTIN_CVTPH2PS256,
30468   IX86_BUILTIN_CVTPS2PH,
30469   IX86_BUILTIN_CVTPS2PH256,
30470
30471   /* CFString built-in for darwin */
30472   IX86_BUILTIN_CFSTRING,
30473
30474   /* Builtins to get CPU type and supported features. */
30475   IX86_BUILTIN_CPU_INIT,
30476   IX86_BUILTIN_CPU_IS,
30477   IX86_BUILTIN_CPU_SUPPORTS,
30478
30479   /* Read/write FLAGS register built-ins.  */
30480   IX86_BUILTIN_READ_FLAGS,
30481   IX86_BUILTIN_WRITE_FLAGS,
30482
30483   IX86_BUILTIN_MAX
30484 };
30485
30486 /* Table for the ix86 builtin decls.  */
30487 static GTY(()) tree ix86_builtins[(int) IX86_BUILTIN_MAX];
30488
30489 /* Table of all of the builtin functions that are possible with different ISA's
30490    but are waiting to be built until a function is declared to use that
30491    ISA.  */
30492 struct builtin_isa {
30493   const char *name;             /* function name */
30494   enum ix86_builtin_func_type tcode; /* type to use in the declaration */
30495   HOST_WIDE_INT isa;            /* isa_flags this builtin is defined for */
30496   bool const_p;                 /* true if the declaration is constant */
30497   bool leaf_p;                  /* true if the declaration has leaf attribute */
30498   bool nothrow_p;               /* true if the declaration has nothrow attribute */
30499   bool set_and_not_built_p;
30500 };
30501
30502 static struct builtin_isa ix86_builtins_isa[(int) IX86_BUILTIN_MAX];
30503
30504
30505 /* Add an ix86 target builtin function with CODE, NAME and TYPE.  Save the MASK
30506    of which isa_flags to use in the ix86_builtins_isa array.  Stores the
30507    function decl in the ix86_builtins array.  Returns the function decl or
30508    NULL_TREE, if the builtin was not added.
30509
30510    If the front end has a special hook for builtin functions, delay adding
30511    builtin functions that aren't in the current ISA until the ISA is changed
30512    with function specific optimization.  Doing so, can save about 300K for the
30513    default compiler.  When the builtin is expanded, check at that time whether
30514    it is valid.
30515
30516    If the front end doesn't have a special hook, record all builtins, even if
30517    it isn't an instruction set in the current ISA in case the user uses
30518    function specific options for a different ISA, so that we don't get scope
30519    errors if a builtin is added in the middle of a function scope.  */
30520
30521 static inline tree
30522 def_builtin (HOST_WIDE_INT mask, const char *name,
30523              enum ix86_builtin_func_type tcode,
30524              enum ix86_builtins code)
30525 {
30526   tree decl = NULL_TREE;
30527
30528   if (!(mask & OPTION_MASK_ISA_64BIT) || TARGET_64BIT)
30529     {
30530       ix86_builtins_isa[(int) code].isa = mask;
30531
30532       mask &= ~OPTION_MASK_ISA_64BIT;
30533       if (mask == 0
30534           || (mask & ix86_isa_flags) != 0
30535           || (lang_hooks.builtin_function
30536               == lang_hooks.builtin_function_ext_scope))
30537
30538         {
30539           tree type = ix86_get_builtin_func_type (tcode);
30540           decl = add_builtin_function (name, type, code, BUILT_IN_MD,
30541                                        NULL, NULL_TREE);
30542           ix86_builtins[(int) code] = decl;
30543           ix86_builtins_isa[(int) code].set_and_not_built_p = false;
30544         }
30545       else
30546         {
30547           ix86_builtins[(int) code] = NULL_TREE;
30548           ix86_builtins_isa[(int) code].tcode = tcode;
30549           ix86_builtins_isa[(int) code].name = name;
30550           ix86_builtins_isa[(int) code].leaf_p = false;
30551           ix86_builtins_isa[(int) code].nothrow_p = false;
30552           ix86_builtins_isa[(int) code].const_p = false;
30553           ix86_builtins_isa[(int) code].set_and_not_built_p = true;
30554         }
30555     }
30556
30557   return decl;
30558 }
30559
30560 /* Like def_builtin, but also marks the function decl "const".  */
30561
30562 static inline tree
30563 def_builtin_const (HOST_WIDE_INT mask, const char *name,
30564                    enum ix86_builtin_func_type tcode, enum ix86_builtins code)
30565 {
30566   tree decl = def_builtin (mask, name, tcode, code);
30567   if (decl)
30568     TREE_READONLY (decl) = 1;
30569   else
30570     ix86_builtins_isa[(int) code].const_p = true;
30571
30572   return decl;
30573 }
30574
30575 /* Add any new builtin functions for a given ISA that may not have been
30576    declared.  This saves a bit of space compared to adding all of the
30577    declarations to the tree, even if we didn't use them.  */
30578
30579 static void
30580 ix86_add_new_builtins (HOST_WIDE_INT isa)
30581 {
30582   int i;
30583
30584   for (i = 0; i < (int)IX86_BUILTIN_MAX; i++)
30585     {
30586       if ((ix86_builtins_isa[i].isa & isa) != 0
30587           && ix86_builtins_isa[i].set_and_not_built_p)
30588         {
30589           tree decl, type;
30590
30591           /* Don't define the builtin again.  */
30592           ix86_builtins_isa[i].set_and_not_built_p = false;
30593
30594           type = ix86_get_builtin_func_type (ix86_builtins_isa[i].tcode);
30595           decl = add_builtin_function_ext_scope (ix86_builtins_isa[i].name,
30596                                                  type, i, BUILT_IN_MD, NULL,
30597                                                  NULL_TREE);
30598
30599           ix86_builtins[i] = decl;
30600           if (ix86_builtins_isa[i].const_p)
30601             TREE_READONLY (decl) = 1;
30602           if (ix86_builtins_isa[i].leaf_p)
30603             DECL_ATTRIBUTES (decl) = build_tree_list (get_identifier ("leaf"),
30604                                                       NULL_TREE);
30605           if (ix86_builtins_isa[i].nothrow_p)
30606             TREE_NOTHROW (decl) = 1;
30607         }
30608     }
30609 }
30610
30611 /* Bits for builtin_description.flag.  */
30612
30613 /* Set when we don't support the comparison natively, and should
30614    swap_comparison in order to support it.  */
30615 #define BUILTIN_DESC_SWAP_OPERANDS      1
30616
30617 struct builtin_description
30618 {
30619   const HOST_WIDE_INT mask;
30620   const enum insn_code icode;
30621   const char *const name;
30622   const enum ix86_builtins code;
30623   const enum rtx_code comparison;
30624   const int flag;
30625 };
30626
30627 static const struct builtin_description bdesc_comi[] =
30628 {
30629   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comieq", IX86_BUILTIN_COMIEQSS, UNEQ, 0 },
30630   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comilt", IX86_BUILTIN_COMILTSS, UNLT, 0 },
30631   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comile", IX86_BUILTIN_COMILESS, UNLE, 0 },
30632   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comigt", IX86_BUILTIN_COMIGTSS, GT, 0 },
30633   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comige", IX86_BUILTIN_COMIGESS, GE, 0 },
30634   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_comi, "__builtin_ia32_comineq", IX86_BUILTIN_COMINEQSS, LTGT, 0 },
30635   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomieq", IX86_BUILTIN_UCOMIEQSS, UNEQ, 0 },
30636   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomilt", IX86_BUILTIN_UCOMILTSS, UNLT, 0 },
30637   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomile", IX86_BUILTIN_UCOMILESS, UNLE, 0 },
30638   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomigt", IX86_BUILTIN_UCOMIGTSS, GT, 0 },
30639   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomige", IX86_BUILTIN_UCOMIGESS, GE, 0 },
30640   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_ucomi, "__builtin_ia32_ucomineq", IX86_BUILTIN_UCOMINEQSS, LTGT, 0 },
30641   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdeq", IX86_BUILTIN_COMIEQSD, UNEQ, 0 },
30642   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdlt", IX86_BUILTIN_COMILTSD, UNLT, 0 },
30643   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdle", IX86_BUILTIN_COMILESD, UNLE, 0 },
30644   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdgt", IX86_BUILTIN_COMIGTSD, GT, 0 },
30645   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdge", IX86_BUILTIN_COMIGESD, GE, 0 },
30646   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_comi, "__builtin_ia32_comisdneq", IX86_BUILTIN_COMINEQSD, LTGT, 0 },
30647   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdeq", IX86_BUILTIN_UCOMIEQSD, UNEQ, 0 },
30648   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdlt", IX86_BUILTIN_UCOMILTSD, UNLT, 0 },
30649   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdle", IX86_BUILTIN_UCOMILESD, UNLE, 0 },
30650   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdgt", IX86_BUILTIN_UCOMIGTSD, GT, 0 },
30651   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdge", IX86_BUILTIN_UCOMIGESD, GE, 0 },
30652   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ucomi, "__builtin_ia32_ucomisdneq", IX86_BUILTIN_UCOMINEQSD, LTGT, 0 },
30653 };
30654
30655 static const struct builtin_description bdesc_pcmpestr[] =
30656 {
30657   /* SSE4.2 */
30658   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestri128", IX86_BUILTIN_PCMPESTRI128, UNKNOWN, 0 },
30659   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrm128", IX86_BUILTIN_PCMPESTRM128, UNKNOWN, 0 },
30660   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestria128", IX86_BUILTIN_PCMPESTRA128, UNKNOWN, (int) CCAmode },
30661   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestric128", IX86_BUILTIN_PCMPESTRC128, UNKNOWN, (int) CCCmode },
30662   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestrio128", IX86_BUILTIN_PCMPESTRO128, UNKNOWN, (int) CCOmode },
30663   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestris128", IX86_BUILTIN_PCMPESTRS128, UNKNOWN, (int) CCSmode },
30664   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpestr, "__builtin_ia32_pcmpestriz128", IX86_BUILTIN_PCMPESTRZ128, UNKNOWN, (int) CCZmode },
30665 };
30666
30667 static const struct builtin_description bdesc_pcmpistr[] =
30668 {
30669   /* SSE4.2 */
30670   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistri128", IX86_BUILTIN_PCMPISTRI128, UNKNOWN, 0 },
30671   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrm128", IX86_BUILTIN_PCMPISTRM128, UNKNOWN, 0 },
30672   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistria128", IX86_BUILTIN_PCMPISTRA128, UNKNOWN, (int) CCAmode },
30673   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistric128", IX86_BUILTIN_PCMPISTRC128, UNKNOWN, (int) CCCmode },
30674   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistrio128", IX86_BUILTIN_PCMPISTRO128, UNKNOWN, (int) CCOmode },
30675   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistris128", IX86_BUILTIN_PCMPISTRS128, UNKNOWN, (int) CCSmode },
30676   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_pcmpistr, "__builtin_ia32_pcmpistriz128", IX86_BUILTIN_PCMPISTRZ128, UNKNOWN, (int) CCZmode },
30677 };
30678
30679 /* Special builtins with variable number of arguments.  */
30680 static const struct builtin_description bdesc_special_args[] =
30681 {
30682   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_rdtsc", IX86_BUILTIN_RDTSC, UNKNOWN, (int) UINT64_FTYPE_VOID },
30683   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_rdtscp", IX86_BUILTIN_RDTSCP, UNKNOWN, (int) UINT64_FTYPE_PUNSIGNED },
30684   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_pause, "__builtin_ia32_pause", IX86_BUILTIN_PAUSE, UNKNOWN, (int) VOID_FTYPE_VOID },
30685
30686   /* 80387 (for use internally for atomic compound assignment).  */
30687   { 0, CODE_FOR_fnstenv, "__builtin_ia32_fnstenv", IX86_BUILTIN_FNSTENV, UNKNOWN, (int) VOID_FTYPE_PVOID },
30688   { 0, CODE_FOR_fldenv, "__builtin_ia32_fldenv", IX86_BUILTIN_FLDENV, UNKNOWN, (int) VOID_FTYPE_PCVOID },
30689   { 0, CODE_FOR_fnstsw, "__builtin_ia32_fnstsw", IX86_BUILTIN_FNSTSW, UNKNOWN, (int) USHORT_FTYPE_VOID },
30690   { 0, CODE_FOR_fnclex, "__builtin_ia32_fnclex", IX86_BUILTIN_FNCLEX, UNKNOWN, (int) VOID_FTYPE_VOID },
30691
30692   /* MMX */
30693   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_emms, "__builtin_ia32_emms", IX86_BUILTIN_EMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
30694
30695   /* 3DNow! */
30696   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_femms, "__builtin_ia32_femms", IX86_BUILTIN_FEMMS, UNKNOWN, (int) VOID_FTYPE_VOID },
30697
30698   /* FXSR, XSAVE, XSAVEOPT, XSAVEC and XSAVES.  */
30699   { OPTION_MASK_ISA_FXSR, CODE_FOR_nothing, "__builtin_ia32_fxsave", IX86_BUILTIN_FXSAVE, UNKNOWN, (int) VOID_FTYPE_PVOID },
30700   { OPTION_MASK_ISA_FXSR, CODE_FOR_nothing, "__builtin_ia32_fxrstor", IX86_BUILTIN_FXRSTOR, UNKNOWN, (int) VOID_FTYPE_PVOID },
30701   { OPTION_MASK_ISA_XSAVE, CODE_FOR_nothing, "__builtin_ia32_xsave", IX86_BUILTIN_XSAVE, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30702   { OPTION_MASK_ISA_XSAVE, CODE_FOR_nothing, "__builtin_ia32_xrstor", IX86_BUILTIN_XRSTOR, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30703   { OPTION_MASK_ISA_XSAVEOPT, CODE_FOR_nothing, "__builtin_ia32_xsaveopt", IX86_BUILTIN_XSAVEOPT, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30704   { OPTION_MASK_ISA_XSAVES, CODE_FOR_nothing, "__builtin_ia32_xsaves", IX86_BUILTIN_XSAVES, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30705   { OPTION_MASK_ISA_XSAVES, CODE_FOR_nothing, "__builtin_ia32_xrstors", IX86_BUILTIN_XRSTORS, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30706   { OPTION_MASK_ISA_XSAVEC, CODE_FOR_nothing, "__builtin_ia32_xsavec", IX86_BUILTIN_XSAVEC, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30707
30708   { OPTION_MASK_ISA_FXSR | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_fxsave64", IX86_BUILTIN_FXSAVE64, UNKNOWN, (int) VOID_FTYPE_PVOID },
30709   { OPTION_MASK_ISA_FXSR | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_fxrstor64", IX86_BUILTIN_FXRSTOR64, UNKNOWN, (int) VOID_FTYPE_PVOID },
30710   { OPTION_MASK_ISA_XSAVE | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsave64", IX86_BUILTIN_XSAVE64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30711   { OPTION_MASK_ISA_XSAVE | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xrstor64", IX86_BUILTIN_XRSTOR64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30712   { OPTION_MASK_ISA_XSAVEOPT | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsaveopt64", IX86_BUILTIN_XSAVEOPT64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30713   { OPTION_MASK_ISA_XSAVES | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsaves64", IX86_BUILTIN_XSAVES64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30714   { OPTION_MASK_ISA_XSAVES | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xrstors64", IX86_BUILTIN_XRSTORS64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30715   { OPTION_MASK_ISA_XSAVEC | OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_xsavec64", IX86_BUILTIN_XSAVEC64, UNKNOWN, (int) VOID_FTYPE_PVOID_INT64 },
30716
30717   /* SSE */
30718   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storeups, "__builtin_ia32_storeups", IX86_BUILTIN_STOREUPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
30719   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movntv4sf, "__builtin_ia32_movntps", IX86_BUILTIN_MOVNTPS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
30720   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadups, "__builtin_ia32_loadups", IX86_BUILTIN_LOADUPS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
30721
30722   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadhps_exp, "__builtin_ia32_loadhps", IX86_BUILTIN_LOADHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
30723   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_loadlps_exp, "__builtin_ia32_loadlps", IX86_BUILTIN_LOADLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_PCV2SF },
30724   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storehps, "__builtin_ia32_storehps", IX86_BUILTIN_STOREHPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
30725   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_storelps, "__builtin_ia32_storelps", IX86_BUILTIN_STORELPS, UNKNOWN, (int) VOID_FTYPE_PV2SF_V4SF },
30726
30727   /* SSE or 3DNow!A  */
30728   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_sfence, "__builtin_ia32_sfence", IX86_BUILTIN_SFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
30729   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_sse_movntq, "__builtin_ia32_movntq", IX86_BUILTIN_MOVNTQ, UNKNOWN, (int) VOID_FTYPE_PULONGLONG_ULONGLONG },
30730
30731   /* SSE2 */
30732   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lfence, "__builtin_ia32_lfence", IX86_BUILTIN_LFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
30733   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_mfence, 0, IX86_BUILTIN_MFENCE, UNKNOWN, (int) VOID_FTYPE_VOID },
30734   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_storeupd, "__builtin_ia32_storeupd", IX86_BUILTIN_STOREUPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
30735   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_storedquv16qi, "__builtin_ia32_storedqu", IX86_BUILTIN_STOREDQU, UNKNOWN, (int) VOID_FTYPE_PCHAR_V16QI },
30736   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2df, "__builtin_ia32_movntpd", IX86_BUILTIN_MOVNTPD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
30737   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntv2di, "__builtin_ia32_movntdq", IX86_BUILTIN_MOVNTDQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI },
30738   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movntisi, "__builtin_ia32_movnti", IX86_BUILTIN_MOVNTI, UNKNOWN, (int) VOID_FTYPE_PINT_INT },
30739   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_movntidi, "__builtin_ia32_movnti64", IX86_BUILTIN_MOVNTI64, UNKNOWN, (int) VOID_FTYPE_PLONGLONG_LONGLONG },
30740   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadupd, "__builtin_ia32_loadupd", IX86_BUILTIN_LOADUPD, UNKNOWN, (int) V2DF_FTYPE_PCDOUBLE },
30741   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loaddquv16qi, "__builtin_ia32_loaddqu", IX86_BUILTIN_LOADDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
30742
30743   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadhpd_exp, "__builtin_ia32_loadhpd", IX86_BUILTIN_LOADHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
30744   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_loadlpd_exp, "__builtin_ia32_loadlpd", IX86_BUILTIN_LOADLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_PCDOUBLE },
30745
30746   /* SSE3 */
30747   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_lddqu, "__builtin_ia32_lddqu", IX86_BUILTIN_LDDQU, UNKNOWN, (int) V16QI_FTYPE_PCCHAR },
30748
30749   /* SSE4.1 */
30750   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_movntdqa, "__builtin_ia32_movntdqa", IX86_BUILTIN_MOVNTDQA, UNKNOWN, (int) V2DI_FTYPE_PV2DI },
30751
30752   /* SSE4A */
30753   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv2df, "__builtin_ia32_movntsd", IX86_BUILTIN_MOVNTSD, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V2DF },
30754   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_vmmovntv4sf, "__builtin_ia32_movntss", IX86_BUILTIN_MOVNTSS, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V4SF },
30755
30756   /* AVX */
30757   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroall, "__builtin_ia32_vzeroall", IX86_BUILTIN_VZEROALL, UNKNOWN, (int) VOID_FTYPE_VOID },
30758   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vzeroupper, "__builtin_ia32_vzeroupper", IX86_BUILTIN_VZEROUPPER, UNKNOWN, (int) VOID_FTYPE_VOID },
30759
30760   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_dupv4sf, "__builtin_ia32_vbroadcastss", IX86_BUILTIN_VBROADCASTSS, UNKNOWN, (int) V4SF_FTYPE_PCFLOAT },
30761   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_dupv4df, "__builtin_ia32_vbroadcastsd256", IX86_BUILTIN_VBROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
30762   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_dupv8sf, "__builtin_ia32_vbroadcastss256", IX86_BUILTIN_VBROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
30763   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_v4df, "__builtin_ia32_vbroadcastf128_pd256", IX86_BUILTIN_VBROADCASTPD256, UNKNOWN, (int) V4DF_FTYPE_PCV2DF },
30764   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vbroadcastf128_v8sf, "__builtin_ia32_vbroadcastf128_ps256", IX86_BUILTIN_VBROADCASTPS256, UNKNOWN, (int) V8SF_FTYPE_PCV4SF },
30765
30766   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_loadupd256, "__builtin_ia32_loadupd256", IX86_BUILTIN_LOADUPD256, UNKNOWN, (int) V4DF_FTYPE_PCDOUBLE },
30767   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_loadups256, "__builtin_ia32_loadups256", IX86_BUILTIN_LOADUPS256, UNKNOWN, (int) V8SF_FTYPE_PCFLOAT },
30768   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_storeupd256, "__builtin_ia32_storeupd256", IX86_BUILTIN_STOREUPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
30769   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_storeups256, "__builtin_ia32_storeups256", IX86_BUILTIN_STOREUPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
30770   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_loaddquv32qi, "__builtin_ia32_loaddqu256", IX86_BUILTIN_LOADDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
30771   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_storedquv32qi, "__builtin_ia32_storedqu256", IX86_BUILTIN_STOREDQU256, UNKNOWN, (int) VOID_FTYPE_PCHAR_V32QI },
30772   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_lddqu256, "__builtin_ia32_lddqu256", IX86_BUILTIN_LDDQU256, UNKNOWN, (int) V32QI_FTYPE_PCCHAR },
30773
30774   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4di, "__builtin_ia32_movntdq256", IX86_BUILTIN_MOVNTDQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI },
30775   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv4df, "__builtin_ia32_movntpd256", IX86_BUILTIN_MOVNTPD256, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V4DF },
30776   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movntv8sf, "__builtin_ia32_movntps256", IX86_BUILTIN_MOVNTPS256, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V8SF },
30777
30778   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd, "__builtin_ia32_maskloadpd", IX86_BUILTIN_MASKLOADPD, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DI },
30779   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps, "__builtin_ia32_maskloadps", IX86_BUILTIN_MASKLOADPS, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SI },
30780   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadpd256, "__builtin_ia32_maskloadpd256", IX86_BUILTIN_MASKLOADPD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DI },
30781   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskloadps256, "__builtin_ia32_maskloadps256", IX86_BUILTIN_MASKLOADPS256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SI },
30782   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd, "__builtin_ia32_maskstorepd", IX86_BUILTIN_MASKSTOREPD, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DI_V2DF },
30783   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps, "__builtin_ia32_maskstoreps", IX86_BUILTIN_MASKSTOREPS, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SI_V4SF },
30784   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstorepd256, "__builtin_ia32_maskstorepd256", IX86_BUILTIN_MASKSTOREPD256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DI_V4DF },
30785   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_maskstoreps256, "__builtin_ia32_maskstoreps256", IX86_BUILTIN_MASKSTOREPS256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SI_V8SF },
30786
30787   /* AVX2 */
30788   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_movntdqa, "__builtin_ia32_movntdqa256", IX86_BUILTIN_MOVNTDQA256, UNKNOWN, (int) V4DI_FTYPE_PV4DI },
30789   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadd, "__builtin_ia32_maskloadd", IX86_BUILTIN_MASKLOADD, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI },
30790   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadq, "__builtin_ia32_maskloadq", IX86_BUILTIN_MASKLOADQ, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI },
30791   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadd256, "__builtin_ia32_maskloadd256", IX86_BUILTIN_MASKLOADD256, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI },
30792   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskloadq256, "__builtin_ia32_maskloadq256", IX86_BUILTIN_MASKLOADQ256, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI },
30793   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstored, "__builtin_ia32_maskstored", IX86_BUILTIN_MASKSTORED, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_V4SI },
30794   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstoreq, "__builtin_ia32_maskstoreq", IX86_BUILTIN_MASKSTOREQ, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_V2DI },
30795   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstored256, "__builtin_ia32_maskstored256", IX86_BUILTIN_MASKSTORED256, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_V8SI },
30796   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_maskstoreq256, "__builtin_ia32_maskstoreq256", IX86_BUILTIN_MASKSTOREQ256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_V4DI },
30797
30798   /* AVX512F */
30799   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev16sf_mask, "__builtin_ia32_compressstoresf512_mask", IX86_BUILTIN_COMPRESSPSSTORE512, UNKNOWN, (int) VOID_FTYPE_PV16SF_V16SF_HI },
30800   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev16si_mask, "__builtin_ia32_compressstoresi512_mask", IX86_BUILTIN_PCOMPRESSDSTORE512, UNKNOWN, (int) VOID_FTYPE_PV16SI_V16SI_HI },
30801   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev8df_mask, "__builtin_ia32_compressstoredf512_mask", IX86_BUILTIN_COMPRESSPDSTORE512, UNKNOWN, (int) VOID_FTYPE_PV8DF_V8DF_QI },
30802   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressstorev8di_mask, "__builtin_ia32_compressstoredi512_mask", IX86_BUILTIN_PCOMPRESSQSTORE512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI_QI },
30803   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_mask, "__builtin_ia32_expandloadsf512_mask", IX86_BUILTIN_EXPANDPSLOAD512, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30804   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_maskz, "__builtin_ia32_expandloadsf512_maskz", IX86_BUILTIN_EXPANDPSLOAD512Z, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30805   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_mask, "__builtin_ia32_expandloadsi512_mask", IX86_BUILTIN_PEXPANDDLOAD512, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30806   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_maskz, "__builtin_ia32_expandloadsi512_maskz", IX86_BUILTIN_PEXPANDDLOAD512Z, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30807   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_mask, "__builtin_ia32_expandloaddf512_mask", IX86_BUILTIN_EXPANDPDLOAD512, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30808   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_maskz, "__builtin_ia32_expandloaddf512_maskz", IX86_BUILTIN_EXPANDPDLOAD512Z, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30809   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_mask, "__builtin_ia32_expandloaddi512_mask", IX86_BUILTIN_PEXPANDQLOAD512, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30810   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_maskz, "__builtin_ia32_expandloaddi512_maskz", IX86_BUILTIN_PEXPANDQLOAD512Z, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30811   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loaddquv16si_mask, "__builtin_ia32_loaddqusi512_mask", IX86_BUILTIN_LOADDQUSI512, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30812   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loaddquv8di_mask, "__builtin_ia32_loaddqudi512_mask", IX86_BUILTIN_LOADDQUDI512, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30813   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadupd512_mask, "__builtin_ia32_loadupd512_mask", IX86_BUILTIN_LOADUPD512, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30814   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadups512_mask, "__builtin_ia32_loadups512_mask", IX86_BUILTIN_LOADUPS512, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30815   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16sf_mask, "__builtin_ia32_loadaps512_mask", IX86_BUILTIN_LOADAPS512, UNKNOWN, (int) V16SF_FTYPE_PCV16SF_V16SF_HI },
30816   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16si_mask, "__builtin_ia32_movdqa32load512_mask", IX86_BUILTIN_MOVDQA32LOAD512, UNKNOWN, (int) V16SI_FTYPE_PCV16SI_V16SI_HI },
30817   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8df_mask, "__builtin_ia32_loadapd512_mask", IX86_BUILTIN_LOADAPD512, UNKNOWN, (int) V8DF_FTYPE_PCV8DF_V8DF_QI },
30818   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8di_mask, "__builtin_ia32_movdqa64load512_mask", IX86_BUILTIN_MOVDQA64LOAD512, UNKNOWN, (int) V8DI_FTYPE_PCV8DI_V8DI_QI },
30819   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntv16sf, "__builtin_ia32_movntps512", IX86_BUILTIN_MOVNTPS512, UNKNOWN, (int) VOID_FTYPE_PFLOAT_V16SF },
30820   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntv8df, "__builtin_ia32_movntpd512", IX86_BUILTIN_MOVNTPD512, UNKNOWN, (int) VOID_FTYPE_PDOUBLE_V8DF },
30821   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntv8di, "__builtin_ia32_movntdq512", IX86_BUILTIN_MOVNTDQ512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI },
30822   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movntdqa, "__builtin_ia32_movntdqa512", IX86_BUILTIN_MOVNTDQA512, UNKNOWN, (int) V8DI_FTYPE_PV8DI },
30823   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storedquv16si_mask, "__builtin_ia32_storedqusi512_mask", IX86_BUILTIN_STOREDQUSI512, UNKNOWN, (int) VOID_FTYPE_PV16SI_V16SI_HI },
30824   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storedquv8di_mask, "__builtin_ia32_storedqudi512_mask", IX86_BUILTIN_STOREDQUDI512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI_QI },
30825   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storeupd512_mask, "__builtin_ia32_storeupd512_mask", IX86_BUILTIN_STOREUPD512, UNKNOWN, (int) VOID_FTYPE_PV8DF_V8DF_QI },
30826   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div8si2_mask_store, "__builtin_ia32_pmovusqd512mem_mask", IX86_BUILTIN_PMOVUSQD512_MEM, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8DI_QI },
30827   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div8si2_mask_store, "__builtin_ia32_pmovsqd512mem_mask", IX86_BUILTIN_PMOVSQD512_MEM, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8DI_QI },
30828   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div8si2_mask_store, "__builtin_ia32_pmovqd512mem_mask", IX86_BUILTIN_PMOVQD512_MEM, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8DI_QI },
30829   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div8hi2_mask_store, "__builtin_ia32_pmovusqw512mem_mask", IX86_BUILTIN_PMOVUSQW512_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V8DI_QI },
30830   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div8hi2_mask_store, "__builtin_ia32_pmovsqw512mem_mask", IX86_BUILTIN_PMOVSQW512_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V8DI_QI },
30831   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div8hi2_mask_store, "__builtin_ia32_pmovqw512mem_mask", IX86_BUILTIN_PMOVQW512_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V8DI_QI },
30832   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev16siv16hi2_mask_store, "__builtin_ia32_pmovusdw512mem_mask", IX86_BUILTIN_PMOVUSDW512_MEM, UNKNOWN, (int) VOID_FTYPE_PV16HI_V16SI_HI },
30833   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev16siv16hi2_mask_store, "__builtin_ia32_pmovsdw512mem_mask", IX86_BUILTIN_PMOVSDW512_MEM, UNKNOWN, (int) VOID_FTYPE_PV16HI_V16SI_HI },
30834   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev16siv16hi2_mask_store, "__builtin_ia32_pmovdw512mem_mask", IX86_BUILTIN_PMOVDW512_MEM, UNKNOWN, (int) VOID_FTYPE_PV16HI_V16SI_HI },
30835   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div16qi2_mask_store, "__builtin_ia32_pmovqb512mem_mask", IX86_BUILTIN_PMOVQB512_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V8DI_QI },
30836   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div16qi2_mask_store, "__builtin_ia32_pmovusqb512mem_mask", IX86_BUILTIN_PMOVUSQB512_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V8DI_QI },
30837   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div16qi2_mask_store, "__builtin_ia32_pmovsqb512mem_mask", IX86_BUILTIN_PMOVSQB512_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V8DI_QI },
30838   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev16siv16qi2_mask_store, "__builtin_ia32_pmovusdb512mem_mask", IX86_BUILTIN_PMOVUSDB512_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V16SI_HI },
30839   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev16siv16qi2_mask_store, "__builtin_ia32_pmovsdb512mem_mask", IX86_BUILTIN_PMOVSDB512_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V16SI_HI },
30840   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev16siv16qi2_mask_store, "__builtin_ia32_pmovdb512mem_mask", IX86_BUILTIN_PMOVDB512_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V16SI_HI },
30841   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storeups512_mask, "__builtin_ia32_storeups512_mask", IX86_BUILTIN_STOREUPS512, UNKNOWN, (int) VOID_FTYPE_PV16SF_V16SF_HI },
30842   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev16sf_mask, "__builtin_ia32_storeaps512_mask", IX86_BUILTIN_STOREAPS512, UNKNOWN, (int) VOID_FTYPE_PV16SF_V16SF_HI },
30843   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev16si_mask, "__builtin_ia32_movdqa32store512_mask", IX86_BUILTIN_MOVDQA32STORE512, UNKNOWN, (int) VOID_FTYPE_PV16SI_V16SI_HI },
30844   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev8df_mask, "__builtin_ia32_storeapd512_mask", IX86_BUILTIN_STOREAPD512, UNKNOWN, (int) VOID_FTYPE_PV8DF_V8DF_QI },
30845   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_storev8di_mask, "__builtin_ia32_movdqa64store512_mask", IX86_BUILTIN_MOVDQA64STORE512, UNKNOWN, (int) VOID_FTYPE_PV8DI_V8DI_QI },
30846
30847   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_llwpcb, "__builtin_ia32_llwpcb", IX86_BUILTIN_LLWPCB, UNKNOWN, (int) VOID_FTYPE_PVOID },
30848   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_slwpcb, "__builtin_ia32_slwpcb", IX86_BUILTIN_SLWPCB, UNKNOWN, (int) PVOID_FTYPE_VOID },
30849   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpvalsi3, "__builtin_ia32_lwpval32", IX86_BUILTIN_LWPVAL32, UNKNOWN, (int) VOID_FTYPE_UINT_UINT_UINT },
30850   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpvaldi3, "__builtin_ia32_lwpval64", IX86_BUILTIN_LWPVAL64, UNKNOWN, (int) VOID_FTYPE_UINT64_UINT_UINT },
30851   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpinssi3, "__builtin_ia32_lwpins32", IX86_BUILTIN_LWPINS32, UNKNOWN, (int) UCHAR_FTYPE_UINT_UINT_UINT },
30852   { OPTION_MASK_ISA_LWP, CODE_FOR_lwp_lwpinsdi3, "__builtin_ia32_lwpins64", IX86_BUILTIN_LWPINS64, UNKNOWN, (int) UCHAR_FTYPE_UINT64_UINT_UINT },
30853
30854   /* FSGSBASE */
30855   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdfsbasesi, "__builtin_ia32_rdfsbase32", IX86_BUILTIN_RDFSBASE32, UNKNOWN, (int) UNSIGNED_FTYPE_VOID },
30856   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdfsbasedi, "__builtin_ia32_rdfsbase64", IX86_BUILTIN_RDFSBASE64, UNKNOWN, (int) UINT64_FTYPE_VOID },
30857   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdgsbasesi, "__builtin_ia32_rdgsbase32", IX86_BUILTIN_RDGSBASE32, UNKNOWN, (int) UNSIGNED_FTYPE_VOID },
30858   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_rdgsbasedi, "__builtin_ia32_rdgsbase64", IX86_BUILTIN_RDGSBASE64, UNKNOWN, (int) UINT64_FTYPE_VOID },
30859   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrfsbasesi, "__builtin_ia32_wrfsbase32", IX86_BUILTIN_WRFSBASE32, UNKNOWN, (int) VOID_FTYPE_UNSIGNED },
30860   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrfsbasedi, "__builtin_ia32_wrfsbase64", IX86_BUILTIN_WRFSBASE64, UNKNOWN, (int) VOID_FTYPE_UINT64 },
30861   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrgsbasesi, "__builtin_ia32_wrgsbase32", IX86_BUILTIN_WRGSBASE32, UNKNOWN, (int) VOID_FTYPE_UNSIGNED },
30862   { OPTION_MASK_ISA_FSGSBASE | OPTION_MASK_ISA_64BIT, CODE_FOR_wrgsbasedi, "__builtin_ia32_wrgsbase64", IX86_BUILTIN_WRGSBASE64, UNKNOWN, (int) VOID_FTYPE_UINT64 },
30863
30864   /* RTM */
30865   { OPTION_MASK_ISA_RTM, CODE_FOR_xbegin, "__builtin_ia32_xbegin", IX86_BUILTIN_XBEGIN, UNKNOWN, (int) UNSIGNED_FTYPE_VOID },
30866   { OPTION_MASK_ISA_RTM, CODE_FOR_xend, "__builtin_ia32_xend", IX86_BUILTIN_XEND, UNKNOWN, (int) VOID_FTYPE_VOID },
30867   { OPTION_MASK_ISA_RTM, CODE_FOR_xtest, "__builtin_ia32_xtest", IX86_BUILTIN_XTEST, UNKNOWN, (int) INT_FTYPE_VOID },
30868
30869   /* AVX512BW */
30870   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_loaddquv32hi_mask, "__builtin_ia32_loaddquhi512_mask", IX86_BUILTIN_LOADDQUHI512_MASK, UNKNOWN, (int) V32HI_FTYPE_PCV32HI_V32HI_SI },
30871   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512f_loaddquv64qi_mask, "__builtin_ia32_loaddquqi512_mask", IX86_BUILTIN_LOADDQUQI512_MASK, UNKNOWN, (int) V64QI_FTYPE_PCV64QI_V64QI_DI },
30872   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_storedquv32hi_mask, "__builtin_ia32_storedquhi512_mask", IX86_BUILTIN_STOREDQUHI512_MASK, UNKNOWN, (int) VOID_FTYPE_PV32HI_V32HI_SI },
30873   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_storedquv64qi_mask, "__builtin_ia32_storedquqi512_mask", IX86_BUILTIN_STOREDQUQI512_MASK, UNKNOWN, (int) VOID_FTYPE_PV64QI_V64QI_DI },
30874
30875   /* AVX512VL */
30876   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv16hi_mask, "__builtin_ia32_loaddquhi256_mask", IX86_BUILTIN_LOADDQUHI256_MASK, UNKNOWN, (int) V16HI_FTYPE_PCV16HI_V16HI_HI },
30877   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv8hi_mask, "__builtin_ia32_loaddquhi128_mask", IX86_BUILTIN_LOADDQUHI128_MASK, UNKNOWN, (int) V8HI_FTYPE_PCV8HI_V8HI_QI },
30878   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loaddquv32qi_mask, "__builtin_ia32_loaddquqi256_mask", IX86_BUILTIN_LOADDQUQI256_MASK, UNKNOWN, (int) V32QI_FTYPE_PCV32QI_V32QI_SI },
30879   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_loaddquv16qi_mask, "__builtin_ia32_loaddquqi128_mask", IX86_BUILTIN_LOADDQUQI128_MASK, UNKNOWN, (int) V16QI_FTYPE_PCV16QI_V16QI_HI },
30880   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4di_mask, "__builtin_ia32_movdqa64load256_mask", IX86_BUILTIN_MOVDQA64LOAD256_MASK, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
30881   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2di_mask, "__builtin_ia32_movdqa64load128_mask", IX86_BUILTIN_MOVDQA64LOAD128_MASK, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
30882   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8si_mask, "__builtin_ia32_movdqa32load256_mask", IX86_BUILTIN_MOVDQA32LOAD256_MASK, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
30883   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4si_mask, "__builtin_ia32_movdqa32load128_mask", IX86_BUILTIN_MOVDQA32LOAD128_MASK, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
30884   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4di_mask, "__builtin_ia32_movdqa64store256_mask", IX86_BUILTIN_MOVDQA64STORE256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_QI },
30885   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev2di_mask, "__builtin_ia32_movdqa64store128_mask", IX86_BUILTIN_MOVDQA64STORE128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_QI },
30886   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev8si_mask, "__builtin_ia32_movdqa32store256_mask", IX86_BUILTIN_MOVDQA32STORE256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_QI },
30887   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4si_mask, "__builtin_ia32_movdqa32store128_mask", IX86_BUILTIN_MOVDQA32STORE128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_QI },
30888   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4df_mask, "__builtin_ia32_loadapd256_mask", IX86_BUILTIN_LOADAPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
30889   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2df_mask, "__builtin_ia32_loadapd128_mask", IX86_BUILTIN_LOADAPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
30890   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8sf_mask, "__builtin_ia32_loadaps256_mask", IX86_BUILTIN_LOADAPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
30891   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4sf_mask, "__builtin_ia32_loadaps128_mask", IX86_BUILTIN_LOADAPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
30892   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4df_mask, "__builtin_ia32_storeapd256_mask", IX86_BUILTIN_STOREAPD256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_QI },
30893   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev2df_mask, "__builtin_ia32_storeapd128_mask", IX86_BUILTIN_STOREAPD128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_QI },
30894   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev8sf_mask, "__builtin_ia32_storeaps256_mask", IX86_BUILTIN_STOREAPS256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_QI },
30895   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storev4sf_mask, "__builtin_ia32_storeaps128_mask", IX86_BUILTIN_STOREAPS128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_QI },
30896   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loadupd256_mask, "__builtin_ia32_loadupd256_mask", IX86_BUILTIN_LOADUPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
30897   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_loadupd_mask, "__builtin_ia32_loadupd128_mask", IX86_BUILTIN_LOADUPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
30898   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loadups256_mask, "__builtin_ia32_loadups256_mask", IX86_BUILTIN_LOADUPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
30899   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse_loadups_mask, "__builtin_ia32_loadups128_mask", IX86_BUILTIN_LOADUPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
30900   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeupd256_mask, "__builtin_ia32_storeupd256_mask", IX86_BUILTIN_STOREUPD256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_QI },
30901   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeupd_mask, "__builtin_ia32_storeupd128_mask", IX86_BUILTIN_STOREUPD128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_QI },
30902   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeups256_mask, "__builtin_ia32_storeups256_mask", IX86_BUILTIN_STOREUPS256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_QI },
30903   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storeups_mask, "__builtin_ia32_storeups128_mask", IX86_BUILTIN_STOREUPS128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_QI },
30904   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv4di_mask, "__builtin_ia32_loaddqudi256_mask", IX86_BUILTIN_LOADDQUDI256_MASK, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
30905   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv2di_mask, "__builtin_ia32_loaddqudi128_mask", IX86_BUILTIN_LOADDQUDI128_MASK, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
30906   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loaddquv8si_mask, "__builtin_ia32_loaddqusi256_mask", IX86_BUILTIN_LOADDQUSI256_MASK, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
30907   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_loaddquv4si_mask, "__builtin_ia32_loaddqusi128_mask", IX86_BUILTIN_LOADDQUSI128_MASK, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
30908   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv4di_mask, "__builtin_ia32_storedqudi256_mask", IX86_BUILTIN_STOREDQUDI256_MASK, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_QI },
30909   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv2di_mask, "__builtin_ia32_storedqudi128_mask", IX86_BUILTIN_STOREDQUDI128_MASK, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_QI },
30910   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv8si_mask, "__builtin_ia32_storedqusi256_mask", IX86_BUILTIN_STOREDQUSI256_MASK, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_QI },
30911   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv4si_mask, "__builtin_ia32_storedqusi128_mask", IX86_BUILTIN_STOREDQUSI128_MASK, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_QI },
30912   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv16hi_mask, "__builtin_ia32_storedquhi256_mask", IX86_BUILTIN_STOREDQUHI256_MASK, UNKNOWN, (int) VOID_FTYPE_PV16HI_V16HI_HI },
30913   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv8hi_mask, "__builtin_ia32_storedquhi128_mask", IX86_BUILTIN_STOREDQUHI128_MASK, UNKNOWN, (int) VOID_FTYPE_PV8HI_V8HI_QI },
30914   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv32qi_mask, "__builtin_ia32_storedquqi256_mask", IX86_BUILTIN_STOREDQUQI256_MASK, UNKNOWN, (int) VOID_FTYPE_PV32QI_V32QI_SI },
30915   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_storedquv16qi_mask, "__builtin_ia32_storedquqi128_mask", IX86_BUILTIN_STOREDQUQI128_MASK, UNKNOWN, (int) VOID_FTYPE_PV16QI_V16QI_HI },
30916   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4df_mask, "__builtin_ia32_compressstoredf256_mask", IX86_BUILTIN_COMPRESSPDSTORE256, UNKNOWN, (int) VOID_FTYPE_PV4DF_V4DF_QI },
30917   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev2df_mask, "__builtin_ia32_compressstoredf128_mask", IX86_BUILTIN_COMPRESSPDSTORE128, UNKNOWN, (int) VOID_FTYPE_PV2DF_V2DF_QI },
30918   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev8sf_mask, "__builtin_ia32_compressstoresf256_mask", IX86_BUILTIN_COMPRESSPSSTORE256, UNKNOWN, (int) VOID_FTYPE_PV8SF_V8SF_QI },
30919   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4sf_mask, "__builtin_ia32_compressstoresf128_mask", IX86_BUILTIN_COMPRESSPSSTORE128, UNKNOWN, (int) VOID_FTYPE_PV4SF_V4SF_QI },
30920   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4di_mask, "__builtin_ia32_compressstoredi256_mask", IX86_BUILTIN_PCOMPRESSQSTORE256, UNKNOWN, (int) VOID_FTYPE_PV4DI_V4DI_QI },
30921   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev2di_mask, "__builtin_ia32_compressstoredi128_mask", IX86_BUILTIN_PCOMPRESSQSTORE128, UNKNOWN, (int) VOID_FTYPE_PV2DI_V2DI_QI },
30922   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev8si_mask, "__builtin_ia32_compressstoresi256_mask", IX86_BUILTIN_PCOMPRESSDSTORE256, UNKNOWN, (int) VOID_FTYPE_PV8SI_V8SI_QI },
30923   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressstorev4si_mask, "__builtin_ia32_compressstoresi128_mask", IX86_BUILTIN_PCOMPRESSDSTORE128, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4SI_QI },
30924   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_mask, "__builtin_ia32_expandloaddf256_mask", IX86_BUILTIN_EXPANDPDLOAD256, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
30925   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_mask, "__builtin_ia32_expandloaddf128_mask", IX86_BUILTIN_EXPANDPDLOAD128, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
30926   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_mask, "__builtin_ia32_expandloadsf256_mask", IX86_BUILTIN_EXPANDPSLOAD256, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
30927   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_mask, "__builtin_ia32_expandloadsf128_mask", IX86_BUILTIN_EXPANDPSLOAD128, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
30928   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_mask, "__builtin_ia32_expandloaddi256_mask", IX86_BUILTIN_PEXPANDQLOAD256, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
30929   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_mask, "__builtin_ia32_expandloaddi128_mask", IX86_BUILTIN_PEXPANDQLOAD128, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
30930   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_mask, "__builtin_ia32_expandloadsi256_mask", IX86_BUILTIN_PEXPANDDLOAD256, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
30931   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_mask, "__builtin_ia32_expandloadsi128_mask", IX86_BUILTIN_PEXPANDDLOAD128, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
30932   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_maskz, "__builtin_ia32_expandloaddf256_maskz", IX86_BUILTIN_EXPANDPDLOAD256Z, UNKNOWN, (int) V4DF_FTYPE_PCV4DF_V4DF_QI },
30933   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_maskz, "__builtin_ia32_expandloaddf128_maskz", IX86_BUILTIN_EXPANDPDLOAD128Z, UNKNOWN, (int) V2DF_FTYPE_PCV2DF_V2DF_QI },
30934   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_maskz, "__builtin_ia32_expandloadsf256_maskz", IX86_BUILTIN_EXPANDPSLOAD256Z, UNKNOWN, (int) V8SF_FTYPE_PCV8SF_V8SF_QI },
30935   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_maskz, "__builtin_ia32_expandloadsf128_maskz", IX86_BUILTIN_EXPANDPSLOAD128Z, UNKNOWN, (int) V4SF_FTYPE_PCV4SF_V4SF_QI },
30936   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_maskz, "__builtin_ia32_expandloaddi256_maskz", IX86_BUILTIN_PEXPANDQLOAD256Z, UNKNOWN, (int) V4DI_FTYPE_PCV4DI_V4DI_QI },
30937   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_maskz, "__builtin_ia32_expandloaddi128_maskz", IX86_BUILTIN_PEXPANDQLOAD128Z, UNKNOWN, (int) V2DI_FTYPE_PCV2DI_V2DI_QI },
30938   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_maskz, "__builtin_ia32_expandloadsi256_maskz", IX86_BUILTIN_PEXPANDDLOAD256Z, UNKNOWN, (int) V8SI_FTYPE_PCV8SI_V8SI_QI },
30939   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_maskz, "__builtin_ia32_expandloadsi128_maskz", IX86_BUILTIN_PEXPANDDLOAD128Z, UNKNOWN, (int) V4SI_FTYPE_PCV4SI_V4SI_QI },
30940   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4si2_mask_store, "__builtin_ia32_pmovqd256mem_mask", IX86_BUILTIN_PMOVQD256_MEM, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4DI_QI },
30941   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2si2_mask_store, "__builtin_ia32_pmovqd128mem_mask", IX86_BUILTIN_PMOVQD128_MEM, UNKNOWN, (int) VOID_FTYPE_PV4SI_V2DI_QI },
30942   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4si2_mask_store, "__builtin_ia32_pmovsqd256mem_mask", IX86_BUILTIN_PMOVSQD256_MEM, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4DI_QI },
30943   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2si2_mask_store, "__builtin_ia32_pmovsqd128mem_mask", IX86_BUILTIN_PMOVSQD128_MEM, UNKNOWN, (int) VOID_FTYPE_PV4SI_V2DI_QI },
30944   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4si2_mask_store, "__builtin_ia32_pmovusqd256mem_mask", IX86_BUILTIN_PMOVUSQD256_MEM, UNKNOWN, (int) VOID_FTYPE_PV4SI_V4DI_QI },
30945   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2si2_mask_store, "__builtin_ia32_pmovusqd128mem_mask", IX86_BUILTIN_PMOVUSQD128_MEM, UNKNOWN, (int) VOID_FTYPE_PV4SI_V2DI_QI },
30946   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4hi2_mask_store, "__builtin_ia32_pmovqw256mem_mask", IX86_BUILTIN_PMOVQW256_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V4DI_QI },
30947   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2hi2_mask_store, "__builtin_ia32_pmovqw128mem_mask", IX86_BUILTIN_PMOVQW128_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V2DI_QI },
30948   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4hi2_mask_store, "__builtin_ia32_pmovsqw256mem_mask", IX86_BUILTIN_PMOVSQW256_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V4DI_QI },
30949   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2hi2_mask_store, "__builtin_ia32_pmovsqw128mem_mask", IX86_BUILTIN_PMOVSQW128_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V2DI_QI },
30950   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4hi2_mask_store, "__builtin_ia32_pmovusqw256mem_mask", IX86_BUILTIN_PMOVUSQW256_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V4DI_QI },
30951   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2hi2_mask_store, "__builtin_ia32_pmovusqw128mem_mask", IX86_BUILTIN_PMOVUSQW128_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V2DI_QI },
30952   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4qi2_mask_store, "__builtin_ia32_pmovqb256mem_mask", IX86_BUILTIN_PMOVQB256_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V4DI_QI },
30953   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2qi2_mask_store, "__builtin_ia32_pmovqb128mem_mask", IX86_BUILTIN_PMOVQB128_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V2DI_QI },
30954   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4qi2_mask_store, "__builtin_ia32_pmovsqb256mem_mask", IX86_BUILTIN_PMOVSQB256_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V4DI_QI },
30955   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2qi2_mask_store, "__builtin_ia32_pmovsqb128mem_mask", IX86_BUILTIN_PMOVSQB128_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V2DI_QI },
30956   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4qi2_mask_store, "__builtin_ia32_pmovusqb256mem_mask", IX86_BUILTIN_PMOVUSQB256_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V4DI_QI },
30957   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2qi2_mask_store, "__builtin_ia32_pmovusqb128mem_mask", IX86_BUILTIN_PMOVUSQB128_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V2DI_QI },
30958   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev8siv8qi2_mask_store, "__builtin_ia32_pmovdb256mem_mask", IX86_BUILTIN_PMOVDB256_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V8SI_QI },
30959   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4siv4qi2_mask_store, "__builtin_ia32_pmovdb128mem_mask", IX86_BUILTIN_PMOVDB128_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V4SI_QI },
30960   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev8siv8qi2_mask_store, "__builtin_ia32_pmovsdb256mem_mask", IX86_BUILTIN_PMOVSDB256_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V8SI_QI },
30961   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4siv4qi2_mask_store, "__builtin_ia32_pmovsdb128mem_mask", IX86_BUILTIN_PMOVSDB128_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V4SI_QI },
30962   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev8siv8qi2_mask_store, "__builtin_ia32_pmovusdb256mem_mask", IX86_BUILTIN_PMOVUSDB256_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V8SI_QI },
30963   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4siv4qi2_mask_store, "__builtin_ia32_pmovusdb128mem_mask", IX86_BUILTIN_PMOVUSDB128_MEM, UNKNOWN, (int) VOID_FTYPE_PV16QI_V4SI_QI },
30964   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev8siv8hi2_mask_store, "__builtin_ia32_pmovdw256mem_mask", IX86_BUILTIN_PMOVDW256_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V8SI_QI },
30965   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4siv4hi2_mask_store, "__builtin_ia32_pmovdw128mem_mask", IX86_BUILTIN_PMOVDW128_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V4SI_QI },
30966   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev8siv8hi2_mask_store, "__builtin_ia32_pmovsdw256mem_mask", IX86_BUILTIN_PMOVSDW256_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V8SI_QI },
30967   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4siv4hi2_mask_store, "__builtin_ia32_pmovsdw128mem_mask", IX86_BUILTIN_PMOVSDW128_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V4SI_QI },
30968   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev8siv8hi2_mask_store, "__builtin_ia32_pmovusdw256mem_mask", IX86_BUILTIN_PMOVUSDW256_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V8SI_QI },
30969   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4siv4hi2_mask_store, "__builtin_ia32_pmovusdw128mem_mask", IX86_BUILTIN_PMOVUSDW128_MEM, UNKNOWN, (int) VOID_FTYPE_PV8HI_V4SI_QI },
30970
30971   /* PCOMMIT.  */
30972   { OPTION_MASK_ISA_PCOMMIT, CODE_FOR_pcommit, "__builtin_ia32_pcommit", IX86_BUILTIN_PCOMMIT, UNKNOWN, (int) VOID_FTYPE_VOID },
30973 };
30974
30975 /* Builtins with variable number of arguments.  */
30976 static const struct builtin_description bdesc_args[] =
30977 {
30978   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_bsr, "__builtin_ia32_bsrsi", IX86_BUILTIN_BSRSI, UNKNOWN, (int) INT_FTYPE_INT },
30979   { OPTION_MASK_ISA_64BIT, CODE_FOR_bsr_rex64, "__builtin_ia32_bsrdi", IX86_BUILTIN_BSRDI, UNKNOWN, (int) INT64_FTYPE_INT64 },
30980   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_nothing, "__builtin_ia32_rdpmc", IX86_BUILTIN_RDPMC, UNKNOWN, (int) UINT64_FTYPE_INT },
30981   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotlqi3, "__builtin_ia32_rolqi", IX86_BUILTIN_ROLQI, UNKNOWN, (int) UINT8_FTYPE_UINT8_INT },
30982   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotlhi3, "__builtin_ia32_rolhi", IX86_BUILTIN_ROLHI, UNKNOWN, (int) UINT16_FTYPE_UINT16_INT },
30983   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotrqi3, "__builtin_ia32_rorqi", IX86_BUILTIN_RORQI, UNKNOWN, (int) UINT8_FTYPE_UINT8_INT },
30984   { ~OPTION_MASK_ISA_64BIT, CODE_FOR_rotrhi3, "__builtin_ia32_rorhi", IX86_BUILTIN_RORHI, UNKNOWN, (int) UINT16_FTYPE_UINT16_INT },
30985
30986   /* MMX */
30987   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv8qi3, "__builtin_ia32_paddb", IX86_BUILTIN_PADDB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30988   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv4hi3, "__builtin_ia32_paddw", IX86_BUILTIN_PADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30989   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_addv2si3, "__builtin_ia32_paddd", IX86_BUILTIN_PADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
30990   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv8qi3, "__builtin_ia32_psubb", IX86_BUILTIN_PSUBB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30991   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv4hi3, "__builtin_ia32_psubw", IX86_BUILTIN_PSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30992   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_subv2si3, "__builtin_ia32_psubd", IX86_BUILTIN_PSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
30993
30994   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv8qi3, "__builtin_ia32_paddsb", IX86_BUILTIN_PADDSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30995   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ssaddv4hi3, "__builtin_ia32_paddsw", IX86_BUILTIN_PADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30996   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv8qi3, "__builtin_ia32_psubsb", IX86_BUILTIN_PSUBSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30997   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_sssubv4hi3, "__builtin_ia32_psubsw", IX86_BUILTIN_PSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
30998   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv8qi3, "__builtin_ia32_paddusb", IX86_BUILTIN_PADDUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
30999   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_usaddv4hi3, "__builtin_ia32_paddusw", IX86_BUILTIN_PADDUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31000   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv8qi3, "__builtin_ia32_psubusb", IX86_BUILTIN_PSUBUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31001   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ussubv4hi3, "__builtin_ia32_psubusw", IX86_BUILTIN_PSUBUSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31002
31003   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_mulv4hi3, "__builtin_ia32_pmullw", IX86_BUILTIN_PMULLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31004   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_smulv4hi3_highpart, "__builtin_ia32_pmulhw", IX86_BUILTIN_PMULHW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31005
31006   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andv2si3, "__builtin_ia32_pand", IX86_BUILTIN_PAND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31007   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_andnotv2si3, "__builtin_ia32_pandn", IX86_BUILTIN_PANDN, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31008   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_iorv2si3, "__builtin_ia32_por", IX86_BUILTIN_POR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31009   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_xorv2si3, "__builtin_ia32_pxor", IX86_BUILTIN_PXOR, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31010
31011   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv8qi3, "__builtin_ia32_pcmpeqb", IX86_BUILTIN_PCMPEQB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31012   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv4hi3, "__builtin_ia32_pcmpeqw", IX86_BUILTIN_PCMPEQW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31013   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_eqv2si3, "__builtin_ia32_pcmpeqd", IX86_BUILTIN_PCMPEQD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31014   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv8qi3, "__builtin_ia32_pcmpgtb", IX86_BUILTIN_PCMPGTB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31015   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv4hi3, "__builtin_ia32_pcmpgtw", IX86_BUILTIN_PCMPGTW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31016   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_gtv2si3, "__builtin_ia32_pcmpgtd", IX86_BUILTIN_PCMPGTD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31017
31018   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhbw, "__builtin_ia32_punpckhbw", IX86_BUILTIN_PUNPCKHBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31019   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhwd, "__builtin_ia32_punpckhwd", IX86_BUILTIN_PUNPCKHWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31020   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckhdq, "__builtin_ia32_punpckhdq", IX86_BUILTIN_PUNPCKHDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31021   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklbw, "__builtin_ia32_punpcklbw", IX86_BUILTIN_PUNPCKLBW, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31022   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpcklwd, "__builtin_ia32_punpcklwd", IX86_BUILTIN_PUNPCKLWD, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI},
31023   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_punpckldq, "__builtin_ia32_punpckldq", IX86_BUILTIN_PUNPCKLDQ, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI},
31024
31025   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packsswb, "__builtin_ia32_packsswb", IX86_BUILTIN_PACKSSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
31026   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packssdw, "__builtin_ia32_packssdw", IX86_BUILTIN_PACKSSDW, UNKNOWN, (int) V4HI_FTYPE_V2SI_V2SI },
31027   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_packuswb, "__builtin_ia32_packuswb", IX86_BUILTIN_PACKUSWB, UNKNOWN, (int) V8QI_FTYPE_V4HI_V4HI },
31028
31029   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_pmaddwd, "__builtin_ia32_pmaddwd", IX86_BUILTIN_PMADDWD, UNKNOWN, (int) V2SI_FTYPE_V4HI_V4HI },
31030
31031   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllwi", IX86_BUILTIN_PSLLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
31032   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslldi", IX86_BUILTIN_PSLLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
31033   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllqi", IX86_BUILTIN_PSLLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
31034   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv4hi3, "__builtin_ia32_psllw", IX86_BUILTIN_PSLLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
31035   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv2si3, "__builtin_ia32_pslld", IX86_BUILTIN_PSLLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
31036   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashlv1di3, "__builtin_ia32_psllq", IX86_BUILTIN_PSLLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
31037
31038   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlwi", IX86_BUILTIN_PSRLWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
31039   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrldi", IX86_BUILTIN_PSRLDI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
31040   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlqi", IX86_BUILTIN_PSRLQI, UNKNOWN, (int) V1DI_FTYPE_V1DI_SI_COUNT },
31041   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv4hi3, "__builtin_ia32_psrlw", IX86_BUILTIN_PSRLW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
31042   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv2si3, "__builtin_ia32_psrld", IX86_BUILTIN_PSRLD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
31043   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_lshrv1di3, "__builtin_ia32_psrlq", IX86_BUILTIN_PSRLQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_COUNT },
31044
31045   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psrawi", IX86_BUILTIN_PSRAWI, UNKNOWN, (int) V4HI_FTYPE_V4HI_SI_COUNT },
31046   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psradi", IX86_BUILTIN_PSRADI, UNKNOWN, (int) V2SI_FTYPE_V2SI_SI_COUNT },
31047   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv4hi3, "__builtin_ia32_psraw", IX86_BUILTIN_PSRAW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI_COUNT },
31048   { OPTION_MASK_ISA_MMX, CODE_FOR_mmx_ashrv2si3, "__builtin_ia32_psrad", IX86_BUILTIN_PSRAD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI_COUNT },
31049
31050   /* 3DNow! */
31051   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pf2id, "__builtin_ia32_pf2id", IX86_BUILTIN_PF2ID, UNKNOWN, (int) V2SI_FTYPE_V2SF },
31052   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_floatv2si2, "__builtin_ia32_pi2fd", IX86_BUILTIN_PI2FD, UNKNOWN, (int) V2SF_FTYPE_V2SI },
31053   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpv2sf2, "__builtin_ia32_pfrcp", IX86_BUILTIN_PFRCP, UNKNOWN, (int) V2SF_FTYPE_V2SF },
31054   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqrtv2sf2, "__builtin_ia32_pfrsqrt", IX86_BUILTIN_PFRSQRT, UNKNOWN, (int) V2SF_FTYPE_V2SF },
31055
31056   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgusb", IX86_BUILTIN_PAVGUSB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31057   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_haddv2sf3, "__builtin_ia32_pfacc", IX86_BUILTIN_PFACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31058   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_addv2sf3, "__builtin_ia32_pfadd", IX86_BUILTIN_PFADD, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31059   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_eqv2sf3, "__builtin_ia32_pfcmpeq", IX86_BUILTIN_PFCMPEQ, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
31060   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gev2sf3, "__builtin_ia32_pfcmpge", IX86_BUILTIN_PFCMPGE, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
31061   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_gtv2sf3, "__builtin_ia32_pfcmpgt", IX86_BUILTIN_PFCMPGT, UNKNOWN, (int) V2SI_FTYPE_V2SF_V2SF },
31062   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_smaxv2sf3, "__builtin_ia32_pfmax", IX86_BUILTIN_PFMAX, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31063   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_sminv2sf3, "__builtin_ia32_pfmin", IX86_BUILTIN_PFMIN, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31064   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_mulv2sf3, "__builtin_ia32_pfmul", IX86_BUILTIN_PFMUL, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31065   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit1v2sf3, "__builtin_ia32_pfrcpit1", IX86_BUILTIN_PFRCPIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31066   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rcpit2v2sf3, "__builtin_ia32_pfrcpit2", IX86_BUILTIN_PFRCPIT2, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31067   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_rsqit1v2sf3, "__builtin_ia32_pfrsqit1", IX86_BUILTIN_PFRSQIT1, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31068   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subv2sf3, "__builtin_ia32_pfsub", IX86_BUILTIN_PFSUB, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31069   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_subrv2sf3, "__builtin_ia32_pfsubr", IX86_BUILTIN_PFSUBR, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31070   { OPTION_MASK_ISA_3DNOW, CODE_FOR_mmx_pmulhrwv4hi3, "__builtin_ia32_pmulhrw", IX86_BUILTIN_PMULHRW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31071
31072   /* 3DNow!A */
31073   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pf2iw, "__builtin_ia32_pf2iw", IX86_BUILTIN_PF2IW, UNKNOWN, (int) V2SI_FTYPE_V2SF },
31074   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pi2fw, "__builtin_ia32_pi2fw", IX86_BUILTIN_PI2FW, UNKNOWN, (int) V2SF_FTYPE_V2SI },
31075   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2si2, "__builtin_ia32_pswapdsi", IX86_BUILTIN_PSWAPDSI, UNKNOWN, (int) V2SI_FTYPE_V2SI },
31076   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pswapdv2sf2, "__builtin_ia32_pswapdsf", IX86_BUILTIN_PSWAPDSF, UNKNOWN, (int) V2SF_FTYPE_V2SF },
31077   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_hsubv2sf3, "__builtin_ia32_pfnacc", IX86_BUILTIN_PFNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31078   { OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_addsubv2sf3, "__builtin_ia32_pfpnacc", IX86_BUILTIN_PFPNACC, UNKNOWN, (int) V2SF_FTYPE_V2SF_V2SF },
31079
31080   /* SSE */
31081   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movmskps, "__builtin_ia32_movmskps", IX86_BUILTIN_MOVMSKPS, UNKNOWN, (int) INT_FTYPE_V4SF },
31082   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_sqrtv4sf2, "__builtin_ia32_sqrtps", IX86_BUILTIN_SQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31083   { OPTION_MASK_ISA_SSE, CODE_FOR_sqrtv4sf2, "__builtin_ia32_sqrtps_nr", IX86_BUILTIN_SQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31084   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rsqrtv4sf2, "__builtin_ia32_rsqrtps", IX86_BUILTIN_RSQRTPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31085   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtv4sf2, "__builtin_ia32_rsqrtps_nr", IX86_BUILTIN_RSQRTPS_NR, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31086   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_rcpv4sf2, "__builtin_ia32_rcpps", IX86_BUILTIN_RCPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31087   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtps2pi, "__builtin_ia32_cvtps2pi", IX86_BUILTIN_CVTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
31088   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtss2si, "__builtin_ia32_cvtss2si", IX86_BUILTIN_CVTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
31089   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq, "__builtin_ia32_cvtss2si64", IX86_BUILTIN_CVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
31090   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttps2pi, "__builtin_ia32_cvttps2pi", IX86_BUILTIN_CVTTPS2PI, UNKNOWN, (int) V2SI_FTYPE_V4SF },
31091   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvttss2si, "__builtin_ia32_cvttss2si", IX86_BUILTIN_CVTTSS2SI, UNKNOWN, (int) INT_FTYPE_V4SF },
31092   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq, "__builtin_ia32_cvttss2si64", IX86_BUILTIN_CVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF },
31093
31094   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_shufps, "__builtin_ia32_shufps", IX86_BUILTIN_SHUFPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31095
31096   { OPTION_MASK_ISA_SSE, CODE_FOR_addv4sf3, "__builtin_ia32_addps", IX86_BUILTIN_ADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31097   { OPTION_MASK_ISA_SSE, CODE_FOR_subv4sf3, "__builtin_ia32_subps", IX86_BUILTIN_SUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31098   { OPTION_MASK_ISA_SSE, CODE_FOR_mulv4sf3, "__builtin_ia32_mulps", IX86_BUILTIN_MULPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31099   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_divv4sf3, "__builtin_ia32_divps", IX86_BUILTIN_DIVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31100   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmaddv4sf3,  "__builtin_ia32_addss", IX86_BUILTIN_ADDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31101   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsubv4sf3,  "__builtin_ia32_subss", IX86_BUILTIN_SUBSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31102   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmulv4sf3,  "__builtin_ia32_mulss", IX86_BUILTIN_MULSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31103   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmdivv4sf3,  "__builtin_ia32_divss", IX86_BUILTIN_DIVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31104
31105   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpeqps", IX86_BUILTIN_CMPEQPS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
31106   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpltps", IX86_BUILTIN_CMPLTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
31107   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpleps", IX86_BUILTIN_CMPLEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
31108   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgtps", IX86_BUILTIN_CMPGTPS, LT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
31109   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpgeps", IX86_BUILTIN_CMPGEPS, LE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
31110   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpunordps", IX86_BUILTIN_CMPUNORDPS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31111   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpneqps", IX86_BUILTIN_CMPNEQPS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
31112   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnltps", IX86_BUILTIN_CMPNLTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
31113   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpnleps", IX86_BUILTIN_CMPNLEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
31114   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngtps", IX86_BUILTIN_CMPNGTPS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF_SWAP },
31115   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpngeps", IX86_BUILTIN_CMPNGEPS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF_SWAP},
31116   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_maskcmpv4sf3, "__builtin_ia32_cmpordps", IX86_BUILTIN_CMPORDPS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31117   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpeqss", IX86_BUILTIN_CMPEQSS, EQ, (int) V4SF_FTYPE_V4SF_V4SF },
31118   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpltss", IX86_BUILTIN_CMPLTSS, LT, (int) V4SF_FTYPE_V4SF_V4SF },
31119   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpless", IX86_BUILTIN_CMPLESS, LE, (int) V4SF_FTYPE_V4SF_V4SF },
31120   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpunordss", IX86_BUILTIN_CMPUNORDSS, UNORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31121   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpneqss", IX86_BUILTIN_CMPNEQSS, NE, (int) V4SF_FTYPE_V4SF_V4SF },
31122   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnltss", IX86_BUILTIN_CMPNLTSS, UNGE, (int) V4SF_FTYPE_V4SF_V4SF },
31123   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpnless", IX86_BUILTIN_CMPNLESS, UNGT, (int) V4SF_FTYPE_V4SF_V4SF },
31124   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmmaskcmpv4sf3, "__builtin_ia32_cmpordss", IX86_BUILTIN_CMPORDSS, ORDERED, (int) V4SF_FTYPE_V4SF_V4SF },
31125
31126   { OPTION_MASK_ISA_SSE, CODE_FOR_sminv4sf3, "__builtin_ia32_minps", IX86_BUILTIN_MINPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31127   { OPTION_MASK_ISA_SSE, CODE_FOR_smaxv4sf3, "__builtin_ia32_maxps", IX86_BUILTIN_MAXPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31128   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsminv4sf3, "__builtin_ia32_minss", IX86_BUILTIN_MINSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31129   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsmaxv4sf3, "__builtin_ia32_maxss", IX86_BUILTIN_MAXSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31130
31131   { OPTION_MASK_ISA_SSE, CODE_FOR_andv4sf3, "__builtin_ia32_andps", IX86_BUILTIN_ANDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31132   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_andnotv4sf3,  "__builtin_ia32_andnps", IX86_BUILTIN_ANDNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31133   { OPTION_MASK_ISA_SSE, CODE_FOR_iorv4sf3, "__builtin_ia32_orps", IX86_BUILTIN_ORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31134   { OPTION_MASK_ISA_SSE, CODE_FOR_xorv4sf3,  "__builtin_ia32_xorps", IX86_BUILTIN_XORPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31135
31136   { OPTION_MASK_ISA_SSE, CODE_FOR_copysignv4sf3,  "__builtin_ia32_copysignps", IX86_BUILTIN_CPYSGNPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31137
31138   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movss,  "__builtin_ia32_movss", IX86_BUILTIN_MOVSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31139   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movhlps_exp,  "__builtin_ia32_movhlps", IX86_BUILTIN_MOVHLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31140   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_movlhps_exp,  "__builtin_ia32_movlhps", IX86_BUILTIN_MOVLHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31141   { OPTION_MASK_ISA_SSE, CODE_FOR_vec_interleave_highv4sf, "__builtin_ia32_unpckhps", IX86_BUILTIN_UNPCKHPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31142   { OPTION_MASK_ISA_SSE, CODE_FOR_vec_interleave_lowv4sf, "__builtin_ia32_unpcklps", IX86_BUILTIN_UNPCKLPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31143
31144   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtpi2ps, "__builtin_ia32_cvtpi2ps", IX86_BUILTIN_CVTPI2PS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2SI },
31145   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_cvtsi2ss, "__builtin_ia32_cvtsi2ss", IX86_BUILTIN_CVTSI2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_SI },
31146   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq, "__builtin_ia32_cvtsi642ss", IX86_BUILTIN_CVTSI642SS, UNKNOWN, V4SF_FTYPE_V4SF_DI },
31147
31148   { OPTION_MASK_ISA_SSE, CODE_FOR_rsqrtsf2, "__builtin_ia32_rsqrtf", IX86_BUILTIN_RSQRTF, UNKNOWN, (int) FLOAT_FTYPE_FLOAT },
31149
31150   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmsqrtv4sf2, "__builtin_ia32_sqrtss", IX86_BUILTIN_SQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
31151   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrsqrtv4sf2, "__builtin_ia32_rsqrtss", IX86_BUILTIN_RSQRTSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
31152   { OPTION_MASK_ISA_SSE, CODE_FOR_sse_vmrcpv4sf2, "__builtin_ia32_rcpss", IX86_BUILTIN_RCPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_VEC_MERGE },
31153
31154   { OPTION_MASK_ISA_SSE, CODE_FOR_abstf2, 0, IX86_BUILTIN_FABSQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128 },
31155   { OPTION_MASK_ISA_SSE, CODE_FOR_copysigntf3, 0, IX86_BUILTIN_COPYSIGNQ, UNKNOWN, (int) FLOAT128_FTYPE_FLOAT128_FLOAT128 },
31156
31157   /* SSE MMX or 3Dnow!A */
31158   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_uavgv8qi3, "__builtin_ia32_pavgb", IX86_BUILTIN_PAVGB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31159   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_uavgv4hi3, "__builtin_ia32_pavgw", IX86_BUILTIN_PAVGW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31160   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_umulv4hi3_highpart, "__builtin_ia32_pmulhuw", IX86_BUILTIN_PMULHUW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31161
31162   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_umaxv8qi3, "__builtin_ia32_pmaxub", IX86_BUILTIN_PMAXUB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31163   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_smaxv4hi3, "__builtin_ia32_pmaxsw", IX86_BUILTIN_PMAXSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31164   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_uminv8qi3, "__builtin_ia32_pminub", IX86_BUILTIN_PMINUB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31165   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_sminv4hi3, "__builtin_ia32_pminsw", IX86_BUILTIN_PMINSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31166
31167   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_psadbw, "__builtin_ia32_psadbw", IX86_BUILTIN_PSADBW, UNKNOWN, (int) V1DI_FTYPE_V8QI_V8QI },
31168   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pmovmskb, "__builtin_ia32_pmovmskb", IX86_BUILTIN_PMOVMSKB, UNKNOWN, (int) INT_FTYPE_V8QI },
31169
31170   { OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A, CODE_FOR_mmx_pshufw, "__builtin_ia32_pshufw", IX86_BUILTIN_PSHUFW, UNKNOWN, (int) V4HI_FTYPE_V4HI_INT },
31171
31172   /* SSE2 */
31173   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_shufpd, "__builtin_ia32_shufpd", IX86_BUILTIN_SHUFPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31174
31175   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movmskpd, "__builtin_ia32_movmskpd", IX86_BUILTIN_MOVMSKPD, UNKNOWN, (int) INT_FTYPE_V2DF  },
31176   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmovmskb, "__builtin_ia32_pmovmskb128", IX86_BUILTIN_PMOVMSKB128, UNKNOWN, (int) INT_FTYPE_V16QI },
31177   { OPTION_MASK_ISA_SSE2, CODE_FOR_sqrtv2df2, "__builtin_ia32_sqrtpd", IX86_BUILTIN_SQRTPD, UNKNOWN, (int) V2DF_FTYPE_V2DF },
31178   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtdq2pd, "__builtin_ia32_cvtdq2pd", IX86_BUILTIN_CVTDQ2PD, UNKNOWN, (int) V2DF_FTYPE_V4SI },
31179   { OPTION_MASK_ISA_SSE2, CODE_FOR_floatv4siv4sf2, "__builtin_ia32_cvtdq2ps", IX86_BUILTIN_CVTDQ2PS, UNKNOWN, (int) V4SF_FTYPE_V4SI },
31180
31181   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2dq, "__builtin_ia32_cvtpd2dq", IX86_BUILTIN_CVTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
31182   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2pi, "__builtin_ia32_cvtpd2pi", IX86_BUILTIN_CVTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
31183   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpd2ps, "__builtin_ia32_cvtpd2ps", IX86_BUILTIN_CVTPD2PS, UNKNOWN, (int) V4SF_FTYPE_V2DF },
31184   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2dq, "__builtin_ia32_cvttpd2dq", IX86_BUILTIN_CVTTPD2DQ, UNKNOWN, (int) V4SI_FTYPE_V2DF },
31185   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttpd2pi, "__builtin_ia32_cvttpd2pi", IX86_BUILTIN_CVTTPD2PI, UNKNOWN, (int) V2SI_FTYPE_V2DF },
31186
31187   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtpi2pd, "__builtin_ia32_cvtpi2pd", IX86_BUILTIN_CVTPI2PD, UNKNOWN, (int) V2DF_FTYPE_V2SI },
31188
31189   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2si, "__builtin_ia32_cvtsd2si", IX86_BUILTIN_CVTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
31190   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvttsd2si, "__builtin_ia32_cvttsd2si", IX86_BUILTIN_CVTTSD2SI, UNKNOWN, (int) INT_FTYPE_V2DF },
31191   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq, "__builtin_ia32_cvtsd2si64", IX86_BUILTIN_CVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
31192   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq, "__builtin_ia32_cvttsd2si64", IX86_BUILTIN_CVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF },
31193
31194   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_fix_notruncv4sfv4si, "__builtin_ia32_cvtps2dq", IX86_BUILTIN_CVTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
31195   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtps2pd, "__builtin_ia32_cvtps2pd", IX86_BUILTIN_CVTPS2PD, UNKNOWN, (int) V2DF_FTYPE_V4SF },
31196   { OPTION_MASK_ISA_SSE2, CODE_FOR_fix_truncv4sfv4si2, "__builtin_ia32_cvttps2dq", IX86_BUILTIN_CVTTPS2DQ, UNKNOWN, (int) V4SI_FTYPE_V4SF },
31197
31198   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2df3, "__builtin_ia32_addpd", IX86_BUILTIN_ADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31199   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2df3, "__builtin_ia32_subpd", IX86_BUILTIN_SUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31200   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv2df3, "__builtin_ia32_mulpd", IX86_BUILTIN_MULPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31201   { OPTION_MASK_ISA_SSE2, CODE_FOR_divv2df3, "__builtin_ia32_divpd", IX86_BUILTIN_DIVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31202   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmaddv2df3,  "__builtin_ia32_addsd", IX86_BUILTIN_ADDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31203   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsubv2df3,  "__builtin_ia32_subsd", IX86_BUILTIN_SUBSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31204   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmulv2df3,  "__builtin_ia32_mulsd", IX86_BUILTIN_MULSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31205   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmdivv2df3,  "__builtin_ia32_divsd", IX86_BUILTIN_DIVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31206
31207   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpeqpd", IX86_BUILTIN_CMPEQPD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
31208   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpltpd", IX86_BUILTIN_CMPLTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
31209   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmplepd", IX86_BUILTIN_CMPLEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
31210   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgtpd", IX86_BUILTIN_CMPGTPD, LT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
31211   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpgepd", IX86_BUILTIN_CMPGEPD, LE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP},
31212   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpunordpd", IX86_BUILTIN_CMPUNORDPD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31213   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpneqpd", IX86_BUILTIN_CMPNEQPD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
31214   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnltpd", IX86_BUILTIN_CMPNLTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
31215   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpnlepd", IX86_BUILTIN_CMPNLEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
31216   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngtpd", IX86_BUILTIN_CMPNGTPD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
31217   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpngepd", IX86_BUILTIN_CMPNGEPD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF_SWAP },
31218   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_maskcmpv2df3, "__builtin_ia32_cmpordpd", IX86_BUILTIN_CMPORDPD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31219   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpeqsd", IX86_BUILTIN_CMPEQSD, EQ, (int) V2DF_FTYPE_V2DF_V2DF },
31220   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpltsd", IX86_BUILTIN_CMPLTSD, LT, (int) V2DF_FTYPE_V2DF_V2DF },
31221   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmplesd", IX86_BUILTIN_CMPLESD, LE, (int) V2DF_FTYPE_V2DF_V2DF },
31222   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpunordsd", IX86_BUILTIN_CMPUNORDSD, UNORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31223   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpneqsd", IX86_BUILTIN_CMPNEQSD, NE, (int) V2DF_FTYPE_V2DF_V2DF },
31224   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnltsd", IX86_BUILTIN_CMPNLTSD, UNGE, (int) V2DF_FTYPE_V2DF_V2DF },
31225   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpnlesd", IX86_BUILTIN_CMPNLESD, UNGT, (int) V2DF_FTYPE_V2DF_V2DF },
31226   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmmaskcmpv2df3, "__builtin_ia32_cmpordsd", IX86_BUILTIN_CMPORDSD, ORDERED, (int) V2DF_FTYPE_V2DF_V2DF },
31227
31228   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv2df3, "__builtin_ia32_minpd", IX86_BUILTIN_MINPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31229   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv2df3, "__builtin_ia32_maxpd", IX86_BUILTIN_MAXPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31230   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsminv2df3, "__builtin_ia32_minsd", IX86_BUILTIN_MINSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31231   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsmaxv2df3, "__builtin_ia32_maxsd", IX86_BUILTIN_MAXSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31232
31233   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2df3, "__builtin_ia32_andpd", IX86_BUILTIN_ANDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31234   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2df3,  "__builtin_ia32_andnpd", IX86_BUILTIN_ANDNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31235   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2df3, "__builtin_ia32_orpd", IX86_BUILTIN_ORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31236   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2df3,  "__builtin_ia32_xorpd", IX86_BUILTIN_XORPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31237
31238   { OPTION_MASK_ISA_SSE2, CODE_FOR_copysignv2df3,  "__builtin_ia32_copysignpd", IX86_BUILTIN_CPYSGNPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31239
31240   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_movsd,  "__builtin_ia32_movsd", IX86_BUILTIN_MOVSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31241   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv2df, "__builtin_ia32_unpckhpd", IX86_BUILTIN_UNPCKHPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31242   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv2df, "__builtin_ia32_unpcklpd", IX86_BUILTIN_UNPCKLPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31243
31244   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_pack_sfix_v2df, "__builtin_ia32_vec_pack_sfix", IX86_BUILTIN_VEC_PACK_SFIX, UNKNOWN, (int) V4SI_FTYPE_V2DF_V2DF },
31245
31246   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv16qi3, "__builtin_ia32_paddb128", IX86_BUILTIN_PADDB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31247   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv8hi3, "__builtin_ia32_paddw128", IX86_BUILTIN_PADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31248   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv4si3, "__builtin_ia32_paddd128", IX86_BUILTIN_PADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31249   { OPTION_MASK_ISA_SSE2, CODE_FOR_addv2di3, "__builtin_ia32_paddq128", IX86_BUILTIN_PADDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31250   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv16qi3, "__builtin_ia32_psubb128", IX86_BUILTIN_PSUBB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31251   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv8hi3, "__builtin_ia32_psubw128", IX86_BUILTIN_PSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31252   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv4si3, "__builtin_ia32_psubd128", IX86_BUILTIN_PSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31253   { OPTION_MASK_ISA_SSE2, CODE_FOR_subv2di3, "__builtin_ia32_psubq128", IX86_BUILTIN_PSUBQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31254
31255   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv16qi3, "__builtin_ia32_paddsb128", IX86_BUILTIN_PADDSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31256   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ssaddv8hi3, "__builtin_ia32_paddsw128", IX86_BUILTIN_PADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31257   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv16qi3, "__builtin_ia32_psubsb128", IX86_BUILTIN_PSUBSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31258   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_sssubv8hi3, "__builtin_ia32_psubsw128", IX86_BUILTIN_PSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31259   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv16qi3, "__builtin_ia32_paddusb128", IX86_BUILTIN_PADDUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31260   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_usaddv8hi3, "__builtin_ia32_paddusw128", IX86_BUILTIN_PADDUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31261   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv16qi3, "__builtin_ia32_psubusb128", IX86_BUILTIN_PSUBUSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31262   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ussubv8hi3, "__builtin_ia32_psubusw128", IX86_BUILTIN_PSUBUSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31263
31264   { OPTION_MASK_ISA_SSE2, CODE_FOR_mulv8hi3, "__builtin_ia32_pmullw128", IX86_BUILTIN_PMULLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31265   { OPTION_MASK_ISA_SSE2, CODE_FOR_smulv8hi3_highpart, "__builtin_ia32_pmulhw128", IX86_BUILTIN_PMULHW128, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI },
31266
31267   { OPTION_MASK_ISA_SSE2, CODE_FOR_andv2di3, "__builtin_ia32_pand128", IX86_BUILTIN_PAND128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31268   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_andnotv2di3, "__builtin_ia32_pandn128", IX86_BUILTIN_PANDN128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31269   { OPTION_MASK_ISA_SSE2, CODE_FOR_iorv2di3, "__builtin_ia32_por128", IX86_BUILTIN_POR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31270   { OPTION_MASK_ISA_SSE2, CODE_FOR_xorv2di3, "__builtin_ia32_pxor128", IX86_BUILTIN_PXOR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31271
31272   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv16qi3, "__builtin_ia32_pavgb128", IX86_BUILTIN_PAVGB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31273   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_uavgv8hi3, "__builtin_ia32_pavgw128", IX86_BUILTIN_PAVGW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31274
31275   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv16qi3, "__builtin_ia32_pcmpeqb128", IX86_BUILTIN_PCMPEQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31276   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv8hi3, "__builtin_ia32_pcmpeqw128", IX86_BUILTIN_PCMPEQW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31277   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_eqv4si3, "__builtin_ia32_pcmpeqd128", IX86_BUILTIN_PCMPEQD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
31278   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv16qi3, "__builtin_ia32_pcmpgtb128", IX86_BUILTIN_PCMPGTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31279   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv8hi3, "__builtin_ia32_pcmpgtw128", IX86_BUILTIN_PCMPGTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31280   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_gtv4si3, "__builtin_ia32_pcmpgtd128", IX86_BUILTIN_PCMPGTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI  },
31281
31282   { OPTION_MASK_ISA_SSE2, CODE_FOR_umaxv16qi3, "__builtin_ia32_pmaxub128", IX86_BUILTIN_PMAXUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31283   { OPTION_MASK_ISA_SSE2, CODE_FOR_smaxv8hi3, "__builtin_ia32_pmaxsw128", IX86_BUILTIN_PMAXSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31284   { OPTION_MASK_ISA_SSE2, CODE_FOR_uminv16qi3, "__builtin_ia32_pminub128", IX86_BUILTIN_PMINUB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31285   { OPTION_MASK_ISA_SSE2, CODE_FOR_sminv8hi3, "__builtin_ia32_pminsw128", IX86_BUILTIN_PMINSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31286
31287   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv16qi, "__builtin_ia32_punpckhbw128", IX86_BUILTIN_PUNPCKHBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31288   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv8hi, "__builtin_ia32_punpckhwd128", IX86_BUILTIN_PUNPCKHWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI  },
31289   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv4si, "__builtin_ia32_punpckhdq128", IX86_BUILTIN_PUNPCKHDQ128, UNKNOWN,  (int) V4SI_FTYPE_V4SI_V4SI },
31290   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_highv2di, "__builtin_ia32_punpckhqdq128", IX86_BUILTIN_PUNPCKHQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31291   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv16qi, "__builtin_ia32_punpcklbw128", IX86_BUILTIN_PUNPCKLBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31292   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv8hi, "__builtin_ia32_punpcklwd128", IX86_BUILTIN_PUNPCKLWD128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31293   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv4si, "__builtin_ia32_punpckldq128", IX86_BUILTIN_PUNPCKLDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31294   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_interleave_lowv2di, "__builtin_ia32_punpcklqdq128", IX86_BUILTIN_PUNPCKLQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31295
31296   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packsswb, "__builtin_ia32_packsswb128", IX86_BUILTIN_PACKSSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
31297   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packssdw, "__builtin_ia32_packssdw128", IX86_BUILTIN_PACKSSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
31298   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_packuswb, "__builtin_ia32_packuswb128", IX86_BUILTIN_PACKUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI },
31299
31300   { OPTION_MASK_ISA_SSE2, CODE_FOR_umulv8hi3_highpart, "__builtin_ia32_pmulhuw128", IX86_BUILTIN_PMULHUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31301   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_psadbw, "__builtin_ia32_psadbw128", IX86_BUILTIN_PSADBW128, UNKNOWN, (int) V2DI_FTYPE_V16QI_V16QI },
31302
31303   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_umulv1siv1di3, "__builtin_ia32_pmuludq", IX86_BUILTIN_PMULUDQ, UNKNOWN, (int) V1DI_FTYPE_V2SI_V2SI },
31304   { OPTION_MASK_ISA_SSE2, CODE_FOR_vec_widen_umult_even_v4si, "__builtin_ia32_pmuludq128", IX86_BUILTIN_PMULUDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
31305
31306   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pmaddwd, "__builtin_ia32_pmaddwd128", IX86_BUILTIN_PMADDWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI },
31307
31308   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsi2sd, "__builtin_ia32_cvtsi2sd", IX86_BUILTIN_CVTSI2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_SI },
31309   { OPTION_MASK_ISA_SSE2 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq, "__builtin_ia32_cvtsi642sd", IX86_BUILTIN_CVTSI642SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_DI },
31310   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtsd2ss, "__builtin_ia32_cvtsd2ss", IX86_BUILTIN_CVTSD2SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF },
31311   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_cvtss2sd, "__builtin_ia32_cvtss2sd", IX86_BUILTIN_CVTSS2SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF },
31312
31313   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_ashlv1ti3, "__builtin_ia32_pslldqi128", IX86_BUILTIN_PSLLDQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_CONVERT },
31314   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllwi128", IX86_BUILTIN_PSLLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
31315   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslldi128", IX86_BUILTIN_PSLLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
31316   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllqi128", IX86_BUILTIN_PSLLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
31317   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv8hi3, "__builtin_ia32_psllw128", IX86_BUILTIN_PSLLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
31318   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv4si3, "__builtin_ia32_pslld128", IX86_BUILTIN_PSLLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
31319   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashlv2di3, "__builtin_ia32_psllq128", IX86_BUILTIN_PSLLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
31320
31321   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_lshrv1ti3, "__builtin_ia32_psrldqi128", IX86_BUILTIN_PSRLDQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_CONVERT },
31322   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlwi128", IX86_BUILTIN_PSRLWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
31323   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrldi128", IX86_BUILTIN_PSRLDI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
31324   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlqi128", IX86_BUILTIN_PSRLQI128, UNKNOWN, (int) V2DI_FTYPE_V2DI_SI_COUNT },
31325   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv8hi3, "__builtin_ia32_psrlw128", IX86_BUILTIN_PSRLW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
31326   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv4si3, "__builtin_ia32_psrld128", IX86_BUILTIN_PSRLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
31327   { OPTION_MASK_ISA_SSE2, CODE_FOR_lshrv2di3, "__builtin_ia32_psrlq128", IX86_BUILTIN_PSRLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_COUNT },
31328
31329   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psrawi128", IX86_BUILTIN_PSRAWI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_SI_COUNT },
31330   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psradi128", IX86_BUILTIN_PSRADI128, UNKNOWN, (int) V4SI_FTYPE_V4SI_SI_COUNT },
31331   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv8hi3, "__builtin_ia32_psraw128", IX86_BUILTIN_PSRAW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_COUNT },
31332   { OPTION_MASK_ISA_SSE2, CODE_FOR_ashrv4si3, "__builtin_ia32_psrad128", IX86_BUILTIN_PSRAD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_COUNT },
31333
31334   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufd, "__builtin_ia32_pshufd", IX86_BUILTIN_PSHUFD, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT },
31335   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshuflw, "__builtin_ia32_pshuflw", IX86_BUILTIN_PSHUFLW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
31336   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_pshufhw, "__builtin_ia32_pshufhw", IX86_BUILTIN_PSHUFHW, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT },
31337
31338   { OPTION_MASK_ISA_SSE2, CODE_FOR_sse2_vmsqrtv2df2, "__builtin_ia32_sqrtsd", IX86_BUILTIN_SQRTSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_VEC_MERGE },
31339
31340   { OPTION_MASK_ISA_SSE, CODE_FOR_sse2_movq128, "__builtin_ia32_movq128", IX86_BUILTIN_MOVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
31341
31342   /* SSE2 MMX */
31343   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_addv1di3, "__builtin_ia32_paddq", IX86_BUILTIN_PADDQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
31344   { OPTION_MASK_ISA_SSE2, CODE_FOR_mmx_subv1di3, "__builtin_ia32_psubq", IX86_BUILTIN_PSUBQ, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI },
31345
31346   /* SSE3 */
31347   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movshdup, "__builtin_ia32_movshdup", IX86_BUILTIN_MOVSHDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF},
31348   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_movsldup, "__builtin_ia32_movsldup", IX86_BUILTIN_MOVSLDUP, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31349
31350   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv4sf3, "__builtin_ia32_addsubps", IX86_BUILTIN_ADDSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31351   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_addsubv2df3, "__builtin_ia32_addsubpd", IX86_BUILTIN_ADDSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31352   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv4sf3, "__builtin_ia32_haddps", IX86_BUILTIN_HADDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31353   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_haddv2df3, "__builtin_ia32_haddpd", IX86_BUILTIN_HADDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31354   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv4sf3, "__builtin_ia32_hsubps", IX86_BUILTIN_HSUBPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31355   { OPTION_MASK_ISA_SSE3, CODE_FOR_sse3_hsubv2df3, "__builtin_ia32_hsubpd", IX86_BUILTIN_HSUBPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31356
31357   /* SSSE3 */
31358   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv16qi2, "__builtin_ia32_pabsb128", IX86_BUILTIN_PABSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
31359   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8qi2, "__builtin_ia32_pabsb", IX86_BUILTIN_PABSB, UNKNOWN, (int) V8QI_FTYPE_V8QI },
31360   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv8hi2, "__builtin_ia32_pabsw128", IX86_BUILTIN_PABSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
31361   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4hi2, "__builtin_ia32_pabsw", IX86_BUILTIN_PABSW, UNKNOWN, (int) V4HI_FTYPE_V4HI },
31362   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv4si2, "__builtin_ia32_pabsd128", IX86_BUILTIN_PABSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
31363   { OPTION_MASK_ISA_SSSE3, CODE_FOR_absv2si2, "__builtin_ia32_pabsd", IX86_BUILTIN_PABSD, UNKNOWN, (int) V2SI_FTYPE_V2SI },
31364
31365   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv8hi3, "__builtin_ia32_phaddw128", IX86_BUILTIN_PHADDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31366   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddwv4hi3, "__builtin_ia32_phaddw", IX86_BUILTIN_PHADDW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31367   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv4si3, "__builtin_ia32_phaddd128", IX86_BUILTIN_PHADDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31368   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phadddv2si3, "__builtin_ia32_phaddd", IX86_BUILTIN_PHADDD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31369   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv8hi3, "__builtin_ia32_phaddsw128", IX86_BUILTIN_PHADDSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31370   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phaddswv4hi3, "__builtin_ia32_phaddsw", IX86_BUILTIN_PHADDSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31371   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv8hi3, "__builtin_ia32_phsubw128", IX86_BUILTIN_PHSUBW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31372   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubwv4hi3, "__builtin_ia32_phsubw", IX86_BUILTIN_PHSUBW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31373   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv4si3, "__builtin_ia32_phsubd128", IX86_BUILTIN_PHSUBD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31374   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubdv2si3, "__builtin_ia32_phsubd", IX86_BUILTIN_PHSUBD, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31375   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv8hi3, "__builtin_ia32_phsubsw128", IX86_BUILTIN_PHSUBSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31376   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_phsubswv4hi3, "__builtin_ia32_phsubsw", IX86_BUILTIN_PHSUBSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31377   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw128, "__builtin_ia32_pmaddubsw128", IX86_BUILTIN_PMADDUBSW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI },
31378   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmaddubsw, "__builtin_ia32_pmaddubsw", IX86_BUILTIN_PMADDUBSW, UNKNOWN, (int) V4HI_FTYPE_V8QI_V8QI },
31379   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv8hi3, "__builtin_ia32_pmulhrsw128", IX86_BUILTIN_PMULHRSW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31380   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pmulhrswv4hi3, "__builtin_ia32_pmulhrsw", IX86_BUILTIN_PMULHRSW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31381   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv16qi3, "__builtin_ia32_pshufb128", IX86_BUILTIN_PSHUFB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31382   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_pshufbv8qi3, "__builtin_ia32_pshufb", IX86_BUILTIN_PSHUFB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31383   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv16qi3, "__builtin_ia32_psignb128", IX86_BUILTIN_PSIGNB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31384   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8qi3, "__builtin_ia32_psignb", IX86_BUILTIN_PSIGNB, UNKNOWN, (int) V8QI_FTYPE_V8QI_V8QI },
31385   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv8hi3, "__builtin_ia32_psignw128", IX86_BUILTIN_PSIGNW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31386   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4hi3, "__builtin_ia32_psignw", IX86_BUILTIN_PSIGNW, UNKNOWN, (int) V4HI_FTYPE_V4HI_V4HI },
31387   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv4si3, "__builtin_ia32_psignd128", IX86_BUILTIN_PSIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31388   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_psignv2si3, "__builtin_ia32_psignd", IX86_BUILTIN_PSIGND, UNKNOWN, (int) V2SI_FTYPE_V2SI_V2SI },
31389
31390   /* SSSE3.  */
31391   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrti, "__builtin_ia32_palignr128", IX86_BUILTIN_PALIGNR128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT_CONVERT },
31392   { OPTION_MASK_ISA_SSSE3, CODE_FOR_ssse3_palignrdi, "__builtin_ia32_palignr", IX86_BUILTIN_PALIGNR, UNKNOWN, (int) V1DI_FTYPE_V1DI_V1DI_INT_CONVERT },
31393
31394   /* SSE4.1 */
31395   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendpd, "__builtin_ia32_blendpd", IX86_BUILTIN_BLENDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31396   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendps, "__builtin_ia32_blendps", IX86_BUILTIN_BLENDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31397   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvpd, "__builtin_ia32_blendvpd", IX86_BUILTIN_BLENDVPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF },
31398   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_blendvps, "__builtin_ia32_blendvps", IX86_BUILTIN_BLENDVPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF },
31399   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dppd, "__builtin_ia32_dppd", IX86_BUILTIN_DPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31400   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_dpps, "__builtin_ia32_dpps", IX86_BUILTIN_DPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31401   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_insertps, "__builtin_ia32_insertps128", IX86_BUILTIN_INSERTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31402   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mpsadbw, "__builtin_ia32_mpsadbw128", IX86_BUILTIN_MPSADBW128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_INT },
31403   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendvb, "__builtin_ia32_pblendvb128", IX86_BUILTIN_PBLENDVB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI },
31404   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_pblendw, "__builtin_ia32_pblendw128", IX86_BUILTIN_PBLENDW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_INT },
31405
31406   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv8qiv8hi2, "__builtin_ia32_pmovsxbw128", IX86_BUILTIN_PMOVSXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
31407   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv4qiv4si2, "__builtin_ia32_pmovsxbd128", IX86_BUILTIN_PMOVSXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
31408   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv2qiv2di2, "__builtin_ia32_pmovsxbq128", IX86_BUILTIN_PMOVSXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
31409   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv4hiv4si2, "__builtin_ia32_pmovsxwd128", IX86_BUILTIN_PMOVSXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
31410   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv2hiv2di2, "__builtin_ia32_pmovsxwq128", IX86_BUILTIN_PMOVSXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
31411   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_sign_extendv2siv2di2, "__builtin_ia32_pmovsxdq128", IX86_BUILTIN_PMOVSXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
31412   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv8qiv8hi2, "__builtin_ia32_pmovzxbw128", IX86_BUILTIN_PMOVZXBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI },
31413   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4qiv4si2, "__builtin_ia32_pmovzxbd128", IX86_BUILTIN_PMOVZXBD128, UNKNOWN, (int) V4SI_FTYPE_V16QI },
31414   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2qiv2di2, "__builtin_ia32_pmovzxbq128", IX86_BUILTIN_PMOVZXBQ128, UNKNOWN, (int) V2DI_FTYPE_V16QI },
31415   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv4hiv4si2, "__builtin_ia32_pmovzxwd128", IX86_BUILTIN_PMOVZXWD128, UNKNOWN, (int) V4SI_FTYPE_V8HI },
31416   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2hiv2di2, "__builtin_ia32_pmovzxwq128", IX86_BUILTIN_PMOVZXWQ128, UNKNOWN, (int) V2DI_FTYPE_V8HI },
31417   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_zero_extendv2siv2di2, "__builtin_ia32_pmovzxdq128", IX86_BUILTIN_PMOVZXDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI },
31418   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_phminposuw, "__builtin_ia32_phminposuw128", IX86_BUILTIN_PHMINPOSUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
31419
31420   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_packusdw, "__builtin_ia32_packusdw128", IX86_BUILTIN_PACKUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI },
31421   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_eqv2di3, "__builtin_ia32_pcmpeqq", IX86_BUILTIN_PCMPEQQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31422   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv16qi3, "__builtin_ia32_pmaxsb128", IX86_BUILTIN_PMAXSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31423   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_smaxv4si3, "__builtin_ia32_pmaxsd128", IX86_BUILTIN_PMAXSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31424   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv4si3, "__builtin_ia32_pmaxud128", IX86_BUILTIN_PMAXUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31425   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_umaxv8hi3, "__builtin_ia32_pmaxuw128", IX86_BUILTIN_PMAXUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31426   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv16qi3, "__builtin_ia32_pminsb128", IX86_BUILTIN_PMINSB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI },
31427   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sminv4si3, "__builtin_ia32_pminsd128", IX86_BUILTIN_PMINSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31428   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv4si3, "__builtin_ia32_pminud128", IX86_BUILTIN_PMINUD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31429   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_uminv8hi3, "__builtin_ia32_pminuw128", IX86_BUILTIN_PMINUW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI },
31430   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_sse4_1_mulv2siv2di3, "__builtin_ia32_pmuldq128", IX86_BUILTIN_PMULDQ128, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI },
31431   { OPTION_MASK_ISA_SSE4_1, CODE_FOR_mulv4si3, "__builtin_ia32_pmulld128", IX86_BUILTIN_PMULLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31432
31433   /* SSE4.1 */
31434   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_roundpd", IX86_BUILTIN_ROUNDPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
31435   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_roundps", IX86_BUILTIN_ROUNDPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
31436   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundsd, "__builtin_ia32_roundsd", IX86_BUILTIN_ROUNDSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31437   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundss, "__builtin_ia32_roundss", IX86_BUILTIN_ROUNDSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31438
31439   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_floorpd", IX86_BUILTIN_FLOORPD, (enum rtx_code) ROUND_FLOOR, (int) V2DF_FTYPE_V2DF_ROUND },
31440   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_ceilpd", IX86_BUILTIN_CEILPD, (enum rtx_code) ROUND_CEIL, (int) V2DF_FTYPE_V2DF_ROUND },
31441   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_truncpd", IX86_BUILTIN_TRUNCPD, (enum rtx_code) ROUND_TRUNC, (int) V2DF_FTYPE_V2DF_ROUND },
31442   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd, "__builtin_ia32_rintpd", IX86_BUILTIN_RINTPD, (enum rtx_code) ROUND_MXCSR, (int) V2DF_FTYPE_V2DF_ROUND },
31443
31444   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd_vec_pack_sfix, "__builtin_ia32_floorpd_vec_pack_sfix", IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX, (enum rtx_code) ROUND_FLOOR, (int) V4SI_FTYPE_V2DF_V2DF_ROUND },
31445   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundpd_vec_pack_sfix, "__builtin_ia32_ceilpd_vec_pack_sfix", IX86_BUILTIN_CEILPD_VEC_PACK_SFIX, (enum rtx_code) ROUND_CEIL, (int) V4SI_FTYPE_V2DF_V2DF_ROUND },
31446
31447   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv2df2, "__builtin_ia32_roundpd_az", IX86_BUILTIN_ROUNDPD_AZ, UNKNOWN, (int) V2DF_FTYPE_V2DF },
31448   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv2df2_vec_pack_sfix, "__builtin_ia32_roundpd_az_vec_pack_sfix", IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX, UNKNOWN, (int) V4SI_FTYPE_V2DF_V2DF },
31449
31450   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_floorps", IX86_BUILTIN_FLOORPS, (enum rtx_code) ROUND_FLOOR, (int) V4SF_FTYPE_V4SF_ROUND },
31451   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_ceilps", IX86_BUILTIN_CEILPS, (enum rtx_code) ROUND_CEIL, (int) V4SF_FTYPE_V4SF_ROUND },
31452   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_truncps", IX86_BUILTIN_TRUNCPS, (enum rtx_code) ROUND_TRUNC, (int) V4SF_FTYPE_V4SF_ROUND },
31453   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps, "__builtin_ia32_rintps", IX86_BUILTIN_RINTPS, (enum rtx_code) ROUND_MXCSR, (int) V4SF_FTYPE_V4SF_ROUND },
31454
31455   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps_sfix, "__builtin_ia32_floorps_sfix", IX86_BUILTIN_FLOORPS_SFIX, (enum rtx_code) ROUND_FLOOR, (int) V4SI_FTYPE_V4SF_ROUND },
31456   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_roundps_sfix, "__builtin_ia32_ceilps_sfix", IX86_BUILTIN_CEILPS_SFIX, (enum rtx_code) ROUND_CEIL, (int) V4SI_FTYPE_V4SF_ROUND },
31457
31458   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv4sf2, "__builtin_ia32_roundps_az", IX86_BUILTIN_ROUNDPS_AZ, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31459   { OPTION_MASK_ISA_ROUND, CODE_FOR_roundv4sf2_sfix, "__builtin_ia32_roundps_az_sfix", IX86_BUILTIN_ROUNDPS_AZ_SFIX, UNKNOWN, (int) V4SI_FTYPE_V4SF },
31460
31461   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestz128", IX86_BUILTIN_PTESTZ, EQ, (int) INT_FTYPE_V2DI_V2DI_PTEST },
31462   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestc128", IX86_BUILTIN_PTESTC, LTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
31463   { OPTION_MASK_ISA_ROUND, CODE_FOR_sse4_1_ptest, "__builtin_ia32_ptestnzc128", IX86_BUILTIN_PTESTNZC, GTU, (int) INT_FTYPE_V2DI_V2DI_PTEST },
31464
31465   /* SSE4.2 */
31466   { OPTION_MASK_ISA_SSE4_2, CODE_FOR_sse4_2_gtv2di3, "__builtin_ia32_pcmpgtq", IX86_BUILTIN_PCMPGTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31467   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_CRC32, CODE_FOR_sse4_2_crc32qi, "__builtin_ia32_crc32qi", IX86_BUILTIN_CRC32QI, UNKNOWN, (int) UINT_FTYPE_UINT_UCHAR },
31468   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_CRC32, CODE_FOR_sse4_2_crc32hi, "__builtin_ia32_crc32hi", IX86_BUILTIN_CRC32HI, UNKNOWN, (int) UINT_FTYPE_UINT_USHORT },
31469   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_CRC32, CODE_FOR_sse4_2_crc32si, "__builtin_ia32_crc32si", IX86_BUILTIN_CRC32SI, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31470   { OPTION_MASK_ISA_SSE4_2 | OPTION_MASK_ISA_CRC32 | OPTION_MASK_ISA_64BIT, CODE_FOR_sse4_2_crc32di, "__builtin_ia32_crc32di", IX86_BUILTIN_CRC32DI, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31471
31472   /* SSE4A */
31473   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrqi, "__builtin_ia32_extrqi", IX86_BUILTIN_EXTRQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_UINT_UINT },
31474   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_extrq, "__builtin_ia32_extrq", IX86_BUILTIN_EXTRQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V16QI },
31475   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertqi, "__builtin_ia32_insertqi", IX86_BUILTIN_INSERTQI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_UINT_UINT },
31476   { OPTION_MASK_ISA_SSE4A, CODE_FOR_sse4a_insertq, "__builtin_ia32_insertq", IX86_BUILTIN_INSERTQ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31477
31478   /* AES */
31479   { OPTION_MASK_ISA_SSE2, CODE_FOR_aeskeygenassist, 0, IX86_BUILTIN_AESKEYGENASSIST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT },
31480   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesimc, 0, IX86_BUILTIN_AESIMC128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
31481
31482   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenc, 0, IX86_BUILTIN_AESENC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31483   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesenclast, 0, IX86_BUILTIN_AESENCLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31484   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdec, 0, IX86_BUILTIN_AESDEC128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31485   { OPTION_MASK_ISA_SSE2, CODE_FOR_aesdeclast, 0, IX86_BUILTIN_AESDECLAST128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31486
31487   /* PCLMUL */
31488   { OPTION_MASK_ISA_SSE2, CODE_FOR_pclmulqdq, 0, IX86_BUILTIN_PCLMULQDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT },
31489
31490   /* AVX */
31491   { OPTION_MASK_ISA_AVX, CODE_FOR_addv4df3, "__builtin_ia32_addpd256", IX86_BUILTIN_ADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31492   { OPTION_MASK_ISA_AVX, CODE_FOR_addv8sf3, "__builtin_ia32_addps256", IX86_BUILTIN_ADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31493   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv4df3, "__builtin_ia32_addsubpd256", IX86_BUILTIN_ADDSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31494   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_addsubv8sf3, "__builtin_ia32_addsubps256", IX86_BUILTIN_ADDSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31495   { OPTION_MASK_ISA_AVX, CODE_FOR_andv4df3, "__builtin_ia32_andpd256", IX86_BUILTIN_ANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31496   { OPTION_MASK_ISA_AVX, CODE_FOR_andv8sf3, "__builtin_ia32_andps256", IX86_BUILTIN_ANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31497   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv4df3, "__builtin_ia32_andnpd256", IX86_BUILTIN_ANDNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31498   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_andnotv8sf3, "__builtin_ia32_andnps256", IX86_BUILTIN_ANDNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31499   { OPTION_MASK_ISA_AVX, CODE_FOR_divv4df3, "__builtin_ia32_divpd256", IX86_BUILTIN_DIVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31500   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_divv8sf3, "__builtin_ia32_divps256", IX86_BUILTIN_DIVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31501   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv4df3, "__builtin_ia32_haddpd256", IX86_BUILTIN_HADDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31502   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv8sf3, "__builtin_ia32_hsubps256", IX86_BUILTIN_HSUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31503   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_hsubv4df3, "__builtin_ia32_hsubpd256", IX86_BUILTIN_HSUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31504   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_haddv8sf3, "__builtin_ia32_haddps256", IX86_BUILTIN_HADDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31505   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv4df3, "__builtin_ia32_maxpd256", IX86_BUILTIN_MAXPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31506   { OPTION_MASK_ISA_AVX, CODE_FOR_smaxv8sf3, "__builtin_ia32_maxps256", IX86_BUILTIN_MAXPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31507   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv4df3, "__builtin_ia32_minpd256", IX86_BUILTIN_MINPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31508   { OPTION_MASK_ISA_AVX, CODE_FOR_sminv8sf3, "__builtin_ia32_minps256", IX86_BUILTIN_MINPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31509   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv4df3, "__builtin_ia32_mulpd256", IX86_BUILTIN_MULPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31510   { OPTION_MASK_ISA_AVX, CODE_FOR_mulv8sf3, "__builtin_ia32_mulps256", IX86_BUILTIN_MULPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31511   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv4df3, "__builtin_ia32_orpd256", IX86_BUILTIN_ORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31512   { OPTION_MASK_ISA_AVX, CODE_FOR_iorv8sf3, "__builtin_ia32_orps256", IX86_BUILTIN_ORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31513   { OPTION_MASK_ISA_AVX, CODE_FOR_subv4df3, "__builtin_ia32_subpd256", IX86_BUILTIN_SUBPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31514   { OPTION_MASK_ISA_AVX, CODE_FOR_subv8sf3, "__builtin_ia32_subps256", IX86_BUILTIN_SUBPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31515   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv4df3, "__builtin_ia32_xorpd256", IX86_BUILTIN_XORPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31516   { OPTION_MASK_ISA_AVX, CODE_FOR_xorv8sf3, "__builtin_ia32_xorps256", IX86_BUILTIN_XORPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31517
31518   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv2df3, "__builtin_ia32_vpermilvarpd", IX86_BUILTIN_VPERMILVARPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI },
31519   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4sf3, "__builtin_ia32_vpermilvarps", IX86_BUILTIN_VPERMILVARPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI },
31520   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv4df3, "__builtin_ia32_vpermilvarpd256", IX86_BUILTIN_VPERMILVARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI },
31521   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilvarv8sf3, "__builtin_ia32_vpermilvarps256", IX86_BUILTIN_VPERMILVARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
31522
31523   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendpd256, "__builtin_ia32_blendpd256", IX86_BUILTIN_BLENDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31524   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendps256, "__builtin_ia32_blendps256", IX86_BUILTIN_BLENDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31525   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvpd256, "__builtin_ia32_blendvpd256", IX86_BUILTIN_BLENDVPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF },
31526   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_blendvps256, "__builtin_ia32_blendvps256", IX86_BUILTIN_BLENDVPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF },
31527   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_dpps256, "__builtin_ia32_dpps256", IX86_BUILTIN_DPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31528   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufpd256, "__builtin_ia32_shufpd256", IX86_BUILTIN_SHUFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31529   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_shufps256, "__builtin_ia32_shufps256", IX86_BUILTIN_SHUFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31530   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vmcmpv2df3, "__builtin_ia32_cmpsd", IX86_BUILTIN_CMPSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31531   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vmcmpv4sf3, "__builtin_ia32_cmpss", IX86_BUILTIN_CMPSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31532   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv2df3, "__builtin_ia32_cmppd", IX86_BUILTIN_CMPPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
31533   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv4sf3, "__builtin_ia32_cmpps", IX86_BUILTIN_CMPPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
31534   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv4df3, "__builtin_ia32_cmppd256", IX86_BUILTIN_CMPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31535   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cmpv8sf3, "__builtin_ia32_cmpps256", IX86_BUILTIN_CMPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31536   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v4df, "__builtin_ia32_vextractf128_pd256", IX86_BUILTIN_EXTRACTF128PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT },
31537   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8sf, "__builtin_ia32_vextractf128_ps256", IX86_BUILTIN_EXTRACTF128PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT },
31538   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vextractf128v8si, "__builtin_ia32_vextractf128_si256", IX86_BUILTIN_EXTRACTF128SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT },
31539   { OPTION_MASK_ISA_AVX, CODE_FOR_floatv4siv4df2, "__builtin_ia32_cvtdq2pd256", IX86_BUILTIN_CVTDQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SI },
31540   { OPTION_MASK_ISA_AVX, CODE_FOR_floatv8siv8sf2, "__builtin_ia32_cvtdq2ps256", IX86_BUILTIN_CVTDQ2PS256, UNKNOWN, (int) V8SF_FTYPE_V8SI },
31541   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2ps256, "__builtin_ia32_cvtpd2ps256", IX86_BUILTIN_CVTPD2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DF },
31542   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_fix_notruncv8sfv8si, "__builtin_ia32_cvtps2dq256", IX86_BUILTIN_CVTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
31543   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtps2pd256, "__builtin_ia32_cvtps2pd256", IX86_BUILTIN_CVTPS2PD256, UNKNOWN, (int) V4DF_FTYPE_V4SF },
31544   { OPTION_MASK_ISA_AVX, CODE_FOR_fix_truncv4dfv4si2, "__builtin_ia32_cvttpd2dq256", IX86_BUILTIN_CVTTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
31545   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_cvtpd2dq256, "__builtin_ia32_cvtpd2dq256", IX86_BUILTIN_CVTPD2DQ256, UNKNOWN, (int) V4SI_FTYPE_V4DF },
31546   { OPTION_MASK_ISA_AVX, CODE_FOR_fix_truncv8sfv8si2, "__builtin_ia32_cvttps2dq256", IX86_BUILTIN_CVTTPS2DQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
31547   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v4df3, "__builtin_ia32_vperm2f128_pd256", IX86_BUILTIN_VPERM2F128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT },
31548   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8sf3, "__builtin_ia32_vperm2f128_ps256", IX86_BUILTIN_VPERM2F128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT },
31549   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vperm2f128v8si3, "__builtin_ia32_vperm2f128_si256", IX86_BUILTIN_VPERM2F128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
31550   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv2df, "__builtin_ia32_vpermilpd", IX86_BUILTIN_VPERMILPD, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT },
31551   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4sf, "__builtin_ia32_vpermilps", IX86_BUILTIN_VPERMILPS, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT },
31552   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv4df, "__builtin_ia32_vpermilpd256", IX86_BUILTIN_VPERMILPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
31553   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vpermilv8sf, "__builtin_ia32_vpermilps256", IX86_BUILTIN_VPERMILPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
31554   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v4df, "__builtin_ia32_vinsertf128_pd256", IX86_BUILTIN_VINSERTF128PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT },
31555   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8sf, "__builtin_ia32_vinsertf128_ps256", IX86_BUILTIN_VINSERTF128PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT },
31556   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vinsertf128v8si, "__builtin_ia32_vinsertf128_si256", IX86_BUILTIN_VINSERTF128SI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT },
31557
31558   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movshdup256, "__builtin_ia32_movshdup256", IX86_BUILTIN_MOVSHDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31559   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movsldup256, "__builtin_ia32_movsldup256", IX86_BUILTIN_MOVSLDUP256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31560   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movddup256, "__builtin_ia32_movddup256", IX86_BUILTIN_MOVDDUP256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
31561
31562   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv4df2, "__builtin_ia32_sqrtpd256", IX86_BUILTIN_SQRTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
31563   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_sqrtv8sf2, "__builtin_ia32_sqrtps256", IX86_BUILTIN_SQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31564   { OPTION_MASK_ISA_AVX, CODE_FOR_sqrtv8sf2, "__builtin_ia32_sqrtps_nr256", IX86_BUILTIN_SQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31565   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rsqrtv8sf2, "__builtin_ia32_rsqrtps256", IX86_BUILTIN_RSQRTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31566   { OPTION_MASK_ISA_AVX, CODE_FOR_rsqrtv8sf2, "__builtin_ia32_rsqrtps_nr256", IX86_BUILTIN_RSQRTPS_NR256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31567
31568   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_rcpv8sf2, "__builtin_ia32_rcpps256", IX86_BUILTIN_RCPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31569
31570   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_roundpd256", IX86_BUILTIN_ROUNDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
31571   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_roundps256", IX86_BUILTIN_ROUNDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT },
31572
31573   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_floorpd256", IX86_BUILTIN_FLOORPD256, (enum rtx_code) ROUND_FLOOR, (int) V4DF_FTYPE_V4DF_ROUND },
31574   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_ceilpd256", IX86_BUILTIN_CEILPD256, (enum rtx_code) ROUND_CEIL, (int) V4DF_FTYPE_V4DF_ROUND },
31575   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_truncpd256", IX86_BUILTIN_TRUNCPD256, (enum rtx_code) ROUND_TRUNC, (int) V4DF_FTYPE_V4DF_ROUND },
31576   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd256, "__builtin_ia32_rintpd256", IX86_BUILTIN_RINTPD256, (enum rtx_code) ROUND_MXCSR, (int) V4DF_FTYPE_V4DF_ROUND },
31577
31578   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv4df2, "__builtin_ia32_roundpd_az256", IX86_BUILTIN_ROUNDPD_AZ256, UNKNOWN, (int) V4DF_FTYPE_V4DF },
31579   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv4df2_vec_pack_sfix, "__builtin_ia32_roundpd_az_vec_pack_sfix256", IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX256, UNKNOWN, (int) V8SI_FTYPE_V4DF_V4DF },
31580
31581   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd_vec_pack_sfix256, "__builtin_ia32_floorpd_vec_pack_sfix256", IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX256, (enum rtx_code) ROUND_FLOOR, (int) V8SI_FTYPE_V4DF_V4DF_ROUND },
31582   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundpd_vec_pack_sfix256, "__builtin_ia32_ceilpd_vec_pack_sfix256", IX86_BUILTIN_CEILPD_VEC_PACK_SFIX256, (enum rtx_code) ROUND_CEIL, (int) V8SI_FTYPE_V4DF_V4DF_ROUND },
31583
31584   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_floorps256", IX86_BUILTIN_FLOORPS256, (enum rtx_code) ROUND_FLOOR, (int) V8SF_FTYPE_V8SF_ROUND },
31585   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_ceilps256", IX86_BUILTIN_CEILPS256, (enum rtx_code) ROUND_CEIL, (int) V8SF_FTYPE_V8SF_ROUND },
31586   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_truncps256", IX86_BUILTIN_TRUNCPS256, (enum rtx_code) ROUND_TRUNC, (int) V8SF_FTYPE_V8SF_ROUND },
31587   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps256, "__builtin_ia32_rintps256", IX86_BUILTIN_RINTPS256, (enum rtx_code) ROUND_MXCSR, (int) V8SF_FTYPE_V8SF_ROUND },
31588
31589   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps_sfix256, "__builtin_ia32_floorps_sfix256", IX86_BUILTIN_FLOORPS_SFIX256, (enum rtx_code) ROUND_FLOOR, (int) V8SI_FTYPE_V8SF_ROUND },
31590   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_roundps_sfix256, "__builtin_ia32_ceilps_sfix256", IX86_BUILTIN_CEILPS_SFIX256, (enum rtx_code) ROUND_CEIL, (int) V8SI_FTYPE_V8SF_ROUND },
31591
31592   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv8sf2, "__builtin_ia32_roundps_az256", IX86_BUILTIN_ROUNDPS_AZ256, UNKNOWN, (int) V8SF_FTYPE_V8SF },
31593   { OPTION_MASK_ISA_AVX, CODE_FOR_roundv8sf2_sfix, "__builtin_ia32_roundps_az_sfix256", IX86_BUILTIN_ROUNDPS_AZ_SFIX256, UNKNOWN, (int) V8SI_FTYPE_V8SF },
31594
31595   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhpd256,  "__builtin_ia32_unpckhpd256", IX86_BUILTIN_UNPCKHPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31596   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklpd256,  "__builtin_ia32_unpcklpd256", IX86_BUILTIN_UNPCKLPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31597   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpckhps256,  "__builtin_ia32_unpckhps256", IX86_BUILTIN_UNPCKHPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31598   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_unpcklps256,  "__builtin_ia32_unpcklps256", IX86_BUILTIN_UNPCKLPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31599
31600   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_si256_si, "__builtin_ia32_si256_si", IX86_BUILTIN_SI256_SI, UNKNOWN, (int) V8SI_FTYPE_V4SI },
31601   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ps256_ps, "__builtin_ia32_ps256_ps", IX86_BUILTIN_PS256_PS, UNKNOWN, (int) V8SF_FTYPE_V4SF },
31602   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_pd256_pd, "__builtin_ia32_pd256_pd", IX86_BUILTIN_PD256_PD, UNKNOWN, (int) V4DF_FTYPE_V2DF },
31603   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_extract_lo_v8si, "__builtin_ia32_si_si256", IX86_BUILTIN_SI_SI256, UNKNOWN, (int) V4SI_FTYPE_V8SI },
31604   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_extract_lo_v8sf, "__builtin_ia32_ps_ps256", IX86_BUILTIN_PS_PS256, UNKNOWN, (int) V4SF_FTYPE_V8SF },
31605   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_extract_lo_v4df, "__builtin_ia32_pd_pd256", IX86_BUILTIN_PD_PD256, UNKNOWN, (int) V2DF_FTYPE_V4DF },
31606
31607   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestzpd", IX86_BUILTIN_VTESTZPD, EQ, (int) INT_FTYPE_V2DF_V2DF_PTEST },
31608   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestcpd", IX86_BUILTIN_VTESTCPD, LTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
31609   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd, "__builtin_ia32_vtestnzcpd", IX86_BUILTIN_VTESTNZCPD, GTU, (int) INT_FTYPE_V2DF_V2DF_PTEST },
31610   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestzps", IX86_BUILTIN_VTESTZPS, EQ, (int) INT_FTYPE_V4SF_V4SF_PTEST },
31611   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestcps", IX86_BUILTIN_VTESTCPS, LTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
31612   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps, "__builtin_ia32_vtestnzcps", IX86_BUILTIN_VTESTNZCPS, GTU, (int) INT_FTYPE_V4SF_V4SF_PTEST },
31613   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestzpd256", IX86_BUILTIN_VTESTZPD256, EQ, (int) INT_FTYPE_V4DF_V4DF_PTEST },
31614   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestcpd256", IX86_BUILTIN_VTESTCPD256, LTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
31615   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestpd256, "__builtin_ia32_vtestnzcpd256", IX86_BUILTIN_VTESTNZCPD256, GTU, (int) INT_FTYPE_V4DF_V4DF_PTEST },
31616   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestzps256", IX86_BUILTIN_VTESTZPS256, EQ, (int) INT_FTYPE_V8SF_V8SF_PTEST },
31617   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestcps256", IX86_BUILTIN_VTESTCPS256, LTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
31618   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_vtestps256, "__builtin_ia32_vtestnzcps256", IX86_BUILTIN_VTESTNZCPS256, GTU, (int) INT_FTYPE_V8SF_V8SF_PTEST },
31619   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestz256", IX86_BUILTIN_PTESTZ256, EQ, (int) INT_FTYPE_V4DI_V4DI_PTEST },
31620   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestc256", IX86_BUILTIN_PTESTC256, LTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
31621   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_ptest256, "__builtin_ia32_ptestnzc256", IX86_BUILTIN_PTESTNZC256, GTU, (int) INT_FTYPE_V4DI_V4DI_PTEST },
31622
31623   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskpd256, "__builtin_ia32_movmskpd256", IX86_BUILTIN_MOVMSKPD256, UNKNOWN, (int) INT_FTYPE_V4DF  },
31624   { OPTION_MASK_ISA_AVX, CODE_FOR_avx_movmskps256, "__builtin_ia32_movmskps256", IX86_BUILTIN_MOVMSKPS256, UNKNOWN, (int) INT_FTYPE_V8SF },
31625
31626   { OPTION_MASK_ISA_AVX, CODE_FOR_copysignv8sf3,  "__builtin_ia32_copysignps256", IX86_BUILTIN_CPYSGNPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF },
31627   { OPTION_MASK_ISA_AVX, CODE_FOR_copysignv4df3,  "__builtin_ia32_copysignpd256", IX86_BUILTIN_CPYSGNPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF },
31628
31629   { OPTION_MASK_ISA_AVX, CODE_FOR_vec_pack_sfix_v4df, "__builtin_ia32_vec_pack_sfix256 ", IX86_BUILTIN_VEC_PACK_SFIX256, UNKNOWN, (int) V8SI_FTYPE_V4DF_V4DF },
31630
31631   /* AVX2 */
31632   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_mpsadbw, "__builtin_ia32_mpsadbw256", IX86_BUILTIN_MPSADBW256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_INT },
31633   { OPTION_MASK_ISA_AVX2, CODE_FOR_absv32qi2, "__builtin_ia32_pabsb256", IX86_BUILTIN_PABSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI },
31634   { OPTION_MASK_ISA_AVX2, CODE_FOR_absv16hi2, "__builtin_ia32_pabsw256", IX86_BUILTIN_PABSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI },
31635   { OPTION_MASK_ISA_AVX2, CODE_FOR_absv8si2, "__builtin_ia32_pabsd256", IX86_BUILTIN_PABSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI },
31636   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packssdw, "__builtin_ia32_packssdw256",  IX86_BUILTIN_PACKSSDW256, UNKNOWN, (int) V16HI_FTYPE_V8SI_V8SI },
31637   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packsswb, "__builtin_ia32_packsswb256",  IX86_BUILTIN_PACKSSWB256, UNKNOWN, (int) V32QI_FTYPE_V16HI_V16HI },
31638   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packusdw, "__builtin_ia32_packusdw256",  IX86_BUILTIN_PACKUSDW256, UNKNOWN, (int) V16HI_FTYPE_V8SI_V8SI },
31639   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_packuswb, "__builtin_ia32_packuswb256",  IX86_BUILTIN_PACKUSWB256, UNKNOWN, (int) V32QI_FTYPE_V16HI_V16HI },
31640   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv32qi3, "__builtin_ia32_paddb256", IX86_BUILTIN_PADDB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31641   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv16hi3, "__builtin_ia32_paddw256", IX86_BUILTIN_PADDW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31642   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv8si3, "__builtin_ia32_paddd256", IX86_BUILTIN_PADDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31643   { OPTION_MASK_ISA_AVX2, CODE_FOR_addv4di3, "__builtin_ia32_paddq256", IX86_BUILTIN_PADDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31644   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ssaddv32qi3, "__builtin_ia32_paddsb256", IX86_BUILTIN_PADDSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31645   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ssaddv16hi3, "__builtin_ia32_paddsw256", IX86_BUILTIN_PADDSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31646   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_usaddv32qi3, "__builtin_ia32_paddusb256", IX86_BUILTIN_PADDUSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31647   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_usaddv16hi3, "__builtin_ia32_paddusw256", IX86_BUILTIN_PADDUSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31648   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_palignrv2ti, "__builtin_ia32_palignr256", IX86_BUILTIN_PALIGNR256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_INT_CONVERT },
31649   { OPTION_MASK_ISA_AVX2, CODE_FOR_andv4di3, "__builtin_ia32_andsi256", IX86_BUILTIN_AND256I, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31650   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_andnotv4di3, "__builtin_ia32_andnotsi256", IX86_BUILTIN_ANDNOT256I, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31651   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_uavgv32qi3, "__builtin_ia32_pavgb256",  IX86_BUILTIN_PAVGB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31652   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_uavgv16hi3, "__builtin_ia32_pavgw256",  IX86_BUILTIN_PAVGW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31653   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblendvb, "__builtin_ia32_pblendvb256", IX86_BUILTIN_PBLENDVB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI },
31654   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblendw, "__builtin_ia32_pblendw256", IX86_BUILTIN_PBLENDVW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_INT },
31655   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv32qi3, "__builtin_ia32_pcmpeqb256", IX86_BUILTIN_PCMPEQB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31656   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv16hi3, "__builtin_ia32_pcmpeqw256", IX86_BUILTIN_PCMPEQW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31657   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv8si3, "__builtin_ia32_pcmpeqd256", IX86_BUILTIN_PCMPEQD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI  },
31658   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_eqv4di3, "__builtin_ia32_pcmpeqq256", IX86_BUILTIN_PCMPEQQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI  },
31659   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv32qi3, "__builtin_ia32_pcmpgtb256", IX86_BUILTIN_PCMPGTB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31660   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv16hi3, "__builtin_ia32_pcmpgtw256", IX86_BUILTIN_PCMPGTW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31661   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv8si3, "__builtin_ia32_pcmpgtd256", IX86_BUILTIN_PCMPGTD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI  },
31662   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_gtv4di3, "__builtin_ia32_pcmpgtq256", IX86_BUILTIN_PCMPGTQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI  },
31663   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phaddwv16hi3, "__builtin_ia32_phaddw256", IX86_BUILTIN_PHADDW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31664   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phadddv8si3, "__builtin_ia32_phaddd256", IX86_BUILTIN_PHADDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31665   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phaddswv16hi3, "__builtin_ia32_phaddsw256", IX86_BUILTIN_PHADDSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31666   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phsubwv16hi3, "__builtin_ia32_phsubw256", IX86_BUILTIN_PHSUBW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31667   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phsubdv8si3, "__builtin_ia32_phsubd256", IX86_BUILTIN_PHSUBD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31668   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_phsubswv16hi3, "__builtin_ia32_phsubsw256", IX86_BUILTIN_PHSUBSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31669   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmaddubsw256, "__builtin_ia32_pmaddubsw256", IX86_BUILTIN_PMADDUBSW256, UNKNOWN, (int) V16HI_FTYPE_V32QI_V32QI },
31670   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmaddwd, "__builtin_ia32_pmaddwd256", IX86_BUILTIN_PMADDWD256, UNKNOWN, (int) V8SI_FTYPE_V16HI_V16HI },
31671   { OPTION_MASK_ISA_AVX2, CODE_FOR_smaxv32qi3, "__builtin_ia32_pmaxsb256", IX86_BUILTIN_PMAXSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31672   { OPTION_MASK_ISA_AVX2, CODE_FOR_smaxv16hi3, "__builtin_ia32_pmaxsw256", IX86_BUILTIN_PMAXSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31673   { OPTION_MASK_ISA_AVX2, CODE_FOR_smaxv8si3 , "__builtin_ia32_pmaxsd256", IX86_BUILTIN_PMAXSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31674   { OPTION_MASK_ISA_AVX2, CODE_FOR_umaxv32qi3, "__builtin_ia32_pmaxub256", IX86_BUILTIN_PMAXUB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31675   { OPTION_MASK_ISA_AVX2, CODE_FOR_umaxv16hi3, "__builtin_ia32_pmaxuw256", IX86_BUILTIN_PMAXUW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31676   { OPTION_MASK_ISA_AVX2, CODE_FOR_umaxv8si3 , "__builtin_ia32_pmaxud256", IX86_BUILTIN_PMAXUD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31677   { OPTION_MASK_ISA_AVX2, CODE_FOR_sminv32qi3, "__builtin_ia32_pminsb256", IX86_BUILTIN_PMINSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31678   { OPTION_MASK_ISA_AVX2, CODE_FOR_sminv16hi3, "__builtin_ia32_pminsw256", IX86_BUILTIN_PMINSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31679   { OPTION_MASK_ISA_AVX2, CODE_FOR_sminv8si3 , "__builtin_ia32_pminsd256", IX86_BUILTIN_PMINSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31680   { OPTION_MASK_ISA_AVX2, CODE_FOR_uminv32qi3, "__builtin_ia32_pminub256", IX86_BUILTIN_PMINUB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31681   { OPTION_MASK_ISA_AVX2, CODE_FOR_uminv16hi3, "__builtin_ia32_pminuw256", IX86_BUILTIN_PMINUW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31682   { OPTION_MASK_ISA_AVX2, CODE_FOR_uminv8si3 , "__builtin_ia32_pminud256", IX86_BUILTIN_PMINUD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31683   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmovmskb, "__builtin_ia32_pmovmskb256", IX86_BUILTIN_PMOVMSKB256, UNKNOWN, (int) INT_FTYPE_V32QI },
31684   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv16qiv16hi2, "__builtin_ia32_pmovsxbw256", IX86_BUILTIN_PMOVSXBW256, UNKNOWN, (int) V16HI_FTYPE_V16QI },
31685   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv8qiv8si2  , "__builtin_ia32_pmovsxbd256", IX86_BUILTIN_PMOVSXBD256, UNKNOWN, (int) V8SI_FTYPE_V16QI },
31686   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv4qiv4di2  , "__builtin_ia32_pmovsxbq256", IX86_BUILTIN_PMOVSXBQ256, UNKNOWN, (int) V4DI_FTYPE_V16QI },
31687   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv8hiv8si2  , "__builtin_ia32_pmovsxwd256", IX86_BUILTIN_PMOVSXWD256, UNKNOWN, (int) V8SI_FTYPE_V8HI },
31688   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv4hiv4di2  , "__builtin_ia32_pmovsxwq256", IX86_BUILTIN_PMOVSXWQ256, UNKNOWN, (int) V4DI_FTYPE_V8HI },
31689   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sign_extendv4siv4di2  , "__builtin_ia32_pmovsxdq256", IX86_BUILTIN_PMOVSXDQ256, UNKNOWN, (int) V4DI_FTYPE_V4SI },
31690   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv16qiv16hi2, "__builtin_ia32_pmovzxbw256", IX86_BUILTIN_PMOVZXBW256, UNKNOWN, (int) V16HI_FTYPE_V16QI },
31691   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv8qiv8si2  , "__builtin_ia32_pmovzxbd256", IX86_BUILTIN_PMOVZXBD256, UNKNOWN, (int) V8SI_FTYPE_V16QI },
31692   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv4qiv4di2  , "__builtin_ia32_pmovzxbq256", IX86_BUILTIN_PMOVZXBQ256, UNKNOWN, (int) V4DI_FTYPE_V16QI },
31693   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv8hiv8si2  , "__builtin_ia32_pmovzxwd256", IX86_BUILTIN_PMOVZXWD256, UNKNOWN, (int) V8SI_FTYPE_V8HI },
31694   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv4hiv4di2  , "__builtin_ia32_pmovzxwq256", IX86_BUILTIN_PMOVZXWQ256, UNKNOWN, (int) V4DI_FTYPE_V8HI },
31695   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_zero_extendv4siv4di2  , "__builtin_ia32_pmovzxdq256", IX86_BUILTIN_PMOVZXDQ256, UNKNOWN, (int) V4DI_FTYPE_V4SI },
31696   { OPTION_MASK_ISA_AVX2, CODE_FOR_vec_widen_smult_even_v8si, "__builtin_ia32_pmuldq256", IX86_BUILTIN_PMULDQ256, UNKNOWN, (int) V4DI_FTYPE_V8SI_V8SI },
31697   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pmulhrswv16hi3 , "__builtin_ia32_pmulhrsw256", IX86_BUILTIN_PMULHRSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31698   { OPTION_MASK_ISA_AVX2, CODE_FOR_umulv16hi3_highpart, "__builtin_ia32_pmulhuw256" , IX86_BUILTIN_PMULHUW256 , UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31699   { OPTION_MASK_ISA_AVX2, CODE_FOR_smulv16hi3_highpart, "__builtin_ia32_pmulhw256"  , IX86_BUILTIN_PMULHW256  , UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31700   { OPTION_MASK_ISA_AVX2, CODE_FOR_mulv16hi3, "__builtin_ia32_pmullw256"  , IX86_BUILTIN_PMULLW256  , UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31701   { OPTION_MASK_ISA_AVX2, CODE_FOR_mulv8si3, "__builtin_ia32_pmulld256"  , IX86_BUILTIN_PMULLD256  , UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31702   { OPTION_MASK_ISA_AVX2, CODE_FOR_vec_widen_umult_even_v8si, "__builtin_ia32_pmuludq256", IX86_BUILTIN_PMULUDQ256, UNKNOWN, (int) V4DI_FTYPE_V8SI_V8SI },
31703   { OPTION_MASK_ISA_AVX2, CODE_FOR_iorv4di3, "__builtin_ia32_por256", IX86_BUILTIN_POR256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31704   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psadbw, "__builtin_ia32_psadbw256", IX86_BUILTIN_PSADBW256, UNKNOWN, (int) V16HI_FTYPE_V32QI_V32QI },
31705   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshufbv32qi3, "__builtin_ia32_pshufb256", IX86_BUILTIN_PSHUFB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31706   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshufdv3, "__builtin_ia32_pshufd256", IX86_BUILTIN_PSHUFD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT },
31707   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshufhwv3, "__builtin_ia32_pshufhw256", IX86_BUILTIN_PSHUFHW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT },
31708   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pshuflwv3, "__builtin_ia32_pshuflw256", IX86_BUILTIN_PSHUFLW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT },
31709   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psignv32qi3, "__builtin_ia32_psignb256", IX86_BUILTIN_PSIGNB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31710   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psignv16hi3, "__builtin_ia32_psignw256", IX86_BUILTIN_PSIGNW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31711   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_psignv8si3 , "__builtin_ia32_psignd256", IX86_BUILTIN_PSIGND256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31712   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlv2ti3, "__builtin_ia32_pslldqi256", IX86_BUILTIN_PSLLDQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_CONVERT },
31713   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv16hi3, "__builtin_ia32_psllwi256", IX86_BUILTIN_PSLLWI256 , UNKNOWN, (int) V16HI_FTYPE_V16HI_SI_COUNT },
31714   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv16hi3, "__builtin_ia32_psllw256", IX86_BUILTIN_PSLLW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_COUNT },
31715   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv8si3, "__builtin_ia32_pslldi256", IX86_BUILTIN_PSLLDI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_SI_COUNT },
31716   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv8si3, "__builtin_ia32_pslld256", IX86_BUILTIN_PSLLD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_COUNT },
31717   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv4di3, "__builtin_ia32_psllqi256", IX86_BUILTIN_PSLLQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_COUNT },
31718   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashlv4di3, "__builtin_ia32_psllq256", IX86_BUILTIN_PSLLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_COUNT },
31719   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv16hi3, "__builtin_ia32_psrawi256", IX86_BUILTIN_PSRAWI256, UNKNOWN, (int) V16HI_FTYPE_V16HI_SI_COUNT },
31720   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv16hi3, "__builtin_ia32_psraw256", IX86_BUILTIN_PSRAW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_COUNT },
31721   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv8si3, "__builtin_ia32_psradi256", IX86_BUILTIN_PSRADI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_SI_COUNT },
31722   { OPTION_MASK_ISA_AVX2, CODE_FOR_ashrv8si3, "__builtin_ia32_psrad256", IX86_BUILTIN_PSRAD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_COUNT },
31723   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrv2ti3, "__builtin_ia32_psrldqi256", IX86_BUILTIN_PSRLDQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_CONVERT },
31724   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv16hi3, "__builtin_ia32_psrlwi256", IX86_BUILTIN_PSRLWI256 , UNKNOWN, (int) V16HI_FTYPE_V16HI_SI_COUNT },
31725   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv16hi3, "__builtin_ia32_psrlw256", IX86_BUILTIN_PSRLW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_COUNT },
31726   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv8si3, "__builtin_ia32_psrldi256", IX86_BUILTIN_PSRLDI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_SI_COUNT },
31727   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv8si3, "__builtin_ia32_psrld256", IX86_BUILTIN_PSRLD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_COUNT },
31728   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv4di3, "__builtin_ia32_psrlqi256", IX86_BUILTIN_PSRLQI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_COUNT },
31729   { OPTION_MASK_ISA_AVX2, CODE_FOR_lshrv4di3, "__builtin_ia32_psrlq256", IX86_BUILTIN_PSRLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_COUNT },
31730   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv32qi3, "__builtin_ia32_psubb256", IX86_BUILTIN_PSUBB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31731   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv16hi3, "__builtin_ia32_psubw256", IX86_BUILTIN_PSUBW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31732   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv8si3, "__builtin_ia32_psubd256", IX86_BUILTIN_PSUBD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31733   { OPTION_MASK_ISA_AVX2, CODE_FOR_subv4di3, "__builtin_ia32_psubq256", IX86_BUILTIN_PSUBQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31734   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sssubv32qi3, "__builtin_ia32_psubsb256", IX86_BUILTIN_PSUBSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31735   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_sssubv16hi3, "__builtin_ia32_psubsw256", IX86_BUILTIN_PSUBSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31736   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ussubv32qi3, "__builtin_ia32_psubusb256", IX86_BUILTIN_PSUBUSB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31737   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ussubv16hi3, "__builtin_ia32_psubusw256", IX86_BUILTIN_PSUBUSW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31738   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv32qi, "__builtin_ia32_punpckhbw256", IX86_BUILTIN_PUNPCKHBW256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31739   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv16hi, "__builtin_ia32_punpckhwd256", IX86_BUILTIN_PUNPCKHWD256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI  },
31740   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv8si, "__builtin_ia32_punpckhdq256", IX86_BUILTIN_PUNPCKHDQ256, UNKNOWN,  (int) V8SI_FTYPE_V8SI_V8SI },
31741   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_highv4di, "__builtin_ia32_punpckhqdq256", IX86_BUILTIN_PUNPCKHQDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31742   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv32qi, "__builtin_ia32_punpcklbw256", IX86_BUILTIN_PUNPCKLBW256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI },
31743   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv16hi, "__builtin_ia32_punpcklwd256", IX86_BUILTIN_PUNPCKLWD256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI },
31744   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv8si, "__builtin_ia32_punpckldq256", IX86_BUILTIN_PUNPCKLDQ256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31745   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_interleave_lowv4di, "__builtin_ia32_punpcklqdq256", IX86_BUILTIN_PUNPCKLQDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31746   { OPTION_MASK_ISA_AVX2, CODE_FOR_xorv4di3, "__builtin_ia32_pxor256", IX86_BUILTIN_PXOR256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31747   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vec_dupv4sf, "__builtin_ia32_vbroadcastss_ps", IX86_BUILTIN_VBROADCASTSS_PS, UNKNOWN, (int) V4SF_FTYPE_V4SF },
31748   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vec_dupv8sf, "__builtin_ia32_vbroadcastss_ps256", IX86_BUILTIN_VBROADCASTSS_PS256, UNKNOWN, (int) V8SF_FTYPE_V4SF },
31749   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vec_dupv4df, "__builtin_ia32_vbroadcastsd_pd256", IX86_BUILTIN_VBROADCASTSD_PD256, UNKNOWN, (int) V4DF_FTYPE_V2DF },
31750   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_vbroadcasti128_v4di, "__builtin_ia32_vbroadcastsi256", IX86_BUILTIN_VBROADCASTSI256, UNKNOWN, (int) V4DI_FTYPE_V2DI },
31751   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblenddv4si, "__builtin_ia32_pblendd128", IX86_BUILTIN_PBLENDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_INT },
31752   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pblenddv8si, "__builtin_ia32_pblendd256", IX86_BUILTIN_PBLENDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT },
31753   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv32qi, "__builtin_ia32_pbroadcastb256", IX86_BUILTIN_PBROADCASTB256, UNKNOWN, (int) V32QI_FTYPE_V16QI },
31754   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv16hi, "__builtin_ia32_pbroadcastw256", IX86_BUILTIN_PBROADCASTW256, UNKNOWN, (int) V16HI_FTYPE_V8HI },
31755   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv8si, "__builtin_ia32_pbroadcastd256", IX86_BUILTIN_PBROADCASTD256, UNKNOWN, (int) V8SI_FTYPE_V4SI },
31756   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv4di, "__builtin_ia32_pbroadcastq256", IX86_BUILTIN_PBROADCASTQ256, UNKNOWN, (int) V4DI_FTYPE_V2DI },
31757   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv16qi, "__builtin_ia32_pbroadcastb128", IX86_BUILTIN_PBROADCASTB128, UNKNOWN, (int) V16QI_FTYPE_V16QI },
31758   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv8hi, "__builtin_ia32_pbroadcastw128", IX86_BUILTIN_PBROADCASTW128, UNKNOWN, (int) V8HI_FTYPE_V8HI },
31759   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv4si, "__builtin_ia32_pbroadcastd128", IX86_BUILTIN_PBROADCASTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI },
31760   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_pbroadcastv2di, "__builtin_ia32_pbroadcastq128", IX86_BUILTIN_PBROADCASTQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI },
31761   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permvarv8si, "__builtin_ia32_permvarsi256", IX86_BUILTIN_VPERMVARSI256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31762   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permvarv8sf, "__builtin_ia32_permvarsf256", IX86_BUILTIN_VPERMVARSF256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI },
31763   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permv4df, "__builtin_ia32_permdf256", IX86_BUILTIN_VPERMDF256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT },
31764   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permv4di, "__builtin_ia32_permdi256", IX86_BUILTIN_VPERMDI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT },
31765   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_permv2ti, "__builtin_ia32_permti256", IX86_BUILTIN_VPERMTI256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_INT },
31766   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx_vextractf128v4di, "__builtin_ia32_extract128i256", IX86_BUILTIN_VEXTRACT128I256, UNKNOWN, (int) V2DI_FTYPE_V4DI_INT },
31767   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx_vinsertf128v4di, "__builtin_ia32_insert128i256", IX86_BUILTIN_VINSERT128I256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_INT },
31768   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv4di, "__builtin_ia32_psllv4di", IX86_BUILTIN_PSLLVV4DI, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31769   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv2di, "__builtin_ia32_psllv2di", IX86_BUILTIN_PSLLVV2DI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31770   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv8si, "__builtin_ia32_psllv8si", IX86_BUILTIN_PSLLVV8SI, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31771   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashlvv4si, "__builtin_ia32_psllv4si", IX86_BUILTIN_PSLLVV4SI, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31772   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashrvv8si, "__builtin_ia32_psrav8si", IX86_BUILTIN_PSRAVV8SI, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31773   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_ashrvv4si, "__builtin_ia32_psrav4si", IX86_BUILTIN_PSRAVV4SI, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31774   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv4di, "__builtin_ia32_psrlv4di", IX86_BUILTIN_PSRLVV4DI, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI },
31775   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv2di, "__builtin_ia32_psrlv2di", IX86_BUILTIN_PSRLVV2DI, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI },
31776   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv8si, "__builtin_ia32_psrlv8si", IX86_BUILTIN_PSRLVV8SI, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI },
31777   { OPTION_MASK_ISA_AVX2, CODE_FOR_avx2_lshrvv4si, "__builtin_ia32_psrlv4si", IX86_BUILTIN_PSRLVV4SI, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
31778
31779   { OPTION_MASK_ISA_LZCNT, CODE_FOR_clzhi2_lzcnt,   "__builtin_clzs",   IX86_BUILTIN_CLZS,    UNKNOWN,     (int) UINT16_FTYPE_UINT16 },
31780
31781   /* BMI */
31782   { OPTION_MASK_ISA_BMI, CODE_FOR_bmi_bextr_si, "__builtin_ia32_bextr_u32", IX86_BUILTIN_BEXTR32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31783   { OPTION_MASK_ISA_BMI, CODE_FOR_bmi_bextr_di, "__builtin_ia32_bextr_u64", IX86_BUILTIN_BEXTR64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31784   { OPTION_MASK_ISA_BMI, CODE_FOR_ctzhi2,       "__builtin_ctzs",           IX86_BUILTIN_CTZS,    UNKNOWN, (int) UINT16_FTYPE_UINT16 },
31785
31786   /* TBM */
31787   { OPTION_MASK_ISA_TBM, CODE_FOR_tbm_bextri_si, "__builtin_ia32_bextri_u32", IX86_BUILTIN_BEXTRI32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31788   { OPTION_MASK_ISA_TBM, CODE_FOR_tbm_bextri_di, "__builtin_ia32_bextri_u64", IX86_BUILTIN_BEXTRI64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31789
31790   /* F16C */
31791   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtph2ps, "__builtin_ia32_vcvtph2ps", IX86_BUILTIN_CVTPH2PS, UNKNOWN, (int) V4SF_FTYPE_V8HI },
31792   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtph2ps256, "__builtin_ia32_vcvtph2ps256", IX86_BUILTIN_CVTPH2PS256, UNKNOWN, (int) V8SF_FTYPE_V8HI },
31793   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtps2ph, "__builtin_ia32_vcvtps2ph", IX86_BUILTIN_CVTPS2PH, UNKNOWN, (int) V8HI_FTYPE_V4SF_INT },
31794   { OPTION_MASK_ISA_F16C, CODE_FOR_vcvtps2ph256, "__builtin_ia32_vcvtps2ph256", IX86_BUILTIN_CVTPS2PH256, UNKNOWN, (int) V8HI_FTYPE_V8SF_INT },
31795
31796   /* BMI2 */
31797   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_bzhi_si3, "__builtin_ia32_bzhi_si", IX86_BUILTIN_BZHI32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31798   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_bzhi_di3, "__builtin_ia32_bzhi_di", IX86_BUILTIN_BZHI64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31799   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pdep_si3, "__builtin_ia32_pdep_si", IX86_BUILTIN_PDEP32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31800   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pdep_di3, "__builtin_ia32_pdep_di", IX86_BUILTIN_PDEP64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31801   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pext_si3, "__builtin_ia32_pext_si", IX86_BUILTIN_PEXT32, UNKNOWN, (int) UINT_FTYPE_UINT_UINT },
31802   { OPTION_MASK_ISA_BMI2, CODE_FOR_bmi2_pext_di3, "__builtin_ia32_pext_di", IX86_BUILTIN_PEXT64, UNKNOWN, (int) UINT64_FTYPE_UINT64_UINT64 },
31803
31804   /* AVX512F */
31805   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_si512_256si, "__builtin_ia32_si512_256si", IX86_BUILTIN_SI512_SI256, UNKNOWN, (int) V16SI_FTYPE_V8SI },
31806   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ps512_256ps, "__builtin_ia32_ps512_256ps", IX86_BUILTIN_PS512_PS256, UNKNOWN, (int) V16SF_FTYPE_V8SF },
31807   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_pd512_256pd, "__builtin_ia32_pd512_256pd", IX86_BUILTIN_PD512_PD256, UNKNOWN, (int) V8DF_FTYPE_V4DF },
31808   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_si512_si, "__builtin_ia32_si512_si", IX86_BUILTIN_SI512_SI, UNKNOWN, (int) V16SI_FTYPE_V4SI },
31809   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ps512_ps, "__builtin_ia32_ps512_ps", IX86_BUILTIN_PS512_PS, UNKNOWN, (int) V16SF_FTYPE_V4SF },
31810   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_pd512_pd, "__builtin_ia32_pd512_pd", IX86_BUILTIN_PD512_PD, UNKNOWN, (int) V8DF_FTYPE_V2DF },
31811   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_alignv16si_mask, "__builtin_ia32_alignd512_mask", IX86_BUILTIN_ALIGND512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_INT_V16SI_HI },
31812   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_alignv8di_mask, "__builtin_ia32_alignq512_mask", IX86_BUILTIN_ALIGNQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_INT_V8DI_QI },
31813   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv16si, "__builtin_ia32_blendmd_512_mask", IX86_BUILTIN_BLENDMD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31814   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv8df, "__builtin_ia32_blendmpd_512_mask", IX86_BUILTIN_BLENDMPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31815   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv16sf, "__builtin_ia32_blendmps_512_mask", IX86_BUILTIN_BLENDMPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31816   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_blendmv8di, "__builtin_ia32_blendmq_512_mask", IX86_BUILTIN_BLENDMQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31817   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv16sf_mask, "__builtin_ia32_broadcastf32x4_512", IX86_BUILTIN_BROADCASTF32X4_512, UNKNOWN, (int) V16SF_FTYPE_V4SF_V16SF_HI },
31818   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv8df_mask, "__builtin_ia32_broadcastf64x4_512", IX86_BUILTIN_BROADCASTF64X4_512, UNKNOWN, (int) V8DF_FTYPE_V4DF_V8DF_QI },
31819   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv16si_mask, "__builtin_ia32_broadcasti32x4_512", IX86_BUILTIN_BROADCASTI32X4_512, UNKNOWN, (int) V16SI_FTYPE_V4SI_V16SI_HI },
31820   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_broadcastv8di_mask, "__builtin_ia32_broadcasti64x4_512", IX86_BUILTIN_BROADCASTI64X4_512, UNKNOWN, (int) V8DI_FTYPE_V4DI_V8DI_QI },
31821   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv8df_mask, "__builtin_ia32_broadcastsd512", IX86_BUILTIN_BROADCASTSD512, UNKNOWN, (int) V8DF_FTYPE_V2DF_V8DF_QI },
31822   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv16sf_mask, "__builtin_ia32_broadcastss512", IX86_BUILTIN_BROADCASTSS512, UNKNOWN, (int) V16SF_FTYPE_V4SF_V16SF_HI },
31823   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cmpv16si3_mask, "__builtin_ia32_cmpd512_mask", IX86_BUILTIN_CMPD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_INT_HI },
31824   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cmpv8di3_mask, "__builtin_ia32_cmpq512_mask", IX86_BUILTIN_CMPQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_INT_QI },
31825   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv8df_mask, "__builtin_ia32_compressdf512_mask", IX86_BUILTIN_COMPRESSPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31826   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv16sf_mask, "__builtin_ia32_compresssf512_mask", IX86_BUILTIN_COMPRESSPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31827   { OPTION_MASK_ISA_AVX512F, CODE_FOR_floatv8siv8df2_mask, "__builtin_ia32_cvtdq2pd512_mask", IX86_BUILTIN_CVTDQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8SI_V8DF_QI },
31828   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtps2ph512_mask,  "__builtin_ia32_vcvtps2ph512_mask", IX86_BUILTIN_CVTPS2PH512, UNKNOWN, (int) V16HI_FTYPE_V16SF_INT_V16HI_HI },
31829   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ufloatv8siv8df2_mask, "__builtin_ia32_cvtudq2pd512_mask", IX86_BUILTIN_CVTUDQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8SI_V8DF_QI },
31830   { OPTION_MASK_ISA_AVX512F, CODE_FOR_cvtusi2sd32, "__builtin_ia32_cvtusi2sd32", IX86_BUILTIN_CVTUSI2SD32, UNKNOWN, (int) V2DF_FTYPE_V2DF_UINT },
31831   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_mask, "__builtin_ia32_expanddf512_mask", IX86_BUILTIN_EXPANDPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31832   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8df_maskz, "__builtin_ia32_expanddf512_maskz", IX86_BUILTIN_EXPANDPD512Z, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31833   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_mask, "__builtin_ia32_expandsf512_mask", IX86_BUILTIN_EXPANDPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31834   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16sf_maskz, "__builtin_ia32_expandsf512_maskz", IX86_BUILTIN_EXPANDPS512Z, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31835   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextractf32x4_mask, "__builtin_ia32_extractf32x4_mask", IX86_BUILTIN_EXTRACTF32X4, UNKNOWN, (int) V4SF_FTYPE_V16SF_INT_V4SF_QI },
31836   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextractf64x4_mask, "__builtin_ia32_extractf64x4_mask", IX86_BUILTIN_EXTRACTF64X4, UNKNOWN, (int) V4DF_FTYPE_V8DF_INT_V4DF_QI },
31837   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextracti32x4_mask, "__builtin_ia32_extracti32x4_mask", IX86_BUILTIN_EXTRACTI32X4, UNKNOWN, (int) V4SI_FTYPE_V16SI_INT_V4SI_QI },
31838   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vextracti64x4_mask, "__builtin_ia32_extracti64x4_mask", IX86_BUILTIN_EXTRACTI64X4, UNKNOWN, (int) V4DI_FTYPE_V8DI_INT_V4DI_QI },
31839   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vinsertf32x4_mask, "__builtin_ia32_insertf32x4_mask", IX86_BUILTIN_INSERTF32X4, UNKNOWN, (int) V16SF_FTYPE_V16SF_V4SF_INT_V16SF_HI },
31840   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vinsertf64x4_mask, "__builtin_ia32_insertf64x4_mask", IX86_BUILTIN_INSERTF64X4, UNKNOWN, (int) V8DF_FTYPE_V8DF_V4DF_INT_V8DF_QI },
31841   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vinserti32x4_mask, "__builtin_ia32_inserti32x4_mask", IX86_BUILTIN_INSERTI32X4, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_INT_V16SI_HI },
31842   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vinserti64x4_mask, "__builtin_ia32_inserti64x4_mask", IX86_BUILTIN_INSERTI64X4, UNKNOWN, (int) V8DI_FTYPE_V8DI_V4DI_INT_V8DI_QI },
31843   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8df_mask, "__builtin_ia32_movapd512_mask", IX86_BUILTIN_MOVAPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31844   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16sf_mask, "__builtin_ia32_movaps512_mask", IX86_BUILTIN_MOVAPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31845   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movddup512_mask, "__builtin_ia32_movddup512_mask", IX86_BUILTIN_MOVDDUP512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31846   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv16si_mask, "__builtin_ia32_movdqa32_512_mask", IX86_BUILTIN_MOVDQA32_512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31847   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_loadv8di_mask, "__builtin_ia32_movdqa64_512_mask", IX86_BUILTIN_MOVDQA64_512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31848   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movshdup512_mask, "__builtin_ia32_movshdup512_mask", IX86_BUILTIN_MOVSHDUP512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31849   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_movsldup512_mask, "__builtin_ia32_movsldup512_mask", IX86_BUILTIN_MOVSLDUP512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31850   { OPTION_MASK_ISA_AVX512F, CODE_FOR_absv16si2_mask, "__builtin_ia32_pabsd512_mask", IX86_BUILTIN_PABSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31851   { OPTION_MASK_ISA_AVX512F, CODE_FOR_absv8di2_mask, "__builtin_ia32_pabsq512_mask", IX86_BUILTIN_PABSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31852   { OPTION_MASK_ISA_AVX512F, CODE_FOR_addv16si3_mask, "__builtin_ia32_paddd512_mask", IX86_BUILTIN_PADDD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31853   { OPTION_MASK_ISA_AVX512F, CODE_FOR_addv8di3_mask, "__builtin_ia32_paddq512_mask", IX86_BUILTIN_PADDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31854   { OPTION_MASK_ISA_AVX512F, CODE_FOR_andv16si3_mask, "__builtin_ia32_pandd512_mask", IX86_BUILTIN_PANDD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31855   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_andnotv16si3_mask, "__builtin_ia32_pandnd512_mask", IX86_BUILTIN_PANDND512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31856   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_andnotv8di3_mask, "__builtin_ia32_pandnq512_mask", IX86_BUILTIN_PANDNQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31857   { OPTION_MASK_ISA_AVX512F, CODE_FOR_andv8di3_mask, "__builtin_ia32_pandq512_mask", IX86_BUILTIN_PANDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31858   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv16si_mask, "__builtin_ia32_pbroadcastd512", IX86_BUILTIN_PBROADCASTD512, UNKNOWN, (int) V16SI_FTYPE_V4SI_V16SI_HI },
31859   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dup_gprv16si_mask, "__builtin_ia32_pbroadcastd512_gpr_mask", IX86_BUILTIN_PBROADCASTD512_GPR, UNKNOWN, (int) V16SI_FTYPE_SI_V16SI_HI },
31860   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskb_vec_dupv8di, "__builtin_ia32_broadcastmb512", IX86_BUILTIN_PBROADCASTMB512, UNKNOWN, (int) V8DI_FTYPE_QI },
31861   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskw_vec_dupv16si, "__builtin_ia32_broadcastmw512", IX86_BUILTIN_PBROADCASTMW512, UNKNOWN, (int) V16SI_FTYPE_HI },
31862   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dupv8di_mask, "__builtin_ia32_pbroadcastq512", IX86_BUILTIN_PBROADCASTQ512, UNKNOWN, (int) V8DI_FTYPE_V2DI_V8DI_QI },
31863   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vec_dup_gprv8di_mask, "__builtin_ia32_pbroadcastq512_gpr_mask", IX86_BUILTIN_PBROADCASTQ512_GPR, UNKNOWN, (int) V8DI_FTYPE_DI_V8DI_QI },
31864   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_eqv16si3_mask, "__builtin_ia32_pcmpeqd512_mask", IX86_BUILTIN_PCMPEQD512_MASK, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31865   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_eqv8di3_mask, "__builtin_ia32_pcmpeqq512_mask", IX86_BUILTIN_PCMPEQQ512_MASK, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31866   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_gtv16si3_mask, "__builtin_ia32_pcmpgtd512_mask", IX86_BUILTIN_PCMPGTD512_MASK, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31867   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_gtv8di3_mask, "__builtin_ia32_pcmpgtq512_mask", IX86_BUILTIN_PCMPGTQ512_MASK, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31868   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv16si_mask, "__builtin_ia32_compresssi512_mask", IX86_BUILTIN_PCOMPRESSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31869   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_compressv8di_mask, "__builtin_ia32_compressdi512_mask", IX86_BUILTIN_PCOMPRESSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31870   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_mask, "__builtin_ia32_expandsi512_mask", IX86_BUILTIN_PEXPANDD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31871   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv16si_maskz, "__builtin_ia32_expandsi512_maskz", IX86_BUILTIN_PEXPANDD512Z, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31872   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_mask, "__builtin_ia32_expanddi512_mask", IX86_BUILTIN_PEXPANDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31873   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_expandv8di_maskz, "__builtin_ia32_expanddi512_maskz", IX86_BUILTIN_PEXPANDQ512Z, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31874   { OPTION_MASK_ISA_AVX512F, CODE_FOR_smaxv16si3_mask, "__builtin_ia32_pmaxsd512_mask", IX86_BUILTIN_PMAXSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31875   { OPTION_MASK_ISA_AVX512F, CODE_FOR_smaxv8di3_mask, "__builtin_ia32_pmaxsq512_mask", IX86_BUILTIN_PMAXSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31876   { OPTION_MASK_ISA_AVX512F, CODE_FOR_umaxv16si3_mask, "__builtin_ia32_pmaxud512_mask", IX86_BUILTIN_PMAXUD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31877   { OPTION_MASK_ISA_AVX512F, CODE_FOR_umaxv8di3_mask, "__builtin_ia32_pmaxuq512_mask", IX86_BUILTIN_PMAXUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31878   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sminv16si3_mask, "__builtin_ia32_pminsd512_mask", IX86_BUILTIN_PMINSD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31879   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sminv8di3_mask, "__builtin_ia32_pminsq512_mask", IX86_BUILTIN_PMINSQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31880   { OPTION_MASK_ISA_AVX512F, CODE_FOR_uminv16si3_mask, "__builtin_ia32_pminud512_mask", IX86_BUILTIN_PMINUD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31881   { OPTION_MASK_ISA_AVX512F, CODE_FOR_uminv8di3_mask, "__builtin_ia32_pminuq512_mask", IX86_BUILTIN_PMINUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31882   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev16siv16qi2_mask, "__builtin_ia32_pmovdb512_mask", IX86_BUILTIN_PMOVDB512, UNKNOWN, (int) V16QI_FTYPE_V16SI_V16QI_HI },
31883   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev16siv16hi2_mask, "__builtin_ia32_pmovdw512_mask", IX86_BUILTIN_PMOVDW512, UNKNOWN, (int) V16HI_FTYPE_V16SI_V16HI_HI },
31884   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div16qi2_mask, "__builtin_ia32_pmovqb512_mask", IX86_BUILTIN_PMOVQB512, UNKNOWN, (int) V16QI_FTYPE_V8DI_V16QI_QI },
31885   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div8si2_mask, "__builtin_ia32_pmovqd512_mask", IX86_BUILTIN_PMOVQD512, UNKNOWN, (int) V8SI_FTYPE_V8DI_V8SI_QI },
31886   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_truncatev8div8hi2_mask, "__builtin_ia32_pmovqw512_mask", IX86_BUILTIN_PMOVQW512, UNKNOWN, (int) V8HI_FTYPE_V8DI_V8HI_QI },
31887   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev16siv16qi2_mask, "__builtin_ia32_pmovsdb512_mask", IX86_BUILTIN_PMOVSDB512, UNKNOWN, (int) V16QI_FTYPE_V16SI_V16QI_HI },
31888   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev16siv16hi2_mask, "__builtin_ia32_pmovsdw512_mask", IX86_BUILTIN_PMOVSDW512, UNKNOWN, (int) V16HI_FTYPE_V16SI_V16HI_HI },
31889   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div16qi2_mask, "__builtin_ia32_pmovsqb512_mask", IX86_BUILTIN_PMOVSQB512, UNKNOWN, (int) V16QI_FTYPE_V8DI_V16QI_QI },
31890   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div8si2_mask, "__builtin_ia32_pmovsqd512_mask", IX86_BUILTIN_PMOVSQD512, UNKNOWN, (int) V8SI_FTYPE_V8DI_V8SI_QI },
31891   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ss_truncatev8div8hi2_mask, "__builtin_ia32_pmovsqw512_mask", IX86_BUILTIN_PMOVSQW512, UNKNOWN, (int) V8HI_FTYPE_V8DI_V8HI_QI },
31892   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv16qiv16si2_mask, "__builtin_ia32_pmovsxbd512_mask", IX86_BUILTIN_PMOVSXBD512, UNKNOWN, (int) V16SI_FTYPE_V16QI_V16SI_HI },
31893   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv8qiv8di2_mask, "__builtin_ia32_pmovsxbq512_mask", IX86_BUILTIN_PMOVSXBQ512, UNKNOWN, (int) V8DI_FTYPE_V16QI_V8DI_QI },
31894   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv8siv8di2_mask, "__builtin_ia32_pmovsxdq512_mask", IX86_BUILTIN_PMOVSXDQ512, UNKNOWN, (int) V8DI_FTYPE_V8SI_V8DI_QI },
31895   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv16hiv16si2_mask, "__builtin_ia32_pmovsxwd512_mask", IX86_BUILTIN_PMOVSXWD512, UNKNOWN, (int) V16SI_FTYPE_V16HI_V16SI_HI },
31896   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sign_extendv8hiv8di2_mask, "__builtin_ia32_pmovsxwq512_mask", IX86_BUILTIN_PMOVSXWQ512, UNKNOWN, (int) V8DI_FTYPE_V8HI_V8DI_QI },
31897   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev16siv16qi2_mask, "__builtin_ia32_pmovusdb512_mask", IX86_BUILTIN_PMOVUSDB512, UNKNOWN, (int) V16QI_FTYPE_V16SI_V16QI_HI },
31898   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev16siv16hi2_mask, "__builtin_ia32_pmovusdw512_mask", IX86_BUILTIN_PMOVUSDW512, UNKNOWN, (int) V16HI_FTYPE_V16SI_V16HI_HI },
31899   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div16qi2_mask, "__builtin_ia32_pmovusqb512_mask", IX86_BUILTIN_PMOVUSQB512, UNKNOWN, (int) V16QI_FTYPE_V8DI_V16QI_QI },
31900   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div8si2_mask, "__builtin_ia32_pmovusqd512_mask", IX86_BUILTIN_PMOVUSQD512, UNKNOWN, (int) V8SI_FTYPE_V8DI_V8SI_QI },
31901   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_us_truncatev8div8hi2_mask, "__builtin_ia32_pmovusqw512_mask", IX86_BUILTIN_PMOVUSQW512, UNKNOWN, (int) V8HI_FTYPE_V8DI_V8HI_QI },
31902   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv16qiv16si2_mask, "__builtin_ia32_pmovzxbd512_mask", IX86_BUILTIN_PMOVZXBD512, UNKNOWN, (int) V16SI_FTYPE_V16QI_V16SI_HI },
31903   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv8qiv8di2_mask, "__builtin_ia32_pmovzxbq512_mask", IX86_BUILTIN_PMOVZXBQ512, UNKNOWN, (int) V8DI_FTYPE_V16QI_V8DI_QI },
31904   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv8siv8di2_mask, "__builtin_ia32_pmovzxdq512_mask", IX86_BUILTIN_PMOVZXDQ512, UNKNOWN, (int) V8DI_FTYPE_V8SI_V8DI_QI },
31905   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv16hiv16si2_mask, "__builtin_ia32_pmovzxwd512_mask", IX86_BUILTIN_PMOVZXWD512, UNKNOWN, (int) V16SI_FTYPE_V16HI_V16SI_HI },
31906   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_zero_extendv8hiv8di2_mask, "__builtin_ia32_pmovzxwq512_mask", IX86_BUILTIN_PMOVZXWQ512, UNKNOWN, (int) V8DI_FTYPE_V8HI_V8DI_QI },
31907   { OPTION_MASK_ISA_AVX512F, CODE_FOR_vec_widen_smult_even_v16si_mask, "__builtin_ia32_pmuldq512_mask", IX86_BUILTIN_PMULDQ512, UNKNOWN, (int) V8DI_FTYPE_V16SI_V16SI_V8DI_QI },
31908   { OPTION_MASK_ISA_AVX512F, CODE_FOR_mulv16si3_mask, "__builtin_ia32_pmulld512_mask"  , IX86_BUILTIN_PMULLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31909   { OPTION_MASK_ISA_AVX512F, CODE_FOR_vec_widen_umult_even_v16si_mask, "__builtin_ia32_pmuludq512_mask", IX86_BUILTIN_PMULUDQ512, UNKNOWN, (int) V8DI_FTYPE_V16SI_V16SI_V8DI_QI },
31910   { OPTION_MASK_ISA_AVX512F, CODE_FOR_iorv16si3_mask, "__builtin_ia32_pord512_mask", IX86_BUILTIN_PORD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31911   { OPTION_MASK_ISA_AVX512F, CODE_FOR_iorv8di3_mask, "__builtin_ia32_porq512_mask", IX86_BUILTIN_PORQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31912   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolv16si_mask, "__builtin_ia32_prold512_mask", IX86_BUILTIN_PROLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31913   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolv8di_mask, "__builtin_ia32_prolq512_mask", IX86_BUILTIN_PROLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31914   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolvv16si_mask, "__builtin_ia32_prolvd512_mask", IX86_BUILTIN_PROLVD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31915   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rolvv8di_mask, "__builtin_ia32_prolvq512_mask", IX86_BUILTIN_PROLVQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31916   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorv16si_mask, "__builtin_ia32_prord512_mask", IX86_BUILTIN_PRORD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31917   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorv8di_mask, "__builtin_ia32_prorq512_mask", IX86_BUILTIN_PRORQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31918   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorvv16si_mask, "__builtin_ia32_prorvd512_mask", IX86_BUILTIN_PRORVD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31919   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rorvv8di_mask, "__builtin_ia32_prorvq512_mask", IX86_BUILTIN_PRORVQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31920   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_pshufdv3_mask, "__builtin_ia32_pshufd512_mask", IX86_BUILTIN_PSHUFD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31921   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv16si3_mask, "__builtin_ia32_pslld512_mask", IX86_BUILTIN_PSLLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_V16SI_HI },
31922   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv16si3_mask, "__builtin_ia32_pslldi512_mask", IX86_BUILTIN_PSLLDI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31923   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv8di3_mask, "__builtin_ia32_psllq512_mask", IX86_BUILTIN_PSLLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_V8DI_QI },
31924   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashlv8di3_mask, "__builtin_ia32_psllqi512_mask", IX86_BUILTIN_PSLLQI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31925   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashlvv16si_mask, "__builtin_ia32_psllv16si_mask", IX86_BUILTIN_PSLLVV16SI, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31926   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashlvv8di_mask, "__builtin_ia32_psllv8di_mask", IX86_BUILTIN_PSLLVV8DI, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31927   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv16si3_mask, "__builtin_ia32_psrad512_mask", IX86_BUILTIN_PSRAD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_V16SI_HI },
31928   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv16si3_mask, "__builtin_ia32_psradi512_mask", IX86_BUILTIN_PSRADI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31929   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv8di3_mask, "__builtin_ia32_psraq512_mask", IX86_BUILTIN_PSRAQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_V8DI_QI },
31930   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ashrv8di3_mask, "__builtin_ia32_psraqi512_mask", IX86_BUILTIN_PSRAQI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31931   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashrvv16si_mask, "__builtin_ia32_psrav16si_mask", IX86_BUILTIN_PSRAVV16SI, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31932   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ashrvv8di_mask, "__builtin_ia32_psrav8di_mask", IX86_BUILTIN_PSRAVV8DI, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31933   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv16si3_mask, "__builtin_ia32_psrld512_mask", IX86_BUILTIN_PSRLD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V4SI_V16SI_HI },
31934   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv16si3_mask, "__builtin_ia32_psrldi512_mask", IX86_BUILTIN_PSRLDI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_INT_V16SI_HI },
31935   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv8di3_mask, "__builtin_ia32_psrlq512_mask", IX86_BUILTIN_PSRLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_V8DI_QI },
31936   { OPTION_MASK_ISA_AVX512F, CODE_FOR_lshrv8di3_mask, "__builtin_ia32_psrlqi512_mask", IX86_BUILTIN_PSRLQI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31937   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_lshrvv16si_mask, "__builtin_ia32_psrlv16si_mask", IX86_BUILTIN_PSRLVV16SI, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31938   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_lshrvv8di_mask, "__builtin_ia32_psrlv8di_mask", IX86_BUILTIN_PSRLVV8DI, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31939   { OPTION_MASK_ISA_AVX512F, CODE_FOR_subv16si3_mask, "__builtin_ia32_psubd512_mask", IX86_BUILTIN_PSUBD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31940   { OPTION_MASK_ISA_AVX512F, CODE_FOR_subv8di3_mask, "__builtin_ia32_psubq512_mask", IX86_BUILTIN_PSUBQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31941   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testmv16si3_mask, "__builtin_ia32_ptestmd512", IX86_BUILTIN_PTESTMD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31942   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testmv8di3_mask, "__builtin_ia32_ptestmq512", IX86_BUILTIN_PTESTMQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31943   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testnmv16si3_mask, "__builtin_ia32_ptestnmd512", IX86_BUILTIN_PTESTNMD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_HI },
31944   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_testnmv8di3_mask, "__builtin_ia32_ptestnmq512", IX86_BUILTIN_PTESTNMQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_QI },
31945   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_interleave_highv16si_mask, "__builtin_ia32_punpckhdq512_mask", IX86_BUILTIN_PUNPCKHDQ512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31946   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_interleave_highv8di_mask, "__builtin_ia32_punpckhqdq512_mask", IX86_BUILTIN_PUNPCKHQDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31947   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_interleave_lowv16si_mask, "__builtin_ia32_punpckldq512_mask", IX86_BUILTIN_PUNPCKLDQ512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31948   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_interleave_lowv8di_mask, "__builtin_ia32_punpcklqdq512_mask", IX86_BUILTIN_PUNPCKLQDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31949   { OPTION_MASK_ISA_AVX512F, CODE_FOR_xorv16si3_mask, "__builtin_ia32_pxord512_mask", IX86_BUILTIN_PXORD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31950   { OPTION_MASK_ISA_AVX512F, CODE_FOR_xorv8di3_mask, "__builtin_ia32_pxorq512_mask", IX86_BUILTIN_PXORQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31951   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rcp14v8df_mask, "__builtin_ia32_rcp14pd512_mask", IX86_BUILTIN_RCP14PD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31952   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rcp14v16sf_mask, "__builtin_ia32_rcp14ps512_mask", IX86_BUILTIN_RCP14PS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31953   { OPTION_MASK_ISA_AVX512F, CODE_FOR_srcp14v2df, "__builtin_ia32_rcp14sd", IX86_BUILTIN_RCP14SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31954   { OPTION_MASK_ISA_AVX512F, CODE_FOR_srcp14v4sf, "__builtin_ia32_rcp14ss", IX86_BUILTIN_RCP14SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31955   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v8df_mask, "__builtin_ia32_rsqrt14pd512_mask", IX86_BUILTIN_RSQRT14PD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI },
31956   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v16sf_mask, "__builtin_ia32_rsqrt14ps512_mask", IX86_BUILTIN_RSQRT14PS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI },
31957   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v2df, "__builtin_ia32_rsqrt14sd", IX86_BUILTIN_RSQRT14SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF },
31958   { OPTION_MASK_ISA_AVX512F, CODE_FOR_rsqrt14v4sf, "__builtin_ia32_rsqrt14ss", IX86_BUILTIN_RSQRT14SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF },
31959   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_shufpd512_mask, "__builtin_ia32_shufpd512_mask", IX86_BUILTIN_SHUFPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_INT_V8DF_QI },
31960   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_shufps512_mask, "__builtin_ia32_shufps512_mask", IX86_BUILTIN_SHUFPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_INT_V16SF_HI },
31961   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_shuf_f32x4_mask, "__builtin_ia32_shuf_f32x4_mask", IX86_BUILTIN_SHUF_F32x4, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_INT_V16SF_HI },
31962   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_shuf_f64x2_mask, "__builtin_ia32_shuf_f64x2_mask", IX86_BUILTIN_SHUF_F64x2, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_INT_V8DF_QI },
31963   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_shuf_i32x4_mask, "__builtin_ia32_shuf_i32x4_mask", IX86_BUILTIN_SHUF_I32x4, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_INT_V16SI_HI },
31964   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_shuf_i64x2_mask, "__builtin_ia32_shuf_i64x2_mask", IX86_BUILTIN_SHUF_I64x2, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_INT_V8DI_QI },
31965   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ucmpv16si3_mask, "__builtin_ia32_ucmpd512_mask", IX86_BUILTIN_UCMPD512, UNKNOWN, (int) HI_FTYPE_V16SI_V16SI_INT_HI },
31966   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ucmpv8di3_mask, "__builtin_ia32_ucmpq512_mask", IX86_BUILTIN_UCMPQ512, UNKNOWN, (int) QI_FTYPE_V8DI_V8DI_INT_QI },
31967   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpckhpd512_mask, "__builtin_ia32_unpckhpd512_mask", IX86_BUILTIN_UNPCKHPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
31968   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpckhps512_mask, "__builtin_ia32_unpckhps512_mask", IX86_BUILTIN_UNPCKHPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
31969   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpcklpd512_mask, "__builtin_ia32_unpcklpd512_mask", IX86_BUILTIN_UNPCKLPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
31970   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_unpcklps512_mask,  "__builtin_ia32_unpcklps512_mask", IX86_BUILTIN_UNPCKLPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
31971   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_clzv16si2_mask, "__builtin_ia32_vplzcntd_512_mask", IX86_BUILTIN_VPCLZCNTD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31972   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_clzv8di2_mask, "__builtin_ia32_vplzcntq_512_mask", IX86_BUILTIN_VPCLZCNTQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31973   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_conflictv16si_mask, "__builtin_ia32_vpconflictsi_512_mask", IX86_BUILTIN_VPCONFLICTD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_HI },
31974   { OPTION_MASK_ISA_AVX512CD, CODE_FOR_conflictv8di_mask, "__builtin_ia32_vpconflictdi_512_mask", IX86_BUILTIN_VPCONFLICTQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_QI },
31975   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permv8df_mask, "__builtin_ia32_permdf512_mask", IX86_BUILTIN_VPERMDF512, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI },
31976   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permv8di_mask, "__builtin_ia32_permdi512_mask", IX86_BUILTIN_VPERMDI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_V8DI_QI },
31977   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv16si3_mask, "__builtin_ia32_vpermi2vard512_mask", IX86_BUILTIN_VPERMI2VARD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31978   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv8df3_mask, "__builtin_ia32_vpermi2varpd512_mask", IX86_BUILTIN_VPERMI2VARPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DI_V8DF_QI },
31979   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv16sf3_mask, "__builtin_ia32_vpermi2varps512_mask", IX86_BUILTIN_VPERMI2VARPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SI_V16SF_HI },
31980   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermi2varv8di3_mask, "__builtin_ia32_vpermi2varq512_mask", IX86_BUILTIN_VPERMI2VARQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31981   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilv8df_mask, "__builtin_ia32_vpermilpd512_mask", IX86_BUILTIN_VPERMILPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI },
31982   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilv16sf_mask, "__builtin_ia32_vpermilps512_mask", IX86_BUILTIN_VPERMILPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_INT_V16SF_HI },
31983   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilvarv8df3_mask, "__builtin_ia32_vpermilvarpd512_mask", IX86_BUILTIN_VPERMILVARPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DI_V8DF_QI },
31984   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermilvarv16sf3_mask, "__builtin_ia32_vpermilvarps512_mask", IX86_BUILTIN_VPERMILVARPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SI_V16SF_HI },
31985   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv16si3_mask, "__builtin_ia32_vpermt2vard512_mask", IX86_BUILTIN_VPERMT2VARD512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31986   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv16si3_maskz, "__builtin_ia32_vpermt2vard512_maskz", IX86_BUILTIN_VPERMT2VARD512_MASKZ, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31987   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv8df3_mask, "__builtin_ia32_vpermt2varpd512_mask", IX86_BUILTIN_VPERMT2VARPD512, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_V8DF_QI },
31988   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv8df3_maskz, "__builtin_ia32_vpermt2varpd512_maskz", IX86_BUILTIN_VPERMT2VARPD512_MASKZ, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_V8DF_QI },
31989   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv16sf3_mask, "__builtin_ia32_vpermt2varps512_mask", IX86_BUILTIN_VPERMT2VARPS512, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_V16SF_HI },
31990   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv16sf3_maskz, "__builtin_ia32_vpermt2varps512_maskz", IX86_BUILTIN_VPERMT2VARPS512_MASKZ, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_V16SF_HI },
31991   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv8di3_mask, "__builtin_ia32_vpermt2varq512_mask", IX86_BUILTIN_VPERMT2VARQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31992   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vpermt2varv8di3_maskz, "__builtin_ia32_vpermt2varq512_maskz", IX86_BUILTIN_VPERMT2VARQ512_MASKZ, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31993   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv8df_mask, "__builtin_ia32_permvardf512_mask", IX86_BUILTIN_VPERMVARDF512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DI_V8DF_QI },
31994   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv8di_mask, "__builtin_ia32_permvardi512_mask", IX86_BUILTIN_VPERMVARDI512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
31995   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv16sf_mask, "__builtin_ia32_permvarsf512_mask", IX86_BUILTIN_VPERMVARSF512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SI_V16SF_HI },
31996   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_permvarv16si_mask, "__builtin_ia32_permvarsi512_mask", IX86_BUILTIN_VPERMVARSI512, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_HI },
31997   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vternlogv16si_mask, "__builtin_ia32_pternlogd512_mask", IX86_BUILTIN_VTERNLOGD512_MASK, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_INT_HI },
31998   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vternlogv16si_maskz, "__builtin_ia32_pternlogd512_maskz", IX86_BUILTIN_VTERNLOGD512_MASKZ, UNKNOWN, (int) V16SI_FTYPE_V16SI_V16SI_V16SI_INT_HI },
31999   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vternlogv8di_mask, "__builtin_ia32_pternlogq512_mask", IX86_BUILTIN_VTERNLOGQ512_MASK, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_INT_QI },
32000   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vternlogv8di_maskz, "__builtin_ia32_pternlogq512_maskz", IX86_BUILTIN_VTERNLOGQ512_MASKZ, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_INT_QI },
32001
32002   { OPTION_MASK_ISA_AVX512F, CODE_FOR_copysignv16sf3,  "__builtin_ia32_copysignps512", IX86_BUILTIN_CPYSGNPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF },
32003   { OPTION_MASK_ISA_AVX512F, CODE_FOR_copysignv8df3,  "__builtin_ia32_copysignpd512", IX86_BUILTIN_CPYSGNPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF },
32004   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sqrtv8df2, "__builtin_ia32_sqrtpd512", IX86_BUILTIN_SQRTPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF },
32005   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sqrtv16sf2, "__builtin_ia32_sqrtps512", IX86_BUILTIN_SQRTPS_NR512, UNKNOWN, (int) V16SF_FTYPE_V16SF },
32006   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_exp2v16sf, "__builtin_ia32_exp2ps", IX86_BUILTIN_EXP2PS, UNKNOWN, (int) V16SF_FTYPE_V16SF },
32007   { OPTION_MASK_ISA_AVX512F, CODE_FOR_roundv8df2_vec_pack_sfix, "__builtin_ia32_roundpd_az_vec_pack_sfix512", IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX512, UNKNOWN, (int) V16SI_FTYPE_V8DF_V8DF },
32008   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_roundpd_vec_pack_sfix512, "__builtin_ia32_floorpd_vec_pack_sfix512", IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX512, (enum rtx_code) ROUND_FLOOR, (int) V16SI_FTYPE_V8DF_V8DF_ROUND },
32009   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_roundpd_vec_pack_sfix512, "__builtin_ia32_ceilpd_vec_pack_sfix512", IX86_BUILTIN_CEILPD_VEC_PACK_SFIX512, (enum rtx_code) ROUND_CEIL, (int) V16SI_FTYPE_V8DF_V8DF_ROUND },
32010
32011   /* Mask arithmetic operations */
32012   { OPTION_MASK_ISA_AVX512F, CODE_FOR_andhi3, "__builtin_ia32_kandhi", IX86_BUILTIN_KAND16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32013   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kandnhi, "__builtin_ia32_kandnhi", IX86_BUILTIN_KANDN16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32014   { OPTION_MASK_ISA_AVX512F, CODE_FOR_one_cmplhi2, "__builtin_ia32_knothi", IX86_BUILTIN_KNOT16, UNKNOWN, (int) HI_FTYPE_HI },
32015   { OPTION_MASK_ISA_AVX512F, CODE_FOR_iorhi3, "__builtin_ia32_korhi", IX86_BUILTIN_KOR16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32016   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kortestchi, "__builtin_ia32_kortestchi", IX86_BUILTIN_KORTESTC16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32017   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kortestzhi, "__builtin_ia32_kortestzhi", IX86_BUILTIN_KORTESTZ16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32018   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kunpckhi, "__builtin_ia32_kunpckhi", IX86_BUILTIN_KUNPCKBW, UNKNOWN, (int) HI_FTYPE_HI_HI },
32019   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kxnorhi, "__builtin_ia32_kxnorhi", IX86_BUILTIN_KXNOR16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32020   { OPTION_MASK_ISA_AVX512F, CODE_FOR_xorhi3, "__builtin_ia32_kxorhi", IX86_BUILTIN_KXOR16, UNKNOWN, (int) HI_FTYPE_HI_HI },
32021   { OPTION_MASK_ISA_AVX512F, CODE_FOR_kmovw, "__builtin_ia32_kmov16", IX86_BUILTIN_KMOV16, UNKNOWN, (int) HI_FTYPE_HI },
32022
32023   /* SHA */
32024   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1msg1, 0, IX86_BUILTIN_SHA1MSG1, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32025   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1msg2, 0, IX86_BUILTIN_SHA1MSG2, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32026   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1nexte, 0, IX86_BUILTIN_SHA1NEXTE, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32027   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha1rnds4, 0, IX86_BUILTIN_SHA1RNDS4, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_INT },
32028   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha256msg1, 0, IX86_BUILTIN_SHA256MSG1, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32029   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha256msg2, 0, IX86_BUILTIN_SHA256MSG2, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI },
32030   { OPTION_MASK_ISA_SSE2, CODE_FOR_sha256rnds2, 0, IX86_BUILTIN_SHA256RNDS2, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI },
32031
32032   /* AVX512VL.  */
32033   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_palignrv32qi_mask, "__builtin_ia32_palignr256_mask", IX86_BUILTIN_PALIGNR256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_INT_V4DI_SI_CONVERT },
32034   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ssse3_palignrv16qi_mask, "__builtin_ia32_palignr128_mask", IX86_BUILTIN_PALIGNR128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT_V2DI_HI_CONVERT },
32035   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4di_mask, "__builtin_ia32_movdqa64_256_mask", IX86_BUILTIN_MOVDQA64_256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32036   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2di_mask, "__builtin_ia32_movdqa64_128_mask", IX86_BUILTIN_MOVDQA64_128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32037   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8si_mask, "__builtin_ia32_movdqa32_256_mask", IX86_BUILTIN_MOVDQA32_256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32038   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4si_mask, "__builtin_ia32_movdqa32_128_mask", IX86_BUILTIN_MOVDQA32_128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32039   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4df_mask, "__builtin_ia32_movapd256_mask", IX86_BUILTIN_MOVAPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32040   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv2df_mask, "__builtin_ia32_movapd128_mask", IX86_BUILTIN_MOVAPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32041   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv8sf_mask, "__builtin_ia32_movaps256_mask", IX86_BUILTIN_MOVAPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32042   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loadv4sf_mask, "__builtin_ia32_movaps128_mask", IX86_BUILTIN_MOVAPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32043   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv16hi_mask, "__builtin_ia32_movdquhi256_mask", IX86_BUILTIN_MOVDQUHI256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_HI },
32044   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_loaddquv8hi_mask, "__builtin_ia32_movdquhi128_mask", IX86_BUILTIN_MOVDQUHI128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_QI },
32045   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_loaddquv32qi_mask, "__builtin_ia32_movdquqi256_mask", IX86_BUILTIN_MOVDQUQI256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_SI },
32046   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_loaddquv16qi_mask, "__builtin_ia32_movdquqi128_mask", IX86_BUILTIN_MOVDQUQI128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_HI },
32047   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4sf3_mask, "__builtin_ia32_minps_mask", IX86_BUILTIN_MINPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32048   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4sf3_mask, "__builtin_ia32_maxps_mask", IX86_BUILTIN_MAXPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32049   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv2df3_mask, "__builtin_ia32_minpd_mask", IX86_BUILTIN_MINPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32050   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv2df3_mask, "__builtin_ia32_maxpd_mask", IX86_BUILTIN_MAXPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32051   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4df3_mask, "__builtin_ia32_maxpd256_mask", IX86_BUILTIN_MAXPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32052   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv8sf3_mask, "__builtin_ia32_maxps256_mask", IX86_BUILTIN_MAXPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32053   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4df3_mask, "__builtin_ia32_minpd256_mask", IX86_BUILTIN_MINPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32054   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv8sf3_mask, "__builtin_ia32_minps256_mask", IX86_BUILTIN_MINPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32055   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv4sf3_mask, "__builtin_ia32_mulps_mask", IX86_BUILTIN_MULPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32056   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse_divv4sf3_mask, "__builtin_ia32_divps_mask", IX86_BUILTIN_DIVPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32057   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv2df3_mask, "__builtin_ia32_mulpd_mask", IX86_BUILTIN_MULPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32058   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_divv2df3_mask, "__builtin_ia32_divpd_mask", IX86_BUILTIN_DIVPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32059   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_divv4df3_mask, "__builtin_ia32_divpd256_mask", IX86_BUILTIN_DIVPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32060   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_divv8sf3_mask, "__builtin_ia32_divps256_mask", IX86_BUILTIN_DIVPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32061   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv4df3_mask, "__builtin_ia32_mulpd256_mask", IX86_BUILTIN_MULPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32062   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv8sf3_mask, "__builtin_ia32_mulps256_mask", IX86_BUILTIN_MULPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32063   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv2df3_mask, "__builtin_ia32_addpd128_mask", IX86_BUILTIN_ADDPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32064   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4df3_mask, "__builtin_ia32_addpd256_mask", IX86_BUILTIN_ADDPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32065   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4sf3_mask, "__builtin_ia32_addps128_mask", IX86_BUILTIN_ADDPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32066   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv8sf3_mask, "__builtin_ia32_addps256_mask", IX86_BUILTIN_ADDPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32067   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv2df3_mask, "__builtin_ia32_subpd128_mask", IX86_BUILTIN_SUBPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32068   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4df3_mask, "__builtin_ia32_subpd256_mask", IX86_BUILTIN_SUBPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32069   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4sf3_mask, "__builtin_ia32_subps128_mask", IX86_BUILTIN_SUBPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32070   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv8sf3_mask, "__builtin_ia32_subps256_mask", IX86_BUILTIN_SUBPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32071   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv4df3_mask, "__builtin_ia32_xorpd256_mask", IX86_BUILTIN_XORPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32072   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv2df3_mask, "__builtin_ia32_xorpd128_mask", IX86_BUILTIN_XORPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32073   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv8sf3_mask, "__builtin_ia32_xorps256_mask", IX86_BUILTIN_XORPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32074   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv4sf3_mask, "__builtin_ia32_xorps128_mask", IX86_BUILTIN_XORPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32075   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv4df3_mask, "__builtin_ia32_orpd256_mask", IX86_BUILTIN_ORPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32076   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv2df3_mask, "__builtin_ia32_orpd128_mask", IX86_BUILTIN_ORPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32077   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv8sf3_mask, "__builtin_ia32_orps256_mask", IX86_BUILTIN_ORPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32078   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv4sf3_mask, "__builtin_ia32_orps128_mask", IX86_BUILTIN_ORPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32079   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_broadcastv8sf_mask, "__builtin_ia32_broadcastf32x2_256_mask", IX86_BUILTIN_BROADCASTF32x2_256, UNKNOWN, (int) V8SF_FTYPE_V4SF_V8SF_QI },
32080   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_broadcastv8si_mask, "__builtin_ia32_broadcasti32x2_256_mask", IX86_BUILTIN_BROADCASTI32x2_256, UNKNOWN, (int) V8SI_FTYPE_V4SI_V8SI_QI },
32081   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_broadcastv4si_mask, "__builtin_ia32_broadcasti32x2_128_mask", IX86_BUILTIN_BROADCASTI32x2_128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32082   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_broadcastv4df_mask_1, "__builtin_ia32_broadcastf64x2_256_mask", IX86_BUILTIN_BROADCASTF64X2_256, UNKNOWN, (int) V4DF_FTYPE_V2DF_V4DF_QI },
32083   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_broadcastv4di_mask_1, "__builtin_ia32_broadcasti64x2_256_mask", IX86_BUILTIN_BROADCASTI64X2_256, UNKNOWN, (int) V4DI_FTYPE_V2DI_V4DI_QI },
32084   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_broadcastv8sf_mask_1, "__builtin_ia32_broadcastf32x4_256_mask", IX86_BUILTIN_BROADCASTF32X4_256, UNKNOWN, (int) V8SF_FTYPE_V4SF_V8SF_QI },
32085   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_broadcastv8si_mask_1, "__builtin_ia32_broadcasti32x4_256_mask", IX86_BUILTIN_BROADCASTI32X4_256, UNKNOWN, (int) V8SI_FTYPE_V4SI_V8SI_QI },
32086   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vextractf128v8sf, "__builtin_ia32_extractf32x4_256_mask", IX86_BUILTIN_EXTRACTF32X4_256, UNKNOWN, (int) V4SF_FTYPE_V8SF_INT_V4SF_QI },
32087   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vextractf128v8si, "__builtin_ia32_extracti32x4_256_mask", IX86_BUILTIN_EXTRACTI32X4_256, UNKNOWN, (int) V4SI_FTYPE_V8SI_INT_V4SI_QI },
32088   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512bw_dbpsadbwv16hi_mask, "__builtin_ia32_dbpsadbw256_mask", IX86_BUILTIN_DBPSADBW256, UNKNOWN, (int) V16HI_FTYPE_V32QI_V32QI_INT_V16HI_HI },
32089   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512bw_dbpsadbwv8hi_mask, "__builtin_ia32_dbpsadbw128_mask", IX86_BUILTIN_DBPSADBW128, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI_INT_V8HI_QI },
32090   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv4dfv4di2_mask, "__builtin_ia32_cvttpd2qq256_mask", IX86_BUILTIN_CVTTPD2QQ256, UNKNOWN, (int) V4DI_FTYPE_V4DF_V4DI_QI },
32091   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv2dfv2di2_mask, "__builtin_ia32_cvttpd2qq128_mask", IX86_BUILTIN_CVTTPD2QQ128, UNKNOWN, (int) V2DI_FTYPE_V2DF_V2DI_QI },
32092   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv4dfv4di2_mask, "__builtin_ia32_cvttpd2uqq256_mask", IX86_BUILTIN_CVTTPD2UQQ256, UNKNOWN, (int) V4DI_FTYPE_V4DF_V4DI_QI },
32093   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv2dfv2di2_mask, "__builtin_ia32_cvttpd2uqq128_mask", IX86_BUILTIN_CVTTPD2UQQ128, UNKNOWN, (int) V2DI_FTYPE_V2DF_V2DI_QI },
32094   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_notruncv4dfv4di2_mask, "__builtin_ia32_cvtpd2qq256_mask", IX86_BUILTIN_CVTPD2QQ256, UNKNOWN, (int) V4DI_FTYPE_V4DF_V4DI_QI },
32095   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_notruncv2dfv2di2_mask, "__builtin_ia32_cvtpd2qq128_mask", IX86_BUILTIN_CVTPD2QQ128, UNKNOWN, (int) V2DI_FTYPE_V2DF_V2DI_QI },
32096   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_notruncv4dfv4di2_mask, "__builtin_ia32_cvtpd2uqq256_mask", IX86_BUILTIN_CVTPD2UQQ256, UNKNOWN, (int) V4DI_FTYPE_V4DF_V4DI_QI },
32097   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_notruncv2dfv2di2_mask, "__builtin_ia32_cvtpd2uqq128_mask", IX86_BUILTIN_CVTPD2UQQ128, UNKNOWN, (int) V2DI_FTYPE_V2DF_V2DI_QI },
32098   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_notruncv4dfv4si2_mask, "__builtin_ia32_cvtpd2udq256_mask", IX86_BUILTIN_CVTPD2UDQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32099   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_notruncv2dfv2si2_mask, "__builtin_ia32_cvtpd2udq128_mask", IX86_BUILTIN_CVTPD2UDQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32100   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv4sfv4di2_mask, "__builtin_ia32_cvttps2qq256_mask", IX86_BUILTIN_CVTTPS2QQ256, UNKNOWN, (int) V4DI_FTYPE_V4SF_V4DI_QI },
32101   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv2sfv2di2_mask, "__builtin_ia32_cvttps2qq128_mask", IX86_BUILTIN_CVTTPS2QQ128, UNKNOWN, (int) V2DI_FTYPE_V4SF_V2DI_QI },
32102   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv4sfv4di2_mask, "__builtin_ia32_cvttps2uqq256_mask", IX86_BUILTIN_CVTTPS2UQQ256, UNKNOWN, (int) V4DI_FTYPE_V4SF_V4DI_QI },
32103   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv2sfv2di2_mask, "__builtin_ia32_cvttps2uqq128_mask", IX86_BUILTIN_CVTTPS2UQQ128, UNKNOWN, (int) V2DI_FTYPE_V4SF_V2DI_QI },
32104   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv8sfv8si2_mask, "__builtin_ia32_cvttps2dq256_mask", IX86_BUILTIN_CVTTPS2DQ256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32105   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv4sfv4si2_mask, "__builtin_ia32_cvttps2dq128_mask", IX86_BUILTIN_CVTTPS2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32106   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv8sfv8si2_mask, "__builtin_ia32_cvttps2udq256_mask", IX86_BUILTIN_CVTTPS2UDQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32107   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv4sfv4si2_mask, "__builtin_ia32_cvttps2udq128_mask", IX86_BUILTIN_CVTTPS2UDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32108   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_fix_truncv4dfv4si2_mask, "__builtin_ia32_cvttpd2dq256_mask", IX86_BUILTIN_CVTTPD2DQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32109   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvttpd2dq_mask, "__builtin_ia32_cvttpd2dq128_mask", IX86_BUILTIN_CVTTPD2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32110   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv4dfv4si2_mask, "__builtin_ia32_cvttpd2udq256_mask", IX86_BUILTIN_CVTTPD2UDQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32111   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufix_truncv2dfv2si2_mask, "__builtin_ia32_cvttpd2udq128_mask", IX86_BUILTIN_CVTTPD2UDQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32112   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_cvtpd2dq256_mask, "__builtin_ia32_cvtpd2dq256_mask", IX86_BUILTIN_CVTPD2DQ256_MASK, UNKNOWN, (int) V4SI_FTYPE_V4DF_V4SI_QI },
32113   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtpd2dq_mask, "__builtin_ia32_cvtpd2dq128_mask", IX86_BUILTIN_CVTPD2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V2DF_V4SI_QI },
32114   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv4siv4df2_mask, "__builtin_ia32_cvtdq2pd256_mask", IX86_BUILTIN_CVTDQ2PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4SI_V4DF_QI },
32115   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtdq2pd_mask, "__builtin_ia32_cvtdq2pd128_mask", IX86_BUILTIN_CVTDQ2PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V4SI_V2DF_QI },
32116   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv4siv4df2_mask, "__builtin_ia32_cvtudq2pd256_mask", IX86_BUILTIN_CVTUDQ2PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4SI_V4DF_QI },
32117   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv2siv2df2_mask, "__builtin_ia32_cvtudq2pd128_mask", IX86_BUILTIN_CVTUDQ2PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V4SI_V2DF_QI },
32118   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv8siv8sf2_mask, "__builtin_ia32_cvtdq2ps256_mask", IX86_BUILTIN_CVTDQ2PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_QI },
32119   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv4siv4sf2_mask, "__builtin_ia32_cvtdq2ps128_mask", IX86_BUILTIN_CVTDQ2PS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_QI },
32120   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv8siv8sf2_mask, "__builtin_ia32_cvtudq2ps256_mask", IX86_BUILTIN_CVTUDQ2PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_QI },
32121   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv4siv4sf2_mask, "__builtin_ia32_cvtudq2ps128_mask", IX86_BUILTIN_CVTUDQ2PS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_QI },
32122   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_cvtps2pd256_mask, "__builtin_ia32_cvtps2pd256_mask", IX86_BUILTIN_CVTPS2PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4SF_V4DF_QI },
32123   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtps2pd_mask, "__builtin_ia32_cvtps2pd128_mask", IX86_BUILTIN_CVTPS2PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V4SF_V2DF_QI },
32124   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv32qi_mask, "__builtin_ia32_pbroadcastb256_mask", IX86_BUILTIN_PBROADCASTB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V16QI_V32QI_SI },
32125   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dup_gprv32qi_mask, "__builtin_ia32_pbroadcastb256_gpr_mask", IX86_BUILTIN_PBROADCASTB256_GPR_MASK, UNKNOWN, (int) V32QI_FTYPE_QI_V32QI_SI },
32126   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv16qi_mask, "__builtin_ia32_pbroadcastb128_mask", IX86_BUILTIN_PBROADCASTB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_HI },
32127   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dup_gprv16qi_mask, "__builtin_ia32_pbroadcastb128_gpr_mask", IX86_BUILTIN_PBROADCASTB128_GPR_MASK, UNKNOWN, (int) V16QI_FTYPE_QI_V16QI_HI },
32128   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv16hi_mask, "__builtin_ia32_pbroadcastw256_mask", IX86_BUILTIN_PBROADCASTW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V8HI_V16HI_HI },
32129   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dup_gprv16hi_mask, "__builtin_ia32_pbroadcastw256_gpr_mask", IX86_BUILTIN_PBROADCASTW256_GPR_MASK, UNKNOWN, (int) V16HI_FTYPE_HI_V16HI_HI },
32130   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv8hi_mask, "__builtin_ia32_pbroadcastw128_mask", IX86_BUILTIN_PBROADCASTW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_QI },
32131   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dup_gprv8hi_mask, "__builtin_ia32_pbroadcastw128_gpr_mask", IX86_BUILTIN_PBROADCASTW128_GPR_MASK, UNKNOWN, (int) V8HI_FTYPE_HI_V8HI_QI },
32132   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv8si_mask, "__builtin_ia32_pbroadcastd256_mask", IX86_BUILTIN_PBROADCASTD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V4SI_V8SI_QI },
32133   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dup_gprv8si_mask, "__builtin_ia32_pbroadcastd256_gpr_mask", IX86_BUILTIN_PBROADCASTD256_GPR_MASK, UNKNOWN, (int) V8SI_FTYPE_SI_V8SI_QI },
32134   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv4si_mask, "__builtin_ia32_pbroadcastd128_mask", IX86_BUILTIN_PBROADCASTD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32135   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dup_gprv4si_mask, "__builtin_ia32_pbroadcastd128_gpr_mask", IX86_BUILTIN_PBROADCASTD128_GPR_MASK, UNKNOWN, (int) V4SI_FTYPE_SI_V4SI_QI },
32136   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv4di_mask, "__builtin_ia32_pbroadcastq256_mask", IX86_BUILTIN_PBROADCASTQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V2DI_V4DI_QI },
32137   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dup_gprv4di_mask, "__builtin_ia32_pbroadcastq256_gpr_mask", IX86_BUILTIN_PBROADCASTQ256_GPR_MASK, UNKNOWN, (int) V4DI_FTYPE_DI_V4DI_QI },
32138   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv2di_mask, "__builtin_ia32_pbroadcastq128_mask", IX86_BUILTIN_PBROADCASTQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32139   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dup_gprv2di_mask, "__builtin_ia32_pbroadcastq128_gpr_mask", IX86_BUILTIN_PBROADCASTQ128_GPR_MASK, UNKNOWN, (int) V2DI_FTYPE_DI_V2DI_QI },
32140   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv8sf_mask, "__builtin_ia32_broadcastss256_mask", IX86_BUILTIN_BROADCASTSS256, UNKNOWN, (int) V8SF_FTYPE_V4SF_V8SF_QI },
32141   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv4sf_mask, "__builtin_ia32_broadcastss128_mask", IX86_BUILTIN_BROADCASTSS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32142   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vec_dupv4df_mask, "__builtin_ia32_broadcastsd256_mask", IX86_BUILTIN_BROADCASTSD256, UNKNOWN, (int) V4DF_FTYPE_V2DF_V4DF_QI },
32143   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vextractf128v4df, "__builtin_ia32_extractf64x2_256_mask", IX86_BUILTIN_EXTRACTF64X2_256, UNKNOWN, (int) V2DF_FTYPE_V4DF_INT_V2DF_QI },
32144   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vextractf128v4di, "__builtin_ia32_extracti64x2_256_mask", IX86_BUILTIN_EXTRACTI64X2_256, UNKNOWN, (int) V2DI_FTYPE_V4DI_INT_V2DI_QI },
32145   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vinsertv8sf, "__builtin_ia32_insertf32x4_256_mask", IX86_BUILTIN_INSERTF32X4_256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V4SF_INT_V8SF_QI },
32146   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vinsertv8si, "__builtin_ia32_inserti32x4_256_mask", IX86_BUILTIN_INSERTI32X4_256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_INT_V8SI_QI },
32147   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_sign_extendv16qiv16hi2_mask, "__builtin_ia32_pmovsxbw256_mask", IX86_BUILTIN_PMOVSXBW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16QI_V16HI_HI },
32148   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_sign_extendv8qiv8hi2_mask, "__builtin_ia32_pmovsxbw128_mask", IX86_BUILTIN_PMOVSXBW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V16QI_V8HI_QI },
32149   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_sign_extendv8qiv8si2_mask, "__builtin_ia32_pmovsxbd256_mask", IX86_BUILTIN_PMOVSXBD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V16QI_V8SI_QI },
32150   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_sign_extendv4qiv4si2_mask, "__builtin_ia32_pmovsxbd128_mask", IX86_BUILTIN_PMOVSXBD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V16QI_V4SI_QI },
32151   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_sign_extendv4qiv4di2_mask, "__builtin_ia32_pmovsxbq256_mask", IX86_BUILTIN_PMOVSXBQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V16QI_V4DI_QI },
32152   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_sign_extendv2qiv2di2_mask, "__builtin_ia32_pmovsxbq128_mask", IX86_BUILTIN_PMOVSXBQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V16QI_V2DI_QI },
32153   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_sign_extendv8hiv8si2_mask, "__builtin_ia32_pmovsxwd256_mask", IX86_BUILTIN_PMOVSXWD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8HI_V8SI_QI },
32154   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_sign_extendv4hiv4si2_mask, "__builtin_ia32_pmovsxwd128_mask", IX86_BUILTIN_PMOVSXWD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V8HI_V4SI_QI },
32155   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_sign_extendv4hiv4di2_mask, "__builtin_ia32_pmovsxwq256_mask", IX86_BUILTIN_PMOVSXWQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V8HI_V4DI_QI },
32156   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_sign_extendv2hiv2di2_mask, "__builtin_ia32_pmovsxwq128_mask", IX86_BUILTIN_PMOVSXWQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V8HI_V2DI_QI },
32157   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_sign_extendv4siv4di2_mask, "__builtin_ia32_pmovsxdq256_mask", IX86_BUILTIN_PMOVSXDQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4SI_V4DI_QI },
32158   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_sign_extendv2siv2di2_mask, "__builtin_ia32_pmovsxdq128_mask", IX86_BUILTIN_PMOVSXDQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V4SI_V2DI_QI },
32159   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_zero_extendv16qiv16hi2_mask, "__builtin_ia32_pmovzxbw256_mask", IX86_BUILTIN_PMOVZXBW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16QI_V16HI_HI },
32160   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_zero_extendv8qiv8hi2_mask, "__builtin_ia32_pmovzxbw128_mask", IX86_BUILTIN_PMOVZXBW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V16QI_V8HI_QI },
32161   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_zero_extendv8qiv8si2_mask, "__builtin_ia32_pmovzxbd256_mask", IX86_BUILTIN_PMOVZXBD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V16QI_V8SI_QI },
32162   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_zero_extendv4qiv4si2_mask, "__builtin_ia32_pmovzxbd128_mask", IX86_BUILTIN_PMOVZXBD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V16QI_V4SI_QI },
32163   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_zero_extendv4qiv4di2_mask, "__builtin_ia32_pmovzxbq256_mask", IX86_BUILTIN_PMOVZXBQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V16QI_V4DI_QI },
32164   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_zero_extendv2qiv2di2_mask, "__builtin_ia32_pmovzxbq128_mask", IX86_BUILTIN_PMOVZXBQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V16QI_V2DI_QI },
32165   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_zero_extendv8hiv8si2_mask, "__builtin_ia32_pmovzxwd256_mask", IX86_BUILTIN_PMOVZXWD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8HI_V8SI_QI },
32166   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_zero_extendv4hiv4si2_mask, "__builtin_ia32_pmovzxwd128_mask", IX86_BUILTIN_PMOVZXWD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V8HI_V4SI_QI },
32167   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_zero_extendv4hiv4di2_mask, "__builtin_ia32_pmovzxwq256_mask", IX86_BUILTIN_PMOVZXWQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V8HI_V4DI_QI },
32168   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_zero_extendv2hiv2di2_mask, "__builtin_ia32_pmovzxwq128_mask", IX86_BUILTIN_PMOVZXWQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V8HI_V2DI_QI },
32169   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_zero_extendv4siv4di2_mask, "__builtin_ia32_pmovzxdq256_mask", IX86_BUILTIN_PMOVZXDQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4SI_V4DI_QI },
32170   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_zero_extendv2siv2di2_mask, "__builtin_ia32_pmovzxdq128_mask", IX86_BUILTIN_PMOVZXDQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V4SI_V2DI_QI },
32171   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_reducepv4df_mask, "__builtin_ia32_reducepd256_mask", IX86_BUILTIN_REDUCEPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT_V4DF_QI },
32172   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_reducepv2df_mask, "__builtin_ia32_reducepd128_mask", IX86_BUILTIN_REDUCEPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT_V2DF_QI },
32173   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_reducepv8sf_mask, "__builtin_ia32_reduceps256_mask", IX86_BUILTIN_REDUCEPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT_V8SF_QI },
32174   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_reducepv4sf_mask, "__builtin_ia32_reduceps128_mask", IX86_BUILTIN_REDUCEPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT_V4SF_QI },
32175   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducesv2df, "__builtin_ia32_reducesd", IX86_BUILTIN_REDUCESD_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32176   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducesv4sf, "__builtin_ia32_reducess", IX86_BUILTIN_REDUCESS_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32177   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_permvarv16hi_mask, "__builtin_ia32_permvarhi256_mask", IX86_BUILTIN_VPERMVARHI256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32178   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_permvarv8hi_mask, "__builtin_ia32_permvarhi128_mask", IX86_BUILTIN_VPERMVARHI128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32179   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv16hi3_mask, "__builtin_ia32_vpermt2varhi256_mask", IX86_BUILTIN_VPERMT2VARHI256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32180   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv16hi3_maskz, "__builtin_ia32_vpermt2varhi256_maskz", IX86_BUILTIN_VPERMT2VARHI256_MASKZ, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32181   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8hi3_mask, "__builtin_ia32_vpermt2varhi128_mask", IX86_BUILTIN_VPERMT2VARHI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32182   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8hi3_maskz, "__builtin_ia32_vpermt2varhi128_maskz", IX86_BUILTIN_VPERMT2VARHI128_MASKZ, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32183   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv16hi3_mask, "__builtin_ia32_vpermi2varhi256_mask", IX86_BUILTIN_VPERMI2VARHI256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32184   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv8hi3_mask, "__builtin_ia32_vpermi2varhi128_mask", IX86_BUILTIN_VPERMI2VARHI128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32185   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v4df_mask, "__builtin_ia32_rcp14pd256_mask", IX86_BUILTIN_RCP14PD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32186   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v2df_mask, "__builtin_ia32_rcp14pd128_mask", IX86_BUILTIN_RCP14PD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32187   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v8sf_mask, "__builtin_ia32_rcp14ps256_mask", IX86_BUILTIN_RCP14PS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32188   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rcp14v4sf_mask, "__builtin_ia32_rcp14ps128_mask", IX86_BUILTIN_RCP14PS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32189   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v4df_mask, "__builtin_ia32_rsqrt14pd256_mask", IX86_BUILTIN_RSQRT14PD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32190   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v2df_mask, "__builtin_ia32_rsqrt14pd128_mask", IX86_BUILTIN_RSQRT14PD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32191   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v8sf_mask, "__builtin_ia32_rsqrt14ps256_mask", IX86_BUILTIN_RSQRT14PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32192   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_rsqrt14v4sf_mask, "__builtin_ia32_rsqrt14ps128_mask", IX86_BUILTIN_RSQRT14PS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32193   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_sqrtv4df2_mask, "__builtin_ia32_sqrtpd256_mask", IX86_BUILTIN_SQRTPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32194   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_sqrtv2df2_mask, "__builtin_ia32_sqrtpd128_mask", IX86_BUILTIN_SQRTPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32195   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_sqrtv8sf2_mask, "__builtin_ia32_sqrtps256_mask", IX86_BUILTIN_SQRTPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32196   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse_sqrtv4sf2_mask, "__builtin_ia32_sqrtps128_mask", IX86_BUILTIN_SQRTPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32197   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv16qi3_mask, "__builtin_ia32_paddb128_mask", IX86_BUILTIN_PADDB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32198   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv8hi3_mask, "__builtin_ia32_paddw128_mask", IX86_BUILTIN_PADDW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32199   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4si3_mask, "__builtin_ia32_paddd128_mask", IX86_BUILTIN_PADDD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32200   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv2di3_mask, "__builtin_ia32_paddq128_mask", IX86_BUILTIN_PADDQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32201   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv16qi3_mask, "__builtin_ia32_psubb128_mask", IX86_BUILTIN_PSUBB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32202   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv8hi3_mask, "__builtin_ia32_psubw128_mask", IX86_BUILTIN_PSUBW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32203   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4si3_mask, "__builtin_ia32_psubd128_mask", IX86_BUILTIN_PSUBD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32204   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv2di3_mask, "__builtin_ia32_psubq128_mask", IX86_BUILTIN_PSUBQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32205   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_ssaddv16qi3_mask, "__builtin_ia32_paddsb128_mask", IX86_BUILTIN_PADDSB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32206   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_ssaddv8hi3_mask, "__builtin_ia32_paddsw128_mask", IX86_BUILTIN_PADDSW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32207   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_sssubv16qi3_mask, "__builtin_ia32_psubsb128_mask", IX86_BUILTIN_PSUBSB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32208   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_sssubv8hi3_mask, "__builtin_ia32_psubsw128_mask", IX86_BUILTIN_PSUBSW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32209   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_usaddv16qi3_mask, "__builtin_ia32_paddusb128_mask", IX86_BUILTIN_PADDUSB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32210   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_usaddv8hi3_mask, "__builtin_ia32_paddusw128_mask", IX86_BUILTIN_PADDUSW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32211   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_ussubv16qi3_mask, "__builtin_ia32_psubusb128_mask", IX86_BUILTIN_PSUBUSB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32212   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_ussubv8hi3_mask, "__builtin_ia32_psubusw128_mask", IX86_BUILTIN_PSUBUSW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32213   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv32qi3_mask, "__builtin_ia32_paddb256_mask", IX86_BUILTIN_PADDB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32214   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv16hi3_mask, "__builtin_ia32_paddw256_mask", IX86_BUILTIN_PADDW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32215   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv8si3_mask, "__builtin_ia32_paddd256_mask", IX86_BUILTIN_PADDD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32216   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_addv4di3_mask, "__builtin_ia32_paddq256_mask", IX86_BUILTIN_PADDQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32217   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ssaddv32qi3_mask, "__builtin_ia32_paddsb256_mask", IX86_BUILTIN_PADDSB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32218   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ssaddv16hi3_mask, "__builtin_ia32_paddsw256_mask", IX86_BUILTIN_PADDSW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32219   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_usaddv32qi3_mask, "__builtin_ia32_paddusb256_mask", IX86_BUILTIN_PADDUSB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32220   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_usaddv16hi3_mask, "__builtin_ia32_paddusw256_mask", IX86_BUILTIN_PADDUSW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32221   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv32qi3_mask, "__builtin_ia32_psubb256_mask", IX86_BUILTIN_PSUBB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32222   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv16hi3_mask, "__builtin_ia32_psubw256_mask", IX86_BUILTIN_PSUBW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32223   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv8si3_mask, "__builtin_ia32_psubd256_mask", IX86_BUILTIN_PSUBD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32224   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_subv4di3_mask, "__builtin_ia32_psubq256_mask", IX86_BUILTIN_PSUBQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32225   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_sssubv32qi3_mask, "__builtin_ia32_psubsb256_mask", IX86_BUILTIN_PSUBSB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32226   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_sssubv16hi3_mask, "__builtin_ia32_psubsw256_mask", IX86_BUILTIN_PSUBSW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32227   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ussubv32qi3_mask, "__builtin_ia32_psubusb256_mask", IX86_BUILTIN_PSUBUSB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32228   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ussubv16hi3_mask, "__builtin_ia32_psubusw256_mask", IX86_BUILTIN_PSUBUSW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32229   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_shuf_f64x2_mask, "__builtin_ia32_shuf_f64x2_256_mask", IX86_BUILTIN_SHUF_F64x2_256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT_V4DF_QI },
32230   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_shuf_i64x2_mask, "__builtin_ia32_shuf_i64x2_256_mask", IX86_BUILTIN_SHUF_I64x2_256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_INT_V4DI_QI },
32231   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_shuf_i32x4_mask, "__builtin_ia32_shuf_i32x4_256_mask", IX86_BUILTIN_SHUF_I32x4_256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT_V8SI_QI },
32232   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_shuf_f32x4_mask, "__builtin_ia32_shuf_f32x4_256_mask", IX86_BUILTIN_SHUF_F32x4_256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT_V8SF_QI },
32233   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev8hiv8qi2_mask, "__builtin_ia32_pmovwb128_mask", IX86_BUILTIN_PMOVWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V16QI_QI },
32234   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev16hiv16qi2_mask, "__builtin_ia32_pmovwb256_mask", IX86_BUILTIN_PMOVWB256, UNKNOWN, (int) V16QI_FTYPE_V16HI_V16QI_HI },
32235   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev8hiv8qi2_mask, "__builtin_ia32_pmovswb128_mask", IX86_BUILTIN_PMOVSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V16QI_QI },
32236   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev16hiv16qi2_mask, "__builtin_ia32_pmovswb256_mask", IX86_BUILTIN_PMOVSWB256, UNKNOWN, (int) V16QI_FTYPE_V16HI_V16QI_HI },
32237   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev8hiv8qi2_mask, "__builtin_ia32_pmovuswb128_mask", IX86_BUILTIN_PMOVUSWB128, UNKNOWN, (int) V16QI_FTYPE_V8HI_V16QI_QI },
32238   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev16hiv16qi2_mask, "__builtin_ia32_pmovuswb256_mask", IX86_BUILTIN_PMOVUSWB256, UNKNOWN, (int) V16QI_FTYPE_V16HI_V16QI_HI },
32239   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4siv4qi2_mask, "__builtin_ia32_pmovdb128_mask", IX86_BUILTIN_PMOVDB128, UNKNOWN, (int) V16QI_FTYPE_V4SI_V16QI_QI },
32240   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev8siv8qi2_mask, "__builtin_ia32_pmovdb256_mask", IX86_BUILTIN_PMOVDB256, UNKNOWN, (int) V16QI_FTYPE_V8SI_V16QI_QI },
32241   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4siv4qi2_mask, "__builtin_ia32_pmovsdb128_mask", IX86_BUILTIN_PMOVSDB128, UNKNOWN, (int) V16QI_FTYPE_V4SI_V16QI_QI },
32242   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev8siv8qi2_mask, "__builtin_ia32_pmovsdb256_mask", IX86_BUILTIN_PMOVSDB256, UNKNOWN, (int) V16QI_FTYPE_V8SI_V16QI_QI },
32243   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4siv4qi2_mask, "__builtin_ia32_pmovusdb128_mask", IX86_BUILTIN_PMOVUSDB128, UNKNOWN, (int) V16QI_FTYPE_V4SI_V16QI_QI },
32244   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev8siv8qi2_mask, "__builtin_ia32_pmovusdb256_mask", IX86_BUILTIN_PMOVUSDB256, UNKNOWN, (int) V16QI_FTYPE_V8SI_V16QI_QI },
32245   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4siv4hi2_mask, "__builtin_ia32_pmovdw128_mask", IX86_BUILTIN_PMOVDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V8HI_QI },
32246   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev8siv8hi2_mask, "__builtin_ia32_pmovdw256_mask", IX86_BUILTIN_PMOVDW256, UNKNOWN, (int) V8HI_FTYPE_V8SI_V8HI_QI },
32247   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4siv4hi2_mask, "__builtin_ia32_pmovsdw128_mask", IX86_BUILTIN_PMOVSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V8HI_QI },
32248   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev8siv8hi2_mask, "__builtin_ia32_pmovsdw256_mask", IX86_BUILTIN_PMOVSDW256, UNKNOWN, (int) V8HI_FTYPE_V8SI_V8HI_QI },
32249   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4siv4hi2_mask, "__builtin_ia32_pmovusdw128_mask", IX86_BUILTIN_PMOVUSDW128, UNKNOWN, (int) V8HI_FTYPE_V4SI_V8HI_QI },
32250   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev8siv8hi2_mask, "__builtin_ia32_pmovusdw256_mask", IX86_BUILTIN_PMOVUSDW256, UNKNOWN, (int) V8HI_FTYPE_V8SI_V8HI_QI },
32251   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2qi2_mask, "__builtin_ia32_pmovqb128_mask", IX86_BUILTIN_PMOVQB128, UNKNOWN, (int) V16QI_FTYPE_V2DI_V16QI_QI },
32252   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4qi2_mask, "__builtin_ia32_pmovqb256_mask", IX86_BUILTIN_PMOVQB256, UNKNOWN, (int) V16QI_FTYPE_V4DI_V16QI_QI },
32253   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2qi2_mask, "__builtin_ia32_pmovsqb128_mask", IX86_BUILTIN_PMOVSQB128, UNKNOWN, (int) V16QI_FTYPE_V2DI_V16QI_QI },
32254   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4qi2_mask, "__builtin_ia32_pmovsqb256_mask", IX86_BUILTIN_PMOVSQB256, UNKNOWN, (int) V16QI_FTYPE_V4DI_V16QI_QI },
32255   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2qi2_mask, "__builtin_ia32_pmovusqb128_mask", IX86_BUILTIN_PMOVUSQB128, UNKNOWN, (int) V16QI_FTYPE_V2DI_V16QI_QI },
32256   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4qi2_mask, "__builtin_ia32_pmovusqb256_mask", IX86_BUILTIN_PMOVUSQB256, UNKNOWN, (int) V16QI_FTYPE_V4DI_V16QI_QI },
32257   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2hi2_mask, "__builtin_ia32_pmovqw128_mask", IX86_BUILTIN_PMOVQW128, UNKNOWN, (int) V8HI_FTYPE_V2DI_V8HI_QI },
32258   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4hi2_mask, "__builtin_ia32_pmovqw256_mask", IX86_BUILTIN_PMOVQW256, UNKNOWN, (int) V8HI_FTYPE_V4DI_V8HI_QI },
32259   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2hi2_mask, "__builtin_ia32_pmovsqw128_mask", IX86_BUILTIN_PMOVSQW128, UNKNOWN, (int) V8HI_FTYPE_V2DI_V8HI_QI },
32260   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4hi2_mask, "__builtin_ia32_pmovsqw256_mask", IX86_BUILTIN_PMOVSQW256, UNKNOWN, (int) V8HI_FTYPE_V4DI_V8HI_QI },
32261   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2hi2_mask, "__builtin_ia32_pmovusqw128_mask", IX86_BUILTIN_PMOVUSQW128, UNKNOWN, (int) V8HI_FTYPE_V2DI_V8HI_QI },
32262   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4hi2_mask, "__builtin_ia32_pmovusqw256_mask", IX86_BUILTIN_PMOVUSQW256, UNKNOWN, (int) V8HI_FTYPE_V4DI_V8HI_QI },
32263   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev2div2si2_mask, "__builtin_ia32_pmovqd128_mask", IX86_BUILTIN_PMOVQD128, UNKNOWN, (int) V4SI_FTYPE_V2DI_V4SI_QI },
32264   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_truncatev4div4si2_mask, "__builtin_ia32_pmovqd256_mask", IX86_BUILTIN_PMOVQD256, UNKNOWN, (int) V4SI_FTYPE_V4DI_V4SI_QI },
32265   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev2div2si2_mask, "__builtin_ia32_pmovsqd128_mask", IX86_BUILTIN_PMOVSQD128, UNKNOWN, (int) V4SI_FTYPE_V2DI_V4SI_QI },
32266   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ss_truncatev4div4si2_mask, "__builtin_ia32_pmovsqd256_mask", IX86_BUILTIN_PMOVSQD256, UNKNOWN, (int) V4SI_FTYPE_V4DI_V4SI_QI },
32267   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev2div2si2_mask, "__builtin_ia32_pmovusqd128_mask", IX86_BUILTIN_PMOVUSQD128, UNKNOWN, (int) V4SI_FTYPE_V2DI_V4SI_QI },
32268   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_us_truncatev4div4si2_mask, "__builtin_ia32_pmovusqd256_mask", IX86_BUILTIN_PMOVUSQD256, UNKNOWN, (int) V4SI_FTYPE_V4DI_V4SI_QI },
32269   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_rangepv4df_mask, "__builtin_ia32_rangepd256_mask", IX86_BUILTIN_RANGEPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT_V4DF_QI },
32270   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_rangepv2df_mask, "__builtin_ia32_rangepd128_mask", IX86_BUILTIN_RANGEPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_V2DF_QI },
32271   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_rangepv8sf_mask, "__builtin_ia32_rangeps256_mask", IX86_BUILTIN_RANGEPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT_V8SF_QI },
32272   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_rangepv4sf_mask, "__builtin_ia32_rangeps128_mask", IX86_BUILTIN_RANGEPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_V4SF_QI },
32273   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv8sf_mask, "__builtin_ia32_getexpps256_mask", IX86_BUILTIN_GETEXPPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32274   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv4df_mask, "__builtin_ia32_getexppd256_mask", IX86_BUILTIN_GETEXPPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32275   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv4sf_mask, "__builtin_ia32_getexpps128_mask", IX86_BUILTIN_GETEXPPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32276   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getexpv2df_mask, "__builtin_ia32_getexppd128_mask", IX86_BUILTIN_GETEXPPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32277   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fixupimmv4df_mask, "__builtin_ia32_fixupimmpd256_mask", IX86_BUILTIN_FIXUPIMMPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DI_INT_QI },
32278   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fixupimmv4df_maskz, "__builtin_ia32_fixupimmpd256_maskz", IX86_BUILTIN_FIXUPIMMPD256_MASKZ, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DI_INT_QI },
32279   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fixupimmv8sf_mask, "__builtin_ia32_fixupimmps256_mask", IX86_BUILTIN_FIXUPIMMPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SI_INT_QI },
32280   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fixupimmv8sf_maskz, "__builtin_ia32_fixupimmps256_maskz", IX86_BUILTIN_FIXUPIMMPS256_MASKZ, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SI_INT_QI },
32281   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fixupimmv2df_mask, "__builtin_ia32_fixupimmpd128_mask", IX86_BUILTIN_FIXUPIMMPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI },
32282   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fixupimmv2df_maskz, "__builtin_ia32_fixupimmpd128_maskz", IX86_BUILTIN_FIXUPIMMPD128_MASKZ, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI },
32283   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fixupimmv4sf_mask, "__builtin_ia32_fixupimmps128_mask", IX86_BUILTIN_FIXUPIMMPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI },
32284   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fixupimmv4sf_maskz, "__builtin_ia32_fixupimmps128_maskz", IX86_BUILTIN_FIXUPIMMPS128_MASKZ, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI },
32285   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv4di2_mask, "__builtin_ia32_pabsq256_mask", IX86_BUILTIN_PABSQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32286   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv2di2_mask, "__builtin_ia32_pabsq128_mask", IX86_BUILTIN_PABSQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32287   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv8si2_mask, "__builtin_ia32_pabsd256_mask", IX86_BUILTIN_PABSD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32288   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv4si2_mask, "__builtin_ia32_pabsd128_mask", IX86_BUILTIN_PABSD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32289   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_pmulhrswv16hi3_mask , "__builtin_ia32_pmulhrsw256_mask", IX86_BUILTIN_PMULHRSW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32290   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ssse3_pmulhrswv8hi3_mask, "__builtin_ia32_pmulhrsw128_mask", IX86_BUILTIN_PMULHRSW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32291   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_umulv8hi3_highpart_mask, "__builtin_ia32_pmulhuw128_mask", IX86_BUILTIN_PMULHUW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32292   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_umulv16hi3_highpart_mask, "__builtin_ia32_pmulhuw256_mask" , IX86_BUILTIN_PMULHUW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32293   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_smulv16hi3_highpart_mask, "__builtin_ia32_pmulhw256_mask"  , IX86_BUILTIN_PMULHW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32294   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_smulv8hi3_highpart_mask, "__builtin_ia32_pmulhw128_mask", IX86_BUILTIN_PMULHW128_MASK, UNKNOWN,(int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32295   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv16hi3_mask, "__builtin_ia32_pmullw256_mask"  , IX86_BUILTIN_PMULLW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32296   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv8hi3_mask, "__builtin_ia32_pmullw128_mask", IX86_BUILTIN_PMULLW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32297   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_mulv4di3_mask, "__builtin_ia32_pmullq256_mask", IX86_BUILTIN_PMULLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32298   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_mulv2di3_mask, "__builtin_ia32_pmullq128_mask", IX86_BUILTIN_PMULLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32299   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv4df3_mask, "__builtin_ia32_andpd256_mask", IX86_BUILTIN_ANDPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32300   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv2df3_mask, "__builtin_ia32_andpd128_mask", IX86_BUILTIN_ANDPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32301   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv8sf3_mask, "__builtin_ia32_andps256_mask", IX86_BUILTIN_ANDPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32302   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv4sf3_mask, "__builtin_ia32_andps128_mask", IX86_BUILTIN_ANDPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32303   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_andnotv4df3_mask, "__builtin_ia32_andnpd256_mask", IX86_BUILTIN_ANDNPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32304   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_andnotv2df3_mask, "__builtin_ia32_andnpd128_mask", IX86_BUILTIN_ANDNPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32305   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_andnotv8sf3_mask, "__builtin_ia32_andnps256_mask", IX86_BUILTIN_ANDNPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32306   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse_andnotv4sf3_mask, "__builtin_ia32_andnps128_mask", IX86_BUILTIN_ANDNPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32307   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv8hi3_mask, "__builtin_ia32_psllwi128_mask", IX86_BUILTIN_PSLLWI128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT_V8HI_QI },
32308   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4si3_mask, "__builtin_ia32_pslldi128_mask", IX86_BUILTIN_PSLLDI128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32309   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv2di3_mask, "__builtin_ia32_psllqi128_mask", IX86_BUILTIN_PSLLQI128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32310   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv8hi3_mask, "__builtin_ia32_psllw128_mask", IX86_BUILTIN_PSLLW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32311   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4si3_mask, "__builtin_ia32_pslld128_mask", IX86_BUILTIN_PSLLD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32312   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv2di3_mask, "__builtin_ia32_psllq128_mask", IX86_BUILTIN_PSLLQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32313   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv16hi3_mask, "__builtin_ia32_psllwi256_mask", IX86_BUILTIN_PSLLWI256_MASK , UNKNOWN, (int) V16HI_FTYPE_V16HI_INT_V16HI_HI },
32314   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv16hi3_mask, "__builtin_ia32_psllw256_mask", IX86_BUILTIN_PSLLW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_V16HI_HI },
32315   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv8si3_mask, "__builtin_ia32_pslldi256_mask", IX86_BUILTIN_PSLLDI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32316   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv8si3_mask, "__builtin_ia32_pslld256_mask", IX86_BUILTIN_PSLLD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_V8SI_QI },
32317   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4di3_mask, "__builtin_ia32_psllqi256_mask", IX86_BUILTIN_PSLLQI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32318   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashlv4di3_mask, "__builtin_ia32_psllq256_mask", IX86_BUILTIN_PSLLQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_V4DI_QI },
32319   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4si3_mask, "__builtin_ia32_psradi128_mask", IX86_BUILTIN_PSRADI128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32320   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4si3_mask, "__builtin_ia32_psrad128_mask", IX86_BUILTIN_PSRAD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32321   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv8si3_mask, "__builtin_ia32_psradi256_mask", IX86_BUILTIN_PSRADI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32322   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv8si3_mask, "__builtin_ia32_psrad256_mask", IX86_BUILTIN_PSRAD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_V8SI_QI },
32323   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv2di3_mask, "__builtin_ia32_psraqi128_mask", IX86_BUILTIN_PSRAQI128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32324   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv2di3_mask, "__builtin_ia32_psraq128_mask", IX86_BUILTIN_PSRAQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32325   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4di3_mask, "__builtin_ia32_psraqi256_mask", IX86_BUILTIN_PSRAQI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32326   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv4di3_mask, "__builtin_ia32_psraq256_mask", IX86_BUILTIN_PSRAQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_V4DI_QI },
32327   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv8si3_mask, "__builtin_ia32_pandd256_mask", IX86_BUILTIN_PANDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32328   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv4si3_mask, "__builtin_ia32_pandd128_mask", IX86_BUILTIN_PANDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32329   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4si3_mask, "__builtin_ia32_psrldi128_mask", IX86_BUILTIN_PSRLDI128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32330   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4si3_mask, "__builtin_ia32_psrld128_mask", IX86_BUILTIN_PSRLD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32331   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv8si3_mask, "__builtin_ia32_psrldi256_mask", IX86_BUILTIN_PSRLDI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32332   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv8si3_mask, "__builtin_ia32_psrld256_mask", IX86_BUILTIN_PSRLD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V4SI_V8SI_QI },
32333   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv2di3_mask, "__builtin_ia32_psrlqi128_mask", IX86_BUILTIN_PSRLQI128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32334   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv2di3_mask, "__builtin_ia32_psrlq128_mask", IX86_BUILTIN_PSRLQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32335   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4di3_mask, "__builtin_ia32_psrlqi256_mask", IX86_BUILTIN_PSRLQI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32336   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv4di3_mask, "__builtin_ia32_psrlq256_mask", IX86_BUILTIN_PSRLQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_V4DI_QI },
32337   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv4di3_mask, "__builtin_ia32_pandq256_mask", IX86_BUILTIN_PANDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32338   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_andv2di3_mask, "__builtin_ia32_pandq128_mask", IX86_BUILTIN_PANDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32339   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_andnotv8si3_mask, "__builtin_ia32_pandnd256_mask", IX86_BUILTIN_PANDND256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32340   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_andnotv4si3_mask, "__builtin_ia32_pandnd128_mask", IX86_BUILTIN_PANDND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32341   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_andnotv4di3_mask, "__builtin_ia32_pandnq256_mask", IX86_BUILTIN_PANDNQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32342   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_andnotv2di3_mask, "__builtin_ia32_pandnq128_mask", IX86_BUILTIN_PANDNQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32343   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv8si3_mask, "__builtin_ia32_pord256_mask", IX86_BUILTIN_PORD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32344   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv4si3_mask, "__builtin_ia32_pord128_mask", IX86_BUILTIN_PORD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32345   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv4di3_mask, "__builtin_ia32_porq256_mask", IX86_BUILTIN_PORQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32346   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_iorv2di3_mask, "__builtin_ia32_porq128_mask", IX86_BUILTIN_PORQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32347   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv8si3_mask, "__builtin_ia32_pxord256_mask", IX86_BUILTIN_PXORD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32348   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv4si3_mask, "__builtin_ia32_pxord128_mask", IX86_BUILTIN_PXORD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32349   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv4di3_mask, "__builtin_ia32_pxorq256_mask", IX86_BUILTIN_PXORQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32350   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_xorv2di3_mask, "__builtin_ia32_pxorq128_mask", IX86_BUILTIN_PXORQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32351   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_packsswb_mask, "__builtin_ia32_packsswb256_mask",  IX86_BUILTIN_PACKSSWB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V16HI_V16HI_V32QI_SI },
32352   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_packsswb_mask, "__builtin_ia32_packsswb128_mask",  IX86_BUILTIN_PACKSSWB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI_V16QI_HI },
32353   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_packuswb_mask, "__builtin_ia32_packuswb256_mask",  IX86_BUILTIN_PACKUSWB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V16HI_V16HI_V32QI_SI },
32354   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_packuswb_mask, "__builtin_ia32_packuswb128_mask",  IX86_BUILTIN_PACKUSWB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V8HI_V8HI_V16QI_HI },
32355   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rndscalev8sf_mask, "__builtin_ia32_rndscaleps_256_mask", IX86_BUILTIN_RNDSCALEPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT_V8SF_QI },
32356   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rndscalev4df_mask, "__builtin_ia32_rndscalepd_256_mask", IX86_BUILTIN_RNDSCALEPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT_V4DF_QI },
32357   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rndscalev4sf_mask, "__builtin_ia32_rndscaleps_128_mask", IX86_BUILTIN_RNDSCALEPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT_V4SF_QI },
32358   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rndscalev2df_mask, "__builtin_ia32_rndscalepd_128_mask", IX86_BUILTIN_RNDSCALEPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT_V2DF_QI },
32359   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vternlogv4di_mask, "__builtin_ia32_pternlogq256_mask", IX86_BUILTIN_VTERNLOGQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_INT_QI },
32360   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vternlogv4di_maskz, "__builtin_ia32_pternlogq256_maskz", IX86_BUILTIN_VTERNLOGQ256_MASKZ, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_INT_QI },
32361   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vternlogv8si_mask, "__builtin_ia32_pternlogd256_mask", IX86_BUILTIN_VTERNLOGD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_INT_QI },
32362   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vternlogv8si_maskz, "__builtin_ia32_pternlogd256_maskz", IX86_BUILTIN_VTERNLOGD256_MASKZ, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_INT_QI },
32363   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vternlogv2di_mask, "__builtin_ia32_pternlogq128_mask", IX86_BUILTIN_VTERNLOGQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_INT_QI },
32364   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vternlogv2di_maskz, "__builtin_ia32_pternlogq128_maskz", IX86_BUILTIN_VTERNLOGQ128_MASKZ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_INT_QI },
32365   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vternlogv4si_mask, "__builtin_ia32_pternlogd128_mask", IX86_BUILTIN_VTERNLOGD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_INT_QI },
32366   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vternlogv4si_maskz, "__builtin_ia32_pternlogd128_maskz", IX86_BUILTIN_VTERNLOGD128_MASKZ, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_INT_QI },
32367   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv4df_mask, "__builtin_ia32_scalefpd256_mask", IX86_BUILTIN_SCALEFPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32368   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv8sf_mask, "__builtin_ia32_scalefps256_mask", IX86_BUILTIN_SCALEFPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32369   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv2df_mask, "__builtin_ia32_scalefpd128_mask", IX86_BUILTIN_SCALEFPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32370   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_scalefv4sf_mask, "__builtin_ia32_scalefps128_mask", IX86_BUILTIN_SCALEFPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32371   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v4df_mask, "__builtin_ia32_vfmaddpd256_mask", IX86_BUILTIN_VFMADDPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32372   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v4df_mask3, "__builtin_ia32_vfmaddpd256_mask3", IX86_BUILTIN_VFMADDPD256_MASK3, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32373   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v4df_maskz, "__builtin_ia32_vfmaddpd256_maskz", IX86_BUILTIN_VFMADDPD256_MASKZ, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32374   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v2df_mask, "__builtin_ia32_vfmaddpd128_mask", IX86_BUILTIN_VFMADDPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32375   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v2df_mask3, "__builtin_ia32_vfmaddpd128_mask3", IX86_BUILTIN_VFMADDPD128_MASK3, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32376   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v2df_maskz, "__builtin_ia32_vfmaddpd128_maskz", IX86_BUILTIN_VFMADDPD128_MASKZ, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32377   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v8sf_mask, "__builtin_ia32_vfmaddps256_mask", IX86_BUILTIN_VFMADDPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32378   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v8sf_mask3, "__builtin_ia32_vfmaddps256_mask3", IX86_BUILTIN_VFMADDPS256_MASK3, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32379   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v8sf_maskz, "__builtin_ia32_vfmaddps256_maskz", IX86_BUILTIN_VFMADDPS256_MASKZ, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32380   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v4sf_mask, "__builtin_ia32_vfmaddps128_mask", IX86_BUILTIN_VFMADDPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32381   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v4sf_mask3, "__builtin_ia32_vfmaddps128_mask3", IX86_BUILTIN_VFMADDPS128_MASK3, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32382   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmadd_v4sf_maskz, "__builtin_ia32_vfmaddps128_maskz", IX86_BUILTIN_VFMADDPS128_MASKZ, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32383   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmsub_v4df_mask3, "__builtin_ia32_vfmsubpd256_mask3", IX86_BUILTIN_VFMSUBPD256_MASK3, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32384   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmsub_v2df_mask3, "__builtin_ia32_vfmsubpd128_mask3", IX86_BUILTIN_VFMSUBPD128_MASK3, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32385   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmsub_v8sf_mask3, "__builtin_ia32_vfmsubps256_mask3", IX86_BUILTIN_VFMSUBPS256_MASK3, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32386   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmsub_v4sf_mask3, "__builtin_ia32_vfmsubps128_mask3", IX86_BUILTIN_VFMSUBPS128_MASK3, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32387   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmadd_v4df_mask, "__builtin_ia32_vfnmaddpd256_mask", IX86_BUILTIN_VFNMADDPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32388   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmadd_v2df_mask, "__builtin_ia32_vfnmaddpd128_mask", IX86_BUILTIN_VFNMADDPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32389   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmadd_v8sf_mask, "__builtin_ia32_vfnmaddps256_mask", IX86_BUILTIN_VFNMADDPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32390   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmadd_v4sf_mask, "__builtin_ia32_vfnmaddps128_mask", IX86_BUILTIN_VFNMADDPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32391   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmsub_v4df_mask, "__builtin_ia32_vfnmsubpd256_mask", IX86_BUILTIN_VFNMSUBPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32392   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmsub_v4df_mask3, "__builtin_ia32_vfnmsubpd256_mask3", IX86_BUILTIN_VFNMSUBPD256_MASK3, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32393   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmsub_v2df_mask, "__builtin_ia32_vfnmsubpd128_mask", IX86_BUILTIN_VFNMSUBPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32394   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmsub_v2df_mask3, "__builtin_ia32_vfnmsubpd128_mask3", IX86_BUILTIN_VFNMSUBPD128_MASK3, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32395   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmsub_v8sf_mask, "__builtin_ia32_vfnmsubps256_mask", IX86_BUILTIN_VFNMSUBPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32396   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmsub_v8sf_mask3, "__builtin_ia32_vfnmsubps256_mask3", IX86_BUILTIN_VFNMSUBPS256_MASK3, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32397   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmsub_v4sf_mask, "__builtin_ia32_vfnmsubps128_mask", IX86_BUILTIN_VFNMSUBPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32398   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fnmsub_v4sf_mask3, "__builtin_ia32_vfnmsubps128_mask3", IX86_BUILTIN_VFNMSUBPS128_MASK3, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32399   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v4df_mask, "__builtin_ia32_vfmaddsubpd256_mask", IX86_BUILTIN_VFMADDSUBPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32400   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v4df_mask3, "__builtin_ia32_vfmaddsubpd256_mask3", IX86_BUILTIN_VFMADDSUBPD256_MASK3, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32401   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v4df_maskz, "__builtin_ia32_vfmaddsubpd256_maskz", IX86_BUILTIN_VFMADDSUBPD256_MASKZ, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32402   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v2df_mask, "__builtin_ia32_vfmaddsubpd128_mask", IX86_BUILTIN_VFMADDSUBPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32403   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v2df_mask3, "__builtin_ia32_vfmaddsubpd128_mask3", IX86_BUILTIN_VFMADDSUBPD128_MASK3, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32404   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v2df_maskz, "__builtin_ia32_vfmaddsubpd128_maskz", IX86_BUILTIN_VFMADDSUBPD128_MASKZ, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32405   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v8sf_mask, "__builtin_ia32_vfmaddsubps256_mask", IX86_BUILTIN_VFMADDSUBPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32406   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v8sf_mask3, "__builtin_ia32_vfmaddsubps256_mask3", IX86_BUILTIN_VFMADDSUBPS256_MASK3, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32407   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v8sf_maskz, "__builtin_ia32_vfmaddsubps256_maskz", IX86_BUILTIN_VFMADDSUBPS256_MASKZ, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32408   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v4sf_mask, "__builtin_ia32_vfmaddsubps128_mask", IX86_BUILTIN_VFMADDSUBPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32409   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v4sf_mask3, "__builtin_ia32_vfmaddsubps128_mask3", IX86_BUILTIN_VFMADDSUBPS128_MASK3, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32410   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmaddsub_v4sf_maskz, "__builtin_ia32_vfmaddsubps128_maskz", IX86_BUILTIN_VFMADDSUBPS128_MASKZ, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32411   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmsubadd_v4df_mask3, "__builtin_ia32_vfmsubaddpd256_mask3", IX86_BUILTIN_VFMSUBADDPD256_MASK3, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32412   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmsubadd_v2df_mask3, "__builtin_ia32_vfmsubaddpd128_mask3", IX86_BUILTIN_VFMSUBADDPD128_MASK3, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32413   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmsubadd_v8sf_mask3, "__builtin_ia32_vfmsubaddps256_mask3", IX86_BUILTIN_VFMSUBADDPS256_MASK3, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32414   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_fmsubadd_v4sf_mask3, "__builtin_ia32_vfmsubaddps128_mask3", IX86_BUILTIN_VFMSUBADDPS128_MASK3, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32415   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vinsertv4df, "__builtin_ia32_insertf64x2_256_mask", IX86_BUILTIN_INSERTF64X2_256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V2DF_INT_V4DF_QI },
32416   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vinsertv4di, "__builtin_ia32_inserti64x2_256_mask", IX86_BUILTIN_INSERTI64X2_256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V2DI_INT_V4DI_QI },
32417   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ashrvv16hi_mask, "__builtin_ia32_psrav16hi_mask", IX86_BUILTIN_PSRAVV16HI, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32418   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ashrvv8hi_mask, "__builtin_ia32_psrav8hi_mask", IX86_BUILTIN_PSRAVV8HI, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32419   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512bw_pmaddubsw512v16hi_mask, "__builtin_ia32_pmaddubsw256_mask", IX86_BUILTIN_PMADDUBSW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V32QI_V32QI_V16HI_HI },
32420   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512bw_pmaddubsw512v8hi_mask, "__builtin_ia32_pmaddubsw128_mask", IX86_BUILTIN_PMADDUBSW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V16QI_V16QI_V8HI_QI },
32421   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512bw_pmaddwd512v16hi_mask, "__builtin_ia32_pmaddwd256_mask", IX86_BUILTIN_PMADDWD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V16HI_V16HI_V8SI_QI },
32422   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512bw_pmaddwd512v8hi_mask, "__builtin_ia32_pmaddwd128_mask", IX86_BUILTIN_PMADDWD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V8HI_V8HI_V4SI_QI },
32423   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_lshrvv16hi_mask, "__builtin_ia32_psrlv16hi_mask", IX86_BUILTIN_PSRLVV16HI, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32424   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_lshrvv8hi_mask, "__builtin_ia32_psrlv8hi_mask", IX86_BUILTIN_PSRLVV8HI, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32425   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_fix_notruncv8sfv8si_mask, "__builtin_ia32_cvtps2dq256_mask", IX86_BUILTIN_CVTPS2DQ256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32426   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_fix_notruncv4sfv4si_mask, "__builtin_ia32_cvtps2dq128_mask", IX86_BUILTIN_CVTPS2DQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32427   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ufix_notruncv8sfv8si_mask, "__builtin_ia32_cvtps2udq256_mask", IX86_BUILTIN_CVTPS2UDQ256, UNKNOWN, (int) V8SI_FTYPE_V8SF_V8SI_QI },
32428   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ufix_notruncv4sfv4si_mask, "__builtin_ia32_cvtps2udq128_mask", IX86_BUILTIN_CVTPS2UDQ128, UNKNOWN, (int) V4SI_FTYPE_V4SF_V4SI_QI },
32429   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_cvtps2qqv4di_mask, "__builtin_ia32_cvtps2qq256_mask", IX86_BUILTIN_CVTPS2QQ256, UNKNOWN, (int) V4DI_FTYPE_V4SF_V4DI_QI },
32430   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_cvtps2qqv2di_mask, "__builtin_ia32_cvtps2qq128_mask", IX86_BUILTIN_CVTPS2QQ128, UNKNOWN, (int) V2DI_FTYPE_V4SF_V2DI_QI },
32431   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_cvtps2uqqv4di_mask, "__builtin_ia32_cvtps2uqq256_mask", IX86_BUILTIN_CVTPS2UQQ256, UNKNOWN, (int) V4DI_FTYPE_V4SF_V4DI_QI },
32432   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_cvtps2uqqv2di_mask, "__builtin_ia32_cvtps2uqq128_mask", IX86_BUILTIN_CVTPS2UQQ128, UNKNOWN, (int) V2DI_FTYPE_V4SF_V2DI_QI },
32433   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv8sf_mask, "__builtin_ia32_getmantps256_mask", IX86_BUILTIN_GETMANTPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT_V8SF_QI },
32434   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv4sf_mask, "__builtin_ia32_getmantps128_mask", IX86_BUILTIN_GETMANTPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT_V4SF_QI },
32435   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv4df_mask, "__builtin_ia32_getmantpd256_mask", IX86_BUILTIN_GETMANTPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT_V4DF_QI },
32436   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_getmantv2df_mask, "__builtin_ia32_getmantpd128_mask", IX86_BUILTIN_GETMANTPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT_V2DF_QI },
32437   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_movddup256_mask, "__builtin_ia32_movddup256_mask", IX86_BUILTIN_MOVDDUP256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32438   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_dupv2df_mask, "__builtin_ia32_movddup128_mask", IX86_BUILTIN_MOVDDUP128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32439   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_movshdup256_mask, "__builtin_ia32_movshdup256_mask", IX86_BUILTIN_MOVSHDUP256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32440   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse3_movshdup_mask, "__builtin_ia32_movshdup128_mask", IX86_BUILTIN_MOVSHDUP128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32441   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_movsldup256_mask, "__builtin_ia32_movsldup256_mask", IX86_BUILTIN_MOVSLDUP256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32442   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse3_movsldup_mask, "__builtin_ia32_movsldup128_mask", IX86_BUILTIN_MOVSLDUP128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32443   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv4div4sf2_mask, "__builtin_ia32_cvtqq2ps256_mask", IX86_BUILTIN_CVTQQ2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DI_V4SF_QI },
32444   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv2div2sf2_mask, "__builtin_ia32_cvtqq2ps128_mask", IX86_BUILTIN_CVTQQ2PS128, UNKNOWN, (int) V4SF_FTYPE_V2DI_V4SF_QI },
32445   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv4div4sf2_mask, "__builtin_ia32_cvtuqq2ps256_mask", IX86_BUILTIN_CVTUQQ2PS256, UNKNOWN, (int) V4SF_FTYPE_V4DI_V4SF_QI },
32446   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv2div2sf2_mask, "__builtin_ia32_cvtuqq2ps128_mask", IX86_BUILTIN_CVTUQQ2PS128, UNKNOWN, (int) V4SF_FTYPE_V2DI_V4SF_QI },
32447   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv4div4df2_mask, "__builtin_ia32_cvtqq2pd256_mask", IX86_BUILTIN_CVTQQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4DI_V4DF_QI },
32448   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_floatv2div2df2_mask, "__builtin_ia32_cvtqq2pd128_mask", IX86_BUILTIN_CVTQQ2PD128, UNKNOWN, (int) V2DF_FTYPE_V2DI_V2DF_QI },
32449   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv4div4df2_mask, "__builtin_ia32_cvtuqq2pd256_mask", IX86_BUILTIN_CVTUQQ2PD256, UNKNOWN, (int) V4DF_FTYPE_V4DI_V4DF_QI },
32450   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ufloatv2div2df2_mask, "__builtin_ia32_cvtuqq2pd128_mask", IX86_BUILTIN_CVTUQQ2PD128, UNKNOWN, (int) V2DF_FTYPE_V2DI_V2DF_QI },
32451   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4di3_mask, "__builtin_ia32_vpermt2varq256_mask", IX86_BUILTIN_VPERMT2VARQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32452   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4di3_maskz, "__builtin_ia32_vpermt2varq256_maskz", IX86_BUILTIN_VPERMT2VARQ256_MASKZ, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32453   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8si3_mask, "__builtin_ia32_vpermt2vard256_mask", IX86_BUILTIN_VPERMT2VARD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32454   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8si3_maskz, "__builtin_ia32_vpermt2vard256_maskz", IX86_BUILTIN_VPERMT2VARD256_MASKZ, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32455   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4di3_mask, "__builtin_ia32_vpermi2varq256_mask", IX86_BUILTIN_VPERMI2VARQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32456   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv8si3_mask, "__builtin_ia32_vpermi2vard256_mask", IX86_BUILTIN_VPERMI2VARD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32457   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4df3_mask, "__builtin_ia32_vpermt2varpd256_mask", IX86_BUILTIN_VPERMT2VARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DI_V4DF_V4DF_QI },
32458   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4df3_maskz, "__builtin_ia32_vpermt2varpd256_maskz", IX86_BUILTIN_VPERMT2VARPD256_MASKZ, UNKNOWN, (int) V4DF_FTYPE_V4DI_V4DF_V4DF_QI },
32459   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8sf3_mask, "__builtin_ia32_vpermt2varps256_mask", IX86_BUILTIN_VPERMT2VARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_V8SF_QI },
32460   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv8sf3_maskz, "__builtin_ia32_vpermt2varps256_maskz", IX86_BUILTIN_VPERMT2VARPS256_MASKZ, UNKNOWN, (int) V8SF_FTYPE_V8SI_V8SF_V8SF_QI },
32461   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4df3_mask, "__builtin_ia32_vpermi2varpd256_mask", IX86_BUILTIN_VPERMI2VARPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI_V4DF_QI },
32462   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv8sf3_mask, "__builtin_ia32_vpermi2varps256_mask", IX86_BUILTIN_VPERMI2VARPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI_V8SF_QI },
32463   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv2di3_mask, "__builtin_ia32_vpermt2varq128_mask", IX86_BUILTIN_VPERMT2VARQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32464   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv2di3_maskz, "__builtin_ia32_vpermt2varq128_maskz", IX86_BUILTIN_VPERMT2VARQ128_MASKZ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32465   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4si3_mask, "__builtin_ia32_vpermt2vard128_mask", IX86_BUILTIN_VPERMT2VARD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32466   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4si3_maskz, "__builtin_ia32_vpermt2vard128_maskz", IX86_BUILTIN_VPERMT2VARD128_MASKZ, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32467   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv2di3_mask, "__builtin_ia32_vpermi2varq128_mask", IX86_BUILTIN_VPERMI2VARQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32468   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4si3_mask, "__builtin_ia32_vpermi2vard128_mask", IX86_BUILTIN_VPERMI2VARD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32469   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv2df3_mask, "__builtin_ia32_vpermt2varpd128_mask", IX86_BUILTIN_VPERMT2VARPD128, UNKNOWN, (int) V2DF_FTYPE_V2DI_V2DF_V2DF_QI },
32470   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv2df3_maskz, "__builtin_ia32_vpermt2varpd128_maskz", IX86_BUILTIN_VPERMT2VARPD128_MASKZ, UNKNOWN, (int) V2DF_FTYPE_V2DI_V2DF_V2DF_QI },
32471   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4sf3_mask, "__builtin_ia32_vpermt2varps128_mask", IX86_BUILTIN_VPERMT2VARPS128, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_V4SF_QI },
32472   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv4sf3_maskz, "__builtin_ia32_vpermt2varps128_maskz", IX86_BUILTIN_VPERMT2VARPS128_MASKZ, UNKNOWN, (int) V4SF_FTYPE_V4SI_V4SF_V4SF_QI },
32473   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv2df3_mask, "__builtin_ia32_vpermi2varpd128_mask", IX86_BUILTIN_VPERMI2VARPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI_V2DF_QI },
32474   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv4sf3_mask, "__builtin_ia32_vpermi2varps128_mask", IX86_BUILTIN_VPERMI2VARPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI_V4SF_QI },
32475   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_pshufbv32qi3_mask, "__builtin_ia32_pshufb256_mask", IX86_BUILTIN_PSHUFB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32476   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ssse3_pshufbv16qi3_mask, "__builtin_ia32_pshufb128_mask", IX86_BUILTIN_PSHUFB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32477   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_pshufhwv3_mask, "__builtin_ia32_pshufhw256_mask", IX86_BUILTIN_PSHUFHW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT_V16HI_HI },
32478   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_pshufhw_mask, "__builtin_ia32_pshufhw128_mask", IX86_BUILTIN_PSHUFHW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT_V8HI_QI },
32479   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_pshuflwv3_mask, "__builtin_ia32_pshuflw256_mask", IX86_BUILTIN_PSHUFLW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT_V16HI_HI },
32480   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_pshuflw_mask, "__builtin_ia32_pshuflw128_mask", IX86_BUILTIN_PSHUFLW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT_V8HI_QI },
32481   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_pshufdv3_mask, "__builtin_ia32_pshufd256_mask", IX86_BUILTIN_PSHUFD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32482   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_pshufd_mask, "__builtin_ia32_pshufd128_mask", IX86_BUILTIN_PSHUFD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32483   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_shufpd256_mask, "__builtin_ia32_shufpd256_mask", IX86_BUILTIN_SHUFPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_INT_V4DF_QI },
32484   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_shufpd_mask, "__builtin_ia32_shufpd128_mask", IX86_BUILTIN_SHUFPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_V2DF_QI },
32485   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_shufps256_mask, "__builtin_ia32_shufps256_mask", IX86_BUILTIN_SHUFPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_INT_V8SF_QI },
32486   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse_shufps_mask, "__builtin_ia32_shufps128_mask", IX86_BUILTIN_SHUFPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_V4SF_QI },
32487   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv4di_mask, "__builtin_ia32_prolvq256_mask", IX86_BUILTIN_PROLVQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32488   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv2di_mask, "__builtin_ia32_prolvq128_mask", IX86_BUILTIN_PROLVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32489   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv4di_mask, "__builtin_ia32_prolq256_mask", IX86_BUILTIN_PROLQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32490   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv2di_mask, "__builtin_ia32_prolq128_mask", IX86_BUILTIN_PROLQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32491   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv4di_mask, "__builtin_ia32_prorvq256_mask", IX86_BUILTIN_PRORVQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32492   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv2di_mask, "__builtin_ia32_prorvq128_mask", IX86_BUILTIN_PRORVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32493   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv4di_mask, "__builtin_ia32_prorq256_mask", IX86_BUILTIN_PRORQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32494   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv2di_mask, "__builtin_ia32_prorq128_mask", IX86_BUILTIN_PRORQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_INT_V2DI_QI },
32495   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashrvv2di_mask, "__builtin_ia32_psravq128_mask", IX86_BUILTIN_PSRAVQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32496   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashrvv4di_mask, "__builtin_ia32_psravq256_mask", IX86_BUILTIN_PSRAVQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32497   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashlvv4di_mask, "__builtin_ia32_psllv4di_mask", IX86_BUILTIN_PSLLVV4DI_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32498   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashlvv2di_mask, "__builtin_ia32_psllv2di_mask", IX86_BUILTIN_PSLLVV2DI_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32499   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashlvv8si_mask, "__builtin_ia32_psllv8si_mask", IX86_BUILTIN_PSLLVV8SI_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32500   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashlvv4si_mask, "__builtin_ia32_psllv4si_mask", IX86_BUILTIN_PSLLVV4SI_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32501   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashrvv8si_mask, "__builtin_ia32_psrav8si_mask", IX86_BUILTIN_PSRAVV8SI_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32502   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_ashrvv4si_mask, "__builtin_ia32_psrav4si_mask", IX86_BUILTIN_PSRAVV4SI_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32503   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_lshrvv4di_mask, "__builtin_ia32_psrlv4di_mask", IX86_BUILTIN_PSRLVV4DI_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32504   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_lshrvv2di_mask, "__builtin_ia32_psrlv2di_mask", IX86_BUILTIN_PSRLVV2DI_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32505   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_lshrvv8si_mask, "__builtin_ia32_psrlv8si_mask", IX86_BUILTIN_PSRLVV8SI_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32506   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_lshrvv4si_mask, "__builtin_ia32_psrlv4si_mask", IX86_BUILTIN_PSRLVV4SI_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32507   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv16hi3_mask, "__builtin_ia32_psrawi256_mask", IX86_BUILTIN_PSRAWI256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT_V16HI_HI },
32508   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv16hi3_mask, "__builtin_ia32_psraw256_mask", IX86_BUILTIN_PSRAW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_V16HI_HI },
32509   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv8hi3_mask, "__builtin_ia32_psrawi128_mask", IX86_BUILTIN_PSRAWI128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT_V8HI_QI },
32510   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_ashrv8hi3_mask, "__builtin_ia32_psraw128_mask", IX86_BUILTIN_PSRAW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32511   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv16hi3_mask, "__builtin_ia32_psrlwi256_mask", IX86_BUILTIN_PSRLWI256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_INT_V16HI_HI },
32512   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv16hi3_mask, "__builtin_ia32_psrlw256_mask", IX86_BUILTIN_PSRLW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V8HI_V16HI_HI },
32513   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv8hi3_mask, "__builtin_ia32_psrlwi128_mask", IX86_BUILTIN_PSRLWI128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_INT_V8HI_QI },
32514   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_lshrv8hi3_mask, "__builtin_ia32_psrlw128_mask", IX86_BUILTIN_PSRLW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32515   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv8si_mask, "__builtin_ia32_prorvd256_mask", IX86_BUILTIN_PRORVD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32516   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv8si_mask, "__builtin_ia32_prolvd256_mask", IX86_BUILTIN_PROLVD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32517   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv8si_mask, "__builtin_ia32_prord256_mask", IX86_BUILTIN_PRORD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32518   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv8si_mask, "__builtin_ia32_prold256_mask", IX86_BUILTIN_PROLD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_INT_V8SI_QI },
32519   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorvv4si_mask, "__builtin_ia32_prorvd128_mask", IX86_BUILTIN_PRORVD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32520   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolvv4si_mask, "__builtin_ia32_prolvd128_mask", IX86_BUILTIN_PROLVD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32521   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rorv4si_mask, "__builtin_ia32_prord128_mask", IX86_BUILTIN_PRORD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32522   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_rolv4si_mask, "__builtin_ia32_prold128_mask", IX86_BUILTIN_PROLD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_INT_V4SI_QI },
32523   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_fpclassv4df_mask, "__builtin_ia32_fpclasspd256_mask", IX86_BUILTIN_FPCLASSPD256, UNKNOWN, (int) QI_FTYPE_V4DF_INT_QI },
32524   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_fpclassv2df_mask, "__builtin_ia32_fpclasspd128_mask", IX86_BUILTIN_FPCLASSPD128, UNKNOWN, (int) QI_FTYPE_V2DF_INT_QI },
32525   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vmfpclassv2df, "__builtin_ia32_fpclasssd", IX86_BUILTIN_FPCLASSSD, UNKNOWN, (int) QI_FTYPE_V2DF_INT },
32526   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_fpclassv8sf_mask, "__builtin_ia32_fpclassps256_mask", IX86_BUILTIN_FPCLASSPS256, UNKNOWN, (int) QI_FTYPE_V8SF_INT_QI },
32527   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512dq_fpclassv4sf_mask, "__builtin_ia32_fpclassps128_mask", IX86_BUILTIN_FPCLASSPS128, UNKNOWN, (int) QI_FTYPE_V4SF_INT_QI },
32528   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vmfpclassv4sf, "__builtin_ia32_fpclassss", IX86_BUILTIN_FPCLASSSS, UNKNOWN, (int) QI_FTYPE_V4SF_INT },
32529   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtb2maskv16qi, "__builtin_ia32_cvtb2mask128", IX86_BUILTIN_CVTB2MASK128, UNKNOWN, (int) HI_FTYPE_V16QI },
32530   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtb2maskv32qi, "__builtin_ia32_cvtb2mask256", IX86_BUILTIN_CVTB2MASK256, UNKNOWN, (int) SI_FTYPE_V32QI },
32531   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtw2maskv8hi, "__builtin_ia32_cvtw2mask128", IX86_BUILTIN_CVTW2MASK128, UNKNOWN, (int) QI_FTYPE_V8HI },
32532   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtw2maskv16hi, "__builtin_ia32_cvtw2mask256", IX86_BUILTIN_CVTW2MASK256, UNKNOWN, (int) HI_FTYPE_V16HI },
32533   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtd2maskv4si, "__builtin_ia32_cvtd2mask128", IX86_BUILTIN_CVTD2MASK128, UNKNOWN, (int) QI_FTYPE_V4SI },
32534   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtd2maskv8si, "__builtin_ia32_cvtd2mask256", IX86_BUILTIN_CVTD2MASK256, UNKNOWN, (int) QI_FTYPE_V8SI },
32535   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtq2maskv2di, "__builtin_ia32_cvtq2mask128", IX86_BUILTIN_CVTQ2MASK128, UNKNOWN, (int) QI_FTYPE_V2DI },
32536   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtq2maskv4di, "__builtin_ia32_cvtq2mask256", IX86_BUILTIN_CVTQ2MASK256, UNKNOWN, (int) QI_FTYPE_V4DI },
32537   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2bv16qi, "__builtin_ia32_cvtmask2b128", IX86_BUILTIN_CVTMASK2B128, UNKNOWN, (int) V16QI_FTYPE_HI },
32538   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2bv32qi, "__builtin_ia32_cvtmask2b256", IX86_BUILTIN_CVTMASK2B256, UNKNOWN, (int) V32QI_FTYPE_SI },
32539   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2wv8hi, "__builtin_ia32_cvtmask2w128", IX86_BUILTIN_CVTMASK2W128, UNKNOWN, (int) V8HI_FTYPE_QI },
32540   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2wv16hi, "__builtin_ia32_cvtmask2w256", IX86_BUILTIN_CVTMASK2W256, UNKNOWN, (int) V16HI_FTYPE_HI },
32541   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2dv4si, "__builtin_ia32_cvtmask2d128", IX86_BUILTIN_CVTMASK2D128, UNKNOWN, (int) V4SI_FTYPE_QI },
32542   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2dv8si, "__builtin_ia32_cvtmask2d256", IX86_BUILTIN_CVTMASK2D256, UNKNOWN, (int) V8SI_FTYPE_QI },
32543   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2qv2di, "__builtin_ia32_cvtmask2q128", IX86_BUILTIN_CVTMASK2Q128, UNKNOWN, (int) V2DI_FTYPE_QI },
32544   { OPTION_MASK_ISA_AVX512DQ | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cvtmask2qv4di, "__builtin_ia32_cvtmask2q256", IX86_BUILTIN_CVTMASK2Q256, UNKNOWN, (int) V4DI_FTYPE_QI },
32545   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv16qi3_mask, "__builtin_ia32_pcmpeqb128_mask", IX86_BUILTIN_PCMPEQB128_MASK, UNKNOWN, (int) HI_FTYPE_V16QI_V16QI_HI },
32546   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv32qi3_mask, "__builtin_ia32_pcmpeqb256_mask", IX86_BUILTIN_PCMPEQB256_MASK, UNKNOWN, (int) SI_FTYPE_V32QI_V32QI_SI },
32547   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv8hi3_mask, "__builtin_ia32_pcmpeqw128_mask", IX86_BUILTIN_PCMPEQW128_MASK, UNKNOWN, (int) QI_FTYPE_V8HI_V8HI_QI },
32548   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv16hi3_mask, "__builtin_ia32_pcmpeqw256_mask", IX86_BUILTIN_PCMPEQW256_MASK, UNKNOWN, (int) HI_FTYPE_V16HI_V16HI_HI },
32549   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv4si3_mask, "__builtin_ia32_pcmpeqd128_mask", IX86_BUILTIN_PCMPEQD128_MASK, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32550   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv8si3_mask, "__builtin_ia32_pcmpeqd256_mask", IX86_BUILTIN_PCMPEQD256_MASK, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32551   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv2di3_mask, "__builtin_ia32_pcmpeqq128_mask", IX86_BUILTIN_PCMPEQQ128_MASK, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32552   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_eqv4di3_mask, "__builtin_ia32_pcmpeqq256_mask", IX86_BUILTIN_PCMPEQQ256_MASK, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32553   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv16qi3_mask, "__builtin_ia32_pcmpgtb128_mask", IX86_BUILTIN_PCMPGTB128_MASK, UNKNOWN, (int) HI_FTYPE_V16QI_V16QI_HI },
32554   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv32qi3_mask, "__builtin_ia32_pcmpgtb256_mask", IX86_BUILTIN_PCMPGTB256_MASK, UNKNOWN, (int) SI_FTYPE_V32QI_V32QI_SI },
32555   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv8hi3_mask, "__builtin_ia32_pcmpgtw128_mask", IX86_BUILTIN_PCMPGTW128_MASK, UNKNOWN, (int) QI_FTYPE_V8HI_V8HI_QI },
32556   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv16hi3_mask, "__builtin_ia32_pcmpgtw256_mask", IX86_BUILTIN_PCMPGTW256_MASK, UNKNOWN, (int) HI_FTYPE_V16HI_V16HI_HI },
32557   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv4si3_mask, "__builtin_ia32_pcmpgtd128_mask", IX86_BUILTIN_PCMPGTD128_MASK, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32558   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv8si3_mask, "__builtin_ia32_pcmpgtd256_mask", IX86_BUILTIN_PCMPGTD256_MASK, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32559   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv2di3_mask, "__builtin_ia32_pcmpgtq128_mask", IX86_BUILTIN_PCMPGTQ128_MASK, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32560   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_gtv4di3_mask, "__builtin_ia32_pcmpgtq256_mask", IX86_BUILTIN_PCMPGTQ256_MASK, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32561   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv16qi3_mask, "__builtin_ia32_ptestmb128", IX86_BUILTIN_PTESTMB128, UNKNOWN, (int) HI_FTYPE_V16QI_V16QI_HI },
32562   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv32qi3_mask, "__builtin_ia32_ptestmb256", IX86_BUILTIN_PTESTMB256, UNKNOWN, (int) SI_FTYPE_V32QI_V32QI_SI },
32563   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv8hi3_mask, "__builtin_ia32_ptestmw128", IX86_BUILTIN_PTESTMW128, UNKNOWN, (int) QI_FTYPE_V8HI_V8HI_QI },
32564   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv16hi3_mask, "__builtin_ia32_ptestmw256", IX86_BUILTIN_PTESTMW256, UNKNOWN, (int) HI_FTYPE_V16HI_V16HI_HI },
32565   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv4si3_mask, "__builtin_ia32_ptestmd128", IX86_BUILTIN_PTESTMD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32566   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv8si3_mask, "__builtin_ia32_ptestmd256", IX86_BUILTIN_PTESTMD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32567   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv2di3_mask, "__builtin_ia32_ptestmq128", IX86_BUILTIN_PTESTMQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32568   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testmv4di3_mask, "__builtin_ia32_ptestmq256", IX86_BUILTIN_PTESTMQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32569   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv16qi3_mask, "__builtin_ia32_ptestnmb128", IX86_BUILTIN_PTESTNMB128, UNKNOWN, (int) HI_FTYPE_V16QI_V16QI_HI },
32570   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv32qi3_mask, "__builtin_ia32_ptestnmb256", IX86_BUILTIN_PTESTNMB256, UNKNOWN, (int) SI_FTYPE_V32QI_V32QI_SI },
32571   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv8hi3_mask, "__builtin_ia32_ptestnmw128", IX86_BUILTIN_PTESTNMW128, UNKNOWN, (int) QI_FTYPE_V8HI_V8HI_QI },
32572   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv16hi3_mask, "__builtin_ia32_ptestnmw256", IX86_BUILTIN_PTESTNMW256, UNKNOWN, (int) HI_FTYPE_V16HI_V16HI_HI },
32573   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv4si3_mask, "__builtin_ia32_ptestnmd128", IX86_BUILTIN_PTESTNMD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_QI },
32574   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv8si3_mask, "__builtin_ia32_ptestnmd256", IX86_BUILTIN_PTESTNMD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_QI },
32575   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv2di3_mask, "__builtin_ia32_ptestnmq128", IX86_BUILTIN_PTESTNMQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_QI },
32576   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_testnmv4di3_mask, "__builtin_ia32_ptestnmq256", IX86_BUILTIN_PTESTNMQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_QI },
32577   { OPTION_MASK_ISA_AVX512VL | OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskb_vec_dupv2di, "__builtin_ia32_broadcastmb128", IX86_BUILTIN_PBROADCASTMB128, UNKNOWN, (int) V2DI_FTYPE_QI },
32578   { OPTION_MASK_ISA_AVX512VL | OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskb_vec_dupv4di, "__builtin_ia32_broadcastmb256", IX86_BUILTIN_PBROADCASTMB256, UNKNOWN, (int) V4DI_FTYPE_QI },
32579   { OPTION_MASK_ISA_AVX512VL | OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskw_vec_dupv4si, "__builtin_ia32_broadcastmw128", IX86_BUILTIN_PBROADCASTMW128, UNKNOWN, (int) V4SI_FTYPE_HI },
32580   { OPTION_MASK_ISA_AVX512VL | OPTION_MASK_ISA_AVX512CD, CODE_FOR_avx512cd_maskw_vec_dupv8si, "__builtin_ia32_broadcastmw256", IX86_BUILTIN_PBROADCASTMW256, UNKNOWN, (int) V8SI_FTYPE_HI },
32581   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4df_mask, "__builtin_ia32_compressdf256_mask", IX86_BUILTIN_COMPRESSPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32582   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv2df_mask, "__builtin_ia32_compressdf128_mask", IX86_BUILTIN_COMPRESSPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32583   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv8sf_mask, "__builtin_ia32_compresssf256_mask", IX86_BUILTIN_COMPRESSPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32584   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4sf_mask, "__builtin_ia32_compresssf128_mask", IX86_BUILTIN_COMPRESSPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32585   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4di_mask, "__builtin_ia32_compressdi256_mask", IX86_BUILTIN_PCOMPRESSQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32586   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv2di_mask, "__builtin_ia32_compressdi128_mask", IX86_BUILTIN_PCOMPRESSQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32587   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv8si_mask, "__builtin_ia32_compresssi256_mask", IX86_BUILTIN_PCOMPRESSD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32588   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_compressv4si_mask, "__builtin_ia32_compresssi128_mask", IX86_BUILTIN_PCOMPRESSD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32589   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_mask, "__builtin_ia32_expanddf256_mask", IX86_BUILTIN_EXPANDPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32590   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_mask, "__builtin_ia32_expanddf128_mask", IX86_BUILTIN_EXPANDPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32591   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_mask, "__builtin_ia32_expandsf256_mask", IX86_BUILTIN_EXPANDPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32592   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_mask, "__builtin_ia32_expandsf128_mask", IX86_BUILTIN_EXPANDPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32593   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_mask, "__builtin_ia32_expanddi256_mask", IX86_BUILTIN_PEXPANDQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32594   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_mask, "__builtin_ia32_expanddi128_mask", IX86_BUILTIN_PEXPANDQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32595   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_mask, "__builtin_ia32_expandsi256_mask", IX86_BUILTIN_PEXPANDD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32596   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_mask, "__builtin_ia32_expandsi128_mask", IX86_BUILTIN_PEXPANDD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32597   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4df_maskz, "__builtin_ia32_expanddf256_maskz", IX86_BUILTIN_EXPANDPD256Z, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32598   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2df_maskz, "__builtin_ia32_expanddf128_maskz", IX86_BUILTIN_EXPANDPD128Z, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32599   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8sf_maskz, "__builtin_ia32_expandsf256_maskz", IX86_BUILTIN_EXPANDPS256Z, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32600   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4sf_maskz, "__builtin_ia32_expandsf128_maskz", IX86_BUILTIN_EXPANDPS128Z, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32601   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4di_maskz, "__builtin_ia32_expanddi256_maskz", IX86_BUILTIN_PEXPANDQ256Z, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32602   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv2di_maskz, "__builtin_ia32_expanddi128_maskz", IX86_BUILTIN_PEXPANDQ128Z, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32603   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv8si_maskz, "__builtin_ia32_expandsi256_maskz", IX86_BUILTIN_PEXPANDD256Z, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32604   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_expandv4si_maskz, "__builtin_ia32_expandsi128_maskz", IX86_BUILTIN_PEXPANDD128Z, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32605   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv8si3_mask, "__builtin_ia32_pmaxsd256_mask", IX86_BUILTIN_PMAXSD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32606   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv8si3_mask, "__builtin_ia32_pminsd256_mask", IX86_BUILTIN_PMINSD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32607   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv8si3_mask, "__builtin_ia32_pmaxud256_mask", IX86_BUILTIN_PMAXUD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32608   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv8si3_mask, "__builtin_ia32_pminud256_mask", IX86_BUILTIN_PMINUD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32609   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4si3_mask, "__builtin_ia32_pmaxsd128_mask", IX86_BUILTIN_PMAXSD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32610   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4si3_mask, "__builtin_ia32_pminsd128_mask", IX86_BUILTIN_PMINSD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32611   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv4si3_mask, "__builtin_ia32_pmaxud128_mask", IX86_BUILTIN_PMAXUD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32612   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv4si3_mask, "__builtin_ia32_pminud128_mask", IX86_BUILTIN_PMINUD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32613   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv4di3_mask, "__builtin_ia32_pmaxsq256_mask", IX86_BUILTIN_PMAXSQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32614   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv4di3_mask, "__builtin_ia32_pminsq256_mask", IX86_BUILTIN_PMINSQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32615   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv4di3_mask, "__builtin_ia32_pmaxuq256_mask", IX86_BUILTIN_PMAXUQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32616   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv4di3_mask, "__builtin_ia32_pminuq256_mask", IX86_BUILTIN_PMINUQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32617   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv2di3_mask, "__builtin_ia32_pmaxsq128_mask", IX86_BUILTIN_PMAXSQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32618   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv2di3_mask, "__builtin_ia32_pminsq128_mask", IX86_BUILTIN_PMINSQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32619   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv2di3_mask, "__builtin_ia32_pmaxuq128_mask", IX86_BUILTIN_PMAXUQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32620   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv2di3_mask, "__builtin_ia32_pminuq128_mask", IX86_BUILTIN_PMINUQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32621   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv32qi3_mask, "__builtin_ia32_pminsb256_mask", IX86_BUILTIN_PMINSB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32622   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv32qi3_mask, "__builtin_ia32_pminub256_mask", IX86_BUILTIN_PMINUB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32623   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv32qi3_mask, "__builtin_ia32_pmaxsb256_mask", IX86_BUILTIN_PMAXSB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32624   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv32qi3_mask, "__builtin_ia32_pmaxub256_mask", IX86_BUILTIN_PMAXUB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32625   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv16qi3_mask, "__builtin_ia32_pminsb128_mask", IX86_BUILTIN_PMINSB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32626   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv16qi3_mask, "__builtin_ia32_pminub128_mask", IX86_BUILTIN_PMINUB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32627   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv16qi3_mask, "__builtin_ia32_pmaxsb128_mask", IX86_BUILTIN_PMAXSB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32628   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv16qi3_mask, "__builtin_ia32_pmaxub128_mask", IX86_BUILTIN_PMAXUB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32629   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv16hi3_mask, "__builtin_ia32_pminsw256_mask", IX86_BUILTIN_PMINSW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32630   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv16hi3_mask, "__builtin_ia32_pminuw256_mask", IX86_BUILTIN_PMINUW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32631   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv16hi3_mask, "__builtin_ia32_pmaxsw256_mask", IX86_BUILTIN_PMAXSW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32632   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv16hi3_mask, "__builtin_ia32_pmaxuw256_mask", IX86_BUILTIN_PMAXUW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32633   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sminv8hi3_mask, "__builtin_ia32_pminsw128_mask", IX86_BUILTIN_PMINSW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32634   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_uminv8hi3_mask, "__builtin_ia32_pminuw128_mask", IX86_BUILTIN_PMINUW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32635   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_smaxv8hi3_mask, "__builtin_ia32_pmaxsw128_mask", IX86_BUILTIN_PMAXSW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32636   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_umaxv8hi3_mask, "__builtin_ia32_pmaxuw128_mask", IX86_BUILTIN_PMAXUW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32637   { OPTION_MASK_ISA_AVX512CD | OPTION_MASK_ISA_AVX512VL, CODE_FOR_conflictv4di_mask, "__builtin_ia32_vpconflictdi_256_mask", IX86_BUILTIN_VPCONFLICTQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32638   { OPTION_MASK_ISA_AVX512CD | OPTION_MASK_ISA_AVX512VL, CODE_FOR_conflictv8si_mask, "__builtin_ia32_vpconflictsi_256_mask", IX86_BUILTIN_VPCONFLICTD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32639   { OPTION_MASK_ISA_AVX512CD | OPTION_MASK_ISA_AVX512VL, CODE_FOR_clzv4di2_mask, "__builtin_ia32_vplzcntq_256_mask", IX86_BUILTIN_VPCLZCNTQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32640   { OPTION_MASK_ISA_AVX512CD | OPTION_MASK_ISA_AVX512VL, CODE_FOR_clzv8si2_mask, "__builtin_ia32_vplzcntd_256_mask", IX86_BUILTIN_VPCLZCNTD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32641   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_unpckhpd256_mask, "__builtin_ia32_unpckhpd256_mask", IX86_BUILTIN_UNPCKHPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32642   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_unpckhpd128_mask, "__builtin_ia32_unpckhpd128_mask", IX86_BUILTIN_UNPCKHPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32643   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_unpckhps256_mask, "__builtin_ia32_unpckhps256_mask", IX86_BUILTIN_UNPCKHPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32644   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_interleave_highv4sf_mask, "__builtin_ia32_unpckhps128_mask", IX86_BUILTIN_UNPCKHPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32645   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_unpcklpd256_mask, "__builtin_ia32_unpcklpd256_mask", IX86_BUILTIN_UNPCKLPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_V4DF_QI },
32646   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_unpcklpd128_mask, "__builtin_ia32_unpcklpd128_mask", IX86_BUILTIN_UNPCKLPD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_QI },
32647   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_unpcklps256_mask,  "__builtin_ia32_unpcklps256_mask", IX86_BUILTIN_UNPCKLPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_V8SF_QI },
32648   { OPTION_MASK_ISA_AVX512CD | OPTION_MASK_ISA_AVX512VL, CODE_FOR_conflictv2di_mask, "__builtin_ia32_vpconflictdi_128_mask", IX86_BUILTIN_VPCONFLICTQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32649   { OPTION_MASK_ISA_AVX512CD | OPTION_MASK_ISA_AVX512VL, CODE_FOR_conflictv4si_mask, "__builtin_ia32_vpconflictsi_128_mask", IX86_BUILTIN_VPCONFLICTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32650   { OPTION_MASK_ISA_AVX512CD | OPTION_MASK_ISA_AVX512VL, CODE_FOR_clzv2di2_mask, "__builtin_ia32_vplzcntq_128_mask", IX86_BUILTIN_VPCLZCNTQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32651   { OPTION_MASK_ISA_AVX512CD | OPTION_MASK_ISA_AVX512VL, CODE_FOR_clzv4si2_mask, "__builtin_ia32_vplzcntd_128_mask", IX86_BUILTIN_VPCLZCNTD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32652   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_unpcklps128_mask,  "__builtin_ia32_unpcklps128_mask", IX86_BUILTIN_UNPCKLPS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_QI },
32653   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_alignv8si_mask, "__builtin_ia32_alignd256_mask", IX86_BUILTIN_ALIGND256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_INT_V8SI_QI },
32654   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_alignv4di_mask, "__builtin_ia32_alignq256_mask", IX86_BUILTIN_ALIGNQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_INT_V4DI_QI },
32655   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_alignv4si_mask, "__builtin_ia32_alignd128_mask", IX86_BUILTIN_ALIGND128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_INT_V4SI_QI },
32656   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_alignv2di_mask, "__builtin_ia32_alignq128_mask", IX86_BUILTIN_ALIGNQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_INT_V2DI_QI },
32657   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtps2ph256_mask,  "__builtin_ia32_vcvtps2ph256_mask", IX86_BUILTIN_CVTPS2PH256_MASK, UNKNOWN, (int) V8HI_FTYPE_V8SF_INT_V8HI_QI },
32658   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtps2ph_mask,  "__builtin_ia32_vcvtps2ph_mask", IX86_BUILTIN_CVTPS2PH_MASK, UNKNOWN, (int) V8HI_FTYPE_V4SF_INT_V8HI_QI },
32659   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtph2ps_mask, "__builtin_ia32_vcvtph2ps_mask", IX86_BUILTIN_CVTPH2PS_MASK, UNKNOWN, (int) V4SF_FTYPE_V8HI_V4SF_QI },
32660   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vcvtph2ps256_mask, "__builtin_ia32_vcvtph2ps256_mask", IX86_BUILTIN_CVTPH2PS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8HI_V8SF_QI },
32661   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_interleave_highv4si_mask, "__builtin_ia32_punpckhdq128_mask", IX86_BUILTIN_PUNPCKHDQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32662   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_interleave_highv8si_mask, "__builtin_ia32_punpckhdq256_mask", IX86_BUILTIN_PUNPCKHDQ256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32663   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_interleave_highv2di_mask, "__builtin_ia32_punpckhqdq128_mask", IX86_BUILTIN_PUNPCKHQDQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32664   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_interleave_highv4di_mask, "__builtin_ia32_punpckhqdq256_mask", IX86_BUILTIN_PUNPCKHQDQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32665   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_interleave_lowv4si_mask, "__builtin_ia32_punpckldq128_mask", IX86_BUILTIN_PUNPCKLDQ128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32666   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_interleave_lowv8si_mask, "__builtin_ia32_punpckldq256_mask", IX86_BUILTIN_PUNPCKLDQ256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32667   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_interleave_lowv2di_mask, "__builtin_ia32_punpcklqdq128_mask", IX86_BUILTIN_PUNPCKLQDQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32668   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_interleave_lowv4di_mask, "__builtin_ia32_punpcklqdq256_mask", IX86_BUILTIN_PUNPCKLQDQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32669   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_interleave_highv16qi_mask, "__builtin_ia32_punpckhbw128_mask", IX86_BUILTIN_PUNPCKHBW128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32670   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_interleave_highv32qi_mask, "__builtin_ia32_punpckhbw256_mask", IX86_BUILTIN_PUNPCKHBW256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32671   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_interleave_highv8hi_mask, "__builtin_ia32_punpckhwd128_mask", IX86_BUILTIN_PUNPCKHWD128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32672   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_interleave_highv16hi_mask, "__builtin_ia32_punpckhwd256_mask", IX86_BUILTIN_PUNPCKHWD256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32673   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_interleave_lowv16qi_mask, "__builtin_ia32_punpcklbw128_mask", IX86_BUILTIN_PUNPCKLBW128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32674   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_interleave_lowv32qi_mask, "__builtin_ia32_punpcklbw256_mask", IX86_BUILTIN_PUNPCKLBW256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32675   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_interleave_lowv8hi_mask, "__builtin_ia32_punpcklwd128_mask", IX86_BUILTIN_PUNPCKLWD128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32676   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_interleave_lowv16hi_mask, "__builtin_ia32_punpcklwd256_mask", IX86_BUILTIN_PUNPCKLWD256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32677   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ashlvv16hi_mask, "__builtin_ia32_psllv16hi_mask", IX86_BUILTIN_PSLLVV16HI, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32678   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ashlvv8hi_mask, "__builtin_ia32_psllv8hi_mask", IX86_BUILTIN_PSLLVV8HI, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32679   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_packssdw_mask, "__builtin_ia32_packssdw256_mask",  IX86_BUILTIN_PACKSSDW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V8SI_V8SI_V16HI_HI },
32680   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_packssdw_mask, "__builtin_ia32_packssdw128_mask",  IX86_BUILTIN_PACKSSDW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI_V8HI_QI },
32681   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_packusdw_mask, "__builtin_ia32_packusdw256_mask",  IX86_BUILTIN_PACKUSDW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V8SI_V8SI_V16HI_HI },
32682   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_packusdw_mask, "__builtin_ia32_packusdw128_mask",  IX86_BUILTIN_PACKUSDW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V4SI_V4SI_V8HI_QI },
32683   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_uavgv32qi3_mask, "__builtin_ia32_pavgb256_mask", IX86_BUILTIN_PAVGB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32684   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_uavgv16hi3_mask, "__builtin_ia32_pavgw256_mask", IX86_BUILTIN_PAVGW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_V16HI_HI },
32685   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_uavgv16qi3_mask, "__builtin_ia32_pavgb128_mask", IX86_BUILTIN_PAVGB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32686   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_uavgv8hi3_mask, "__builtin_ia32_pavgw128_mask", IX86_BUILTIN_PAVGW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_V8HI_QI },
32687   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_permvarv8sf_mask, "__builtin_ia32_permvarsf256_mask", IX86_BUILTIN_VPERMVARSF256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI_V8SF_QI },
32688   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_permvarv4df_mask, "__builtin_ia32_permvardf256_mask", IX86_BUILTIN_VPERMVARDF256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI_V4DF_QI },
32689   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_permv4df_mask, "__builtin_ia32_permdf256_mask", IX86_BUILTIN_VPERMDF256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT_V4DF_QI },
32690   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv32qi2_mask, "__builtin_ia32_pabsb256_mask", IX86_BUILTIN_PABSB256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_SI },
32691   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv16qi2_mask, "__builtin_ia32_pabsb128_mask", IX86_BUILTIN_PABSB128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_HI },
32692   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv16hi2_mask, "__builtin_ia32_pabsw256_mask", IX86_BUILTIN_PABSW256_MASK, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_HI },
32693   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_absv8hi2_mask, "__builtin_ia32_pabsw128_mask", IX86_BUILTIN_PABSW128_MASK, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_QI },
32694   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_vpermilvarv2df3_mask, "__builtin_ia32_vpermilvarpd_mask", IX86_BUILTIN_VPERMILVARPD_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DI_V2DF_QI },
32695   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_vpermilvarv4sf3_mask, "__builtin_ia32_vpermilvarps_mask", IX86_BUILTIN_VPERMILVARPS_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SI_V4SF_QI },
32696   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_vpermilvarv4df3_mask, "__builtin_ia32_vpermilvarpd256_mask", IX86_BUILTIN_VPERMILVARPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DI_V4DF_QI },
32697   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_vpermilvarv8sf3_mask, "__builtin_ia32_vpermilvarps256_mask", IX86_BUILTIN_VPERMILVARPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SI_V8SF_QI },
32698   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_vpermilv2df_mask, "__builtin_ia32_vpermilpd_mask", IX86_BUILTIN_VPERMILPD_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT_V2DF_QI },
32699   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_vpermilv4sf_mask, "__builtin_ia32_vpermilps_mask", IX86_BUILTIN_VPERMILPS_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT_V4SF_QI },
32700   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_vpermilv4df_mask, "__builtin_ia32_vpermilpd256_mask", IX86_BUILTIN_VPERMILPD256_MASK, UNKNOWN, (int) V4DF_FTYPE_V4DF_INT_V4DF_QI },
32701   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_vpermilv8sf_mask, "__builtin_ia32_vpermilps256_mask", IX86_BUILTIN_VPERMILPS256_MASK, UNKNOWN, (int) V8SF_FTYPE_V8SF_INT_V8SF_QI },
32702   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4di, "__builtin_ia32_blendmq_256_mask", IX86_BUILTIN_BLENDMQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_QI },
32703   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv8si, "__builtin_ia32_blendmd_256_mask", IX86_BUILTIN_BLENDMD256, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_QI },
32704   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4df, "__builtin_ia32_blendmpd_256_mask", IX86_BUILTIN_BLENDMPD256, UNKNOWN, (int) V4DF_FTYPE_V4DF_V4DF_QI },
32705   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv8sf, "__builtin_ia32_blendmps_256_mask", IX86_BUILTIN_BLENDMPS256, UNKNOWN, (int) V8SF_FTYPE_V8SF_V8SF_QI },
32706   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv2di, "__builtin_ia32_blendmq_128_mask", IX86_BUILTIN_BLENDMQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_QI },
32707   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4si, "__builtin_ia32_blendmd_128_mask", IX86_BUILTIN_BLENDMD128, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_QI },
32708   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv2df, "__builtin_ia32_blendmpd_128_mask", IX86_BUILTIN_BLENDMPD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_QI },
32709   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv4sf, "__builtin_ia32_blendmps_128_mask", IX86_BUILTIN_BLENDMPS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_QI },
32710   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv16hi, "__builtin_ia32_blendmw_256_mask", IX86_BUILTIN_BLENDMW256, UNKNOWN, (int) V16HI_FTYPE_V16HI_V16HI_HI },
32711   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv32qi, "__builtin_ia32_blendmb_256_mask", IX86_BUILTIN_BLENDMB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_SI },
32712   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv8hi, "__builtin_ia32_blendmw_128_mask", IX86_BUILTIN_BLENDMW128, UNKNOWN, (int) V8HI_FTYPE_V8HI_V8HI_QI },
32713   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_blendmv16qi, "__builtin_ia32_blendmb_128_mask", IX86_BUILTIN_BLENDMB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_HI },
32714   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv8si3_mask, "__builtin_ia32_pmulld256_mask", IX86_BUILTIN_PMULLD256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32715   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_mulv4si3_mask, "__builtin_ia32_pmulld128_mask", IX86_BUILTIN_PMULLD128_MASK, UNKNOWN, (int) V4SI_FTYPE_V4SI_V4SI_V4SI_QI },
32716   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_widen_umult_even_v8si_mask, "__builtin_ia32_pmuludq256_mask", IX86_BUILTIN_PMULUDQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V8SI_V8SI_V4DI_QI },
32717   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_widen_smult_even_v8si_mask, "__builtin_ia32_pmuldq256_mask", IX86_BUILTIN_PMULDQ256_MASK, UNKNOWN, (int) V4DI_FTYPE_V8SI_V8SI_V4DI_QI },
32718   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse4_1_mulv2siv2di3_mask, "__builtin_ia32_pmuldq128_mask", IX86_BUILTIN_PMULDQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI_V2DI_QI },
32719   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_vec_widen_umult_even_v4si_mask, "__builtin_ia32_pmuludq128_mask", IX86_BUILTIN_PMULUDQ128_MASK, UNKNOWN, (int) V2DI_FTYPE_V4SI_V4SI_V2DI_QI },
32720   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx_cvtpd2ps256_mask, "__builtin_ia32_cvtpd2ps256_mask", IX86_BUILTIN_CVTPD2PS256_MASK, UNKNOWN, (int) V4SF_FTYPE_V4DF_V4SF_QI },
32721   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_sse2_cvtpd2ps_mask, "__builtin_ia32_cvtpd2ps_mask", IX86_BUILTIN_CVTPD2PS_MASK, UNKNOWN, (int) V4SF_FTYPE_V2DF_V4SF_QI },
32722   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_permvarv8si_mask, "__builtin_ia32_permvarsi256_mask", IX86_BUILTIN_VPERMVARSI256_MASK, UNKNOWN, (int) V8SI_FTYPE_V8SI_V8SI_V8SI_QI },
32723   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx2_permvarv4di_mask, "__builtin_ia32_permvardi256_mask", IX86_BUILTIN_VPERMVARDI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32724   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_permv4di_mask, "__builtin_ia32_permdi256_mask", IX86_BUILTIN_VPERMDI256_MASK, UNKNOWN, (int) V4DI_FTYPE_V4DI_INT_V4DI_QI },
32725   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv4di3_mask, "__builtin_ia32_cmpq256_mask", IX86_BUILTIN_CMPQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_INT_QI },
32726   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv8si3_mask, "__builtin_ia32_cmpd256_mask", IX86_BUILTIN_CMPD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_INT_QI },
32727   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv4di3_mask, "__builtin_ia32_ucmpq256_mask", IX86_BUILTIN_UCMPQ256, UNKNOWN, (int) QI_FTYPE_V4DI_V4DI_INT_QI },
32728   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv8si3_mask, "__builtin_ia32_ucmpd256_mask", IX86_BUILTIN_UCMPD256, UNKNOWN, (int) QI_FTYPE_V8SI_V8SI_INT_QI },
32729   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv32qi3_mask, "__builtin_ia32_cmpb256_mask", IX86_BUILTIN_CMPB256, UNKNOWN, (int) SI_FTYPE_V32QI_V32QI_INT_SI },
32730   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv16hi3_mask, "__builtin_ia32_cmpw256_mask", IX86_BUILTIN_CMPW256, UNKNOWN, (int) HI_FTYPE_V16HI_V16HI_INT_HI },
32731   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv32qi3_mask, "__builtin_ia32_ucmpb256_mask", IX86_BUILTIN_UCMPB256, UNKNOWN, (int) SI_FTYPE_V32QI_V32QI_INT_SI },
32732   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv16hi3_mask, "__builtin_ia32_ucmpw256_mask", IX86_BUILTIN_UCMPW256, UNKNOWN, (int) HI_FTYPE_V16HI_V16HI_INT_HI },
32733   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv4df3_mask, "__builtin_ia32_cmppd256_mask", IX86_BUILTIN_CMPPD256_MASK, UNKNOWN, (int) QI_FTYPE_V4DF_V4DF_INT_QI },
32734   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv8sf3_mask, "__builtin_ia32_cmpps256_mask", IX86_BUILTIN_CMPPS256_MASK, UNKNOWN, (int) QI_FTYPE_V8SF_V8SF_INT_QI },
32735   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv2di3_mask, "__builtin_ia32_cmpq128_mask", IX86_BUILTIN_CMPQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_INT_QI },
32736   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv4si3_mask, "__builtin_ia32_cmpd128_mask", IX86_BUILTIN_CMPD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_INT_QI },
32737   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv2di3_mask, "__builtin_ia32_ucmpq128_mask", IX86_BUILTIN_UCMPQ128, UNKNOWN, (int) QI_FTYPE_V2DI_V2DI_INT_QI },
32738   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv4si3_mask, "__builtin_ia32_ucmpd128_mask", IX86_BUILTIN_UCMPD128, UNKNOWN, (int) QI_FTYPE_V4SI_V4SI_INT_QI },
32739   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv16qi3_mask, "__builtin_ia32_cmpb128_mask", IX86_BUILTIN_CMPB128, UNKNOWN, (int) HI_FTYPE_V16QI_V16QI_INT_HI },
32740   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv8hi3_mask, "__builtin_ia32_cmpw128_mask", IX86_BUILTIN_CMPW128, UNKNOWN, (int) QI_FTYPE_V8HI_V8HI_INT_QI },
32741   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv16qi3_mask, "__builtin_ia32_ucmpb128_mask", IX86_BUILTIN_UCMPB128, UNKNOWN, (int) HI_FTYPE_V16QI_V16QI_INT_HI },
32742   { OPTION_MASK_ISA_AVX512BW | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_ucmpv8hi3_mask, "__builtin_ia32_ucmpw128_mask", IX86_BUILTIN_UCMPW128, UNKNOWN, (int) QI_FTYPE_V8HI_V8HI_INT_QI },
32743   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv2df3_mask, "__builtin_ia32_cmppd128_mask", IX86_BUILTIN_CMPPD128_MASK, UNKNOWN, (int) QI_FTYPE_V2DF_V2DF_INT_QI },
32744   { OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_cmpv4sf3_mask, "__builtin_ia32_cmpps128_mask", IX86_BUILTIN_CMPPS128_MASK, UNKNOWN, (int) QI_FTYPE_V4SF_V4SF_INT_QI },
32745
32746   /* AVX512DQ.  */
32747   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_broadcastv16sf_mask, "__builtin_ia32_broadcastf32x2_512_mask", IX86_BUILTIN_BROADCASTF32x2_512, UNKNOWN, (int) V16SF_FTYPE_V4SF_V16SF_HI },
32748   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_broadcastv16si_mask, "__builtin_ia32_broadcasti32x2_512_mask", IX86_BUILTIN_BROADCASTI32x2_512, UNKNOWN, (int) V16SI_FTYPE_V4SI_V16SI_HI },
32749   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_broadcastv8df_mask_1, "__builtin_ia32_broadcastf64x2_512_mask", IX86_BUILTIN_BROADCASTF64X2_512, UNKNOWN, (int) V8DF_FTYPE_V2DF_V8DF_QI },
32750   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_broadcastv8di_mask_1, "__builtin_ia32_broadcasti64x2_512_mask", IX86_BUILTIN_BROADCASTI64X2_512, UNKNOWN, (int) V8DI_FTYPE_V2DI_V8DI_QI },
32751   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_broadcastv16sf_mask_1, "__builtin_ia32_broadcastf32x8_512_mask", IX86_BUILTIN_BROADCASTF32X8_512, UNKNOWN, (int) V16SF_FTYPE_V8SF_V16SF_HI },
32752   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_broadcastv16si_mask_1, "__builtin_ia32_broadcasti32x8_512_mask", IX86_BUILTIN_BROADCASTI32X8_512, UNKNOWN, (int) V16SI_FTYPE_V8SI_V16SI_HI },
32753   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vextractf64x2_mask, "__builtin_ia32_extractf64x2_512_mask", IX86_BUILTIN_EXTRACTF64X2_512, UNKNOWN, (int) V2DF_FTYPE_V8DF_INT_V2DF_QI },
32754   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vextractf32x8_mask, "__builtin_ia32_extractf32x8_mask", IX86_BUILTIN_EXTRACTF32X8, UNKNOWN, (int) V8SF_FTYPE_V16SF_INT_V8SF_QI },
32755   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vextracti64x2_mask, "__builtin_ia32_extracti64x2_512_mask", IX86_BUILTIN_EXTRACTI64X2_512, UNKNOWN, (int) V2DI_FTYPE_V8DI_INT_V2DI_QI },
32756   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vextracti32x8_mask, "__builtin_ia32_extracti32x8_mask", IX86_BUILTIN_EXTRACTI32X8, UNKNOWN, (int) V8SI_FTYPE_V16SI_INT_V8SI_QI },
32757   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducepv8df_mask, "__builtin_ia32_reducepd512_mask", IX86_BUILTIN_REDUCEPD512_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI },
32758   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_reducepv16sf_mask, "__builtin_ia32_reduceps512_mask", IX86_BUILTIN_REDUCEPS512_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_INT_V16SF_HI },
32759   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_mulv8di3_mask, "__builtin_ia32_pmullq512_mask", IX86_BUILTIN_PMULLQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32760   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_xorv8df3_mask, "__builtin_ia32_xorpd512_mask", IX86_BUILTIN_XORPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32761   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_xorv16sf3_mask, "__builtin_ia32_xorps512_mask", IX86_BUILTIN_XORPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32762   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_iorv8df3_mask, "__builtin_ia32_orpd512_mask", IX86_BUILTIN_ORPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32763   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_iorv16sf3_mask, "__builtin_ia32_orps512_mask", IX86_BUILTIN_ORPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32764   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_andv8df3_mask, "__builtin_ia32_andpd512_mask", IX86_BUILTIN_ANDPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI },
32765   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_andv16sf3_mask, "__builtin_ia32_andps512_mask", IX86_BUILTIN_ANDPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32766   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_andnotv8df3_mask, "__builtin_ia32_andnpd512_mask", IX86_BUILTIN_ANDNPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI},
32767   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_andnotv16sf3_mask, "__builtin_ia32_andnps512_mask", IX86_BUILTIN_ANDNPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI },
32768   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vinsertf32x8_mask, "__builtin_ia32_insertf32x8_mask", IX86_BUILTIN_INSERTF32X8, UNKNOWN, (int) V16SF_FTYPE_V16SF_V8SF_INT_V16SF_HI },
32769   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vinserti32x8_mask, "__builtin_ia32_inserti32x8_mask", IX86_BUILTIN_INSERTI32X8, UNKNOWN, (int) V16SI_FTYPE_V16SI_V8SI_INT_V16SI_HI },
32770   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vinsertf64x2_mask, "__builtin_ia32_insertf64x2_512_mask", IX86_BUILTIN_INSERTF64X2_512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V2DF_INT_V8DF_QI },
32771   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_vinserti64x2_mask, "__builtin_ia32_inserti64x2_512_mask", IX86_BUILTIN_INSERTI64X2_512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V2DI_INT_V8DI_QI },
32772   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_fpclassv8df_mask, "__builtin_ia32_fpclasspd512_mask", IX86_BUILTIN_FPCLASSPD512, UNKNOWN, (int) QI_FTYPE_V8DF_INT_QI },
32773   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_fpclassv16sf_mask, "__builtin_ia32_fpclassps512_mask", IX86_BUILTIN_FPCLASSPS512, UNKNOWN, (int) HI_FTYPE_V16SF_INT_HI },
32774   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtd2maskv16si, "__builtin_ia32_cvtd2mask512", IX86_BUILTIN_CVTD2MASK512, UNKNOWN, (int) HI_FTYPE_V16SI },
32775   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtq2maskv8di, "__builtin_ia32_cvtq2mask512", IX86_BUILTIN_CVTQ2MASK512, UNKNOWN, (int) QI_FTYPE_V8DI },
32776   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtmask2dv16si, "__builtin_ia32_cvtmask2d512", IX86_BUILTIN_CVTMASK2D512, UNKNOWN, (int) V16SI_FTYPE_HI },
32777   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512f_cvtmask2qv8di, "__builtin_ia32_cvtmask2q512", IX86_BUILTIN_CVTMASK2Q512, UNKNOWN, (int) V8DI_FTYPE_QI },
32778
32779   /* AVX512BW.  */
32780   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_kunpcksi, "__builtin_ia32_kunpcksi", IX86_BUILTIN_KUNPCKWD, UNKNOWN, (int) SI_FTYPE_SI_SI },
32781   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_kunpckdi, "__builtin_ia32_kunpckdi", IX86_BUILTIN_KUNPCKDQ, UNKNOWN, (int) DI_FTYPE_DI_DI },
32782   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packusdw_mask, "__builtin_ia32_packusdw512_mask",  IX86_BUILTIN_PACKUSDW512, UNKNOWN, (int) V32HI_FTYPE_V16SI_V16SI_V32HI_SI },
32783   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ashlv4ti3, "__builtin_ia32_pslldq512", IX86_BUILTIN_PSLLDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_CONVERT },
32784   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_lshrv4ti3, "__builtin_ia32_psrldq512", IX86_BUILTIN_PSRLDQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_INT_CONVERT },
32785   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packssdw_mask, "__builtin_ia32_packssdw512_mask",  IX86_BUILTIN_PACKSSDW512, UNKNOWN, (int) V32HI_FTYPE_V16SI_V16SI_V32HI_SI },
32786   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_palignrv4ti, "__builtin_ia32_palignr512", IX86_BUILTIN_PALIGNR512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_INT_CONVERT },
32787   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_palignrv64qi_mask, "__builtin_ia32_palignr512_mask", IX86_BUILTIN_PALIGNR512_MASK, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_INT_V8DI_DI_CONVERT },
32788   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_loaddquv32hi_mask, "__builtin_ia32_movdquhi512_mask", IX86_BUILTIN_MOVDQUHI512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_SI },
32789   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512f_loaddquv64qi_mask, "__builtin_ia32_movdquqi512_mask", IX86_BUILTIN_MOVDQUQI512_MASK, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_DI },
32790   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512f_psadbw, "__builtin_ia32_psadbw512", IX86_BUILTIN_PSADBW512, UNKNOWN, (int) V8DI_FTYPE_V64QI_V64QI },
32791   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_dbpsadbwv32hi_mask, "__builtin_ia32_dbpsadbw512_mask", IX86_BUILTIN_DBPSADBW512, UNKNOWN, (int) V32HI_FTYPE_V64QI_V64QI_INT_V32HI_SI },
32792   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vec_dupv64qi_mask, "__builtin_ia32_pbroadcastb512_mask", IX86_BUILTIN_PBROADCASTB512, UNKNOWN, (int) V64QI_FTYPE_V16QI_V64QI_DI },
32793   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vec_dup_gprv64qi_mask, "__builtin_ia32_pbroadcastb512_gpr_mask", IX86_BUILTIN_PBROADCASTB512_GPR, UNKNOWN, (int) V64QI_FTYPE_QI_V64QI_DI },
32794   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vec_dupv32hi_mask, "__builtin_ia32_pbroadcastw512_mask", IX86_BUILTIN_PBROADCASTW512, UNKNOWN, (int) V32HI_FTYPE_V8HI_V32HI_SI },
32795   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vec_dup_gprv32hi_mask, "__builtin_ia32_pbroadcastw512_gpr_mask", IX86_BUILTIN_PBROADCASTW512_GPR, UNKNOWN, (int) V32HI_FTYPE_HI_V32HI_SI },
32796   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_sign_extendv32qiv32hi2_mask, "__builtin_ia32_pmovsxbw512_mask", IX86_BUILTIN_PMOVSXBW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32QI_V32HI_SI },
32797   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_zero_extendv32qiv32hi2_mask, "__builtin_ia32_pmovzxbw512_mask", IX86_BUILTIN_PMOVZXBW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32QI_V32HI_SI },
32798   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_permvarv32hi_mask, "__builtin_ia32_permvarhi512_mask", IX86_BUILTIN_VPERMVARHI512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32799   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vpermt2varv32hi3_mask, "__builtin_ia32_vpermt2varhi512_mask", IX86_BUILTIN_VPERMT2VARHI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32800   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vpermt2varv32hi3_maskz, "__builtin_ia32_vpermt2varhi512_maskz", IX86_BUILTIN_VPERMT2VARHI512_MASKZ, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32801   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_vpermi2varv32hi3_mask, "__builtin_ia32_vpermi2varhi512_mask", IX86_BUILTIN_VPERMI2VARHI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32802   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_uavgv64qi3_mask, "__builtin_ia32_pavgb512_mask", IX86_BUILTIN_PAVGB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32803   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_uavgv32hi3_mask, "__builtin_ia32_pavgw512_mask", IX86_BUILTIN_PAVGW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32804   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_addv64qi3_mask, "__builtin_ia32_paddb512_mask", IX86_BUILTIN_PADDB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32805   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_subv64qi3_mask, "__builtin_ia32_psubb512_mask", IX86_BUILTIN_PSUBB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32806   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_sssubv64qi3_mask, "__builtin_ia32_psubsb512_mask", IX86_BUILTIN_PSUBSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32807   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ssaddv64qi3_mask, "__builtin_ia32_paddsb512_mask", IX86_BUILTIN_PADDSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32808   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ussubv64qi3_mask, "__builtin_ia32_psubusb512_mask", IX86_BUILTIN_PSUBUSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32809   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_usaddv64qi3_mask, "__builtin_ia32_paddusb512_mask", IX86_BUILTIN_PADDUSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32810   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_subv32hi3_mask, "__builtin_ia32_psubw512_mask", IX86_BUILTIN_PSUBW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32811   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_addv32hi3_mask, "__builtin_ia32_paddw512_mask", IX86_BUILTIN_PADDW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32812   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_sssubv32hi3_mask, "__builtin_ia32_psubsw512_mask", IX86_BUILTIN_PSUBSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32813   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ssaddv32hi3_mask, "__builtin_ia32_paddsw512_mask", IX86_BUILTIN_PADDSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32814   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ussubv32hi3_mask, "__builtin_ia32_psubusw512_mask", IX86_BUILTIN_PSUBUSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32815   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_usaddv32hi3_mask, "__builtin_ia32_paddusw512_mask", IX86_BUILTIN_PADDUSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32816   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_umaxv32hi3_mask, "__builtin_ia32_pmaxuw512_mask", IX86_BUILTIN_PMAXUW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32817   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_smaxv32hi3_mask, "__builtin_ia32_pmaxsw512_mask", IX86_BUILTIN_PMAXSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32818   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_uminv32hi3_mask, "__builtin_ia32_pminuw512_mask", IX86_BUILTIN_PMINUW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32819   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_sminv32hi3_mask, "__builtin_ia32_pminsw512_mask", IX86_BUILTIN_PMINSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32820   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_umaxv64qi3_mask, "__builtin_ia32_pmaxub512_mask", IX86_BUILTIN_PMAXUB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32821   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_smaxv64qi3_mask, "__builtin_ia32_pmaxsb512_mask", IX86_BUILTIN_PMAXSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32822   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_uminv64qi3_mask, "__builtin_ia32_pminub512_mask", IX86_BUILTIN_PMINUB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32823   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_sminv64qi3_mask, "__builtin_ia32_pminsb512_mask", IX86_BUILTIN_PMINSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32824   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_truncatev32hiv32qi2_mask, "__builtin_ia32_pmovwb512_mask", IX86_BUILTIN_PMOVWB512, UNKNOWN, (int) V32QI_FTYPE_V32HI_V32QI_SI },
32825   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ss_truncatev32hiv32qi2_mask, "__builtin_ia32_pmovswb512_mask", IX86_BUILTIN_PMOVSWB512, UNKNOWN, (int) V32QI_FTYPE_V32HI_V32QI_SI },
32826   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_us_truncatev32hiv32qi2_mask, "__builtin_ia32_pmovuswb512_mask", IX86_BUILTIN_PMOVUSWB512, UNKNOWN, (int) V32QI_FTYPE_V32HI_V32QI_SI },
32827   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_umulhrswv32hi3_mask, "__builtin_ia32_pmulhrsw512_mask", IX86_BUILTIN_PMULHRSW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32828   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_umulv32hi3_highpart_mask, "__builtin_ia32_pmulhuw512_mask" , IX86_BUILTIN_PMULHUW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32829   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_smulv32hi3_highpart_mask, "__builtin_ia32_pmulhw512_mask"  , IX86_BUILTIN_PMULHW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32830   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_mulv32hi3_mask, "__builtin_ia32_pmullw512_mask", IX86_BUILTIN_PMULLW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32831   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashlv32hi3_mask, "__builtin_ia32_psllwi512_mask", IX86_BUILTIN_PSLLWI512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32832   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashlv32hi3_mask, "__builtin_ia32_psllw512_mask", IX86_BUILTIN_PSLLW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V32HI_V8HI_V32HI_SI },
32833   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packsswb_mask, "__builtin_ia32_packsswb512_mask",  IX86_BUILTIN_PACKSSWB512, UNKNOWN, (int) V64QI_FTYPE_V32HI_V32HI_V64QI_DI },
32834   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_packuswb_mask, "__builtin_ia32_packuswb512_mask",  IX86_BUILTIN_PACKUSWB512, UNKNOWN, (int) V64QI_FTYPE_V32HI_V32HI_V64QI_DI },
32835   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ashrvv32hi_mask, "__builtin_ia32_psrav32hi_mask", IX86_BUILTIN_PSRAVV32HI, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32836   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pmaddubsw512v32hi_mask, "__builtin_ia32_pmaddubsw512_mask", IX86_BUILTIN_PMADDUBSW512_MASK, UNKNOWN, (int) V32HI_FTYPE_V64QI_V64QI_V32HI_SI },
32837   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pmaddwd512v32hi_mask, "__builtin_ia32_pmaddwd512_mask", IX86_BUILTIN_PMADDWD512_MASK, UNKNOWN, (int) V16SI_FTYPE_V32HI_V32HI_V16SI_HI },
32838   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_lshrvv32hi_mask, "__builtin_ia32_psrlv32hi_mask", IX86_BUILTIN_PSRLVV32HI, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32839   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_interleave_highv64qi_mask, "__builtin_ia32_punpckhbw512_mask", IX86_BUILTIN_PUNPCKHBW512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32840   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_interleave_highv32hi_mask, "__builtin_ia32_punpckhwd512_mask", IX86_BUILTIN_PUNPCKHWD512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32841   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_interleave_lowv64qi_mask, "__builtin_ia32_punpcklbw512_mask", IX86_BUILTIN_PUNPCKLBW512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32842   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_interleave_lowv32hi_mask, "__builtin_ia32_punpcklwd512_mask", IX86_BUILTIN_PUNPCKLWD512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32843   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pshufbv64qi3_mask, "__builtin_ia32_pshufb512_mask", IX86_BUILTIN_PSHUFB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32844   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pshufhwv32hi_mask, "__builtin_ia32_pshufhw512_mask", IX86_BUILTIN_PSHUFHW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32845   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_pshuflwv32hi_mask, "__builtin_ia32_pshuflw512_mask", IX86_BUILTIN_PSHUFLW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32846   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashrv32hi3_mask, "__builtin_ia32_psrawi512_mask", IX86_BUILTIN_PSRAWI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32847   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_ashrv32hi3_mask, "__builtin_ia32_psraw512_mask", IX86_BUILTIN_PSRAW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V8HI_V32HI_SI },
32848   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_lshrv32hi3_mask, "__builtin_ia32_psrlwi512_mask", IX86_BUILTIN_PSRLWI512, UNKNOWN, (int) V32HI_FTYPE_V32HI_INT_V32HI_SI },
32849   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_lshrv32hi3_mask, "__builtin_ia32_psrlw512_mask", IX86_BUILTIN_PSRLW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V8HI_V32HI_SI },
32850   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtb2maskv64qi, "__builtin_ia32_cvtb2mask512", IX86_BUILTIN_CVTB2MASK512, UNKNOWN, (int) DI_FTYPE_V64QI },
32851   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtw2maskv32hi, "__builtin_ia32_cvtw2mask512", IX86_BUILTIN_CVTW2MASK512, UNKNOWN, (int) SI_FTYPE_V32HI },
32852   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtmask2bv64qi, "__builtin_ia32_cvtmask2b512", IX86_BUILTIN_CVTMASK2B512, UNKNOWN, (int) V64QI_FTYPE_DI },
32853   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cvtmask2wv32hi, "__builtin_ia32_cvtmask2w512", IX86_BUILTIN_CVTMASK2W512, UNKNOWN, (int) V32HI_FTYPE_SI },
32854   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_eqv64qi3_mask, "__builtin_ia32_pcmpeqb512_mask", IX86_BUILTIN_PCMPEQB512_MASK, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32855   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_eqv32hi3_mask, "__builtin_ia32_pcmpeqw512_mask", IX86_BUILTIN_PCMPEQW512_MASK, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32856   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_gtv64qi3_mask, "__builtin_ia32_pcmpgtb512_mask", IX86_BUILTIN_PCMPGTB512_MASK, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32857   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_gtv32hi3_mask, "__builtin_ia32_pcmpgtw512_mask", IX86_BUILTIN_PCMPGTW512_MASK, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32858   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testmv64qi3_mask, "__builtin_ia32_ptestmb512", IX86_BUILTIN_PTESTMB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32859   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testmv32hi3_mask, "__builtin_ia32_ptestmw512", IX86_BUILTIN_PTESTMW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32860   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testnmv64qi3_mask, "__builtin_ia32_ptestnmb512", IX86_BUILTIN_PTESTNMB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_DI },
32861   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_testnmv32hi3_mask, "__builtin_ia32_ptestnmw512", IX86_BUILTIN_PTESTNMW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_SI },
32862   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ashlvv32hi_mask, "__builtin_ia32_psllv32hi_mask", IX86_BUILTIN_PSLLVV32HI, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_V32HI_SI },
32863   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_absv64qi2_mask, "__builtin_ia32_pabsb512_mask", IX86_BUILTIN_PABSB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_DI },
32864   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_absv32hi2_mask, "__builtin_ia32_pabsw512_mask", IX86_BUILTIN_PABSW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_SI },
32865   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_blendmv32hi, "__builtin_ia32_blendmw_512_mask", IX86_BUILTIN_BLENDMW512, UNKNOWN, (int) V32HI_FTYPE_V32HI_V32HI_SI },
32866   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_blendmv64qi, "__builtin_ia32_blendmb_512_mask", IX86_BUILTIN_BLENDMB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_DI },
32867   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cmpv64qi3_mask, "__builtin_ia32_cmpb512_mask", IX86_BUILTIN_CMPB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_INT_DI },
32868   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_cmpv32hi3_mask, "__builtin_ia32_cmpw512_mask", IX86_BUILTIN_CMPW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_INT_SI },
32869   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ucmpv64qi3_mask, "__builtin_ia32_ucmpb512_mask", IX86_BUILTIN_UCMPB512, UNKNOWN, (int) DI_FTYPE_V64QI_V64QI_INT_DI },
32870   { OPTION_MASK_ISA_AVX512BW, CODE_FOR_avx512bw_ucmpv32hi3_mask, "__builtin_ia32_ucmpw512_mask", IX86_BUILTIN_UCMPW512, UNKNOWN, (int) SI_FTYPE_V32HI_V32HI_INT_SI },
32871
32872   /* AVX512IFMA */
32873   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52luqv8di_mask, "__builtin_ia32_vpmadd52luq512_mask", IX86_BUILTIN_VPMADD52LUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32874   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52luqv8di_maskz, "__builtin_ia32_vpmadd52luq512_maskz", IX86_BUILTIN_VPMADD52LUQ512_MASKZ, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32875   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52huqv8di_mask, "__builtin_ia32_vpmadd52huq512_mask", IX86_BUILTIN_VPMADD52HUQ512, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32876   { OPTION_MASK_ISA_AVX512IFMA, CODE_FOR_vpamdd52huqv8di_maskz, "__builtin_ia32_vpmadd52huq512_maskz", IX86_BUILTIN_VPMADD52HUQ512_MASKZ, UNKNOWN, (int) V8DI_FTYPE_V8DI_V8DI_V8DI_QI },
32877   { OPTION_MASK_ISA_AVX512IFMA | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpamdd52luqv4di_mask, "__builtin_ia32_vpmadd52luq256_mask", IX86_BUILTIN_VPMADD52LUQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32878   { OPTION_MASK_ISA_AVX512IFMA | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpamdd52luqv4di_maskz, "__builtin_ia32_vpmadd52luq256_maskz", IX86_BUILTIN_VPMADD52LUQ256_MASKZ, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32879   { OPTION_MASK_ISA_AVX512IFMA | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpamdd52huqv4di_mask, "__builtin_ia32_vpmadd52huq256_mask", IX86_BUILTIN_VPMADD52HUQ256, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32880   { OPTION_MASK_ISA_AVX512IFMA | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpamdd52huqv4di_maskz, "__builtin_ia32_vpmadd52huq256_maskz", IX86_BUILTIN_VPMADD52HUQ256_MASKZ, UNKNOWN, (int) V4DI_FTYPE_V4DI_V4DI_V4DI_QI },
32881   { OPTION_MASK_ISA_AVX512IFMA | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpamdd52luqv2di_mask, "__builtin_ia32_vpmadd52luq128_mask", IX86_BUILTIN_VPMADD52LUQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32882   { OPTION_MASK_ISA_AVX512IFMA | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpamdd52luqv2di_maskz, "__builtin_ia32_vpmadd52luq128_maskz", IX86_BUILTIN_VPMADD52LUQ128_MASKZ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32883   { OPTION_MASK_ISA_AVX512IFMA | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpamdd52huqv2di_mask, "__builtin_ia32_vpmadd52huq128_mask", IX86_BUILTIN_VPMADD52HUQ128, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32884   { OPTION_MASK_ISA_AVX512IFMA | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpamdd52huqv2di_maskz, "__builtin_ia32_vpmadd52huq128_maskz", IX86_BUILTIN_VPMADD52HUQ128_MASKZ, UNKNOWN, (int) V2DI_FTYPE_V2DI_V2DI_V2DI_QI },
32885
32886   /* AVX512VBMI */
32887   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_vpmultishiftqbv64qi_mask, "__builtin_ia32_vpmultishiftqb512_mask", IX86_BUILTIN_VPMULTISHIFTQB512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32888   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpmultishiftqbv32qi_mask, "__builtin_ia32_vpmultishiftqb256_mask", IX86_BUILTIN_VPMULTISHIFTQB256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32889   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_vpmultishiftqbv16qi_mask, "__builtin_ia32_vpmultishiftqb128_mask", IX86_BUILTIN_VPMULTISHIFTQB128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32890   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_avx512bw_permvarv64qi_mask, "__builtin_ia32_permvarqi512_mask", IX86_BUILTIN_VPERMVARQI512_MASK, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32891   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_avx512bw_vpermt2varv64qi3_mask, "__builtin_ia32_vpermt2varqi512_mask", IX86_BUILTIN_VPERMT2VARQI512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32892   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_avx512bw_vpermt2varv64qi3_maskz, "__builtin_ia32_vpermt2varqi512_maskz", IX86_BUILTIN_VPERMT2VARQI512_MASKZ, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32893   { OPTION_MASK_ISA_AVX512VBMI, CODE_FOR_avx512bw_vpermi2varv64qi3_mask, "__builtin_ia32_vpermi2varqi512_mask", IX86_BUILTIN_VPERMI2VARQI512, UNKNOWN, (int) V64QI_FTYPE_V64QI_V64QI_V64QI_DI },
32894   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_permvarv32qi_mask, "__builtin_ia32_permvarqi256_mask", IX86_BUILTIN_VPERMVARQI256_MASK, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32895   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_permvarv16qi_mask, "__builtin_ia32_permvarqi128_mask", IX86_BUILTIN_VPERMVARQI128_MASK, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32896   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv32qi3_mask, "__builtin_ia32_vpermt2varqi256_mask", IX86_BUILTIN_VPERMT2VARQI256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32897   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv32qi3_maskz, "__builtin_ia32_vpermt2varqi256_maskz", IX86_BUILTIN_VPERMT2VARQI256_MASKZ, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32898   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv16qi3_mask, "__builtin_ia32_vpermt2varqi128_mask", IX86_BUILTIN_VPERMT2VARQI128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32899   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermt2varv16qi3_maskz, "__builtin_ia32_vpermt2varqi128_maskz", IX86_BUILTIN_VPERMT2VARQI128_MASKZ, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32900   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv32qi3_mask, "__builtin_ia32_vpermi2varqi256_mask", IX86_BUILTIN_VPERMI2VARQI256, UNKNOWN, (int) V32QI_FTYPE_V32QI_V32QI_V32QI_SI },
32901   { OPTION_MASK_ISA_AVX512VBMI | OPTION_MASK_ISA_AVX512VL, CODE_FOR_avx512vl_vpermi2varv16qi3_mask, "__builtin_ia32_vpermi2varqi128_mask", IX86_BUILTIN_VPERMI2VARQI128, UNKNOWN, (int) V16QI_FTYPE_V16QI_V16QI_V16QI_HI },
32902 };
32903
32904 /* Builtins with rounding support.  */
32905 static const struct builtin_description bdesc_round_args[] =
32906 {
32907   /* AVX512F */
32908   { OPTION_MASK_ISA_AVX512F, CODE_FOR_addv8df3_mask_round, "__builtin_ia32_addpd512_mask", IX86_BUILTIN_ADDPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
32909   { OPTION_MASK_ISA_AVX512F, CODE_FOR_addv16sf3_mask_round, "__builtin_ia32_addps512_mask", IX86_BUILTIN_ADDPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
32910   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmaddv2df3_round, "__builtin_ia32_addsd_round", IX86_BUILTIN_ADDSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32911   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmaddv4sf3_round, "__builtin_ia32_addss_round", IX86_BUILTIN_ADDSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32912   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cmpv8df3_mask_round, "__builtin_ia32_cmppd512_mask", IX86_BUILTIN_CMPPD512, UNKNOWN, (int) QI_FTYPE_V8DF_V8DF_INT_QI_INT },
32913   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cmpv16sf3_mask_round, "__builtin_ia32_cmpps512_mask", IX86_BUILTIN_CMPPS512, UNKNOWN, (int) HI_FTYPE_V16SF_V16SF_INT_HI_INT },
32914   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vmcmpv2df3_mask_round, "__builtin_ia32_cmpsd_mask", IX86_BUILTIN_CMPSD_MASK, UNKNOWN, (int) QI_FTYPE_V2DF_V2DF_INT_QI_INT },
32915   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vmcmpv4sf3_mask_round, "__builtin_ia32_cmpss_mask", IX86_BUILTIN_CMPSS_MASK, UNKNOWN, (int) QI_FTYPE_V4SF_V4SF_INT_QI_INT },
32916   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_comi_round, "__builtin_ia32_vcomisd", IX86_BUILTIN_COMIDF, UNKNOWN, (int) INT_FTYPE_V2DF_V2DF_INT_INT },
32917   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_comi_round, "__builtin_ia32_vcomiss", IX86_BUILTIN_COMISF, UNKNOWN, (int) INT_FTYPE_V4SF_V4SF_INT_INT },
32918   { OPTION_MASK_ISA_AVX512F, CODE_FOR_floatv16siv16sf2_mask_round, "__builtin_ia32_cvtdq2ps512_mask", IX86_BUILTIN_CVTDQ2PS512, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_HI_INT },
32919   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cvtpd2dq512_mask_round, "__builtin_ia32_cvtpd2dq512_mask", IX86_BUILTIN_CVTPD2DQ512, UNKNOWN, (int) V8SI_FTYPE_V8DF_V8SI_QI_INT },
32920   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cvtpd2ps512_mask_round,  "__builtin_ia32_cvtpd2ps512_mask", IX86_BUILTIN_CVTPD2PS512, UNKNOWN, (int) V8SF_FTYPE_V8DF_V8SF_QI_INT },
32921   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ufix_notruncv8dfv8si2_mask_round, "__builtin_ia32_cvtpd2udq512_mask", IX86_BUILTIN_CVTPD2UDQ512, UNKNOWN, (int) V8SI_FTYPE_V8DF_V8SI_QI_INT },
32922   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtph2ps512_mask_round,  "__builtin_ia32_vcvtph2ps512_mask", IX86_BUILTIN_CVTPH2PS512, UNKNOWN, (int) V16SF_FTYPE_V16HI_V16SF_HI_INT },
32923   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fix_notruncv16sfv16si_mask_round, "__builtin_ia32_cvtps2dq512_mask", IX86_BUILTIN_CVTPS2DQ512, UNKNOWN, (int) V16SI_FTYPE_V16SF_V16SI_HI_INT },
32924   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_cvtps2pd512_mask_round, "__builtin_ia32_cvtps2pd512_mask", IX86_BUILTIN_CVTPS2PD512, UNKNOWN, (int) V8DF_FTYPE_V8SF_V8DF_QI_INT },
32925   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_ufix_notruncv16sfv16si_mask_round, "__builtin_ia32_cvtps2udq512_mask", IX86_BUILTIN_CVTPS2UDQ512, UNKNOWN, (int) V16SI_FTYPE_V16SF_V16SI_HI_INT },
32926   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvtsd2ss_round, "__builtin_ia32_cvtsd2ss_round", IX86_BUILTIN_CVTSD2SS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V2DF_INT },
32927   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsi2sdq_round, "__builtin_ia32_cvtsi2sd64", IX86_BUILTIN_CVTSI2SD64, UNKNOWN, (int) V2DF_FTYPE_V2DF_INT64_INT },
32928   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_cvtsi2ss_round, "__builtin_ia32_cvtsi2ss32", IX86_BUILTIN_CVTSI2SS32, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT_INT },
32929   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtsi2ssq_round, "__builtin_ia32_cvtsi2ss64", IX86_BUILTIN_CVTSI2SS64, UNKNOWN, (int) V4SF_FTYPE_V4SF_INT64_INT },
32930   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvtss2sd_round, "__builtin_ia32_cvtss2sd_round", IX86_BUILTIN_CVTSS2SD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V4SF_INT },
32931   { OPTION_MASK_ISA_AVX512F, CODE_FOR_fix_truncv8dfv8si2_mask_round, "__builtin_ia32_cvttpd2dq512_mask", IX86_BUILTIN_CVTTPD2DQ512, UNKNOWN, (int) V8SI_FTYPE_V8DF_V8SI_QI_INT },
32932   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ufix_truncv8dfv8si2_mask_round, "__builtin_ia32_cvttpd2udq512_mask", IX86_BUILTIN_CVTTPD2UDQ512, UNKNOWN, (int) V8SI_FTYPE_V8DF_V8SI_QI_INT },
32933   { OPTION_MASK_ISA_AVX512F, CODE_FOR_fix_truncv16sfv16si2_mask_round, "__builtin_ia32_cvttps2dq512_mask", IX86_BUILTIN_CVTTPS2DQ512, UNKNOWN, (int) V16SI_FTYPE_V16SF_V16SI_HI_INT },
32934   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ufix_truncv16sfv16si2_mask_round, "__builtin_ia32_cvttps2udq512_mask", IX86_BUILTIN_CVTTPS2UDQ512, UNKNOWN, (int) V16SI_FTYPE_V16SF_V16SI_HI_INT },
32935   { OPTION_MASK_ISA_AVX512F, CODE_FOR_ufloatv16siv16sf2_mask_round, "__builtin_ia32_cvtudq2ps512_mask", IX86_BUILTIN_CVTUDQ2PS512, UNKNOWN, (int) V16SF_FTYPE_V16SI_V16SF_HI_INT },
32936   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_cvtusi2sd64_round, "__builtin_ia32_cvtusi2sd64", IX86_BUILTIN_CVTUSI2SD64, UNKNOWN, (int) V2DF_FTYPE_V2DF_UINT64_INT },
32937   { OPTION_MASK_ISA_AVX512F, CODE_FOR_cvtusi2ss32_round, "__builtin_ia32_cvtusi2ss32", IX86_BUILTIN_CVTUSI2SS32, UNKNOWN, (int) V4SF_FTYPE_V4SF_UINT_INT },
32938   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_cvtusi2ss64_round, "__builtin_ia32_cvtusi2ss64", IX86_BUILTIN_CVTUSI2SS64, UNKNOWN, (int) V4SF_FTYPE_V4SF_UINT64_INT },
32939   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_divv8df3_mask_round, "__builtin_ia32_divpd512_mask", IX86_BUILTIN_DIVPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
32940   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_divv16sf3_mask_round, "__builtin_ia32_divps512_mask", IX86_BUILTIN_DIVPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
32941   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmdivv2df3_round, "__builtin_ia32_divsd_round", IX86_BUILTIN_DIVSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32942   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmdivv4sf3_round, "__builtin_ia32_divss_round", IX86_BUILTIN_DIVSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32943   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fixupimmv8df_mask_round, "__builtin_ia32_fixupimmpd512_mask", IX86_BUILTIN_FIXUPIMMPD512_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DI_INT_QI_INT },
32944   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fixupimmv8df_maskz_round, "__builtin_ia32_fixupimmpd512_maskz", IX86_BUILTIN_FIXUPIMMPD512_MASKZ, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DI_INT_QI_INT },
32945   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fixupimmv16sf_mask_round, "__builtin_ia32_fixupimmps512_mask", IX86_BUILTIN_FIXUPIMMPS512_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SI_INT_HI_INT },
32946   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fixupimmv16sf_maskz_round, "__builtin_ia32_fixupimmps512_maskz", IX86_BUILTIN_FIXUPIMMPS512_MASKZ, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SI_INT_HI_INT },
32947   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sfixupimmv2df_mask_round, "__builtin_ia32_fixupimmsd_mask", IX86_BUILTIN_FIXUPIMMSD128_MASK, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI_INT },
32948   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sfixupimmv2df_maskz_round, "__builtin_ia32_fixupimmsd_maskz", IX86_BUILTIN_FIXUPIMMSD128_MASKZ, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI_INT },
32949   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sfixupimmv4sf_mask_round, "__builtin_ia32_fixupimmss_mask", IX86_BUILTIN_FIXUPIMMSS128_MASK, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI_INT },
32950   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sfixupimmv4sf_maskz_round, "__builtin_ia32_fixupimmss_maskz", IX86_BUILTIN_FIXUPIMMSS128_MASKZ, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI_INT },
32951   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_getexpv8df_mask_round, "__builtin_ia32_getexppd512_mask", IX86_BUILTIN_GETEXPPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI_INT },
32952   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_getexpv16sf_mask_round, "__builtin_ia32_getexpps512_mask", IX86_BUILTIN_GETEXPPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI_INT },
32953   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sgetexpv2df_round, "__builtin_ia32_getexpsd128_round", IX86_BUILTIN_GETEXPSD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32954   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sgetexpv4sf_round, "__builtin_ia32_getexpss128_round", IX86_BUILTIN_GETEXPSS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32955   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_getmantv8df_mask_round, "__builtin_ia32_getmantpd512_mask", IX86_BUILTIN_GETMANTPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI_INT },
32956   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_getmantv16sf_mask_round, "__builtin_ia32_getmantps512_mask", IX86_BUILTIN_GETMANTPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_INT_V16SF_HI_INT },
32957   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vgetmantv2df_round, "__builtin_ia32_getmantsd_round", IX86_BUILTIN_GETMANTSD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_INT },
32958   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vgetmantv4sf_round, "__builtin_ia32_getmantss_round", IX86_BUILTIN_GETMANTSS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_INT },
32959   { OPTION_MASK_ISA_AVX512F, CODE_FOR_smaxv8df3_mask_round, "__builtin_ia32_maxpd512_mask", IX86_BUILTIN_MAXPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
32960   { OPTION_MASK_ISA_AVX512F, CODE_FOR_smaxv16sf3_mask_round, "__builtin_ia32_maxps512_mask", IX86_BUILTIN_MAXPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
32961   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsmaxv2df3_round, "__builtin_ia32_maxsd_round", IX86_BUILTIN_MAXSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32962   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsmaxv4sf3_round, "__builtin_ia32_maxss_round", IX86_BUILTIN_MAXSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32963   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sminv8df3_mask_round, "__builtin_ia32_minpd512_mask", IX86_BUILTIN_MINPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
32964   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sminv16sf3_mask_round, "__builtin_ia32_minps512_mask", IX86_BUILTIN_MINPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
32965   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsminv2df3_round, "__builtin_ia32_minsd_round", IX86_BUILTIN_MINSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32966   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsminv4sf3_round, "__builtin_ia32_minss_round", IX86_BUILTIN_MINSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32967   { OPTION_MASK_ISA_AVX512F, CODE_FOR_mulv8df3_mask_round, "__builtin_ia32_mulpd512_mask", IX86_BUILTIN_MULPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
32968   { OPTION_MASK_ISA_AVX512F, CODE_FOR_mulv16sf3_mask_round, "__builtin_ia32_mulps512_mask", IX86_BUILTIN_MULPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
32969   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmmulv2df3_round, "__builtin_ia32_mulsd_round", IX86_BUILTIN_MULSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32970   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmmulv4sf3_round, "__builtin_ia32_mulss_round", IX86_BUILTIN_MULSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32971   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rndscalev8df_mask_round, "__builtin_ia32_rndscalepd_mask", IX86_BUILTIN_RNDSCALEPD, UNKNOWN, (int) V8DF_FTYPE_V8DF_INT_V8DF_QI_INT },
32972   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rndscalev16sf_mask_round, "__builtin_ia32_rndscaleps_mask", IX86_BUILTIN_RNDSCALEPS, UNKNOWN, (int) V16SF_FTYPE_V16SF_INT_V16SF_HI_INT },
32973   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rndscalev2df_round, "__builtin_ia32_rndscalesd_round", IX86_BUILTIN_RNDSCALESD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_INT },
32974   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_rndscalev4sf_round, "__builtin_ia32_rndscaless_round", IX86_BUILTIN_RNDSCALESS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_INT },
32975   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_scalefv8df_mask_round, "__builtin_ia32_scalefpd512_mask", IX86_BUILTIN_SCALEFPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
32976   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_scalefv16sf_mask_round, "__builtin_ia32_scalefps512_mask", IX86_BUILTIN_SCALEFPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
32977   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vmscalefv2df_round, "__builtin_ia32_scalefsd_round", IX86_BUILTIN_SCALEFSD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32978   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vmscalefv4sf_round, "__builtin_ia32_scalefss_round", IX86_BUILTIN_SCALEFSS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32979   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sqrtv8df2_mask_round, "__builtin_ia32_sqrtpd512_mask", IX86_BUILTIN_SQRTPD512_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI_INT },
32980   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_sqrtv16sf2_mask_round, "__builtin_ia32_sqrtps512_mask", IX86_BUILTIN_SQRTPS512_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI_INT },
32981   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsqrtv2df2_round, "__builtin_ia32_sqrtsd_round", IX86_BUILTIN_SQRTSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32982   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsqrtv4sf2_round, "__builtin_ia32_sqrtss_round", IX86_BUILTIN_SQRTSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32983   { OPTION_MASK_ISA_AVX512F, CODE_FOR_subv8df3_mask_round, "__builtin_ia32_subpd512_mask", IX86_BUILTIN_SUBPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
32984   { OPTION_MASK_ISA_AVX512F, CODE_FOR_subv16sf3_mask_round, "__builtin_ia32_subps512_mask", IX86_BUILTIN_SUBPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
32985   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_vmsubv2df3_round, "__builtin_ia32_subsd_round", IX86_BUILTIN_SUBSD_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
32986   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_vmsubv4sf3_round, "__builtin_ia32_subss_round", IX86_BUILTIN_SUBSS_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
32987   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvtsd2si_round, "__builtin_ia32_vcvtsd2si32", IX86_BUILTIN_VCVTSD2SI32, UNKNOWN, (int) INT_FTYPE_V2DF_INT },
32988   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvtsd2siq_round, "__builtin_ia32_vcvtsd2si64", IX86_BUILTIN_VCVTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF_INT },
32989   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtsd2usi_round, "__builtin_ia32_vcvtsd2usi32", IX86_BUILTIN_VCVTSD2USI32, UNKNOWN, (int) UINT_FTYPE_V2DF_INT },
32990   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_avx512f_vcvtsd2usiq_round, "__builtin_ia32_vcvtsd2usi64", IX86_BUILTIN_VCVTSD2USI64, UNKNOWN, (int) UINT64_FTYPE_V2DF_INT },
32991   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_cvtss2si_round, "__builtin_ia32_vcvtss2si32", IX86_BUILTIN_VCVTSS2SI32, UNKNOWN, (int) INT_FTYPE_V4SF_INT },
32992   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvtss2siq_round, "__builtin_ia32_vcvtss2si64", IX86_BUILTIN_VCVTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF_INT },
32993   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvtss2usi_round, "__builtin_ia32_vcvtss2usi32", IX86_BUILTIN_VCVTSS2USI32, UNKNOWN, (int) UINT_FTYPE_V4SF_INT },
32994   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_avx512f_vcvtss2usiq_round, "__builtin_ia32_vcvtss2usi64", IX86_BUILTIN_VCVTSS2USI64, UNKNOWN, (int) UINT64_FTYPE_V4SF_INT },
32995   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse2_cvttsd2si_round, "__builtin_ia32_vcvttsd2si32", IX86_BUILTIN_VCVTTSD2SI32, UNKNOWN, (int) INT_FTYPE_V2DF_INT },
32996   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_sse2_cvttsd2siq_round, "__builtin_ia32_vcvttsd2si64", IX86_BUILTIN_VCVTTSD2SI64, UNKNOWN, (int) INT64_FTYPE_V2DF_INT },
32997   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvttsd2usi_round, "__builtin_ia32_vcvttsd2usi32", IX86_BUILTIN_VCVTTSD2USI32, UNKNOWN, (int) UINT_FTYPE_V2DF_INT },
32998   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_avx512f_vcvttsd2usiq_round, "__builtin_ia32_vcvttsd2usi64", IX86_BUILTIN_VCVTTSD2USI64, UNKNOWN, (int) UINT64_FTYPE_V2DF_INT },
32999   { OPTION_MASK_ISA_AVX512F, CODE_FOR_sse_cvttss2si_round, "__builtin_ia32_vcvttss2si32", IX86_BUILTIN_VCVTTSS2SI32, UNKNOWN, (int) INT_FTYPE_V4SF_INT },
33000   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_sse_cvttss2siq_round, "__builtin_ia32_vcvttss2si64", IX86_BUILTIN_VCVTTSS2SI64, UNKNOWN, (int) INT64_FTYPE_V4SF_INT },
33001   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_vcvttss2usi_round, "__builtin_ia32_vcvttss2usi32", IX86_BUILTIN_VCVTTSS2USI32, UNKNOWN, (int) UINT_FTYPE_V4SF_INT },
33002   { OPTION_MASK_ISA_AVX512F | OPTION_MASK_ISA_64BIT, CODE_FOR_avx512f_vcvttss2usiq_round, "__builtin_ia32_vcvttss2usi64", IX86_BUILTIN_VCVTTSS2USI64, UNKNOWN, (int) UINT64_FTYPE_V4SF_INT },
33003   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmadd_v8df_mask_round, "__builtin_ia32_vfmaddpd512_mask", IX86_BUILTIN_VFMADDPD512_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33004   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmadd_v8df_mask3_round, "__builtin_ia32_vfmaddpd512_mask3", IX86_BUILTIN_VFMADDPD512_MASK3, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33005   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmadd_v8df_maskz_round, "__builtin_ia32_vfmaddpd512_maskz", IX86_BUILTIN_VFMADDPD512_MASKZ, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33006   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmadd_v16sf_mask_round, "__builtin_ia32_vfmaddps512_mask", IX86_BUILTIN_VFMADDPS512_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33007   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmadd_v16sf_mask3_round, "__builtin_ia32_vfmaddps512_mask3", IX86_BUILTIN_VFMADDPS512_MASK3, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33008   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmadd_v16sf_maskz_round, "__builtin_ia32_vfmaddps512_maskz", IX86_BUILTIN_VFMADDPS512_MASKZ, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33009   { OPTION_MASK_ISA_AVX512F, CODE_FOR_fmai_vmfmadd_v2df_round, "__builtin_ia32_vfmaddsd3_round", IX86_BUILTIN_VFMADDSD3_ROUND, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_V2DF_INT },
33010   { OPTION_MASK_ISA_AVX512F, CODE_FOR_fmai_vmfmadd_v4sf_round, "__builtin_ia32_vfmaddss3_round", IX86_BUILTIN_VFMADDSS3_ROUND, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_V4SF_INT },
33011   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmaddsub_v8df_mask_round, "__builtin_ia32_vfmaddsubpd512_mask", IX86_BUILTIN_VFMADDSUBPD512_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33012   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmaddsub_v8df_mask3_round, "__builtin_ia32_vfmaddsubpd512_mask3", IX86_BUILTIN_VFMADDSUBPD512_MASK3, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33013   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmaddsub_v8df_maskz_round, "__builtin_ia32_vfmaddsubpd512_maskz", IX86_BUILTIN_VFMADDSUBPD512_MASKZ, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33014   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmaddsub_v16sf_mask_round, "__builtin_ia32_vfmaddsubps512_mask", IX86_BUILTIN_VFMADDSUBPS512_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33015   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmaddsub_v16sf_mask3_round, "__builtin_ia32_vfmaddsubps512_mask3", IX86_BUILTIN_VFMADDSUBPS512_MASK3, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33016   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmaddsub_v16sf_maskz_round, "__builtin_ia32_vfmaddsubps512_maskz", IX86_BUILTIN_VFMADDSUBPS512_MASKZ, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33017   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmsubadd_v8df_mask3_round, "__builtin_ia32_vfmsubaddpd512_mask3", IX86_BUILTIN_VFMSUBADDPD512_MASK3, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33018   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmsubadd_v16sf_mask3_round, "__builtin_ia32_vfmsubaddps512_mask3", IX86_BUILTIN_VFMSUBADDPS512_MASK3, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33019   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmsub_v8df_mask3_round, "__builtin_ia32_vfmsubpd512_mask3", IX86_BUILTIN_VFMSUBPD512_MASK3, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33020   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fmsub_v16sf_mask3_round, "__builtin_ia32_vfmsubps512_mask3", IX86_BUILTIN_VFMSUBPS512_MASK3, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33021   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fnmadd_v8df_mask_round, "__builtin_ia32_vfnmaddpd512_mask", IX86_BUILTIN_VFNMADDPD512_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33022   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fnmadd_v16sf_mask_round, "__builtin_ia32_vfnmaddps512_mask", IX86_BUILTIN_VFNMADDPS512_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33023   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fnmsub_v8df_mask_round, "__builtin_ia32_vfnmsubpd512_mask", IX86_BUILTIN_VFNMSUBPD512_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33024   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fnmsub_v8df_mask3_round, "__builtin_ia32_vfnmsubpd512_mask3", IX86_BUILTIN_VFNMSUBPD512_MASK3, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT },
33025   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fnmsub_v16sf_mask_round, "__builtin_ia32_vfnmsubps512_mask", IX86_BUILTIN_VFNMSUBPS512_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33026   { OPTION_MASK_ISA_AVX512F, CODE_FOR_avx512f_fnmsub_v16sf_mask3_round, "__builtin_ia32_vfnmsubps512_mask3", IX86_BUILTIN_VFNMSUBPS512_MASK3, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT },
33027
33028   /* AVX512ER */
33029   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_exp2v8df_mask_round, "__builtin_ia32_exp2pd_mask", IX86_BUILTIN_EXP2PD_MASK, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI_INT },
33030   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_exp2v16sf_mask_round, "__builtin_ia32_exp2ps_mask", IX86_BUILTIN_EXP2PS_MASK, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI_INT },
33031   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_rcp28v8df_mask_round, "__builtin_ia32_rcp28pd_mask", IX86_BUILTIN_RCP28PD, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI_INT },
33032   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_rcp28v16sf_mask_round, "__builtin_ia32_rcp28ps_mask", IX86_BUILTIN_RCP28PS, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI_INT },
33033   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrcp28v2df_round, "__builtin_ia32_rcp28sd_round", IX86_BUILTIN_RCP28SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33034   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrcp28v4sf_round, "__builtin_ia32_rcp28ss_round", IX86_BUILTIN_RCP28SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33035   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_rsqrt28v8df_mask_round, "__builtin_ia32_rsqrt28pd_mask", IX86_BUILTIN_RSQRT28PD, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_QI_INT },
33036   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_rsqrt28v16sf_mask_round, "__builtin_ia32_rsqrt28ps_mask", IX86_BUILTIN_RSQRT28PS, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_HI_INT },
33037   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrsqrt28v2df_round, "__builtin_ia32_rsqrt28sd_round", IX86_BUILTIN_RSQRT28SD, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT },
33038   { OPTION_MASK_ISA_AVX512ER, CODE_FOR_avx512er_vmrsqrt28v4sf_round, "__builtin_ia32_rsqrt28ss_round", IX86_BUILTIN_RSQRT28SS, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT },
33039
33040   /* AVX512DQ.  */
33041   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_rangesv2df_round, "__builtin_ia32_rangesd128_round", IX86_BUILTIN_RANGESD128, UNKNOWN, (int) V2DF_FTYPE_V2DF_V2DF_INT_INT },
33042   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_rangesv4sf_round, "__builtin_ia32_rangess128_round", IX86_BUILTIN_RANGESS128, UNKNOWN, (int) V4SF_FTYPE_V4SF_V4SF_INT_INT },
33043   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_fix_notruncv8dfv8di2_mask_round, "__builtin_ia32_cvtpd2qq512_mask", IX86_BUILTIN_CVTPD2QQ512, UNKNOWN, (int) V8DI_FTYPE_V8DF_V8DI_QI_INT },
33044   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_cvtps2qqv8di_mask_round, "__builtin_ia32_cvtps2qq512_mask", IX86_BUILTIN_CVTPS2QQ512, UNKNOWN, (int) V8DI_FTYPE_V8SF_V8DI_QI_INT },
33045   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_ufix_notruncv8dfv8di2_mask_round, "__builtin_ia32_cvtpd2uqq512_mask", IX86_BUILTIN_CVTPD2UQQ512, UNKNOWN, (int) V8DI_FTYPE_V8DF_V8DI_QI_INT },
33046   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_cvtps2uqqv8di_mask_round, "__builtin_ia32_cvtps2uqq512_mask", IX86_BUILTIN_CVTPS2UQQ512, UNKNOWN, (int) V8DI_FTYPE_V8SF_V8DI_QI_INT },
33047   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_floatv8div8sf2_mask_round, "__builtin_ia32_cvtqq2ps512_mask", IX86_BUILTIN_CVTQQ2PS512, UNKNOWN, (int) V8SF_FTYPE_V8DI_V8SF_QI_INT },
33048   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_ufloatv8div8sf2_mask_round, "__builtin_ia32_cvtuqq2ps512_mask", IX86_BUILTIN_CVTUQQ2PS512, UNKNOWN, (int) V8SF_FTYPE_V8DI_V8SF_QI_INT },
33049   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_floatv8div8df2_mask_round, "__builtin_ia32_cvtqq2pd512_mask", IX86_BUILTIN_CVTQQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_QI_INT },
33050   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_ufloatv8div8df2_mask_round, "__builtin_ia32_cvtuqq2pd512_mask", IX86_BUILTIN_CVTUQQ2PD512, UNKNOWN, (int) V8DF_FTYPE_V8DI_V8DF_QI_INT },
33051   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_fix_truncv8sfv8di2_mask_round, "__builtin_ia32_cvttps2qq512_mask", IX86_BUILTIN_CVTTPS2QQ512, UNKNOWN, (int) V8DI_FTYPE_V8SF_V8DI_QI_INT },
33052   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_ufix_truncv8sfv8di2_mask_round, "__builtin_ia32_cvttps2uqq512_mask", IX86_BUILTIN_CVTTPS2UQQ512, UNKNOWN, (int) V8DI_FTYPE_V8SF_V8DI_QI_INT },
33053   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_fix_truncv8dfv8di2_mask_round, "__builtin_ia32_cvttpd2qq512_mask", IX86_BUILTIN_CVTTPD2QQ512, UNKNOWN, (int) V8DI_FTYPE_V8DF_V8DI_QI_INT },
33054   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_ufix_truncv8dfv8di2_mask_round, "__builtin_ia32_cvttpd2uqq512_mask", IX86_BUILTIN_CVTTPD2UQQ512, UNKNOWN, (int) V8DI_FTYPE_V8DF_V8DI_QI_INT },
33055   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_rangepv16sf_mask_round, "__builtin_ia32_rangeps512_mask", IX86_BUILTIN_RANGEPS512, UNKNOWN, (int) V16SF_FTYPE_V16SF_V16SF_INT_V16SF_HI_INT },
33056   { OPTION_MASK_ISA_AVX512DQ, CODE_FOR_avx512dq_rangepv8df_mask_round, "__builtin_ia32_rangepd512_mask", IX86_BUILTIN_RANGEPD512, UNKNOWN, (int) V8DF_FTYPE_V8DF_V8DF_INT_V8DF_QI_INT },
33057 };
33058
33059 /* Bultins for MPX.  */
33060 static const struct builtin_description bdesc_mpx[] =
33061 {
33062   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndstx", IX86_BUILTIN_BNDSTX, UNKNOWN, (int) VOID_FTYPE_PCVOID_BND_PCVOID },
33063   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndcl", IX86_BUILTIN_BNDCL, UNKNOWN, (int) VOID_FTYPE_PCVOID_BND },
33064   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndcu", IX86_BUILTIN_BNDCU, UNKNOWN, (int) VOID_FTYPE_PCVOID_BND },
33065 };
33066
33067 /* Const builtins for MPX.  */
33068 static const struct builtin_description bdesc_mpx_const[] =
33069 {
33070   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndmk", IX86_BUILTIN_BNDMK, UNKNOWN, (int) BND_FTYPE_PCVOID_ULONG },
33071   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndldx", IX86_BUILTIN_BNDLDX, UNKNOWN, (int) BND_FTYPE_PCVOID_PCVOID },
33072   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_narrow_bounds", IX86_BUILTIN_BNDNARROW, UNKNOWN, (int) PVOID_FTYPE_PCVOID_BND_ULONG },
33073   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndint", IX86_BUILTIN_BNDINT, UNKNOWN, (int) BND_FTYPE_BND_BND },
33074   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_sizeof", IX86_BUILTIN_SIZEOF, UNKNOWN, (int) ULONG_FTYPE_VOID },
33075   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndlower", IX86_BUILTIN_BNDLOWER, UNKNOWN, (int) PVOID_FTYPE_BND },
33076   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndupper", IX86_BUILTIN_BNDUPPER, UNKNOWN, (int) PVOID_FTYPE_BND },
33077   { OPTION_MASK_ISA_MPX, (enum insn_code)0, "__builtin_ia32_bndret", IX86_BUILTIN_BNDRET, UNKNOWN, (int) BND_FTYPE_PCVOID },
33078 };
33079
33080 /* FMA4 and XOP.  */
33081 #define MULTI_ARG_4_DF2_DI_I    V2DF_FTYPE_V2DF_V2DF_V2DI_INT
33082 #define MULTI_ARG_4_DF2_DI_I1   V4DF_FTYPE_V4DF_V4DF_V4DI_INT
33083 #define MULTI_ARG_4_SF2_SI_I    V4SF_FTYPE_V4SF_V4SF_V4SI_INT
33084 #define MULTI_ARG_4_SF2_SI_I1   V8SF_FTYPE_V8SF_V8SF_V8SI_INT
33085 #define MULTI_ARG_3_SF          V4SF_FTYPE_V4SF_V4SF_V4SF
33086 #define MULTI_ARG_3_DF          V2DF_FTYPE_V2DF_V2DF_V2DF
33087 #define MULTI_ARG_3_SF2         V8SF_FTYPE_V8SF_V8SF_V8SF
33088 #define MULTI_ARG_3_DF2         V4DF_FTYPE_V4DF_V4DF_V4DF
33089 #define MULTI_ARG_3_DI          V2DI_FTYPE_V2DI_V2DI_V2DI
33090 #define MULTI_ARG_3_SI          V4SI_FTYPE_V4SI_V4SI_V4SI
33091 #define MULTI_ARG_3_SI_DI       V4SI_FTYPE_V4SI_V4SI_V2DI
33092 #define MULTI_ARG_3_HI          V8HI_FTYPE_V8HI_V8HI_V8HI
33093 #define MULTI_ARG_3_HI_SI       V8HI_FTYPE_V8HI_V8HI_V4SI
33094 #define MULTI_ARG_3_QI          V16QI_FTYPE_V16QI_V16QI_V16QI
33095 #define MULTI_ARG_3_DI2         V4DI_FTYPE_V4DI_V4DI_V4DI
33096 #define MULTI_ARG_3_SI2         V8SI_FTYPE_V8SI_V8SI_V8SI
33097 #define MULTI_ARG_3_HI2         V16HI_FTYPE_V16HI_V16HI_V16HI
33098 #define MULTI_ARG_3_QI2         V32QI_FTYPE_V32QI_V32QI_V32QI
33099 #define MULTI_ARG_2_SF          V4SF_FTYPE_V4SF_V4SF
33100 #define MULTI_ARG_2_DF          V2DF_FTYPE_V2DF_V2DF
33101 #define MULTI_ARG_2_DI          V2DI_FTYPE_V2DI_V2DI
33102 #define MULTI_ARG_2_SI          V4SI_FTYPE_V4SI_V4SI
33103 #define MULTI_ARG_2_HI          V8HI_FTYPE_V8HI_V8HI
33104 #define MULTI_ARG_2_QI          V16QI_FTYPE_V16QI_V16QI
33105 #define MULTI_ARG_2_DI_IMM      V2DI_FTYPE_V2DI_SI
33106 #define MULTI_ARG_2_SI_IMM      V4SI_FTYPE_V4SI_SI
33107 #define MULTI_ARG_2_HI_IMM      V8HI_FTYPE_V8HI_SI
33108 #define MULTI_ARG_2_QI_IMM      V16QI_FTYPE_V16QI_SI
33109 #define MULTI_ARG_2_DI_CMP      V2DI_FTYPE_V2DI_V2DI_CMP
33110 #define MULTI_ARG_2_SI_CMP      V4SI_FTYPE_V4SI_V4SI_CMP
33111 #define MULTI_ARG_2_HI_CMP      V8HI_FTYPE_V8HI_V8HI_CMP
33112 #define MULTI_ARG_2_QI_CMP      V16QI_FTYPE_V16QI_V16QI_CMP
33113 #define MULTI_ARG_2_SF_TF       V4SF_FTYPE_V4SF_V4SF_TF
33114 #define MULTI_ARG_2_DF_TF       V2DF_FTYPE_V2DF_V2DF_TF
33115 #define MULTI_ARG_2_DI_TF       V2DI_FTYPE_V2DI_V2DI_TF
33116 #define MULTI_ARG_2_SI_TF       V4SI_FTYPE_V4SI_V4SI_TF
33117 #define MULTI_ARG_2_HI_TF       V8HI_FTYPE_V8HI_V8HI_TF
33118 #define MULTI_ARG_2_QI_TF       V16QI_FTYPE_V16QI_V16QI_TF
33119 #define MULTI_ARG_1_SF          V4SF_FTYPE_V4SF
33120 #define MULTI_ARG_1_DF          V2DF_FTYPE_V2DF
33121 #define MULTI_ARG_1_SF2         V8SF_FTYPE_V8SF
33122 #define MULTI_ARG_1_DF2         V4DF_FTYPE_V4DF
33123 #define MULTI_ARG_1_DI          V2DI_FTYPE_V2DI
33124 #define MULTI_ARG_1_SI          V4SI_FTYPE_V4SI
33125 #define MULTI_ARG_1_HI          V8HI_FTYPE_V8HI
33126 #define MULTI_ARG_1_QI          V16QI_FTYPE_V16QI
33127 #define MULTI_ARG_1_SI_DI       V2DI_FTYPE_V4SI
33128 #define MULTI_ARG_1_HI_DI       V2DI_FTYPE_V8HI
33129 #define MULTI_ARG_1_HI_SI       V4SI_FTYPE_V8HI
33130 #define MULTI_ARG_1_QI_DI       V2DI_FTYPE_V16QI
33131 #define MULTI_ARG_1_QI_SI       V4SI_FTYPE_V16QI
33132 #define MULTI_ARG_1_QI_HI       V8HI_FTYPE_V16QI
33133
33134 static const struct builtin_description bdesc_multi_arg[] =
33135 {
33136   { OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_vmfmadd_v4sf,
33137     "__builtin_ia32_vfmaddss", IX86_BUILTIN_VFMADDSS,
33138     UNKNOWN, (int)MULTI_ARG_3_SF },
33139   { OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_vmfmadd_v2df,
33140     "__builtin_ia32_vfmaddsd", IX86_BUILTIN_VFMADDSD,
33141     UNKNOWN, (int)MULTI_ARG_3_DF },
33142
33143   { OPTION_MASK_ISA_FMA, CODE_FOR_fmai_vmfmadd_v4sf,
33144     "__builtin_ia32_vfmaddss3", IX86_BUILTIN_VFMADDSS3,
33145     UNKNOWN, (int)MULTI_ARG_3_SF },
33146   { OPTION_MASK_ISA_FMA, CODE_FOR_fmai_vmfmadd_v2df,
33147     "__builtin_ia32_vfmaddsd3", IX86_BUILTIN_VFMADDSD3,
33148     UNKNOWN, (int)MULTI_ARG_3_DF },
33149
33150   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v4sf,
33151     "__builtin_ia32_vfmaddps", IX86_BUILTIN_VFMADDPS,
33152     UNKNOWN, (int)MULTI_ARG_3_SF },
33153   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v2df,
33154     "__builtin_ia32_vfmaddpd", IX86_BUILTIN_VFMADDPD,
33155     UNKNOWN, (int)MULTI_ARG_3_DF },
33156   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v8sf,
33157     "__builtin_ia32_vfmaddps256", IX86_BUILTIN_VFMADDPS256,
33158     UNKNOWN, (int)MULTI_ARG_3_SF2 },
33159   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fma4i_fmadd_v4df,
33160     "__builtin_ia32_vfmaddpd256", IX86_BUILTIN_VFMADDPD256,
33161     UNKNOWN, (int)MULTI_ARG_3_DF2 },
33162
33163   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v4sf,
33164     "__builtin_ia32_vfmaddsubps", IX86_BUILTIN_VFMADDSUBPS,
33165     UNKNOWN, (int)MULTI_ARG_3_SF },
33166   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v2df,
33167     "__builtin_ia32_vfmaddsubpd", IX86_BUILTIN_VFMADDSUBPD,
33168     UNKNOWN, (int)MULTI_ARG_3_DF },
33169   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v8sf,
33170     "__builtin_ia32_vfmaddsubps256", IX86_BUILTIN_VFMADDSUBPS256,
33171     UNKNOWN, (int)MULTI_ARG_3_SF2 },
33172   { OPTION_MASK_ISA_FMA | OPTION_MASK_ISA_FMA4, CODE_FOR_fmaddsub_v4df,
33173     "__builtin_ia32_vfmaddsubpd256", IX86_BUILTIN_VFMADDSUBPD256,
33174     UNKNOWN, (int)MULTI_ARG_3_DF2 },
33175
33176   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v2di,        "__builtin_ia32_vpcmov",      IX86_BUILTIN_VPCMOV,      UNKNOWN,      (int)MULTI_ARG_3_DI },
33177   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v2di,        "__builtin_ia32_vpcmov_v2di", IX86_BUILTIN_VPCMOV_V2DI, UNKNOWN,      (int)MULTI_ARG_3_DI },
33178   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4si,        "__builtin_ia32_vpcmov_v4si", IX86_BUILTIN_VPCMOV_V4SI, UNKNOWN,      (int)MULTI_ARG_3_SI },
33179   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v8hi,        "__builtin_ia32_vpcmov_v8hi", IX86_BUILTIN_VPCMOV_V8HI, UNKNOWN,      (int)MULTI_ARG_3_HI },
33180   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v16qi,       "__builtin_ia32_vpcmov_v16qi",IX86_BUILTIN_VPCMOV_V16QI,UNKNOWN,      (int)MULTI_ARG_3_QI },
33181   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v2df,        "__builtin_ia32_vpcmov_v2df", IX86_BUILTIN_VPCMOV_V2DF, UNKNOWN,      (int)MULTI_ARG_3_DF },
33182   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4sf,        "__builtin_ia32_vpcmov_v4sf", IX86_BUILTIN_VPCMOV_V4SF, UNKNOWN,      (int)MULTI_ARG_3_SF },
33183
33184   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4di256,        "__builtin_ia32_vpcmov256",       IX86_BUILTIN_VPCMOV256,       UNKNOWN,      (int)MULTI_ARG_3_DI2 },
33185   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4di256,        "__builtin_ia32_vpcmov_v4di256",  IX86_BUILTIN_VPCMOV_V4DI256,  UNKNOWN,      (int)MULTI_ARG_3_DI2 },
33186   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v8si256,        "__builtin_ia32_vpcmov_v8si256",  IX86_BUILTIN_VPCMOV_V8SI256,  UNKNOWN,      (int)MULTI_ARG_3_SI2 },
33187   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v16hi256,       "__builtin_ia32_vpcmov_v16hi256", IX86_BUILTIN_VPCMOV_V16HI256, UNKNOWN,      (int)MULTI_ARG_3_HI2 },
33188   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v32qi256,       "__builtin_ia32_vpcmov_v32qi256", IX86_BUILTIN_VPCMOV_V32QI256, UNKNOWN,      (int)MULTI_ARG_3_QI2 },
33189   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v4df256,        "__builtin_ia32_vpcmov_v4df256",  IX86_BUILTIN_VPCMOV_V4DF256,  UNKNOWN,      (int)MULTI_ARG_3_DF2 },
33190   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcmov_v8sf256,        "__builtin_ia32_vpcmov_v8sf256",  IX86_BUILTIN_VPCMOV_V8SF256,  UNKNOWN,      (int)MULTI_ARG_3_SF2 },
33191
33192   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pperm,             "__builtin_ia32_vpperm",      IX86_BUILTIN_VPPERM,      UNKNOWN,      (int)MULTI_ARG_3_QI },
33193
33194   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssww,          "__builtin_ia32_vpmacssww",   IX86_BUILTIN_VPMACSSWW,   UNKNOWN,      (int)MULTI_ARG_3_HI },
33195   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsww,           "__builtin_ia32_vpmacsww",    IX86_BUILTIN_VPMACSWW,    UNKNOWN,      (int)MULTI_ARG_3_HI },
33196   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsswd,          "__builtin_ia32_vpmacsswd",   IX86_BUILTIN_VPMACSSWD,   UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33197   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacswd,           "__builtin_ia32_vpmacswd",    IX86_BUILTIN_VPMACSWD,    UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33198   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssdd,          "__builtin_ia32_vpmacssdd",   IX86_BUILTIN_VPMACSSDD,   UNKNOWN,      (int)MULTI_ARG_3_SI },
33199   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsdd,           "__builtin_ia32_vpmacsdd",    IX86_BUILTIN_VPMACSDD,    UNKNOWN,      (int)MULTI_ARG_3_SI },
33200   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssdql,         "__builtin_ia32_vpmacssdql",  IX86_BUILTIN_VPMACSSDQL,  UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33201   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacssdqh,         "__builtin_ia32_vpmacssdqh",  IX86_BUILTIN_VPMACSSDQH,  UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33202   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsdql,          "__builtin_ia32_vpmacsdql",   IX86_BUILTIN_VPMACSDQL,   UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33203   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmacsdqh,          "__builtin_ia32_vpmacsdqh",   IX86_BUILTIN_VPMACSDQH,   UNKNOWN,      (int)MULTI_ARG_3_SI_DI },
33204   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmadcsswd,         "__builtin_ia32_vpmadcsswd",  IX86_BUILTIN_VPMADCSSWD,  UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33205   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pmadcswd,          "__builtin_ia32_vpmadcswd",   IX86_BUILTIN_VPMADCSWD,   UNKNOWN,      (int)MULTI_ARG_3_HI_SI },
33206
33207   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv2di3,        "__builtin_ia32_vprotq",      IX86_BUILTIN_VPROTQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
33208   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv4si3,        "__builtin_ia32_vprotd",      IX86_BUILTIN_VPROTD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
33209   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv8hi3,        "__builtin_ia32_vprotw",      IX86_BUILTIN_VPROTW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
33210   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vrotlv16qi3,       "__builtin_ia32_vprotb",      IX86_BUILTIN_VPROTB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
33211   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv2di3,         "__builtin_ia32_vprotqi",     IX86_BUILTIN_VPROTQ_IMM,  UNKNOWN,      (int)MULTI_ARG_2_DI_IMM },
33212   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv4si3,         "__builtin_ia32_vprotdi",     IX86_BUILTIN_VPROTD_IMM,  UNKNOWN,      (int)MULTI_ARG_2_SI_IMM },
33213   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv8hi3,         "__builtin_ia32_vprotwi",     IX86_BUILTIN_VPROTW_IMM,  UNKNOWN,      (int)MULTI_ARG_2_HI_IMM },
33214   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_rotlv16qi3,        "__builtin_ia32_vprotbi",     IX86_BUILTIN_VPROTB_IMM,  UNKNOWN,      (int)MULTI_ARG_2_QI_IMM },
33215   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav2di3,         "__builtin_ia32_vpshaq",      IX86_BUILTIN_VPSHAQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
33216   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav4si3,         "__builtin_ia32_vpshad",      IX86_BUILTIN_VPSHAD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
33217   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav8hi3,         "__builtin_ia32_vpshaw",      IX86_BUILTIN_VPSHAW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
33218   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shav16qi3,        "__builtin_ia32_vpshab",      IX86_BUILTIN_VPSHAB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
33219   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv2di3,         "__builtin_ia32_vpshlq",      IX86_BUILTIN_VPSHLQ,      UNKNOWN,      (int)MULTI_ARG_2_DI },
33220   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv4si3,         "__builtin_ia32_vpshld",      IX86_BUILTIN_VPSHLD,      UNKNOWN,      (int)MULTI_ARG_2_SI },
33221   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv8hi3,         "__builtin_ia32_vpshlw",      IX86_BUILTIN_VPSHLW,      UNKNOWN,      (int)MULTI_ARG_2_HI },
33222   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_shlv16qi3,        "__builtin_ia32_vpshlb",      IX86_BUILTIN_VPSHLB,      UNKNOWN,      (int)MULTI_ARG_2_QI },
33223
33224   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vmfrczv4sf2,       "__builtin_ia32_vfrczss",     IX86_BUILTIN_VFRCZSS,     UNKNOWN,      (int)MULTI_ARG_1_SF },
33225   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vmfrczv2df2,       "__builtin_ia32_vfrczsd",     IX86_BUILTIN_VFRCZSD,     UNKNOWN,      (int)MULTI_ARG_1_DF },
33226   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv4sf2,         "__builtin_ia32_vfrczps",     IX86_BUILTIN_VFRCZPS,     UNKNOWN,      (int)MULTI_ARG_1_SF },
33227   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv2df2,         "__builtin_ia32_vfrczpd",     IX86_BUILTIN_VFRCZPD,     UNKNOWN,      (int)MULTI_ARG_1_DF },
33228   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv8sf2,         "__builtin_ia32_vfrczps256",  IX86_BUILTIN_VFRCZPS256,  UNKNOWN,      (int)MULTI_ARG_1_SF2 },
33229   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_frczv4df2,         "__builtin_ia32_vfrczpd256",  IX86_BUILTIN_VFRCZPD256,  UNKNOWN,      (int)MULTI_ARG_1_DF2 },
33230
33231   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddbw,           "__builtin_ia32_vphaddbw",    IX86_BUILTIN_VPHADDBW,    UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
33232   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddbd,           "__builtin_ia32_vphaddbd",    IX86_BUILTIN_VPHADDBD,    UNKNOWN,      (int)MULTI_ARG_1_QI_SI },
33233   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddbq,           "__builtin_ia32_vphaddbq",    IX86_BUILTIN_VPHADDBQ,    UNKNOWN,      (int)MULTI_ARG_1_QI_DI },
33234   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddwd,           "__builtin_ia32_vphaddwd",    IX86_BUILTIN_VPHADDWD,    UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
33235   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddwq,           "__builtin_ia32_vphaddwq",    IX86_BUILTIN_VPHADDWQ,    UNKNOWN,      (int)MULTI_ARG_1_HI_DI },
33236   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phadddq,           "__builtin_ia32_vphadddq",    IX86_BUILTIN_VPHADDDQ,    UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
33237   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddubw,          "__builtin_ia32_vphaddubw",   IX86_BUILTIN_VPHADDUBW,   UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
33238   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddubd,          "__builtin_ia32_vphaddubd",   IX86_BUILTIN_VPHADDUBD,   UNKNOWN,      (int)MULTI_ARG_1_QI_SI },
33239   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddubq,          "__builtin_ia32_vphaddubq",   IX86_BUILTIN_VPHADDUBQ,   UNKNOWN,      (int)MULTI_ARG_1_QI_DI },
33240   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phadduwd,          "__builtin_ia32_vphadduwd",   IX86_BUILTIN_VPHADDUWD,   UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
33241   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phadduwq,          "__builtin_ia32_vphadduwq",   IX86_BUILTIN_VPHADDUWQ,   UNKNOWN,      (int)MULTI_ARG_1_HI_DI },
33242   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phaddudq,          "__builtin_ia32_vphaddudq",   IX86_BUILTIN_VPHADDUDQ,   UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
33243   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phsubbw,           "__builtin_ia32_vphsubbw",    IX86_BUILTIN_VPHSUBBW,    UNKNOWN,      (int)MULTI_ARG_1_QI_HI },
33244   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phsubwd,           "__builtin_ia32_vphsubwd",    IX86_BUILTIN_VPHSUBWD,    UNKNOWN,      (int)MULTI_ARG_1_HI_SI },
33245   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_phsubdq,           "__builtin_ia32_vphsubdq",    IX86_BUILTIN_VPHSUBDQ,    UNKNOWN,      (int)MULTI_ARG_1_SI_DI },
33246
33247   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomeqb",    IX86_BUILTIN_VPCOMEQB,    EQ,           (int)MULTI_ARG_2_QI_CMP },
33248   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomneb",    IX86_BUILTIN_VPCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
33249   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomneqb",   IX86_BUILTIN_VPCOMNEB,    NE,           (int)MULTI_ARG_2_QI_CMP },
33250   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomltb",    IX86_BUILTIN_VPCOMLTB,    LT,           (int)MULTI_ARG_2_QI_CMP },
33251   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomleb",    IX86_BUILTIN_VPCOMLEB,    LE,           (int)MULTI_ARG_2_QI_CMP },
33252   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomgtb",    IX86_BUILTIN_VPCOMGTB,    GT,           (int)MULTI_ARG_2_QI_CMP },
33253   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv16qi3,     "__builtin_ia32_vpcomgeb",    IX86_BUILTIN_VPCOMGEB,    GE,           (int)MULTI_ARG_2_QI_CMP },
33254
33255   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomeqw",    IX86_BUILTIN_VPCOMEQW,    EQ,           (int)MULTI_ARG_2_HI_CMP },
33256   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomnew",    IX86_BUILTIN_VPCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
33257   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomneqw",   IX86_BUILTIN_VPCOMNEW,    NE,           (int)MULTI_ARG_2_HI_CMP },
33258   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomltw",    IX86_BUILTIN_VPCOMLTW,    LT,           (int)MULTI_ARG_2_HI_CMP },
33259   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomlew",    IX86_BUILTIN_VPCOMLEW,    LE,           (int)MULTI_ARG_2_HI_CMP },
33260   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomgtw",    IX86_BUILTIN_VPCOMGTW,    GT,           (int)MULTI_ARG_2_HI_CMP },
33261   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv8hi3,      "__builtin_ia32_vpcomgew",    IX86_BUILTIN_VPCOMGEW,    GE,           (int)MULTI_ARG_2_HI_CMP },
33262
33263   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomeqd",    IX86_BUILTIN_VPCOMEQD,    EQ,           (int)MULTI_ARG_2_SI_CMP },
33264   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomned",    IX86_BUILTIN_VPCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
33265   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomneqd",   IX86_BUILTIN_VPCOMNED,    NE,           (int)MULTI_ARG_2_SI_CMP },
33266   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomltd",    IX86_BUILTIN_VPCOMLTD,    LT,           (int)MULTI_ARG_2_SI_CMP },
33267   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomled",    IX86_BUILTIN_VPCOMLED,    LE,           (int)MULTI_ARG_2_SI_CMP },
33268   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomgtd",    IX86_BUILTIN_VPCOMGTD,    GT,           (int)MULTI_ARG_2_SI_CMP },
33269   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv4si3,      "__builtin_ia32_vpcomged",    IX86_BUILTIN_VPCOMGED,    GE,           (int)MULTI_ARG_2_SI_CMP },
33270
33271   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomeqq",    IX86_BUILTIN_VPCOMEQQ,    EQ,           (int)MULTI_ARG_2_DI_CMP },
33272   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomneq",    IX86_BUILTIN_VPCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
33273   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomneqq",   IX86_BUILTIN_VPCOMNEQ,    NE,           (int)MULTI_ARG_2_DI_CMP },
33274   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomltq",    IX86_BUILTIN_VPCOMLTQ,    LT,           (int)MULTI_ARG_2_DI_CMP },
33275   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomleq",    IX86_BUILTIN_VPCOMLEQ,    LE,           (int)MULTI_ARG_2_DI_CMP },
33276   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomgtq",    IX86_BUILTIN_VPCOMGTQ,    GT,           (int)MULTI_ARG_2_DI_CMP },
33277   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmpv2di3,      "__builtin_ia32_vpcomgeq",    IX86_BUILTIN_VPCOMGEQ,    GE,           (int)MULTI_ARG_2_DI_CMP },
33278
33279   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v16qi3,"__builtin_ia32_vpcomequb",   IX86_BUILTIN_VPCOMEQUB,   EQ,           (int)MULTI_ARG_2_QI_CMP },
33280   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v16qi3,"__builtin_ia32_vpcomneub",   IX86_BUILTIN_VPCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
33281   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v16qi3,"__builtin_ia32_vpcomnequb",  IX86_BUILTIN_VPCOMNEUB,   NE,           (int)MULTI_ARG_2_QI_CMP },
33282   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomltub",   IX86_BUILTIN_VPCOMLTUB,   LTU,          (int)MULTI_ARG_2_QI_CMP },
33283   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomleub",   IX86_BUILTIN_VPCOMLEUB,   LEU,          (int)MULTI_ARG_2_QI_CMP },
33284   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomgtub",   IX86_BUILTIN_VPCOMGTUB,   GTU,          (int)MULTI_ARG_2_QI_CMP },
33285   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv16qi3, "__builtin_ia32_vpcomgeub",   IX86_BUILTIN_VPCOMGEUB,   GEU,          (int)MULTI_ARG_2_QI_CMP },
33286
33287   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v8hi3, "__builtin_ia32_vpcomequw",   IX86_BUILTIN_VPCOMEQUW,   EQ,           (int)MULTI_ARG_2_HI_CMP },
33288   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v8hi3, "__builtin_ia32_vpcomneuw",   IX86_BUILTIN_VPCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
33289   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v8hi3, "__builtin_ia32_vpcomnequw",  IX86_BUILTIN_VPCOMNEUW,   NE,           (int)MULTI_ARG_2_HI_CMP },
33290   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomltuw",   IX86_BUILTIN_VPCOMLTUW,   LTU,          (int)MULTI_ARG_2_HI_CMP },
33291   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomleuw",   IX86_BUILTIN_VPCOMLEUW,   LEU,          (int)MULTI_ARG_2_HI_CMP },
33292   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomgtuw",   IX86_BUILTIN_VPCOMGTUW,   GTU,          (int)MULTI_ARG_2_HI_CMP },
33293   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv8hi3,  "__builtin_ia32_vpcomgeuw",   IX86_BUILTIN_VPCOMGEUW,   GEU,          (int)MULTI_ARG_2_HI_CMP },
33294
33295   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v4si3, "__builtin_ia32_vpcomequd",   IX86_BUILTIN_VPCOMEQUD,   EQ,           (int)MULTI_ARG_2_SI_CMP },
33296   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v4si3, "__builtin_ia32_vpcomneud",   IX86_BUILTIN_VPCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
33297   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v4si3, "__builtin_ia32_vpcomnequd",  IX86_BUILTIN_VPCOMNEUD,   NE,           (int)MULTI_ARG_2_SI_CMP },
33298   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomltud",   IX86_BUILTIN_VPCOMLTUD,   LTU,          (int)MULTI_ARG_2_SI_CMP },
33299   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomleud",   IX86_BUILTIN_VPCOMLEUD,   LEU,          (int)MULTI_ARG_2_SI_CMP },
33300   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomgtud",   IX86_BUILTIN_VPCOMGTUD,   GTU,          (int)MULTI_ARG_2_SI_CMP },
33301   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv4si3,  "__builtin_ia32_vpcomgeud",   IX86_BUILTIN_VPCOMGEUD,   GEU,          (int)MULTI_ARG_2_SI_CMP },
33302
33303   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v2di3, "__builtin_ia32_vpcomequq",   IX86_BUILTIN_VPCOMEQUQ,   EQ,           (int)MULTI_ARG_2_DI_CMP },
33304   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v2di3, "__builtin_ia32_vpcomneuq",   IX86_BUILTIN_VPCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
33305   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_uns2v2di3, "__builtin_ia32_vpcomnequq",  IX86_BUILTIN_VPCOMNEUQ,   NE,           (int)MULTI_ARG_2_DI_CMP },
33306   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomltuq",   IX86_BUILTIN_VPCOMLTUQ,   LTU,          (int)MULTI_ARG_2_DI_CMP },
33307   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomleuq",   IX86_BUILTIN_VPCOMLEUQ,   LEU,          (int)MULTI_ARG_2_DI_CMP },
33308   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomgtuq",   IX86_BUILTIN_VPCOMGTUQ,   GTU,          (int)MULTI_ARG_2_DI_CMP },
33309   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_maskcmp_unsv2di3,  "__builtin_ia32_vpcomgeuq",   IX86_BUILTIN_VPCOMGEUQ,   GEU,          (int)MULTI_ARG_2_DI_CMP },
33310
33311   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv16qi3,     "__builtin_ia32_vpcomfalseb", IX86_BUILTIN_VPCOMFALSEB, (enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
33312   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv8hi3,      "__builtin_ia32_vpcomfalsew", IX86_BUILTIN_VPCOMFALSEW, (enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
33313   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv4si3,      "__builtin_ia32_vpcomfalsed", IX86_BUILTIN_VPCOMFALSED, (enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
33314   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv2di3,      "__builtin_ia32_vpcomfalseq", IX86_BUILTIN_VPCOMFALSEQ, (enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
33315   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv16qi3,     "__builtin_ia32_vpcomfalseub",IX86_BUILTIN_VPCOMFALSEUB,(enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_QI_TF },
33316   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv8hi3,      "__builtin_ia32_vpcomfalseuw",IX86_BUILTIN_VPCOMFALSEUW,(enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_HI_TF },
33317   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv4si3,      "__builtin_ia32_vpcomfalseud",IX86_BUILTIN_VPCOMFALSEUD,(enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_SI_TF },
33318   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv2di3,      "__builtin_ia32_vpcomfalseuq",IX86_BUILTIN_VPCOMFALSEUQ,(enum rtx_code) PCOM_FALSE,   (int)MULTI_ARG_2_DI_TF },
33319
33320   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv16qi3,     "__builtin_ia32_vpcomtrueb",  IX86_BUILTIN_VPCOMTRUEB,  (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
33321   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv8hi3,      "__builtin_ia32_vpcomtruew",  IX86_BUILTIN_VPCOMTRUEW,  (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
33322   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv4si3,      "__builtin_ia32_vpcomtrued",  IX86_BUILTIN_VPCOMTRUED,  (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
33323   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv2di3,      "__builtin_ia32_vpcomtrueq",  IX86_BUILTIN_VPCOMTRUEQ,  (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
33324   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv16qi3,     "__builtin_ia32_vpcomtrueub", IX86_BUILTIN_VPCOMTRUEUB, (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_QI_TF },
33325   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv8hi3,      "__builtin_ia32_vpcomtrueuw", IX86_BUILTIN_VPCOMTRUEUW, (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_HI_TF },
33326   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv4si3,      "__builtin_ia32_vpcomtrueud", IX86_BUILTIN_VPCOMTRUEUD, (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_SI_TF },
33327   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_pcom_tfv2di3,      "__builtin_ia32_vpcomtrueuq", IX86_BUILTIN_VPCOMTRUEUQ, (enum rtx_code) PCOM_TRUE,    (int)MULTI_ARG_2_DI_TF },
33328
33329   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v2df3,     "__builtin_ia32_vpermil2pd",  IX86_BUILTIN_VPERMIL2PD, UNKNOWN, (int)MULTI_ARG_4_DF2_DI_I },
33330   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v4sf3,     "__builtin_ia32_vpermil2ps",  IX86_BUILTIN_VPERMIL2PS, UNKNOWN, (int)MULTI_ARG_4_SF2_SI_I },
33331   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v4df3,     "__builtin_ia32_vpermil2pd256", IX86_BUILTIN_VPERMIL2PD256, UNKNOWN, (int)MULTI_ARG_4_DF2_DI_I1 },
33332   { OPTION_MASK_ISA_XOP, CODE_FOR_xop_vpermil2v8sf3,     "__builtin_ia32_vpermil2ps256", IX86_BUILTIN_VPERMIL2PS256, UNKNOWN, (int)MULTI_ARG_4_SF2_SI_I1 },
33333
33334 };
33335 \f
33336 /* TM vector builtins.  */
33337
33338 /* Reuse the existing x86-specific `struct builtin_description' cause
33339    we're lazy.  Add casts to make them fit.  */
33340 static const struct builtin_description bdesc_tm[] =
33341 {
33342   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_WM64", (enum ix86_builtins) BUILT_IN_TM_STORE_M64, UNKNOWN, VOID_FTYPE_PV2SI_V2SI },
33343   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_WaRM64", (enum ix86_builtins) BUILT_IN_TM_STORE_WAR_M64, UNKNOWN, VOID_FTYPE_PV2SI_V2SI },
33344   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_WaWM64", (enum ix86_builtins) BUILT_IN_TM_STORE_WAW_M64, UNKNOWN, VOID_FTYPE_PV2SI_V2SI },
33345   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33346   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RaRM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAR_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33347   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RaWM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAW_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33348   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_RfWM64", (enum ix86_builtins) BUILT_IN_TM_LOAD_RFW_M64, UNKNOWN, V2SI_FTYPE_PCV2SI },
33349
33350   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_WM128", (enum ix86_builtins) BUILT_IN_TM_STORE_M128, UNKNOWN, VOID_FTYPE_PV4SF_V4SF },
33351   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_WaRM128", (enum ix86_builtins) BUILT_IN_TM_STORE_WAR_M128, UNKNOWN, VOID_FTYPE_PV4SF_V4SF },
33352   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_WaWM128", (enum ix86_builtins) BUILT_IN_TM_STORE_WAW_M128, UNKNOWN, VOID_FTYPE_PV4SF_V4SF },
33353   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33354   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RaRM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAR_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33355   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RaWM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAW_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33356   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_RfWM128", (enum ix86_builtins) BUILT_IN_TM_LOAD_RFW_M128, UNKNOWN, V4SF_FTYPE_PCV4SF },
33357
33358   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_WM256", (enum ix86_builtins) BUILT_IN_TM_STORE_M256, UNKNOWN, VOID_FTYPE_PV8SF_V8SF },
33359   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_WaRM256", (enum ix86_builtins) BUILT_IN_TM_STORE_WAR_M256, UNKNOWN, VOID_FTYPE_PV8SF_V8SF },
33360   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_WaWM256", (enum ix86_builtins) BUILT_IN_TM_STORE_WAW_M256, UNKNOWN, VOID_FTYPE_PV8SF_V8SF },
33361   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33362   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RaRM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAR_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33363   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RaWM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_RAW_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33364   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_RfWM256", (enum ix86_builtins) BUILT_IN_TM_LOAD_RFW_M256, UNKNOWN, V8SF_FTYPE_PCV8SF },
33365
33366   { OPTION_MASK_ISA_MMX, CODE_FOR_nothing, "__builtin__ITM_LM64", (enum ix86_builtins) BUILT_IN_TM_LOG_M64, UNKNOWN, VOID_FTYPE_PCVOID },
33367   { OPTION_MASK_ISA_SSE, CODE_FOR_nothing, "__builtin__ITM_LM128", (enum ix86_builtins) BUILT_IN_TM_LOG_M128, UNKNOWN, VOID_FTYPE_PCVOID },
33368   { OPTION_MASK_ISA_AVX, CODE_FOR_nothing, "__builtin__ITM_LM256", (enum ix86_builtins) BUILT_IN_TM_LOG_M256, UNKNOWN, VOID_FTYPE_PCVOID },
33369 };
33370
33371 /* TM callbacks.  */
33372
33373 /* Return the builtin decl needed to load a vector of TYPE.  */
33374
33375 static tree
33376 ix86_builtin_tm_load (tree type)
33377 {
33378   if (TREE_CODE (type) == VECTOR_TYPE)
33379     {
33380       switch (tree_to_uhwi (TYPE_SIZE (type)))
33381         {
33382         case 64:
33383           return builtin_decl_explicit (BUILT_IN_TM_LOAD_M64);
33384         case 128:
33385           return builtin_decl_explicit (BUILT_IN_TM_LOAD_M128);
33386         case 256:
33387           return builtin_decl_explicit (BUILT_IN_TM_LOAD_M256);
33388         }
33389     }
33390   return NULL_TREE;
33391 }
33392
33393 /* Return the builtin decl needed to store a vector of TYPE.  */
33394
33395 static tree
33396 ix86_builtin_tm_store (tree type)
33397 {
33398   if (TREE_CODE (type) == VECTOR_TYPE)
33399     {
33400       switch (tree_to_uhwi (TYPE_SIZE (type)))
33401         {
33402         case 64:
33403           return builtin_decl_explicit (BUILT_IN_TM_STORE_M64);
33404         case 128:
33405           return builtin_decl_explicit (BUILT_IN_TM_STORE_M128);
33406         case 256:
33407           return builtin_decl_explicit (BUILT_IN_TM_STORE_M256);
33408         }
33409     }
33410   return NULL_TREE;
33411 }
33412 \f
33413 /* Initialize the transactional memory vector load/store builtins.  */
33414
33415 static void
33416 ix86_init_tm_builtins (void)
33417 {
33418   enum ix86_builtin_func_type ftype;
33419   const struct builtin_description *d;
33420   size_t i;
33421   tree decl;
33422   tree attrs_load, attrs_type_load, attrs_store, attrs_type_store;
33423   tree attrs_log, attrs_type_log;
33424
33425   if (!flag_tm)
33426     return;
33427
33428   /* If there are no builtins defined, we must be compiling in a
33429      language without trans-mem support.  */
33430   if (!builtin_decl_explicit_p (BUILT_IN_TM_LOAD_1))
33431     return;
33432
33433   /* Use whatever attributes a normal TM load has.  */
33434   decl = builtin_decl_explicit (BUILT_IN_TM_LOAD_1);
33435   attrs_load = DECL_ATTRIBUTES (decl);
33436   attrs_type_load = TYPE_ATTRIBUTES (TREE_TYPE (decl));
33437   /* Use whatever attributes a normal TM store has.  */
33438   decl = builtin_decl_explicit (BUILT_IN_TM_STORE_1);
33439   attrs_store = DECL_ATTRIBUTES (decl);
33440   attrs_type_store = TYPE_ATTRIBUTES (TREE_TYPE (decl));
33441   /* Use whatever attributes a normal TM log has.  */
33442   decl = builtin_decl_explicit (BUILT_IN_TM_LOG);
33443   attrs_log = DECL_ATTRIBUTES (decl);
33444   attrs_type_log = TYPE_ATTRIBUTES (TREE_TYPE (decl));
33445
33446   for (i = 0, d = bdesc_tm;
33447        i < ARRAY_SIZE (bdesc_tm);
33448        i++, d++)
33449     {
33450       if ((d->mask & ix86_isa_flags) != 0
33451           || (lang_hooks.builtin_function
33452               == lang_hooks.builtin_function_ext_scope))
33453         {
33454           tree type, attrs, attrs_type;
33455           enum built_in_function code = (enum built_in_function) d->code;
33456
33457           ftype = (enum ix86_builtin_func_type) d->flag;
33458           type = ix86_get_builtin_func_type (ftype);
33459
33460           if (BUILTIN_TM_LOAD_P (code))
33461             {
33462               attrs = attrs_load;
33463               attrs_type = attrs_type_load;
33464             }
33465           else if (BUILTIN_TM_STORE_P (code))
33466             {
33467               attrs = attrs_store;
33468               attrs_type = attrs_type_store;
33469             }
33470           else
33471             {
33472               attrs = attrs_log;
33473               attrs_type = attrs_type_log;
33474             }
33475           decl = add_builtin_function (d->name, type, code, BUILT_IN_NORMAL,
33476                                        /* The builtin without the prefix for
33477                                           calling it directly.  */
33478                                        d->name + strlen ("__builtin_"),
33479                                        attrs);
33480           /* add_builtin_function() will set the DECL_ATTRIBUTES, now
33481              set the TYPE_ATTRIBUTES.  */
33482           decl_attributes (&TREE_TYPE (decl), attrs_type, ATTR_FLAG_BUILT_IN);
33483
33484           set_builtin_decl (code, decl, false);
33485         }
33486     }
33487 }
33488
33489 /* Set up all the MMX/SSE builtins, even builtins for instructions that are not
33490    in the current target ISA to allow the user to compile particular modules
33491    with different target specific options that differ from the command line
33492    options.  */
33493 static void
33494 ix86_init_mmx_sse_builtins (void)
33495 {
33496   const struct builtin_description * d;
33497   enum ix86_builtin_func_type ftype;
33498   size_t i;
33499
33500   /* Add all special builtins with variable number of operands.  */
33501   for (i = 0, d = bdesc_special_args;
33502        i < ARRAY_SIZE (bdesc_special_args);
33503        i++, d++)
33504     {
33505       if (d->name == 0)
33506         continue;
33507
33508       ftype = (enum ix86_builtin_func_type) d->flag;
33509       def_builtin (d->mask, d->name, ftype, d->code);
33510     }
33511
33512   /* Add all builtins with variable number of operands.  */
33513   for (i = 0, d = bdesc_args;
33514        i < ARRAY_SIZE (bdesc_args);
33515        i++, d++)
33516     {
33517       if (d->name == 0)
33518         continue;
33519
33520       ftype = (enum ix86_builtin_func_type) d->flag;
33521       def_builtin_const (d->mask, d->name, ftype, d->code);
33522     }
33523
33524   /* Add all builtins with rounding.  */
33525   for (i = 0, d = bdesc_round_args;
33526        i < ARRAY_SIZE (bdesc_round_args);
33527        i++, d++)
33528     {
33529       if (d->name == 0)
33530         continue;
33531
33532       ftype = (enum ix86_builtin_func_type) d->flag;
33533       def_builtin_const (d->mask, d->name, ftype, d->code);
33534     }
33535
33536   /* pcmpestr[im] insns.  */
33537   for (i = 0, d = bdesc_pcmpestr;
33538        i < ARRAY_SIZE (bdesc_pcmpestr);
33539        i++, d++)
33540     {
33541       if (d->code == IX86_BUILTIN_PCMPESTRM128)
33542         ftype = V16QI_FTYPE_V16QI_INT_V16QI_INT_INT;
33543       else
33544         ftype = INT_FTYPE_V16QI_INT_V16QI_INT_INT;
33545       def_builtin_const (d->mask, d->name, ftype, d->code);
33546     }
33547
33548   /* pcmpistr[im] insns.  */
33549   for (i = 0, d = bdesc_pcmpistr;
33550        i < ARRAY_SIZE (bdesc_pcmpistr);
33551        i++, d++)
33552     {
33553       if (d->code == IX86_BUILTIN_PCMPISTRM128)
33554         ftype = V16QI_FTYPE_V16QI_V16QI_INT;
33555       else
33556         ftype = INT_FTYPE_V16QI_V16QI_INT;
33557       def_builtin_const (d->mask, d->name, ftype, d->code);
33558     }
33559
33560   /* comi/ucomi insns.  */
33561   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
33562     {
33563       if (d->mask == OPTION_MASK_ISA_SSE2)
33564         ftype = INT_FTYPE_V2DF_V2DF;
33565       else
33566         ftype = INT_FTYPE_V4SF_V4SF;
33567       def_builtin_const (d->mask, d->name, ftype, d->code);
33568     }
33569
33570   /* SSE */
33571   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_ldmxcsr",
33572                VOID_FTYPE_UNSIGNED, IX86_BUILTIN_LDMXCSR);
33573   def_builtin (OPTION_MASK_ISA_SSE, "__builtin_ia32_stmxcsr",
33574                UNSIGNED_FTYPE_VOID, IX86_BUILTIN_STMXCSR);
33575
33576   /* SSE or 3DNow!A */
33577   def_builtin (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
33578                "__builtin_ia32_maskmovq", VOID_FTYPE_V8QI_V8QI_PCHAR,
33579                IX86_BUILTIN_MASKMOVQ);
33580
33581   /* SSE2 */
33582   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_maskmovdqu",
33583                VOID_FTYPE_V16QI_V16QI_PCHAR, IX86_BUILTIN_MASKMOVDQU);
33584
33585   def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_clflush",
33586                VOID_FTYPE_PCVOID, IX86_BUILTIN_CLFLUSH);
33587   x86_mfence = def_builtin (OPTION_MASK_ISA_SSE2, "__builtin_ia32_mfence",
33588                             VOID_FTYPE_VOID, IX86_BUILTIN_MFENCE);
33589
33590   /* SSE3.  */
33591   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_monitor",
33592                VOID_FTYPE_PCVOID_UNSIGNED_UNSIGNED, IX86_BUILTIN_MONITOR);
33593   def_builtin (OPTION_MASK_ISA_SSE3, "__builtin_ia32_mwait",
33594                VOID_FTYPE_UNSIGNED_UNSIGNED, IX86_BUILTIN_MWAIT);
33595
33596   /* AES */
33597   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenc128",
33598                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESENC128);
33599   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesenclast128",
33600                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESENCLAST128);
33601   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdec128",
33602                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESDEC128);
33603   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesdeclast128",
33604                      V2DI_FTYPE_V2DI_V2DI, IX86_BUILTIN_AESDECLAST128);
33605   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aesimc128",
33606                      V2DI_FTYPE_V2DI, IX86_BUILTIN_AESIMC128);
33607   def_builtin_const (OPTION_MASK_ISA_AES, "__builtin_ia32_aeskeygenassist128",
33608                      V2DI_FTYPE_V2DI_INT, IX86_BUILTIN_AESKEYGENASSIST128);
33609
33610   /* PCLMUL */
33611   def_builtin_const (OPTION_MASK_ISA_PCLMUL, "__builtin_ia32_pclmulqdq128",
33612                      V2DI_FTYPE_V2DI_V2DI_INT, IX86_BUILTIN_PCLMULQDQ128);
33613
33614   /* RDRND */
33615   def_builtin (OPTION_MASK_ISA_RDRND, "__builtin_ia32_rdrand16_step",
33616                INT_FTYPE_PUSHORT, IX86_BUILTIN_RDRAND16_STEP);
33617   def_builtin (OPTION_MASK_ISA_RDRND, "__builtin_ia32_rdrand32_step",
33618                INT_FTYPE_PUNSIGNED, IX86_BUILTIN_RDRAND32_STEP);
33619   def_builtin (OPTION_MASK_ISA_RDRND | OPTION_MASK_ISA_64BIT,
33620                "__builtin_ia32_rdrand64_step", INT_FTYPE_PULONGLONG,
33621                IX86_BUILTIN_RDRAND64_STEP);
33622
33623   /* AVX2 */
33624   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv2df",
33625                V2DF_FTYPE_V2DF_PCDOUBLE_V4SI_V2DF_INT,
33626                IX86_BUILTIN_GATHERSIV2DF);
33627
33628   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4df",
33629                V4DF_FTYPE_V4DF_PCDOUBLE_V4SI_V4DF_INT,
33630                IX86_BUILTIN_GATHERSIV4DF);
33631
33632   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv2df",
33633                V2DF_FTYPE_V2DF_PCDOUBLE_V2DI_V2DF_INT,
33634                IX86_BUILTIN_GATHERDIV2DF);
33635
33636   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4df",
33637                V4DF_FTYPE_V4DF_PCDOUBLE_V4DI_V4DF_INT,
33638                IX86_BUILTIN_GATHERDIV4DF);
33639
33640   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4sf",
33641                V4SF_FTYPE_V4SF_PCFLOAT_V4SI_V4SF_INT,
33642                IX86_BUILTIN_GATHERSIV4SF);
33643
33644   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv8sf",
33645                V8SF_FTYPE_V8SF_PCFLOAT_V8SI_V8SF_INT,
33646                IX86_BUILTIN_GATHERSIV8SF);
33647
33648   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4sf",
33649                V4SF_FTYPE_V4SF_PCFLOAT_V2DI_V4SF_INT,
33650                IX86_BUILTIN_GATHERDIV4SF);
33651
33652   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4sf256",
33653                V4SF_FTYPE_V4SF_PCFLOAT_V4DI_V4SF_INT,
33654                IX86_BUILTIN_GATHERDIV8SF);
33655
33656   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv2di",
33657                V2DI_FTYPE_V2DI_PCINT64_V4SI_V2DI_INT,
33658                IX86_BUILTIN_GATHERSIV2DI);
33659
33660   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4di",
33661                V4DI_FTYPE_V4DI_PCINT64_V4SI_V4DI_INT,
33662                IX86_BUILTIN_GATHERSIV4DI);
33663
33664   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv2di",
33665                V2DI_FTYPE_V2DI_PCINT64_V2DI_V2DI_INT,
33666                IX86_BUILTIN_GATHERDIV2DI);
33667
33668   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4di",
33669                V4DI_FTYPE_V4DI_PCINT64_V4DI_V4DI_INT,
33670                IX86_BUILTIN_GATHERDIV4DI);
33671
33672   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv4si",
33673                V4SI_FTYPE_V4SI_PCINT_V4SI_V4SI_INT,
33674                IX86_BUILTIN_GATHERSIV4SI);
33675
33676   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gathersiv8si",
33677                V8SI_FTYPE_V8SI_PCINT_V8SI_V8SI_INT,
33678                IX86_BUILTIN_GATHERSIV8SI);
33679
33680   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4si",
33681                V4SI_FTYPE_V4SI_PCINT_V2DI_V4SI_INT,
33682                IX86_BUILTIN_GATHERDIV4SI);
33683
33684   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatherdiv4si256",
33685                V4SI_FTYPE_V4SI_PCINT_V4DI_V4SI_INT,
33686                IX86_BUILTIN_GATHERDIV8SI);
33687
33688   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4df ",
33689                V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_V4DF_INT,
33690                IX86_BUILTIN_GATHERALTSIV4DF);
33691
33692   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4sf256 ",
33693                V8SF_FTYPE_V8SF_PCFLOAT_V4DI_V8SF_INT,
33694                IX86_BUILTIN_GATHERALTDIV8SF);
33695
33696   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltsiv4di ",
33697                V4DI_FTYPE_V4DI_PCINT64_V8SI_V4DI_INT,
33698                IX86_BUILTIN_GATHERALTSIV4DI);
33699
33700   def_builtin (OPTION_MASK_ISA_AVX2, "__builtin_ia32_gatheraltdiv4si256 ",
33701                V8SI_FTYPE_V8SI_PCINT_V4DI_V8SI_INT,
33702                IX86_BUILTIN_GATHERALTDIV8SI);
33703
33704   /* AVX512F */
33705   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv16sf",
33706                V16SF_FTYPE_V16SF_PCFLOAT_V16SI_HI_INT,
33707                IX86_BUILTIN_GATHER3SIV16SF);
33708
33709   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv8df",
33710                V8DF_FTYPE_V8DF_PCDOUBLE_V8SI_QI_INT,
33711                IX86_BUILTIN_GATHER3SIV8DF);
33712
33713   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv16sf",
33714                V8SF_FTYPE_V8SF_PCFLOAT_V8DI_QI_INT,
33715                IX86_BUILTIN_GATHER3DIV16SF);
33716
33717   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv8df",
33718                V8DF_FTYPE_V8DF_PCDOUBLE_V8DI_QI_INT,
33719                IX86_BUILTIN_GATHER3DIV8DF);
33720
33721   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv16si",
33722                V16SI_FTYPE_V16SI_PCINT_V16SI_HI_INT,
33723                IX86_BUILTIN_GATHER3SIV16SI);
33724
33725   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gathersiv8di",
33726                V8DI_FTYPE_V8DI_PCINT64_V8SI_QI_INT,
33727                IX86_BUILTIN_GATHER3SIV8DI);
33728
33729   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv16si",
33730                V8SI_FTYPE_V8SI_PCINT_V8DI_QI_INT,
33731                IX86_BUILTIN_GATHER3DIV16SI);
33732
33733   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatherdiv8di",
33734                V8DI_FTYPE_V8DI_PCINT64_V8DI_QI_INT,
33735                IX86_BUILTIN_GATHER3DIV8DI);
33736
33737   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8df ",
33738                V8DF_FTYPE_V8DF_PCDOUBLE_V16SI_QI_INT,
33739                IX86_BUILTIN_GATHER3ALTSIV8DF);
33740
33741   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8sf ",
33742                V16SF_FTYPE_V16SF_PCFLOAT_V8DI_HI_INT,
33743                IX86_BUILTIN_GATHER3ALTDIV16SF);
33744
33745   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltsiv8di ",
33746                V8DI_FTYPE_V8DI_PCINT64_V16SI_QI_INT,
33747                IX86_BUILTIN_GATHER3ALTSIV8DI);
33748
33749   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_gatheraltdiv8si ",
33750                V16SI_FTYPE_V16SI_PCINT_V8DI_HI_INT,
33751                IX86_BUILTIN_GATHER3ALTDIV16SI);
33752
33753   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv16sf",
33754                VOID_FTYPE_PFLOAT_HI_V16SI_V16SF_INT,
33755                IX86_BUILTIN_SCATTERSIV16SF);
33756
33757   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv8df",
33758                VOID_FTYPE_PDOUBLE_QI_V8SI_V8DF_INT,
33759                IX86_BUILTIN_SCATTERSIV8DF);
33760
33761   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv16sf",
33762                VOID_FTYPE_PFLOAT_QI_V8DI_V8SF_INT,
33763                IX86_BUILTIN_SCATTERDIV16SF);
33764
33765   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv8df",
33766                VOID_FTYPE_PDOUBLE_QI_V8DI_V8DF_INT,
33767                IX86_BUILTIN_SCATTERDIV8DF);
33768
33769   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv16si",
33770                VOID_FTYPE_PINT_HI_V16SI_V16SI_INT,
33771                IX86_BUILTIN_SCATTERSIV16SI);
33772
33773   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scattersiv8di",
33774                VOID_FTYPE_PLONGLONG_QI_V8SI_V8DI_INT,
33775                IX86_BUILTIN_SCATTERSIV8DI);
33776
33777   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv16si",
33778                VOID_FTYPE_PINT_QI_V8DI_V8SI_INT,
33779                IX86_BUILTIN_SCATTERDIV16SI);
33780
33781   def_builtin (OPTION_MASK_ISA_AVX512F, "__builtin_ia32_scatterdiv8di",
33782                VOID_FTYPE_PLONGLONG_QI_V8DI_V8DI_INT,
33783                IX86_BUILTIN_SCATTERDIV8DI);
33784
33785   /* AVX512VL */
33786   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv2df",
33787                V2DF_FTYPE_V2DF_PCDOUBLE_V4SI_QI_INT,
33788                IX86_BUILTIN_GATHER3SIV2DF);
33789
33790   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4df",
33791                V4DF_FTYPE_V4DF_PCDOUBLE_V4SI_QI_INT,
33792                IX86_BUILTIN_GATHER3SIV4DF);
33793
33794   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div2df",
33795                V2DF_FTYPE_V2DF_PCDOUBLE_V2DI_QI_INT,
33796                IX86_BUILTIN_GATHER3DIV2DF);
33797
33798   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4df",
33799                V4DF_FTYPE_V4DF_PCDOUBLE_V4DI_QI_INT,
33800                IX86_BUILTIN_GATHER3DIV4DF);
33801
33802   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4sf",
33803                V4SF_FTYPE_V4SF_PCFLOAT_V4SI_QI_INT,
33804                IX86_BUILTIN_GATHER3SIV4SF);
33805
33806   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv8sf",
33807                V8SF_FTYPE_V8SF_PCFLOAT_V8SI_QI_INT,
33808                IX86_BUILTIN_GATHER3SIV8SF);
33809
33810   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4sf",
33811                V4SF_FTYPE_V4SF_PCFLOAT_V2DI_QI_INT,
33812                IX86_BUILTIN_GATHER3DIV4SF);
33813
33814   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div8sf",
33815                V4SF_FTYPE_V4SF_PCFLOAT_V4DI_QI_INT,
33816                IX86_BUILTIN_GATHER3DIV8SF);
33817
33818   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv2di",
33819                V2DI_FTYPE_V2DI_PCINT64_V4SI_QI_INT,
33820                IX86_BUILTIN_GATHER3SIV2DI);
33821
33822   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4di",
33823                V4DI_FTYPE_V4DI_PCINT64_V4SI_QI_INT,
33824                IX86_BUILTIN_GATHER3SIV4DI);
33825
33826   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div2di",
33827                V2DI_FTYPE_V2DI_PCINT64_V2DI_QI_INT,
33828                IX86_BUILTIN_GATHER3DIV2DI);
33829
33830   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4di",
33831                V4DI_FTYPE_V4DI_PCINT64_V4DI_QI_INT,
33832                IX86_BUILTIN_GATHER3DIV4DI);
33833
33834   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv4si",
33835                V4SI_FTYPE_V4SI_PCINT_V4SI_QI_INT,
33836                IX86_BUILTIN_GATHER3SIV4SI);
33837
33838   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3siv8si",
33839                V8SI_FTYPE_V8SI_PCINT_V8SI_QI_INT,
33840                IX86_BUILTIN_GATHER3SIV8SI);
33841
33842   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div4si",
33843                V4SI_FTYPE_V4SI_PCINT_V2DI_QI_INT,
33844                IX86_BUILTIN_GATHER3DIV4SI);
33845
33846   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3div8si",
33847                V4SI_FTYPE_V4SI_PCINT_V4DI_QI_INT,
33848                IX86_BUILTIN_GATHER3DIV8SI);
33849
33850   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4df ",
33851                V4DF_FTYPE_V4DF_PCDOUBLE_V8SI_QI_INT,
33852                IX86_BUILTIN_GATHER3ALTSIV4DF);
33853
33854   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8sf ",
33855                V8SF_FTYPE_V8SF_PCFLOAT_V4DI_QI_INT,
33856                IX86_BUILTIN_GATHER3ALTDIV8SF);
33857
33858   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altsiv4di ",
33859                V4DI_FTYPE_V4DI_PCINT64_V8SI_QI_INT,
33860                IX86_BUILTIN_GATHER3ALTSIV4DI);
33861
33862   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_gather3altdiv8si ",
33863                V8SI_FTYPE_V8SI_PCINT_V4DI_QI_INT,
33864                IX86_BUILTIN_GATHER3ALTDIV8SI);
33865
33866   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv8sf",
33867                VOID_FTYPE_PFLOAT_QI_V8SI_V8SF_INT,
33868                IX86_BUILTIN_SCATTERSIV8SF);
33869
33870   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4sf",
33871                VOID_FTYPE_PFLOAT_QI_V4SI_V4SF_INT,
33872                IX86_BUILTIN_SCATTERSIV4SF);
33873
33874   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4df",
33875                VOID_FTYPE_PDOUBLE_QI_V4SI_V4DF_INT,
33876                IX86_BUILTIN_SCATTERSIV4DF);
33877
33878   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv2df",
33879                VOID_FTYPE_PDOUBLE_QI_V4SI_V2DF_INT,
33880                IX86_BUILTIN_SCATTERSIV2DF);
33881
33882   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv8sf",
33883                VOID_FTYPE_PFLOAT_QI_V4DI_V4SF_INT,
33884                IX86_BUILTIN_SCATTERDIV8SF);
33885
33886   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4sf",
33887                VOID_FTYPE_PFLOAT_QI_V2DI_V4SF_INT,
33888                IX86_BUILTIN_SCATTERDIV4SF);
33889
33890   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4df",
33891                VOID_FTYPE_PDOUBLE_QI_V4DI_V4DF_INT,
33892                IX86_BUILTIN_SCATTERDIV4DF);
33893
33894   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv2df",
33895                VOID_FTYPE_PDOUBLE_QI_V2DI_V2DF_INT,
33896                IX86_BUILTIN_SCATTERDIV2DF);
33897
33898   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv8si",
33899                VOID_FTYPE_PINT_QI_V8SI_V8SI_INT,
33900                IX86_BUILTIN_SCATTERSIV8SI);
33901
33902   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4si",
33903                VOID_FTYPE_PINT_QI_V4SI_V4SI_INT,
33904                IX86_BUILTIN_SCATTERSIV4SI);
33905
33906   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv4di",
33907                VOID_FTYPE_PLONGLONG_QI_V4SI_V4DI_INT,
33908                IX86_BUILTIN_SCATTERSIV4DI);
33909
33910   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scattersiv2di",
33911                VOID_FTYPE_PLONGLONG_QI_V4SI_V2DI_INT,
33912                IX86_BUILTIN_SCATTERSIV2DI);
33913
33914   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv8si",
33915                VOID_FTYPE_PINT_QI_V4DI_V4SI_INT,
33916                IX86_BUILTIN_SCATTERDIV8SI);
33917
33918   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4si",
33919                VOID_FTYPE_PINT_QI_V2DI_V4SI_INT,
33920                IX86_BUILTIN_SCATTERDIV4SI);
33921
33922   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv4di",
33923                VOID_FTYPE_PLONGLONG_QI_V4DI_V4DI_INT,
33924                IX86_BUILTIN_SCATTERDIV4DI);
33925
33926   def_builtin (OPTION_MASK_ISA_AVX512VL, "__builtin_ia32_scatterdiv2di",
33927                VOID_FTYPE_PLONGLONG_QI_V2DI_V2DI_INT,
33928                IX86_BUILTIN_SCATTERDIV2DI);
33929
33930   /* AVX512PF */
33931   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfdpd",
33932                VOID_FTYPE_QI_V8SI_PCINT64_INT_INT,
33933                IX86_BUILTIN_GATHERPFDPD);
33934   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfdps",
33935                VOID_FTYPE_HI_V16SI_PCINT_INT_INT,
33936                IX86_BUILTIN_GATHERPFDPS);
33937   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfqpd",
33938                VOID_FTYPE_QI_V8DI_PCINT64_INT_INT,
33939                IX86_BUILTIN_GATHERPFQPD);
33940   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_gatherpfqps",
33941                VOID_FTYPE_QI_V8DI_PCINT_INT_INT,
33942                IX86_BUILTIN_GATHERPFQPS);
33943   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfdpd",
33944                VOID_FTYPE_QI_V8SI_PCINT64_INT_INT,
33945                IX86_BUILTIN_SCATTERPFDPD);
33946   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfdps",
33947                VOID_FTYPE_HI_V16SI_PCINT_INT_INT,
33948                IX86_BUILTIN_SCATTERPFDPS);
33949   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfqpd",
33950                VOID_FTYPE_QI_V8DI_PCINT64_INT_INT,
33951                IX86_BUILTIN_SCATTERPFQPD);
33952   def_builtin (OPTION_MASK_ISA_AVX512PF, "__builtin_ia32_scatterpfqps",
33953                VOID_FTYPE_QI_V8DI_PCINT_INT_INT,
33954                IX86_BUILTIN_SCATTERPFQPS);
33955
33956   /* SHA */
33957   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1msg1",
33958                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA1MSG1);
33959   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1msg2",
33960                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA1MSG2);
33961   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1nexte",
33962                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA1NEXTE);
33963   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha1rnds4",
33964                      V4SI_FTYPE_V4SI_V4SI_INT, IX86_BUILTIN_SHA1RNDS4);
33965   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha256msg1",
33966                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA256MSG1);
33967   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha256msg2",
33968                      V4SI_FTYPE_V4SI_V4SI, IX86_BUILTIN_SHA256MSG2);
33969   def_builtin_const (OPTION_MASK_ISA_SHA, "__builtin_ia32_sha256rnds2",
33970                      V4SI_FTYPE_V4SI_V4SI_V4SI, IX86_BUILTIN_SHA256RNDS2);
33971
33972   /* RTM.  */
33973   def_builtin (OPTION_MASK_ISA_RTM, "__builtin_ia32_xabort",
33974                VOID_FTYPE_UNSIGNED, IX86_BUILTIN_XABORT);
33975
33976   /* MMX access to the vec_init patterns.  */
33977   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v2si",
33978                      V2SI_FTYPE_INT_INT, IX86_BUILTIN_VEC_INIT_V2SI);
33979
33980   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v4hi",
33981                      V4HI_FTYPE_HI_HI_HI_HI,
33982                      IX86_BUILTIN_VEC_INIT_V4HI);
33983
33984   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_init_v8qi",
33985                      V8QI_FTYPE_QI_QI_QI_QI_QI_QI_QI_QI,
33986                      IX86_BUILTIN_VEC_INIT_V8QI);
33987
33988   /* Access to the vec_extract patterns.  */
33989   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2df",
33990                      DOUBLE_FTYPE_V2DF_INT, IX86_BUILTIN_VEC_EXT_V2DF);
33991   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v2di",
33992                      DI_FTYPE_V2DI_INT, IX86_BUILTIN_VEC_EXT_V2DI);
33993   def_builtin_const (OPTION_MASK_ISA_SSE, "__builtin_ia32_vec_ext_v4sf",
33994                      FLOAT_FTYPE_V4SF_INT, IX86_BUILTIN_VEC_EXT_V4SF);
33995   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v4si",
33996                      SI_FTYPE_V4SI_INT, IX86_BUILTIN_VEC_EXT_V4SI);
33997   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v8hi",
33998                      HI_FTYPE_V8HI_INT, IX86_BUILTIN_VEC_EXT_V8HI);
33999
34000   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
34001                      "__builtin_ia32_vec_ext_v4hi",
34002                      HI_FTYPE_V4HI_INT, IX86_BUILTIN_VEC_EXT_V4HI);
34003
34004   def_builtin_const (OPTION_MASK_ISA_MMX, "__builtin_ia32_vec_ext_v2si",
34005                      SI_FTYPE_V2SI_INT, IX86_BUILTIN_VEC_EXT_V2SI);
34006
34007   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_ext_v16qi",
34008                      QI_FTYPE_V16QI_INT, IX86_BUILTIN_VEC_EXT_V16QI);
34009
34010   /* Access to the vec_set patterns.  */
34011   def_builtin_const (OPTION_MASK_ISA_SSE4_1 | OPTION_MASK_ISA_64BIT,
34012                      "__builtin_ia32_vec_set_v2di",
34013                      V2DI_FTYPE_V2DI_DI_INT, IX86_BUILTIN_VEC_SET_V2DI);
34014
34015   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4sf",
34016                      V4SF_FTYPE_V4SF_FLOAT_INT, IX86_BUILTIN_VEC_SET_V4SF);
34017
34018   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v4si",
34019                      V4SI_FTYPE_V4SI_SI_INT, IX86_BUILTIN_VEC_SET_V4SI);
34020
34021   def_builtin_const (OPTION_MASK_ISA_SSE2, "__builtin_ia32_vec_set_v8hi",
34022                      V8HI_FTYPE_V8HI_HI_INT, IX86_BUILTIN_VEC_SET_V8HI);
34023
34024   def_builtin_const (OPTION_MASK_ISA_SSE | OPTION_MASK_ISA_3DNOW_A,
34025                      "__builtin_ia32_vec_set_v4hi",
34026                      V4HI_FTYPE_V4HI_HI_INT, IX86_BUILTIN_VEC_SET_V4HI);
34027
34028   def_builtin_const (OPTION_MASK_ISA_SSE4_1, "__builtin_ia32_vec_set_v16qi",
34029                      V16QI_FTYPE_V16QI_QI_INT, IX86_BUILTIN_VEC_SET_V16QI);
34030
34031   /* RDSEED */
34032   def_builtin (OPTION_MASK_ISA_RDSEED, "__builtin_ia32_rdseed_hi_step",
34033                INT_FTYPE_PUSHORT, IX86_BUILTIN_RDSEED16_STEP);
34034   def_builtin (OPTION_MASK_ISA_RDSEED, "__builtin_ia32_rdseed_si_step",
34035                INT_FTYPE_PUNSIGNED, IX86_BUILTIN_RDSEED32_STEP);
34036   def_builtin (OPTION_MASK_ISA_RDSEED | OPTION_MASK_ISA_64BIT,
34037                "__builtin_ia32_rdseed_di_step",
34038                INT_FTYPE_PULONGLONG, IX86_BUILTIN_RDSEED64_STEP);
34039
34040   /* ADCX */
34041   def_builtin (0, "__builtin_ia32_addcarryx_u32",
34042                UCHAR_FTYPE_UCHAR_UINT_UINT_PUNSIGNED, IX86_BUILTIN_ADDCARRYX32);
34043   def_builtin (OPTION_MASK_ISA_64BIT,
34044                "__builtin_ia32_addcarryx_u64",
34045                UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PULONGLONG,
34046                IX86_BUILTIN_ADDCARRYX64);
34047
34048   /* SBB */
34049   def_builtin (0, "__builtin_ia32_sbb_u32",
34050                UCHAR_FTYPE_UCHAR_UINT_UINT_PUNSIGNED, IX86_BUILTIN_SBB32);
34051   def_builtin (OPTION_MASK_ISA_64BIT,
34052                "__builtin_ia32_sbb_u64",
34053                UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PULONGLONG,
34054                IX86_BUILTIN_SBB64);
34055
34056   /* Read/write FLAGS.  */
34057   def_builtin (~OPTION_MASK_ISA_64BIT, "__builtin_ia32_readeflags_u32",
34058                UNSIGNED_FTYPE_VOID, IX86_BUILTIN_READ_FLAGS);
34059   def_builtin (OPTION_MASK_ISA_64BIT, "__builtin_ia32_readeflags_u64",
34060                UINT64_FTYPE_VOID, IX86_BUILTIN_READ_FLAGS);
34061   def_builtin (~OPTION_MASK_ISA_64BIT, "__builtin_ia32_writeeflags_u32",
34062                VOID_FTYPE_UNSIGNED, IX86_BUILTIN_WRITE_FLAGS);
34063   def_builtin (OPTION_MASK_ISA_64BIT, "__builtin_ia32_writeeflags_u64",
34064                VOID_FTYPE_UINT64, IX86_BUILTIN_WRITE_FLAGS);
34065
34066   /* CLFLUSHOPT.  */
34067   def_builtin (OPTION_MASK_ISA_CLFLUSHOPT, "__builtin_ia32_clflushopt",
34068                VOID_FTYPE_PCVOID, IX86_BUILTIN_CLFLUSHOPT);
34069
34070   /* CLWB.  */
34071   def_builtin (OPTION_MASK_ISA_CLWB, "__builtin_ia32_clwb",
34072                VOID_FTYPE_PCVOID, IX86_BUILTIN_CLWB);
34073
34074   /* Add FMA4 multi-arg argument instructions */
34075   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
34076     {
34077       if (d->name == 0)
34078         continue;
34079
34080       ftype = (enum ix86_builtin_func_type) d->flag;
34081       def_builtin_const (d->mask, d->name, ftype, d->code);
34082     }
34083 }
34084
34085 static void
34086 ix86_init_mpx_builtins ()
34087 {
34088   const struct builtin_description * d;
34089   enum ix86_builtin_func_type ftype;
34090   tree decl;
34091   size_t i;
34092
34093   for (i = 0, d = bdesc_mpx;
34094        i < ARRAY_SIZE (bdesc_mpx);
34095        i++, d++)
34096     {
34097       if (d->name == 0)
34098         continue;
34099
34100       ftype = (enum ix86_builtin_func_type) d->flag;
34101       decl = def_builtin (d->mask, d->name, ftype, d->code);
34102
34103       /* With no leaf and nothrow flags for MPX builtins
34104          abnormal edges may follow its call when setjmp
34105          presents in the function.  Since we may have a lot
34106          of MPX builtins calls it causes lots of useless
34107          edges and enormous PHI nodes.  To avoid this we mark
34108          MPX builtins as leaf and nothrow.  */
34109       if (decl)
34110         {
34111           DECL_ATTRIBUTES (decl) = build_tree_list (get_identifier ("leaf"),
34112                                                     NULL_TREE);
34113           TREE_NOTHROW (decl) = 1;
34114         }
34115       else
34116         {
34117           ix86_builtins_isa[(int)d->code].leaf_p = true;
34118           ix86_builtins_isa[(int)d->code].nothrow_p = true;
34119         }
34120     }
34121
34122   for (i = 0, d = bdesc_mpx_const;
34123        i < ARRAY_SIZE (bdesc_mpx_const);
34124        i++, d++)
34125     {
34126       if (d->name == 0)
34127         continue;
34128
34129       ftype = (enum ix86_builtin_func_type) d->flag;
34130       decl = def_builtin_const (d->mask, d->name, ftype, d->code);
34131
34132       if (decl)
34133         {
34134           DECL_ATTRIBUTES (decl) = build_tree_list (get_identifier ("leaf"),
34135                                                     NULL_TREE);
34136           TREE_NOTHROW (decl) = 1;
34137         }
34138       else
34139         {
34140           ix86_builtins_isa[(int)d->code].leaf_p = true;
34141           ix86_builtins_isa[(int)d->code].nothrow_p = true;
34142         }
34143     }
34144 }
34145
34146 /* This adds a condition to the basic_block NEW_BB in function FUNCTION_DECL
34147    to return a pointer to VERSION_DECL if the outcome of the expression
34148    formed by PREDICATE_CHAIN is true.  This function will be called during
34149    version dispatch to decide which function version to execute.  It returns
34150    the basic block at the end, to which more conditions can be added.  */
34151
34152 static basic_block
34153 add_condition_to_bb (tree function_decl, tree version_decl,
34154                      tree predicate_chain, basic_block new_bb)
34155 {
34156   gimple return_stmt;
34157   tree convert_expr, result_var;
34158   gimple convert_stmt;
34159   gimple call_cond_stmt;
34160   gimple if_else_stmt;
34161
34162   basic_block bb1, bb2, bb3;
34163   edge e12, e23;
34164
34165   tree cond_var, and_expr_var = NULL_TREE;
34166   gimple_seq gseq;
34167
34168   tree predicate_decl, predicate_arg;
34169
34170   push_cfun (DECL_STRUCT_FUNCTION (function_decl));
34171
34172   gcc_assert (new_bb != NULL);
34173   gseq = bb_seq (new_bb);
34174
34175
34176   convert_expr = build1 (CONVERT_EXPR, ptr_type_node,
34177                          build_fold_addr_expr (version_decl));
34178   result_var = create_tmp_var (ptr_type_node);
34179   convert_stmt = gimple_build_assign (result_var, convert_expr); 
34180   return_stmt = gimple_build_return (result_var);
34181
34182   if (predicate_chain == NULL_TREE)
34183     {
34184       gimple_seq_add_stmt (&gseq, convert_stmt);
34185       gimple_seq_add_stmt (&gseq, return_stmt);
34186       set_bb_seq (new_bb, gseq);
34187       gimple_set_bb (convert_stmt, new_bb);
34188       gimple_set_bb (return_stmt, new_bb);
34189       pop_cfun ();
34190       return new_bb;
34191     }
34192
34193   while (predicate_chain != NULL)
34194     {
34195       cond_var = create_tmp_var (integer_type_node);
34196       predicate_decl = TREE_PURPOSE (predicate_chain);
34197       predicate_arg = TREE_VALUE (predicate_chain);
34198       call_cond_stmt = gimple_build_call (predicate_decl, 1, predicate_arg);
34199       gimple_call_set_lhs (call_cond_stmt, cond_var);
34200
34201       gimple_set_block (call_cond_stmt, DECL_INITIAL (function_decl));
34202       gimple_set_bb (call_cond_stmt, new_bb);
34203       gimple_seq_add_stmt (&gseq, call_cond_stmt);
34204
34205       predicate_chain = TREE_CHAIN (predicate_chain);
34206       
34207       if (and_expr_var == NULL)
34208         and_expr_var = cond_var;
34209       else
34210         {
34211           gimple assign_stmt;
34212           /* Use MIN_EXPR to check if any integer is zero?.
34213              and_expr_var = min_expr <cond_var, and_expr_var>  */
34214           assign_stmt = gimple_build_assign (and_expr_var,
34215                           build2 (MIN_EXPR, integer_type_node,
34216                                   cond_var, and_expr_var));
34217
34218           gimple_set_block (assign_stmt, DECL_INITIAL (function_decl));
34219           gimple_set_bb (assign_stmt, new_bb);
34220           gimple_seq_add_stmt (&gseq, assign_stmt);
34221         }
34222     }
34223
34224   if_else_stmt = gimple_build_cond (GT_EXPR, and_expr_var,
34225                                     integer_zero_node,
34226                                     NULL_TREE, NULL_TREE);
34227   gimple_set_block (if_else_stmt, DECL_INITIAL (function_decl));
34228   gimple_set_bb (if_else_stmt, new_bb);
34229   gimple_seq_add_stmt (&gseq, if_else_stmt);
34230
34231   gimple_seq_add_stmt (&gseq, convert_stmt);
34232   gimple_seq_add_stmt (&gseq, return_stmt);
34233   set_bb_seq (new_bb, gseq);
34234
34235   bb1 = new_bb;
34236   e12 = split_block (bb1, if_else_stmt);
34237   bb2 = e12->dest;
34238   e12->flags &= ~EDGE_FALLTHRU;
34239   e12->flags |= EDGE_TRUE_VALUE;
34240
34241   e23 = split_block (bb2, return_stmt);
34242
34243   gimple_set_bb (convert_stmt, bb2);
34244   gimple_set_bb (return_stmt, bb2);
34245
34246   bb3 = e23->dest;
34247   make_edge (bb1, bb3, EDGE_FALSE_VALUE); 
34248
34249   remove_edge (e23);
34250   make_edge (bb2, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
34251
34252   pop_cfun ();
34253
34254   return bb3;
34255 }
34256
34257 /* This parses the attribute arguments to target in DECL and determines
34258    the right builtin to use to match the platform specification.
34259    It returns the priority value for this version decl.  If PREDICATE_LIST
34260    is not NULL, it stores the list of cpu features that need to be checked
34261    before dispatching this function.  */
34262
34263 static unsigned int
34264 get_builtin_code_for_version (tree decl, tree *predicate_list)
34265 {
34266   tree attrs;
34267   struct cl_target_option cur_target;
34268   tree target_node;
34269   struct cl_target_option *new_target;
34270   const char *arg_str = NULL;
34271   const char *attrs_str = NULL;
34272   char *tok_str = NULL;
34273   char *token;
34274
34275   /* Priority of i386 features, greater value is higher priority.   This is
34276      used to decide the order in which function dispatch must happen.  For
34277      instance, a version specialized for SSE4.2 should be checked for dispatch
34278      before a version for SSE3, as SSE4.2 implies SSE3.  */
34279   enum feature_priority
34280   {
34281     P_ZERO = 0,
34282     P_MMX,
34283     P_SSE,
34284     P_SSE2,
34285     P_SSE3,
34286     P_SSSE3,
34287     P_PROC_SSSE3,
34288     P_SSE4_A,
34289     P_PROC_SSE4_A,
34290     P_SSE4_1,
34291     P_SSE4_2,
34292     P_PROC_SSE4_2,
34293     P_POPCNT,
34294     P_AVX,
34295     P_PROC_AVX,
34296     P_BMI,
34297     P_PROC_BMI,
34298     P_FMA4,
34299     P_XOP,
34300     P_PROC_XOP,
34301     P_FMA,    
34302     P_PROC_FMA,
34303     P_BMI2,
34304     P_AVX2,
34305     P_PROC_AVX2,
34306     P_AVX512F,
34307     P_PROC_AVX512F
34308   };
34309
34310  enum feature_priority priority = P_ZERO;
34311
34312   /* These are the target attribute strings for which a dispatcher is
34313      available, from fold_builtin_cpu.  */
34314
34315   static struct _feature_list
34316     {
34317       const char *const name;
34318       const enum feature_priority priority;
34319     }
34320   const feature_list[] =
34321     {
34322       {"mmx", P_MMX},
34323       {"sse", P_SSE},
34324       {"sse2", P_SSE2},
34325       {"sse3", P_SSE3},
34326       {"sse4a", P_SSE4_A},
34327       {"ssse3", P_SSSE3},
34328       {"sse4.1", P_SSE4_1},
34329       {"sse4.2", P_SSE4_2},
34330       {"popcnt", P_POPCNT},
34331       {"avx", P_AVX},
34332       {"bmi", P_BMI},
34333       {"fma4", P_FMA4},
34334       {"xop", P_XOP},
34335       {"fma", P_FMA},
34336       {"bmi2", P_BMI2},
34337       {"avx2", P_AVX2},
34338       {"avx512f", P_AVX512F}
34339     };
34340
34341
34342   static unsigned int NUM_FEATURES
34343     = sizeof (feature_list) / sizeof (struct _feature_list);
34344
34345   unsigned int i;
34346
34347   tree predicate_chain = NULL_TREE;
34348   tree predicate_decl, predicate_arg;
34349
34350   attrs = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
34351   gcc_assert (attrs != NULL);
34352
34353   attrs = TREE_VALUE (TREE_VALUE (attrs));
34354
34355   gcc_assert (TREE_CODE (attrs) == STRING_CST);
34356   attrs_str = TREE_STRING_POINTER (attrs);
34357
34358   /* Return priority zero for default function.  */
34359   if (strcmp (attrs_str, "default") == 0)
34360     return 0;
34361
34362   /* Handle arch= if specified.  For priority, set it to be 1 more than
34363      the best instruction set the processor can handle.  For instance, if
34364      there is a version for atom and a version for ssse3 (the highest ISA
34365      priority for atom), the atom version must be checked for dispatch
34366      before the ssse3 version. */
34367   if (strstr (attrs_str, "arch=") != NULL)
34368     {
34369       cl_target_option_save (&cur_target, &global_options);
34370       target_node = ix86_valid_target_attribute_tree (attrs, &global_options,
34371                                                       &global_options_set);
34372     
34373       gcc_assert (target_node);
34374       new_target = TREE_TARGET_OPTION (target_node);
34375       gcc_assert (new_target);
34376       
34377       if (new_target->arch_specified && new_target->arch > 0)
34378         {
34379           switch (new_target->arch)
34380             {
34381             case PROCESSOR_CORE2:
34382               arg_str = "core2";
34383               priority = P_PROC_SSSE3;
34384               break;
34385             case PROCESSOR_NEHALEM:
34386               if (new_target->x_ix86_isa_flags & OPTION_MASK_ISA_AES)
34387                 arg_str = "westmere";
34388               else
34389                 /* We translate "arch=corei7" and "arch=nehalem" to
34390                    "corei7" so that it will be mapped to M_INTEL_COREI7
34391                    as cpu type to cover all M_INTEL_COREI7_XXXs.  */
34392                 arg_str = "corei7";
34393               priority = P_PROC_SSE4_2;
34394               break;
34395             case PROCESSOR_SANDYBRIDGE:
34396               if (new_target->x_ix86_isa_flags & OPTION_MASK_ISA_F16C)
34397                 arg_str = "ivybridge";
34398               else
34399                 arg_str = "sandybridge";
34400               priority = P_PROC_AVX;
34401               break;
34402             case PROCESSOR_HASWELL:
34403               if (new_target->x_ix86_isa_flags & OPTION_MASK_ISA_ADX)
34404                 arg_str = "broadwell";
34405               else
34406                 arg_str = "haswell";
34407               priority = P_PROC_AVX2;
34408               break;
34409             case PROCESSOR_BONNELL:
34410               arg_str = "bonnell";
34411               priority = P_PROC_SSSE3;
34412               break;
34413             case PROCESSOR_KNL:
34414               arg_str = "knl";
34415               priority = P_PROC_AVX512F;
34416               break;
34417             case PROCESSOR_SILVERMONT:
34418               arg_str = "silvermont";
34419               priority = P_PROC_SSE4_2;
34420               break;
34421             case PROCESSOR_AMDFAM10:
34422               arg_str = "amdfam10h";
34423               priority = P_PROC_SSE4_A;
34424               break;
34425             case PROCESSOR_BTVER1:
34426               arg_str = "btver1";
34427               priority = P_PROC_SSE4_A;
34428               break;
34429             case PROCESSOR_BTVER2:
34430               arg_str = "btver2";
34431               priority = P_PROC_BMI;
34432               break;
34433             case PROCESSOR_BDVER1:
34434               arg_str = "bdver1";
34435               priority = P_PROC_XOP;
34436               break;
34437             case PROCESSOR_BDVER2:
34438               arg_str = "bdver2";
34439               priority = P_PROC_FMA;
34440               break;
34441             case PROCESSOR_BDVER3:
34442               arg_str = "bdver3";
34443               priority = P_PROC_FMA;
34444               break;
34445             case PROCESSOR_BDVER4:
34446               arg_str = "bdver4";
34447               priority = P_PROC_AVX2;
34448               break;
34449             }  
34450         }    
34451     
34452       cl_target_option_restore (&global_options, &cur_target);
34453         
34454       if (predicate_list && arg_str == NULL)
34455         {
34456           error_at (DECL_SOURCE_LOCATION (decl),
34457                 "No dispatcher found for the versioning attributes");
34458           return 0;
34459         }
34460     
34461       if (predicate_list)
34462         {
34463           predicate_decl = ix86_builtins [(int) IX86_BUILTIN_CPU_IS];
34464           /* For a C string literal the length includes the trailing NULL.  */
34465           predicate_arg = build_string_literal (strlen (arg_str) + 1, arg_str);
34466           predicate_chain = tree_cons (predicate_decl, predicate_arg,
34467                                        predicate_chain);
34468         }
34469     }
34470
34471   /* Process feature name.  */
34472   tok_str =  (char *) xmalloc (strlen (attrs_str) + 1);
34473   strcpy (tok_str, attrs_str);
34474   token = strtok (tok_str, ",");
34475   predicate_decl = ix86_builtins [(int) IX86_BUILTIN_CPU_SUPPORTS];
34476
34477   while (token != NULL)
34478     {
34479       /* Do not process "arch="  */
34480       if (strncmp (token, "arch=", 5) == 0)
34481         {
34482           token = strtok (NULL, ",");
34483           continue;
34484         }
34485       for (i = 0; i < NUM_FEATURES; ++i)
34486         {
34487           if (strcmp (token, feature_list[i].name) == 0)
34488             {
34489               if (predicate_list)
34490                 {
34491                   predicate_arg = build_string_literal (
34492                                   strlen (feature_list[i].name) + 1,
34493                                   feature_list[i].name);
34494                   predicate_chain = tree_cons (predicate_decl, predicate_arg,
34495                                                predicate_chain);
34496                 }
34497               /* Find the maximum priority feature.  */
34498               if (feature_list[i].priority > priority)
34499                 priority = feature_list[i].priority;
34500
34501               break;
34502             }
34503         }
34504       if (predicate_list && i == NUM_FEATURES)
34505         {
34506           error_at (DECL_SOURCE_LOCATION (decl),
34507                     "No dispatcher found for %s", token);
34508           return 0;
34509         }
34510       token = strtok (NULL, ",");
34511     }
34512   free (tok_str);
34513
34514   if (predicate_list && predicate_chain == NULL_TREE)
34515     {
34516       error_at (DECL_SOURCE_LOCATION (decl),
34517                 "No dispatcher found for the versioning attributes : %s",
34518                 attrs_str);
34519       return 0;
34520     }
34521   else if (predicate_list)
34522     {
34523       predicate_chain = nreverse (predicate_chain);
34524       *predicate_list = predicate_chain;
34525     }
34526
34527   return priority; 
34528 }
34529
34530 /* This compares the priority of target features in function DECL1
34531    and DECL2.  It returns positive value if DECL1 is higher priority,
34532    negative value if DECL2 is higher priority and 0 if they are the
34533    same.  */
34534
34535 static int
34536 ix86_compare_version_priority (tree decl1, tree decl2)
34537 {
34538   unsigned int priority1 = get_builtin_code_for_version (decl1, NULL);
34539   unsigned int priority2 = get_builtin_code_for_version (decl2, NULL);
34540
34541   return (int)priority1 - (int)priority2;
34542 }
34543
34544 /* V1 and V2 point to function versions with different priorities
34545    based on the target ISA.  This function compares their priorities.  */
34546  
34547 static int
34548 feature_compare (const void *v1, const void *v2)
34549 {
34550   typedef struct _function_version_info
34551     {
34552       tree version_decl;
34553       tree predicate_chain;
34554       unsigned int dispatch_priority;
34555     } function_version_info;
34556
34557   const function_version_info c1 = *(const function_version_info *)v1;
34558   const function_version_info c2 = *(const function_version_info *)v2;
34559   return (c2.dispatch_priority - c1.dispatch_priority);
34560 }
34561
34562 /* This function generates the dispatch function for
34563    multi-versioned functions.  DISPATCH_DECL is the function which will
34564    contain the dispatch logic.  FNDECLS are the function choices for
34565    dispatch, and is a tree chain.  EMPTY_BB is the basic block pointer
34566    in DISPATCH_DECL in which the dispatch code is generated.  */
34567
34568 static int
34569 dispatch_function_versions (tree dispatch_decl,
34570                             void *fndecls_p,
34571                             basic_block *empty_bb)
34572 {
34573   tree default_decl;
34574   gimple ifunc_cpu_init_stmt;
34575   gimple_seq gseq;
34576   int ix;
34577   tree ele;
34578   vec<tree> *fndecls;
34579   unsigned int num_versions = 0;
34580   unsigned int actual_versions = 0;
34581   unsigned int i;
34582
34583   struct _function_version_info
34584     {
34585       tree version_decl;
34586       tree predicate_chain;
34587       unsigned int dispatch_priority;
34588     }*function_version_info;
34589
34590   gcc_assert (dispatch_decl != NULL
34591               && fndecls_p != NULL
34592               && empty_bb != NULL);
34593
34594   /*fndecls_p is actually a vector.  */
34595   fndecls = static_cast<vec<tree> *> (fndecls_p);
34596
34597   /* At least one more version other than the default.  */
34598   num_versions = fndecls->length ();
34599   gcc_assert (num_versions >= 2);
34600
34601   function_version_info = (struct _function_version_info *)
34602     XNEWVEC (struct _function_version_info, (num_versions - 1));
34603
34604   /* The first version in the vector is the default decl.  */
34605   default_decl = (*fndecls)[0];
34606
34607   push_cfun (DECL_STRUCT_FUNCTION (dispatch_decl));
34608
34609   gseq = bb_seq (*empty_bb);
34610   /* Function version dispatch is via IFUNC.  IFUNC resolvers fire before
34611      constructors, so explicity call __builtin_cpu_init here.  */
34612   ifunc_cpu_init_stmt = gimple_build_call_vec (
34613                      ix86_builtins [(int) IX86_BUILTIN_CPU_INIT], vNULL);
34614   gimple_seq_add_stmt (&gseq, ifunc_cpu_init_stmt);
34615   gimple_set_bb (ifunc_cpu_init_stmt, *empty_bb);
34616   set_bb_seq (*empty_bb, gseq);
34617
34618   pop_cfun ();
34619
34620
34621   for (ix = 1; fndecls->iterate (ix, &ele); ++ix)
34622     {
34623       tree version_decl = ele;
34624       tree predicate_chain = NULL_TREE;
34625       unsigned int priority;
34626       /* Get attribute string, parse it and find the right predicate decl.
34627          The predicate function could be a lengthy combination of many
34628          features, like arch-type and various isa-variants.  */
34629       priority = get_builtin_code_for_version (version_decl,
34630                                                &predicate_chain);
34631
34632       if (predicate_chain == NULL_TREE)
34633         continue;
34634
34635       function_version_info [actual_versions].version_decl = version_decl;
34636       function_version_info [actual_versions].predicate_chain
34637          = predicate_chain;
34638       function_version_info [actual_versions].dispatch_priority = priority;
34639       actual_versions++;
34640     }
34641
34642   /* Sort the versions according to descending order of dispatch priority.  The
34643      priority is based on the ISA.  This is not a perfect solution.  There
34644      could still be ambiguity.  If more than one function version is suitable
34645      to execute,  which one should be dispatched?  In future, allow the user
34646      to specify a dispatch  priority next to the version.  */
34647   qsort (function_version_info, actual_versions,
34648          sizeof (struct _function_version_info), feature_compare);
34649
34650   for  (i = 0; i < actual_versions; ++i)
34651     *empty_bb = add_condition_to_bb (dispatch_decl,
34652                                      function_version_info[i].version_decl,
34653                                      function_version_info[i].predicate_chain,
34654                                      *empty_bb);
34655
34656   /* dispatch default version at the end.  */
34657   *empty_bb = add_condition_to_bb (dispatch_decl, default_decl,
34658                                    NULL, *empty_bb);
34659
34660   free (function_version_info);
34661   return 0;
34662 }
34663
34664 /* Comparator function to be used in qsort routine to sort attribute
34665    specification strings to "target".  */
34666
34667 static int
34668 attr_strcmp (const void *v1, const void *v2)
34669 {
34670   const char *c1 = *(char *const*)v1;
34671   const char *c2 = *(char *const*)v2;
34672   return strcmp (c1, c2);
34673 }
34674
34675 /* ARGLIST is the argument to target attribute.  This function tokenizes
34676    the comma separated arguments, sorts them and returns a string which
34677    is a unique identifier for the comma separated arguments.   It also
34678    replaces non-identifier characters "=,-" with "_".  */
34679
34680 static char *
34681 sorted_attr_string (tree arglist)
34682 {
34683   tree arg;
34684   size_t str_len_sum = 0;
34685   char **args = NULL;
34686   char *attr_str, *ret_str;
34687   char *attr = NULL;
34688   unsigned int argnum = 1;
34689   unsigned int i;
34690
34691   for (arg = arglist; arg; arg = TREE_CHAIN (arg))
34692     {
34693       const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
34694       size_t len = strlen (str);
34695       str_len_sum += len + 1;
34696       if (arg != arglist)
34697         argnum++;
34698       for (i = 0; i < strlen (str); i++)
34699         if (str[i] == ',')
34700           argnum++;
34701     }
34702
34703   attr_str = XNEWVEC (char, str_len_sum);
34704   str_len_sum = 0;
34705   for (arg = arglist; arg; arg = TREE_CHAIN (arg))
34706     {
34707       const char *str = TREE_STRING_POINTER (TREE_VALUE (arg));
34708       size_t len = strlen (str);
34709       memcpy (attr_str + str_len_sum, str, len);
34710       attr_str[str_len_sum + len] = TREE_CHAIN (arg) ? ',' : '\0';
34711       str_len_sum += len + 1;
34712     }
34713
34714   /* Replace "=,-" with "_".  */
34715   for (i = 0; i < strlen (attr_str); i++)
34716     if (attr_str[i] == '=' || attr_str[i]== '-')
34717       attr_str[i] = '_';
34718
34719   if (argnum == 1)
34720     return attr_str;
34721
34722   args = XNEWVEC (char *, argnum);
34723
34724   i = 0;
34725   attr = strtok (attr_str, ",");
34726   while (attr != NULL)
34727     {
34728       args[i] = attr;
34729       i++;
34730       attr = strtok (NULL, ",");
34731     }
34732
34733   qsort (args, argnum, sizeof (char *), attr_strcmp);
34734
34735   ret_str = XNEWVEC (char, str_len_sum);
34736   str_len_sum = 0;
34737   for (i = 0; i < argnum; i++)
34738     {
34739       size_t len = strlen (args[i]);
34740       memcpy (ret_str + str_len_sum, args[i], len);
34741       ret_str[str_len_sum + len] = i < argnum - 1 ? '_' : '\0';
34742       str_len_sum += len + 1;
34743     }
34744
34745   XDELETEVEC (args);
34746   XDELETEVEC (attr_str);
34747   return ret_str;
34748 }
34749
34750 /* This function changes the assembler name for functions that are
34751    versions.  If DECL is a function version and has a "target"
34752    attribute, it appends the attribute string to its assembler name.  */
34753
34754 static tree
34755 ix86_mangle_function_version_assembler_name (tree decl, tree id)
34756 {
34757   tree version_attr;
34758   const char *orig_name, *version_string;
34759   char *attr_str, *assembler_name;
34760
34761   if (DECL_DECLARED_INLINE_P (decl)
34762       && lookup_attribute ("gnu_inline",
34763                            DECL_ATTRIBUTES (decl)))
34764     error_at (DECL_SOURCE_LOCATION (decl),
34765               "Function versions cannot be marked as gnu_inline,"
34766               " bodies have to be generated");
34767
34768   if (DECL_VIRTUAL_P (decl)
34769       || DECL_VINDEX (decl))
34770     sorry ("Virtual function multiversioning not supported");
34771
34772   version_attr = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
34773
34774   /* target attribute string cannot be NULL.  */
34775   gcc_assert (version_attr != NULL_TREE);
34776
34777   orig_name = IDENTIFIER_POINTER (id);
34778   version_string
34779     = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (version_attr)));
34780
34781   if (strcmp (version_string, "default") == 0)
34782     return id;
34783
34784   attr_str = sorted_attr_string (TREE_VALUE (version_attr));
34785   assembler_name = XNEWVEC (char, strlen (orig_name) + strlen (attr_str) + 2);
34786
34787   sprintf (assembler_name, "%s.%s", orig_name, attr_str);
34788
34789   /* Allow assembler name to be modified if already set.  */
34790   if (DECL_ASSEMBLER_NAME_SET_P (decl))
34791     SET_DECL_RTL (decl, NULL);
34792
34793   tree ret = get_identifier (assembler_name);
34794   XDELETEVEC (attr_str);
34795   XDELETEVEC (assembler_name);
34796   return ret;
34797 }
34798
34799 /* This function returns true if FN1 and FN2 are versions of the same function,
34800    that is, the target strings of the function decls are different.  This assumes
34801    that FN1 and FN2 have the same signature.  */
34802
34803 static bool
34804 ix86_function_versions (tree fn1, tree fn2)
34805 {
34806   tree attr1, attr2;
34807   char *target1, *target2;
34808   bool result;
34809
34810   if (TREE_CODE (fn1) != FUNCTION_DECL
34811       || TREE_CODE (fn2) != FUNCTION_DECL)
34812     return false;
34813
34814   attr1 = lookup_attribute ("target", DECL_ATTRIBUTES (fn1));
34815   attr2 = lookup_attribute ("target", DECL_ATTRIBUTES (fn2));
34816
34817   /* At least one function decl should have the target attribute specified.  */
34818   if (attr1 == NULL_TREE && attr2 == NULL_TREE)
34819     return false;
34820
34821   /* Diagnose missing target attribute if one of the decls is already
34822      multi-versioned.  */
34823   if (attr1 == NULL_TREE || attr2 == NULL_TREE)
34824     {
34825       if (DECL_FUNCTION_VERSIONED (fn1) || DECL_FUNCTION_VERSIONED (fn2))
34826         {
34827           if (attr2 != NULL_TREE)
34828             {
34829               tree tem = fn1;
34830               fn1 = fn2;
34831               fn2 = tem;
34832               attr1 = attr2;
34833             }
34834           error_at (DECL_SOURCE_LOCATION (fn2),
34835                     "missing %<target%> attribute for multi-versioned %D",
34836                     fn2);
34837           inform (DECL_SOURCE_LOCATION (fn1),
34838                   "previous declaration of %D", fn1);
34839           /* Prevent diagnosing of the same error multiple times.  */
34840           DECL_ATTRIBUTES (fn2)
34841             = tree_cons (get_identifier ("target"),
34842                          copy_node (TREE_VALUE (attr1)),
34843                          DECL_ATTRIBUTES (fn2));
34844         }
34845       return false;
34846     }
34847
34848   target1 = sorted_attr_string (TREE_VALUE (attr1));
34849   target2 = sorted_attr_string (TREE_VALUE (attr2));
34850
34851   /* The sorted target strings must be different for fn1 and fn2
34852      to be versions.  */
34853   if (strcmp (target1, target2) == 0)
34854     result = false;
34855   else
34856     result = true;
34857
34858   XDELETEVEC (target1);
34859   XDELETEVEC (target2); 
34860   
34861   return result;
34862 }
34863
34864 static tree 
34865 ix86_mangle_decl_assembler_name (tree decl, tree id)
34866 {
34867   /* For function version, add the target suffix to the assembler name.  */
34868   if (TREE_CODE (decl) == FUNCTION_DECL
34869       && DECL_FUNCTION_VERSIONED (decl))
34870     id = ix86_mangle_function_version_assembler_name (decl, id);
34871 #ifdef SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME
34872   id = SUBTARGET_MANGLE_DECL_ASSEMBLER_NAME (decl, id);
34873 #endif
34874
34875   return id;
34876 }
34877
34878 /* Return a new name by appending SUFFIX to the DECL name.  If make_unique
34879    is true, append the full path name of the source file.  */
34880
34881 static char *
34882 make_name (tree decl, const char *suffix, bool make_unique)
34883 {
34884   char *global_var_name;
34885   int name_len;
34886   const char *name;
34887   const char *unique_name = NULL;
34888
34889   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
34890
34891   /* Get a unique name that can be used globally without any chances
34892      of collision at link time.  */
34893   if (make_unique)
34894     unique_name = IDENTIFIER_POINTER (get_file_function_name ("\0"));
34895
34896   name_len = strlen (name) + strlen (suffix) + 2;
34897
34898   if (make_unique)
34899     name_len += strlen (unique_name) + 1;
34900   global_var_name = XNEWVEC (char, name_len);
34901
34902   /* Use '.' to concatenate names as it is demangler friendly.  */
34903   if (make_unique)
34904     snprintf (global_var_name, name_len, "%s.%s.%s", name, unique_name,
34905               suffix);
34906   else
34907     snprintf (global_var_name, name_len, "%s.%s", name, suffix);
34908
34909   return global_var_name;
34910 }
34911
34912 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
34913
34914 /* Make a dispatcher declaration for the multi-versioned function DECL.
34915    Calls to DECL function will be replaced with calls to the dispatcher
34916    by the front-end.  Return the decl created.  */
34917
34918 static tree
34919 make_dispatcher_decl (const tree decl)
34920 {
34921   tree func_decl;
34922   char *func_name;
34923   tree fn_type, func_type;
34924   bool is_uniq = false;
34925
34926   if (TREE_PUBLIC (decl) == 0)
34927     is_uniq = true;
34928
34929   func_name = make_name (decl, "ifunc", is_uniq);
34930
34931   fn_type = TREE_TYPE (decl);
34932   func_type = build_function_type (TREE_TYPE (fn_type),
34933                                    TYPE_ARG_TYPES (fn_type));
34934   
34935   func_decl = build_fn_decl (func_name, func_type);
34936   XDELETEVEC (func_name);
34937   TREE_USED (func_decl) = 1;
34938   DECL_CONTEXT (func_decl) = NULL_TREE;
34939   DECL_INITIAL (func_decl) = error_mark_node;
34940   DECL_ARTIFICIAL (func_decl) = 1;
34941   /* Mark this func as external, the resolver will flip it again if
34942      it gets generated.  */
34943   DECL_EXTERNAL (func_decl) = 1;
34944   /* This will be of type IFUNCs have to be externally visible.  */
34945   TREE_PUBLIC (func_decl) = 1;
34946
34947   return func_decl;  
34948 }
34949
34950 #endif
34951
34952 /* Returns true if decl is multi-versioned and DECL is the default function,
34953    that is it is not tagged with target specific optimization.  */
34954
34955 static bool
34956 is_function_default_version (const tree decl)
34957 {
34958   if (TREE_CODE (decl) != FUNCTION_DECL
34959       || !DECL_FUNCTION_VERSIONED (decl))
34960     return false;
34961   tree attr = lookup_attribute ("target", DECL_ATTRIBUTES (decl));
34962   gcc_assert (attr);
34963   attr = TREE_VALUE (TREE_VALUE (attr));
34964   return (TREE_CODE (attr) == STRING_CST
34965           && strcmp (TREE_STRING_POINTER (attr), "default") == 0);
34966 }
34967
34968 /* Make a dispatcher declaration for the multi-versioned function DECL.
34969    Calls to DECL function will be replaced with calls to the dispatcher
34970    by the front-end.  Returns the decl of the dispatcher function.  */
34971
34972 static tree
34973 ix86_get_function_versions_dispatcher (void *decl)
34974 {
34975   tree fn = (tree) decl;
34976   struct cgraph_node *node = NULL;
34977   struct cgraph_node *default_node = NULL;
34978   struct cgraph_function_version_info *node_v = NULL;
34979   struct cgraph_function_version_info *first_v = NULL;
34980
34981   tree dispatch_decl = NULL;
34982
34983   struct cgraph_function_version_info *default_version_info = NULL;
34984  
34985   gcc_assert (fn != NULL && DECL_FUNCTION_VERSIONED (fn));
34986
34987   node = cgraph_node::get (fn);
34988   gcc_assert (node != NULL);
34989
34990   node_v = node->function_version ();
34991   gcc_assert (node_v != NULL);
34992  
34993   if (node_v->dispatcher_resolver != NULL)
34994     return node_v->dispatcher_resolver;
34995
34996   /* Find the default version and make it the first node.  */
34997   first_v = node_v;
34998   /* Go to the beginning of the chain.  */
34999   while (first_v->prev != NULL)
35000     first_v = first_v->prev;
35001   default_version_info = first_v;
35002   while (default_version_info != NULL)
35003     {
35004       if (is_function_default_version
35005             (default_version_info->this_node->decl))
35006         break;
35007       default_version_info = default_version_info->next;
35008     }
35009
35010   /* If there is no default node, just return NULL.  */
35011   if (default_version_info == NULL)
35012     return NULL;
35013
35014   /* Make default info the first node.  */
35015   if (first_v != default_version_info)
35016     {
35017       default_version_info->prev->next = default_version_info->next;
35018       if (default_version_info->next)
35019         default_version_info->next->prev = default_version_info->prev;
35020       first_v->prev = default_version_info;
35021       default_version_info->next = first_v;
35022       default_version_info->prev = NULL;
35023     }
35024
35025   default_node = default_version_info->this_node;
35026
35027 #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
35028   if (targetm.has_ifunc_p ())
35029     {
35030       struct cgraph_function_version_info *it_v = NULL;
35031       struct cgraph_node *dispatcher_node = NULL;
35032       struct cgraph_function_version_info *dispatcher_version_info = NULL;
35033
35034       /* Right now, the dispatching is done via ifunc.  */
35035       dispatch_decl = make_dispatcher_decl (default_node->decl);
35036
35037       dispatcher_node = cgraph_node::get_create (dispatch_decl);
35038       gcc_assert (dispatcher_node != NULL);
35039       dispatcher_node->dispatcher_function = 1;
35040       dispatcher_version_info
35041         = dispatcher_node->insert_new_function_version ();
35042       dispatcher_version_info->next = default_version_info;
35043       dispatcher_node->definition = 1;
35044
35045       /* Set the dispatcher for all the versions.  */
35046       it_v = default_version_info;
35047       while (it_v != NULL)
35048         {
35049           it_v->dispatcher_resolver = dispatch_decl;
35050           it_v = it_v->next;
35051         }
35052     }
35053   else
35054 #endif
35055     {
35056       error_at (DECL_SOURCE_LOCATION (default_node->decl),
35057                 "multiversioning needs ifunc which is not supported "
35058                 "on this target");
35059     }
35060
35061   return dispatch_decl;
35062 }
35063
35064 /* Makes a function attribute of the form NAME(ARG_NAME) and chains
35065    it to CHAIN.  */
35066
35067 static tree
35068 make_attribute (const char *name, const char *arg_name, tree chain)
35069 {
35070   tree attr_name;
35071   tree attr_arg_name;
35072   tree attr_args;
35073   tree attr;
35074
35075   attr_name = get_identifier (name);
35076   attr_arg_name = build_string (strlen (arg_name), arg_name);
35077   attr_args = tree_cons (NULL_TREE, attr_arg_name, NULL_TREE);
35078   attr = tree_cons (attr_name, attr_args, chain);
35079   return attr;
35080 }
35081
35082 /* Make the resolver function decl to dispatch the versions of
35083    a multi-versioned function,  DEFAULT_DECL.  Create an
35084    empty basic block in the resolver and store the pointer in
35085    EMPTY_BB.  Return the decl of the resolver function.  */
35086
35087 static tree
35088 make_resolver_func (const tree default_decl,
35089                     const tree dispatch_decl,
35090                     basic_block *empty_bb)
35091 {
35092   char *resolver_name;
35093   tree decl, type, decl_name, t;
35094   bool is_uniq = false;
35095
35096   /* IFUNC's have to be globally visible.  So, if the default_decl is
35097      not, then the name of the IFUNC should be made unique.  */
35098   if (TREE_PUBLIC (default_decl) == 0)
35099     is_uniq = true;
35100
35101   /* Append the filename to the resolver function if the versions are
35102      not externally visible.  This is because the resolver function has
35103      to be externally visible for the loader to find it.  So, appending
35104      the filename will prevent conflicts with a resolver function from
35105      another module which is based on the same version name.  */
35106   resolver_name = make_name (default_decl, "resolver", is_uniq);
35107
35108   /* The resolver function should return a (void *). */
35109   type = build_function_type_list (ptr_type_node, NULL_TREE);
35110
35111   decl = build_fn_decl (resolver_name, type);
35112   decl_name = get_identifier (resolver_name);
35113   SET_DECL_ASSEMBLER_NAME (decl, decl_name);
35114
35115   DECL_NAME (decl) = decl_name;
35116   TREE_USED (decl) = 1;
35117   DECL_ARTIFICIAL (decl) = 1;
35118   DECL_IGNORED_P (decl) = 0;
35119   /* IFUNC resolvers have to be externally visible.  */
35120   TREE_PUBLIC (decl) = 1;
35121   DECL_UNINLINABLE (decl) = 1;
35122
35123   /* Resolver is not external, body is generated.  */
35124   DECL_EXTERNAL (decl) = 0;
35125   DECL_EXTERNAL (dispatch_decl) = 0;
35126
35127   DECL_CONTEXT (decl) = NULL_TREE;
35128   DECL_INITIAL (decl) = make_node (BLOCK);
35129   DECL_STATIC_CONSTRUCTOR (decl) = 0;
35130
35131   if (DECL_COMDAT_GROUP (default_decl)
35132       || TREE_PUBLIC (default_decl))
35133     {
35134       /* In this case, each translation unit with a call to this
35135          versioned function will put out a resolver.  Ensure it
35136          is comdat to keep just one copy.  */
35137       DECL_COMDAT (decl) = 1;
35138       make_decl_one_only (decl, DECL_ASSEMBLER_NAME (decl));
35139     }
35140   /* Build result decl and add to function_decl. */
35141   t = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, ptr_type_node);
35142   DECL_ARTIFICIAL (t) = 1;
35143   DECL_IGNORED_P (t) = 1;
35144   DECL_RESULT (decl) = t;
35145
35146   gimplify_function_tree (decl);
35147   push_cfun (DECL_STRUCT_FUNCTION (decl));
35148   *empty_bb = init_lowered_empty_function (decl, false);
35149
35150   cgraph_node::add_new_function (decl, true);
35151   symtab->call_cgraph_insertion_hooks (cgraph_node::get_create (decl));
35152
35153   pop_cfun ();
35154
35155   gcc_assert (dispatch_decl != NULL);
35156   /* Mark dispatch_decl as "ifunc" with resolver as resolver_name.  */
35157   DECL_ATTRIBUTES (dispatch_decl) 
35158     = make_attribute ("ifunc", resolver_name, DECL_ATTRIBUTES (dispatch_decl));
35159
35160   /* Create the alias for dispatch to resolver here.  */
35161   /*cgraph_create_function_alias (dispatch_decl, decl);*/
35162   cgraph_node::create_same_body_alias (dispatch_decl, decl);
35163   XDELETEVEC (resolver_name);
35164   return decl;
35165 }
35166
35167 /* Generate the dispatching code body to dispatch multi-versioned function
35168    DECL.  The target hook is called to process the "target" attributes and
35169    provide the code to dispatch the right function at run-time.  NODE points
35170    to the dispatcher decl whose body will be created.  */
35171
35172 static tree 
35173 ix86_generate_version_dispatcher_body (void *node_p)
35174 {
35175   tree resolver_decl;
35176   basic_block empty_bb;
35177   tree default_ver_decl;
35178   struct cgraph_node *versn;
35179   struct cgraph_node *node;
35180
35181   struct cgraph_function_version_info *node_version_info = NULL;
35182   struct cgraph_function_version_info *versn_info = NULL;
35183
35184   node = (cgraph_node *)node_p;
35185
35186   node_version_info = node->function_version ();
35187   gcc_assert (node->dispatcher_function
35188               && node_version_info != NULL);
35189
35190   if (node_version_info->dispatcher_resolver)
35191     return node_version_info->dispatcher_resolver;
35192
35193   /* The first version in the chain corresponds to the default version.  */
35194   default_ver_decl = node_version_info->next->this_node->decl;
35195
35196   /* node is going to be an alias, so remove the finalized bit.  */
35197   node->definition = false;
35198
35199   resolver_decl = make_resolver_func (default_ver_decl,
35200                                       node->decl, &empty_bb);
35201
35202   node_version_info->dispatcher_resolver = resolver_decl;
35203
35204   push_cfun (DECL_STRUCT_FUNCTION (resolver_decl));
35205
35206   auto_vec<tree, 2> fn_ver_vec;
35207
35208   for (versn_info = node_version_info->next; versn_info;
35209        versn_info = versn_info->next)
35210     {
35211       versn = versn_info->this_node;
35212       /* Check for virtual functions here again, as by this time it should
35213          have been determined if this function needs a vtable index or
35214          not.  This happens for methods in derived classes that override
35215          virtual methods in base classes but are not explicitly marked as
35216          virtual.  */
35217       if (DECL_VINDEX (versn->decl))
35218         sorry ("Virtual function multiversioning not supported");
35219
35220       fn_ver_vec.safe_push (versn->decl);
35221     }
35222
35223   dispatch_function_versions (resolver_decl, &fn_ver_vec, &empty_bb);
35224   cgraph_edge::rebuild_edges ();
35225   pop_cfun ();
35226   return resolver_decl;
35227 }
35228 /* This builds the processor_model struct type defined in
35229    libgcc/config/i386/cpuinfo.c  */
35230
35231 static tree
35232 build_processor_model_struct (void)
35233 {
35234   const char *field_name[] = {"__cpu_vendor", "__cpu_type", "__cpu_subtype",
35235                               "__cpu_features"};
35236   tree field = NULL_TREE, field_chain = NULL_TREE;
35237   int i;
35238   tree type = make_node (RECORD_TYPE);
35239
35240   /* The first 3 fields are unsigned int.  */
35241   for (i = 0; i < 3; ++i)
35242     {
35243       field = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
35244                           get_identifier (field_name[i]), unsigned_type_node);
35245       if (field_chain != NULL_TREE)
35246         DECL_CHAIN (field) = field_chain;
35247       field_chain = field;
35248     }
35249
35250   /* The last field is an array of unsigned integers of size one.  */
35251   field = build_decl (UNKNOWN_LOCATION, FIELD_DECL,
35252                       get_identifier (field_name[3]),
35253                       build_array_type (unsigned_type_node,
35254                                         build_index_type (size_one_node)));
35255   if (field_chain != NULL_TREE)
35256     DECL_CHAIN (field) = field_chain;
35257   field_chain = field;
35258
35259   finish_builtin_struct (type, "__processor_model", field_chain, NULL_TREE);
35260   return type;
35261 }
35262
35263 /* Returns a extern, comdat VAR_DECL of type TYPE and name NAME. */
35264
35265 static tree
35266 make_var_decl (tree type, const char *name)
35267 {
35268   tree new_decl;
35269
35270   new_decl = build_decl (UNKNOWN_LOCATION,
35271                          VAR_DECL,
35272                          get_identifier(name),
35273                          type);
35274
35275   DECL_EXTERNAL (new_decl) = 1;
35276   TREE_STATIC (new_decl) = 1;
35277   TREE_PUBLIC (new_decl) = 1;
35278   DECL_INITIAL (new_decl) = 0;
35279   DECL_ARTIFICIAL (new_decl) = 0;
35280   DECL_PRESERVE_P (new_decl) = 1;
35281
35282   make_decl_one_only (new_decl, DECL_ASSEMBLER_NAME (new_decl));
35283   assemble_variable (new_decl, 0, 0, 0);
35284
35285   return new_decl;
35286 }
35287
35288 /* FNDECL is a __builtin_cpu_is or a __builtin_cpu_supports call that is folded
35289    into an integer defined in libgcc/config/i386/cpuinfo.c */
35290
35291 static tree
35292 fold_builtin_cpu (tree fndecl, tree *args)
35293 {
35294   unsigned int i;
35295   enum ix86_builtins fn_code = (enum ix86_builtins)
35296                                 DECL_FUNCTION_CODE (fndecl);
35297   tree param_string_cst = NULL;
35298
35299   /* This is the order of bit-fields in __processor_features in cpuinfo.c */
35300   enum processor_features
35301   {
35302     F_CMOV = 0,
35303     F_MMX,
35304     F_POPCNT,
35305     F_SSE,
35306     F_SSE2,
35307     F_SSE3,
35308     F_SSSE3,
35309     F_SSE4_1,
35310     F_SSE4_2,
35311     F_AVX,
35312     F_AVX2,
35313     F_SSE4_A,
35314     F_FMA4,
35315     F_XOP,
35316     F_FMA,
35317     F_AVX512F,
35318     F_BMI,
35319     F_BMI2,
35320     F_MAX
35321   };
35322
35323   /* These are the values for vendor types and cpu types  and subtypes
35324      in cpuinfo.c.  Cpu types and subtypes should be subtracted by
35325      the corresponding start value.  */
35326   enum processor_model
35327   {
35328     M_INTEL = 1,
35329     M_AMD,
35330     M_CPU_TYPE_START,
35331     M_INTEL_BONNELL,
35332     M_INTEL_CORE2,
35333     M_INTEL_COREI7,
35334     M_AMDFAM10H,
35335     M_AMDFAM15H,
35336     M_INTEL_SILVERMONT,
35337     M_INTEL_KNL,
35338     M_AMD_BTVER1,
35339     M_AMD_BTVER2,    
35340     M_CPU_SUBTYPE_START,
35341     M_INTEL_COREI7_NEHALEM,
35342     M_INTEL_COREI7_WESTMERE,
35343     M_INTEL_COREI7_SANDYBRIDGE,
35344     M_AMDFAM10H_BARCELONA,
35345     M_AMDFAM10H_SHANGHAI,
35346     M_AMDFAM10H_ISTANBUL,
35347     M_AMDFAM15H_BDVER1,
35348     M_AMDFAM15H_BDVER2,
35349     M_AMDFAM15H_BDVER3,
35350     M_AMDFAM15H_BDVER4,
35351     M_INTEL_COREI7_IVYBRIDGE,
35352     M_INTEL_COREI7_HASWELL,
35353     M_INTEL_COREI7_BROADWELL
35354   };
35355
35356   static struct _arch_names_table
35357     {
35358       const char *const name;
35359       const enum processor_model model;
35360     }
35361   const arch_names_table[] =
35362     {
35363       {"amd", M_AMD},
35364       {"intel", M_INTEL},
35365       {"atom", M_INTEL_BONNELL},
35366       {"slm", M_INTEL_SILVERMONT},
35367       {"core2", M_INTEL_CORE2},
35368       {"corei7", M_INTEL_COREI7},
35369       {"nehalem", M_INTEL_COREI7_NEHALEM},
35370       {"westmere", M_INTEL_COREI7_WESTMERE},
35371       {"sandybridge", M_INTEL_COREI7_SANDYBRIDGE},
35372       {"ivybridge", M_INTEL_COREI7_IVYBRIDGE},
35373       {"haswell", M_INTEL_COREI7_HASWELL},
35374       {"broadwell", M_INTEL_COREI7_BROADWELL},
35375       {"bonnell", M_INTEL_BONNELL},
35376       {"silvermont", M_INTEL_SILVERMONT},
35377       {"knl", M_INTEL_KNL},
35378       {"amdfam10h", M_AMDFAM10H},
35379       {"barcelona", M_AMDFAM10H_BARCELONA},
35380       {"shanghai", M_AMDFAM10H_SHANGHAI},
35381       {"istanbul", M_AMDFAM10H_ISTANBUL},
35382       {"btver1", M_AMD_BTVER1},      
35383       {"amdfam15h", M_AMDFAM15H},
35384       {"bdver1", M_AMDFAM15H_BDVER1},
35385       {"bdver2", M_AMDFAM15H_BDVER2},
35386       {"bdver3", M_AMDFAM15H_BDVER3},
35387       {"bdver4", M_AMDFAM15H_BDVER4},
35388       {"btver2", M_AMD_BTVER2},      
35389     };
35390
35391   static struct _isa_names_table
35392     {
35393       const char *const name;
35394       const enum processor_features feature;
35395     }
35396   const isa_names_table[] =
35397     {
35398       {"cmov",   F_CMOV},
35399       {"mmx",    F_MMX},
35400       {"popcnt", F_POPCNT},
35401       {"sse",    F_SSE},
35402       {"sse2",   F_SSE2},
35403       {"sse3",   F_SSE3},
35404       {"ssse3",  F_SSSE3},
35405       {"sse4a",  F_SSE4_A},
35406       {"sse4.1", F_SSE4_1},
35407       {"sse4.2", F_SSE4_2},
35408       {"avx",    F_AVX},
35409       {"fma4",   F_FMA4},
35410       {"xop",    F_XOP},
35411       {"fma",    F_FMA},
35412       {"avx2",   F_AVX2},
35413       {"avx512f",F_AVX512F},
35414       {"bmi",    F_BMI},
35415       {"bmi2",   F_BMI2}
35416     };
35417
35418   tree __processor_model_type = build_processor_model_struct ();
35419   tree __cpu_model_var = make_var_decl (__processor_model_type,
35420                                         "__cpu_model");
35421
35422
35423   varpool_node::add (__cpu_model_var);
35424
35425   gcc_assert ((args != NULL) && (*args != NULL));
35426
35427   param_string_cst = *args;
35428   while (param_string_cst
35429          && TREE_CODE (param_string_cst) !=  STRING_CST)
35430     {
35431       /* *args must be a expr that can contain other EXPRS leading to a
35432          STRING_CST.   */
35433       if (!EXPR_P (param_string_cst))
35434         {
35435           error ("Parameter to builtin must be a string constant or literal");
35436           return integer_zero_node;
35437         }
35438       param_string_cst = TREE_OPERAND (EXPR_CHECK (param_string_cst), 0);
35439     }
35440
35441   gcc_assert (param_string_cst);
35442
35443   if (fn_code == IX86_BUILTIN_CPU_IS)
35444     {
35445       tree ref;
35446       tree field;
35447       tree final;
35448
35449       unsigned int field_val = 0;
35450       unsigned int NUM_ARCH_NAMES
35451         = sizeof (arch_names_table) / sizeof (struct _arch_names_table);
35452
35453       for (i = 0; i < NUM_ARCH_NAMES; i++)
35454         if (strcmp (arch_names_table[i].name,
35455             TREE_STRING_POINTER (param_string_cst)) == 0)
35456           break;
35457
35458       if (i == NUM_ARCH_NAMES)
35459         {
35460           error ("Parameter to builtin not valid: %s",
35461                  TREE_STRING_POINTER (param_string_cst));
35462           return integer_zero_node;
35463         }
35464
35465       field = TYPE_FIELDS (__processor_model_type);
35466       field_val = arch_names_table[i].model;
35467
35468       /* CPU types are stored in the next field.  */
35469       if (field_val > M_CPU_TYPE_START
35470           && field_val < M_CPU_SUBTYPE_START)
35471         {
35472           field = DECL_CHAIN (field);
35473           field_val -= M_CPU_TYPE_START;
35474         }
35475
35476       /* CPU subtypes are stored in the next field.  */
35477       if (field_val > M_CPU_SUBTYPE_START)
35478         {
35479           field = DECL_CHAIN ( DECL_CHAIN (field));
35480           field_val -= M_CPU_SUBTYPE_START;
35481         }
35482
35483       /* Get the appropriate field in __cpu_model.  */
35484       ref =  build3 (COMPONENT_REF, TREE_TYPE (field), __cpu_model_var,
35485                      field, NULL_TREE);
35486
35487       /* Check the value.  */
35488       final = build2 (EQ_EXPR, unsigned_type_node, ref,
35489                       build_int_cstu (unsigned_type_node, field_val));
35490       return build1 (CONVERT_EXPR, integer_type_node, final);
35491     }
35492   else if (fn_code == IX86_BUILTIN_CPU_SUPPORTS)
35493     {
35494       tree ref;
35495       tree array_elt;
35496       tree field;
35497       tree final;
35498
35499       unsigned int field_val = 0;
35500       unsigned int NUM_ISA_NAMES
35501         = sizeof (isa_names_table) / sizeof (struct _isa_names_table);
35502
35503       for (i = 0; i < NUM_ISA_NAMES; i++)
35504         if (strcmp (isa_names_table[i].name,
35505             TREE_STRING_POINTER (param_string_cst)) == 0)
35506           break;
35507
35508       if (i == NUM_ISA_NAMES)
35509         {
35510           error ("Parameter to builtin not valid: %s",
35511                  TREE_STRING_POINTER (param_string_cst));
35512           return integer_zero_node;
35513         }
35514
35515       field = TYPE_FIELDS (__processor_model_type);
35516       /* Get the last field, which is __cpu_features.  */
35517       while (DECL_CHAIN (field))
35518         field = DECL_CHAIN (field);
35519
35520       /* Get the appropriate field: __cpu_model.__cpu_features  */
35521       ref =  build3 (COMPONENT_REF, TREE_TYPE (field), __cpu_model_var,
35522                      field, NULL_TREE);
35523
35524       /* Access the 0th element of __cpu_features array.  */
35525       array_elt = build4 (ARRAY_REF, unsigned_type_node, ref,
35526                           integer_zero_node, NULL_TREE, NULL_TREE);
35527
35528       field_val = (1 << isa_names_table[i].feature);
35529       /* Return __cpu_model.__cpu_features[0] & field_val  */
35530       final = build2 (BIT_AND_EXPR, unsigned_type_node, array_elt,
35531                       build_int_cstu (unsigned_type_node, field_val));
35532       return build1 (CONVERT_EXPR, integer_type_node, final);
35533     }
35534   gcc_unreachable ();
35535 }
35536
35537 static tree
35538 ix86_fold_builtin (tree fndecl, int n_args,
35539                    tree *args, bool ignore ATTRIBUTE_UNUSED)
35540 {
35541   if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
35542     {
35543       enum ix86_builtins fn_code = (enum ix86_builtins)
35544                                    DECL_FUNCTION_CODE (fndecl);
35545       if (fn_code ==  IX86_BUILTIN_CPU_IS
35546           || fn_code == IX86_BUILTIN_CPU_SUPPORTS)
35547         {
35548           gcc_assert (n_args == 1);
35549           return fold_builtin_cpu (fndecl, args);
35550         }
35551     }
35552
35553 #ifdef SUBTARGET_FOLD_BUILTIN
35554   return SUBTARGET_FOLD_BUILTIN (fndecl, n_args, args, ignore);
35555 #endif
35556
35557   return NULL_TREE;
35558 }
35559
35560 /* Make builtins to detect cpu type and features supported.  NAME is
35561    the builtin name, CODE is the builtin code, and FTYPE is the function
35562    type of the builtin.  */
35563
35564 static void
35565 make_cpu_type_builtin (const char* name, int code,
35566                        enum ix86_builtin_func_type ftype, bool is_const)
35567 {
35568   tree decl;
35569   tree type;
35570
35571   type = ix86_get_builtin_func_type (ftype);
35572   decl = add_builtin_function (name, type, code, BUILT_IN_MD,
35573                                NULL, NULL_TREE);
35574   gcc_assert (decl != NULL_TREE);
35575   ix86_builtins[(int) code] = decl;
35576   TREE_READONLY (decl) = is_const;
35577 }
35578
35579 /* Make builtins to get CPU type and features supported.  The created
35580    builtins are :
35581
35582    __builtin_cpu_init (), to detect cpu type and features,
35583    __builtin_cpu_is ("<CPUNAME>"), to check if cpu is of type <CPUNAME>,
35584    __builtin_cpu_supports ("<FEATURE>"), to check if cpu supports <FEATURE>
35585    */
35586
35587 static void
35588 ix86_init_platform_type_builtins (void)
35589 {
35590   make_cpu_type_builtin ("__builtin_cpu_init", IX86_BUILTIN_CPU_INIT,
35591                          INT_FTYPE_VOID, false);
35592   make_cpu_type_builtin ("__builtin_cpu_is", IX86_BUILTIN_CPU_IS,
35593                          INT_FTYPE_PCCHAR, true);
35594   make_cpu_type_builtin ("__builtin_cpu_supports", IX86_BUILTIN_CPU_SUPPORTS,
35595                          INT_FTYPE_PCCHAR, true);
35596 }
35597
35598 /* Internal method for ix86_init_builtins.  */
35599
35600 static void
35601 ix86_init_builtins_va_builtins_abi (void)
35602 {
35603   tree ms_va_ref, sysv_va_ref;
35604   tree fnvoid_va_end_ms, fnvoid_va_end_sysv;
35605   tree fnvoid_va_start_ms, fnvoid_va_start_sysv;
35606   tree fnvoid_va_copy_ms, fnvoid_va_copy_sysv;
35607   tree fnattr_ms = NULL_TREE, fnattr_sysv = NULL_TREE;
35608
35609   if (!TARGET_64BIT)
35610     return;
35611   fnattr_ms = build_tree_list (get_identifier ("ms_abi"), NULL_TREE);
35612   fnattr_sysv = build_tree_list (get_identifier ("sysv_abi"), NULL_TREE);
35613   ms_va_ref = build_reference_type (ms_va_list_type_node);
35614   sysv_va_ref =
35615     build_pointer_type (TREE_TYPE (sysv_va_list_type_node));
35616
35617   fnvoid_va_end_ms =
35618     build_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
35619   fnvoid_va_start_ms =
35620     build_varargs_function_type_list (void_type_node, ms_va_ref, NULL_TREE);
35621   fnvoid_va_end_sysv =
35622     build_function_type_list (void_type_node, sysv_va_ref, NULL_TREE);
35623   fnvoid_va_start_sysv =
35624     build_varargs_function_type_list (void_type_node, sysv_va_ref,
35625                                        NULL_TREE);
35626   fnvoid_va_copy_ms =
35627     build_function_type_list (void_type_node, ms_va_ref, ms_va_list_type_node,
35628                               NULL_TREE);
35629   fnvoid_va_copy_sysv =
35630     build_function_type_list (void_type_node, sysv_va_ref,
35631                               sysv_va_ref, NULL_TREE);
35632
35633   add_builtin_function ("__builtin_ms_va_start", fnvoid_va_start_ms,
35634                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_ms);
35635   add_builtin_function ("__builtin_ms_va_end", fnvoid_va_end_ms,
35636                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_ms);
35637   add_builtin_function ("__builtin_ms_va_copy", fnvoid_va_copy_ms,
35638                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_ms);
35639   add_builtin_function ("__builtin_sysv_va_start", fnvoid_va_start_sysv,
35640                         BUILT_IN_VA_START, BUILT_IN_NORMAL, NULL, fnattr_sysv);
35641   add_builtin_function ("__builtin_sysv_va_end", fnvoid_va_end_sysv,
35642                         BUILT_IN_VA_END, BUILT_IN_NORMAL, NULL, fnattr_sysv);
35643   add_builtin_function ("__builtin_sysv_va_copy", fnvoid_va_copy_sysv,
35644                         BUILT_IN_VA_COPY, BUILT_IN_NORMAL, NULL, fnattr_sysv);
35645 }
35646
35647 static void
35648 ix86_init_builtin_types (void)
35649 {
35650   tree float128_type_node, float80_type_node;
35651
35652   /* The __float80 type.  */
35653   float80_type_node = long_double_type_node;
35654   if (TYPE_MODE (float80_type_node) != XFmode)
35655     {
35656       /* The __float80 type.  */
35657       float80_type_node = make_node (REAL_TYPE);
35658
35659       TYPE_PRECISION (float80_type_node) = 80;
35660       layout_type (float80_type_node);
35661     }
35662   lang_hooks.types.register_builtin_type (float80_type_node, "__float80");
35663
35664   /* The __float128 type.  */
35665   float128_type_node = make_node (REAL_TYPE);
35666   TYPE_PRECISION (float128_type_node) = 128;
35667   layout_type (float128_type_node);
35668   lang_hooks.types.register_builtin_type (float128_type_node, "__float128");
35669
35670   /* This macro is built by i386-builtin-types.awk.  */
35671   DEFINE_BUILTIN_PRIMITIVE_TYPES;
35672 }
35673
35674 static void
35675 ix86_init_builtins (void)
35676 {
35677   tree t;
35678
35679   ix86_init_builtin_types ();
35680
35681   /* Builtins to get CPU type and features. */
35682   ix86_init_platform_type_builtins ();
35683
35684   /* TFmode support builtins.  */
35685   def_builtin_const (0, "__builtin_infq",
35686                      FLOAT128_FTYPE_VOID, IX86_BUILTIN_INFQ);
35687   def_builtin_const (0, "__builtin_huge_valq",
35688                      FLOAT128_FTYPE_VOID, IX86_BUILTIN_HUGE_VALQ);
35689
35690   /* We will expand them to normal call if SSE isn't available since
35691      they are used by libgcc. */
35692   t = ix86_get_builtin_func_type (FLOAT128_FTYPE_FLOAT128);
35693   t = add_builtin_function ("__builtin_fabsq", t, IX86_BUILTIN_FABSQ,
35694                             BUILT_IN_MD, "__fabstf2", NULL_TREE);
35695   TREE_READONLY (t) = 1;
35696   ix86_builtins[(int) IX86_BUILTIN_FABSQ] = t;
35697
35698   t = ix86_get_builtin_func_type (FLOAT128_FTYPE_FLOAT128_FLOAT128);
35699   t = add_builtin_function ("__builtin_copysignq", t, IX86_BUILTIN_COPYSIGNQ,
35700                             BUILT_IN_MD, "__copysigntf3", NULL_TREE);
35701   TREE_READONLY (t) = 1;
35702   ix86_builtins[(int) IX86_BUILTIN_COPYSIGNQ] = t;
35703
35704   ix86_init_tm_builtins ();
35705   ix86_init_mmx_sse_builtins ();
35706   ix86_init_mpx_builtins ();
35707
35708   if (TARGET_LP64)
35709     ix86_init_builtins_va_builtins_abi ();
35710
35711 #ifdef SUBTARGET_INIT_BUILTINS
35712   SUBTARGET_INIT_BUILTINS;
35713 #endif
35714 }
35715
35716 /* Return the ix86 builtin for CODE.  */
35717
35718 static tree
35719 ix86_builtin_decl (unsigned code, bool)
35720 {
35721   if (code >= IX86_BUILTIN_MAX)
35722     return error_mark_node;
35723
35724   return ix86_builtins[code];
35725 }
35726
35727 /* Errors in the source file can cause expand_expr to return const0_rtx
35728    where we expect a vector.  To avoid crashing, use one of the vector
35729    clear instructions.  */
35730 static rtx
35731 safe_vector_operand (rtx x, machine_mode mode)
35732 {
35733   if (x == const0_rtx)
35734     x = CONST0_RTX (mode);
35735   return x;
35736 }
35737
35738 /* Subroutine of ix86_expand_builtin to take care of binop insns.  */
35739
35740 static rtx
35741 ix86_expand_binop_builtin (enum insn_code icode, tree exp, rtx target)
35742 {
35743   rtx pat;
35744   tree arg0 = CALL_EXPR_ARG (exp, 0);
35745   tree arg1 = CALL_EXPR_ARG (exp, 1);
35746   rtx op0 = expand_normal (arg0);
35747   rtx op1 = expand_normal (arg1);
35748   machine_mode tmode = insn_data[icode].operand[0].mode;
35749   machine_mode mode0 = insn_data[icode].operand[1].mode;
35750   machine_mode mode1 = insn_data[icode].operand[2].mode;
35751
35752   if (VECTOR_MODE_P (mode0))
35753     op0 = safe_vector_operand (op0, mode0);
35754   if (VECTOR_MODE_P (mode1))
35755     op1 = safe_vector_operand (op1, mode1);
35756
35757   if (optimize || !target
35758       || GET_MODE (target) != tmode
35759       || !insn_data[icode].operand[0].predicate (target, tmode))
35760     target = gen_reg_rtx (tmode);
35761
35762   if (GET_MODE (op1) == SImode && mode1 == TImode)
35763     {
35764       rtx x = gen_reg_rtx (V4SImode);
35765       emit_insn (gen_sse2_loadd (x, op1));
35766       op1 = gen_lowpart (TImode, x);
35767     }
35768
35769   if (!insn_data[icode].operand[1].predicate (op0, mode0))
35770     op0 = copy_to_mode_reg (mode0, op0);
35771   if (!insn_data[icode].operand[2].predicate (op1, mode1))
35772     op1 = copy_to_mode_reg (mode1, op1);
35773
35774   pat = GEN_FCN (icode) (target, op0, op1);
35775   if (! pat)
35776     return 0;
35777
35778   emit_insn (pat);
35779
35780   return target;
35781 }
35782
35783 /* Subroutine of ix86_expand_builtin to take care of 2-4 argument insns.  */
35784
35785 static rtx
35786 ix86_expand_multi_arg_builtin (enum insn_code icode, tree exp, rtx target,
35787                                enum ix86_builtin_func_type m_type,
35788                                enum rtx_code sub_code)
35789 {
35790   rtx pat;
35791   int i;
35792   int nargs;
35793   bool comparison_p = false;
35794   bool tf_p = false;
35795   bool last_arg_constant = false;
35796   int num_memory = 0;
35797   struct {
35798     rtx op;
35799     machine_mode mode;
35800   } args[4];
35801
35802   machine_mode tmode = insn_data[icode].operand[0].mode;
35803
35804   switch (m_type)
35805     {
35806     case MULTI_ARG_4_DF2_DI_I:
35807     case MULTI_ARG_4_DF2_DI_I1:
35808     case MULTI_ARG_4_SF2_SI_I:
35809     case MULTI_ARG_4_SF2_SI_I1:
35810       nargs = 4;
35811       last_arg_constant = true;
35812       break;
35813
35814     case MULTI_ARG_3_SF:
35815     case MULTI_ARG_3_DF:
35816     case MULTI_ARG_3_SF2:
35817     case MULTI_ARG_3_DF2:
35818     case MULTI_ARG_3_DI:
35819     case MULTI_ARG_3_SI:
35820     case MULTI_ARG_3_SI_DI:
35821     case MULTI_ARG_3_HI:
35822     case MULTI_ARG_3_HI_SI:
35823     case MULTI_ARG_3_QI:
35824     case MULTI_ARG_3_DI2:
35825     case MULTI_ARG_3_SI2:
35826     case MULTI_ARG_3_HI2:
35827     case MULTI_ARG_3_QI2:
35828       nargs = 3;
35829       break;
35830
35831     case MULTI_ARG_2_SF:
35832     case MULTI_ARG_2_DF:
35833     case MULTI_ARG_2_DI:
35834     case MULTI_ARG_2_SI:
35835     case MULTI_ARG_2_HI:
35836     case MULTI_ARG_2_QI:
35837       nargs = 2;
35838       break;
35839
35840     case MULTI_ARG_2_DI_IMM:
35841     case MULTI_ARG_2_SI_IMM:
35842     case MULTI_ARG_2_HI_IMM:
35843     case MULTI_ARG_2_QI_IMM:
35844       nargs = 2;
35845       last_arg_constant = true;
35846       break;
35847
35848     case MULTI_ARG_1_SF:
35849     case MULTI_ARG_1_DF:
35850     case MULTI_ARG_1_SF2:
35851     case MULTI_ARG_1_DF2:
35852     case MULTI_ARG_1_DI:
35853     case MULTI_ARG_1_SI:
35854     case MULTI_ARG_1_HI:
35855     case MULTI_ARG_1_QI:
35856     case MULTI_ARG_1_SI_DI:
35857     case MULTI_ARG_1_HI_DI:
35858     case MULTI_ARG_1_HI_SI:
35859     case MULTI_ARG_1_QI_DI:
35860     case MULTI_ARG_1_QI_SI:
35861     case MULTI_ARG_1_QI_HI:
35862       nargs = 1;
35863       break;
35864
35865     case MULTI_ARG_2_DI_CMP:
35866     case MULTI_ARG_2_SI_CMP:
35867     case MULTI_ARG_2_HI_CMP:
35868     case MULTI_ARG_2_QI_CMP:
35869       nargs = 2;
35870       comparison_p = true;
35871       break;
35872
35873     case MULTI_ARG_2_SF_TF:
35874     case MULTI_ARG_2_DF_TF:
35875     case MULTI_ARG_2_DI_TF:
35876     case MULTI_ARG_2_SI_TF:
35877     case MULTI_ARG_2_HI_TF:
35878     case MULTI_ARG_2_QI_TF:
35879       nargs = 2;
35880       tf_p = true;
35881       break;
35882
35883     default:
35884       gcc_unreachable ();
35885     }
35886
35887   if (optimize || !target
35888       || GET_MODE (target) != tmode
35889       || !insn_data[icode].operand[0].predicate (target, tmode))
35890     target = gen_reg_rtx (tmode);
35891
35892   gcc_assert (nargs <= 4);
35893
35894   for (i = 0; i < nargs; i++)
35895     {
35896       tree arg = CALL_EXPR_ARG (exp, i);
35897       rtx op = expand_normal (arg);
35898       int adjust = (comparison_p) ? 1 : 0;
35899       machine_mode mode = insn_data[icode].operand[i+adjust+1].mode;
35900
35901       if (last_arg_constant && i == nargs - 1)
35902         {
35903           if (!insn_data[icode].operand[i + 1].predicate (op, mode))
35904             {
35905               enum insn_code new_icode = icode;
35906               switch (icode)
35907                 {
35908                 case CODE_FOR_xop_vpermil2v2df3:
35909                 case CODE_FOR_xop_vpermil2v4sf3:
35910                 case CODE_FOR_xop_vpermil2v4df3:
35911                 case CODE_FOR_xop_vpermil2v8sf3:
35912                   error ("the last argument must be a 2-bit immediate");
35913                   return gen_reg_rtx (tmode);
35914                 case CODE_FOR_xop_rotlv2di3:
35915                   new_icode = CODE_FOR_rotlv2di3;
35916                   goto xop_rotl;
35917                 case CODE_FOR_xop_rotlv4si3:
35918                   new_icode = CODE_FOR_rotlv4si3;
35919                   goto xop_rotl;
35920                 case CODE_FOR_xop_rotlv8hi3:
35921                   new_icode = CODE_FOR_rotlv8hi3;
35922                   goto xop_rotl;
35923                 case CODE_FOR_xop_rotlv16qi3:
35924                   new_icode = CODE_FOR_rotlv16qi3;
35925                 xop_rotl:
35926                   if (CONST_INT_P (op))
35927                     {
35928                       int mask = GET_MODE_BITSIZE (GET_MODE_INNER (tmode)) - 1;
35929                       op = GEN_INT (INTVAL (op) & mask);
35930                       gcc_checking_assert
35931                         (insn_data[icode].operand[i + 1].predicate (op, mode));
35932                     }
35933                   else
35934                     {
35935                       gcc_checking_assert
35936                         (nargs == 2
35937                          && insn_data[new_icode].operand[0].mode == tmode
35938                          && insn_data[new_icode].operand[1].mode == tmode
35939                          && insn_data[new_icode].operand[2].mode == mode
35940                          && insn_data[new_icode].operand[0].predicate
35941                             == insn_data[icode].operand[0].predicate
35942                          && insn_data[new_icode].operand[1].predicate
35943                             == insn_data[icode].operand[1].predicate);
35944                       icode = new_icode;
35945                       goto non_constant;
35946                     }
35947                   break;
35948                 default:
35949                   gcc_unreachable ();
35950                 }
35951             }
35952         }
35953       else
35954         {
35955         non_constant:
35956           if (VECTOR_MODE_P (mode))
35957             op = safe_vector_operand (op, mode);
35958
35959           /* If we aren't optimizing, only allow one memory operand to be
35960              generated.  */
35961           if (memory_operand (op, mode))
35962             num_memory++;
35963
35964           gcc_assert (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode);
35965
35966           if (optimize
35967               || !insn_data[icode].operand[i+adjust+1].predicate (op, mode)
35968               || num_memory > 1)
35969             op = force_reg (mode, op);
35970         }
35971
35972       args[i].op = op;
35973       args[i].mode = mode;
35974     }
35975
35976   switch (nargs)
35977     {
35978     case 1:
35979       pat = GEN_FCN (icode) (target, args[0].op);
35980       break;
35981
35982     case 2:
35983       if (tf_p)
35984         pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
35985                                GEN_INT ((int)sub_code));
35986       else if (! comparison_p)
35987         pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
35988       else
35989         {
35990           rtx cmp_op = gen_rtx_fmt_ee (sub_code, GET_MODE (target),
35991                                        args[0].op,
35992                                        args[1].op);
35993
35994           pat = GEN_FCN (icode) (target, cmp_op, args[0].op, args[1].op);
35995         }
35996       break;
35997
35998     case 3:
35999       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
36000       break;
36001
36002     case 4:
36003       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op, args[3].op);
36004       break;
36005
36006     default:
36007       gcc_unreachable ();
36008     }
36009
36010   if (! pat)
36011     return 0;
36012
36013   emit_insn (pat);
36014   return target;
36015 }
36016
36017 /* Subroutine of ix86_expand_args_builtin to take care of scalar unop
36018    insns with vec_merge.  */
36019
36020 static rtx
36021 ix86_expand_unop_vec_merge_builtin (enum insn_code icode, tree exp,
36022                                     rtx target)
36023 {
36024   rtx pat;
36025   tree arg0 = CALL_EXPR_ARG (exp, 0);
36026   rtx op1, op0 = expand_normal (arg0);
36027   machine_mode tmode = insn_data[icode].operand[0].mode;
36028   machine_mode mode0 = insn_data[icode].operand[1].mode;
36029
36030   if (optimize || !target
36031       || GET_MODE (target) != tmode
36032       || !insn_data[icode].operand[0].predicate (target, tmode))
36033     target = gen_reg_rtx (tmode);
36034
36035   if (VECTOR_MODE_P (mode0))
36036     op0 = safe_vector_operand (op0, mode0);
36037
36038   if ((optimize && !register_operand (op0, mode0))
36039       || !insn_data[icode].operand[1].predicate (op0, mode0))
36040     op0 = copy_to_mode_reg (mode0, op0);
36041
36042   op1 = op0;
36043   if (!insn_data[icode].operand[2].predicate (op1, mode0))
36044     op1 = copy_to_mode_reg (mode0, op1);
36045
36046   pat = GEN_FCN (icode) (target, op0, op1);
36047   if (! pat)
36048     return 0;
36049   emit_insn (pat);
36050   return target;
36051 }
36052
36053 /* Subroutine of ix86_expand_builtin to take care of comparison insns.  */
36054
36055 static rtx
36056 ix86_expand_sse_compare (const struct builtin_description *d,
36057                          tree exp, rtx target, bool swap)
36058 {
36059   rtx pat;
36060   tree arg0 = CALL_EXPR_ARG (exp, 0);
36061   tree arg1 = CALL_EXPR_ARG (exp, 1);
36062   rtx op0 = expand_normal (arg0);
36063   rtx op1 = expand_normal (arg1);
36064   rtx op2;
36065   machine_mode tmode = insn_data[d->icode].operand[0].mode;
36066   machine_mode mode0 = insn_data[d->icode].operand[1].mode;
36067   machine_mode mode1 = insn_data[d->icode].operand[2].mode;
36068   enum rtx_code comparison = d->comparison;
36069
36070   if (VECTOR_MODE_P (mode0))
36071     op0 = safe_vector_operand (op0, mode0);
36072   if (VECTOR_MODE_P (mode1))
36073     op1 = safe_vector_operand (op1, mode1);
36074
36075   /* Swap operands if we have a comparison that isn't available in
36076      hardware.  */
36077   if (swap)
36078     std::swap (op0, op1);
36079
36080   if (optimize || !target
36081       || GET_MODE (target) != tmode
36082       || !insn_data[d->icode].operand[0].predicate (target, tmode))
36083     target = gen_reg_rtx (tmode);
36084
36085   if ((optimize && !register_operand (op0, mode0))
36086       || !insn_data[d->icode].operand[1].predicate (op0, mode0))
36087     op0 = copy_to_mode_reg (mode0, op0);
36088   if ((optimize && !register_operand (op1, mode1))
36089       || !insn_data[d->icode].operand[2].predicate (op1, mode1))
36090     op1 = copy_to_mode_reg (mode1, op1);
36091
36092   op2 = gen_rtx_fmt_ee (comparison, mode0, op0, op1);
36093   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
36094   if (! pat)
36095     return 0;
36096   emit_insn (pat);
36097   return target;
36098 }
36099
36100 /* Subroutine of ix86_expand_builtin to take care of comi insns.  */
36101
36102 static rtx
36103 ix86_expand_sse_comi (const struct builtin_description *d, tree exp,
36104                       rtx target)
36105 {
36106   rtx pat;
36107   tree arg0 = CALL_EXPR_ARG (exp, 0);
36108   tree arg1 = CALL_EXPR_ARG (exp, 1);
36109   rtx op0 = expand_normal (arg0);
36110   rtx op1 = expand_normal (arg1);
36111   machine_mode mode0 = insn_data[d->icode].operand[0].mode;
36112   machine_mode mode1 = insn_data[d->icode].operand[1].mode;
36113   enum rtx_code comparison = d->comparison;
36114
36115   if (VECTOR_MODE_P (mode0))
36116     op0 = safe_vector_operand (op0, mode0);
36117   if (VECTOR_MODE_P (mode1))
36118     op1 = safe_vector_operand (op1, mode1);
36119
36120   /* Swap operands if we have a comparison that isn't available in
36121      hardware.  */
36122   if (d->flag & BUILTIN_DESC_SWAP_OPERANDS)
36123     std::swap (op0, op1);
36124
36125   target = gen_reg_rtx (SImode);
36126   emit_move_insn (target, const0_rtx);
36127   target = gen_rtx_SUBREG (QImode, target, 0);
36128
36129   if ((optimize && !register_operand (op0, mode0))
36130       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36131     op0 = copy_to_mode_reg (mode0, op0);
36132   if ((optimize && !register_operand (op1, mode1))
36133       || !insn_data[d->icode].operand[1].predicate (op1, mode1))
36134     op1 = copy_to_mode_reg (mode1, op1);
36135
36136   pat = GEN_FCN (d->icode) (op0, op1);
36137   if (! pat)
36138     return 0;
36139   emit_insn (pat);
36140   emit_insn (gen_rtx_SET (VOIDmode,
36141                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36142                           gen_rtx_fmt_ee (comparison, QImode,
36143                                           SET_DEST (pat),
36144                                           const0_rtx)));
36145
36146   return SUBREG_REG (target);
36147 }
36148
36149 /* Subroutines of ix86_expand_args_builtin to take care of round insns.  */
36150
36151 static rtx
36152 ix86_expand_sse_round (const struct builtin_description *d, tree exp,
36153                        rtx target)
36154 {
36155   rtx pat;
36156   tree arg0 = CALL_EXPR_ARG (exp, 0);
36157   rtx op1, op0 = expand_normal (arg0);
36158   machine_mode tmode = insn_data[d->icode].operand[0].mode;
36159   machine_mode mode0 = insn_data[d->icode].operand[1].mode;
36160
36161   if (optimize || target == 0
36162       || GET_MODE (target) != tmode
36163       || !insn_data[d->icode].operand[0].predicate (target, tmode))
36164     target = gen_reg_rtx (tmode);
36165
36166   if (VECTOR_MODE_P (mode0))
36167     op0 = safe_vector_operand (op0, mode0);
36168
36169   if ((optimize && !register_operand (op0, mode0))
36170       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36171     op0 = copy_to_mode_reg (mode0, op0);
36172
36173   op1 = GEN_INT (d->comparison);
36174
36175   pat = GEN_FCN (d->icode) (target, op0, op1);
36176   if (! pat)
36177     return 0;
36178   emit_insn (pat);
36179   return target;
36180 }
36181
36182 static rtx
36183 ix86_expand_sse_round_vec_pack_sfix (const struct builtin_description *d,
36184                                      tree exp, rtx target)
36185 {
36186   rtx pat;
36187   tree arg0 = CALL_EXPR_ARG (exp, 0);
36188   tree arg1 = CALL_EXPR_ARG (exp, 1);
36189   rtx op0 = expand_normal (arg0);
36190   rtx op1 = expand_normal (arg1);
36191   rtx op2;
36192   machine_mode tmode = insn_data[d->icode].operand[0].mode;
36193   machine_mode mode0 = insn_data[d->icode].operand[1].mode;
36194   machine_mode mode1 = insn_data[d->icode].operand[2].mode;
36195
36196   if (optimize || target == 0
36197       || GET_MODE (target) != tmode
36198       || !insn_data[d->icode].operand[0].predicate (target, tmode))
36199     target = gen_reg_rtx (tmode);
36200
36201   op0 = safe_vector_operand (op0, mode0);
36202   op1 = safe_vector_operand (op1, mode1);
36203
36204   if ((optimize && !register_operand (op0, mode0))
36205       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36206     op0 = copy_to_mode_reg (mode0, op0);
36207   if ((optimize && !register_operand (op1, mode1))
36208       || !insn_data[d->icode].operand[1].predicate (op1, mode1))
36209     op1 = copy_to_mode_reg (mode1, op1);
36210
36211   op2 = GEN_INT (d->comparison);
36212
36213   pat = GEN_FCN (d->icode) (target, op0, op1, op2);
36214   if (! pat)
36215     return 0;
36216   emit_insn (pat);
36217   return target;
36218 }
36219
36220 /* Subroutine of ix86_expand_builtin to take care of ptest insns.  */
36221
36222 static rtx
36223 ix86_expand_sse_ptest (const struct builtin_description *d, tree exp,
36224                        rtx target)
36225 {
36226   rtx pat;
36227   tree arg0 = CALL_EXPR_ARG (exp, 0);
36228   tree arg1 = CALL_EXPR_ARG (exp, 1);
36229   rtx op0 = expand_normal (arg0);
36230   rtx op1 = expand_normal (arg1);
36231   machine_mode mode0 = insn_data[d->icode].operand[0].mode;
36232   machine_mode mode1 = insn_data[d->icode].operand[1].mode;
36233   enum rtx_code comparison = d->comparison;
36234
36235   if (VECTOR_MODE_P (mode0))
36236     op0 = safe_vector_operand (op0, mode0);
36237   if (VECTOR_MODE_P (mode1))
36238     op1 = safe_vector_operand (op1, mode1);
36239
36240   target = gen_reg_rtx (SImode);
36241   emit_move_insn (target, const0_rtx);
36242   target = gen_rtx_SUBREG (QImode, target, 0);
36243
36244   if ((optimize && !register_operand (op0, mode0))
36245       || !insn_data[d->icode].operand[0].predicate (op0, mode0))
36246     op0 = copy_to_mode_reg (mode0, op0);
36247   if ((optimize && !register_operand (op1, mode1))
36248       || !insn_data[d->icode].operand[1].predicate (op1, mode1))
36249     op1 = copy_to_mode_reg (mode1, op1);
36250
36251   pat = GEN_FCN (d->icode) (op0, op1);
36252   if (! pat)
36253     return 0;
36254   emit_insn (pat);
36255   emit_insn (gen_rtx_SET (VOIDmode,
36256                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36257                           gen_rtx_fmt_ee (comparison, QImode,
36258                                           SET_DEST (pat),
36259                                           const0_rtx)));
36260
36261   return SUBREG_REG (target);
36262 }
36263
36264 /* Subroutine of ix86_expand_builtin to take care of pcmpestr[im] insns.  */
36265
36266 static rtx
36267 ix86_expand_sse_pcmpestr (const struct builtin_description *d,
36268                           tree exp, rtx target)
36269 {
36270   rtx pat;
36271   tree arg0 = CALL_EXPR_ARG (exp, 0);
36272   tree arg1 = CALL_EXPR_ARG (exp, 1);
36273   tree arg2 = CALL_EXPR_ARG (exp, 2);
36274   tree arg3 = CALL_EXPR_ARG (exp, 3);
36275   tree arg4 = CALL_EXPR_ARG (exp, 4);
36276   rtx scratch0, scratch1;
36277   rtx op0 = expand_normal (arg0);
36278   rtx op1 = expand_normal (arg1);
36279   rtx op2 = expand_normal (arg2);
36280   rtx op3 = expand_normal (arg3);
36281   rtx op4 = expand_normal (arg4);
36282   machine_mode tmode0, tmode1, modev2, modei3, modev4, modei5, modeimm;
36283
36284   tmode0 = insn_data[d->icode].operand[0].mode;
36285   tmode1 = insn_data[d->icode].operand[1].mode;
36286   modev2 = insn_data[d->icode].operand[2].mode;
36287   modei3 = insn_data[d->icode].operand[3].mode;
36288   modev4 = insn_data[d->icode].operand[4].mode;
36289   modei5 = insn_data[d->icode].operand[5].mode;
36290   modeimm = insn_data[d->icode].operand[6].mode;
36291
36292   if (VECTOR_MODE_P (modev2))
36293     op0 = safe_vector_operand (op0, modev2);
36294   if (VECTOR_MODE_P (modev4))
36295     op2 = safe_vector_operand (op2, modev4);
36296
36297   if (!insn_data[d->icode].operand[2].predicate (op0, modev2))
36298     op0 = copy_to_mode_reg (modev2, op0);
36299   if (!insn_data[d->icode].operand[3].predicate (op1, modei3))
36300     op1 = copy_to_mode_reg (modei3, op1);
36301   if ((optimize && !register_operand (op2, modev4))
36302       || !insn_data[d->icode].operand[4].predicate (op2, modev4))
36303     op2 = copy_to_mode_reg (modev4, op2);
36304   if (!insn_data[d->icode].operand[5].predicate (op3, modei5))
36305     op3 = copy_to_mode_reg (modei5, op3);
36306
36307   if (!insn_data[d->icode].operand[6].predicate (op4, modeimm))
36308     {
36309       error ("the fifth argument must be an 8-bit immediate");
36310       return const0_rtx;
36311     }
36312
36313   if (d->code == IX86_BUILTIN_PCMPESTRI128)
36314     {
36315       if (optimize || !target
36316           || GET_MODE (target) != tmode0
36317           || !insn_data[d->icode].operand[0].predicate (target, tmode0))
36318         target = gen_reg_rtx (tmode0);
36319
36320       scratch1 = gen_reg_rtx (tmode1);
36321
36322       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2, op3, op4);
36323     }
36324   else if (d->code == IX86_BUILTIN_PCMPESTRM128)
36325     {
36326       if (optimize || !target
36327           || GET_MODE (target) != tmode1
36328           || !insn_data[d->icode].operand[1].predicate (target, tmode1))
36329         target = gen_reg_rtx (tmode1);
36330
36331       scratch0 = gen_reg_rtx (tmode0);
36332
36333       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2, op3, op4);
36334     }
36335   else
36336     {
36337       gcc_assert (d->flag);
36338
36339       scratch0 = gen_reg_rtx (tmode0);
36340       scratch1 = gen_reg_rtx (tmode1);
36341
36342       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2, op3, op4);
36343     }
36344
36345   if (! pat)
36346     return 0;
36347
36348   emit_insn (pat);
36349
36350   if (d->flag)
36351     {
36352       target = gen_reg_rtx (SImode);
36353       emit_move_insn (target, const0_rtx);
36354       target = gen_rtx_SUBREG (QImode, target, 0);
36355
36356       emit_insn
36357         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36358                       gen_rtx_fmt_ee (EQ, QImode,
36359                                       gen_rtx_REG ((machine_mode) d->flag,
36360                                                    FLAGS_REG),
36361                                       const0_rtx)));
36362       return SUBREG_REG (target);
36363     }
36364   else
36365     return target;
36366 }
36367
36368
36369 /* Subroutine of ix86_expand_builtin to take care of pcmpistr[im] insns.  */
36370
36371 static rtx
36372 ix86_expand_sse_pcmpistr (const struct builtin_description *d,
36373                           tree exp, rtx target)
36374 {
36375   rtx pat;
36376   tree arg0 = CALL_EXPR_ARG (exp, 0);
36377   tree arg1 = CALL_EXPR_ARG (exp, 1);
36378   tree arg2 = CALL_EXPR_ARG (exp, 2);
36379   rtx scratch0, scratch1;
36380   rtx op0 = expand_normal (arg0);
36381   rtx op1 = expand_normal (arg1);
36382   rtx op2 = expand_normal (arg2);
36383   machine_mode tmode0, tmode1, modev2, modev3, modeimm;
36384
36385   tmode0 = insn_data[d->icode].operand[0].mode;
36386   tmode1 = insn_data[d->icode].operand[1].mode;
36387   modev2 = insn_data[d->icode].operand[2].mode;
36388   modev3 = insn_data[d->icode].operand[3].mode;
36389   modeimm = insn_data[d->icode].operand[4].mode;
36390
36391   if (VECTOR_MODE_P (modev2))
36392     op0 = safe_vector_operand (op0, modev2);
36393   if (VECTOR_MODE_P (modev3))
36394     op1 = safe_vector_operand (op1, modev3);
36395
36396   if (!insn_data[d->icode].operand[2].predicate (op0, modev2))
36397     op0 = copy_to_mode_reg (modev2, op0);
36398   if ((optimize && !register_operand (op1, modev3))
36399       || !insn_data[d->icode].operand[3].predicate (op1, modev3))
36400     op1 = copy_to_mode_reg (modev3, op1);
36401
36402   if (!insn_data[d->icode].operand[4].predicate (op2, modeimm))
36403     {
36404       error ("the third argument must be an 8-bit immediate");
36405       return const0_rtx;
36406     }
36407
36408   if (d->code == IX86_BUILTIN_PCMPISTRI128)
36409     {
36410       if (optimize || !target
36411           || GET_MODE (target) != tmode0
36412           || !insn_data[d->icode].operand[0].predicate (target, tmode0))
36413         target = gen_reg_rtx (tmode0);
36414
36415       scratch1 = gen_reg_rtx (tmode1);
36416
36417       pat = GEN_FCN (d->icode) (target, scratch1, op0, op1, op2);
36418     }
36419   else if (d->code == IX86_BUILTIN_PCMPISTRM128)
36420     {
36421       if (optimize || !target
36422           || GET_MODE (target) != tmode1
36423           || !insn_data[d->icode].operand[1].predicate (target, tmode1))
36424         target = gen_reg_rtx (tmode1);
36425
36426       scratch0 = gen_reg_rtx (tmode0);
36427
36428       pat = GEN_FCN (d->icode) (scratch0, target, op0, op1, op2);
36429     }
36430   else
36431     {
36432       gcc_assert (d->flag);
36433
36434       scratch0 = gen_reg_rtx (tmode0);
36435       scratch1 = gen_reg_rtx (tmode1);
36436
36437       pat = GEN_FCN (d->icode) (scratch0, scratch1, op0, op1, op2);
36438     }
36439
36440   if (! pat)
36441     return 0;
36442
36443   emit_insn (pat);
36444
36445   if (d->flag)
36446     {
36447       target = gen_reg_rtx (SImode);
36448       emit_move_insn (target, const0_rtx);
36449       target = gen_rtx_SUBREG (QImode, target, 0);
36450
36451       emit_insn
36452         (gen_rtx_SET (VOIDmode, gen_rtx_STRICT_LOW_PART (VOIDmode, target),
36453                       gen_rtx_fmt_ee (EQ, QImode,
36454                                       gen_rtx_REG ((machine_mode) d->flag,
36455                                                    FLAGS_REG),
36456                                       const0_rtx)));
36457       return SUBREG_REG (target);
36458     }
36459   else
36460     return target;
36461 }
36462
36463 /* Subroutine of ix86_expand_builtin to take care of insns with
36464    variable number of operands.  */
36465
36466 static rtx
36467 ix86_expand_args_builtin (const struct builtin_description *d,
36468                           tree exp, rtx target)
36469 {
36470   rtx pat, real_target;
36471   unsigned int i, nargs;
36472   unsigned int nargs_constant = 0;
36473   unsigned int mask_pos = 0;
36474   int num_memory = 0;
36475   struct
36476     {
36477       rtx op;
36478       machine_mode mode;
36479     } args[6];
36480   bool last_arg_count = false;
36481   enum insn_code icode = d->icode;
36482   const struct insn_data_d *insn_p = &insn_data[icode];
36483   machine_mode tmode = insn_p->operand[0].mode;
36484   machine_mode rmode = VOIDmode;
36485   bool swap = false;
36486   enum rtx_code comparison = d->comparison;
36487
36488   switch ((enum ix86_builtin_func_type) d->flag)
36489     {
36490     case V2DF_FTYPE_V2DF_ROUND:
36491     case V4DF_FTYPE_V4DF_ROUND:
36492     case V4SF_FTYPE_V4SF_ROUND:
36493     case V8SF_FTYPE_V8SF_ROUND:
36494     case V4SI_FTYPE_V4SF_ROUND:
36495     case V8SI_FTYPE_V8SF_ROUND:
36496       return ix86_expand_sse_round (d, exp, target);
36497     case V4SI_FTYPE_V2DF_V2DF_ROUND:
36498     case V8SI_FTYPE_V4DF_V4DF_ROUND:
36499     case V16SI_FTYPE_V8DF_V8DF_ROUND:
36500       return ix86_expand_sse_round_vec_pack_sfix (d, exp, target);
36501     case INT_FTYPE_V8SF_V8SF_PTEST:
36502     case INT_FTYPE_V4DI_V4DI_PTEST:
36503     case INT_FTYPE_V4DF_V4DF_PTEST:
36504     case INT_FTYPE_V4SF_V4SF_PTEST:
36505     case INT_FTYPE_V2DI_V2DI_PTEST:
36506     case INT_FTYPE_V2DF_V2DF_PTEST:
36507       return ix86_expand_sse_ptest (d, exp, target);
36508     case FLOAT128_FTYPE_FLOAT128:
36509     case FLOAT_FTYPE_FLOAT:
36510     case INT_FTYPE_INT:
36511     case UINT64_FTYPE_INT:
36512     case UINT16_FTYPE_UINT16:
36513     case INT64_FTYPE_INT64:
36514     case INT64_FTYPE_V4SF:
36515     case INT64_FTYPE_V2DF:
36516     case INT_FTYPE_V16QI:
36517     case INT_FTYPE_V8QI:
36518     case INT_FTYPE_V8SF:
36519     case INT_FTYPE_V4DF:
36520     case INT_FTYPE_V4SF:
36521     case INT_FTYPE_V2DF:
36522     case INT_FTYPE_V32QI:
36523     case V16QI_FTYPE_V16QI:
36524     case V8SI_FTYPE_V8SF:
36525     case V8SI_FTYPE_V4SI:
36526     case V8HI_FTYPE_V8HI:
36527     case V8HI_FTYPE_V16QI:
36528     case V8QI_FTYPE_V8QI:
36529     case V8SF_FTYPE_V8SF:
36530     case V8SF_FTYPE_V8SI:
36531     case V8SF_FTYPE_V4SF:
36532     case V8SF_FTYPE_V8HI:
36533     case V4SI_FTYPE_V4SI:
36534     case V4SI_FTYPE_V16QI:
36535     case V4SI_FTYPE_V4SF:
36536     case V4SI_FTYPE_V8SI:
36537     case V4SI_FTYPE_V8HI:
36538     case V4SI_FTYPE_V4DF:
36539     case V4SI_FTYPE_V2DF:
36540     case V4HI_FTYPE_V4HI:
36541     case V4DF_FTYPE_V4DF:
36542     case V4DF_FTYPE_V4SI:
36543     case V4DF_FTYPE_V4SF:
36544     case V4DF_FTYPE_V2DF:
36545     case V4SF_FTYPE_V4SF:
36546     case V4SF_FTYPE_V4SI:
36547     case V4SF_FTYPE_V8SF:
36548     case V4SF_FTYPE_V4DF:
36549     case V4SF_FTYPE_V8HI:
36550     case V4SF_FTYPE_V2DF:
36551     case V2DI_FTYPE_V2DI:
36552     case V2DI_FTYPE_V16QI:
36553     case V2DI_FTYPE_V8HI:
36554     case V2DI_FTYPE_V4SI:
36555     case V2DF_FTYPE_V2DF:
36556     case V2DF_FTYPE_V4SI:
36557     case V2DF_FTYPE_V4DF:
36558     case V2DF_FTYPE_V4SF:
36559     case V2DF_FTYPE_V2SI:
36560     case V2SI_FTYPE_V2SI:
36561     case V2SI_FTYPE_V4SF:
36562     case V2SI_FTYPE_V2SF:
36563     case V2SI_FTYPE_V2DF:
36564     case V2SF_FTYPE_V2SF:
36565     case V2SF_FTYPE_V2SI:
36566     case V32QI_FTYPE_V32QI:
36567     case V32QI_FTYPE_V16QI:
36568     case V16HI_FTYPE_V16HI:
36569     case V16HI_FTYPE_V8HI:
36570     case V8SI_FTYPE_V8SI:
36571     case V16HI_FTYPE_V16QI:
36572     case V8SI_FTYPE_V16QI:
36573     case V4DI_FTYPE_V16QI:
36574     case V8SI_FTYPE_V8HI:
36575     case V4DI_FTYPE_V8HI:
36576     case V4DI_FTYPE_V4SI:
36577     case V4DI_FTYPE_V2DI:
36578     case HI_FTYPE_HI:
36579     case HI_FTYPE_V16QI:
36580     case SI_FTYPE_V32QI:
36581     case DI_FTYPE_V64QI:
36582     case V16QI_FTYPE_HI:
36583     case V32QI_FTYPE_SI:
36584     case V64QI_FTYPE_DI:
36585     case V8HI_FTYPE_QI:
36586     case V16HI_FTYPE_HI:
36587     case V32HI_FTYPE_SI:
36588     case V4SI_FTYPE_QI:
36589     case V8SI_FTYPE_QI:
36590     case V4SI_FTYPE_HI:
36591     case V8SI_FTYPE_HI:
36592     case QI_FTYPE_V8HI:
36593     case HI_FTYPE_V16HI:
36594     case SI_FTYPE_V32HI:
36595     case QI_FTYPE_V4SI:
36596     case QI_FTYPE_V8SI:
36597     case HI_FTYPE_V16SI:
36598     case QI_FTYPE_V2DI:
36599     case QI_FTYPE_V4DI:
36600     case QI_FTYPE_V8DI:
36601     case UINT_FTYPE_V2DF:
36602     case UINT_FTYPE_V4SF:
36603     case UINT64_FTYPE_V2DF:
36604     case UINT64_FTYPE_V4SF:
36605     case V16QI_FTYPE_V8DI:
36606     case V16HI_FTYPE_V16SI:
36607     case V16SI_FTYPE_HI:
36608     case V2DI_FTYPE_QI:
36609     case V4DI_FTYPE_QI:
36610     case V16SI_FTYPE_V16SI:
36611     case V16SI_FTYPE_INT:
36612     case V16SF_FTYPE_FLOAT:
36613     case V16SF_FTYPE_V8SF:
36614     case V16SI_FTYPE_V8SI:
36615     case V16SF_FTYPE_V4SF:
36616     case V16SI_FTYPE_V4SI:
36617     case V16SF_FTYPE_V16SF:
36618     case V8HI_FTYPE_V8DI:
36619     case V8UHI_FTYPE_V8UHI:
36620     case V8SI_FTYPE_V8DI:
36621     case V8SF_FTYPE_V8DF:
36622     case V8DI_FTYPE_QI:
36623     case V8DI_FTYPE_INT64:
36624     case V8DI_FTYPE_V4DI:
36625     case V8DI_FTYPE_V8DI:
36626     case V8DF_FTYPE_DOUBLE:
36627     case V8DF_FTYPE_V4DF:
36628     case V8DF_FTYPE_V2DF:
36629     case V8DF_FTYPE_V8DF:
36630     case V8DF_FTYPE_V8SI:
36631       nargs = 1;
36632       break;
36633     case V4SF_FTYPE_V4SF_VEC_MERGE:
36634     case V2DF_FTYPE_V2DF_VEC_MERGE:
36635       return ix86_expand_unop_vec_merge_builtin (icode, exp, target);
36636     case FLOAT128_FTYPE_FLOAT128_FLOAT128:
36637     case V16QI_FTYPE_V16QI_V16QI:
36638     case V16QI_FTYPE_V8HI_V8HI:
36639     case V16SI_FTYPE_V16SI_V16SI:
36640     case V16SF_FTYPE_V16SF_V16SF:
36641     case V16SF_FTYPE_V16SF_V16SI:
36642     case V8QI_FTYPE_V8QI_V8QI:
36643     case V8QI_FTYPE_V4HI_V4HI:
36644     case V8HI_FTYPE_V8HI_V8HI:
36645     case V8HI_FTYPE_V16QI_V16QI:
36646     case V8HI_FTYPE_V4SI_V4SI:
36647     case V8SF_FTYPE_V8SF_V8SF:
36648     case V8SF_FTYPE_V8SF_V8SI:
36649     case V8DI_FTYPE_V8DI_V8DI:
36650     case V8DF_FTYPE_V8DF_V8DF:
36651     case V8DF_FTYPE_V8DF_V8DI:
36652     case V4SI_FTYPE_V4SI_V4SI:
36653     case V4SI_FTYPE_V8HI_V8HI:
36654     case V4SI_FTYPE_V4SF_V4SF:
36655     case V4SI_FTYPE_V2DF_V2DF:
36656     case V4HI_FTYPE_V4HI_V4HI:
36657     case V4HI_FTYPE_V8QI_V8QI:
36658     case V4HI_FTYPE_V2SI_V2SI:
36659     case V4DF_FTYPE_V4DF_V4DF:
36660     case V4DF_FTYPE_V4DF_V4DI:
36661     case V4SF_FTYPE_V4SF_V4SF:
36662     case V4SF_FTYPE_V4SF_V4SI:
36663     case V4SF_FTYPE_V4SF_V2SI:
36664     case V4SF_FTYPE_V4SF_V2DF:
36665     case V4SF_FTYPE_V4SF_UINT:
36666     case V4SF_FTYPE_V4SF_UINT64:
36667     case V4SF_FTYPE_V4SF_DI:
36668     case V4SF_FTYPE_V4SF_SI:
36669     case V2DI_FTYPE_V2DI_V2DI:
36670     case V2DI_FTYPE_V16QI_V16QI:
36671     case V2DI_FTYPE_V4SI_V4SI:
36672     case V2UDI_FTYPE_V4USI_V4USI:
36673     case V2DI_FTYPE_V2DI_V16QI:
36674     case V2DI_FTYPE_V2DF_V2DF:
36675     case V2SI_FTYPE_V2SI_V2SI:
36676     case V2SI_FTYPE_V4HI_V4HI:
36677     case V2SI_FTYPE_V2SF_V2SF:
36678     case V2DF_FTYPE_V2DF_V2DF:
36679     case V2DF_FTYPE_V2DF_V4SF:
36680     case V2DF_FTYPE_V2DF_V2DI:
36681     case V2DF_FTYPE_V2DF_DI:
36682     case V2DF_FTYPE_V2DF_SI:
36683     case V2DF_FTYPE_V2DF_UINT:
36684     case V2DF_FTYPE_V2DF_UINT64:
36685     case V2SF_FTYPE_V2SF_V2SF:
36686     case V1DI_FTYPE_V1DI_V1DI:
36687     case V1DI_FTYPE_V8QI_V8QI:
36688     case V1DI_FTYPE_V2SI_V2SI:
36689     case V32QI_FTYPE_V16HI_V16HI:
36690     case V16HI_FTYPE_V8SI_V8SI:
36691     case V32QI_FTYPE_V32QI_V32QI:
36692     case V16HI_FTYPE_V32QI_V32QI:
36693     case V16HI_FTYPE_V16HI_V16HI:
36694     case V8SI_FTYPE_V4DF_V4DF:
36695     case V8SI_FTYPE_V8SI_V8SI:
36696     case V8SI_FTYPE_V16HI_V16HI:
36697     case V4DI_FTYPE_V4DI_V4DI:
36698     case V4DI_FTYPE_V8SI_V8SI:
36699     case V4UDI_FTYPE_V8USI_V8USI:
36700     case QI_FTYPE_V8DI_V8DI:
36701     case V8DI_FTYPE_V64QI_V64QI:
36702     case HI_FTYPE_V16SI_V16SI:
36703       if (comparison == UNKNOWN)
36704         return ix86_expand_binop_builtin (icode, exp, target);
36705       nargs = 2;
36706       break;
36707     case V4SF_FTYPE_V4SF_V4SF_SWAP:
36708     case V2DF_FTYPE_V2DF_V2DF_SWAP:
36709       gcc_assert (comparison != UNKNOWN);
36710       nargs = 2;
36711       swap = true;
36712       break;
36713     case V16HI_FTYPE_V16HI_V8HI_COUNT:
36714     case V16HI_FTYPE_V16HI_SI_COUNT:
36715     case V8SI_FTYPE_V8SI_V4SI_COUNT:
36716     case V8SI_FTYPE_V8SI_SI_COUNT:
36717     case V4DI_FTYPE_V4DI_V2DI_COUNT:
36718     case V4DI_FTYPE_V4DI_INT_COUNT:
36719     case V8HI_FTYPE_V8HI_V8HI_COUNT:
36720     case V8HI_FTYPE_V8HI_SI_COUNT:
36721     case V4SI_FTYPE_V4SI_V4SI_COUNT:
36722     case V4SI_FTYPE_V4SI_SI_COUNT:
36723     case V4HI_FTYPE_V4HI_V4HI_COUNT:
36724     case V4HI_FTYPE_V4HI_SI_COUNT:
36725     case V2DI_FTYPE_V2DI_V2DI_COUNT:
36726     case V2DI_FTYPE_V2DI_SI_COUNT:
36727     case V2SI_FTYPE_V2SI_V2SI_COUNT:
36728     case V2SI_FTYPE_V2SI_SI_COUNT:
36729     case V1DI_FTYPE_V1DI_V1DI_COUNT:
36730     case V1DI_FTYPE_V1DI_SI_COUNT:
36731       nargs = 2;
36732       last_arg_count = true;
36733       break;
36734     case UINT64_FTYPE_UINT64_UINT64:
36735     case UINT_FTYPE_UINT_UINT:
36736     case UINT_FTYPE_UINT_USHORT:
36737     case UINT_FTYPE_UINT_UCHAR:
36738     case UINT16_FTYPE_UINT16_INT:
36739     case UINT8_FTYPE_UINT8_INT:
36740     case HI_FTYPE_HI_HI:
36741     case SI_FTYPE_SI_SI:
36742     case DI_FTYPE_DI_DI:
36743     case V16SI_FTYPE_V8DF_V8DF:
36744       nargs = 2;
36745       break;
36746     case V2DI_FTYPE_V2DI_INT_CONVERT:
36747       nargs = 2;
36748       rmode = V1TImode;
36749       nargs_constant = 1;
36750       break;
36751     case V4DI_FTYPE_V4DI_INT_CONVERT:
36752       nargs = 2;
36753       rmode = V2TImode;
36754       nargs_constant = 1;
36755       break;
36756     case V8DI_FTYPE_V8DI_INT_CONVERT:
36757       nargs = 2;
36758       rmode = V4TImode;
36759       nargs_constant = 1;
36760       break;
36761     case V8HI_FTYPE_V8HI_INT:
36762     case V8HI_FTYPE_V8SF_INT:
36763     case V16HI_FTYPE_V16SF_INT:
36764     case V8HI_FTYPE_V4SF_INT:
36765     case V8SF_FTYPE_V8SF_INT:
36766     case V4SF_FTYPE_V16SF_INT:
36767     case V16SF_FTYPE_V16SF_INT:
36768     case V4SI_FTYPE_V4SI_INT:
36769     case V4SI_FTYPE_V8SI_INT:
36770     case V4HI_FTYPE_V4HI_INT:
36771     case V4DF_FTYPE_V4DF_INT:
36772     case V4DF_FTYPE_V8DF_INT:
36773     case V4SF_FTYPE_V4SF_INT:
36774     case V4SF_FTYPE_V8SF_INT:
36775     case V2DI_FTYPE_V2DI_INT:
36776     case V2DF_FTYPE_V2DF_INT:
36777     case V2DF_FTYPE_V4DF_INT:
36778     case V16HI_FTYPE_V16HI_INT:
36779     case V8SI_FTYPE_V8SI_INT:
36780     case V16SI_FTYPE_V16SI_INT:
36781     case V4SI_FTYPE_V16SI_INT:
36782     case V4DI_FTYPE_V4DI_INT:
36783     case V2DI_FTYPE_V4DI_INT:
36784     case V4DI_FTYPE_V8DI_INT:
36785     case HI_FTYPE_HI_INT:
36786     case QI_FTYPE_V4SF_INT:
36787     case QI_FTYPE_V2DF_INT:
36788       nargs = 2;
36789       nargs_constant = 1;
36790       break;
36791     case V16QI_FTYPE_V16QI_V16QI_V16QI:
36792     case V8SF_FTYPE_V8SF_V8SF_V8SF:
36793     case V4DF_FTYPE_V4DF_V4DF_V4DF:
36794     case V4SF_FTYPE_V4SF_V4SF_V4SF:
36795     case V2DF_FTYPE_V2DF_V2DF_V2DF:
36796     case V32QI_FTYPE_V32QI_V32QI_V32QI:
36797     case HI_FTYPE_V16SI_V16SI_HI:
36798     case QI_FTYPE_V8DI_V8DI_QI:
36799     case V16HI_FTYPE_V16SI_V16HI_HI:
36800     case V16QI_FTYPE_V16SI_V16QI_HI:
36801     case V16QI_FTYPE_V8DI_V16QI_QI:
36802     case V16SF_FTYPE_V16SF_V16SF_HI:
36803     case V16SF_FTYPE_V16SF_V16SF_V16SF:
36804     case V16SF_FTYPE_V16SF_V16SI_V16SF:
36805     case V16SF_FTYPE_V16SI_V16SF_HI:
36806     case V16SF_FTYPE_V16SI_V16SF_V16SF:
36807     case V16SF_FTYPE_V4SF_V16SF_HI:
36808     case V16SI_FTYPE_SI_V16SI_HI:
36809     case V16SI_FTYPE_V16HI_V16SI_HI:
36810     case V16SI_FTYPE_V16QI_V16SI_HI:
36811     case V16SI_FTYPE_V16SF_V16SI_HI:
36812     case V8SF_FTYPE_V4SF_V8SF_QI:
36813     case V4DF_FTYPE_V2DF_V4DF_QI:
36814     case V8SI_FTYPE_V4SI_V8SI_QI:
36815     case V8SI_FTYPE_SI_V8SI_QI:
36816     case V4SI_FTYPE_V4SI_V4SI_QI:
36817     case V4SI_FTYPE_SI_V4SI_QI:
36818     case V4DI_FTYPE_V2DI_V4DI_QI:
36819     case V4DI_FTYPE_DI_V4DI_QI:
36820     case V2DI_FTYPE_V2DI_V2DI_QI:
36821     case V2DI_FTYPE_DI_V2DI_QI:
36822     case V64QI_FTYPE_V64QI_V64QI_DI:
36823     case V64QI_FTYPE_V16QI_V64QI_DI:
36824     case V64QI_FTYPE_QI_V64QI_DI:
36825     case V32QI_FTYPE_V32QI_V32QI_SI:
36826     case V32QI_FTYPE_V16QI_V32QI_SI:
36827     case V32QI_FTYPE_QI_V32QI_SI:
36828     case V16QI_FTYPE_V16QI_V16QI_HI:
36829     case V16QI_FTYPE_QI_V16QI_HI:
36830     case V32HI_FTYPE_V8HI_V32HI_SI:
36831     case V32HI_FTYPE_HI_V32HI_SI:
36832     case V16HI_FTYPE_V8HI_V16HI_HI:
36833     case V16HI_FTYPE_HI_V16HI_HI:
36834     case V8HI_FTYPE_V8HI_V8HI_QI:
36835     case V8HI_FTYPE_HI_V8HI_QI:
36836     case V8SF_FTYPE_V8HI_V8SF_QI:
36837     case V4SF_FTYPE_V8HI_V4SF_QI:
36838     case V8SI_FTYPE_V8SF_V8SI_QI:
36839     case V4SI_FTYPE_V4SF_V4SI_QI:
36840     case V8DI_FTYPE_V8SF_V8DI_QI:
36841     case V4DI_FTYPE_V4SF_V4DI_QI:
36842     case V2DI_FTYPE_V4SF_V2DI_QI:
36843     case V8SF_FTYPE_V8DI_V8SF_QI:
36844     case V4SF_FTYPE_V4DI_V4SF_QI:
36845     case V4SF_FTYPE_V2DI_V4SF_QI:
36846     case V8DF_FTYPE_V8DI_V8DF_QI:
36847     case V4DF_FTYPE_V4DI_V4DF_QI:
36848     case V2DF_FTYPE_V2DI_V2DF_QI:
36849     case V16QI_FTYPE_V8HI_V16QI_QI:
36850     case V16QI_FTYPE_V16HI_V16QI_HI:
36851     case V16QI_FTYPE_V4SI_V16QI_QI:
36852     case V16QI_FTYPE_V8SI_V16QI_QI:
36853     case V8HI_FTYPE_V4SI_V8HI_QI:
36854     case V8HI_FTYPE_V8SI_V8HI_QI:
36855     case V16QI_FTYPE_V2DI_V16QI_QI:
36856     case V16QI_FTYPE_V4DI_V16QI_QI:
36857     case V8HI_FTYPE_V2DI_V8HI_QI:
36858     case V8HI_FTYPE_V4DI_V8HI_QI:
36859     case V4SI_FTYPE_V2DI_V4SI_QI:
36860     case V4SI_FTYPE_V4DI_V4SI_QI:
36861     case V32QI_FTYPE_V32HI_V32QI_SI:
36862     case HI_FTYPE_V16QI_V16QI_HI:
36863     case SI_FTYPE_V32QI_V32QI_SI:
36864     case DI_FTYPE_V64QI_V64QI_DI:
36865     case QI_FTYPE_V8HI_V8HI_QI:
36866     case HI_FTYPE_V16HI_V16HI_HI:
36867     case SI_FTYPE_V32HI_V32HI_SI:
36868     case QI_FTYPE_V4SI_V4SI_QI:
36869     case QI_FTYPE_V8SI_V8SI_QI:
36870     case QI_FTYPE_V2DI_V2DI_QI:
36871     case QI_FTYPE_V4DI_V4DI_QI:
36872     case V4SF_FTYPE_V2DF_V4SF_QI:
36873     case V4SF_FTYPE_V4DF_V4SF_QI:
36874     case V16SI_FTYPE_V16SI_V16SI_HI:
36875     case V16SI_FTYPE_V16SI_V16SI_V16SI:
36876     case V16SI_FTYPE_V4SI_V16SI_HI:
36877     case V2DI_FTYPE_V2DI_V2DI_V2DI:
36878     case V2DI_FTYPE_V4SI_V2DI_QI:
36879     case V2DI_FTYPE_V8HI_V2DI_QI:
36880     case V2DI_FTYPE_V16QI_V2DI_QI:
36881     case V4DI_FTYPE_V4DI_V4DI_QI:
36882     case V4DI_FTYPE_V4SI_V4DI_QI:
36883     case V4DI_FTYPE_V8HI_V4DI_QI:
36884     case V4DI_FTYPE_V16QI_V4DI_QI:
36885     case V8DI_FTYPE_V8DF_V8DI_QI:
36886     case V4DI_FTYPE_V4DF_V4DI_QI:
36887     case V2DI_FTYPE_V2DF_V2DI_QI:
36888     case V4SI_FTYPE_V4DF_V4SI_QI:
36889     case V4SI_FTYPE_V2DF_V4SI_QI:
36890     case V4SI_FTYPE_V8HI_V4SI_QI:
36891     case V4SI_FTYPE_V16QI_V4SI_QI:
36892     case V8SI_FTYPE_V8SI_V8SI_V8SI:
36893     case V4DI_FTYPE_V4DI_V4DI_V4DI:
36894     case V8DF_FTYPE_V2DF_V8DF_QI:
36895     case V8DF_FTYPE_V4DF_V8DF_QI:
36896     case V8DF_FTYPE_V8DF_V8DF_QI:
36897     case V8DF_FTYPE_V8DF_V8DF_V8DF:
36898     case V8SF_FTYPE_V8SF_V8SF_QI:
36899     case V8SF_FTYPE_V8SI_V8SF_QI:
36900     case V4DF_FTYPE_V4DF_V4DF_QI:
36901     case V4SF_FTYPE_V4SF_V4SF_QI:
36902     case V2DF_FTYPE_V2DF_V2DF_QI:
36903     case V2DF_FTYPE_V4SF_V2DF_QI:
36904     case V2DF_FTYPE_V4SI_V2DF_QI:
36905     case V4SF_FTYPE_V4SI_V4SF_QI:
36906     case V4DF_FTYPE_V4SF_V4DF_QI:
36907     case V4DF_FTYPE_V4SI_V4DF_QI:
36908     case V8SI_FTYPE_V8SI_V8SI_QI:
36909     case V8SI_FTYPE_V8HI_V8SI_QI:
36910     case V8SI_FTYPE_V16QI_V8SI_QI:
36911     case V8DF_FTYPE_V8DF_V8DI_V8DF:
36912     case V8DF_FTYPE_V8DI_V8DF_V8DF:
36913     case V8DF_FTYPE_V8SF_V8DF_QI:
36914     case V8DF_FTYPE_V8SI_V8DF_QI:
36915     case V8DI_FTYPE_DI_V8DI_QI:
36916     case V16SF_FTYPE_V8SF_V16SF_HI:
36917     case V16SI_FTYPE_V8SI_V16SI_HI:
36918     case V16HI_FTYPE_V16HI_V16HI_HI:
36919     case V8HI_FTYPE_V16QI_V8HI_QI:
36920     case V16HI_FTYPE_V16QI_V16HI_HI:
36921     case V32HI_FTYPE_V32HI_V32HI_SI:
36922     case V32HI_FTYPE_V32QI_V32HI_SI:
36923     case V8DI_FTYPE_V16QI_V8DI_QI:
36924     case V8DI_FTYPE_V2DI_V8DI_QI:
36925     case V8DI_FTYPE_V4DI_V8DI_QI:
36926     case V8DI_FTYPE_V8DI_V8DI_QI:
36927     case V8DI_FTYPE_V8DI_V8DI_V8DI:
36928     case V8DI_FTYPE_V8HI_V8DI_QI:
36929     case V8DI_FTYPE_V8SI_V8DI_QI:
36930     case V8HI_FTYPE_V8DI_V8HI_QI:
36931     case V8SF_FTYPE_V8DF_V8SF_QI:
36932     case V8SI_FTYPE_V8DF_V8SI_QI:
36933     case V8SI_FTYPE_V8DI_V8SI_QI:
36934     case V4SI_FTYPE_V4SI_V4SI_V4SI:
36935       nargs = 3;
36936       break;
36937     case V32QI_FTYPE_V32QI_V32QI_INT:
36938     case V16HI_FTYPE_V16HI_V16HI_INT:
36939     case V16QI_FTYPE_V16QI_V16QI_INT:
36940     case V4DI_FTYPE_V4DI_V4DI_INT:
36941     case V8HI_FTYPE_V8HI_V8HI_INT:
36942     case V8SI_FTYPE_V8SI_V8SI_INT:
36943     case V8SI_FTYPE_V8SI_V4SI_INT:
36944     case V8SF_FTYPE_V8SF_V8SF_INT:
36945     case V8SF_FTYPE_V8SF_V4SF_INT:
36946     case V4SI_FTYPE_V4SI_V4SI_INT:
36947     case V4DF_FTYPE_V4DF_V4DF_INT:
36948     case V16SF_FTYPE_V16SF_V16SF_INT:
36949     case V16SF_FTYPE_V16SF_V4SF_INT:
36950     case V16SI_FTYPE_V16SI_V4SI_INT:
36951     case V4DF_FTYPE_V4DF_V2DF_INT:
36952     case V4SF_FTYPE_V4SF_V4SF_INT:
36953     case V2DI_FTYPE_V2DI_V2DI_INT:
36954     case V4DI_FTYPE_V4DI_V2DI_INT:
36955     case V2DF_FTYPE_V2DF_V2DF_INT:
36956     case QI_FTYPE_V8DI_V8DI_INT:
36957     case QI_FTYPE_V8DF_V8DF_INT:
36958     case QI_FTYPE_V2DF_V2DF_INT:
36959     case QI_FTYPE_V4SF_V4SF_INT:
36960     case HI_FTYPE_V16SI_V16SI_INT:
36961     case HI_FTYPE_V16SF_V16SF_INT:
36962       nargs = 3;
36963       nargs_constant = 1;
36964       break;
36965     case V4DI_FTYPE_V4DI_V4DI_INT_CONVERT:
36966       nargs = 3;
36967       rmode = V4DImode;
36968       nargs_constant = 1;
36969       break;
36970     case V2DI_FTYPE_V2DI_V2DI_INT_CONVERT:
36971       nargs = 3;
36972       rmode = V2DImode;
36973       nargs_constant = 1;
36974       break;
36975     case V1DI_FTYPE_V1DI_V1DI_INT_CONVERT:
36976       nargs = 3;
36977       rmode = DImode;
36978       nargs_constant = 1;
36979       break;
36980     case V2DI_FTYPE_V2DI_UINT_UINT:
36981       nargs = 3;
36982       nargs_constant = 2;
36983       break;
36984     case V8DI_FTYPE_V8DI_V8DI_INT_CONVERT:
36985       nargs = 3;
36986       rmode = V8DImode;
36987       nargs_constant = 1;
36988       break;
36989     case V8DI_FTYPE_V8DI_V8DI_INT_V8DI_DI_CONVERT:
36990       nargs = 5;
36991       rmode = V8DImode;
36992       mask_pos = 2;
36993       nargs_constant = 1;
36994       break;
36995     case QI_FTYPE_V8DF_INT_QI:
36996     case QI_FTYPE_V4DF_INT_QI:
36997     case QI_FTYPE_V2DF_INT_QI:
36998     case HI_FTYPE_V16SF_INT_HI:
36999     case QI_FTYPE_V8SF_INT_QI:
37000     case QI_FTYPE_V4SF_INT_QI:
37001       nargs = 3;
37002       mask_pos = 1;
37003       nargs_constant = 1;
37004       break;
37005     case V4DI_FTYPE_V4DI_V4DI_INT_V4DI_SI_CONVERT:
37006       nargs = 5;
37007       rmode = V4DImode;
37008       mask_pos = 2;
37009       nargs_constant = 1;
37010       break;
37011     case V2DI_FTYPE_V2DI_V2DI_INT_V2DI_HI_CONVERT:
37012       nargs = 5;
37013       rmode = V2DImode;
37014       mask_pos = 2;
37015       nargs_constant = 1;
37016       break;
37017     case V32QI_FTYPE_V32QI_V32QI_V32QI_SI:
37018     case V32HI_FTYPE_V32HI_V32HI_V32HI_SI:
37019     case V32HI_FTYPE_V64QI_V64QI_V32HI_SI:
37020     case V16SI_FTYPE_V32HI_V32HI_V16SI_HI:
37021     case V64QI_FTYPE_V64QI_V64QI_V64QI_DI:
37022     case V32HI_FTYPE_V32HI_V8HI_V32HI_SI:
37023     case V16HI_FTYPE_V16HI_V8HI_V16HI_HI:
37024     case V8SI_FTYPE_V8SI_V4SI_V8SI_QI:
37025     case V4DI_FTYPE_V4DI_V2DI_V4DI_QI:
37026     case V64QI_FTYPE_V32HI_V32HI_V64QI_DI:
37027     case V32QI_FTYPE_V16HI_V16HI_V32QI_SI:
37028     case V16QI_FTYPE_V8HI_V8HI_V16QI_HI:
37029     case V32HI_FTYPE_V16SI_V16SI_V32HI_SI:
37030     case V16HI_FTYPE_V8SI_V8SI_V16HI_HI:
37031     case V8HI_FTYPE_V4SI_V4SI_V8HI_QI:
37032     case V4DF_FTYPE_V4DF_V4DI_V4DF_QI:
37033     case V8SF_FTYPE_V8SF_V8SI_V8SF_QI:
37034     case V4SF_FTYPE_V4SF_V4SI_V4SF_QI:
37035     case V2DF_FTYPE_V2DF_V2DI_V2DF_QI:
37036     case V2DI_FTYPE_V4SI_V4SI_V2DI_QI:
37037     case V4DI_FTYPE_V8SI_V8SI_V4DI_QI:
37038     case V4DF_FTYPE_V4DI_V4DF_V4DF_QI:
37039     case V8SF_FTYPE_V8SI_V8SF_V8SF_QI:
37040     case V2DF_FTYPE_V2DI_V2DF_V2DF_QI:
37041     case V4SF_FTYPE_V4SI_V4SF_V4SF_QI:
37042     case V16SF_FTYPE_V16SF_V16SF_V16SF_HI:
37043     case V16SF_FTYPE_V16SF_V16SI_V16SF_HI:
37044     case V16SF_FTYPE_V16SI_V16SF_V16SF_HI:
37045     case V16SI_FTYPE_V16SI_V16SI_V16SI_HI:
37046     case V16SI_FTYPE_V16SI_V4SI_V16SI_HI:
37047     case V8HI_FTYPE_V8HI_V8HI_V8HI_QI:
37048     case V8SI_FTYPE_V8SI_V8SI_V8SI_QI:
37049     case V4SI_FTYPE_V4SI_V4SI_V4SI_QI:
37050     case V8SF_FTYPE_V8SF_V8SF_V8SF_QI:
37051     case V16QI_FTYPE_V16QI_V16QI_V16QI_HI:
37052     case V16HI_FTYPE_V16HI_V16HI_V16HI_HI:
37053     case V2DI_FTYPE_V2DI_V2DI_V2DI_QI:
37054     case V2DF_FTYPE_V2DF_V2DF_V2DF_QI:
37055     case V2DF_FTYPE_V2DF_V4SF_V2DF_QI:
37056     case V4DI_FTYPE_V4DI_V4DI_V4DI_QI:
37057     case V4DF_FTYPE_V4DF_V4DF_V4DF_QI:
37058     case V4SF_FTYPE_V4SF_V2DF_V4SF_QI:
37059     case V4SF_FTYPE_V4SF_V4SF_V4SF_QI:
37060     case V8DF_FTYPE_V8DF_V8DF_V8DF_QI:
37061     case V8DF_FTYPE_V8DF_V8DI_V8DF_QI:
37062     case V8DF_FTYPE_V8DI_V8DF_V8DF_QI:
37063     case V8DI_FTYPE_V16SI_V16SI_V8DI_QI:
37064     case V8DI_FTYPE_V8DI_SI_V8DI_V8DI:
37065     case V8DI_FTYPE_V8DI_V2DI_V8DI_QI:
37066     case V8DI_FTYPE_V8DI_V8DI_V8DI_QI:
37067     case V8HI_FTYPE_V16QI_V16QI_V8HI_QI:
37068     case V16HI_FTYPE_V32QI_V32QI_V16HI_HI:
37069     case V8SI_FTYPE_V16HI_V16HI_V8SI_QI:
37070     case V4SI_FTYPE_V8HI_V8HI_V4SI_QI:
37071       nargs = 4;
37072       break;
37073     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT:
37074     case V4DF_FTYPE_V4DF_V4DF_V4DI_INT:
37075     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT:
37076     case V8SF_FTYPE_V8SF_V8SF_V8SI_INT:
37077     case V16SF_FTYPE_V16SF_V16SF_V16SI_INT:
37078       nargs = 4;
37079       nargs_constant = 1;
37080       break;
37081     case QI_FTYPE_V4DI_V4DI_INT_QI:
37082     case QI_FTYPE_V8SI_V8SI_INT_QI:
37083     case QI_FTYPE_V4DF_V4DF_INT_QI:
37084     case QI_FTYPE_V8SF_V8SF_INT_QI:
37085     case QI_FTYPE_V2DI_V2DI_INT_QI:
37086     case QI_FTYPE_V4SI_V4SI_INT_QI:
37087     case QI_FTYPE_V2DF_V2DF_INT_QI:
37088     case QI_FTYPE_V4SF_V4SF_INT_QI:
37089     case DI_FTYPE_V64QI_V64QI_INT_DI:
37090     case SI_FTYPE_V32QI_V32QI_INT_SI:
37091     case HI_FTYPE_V16QI_V16QI_INT_HI:
37092     case SI_FTYPE_V32HI_V32HI_INT_SI:
37093     case HI_FTYPE_V16HI_V16HI_INT_HI:
37094     case QI_FTYPE_V8HI_V8HI_INT_QI:
37095       nargs = 4;
37096       mask_pos = 1;
37097       nargs_constant = 1;
37098       break;
37099     case V2DI_FTYPE_V2DI_V2DI_UINT_UINT:
37100       nargs = 4;
37101       nargs_constant = 2;
37102       break;
37103     case UCHAR_FTYPE_UCHAR_UINT_UINT_PUNSIGNED:
37104     case UCHAR_FTYPE_UCHAR_ULONGLONG_ULONGLONG_PULONGLONG:
37105       nargs = 4;
37106       break;
37107     case QI_FTYPE_V8DI_V8DI_INT_QI:
37108     case HI_FTYPE_V16SI_V16SI_INT_HI:
37109     case QI_FTYPE_V8DF_V8DF_INT_QI:
37110     case HI_FTYPE_V16SF_V16SF_INT_HI:
37111       mask_pos = 1;
37112       nargs = 4;
37113       nargs_constant = 1;
37114       break;
37115     case V8SF_FTYPE_V8SF_INT_V8SF_QI:
37116     case V4SF_FTYPE_V4SF_INT_V4SF_QI:
37117     case V2DF_FTYPE_V4DF_INT_V2DF_QI:
37118     case V2DI_FTYPE_V4DI_INT_V2DI_QI:
37119     case V8SF_FTYPE_V16SF_INT_V8SF_QI:
37120     case V8SI_FTYPE_V16SI_INT_V8SI_QI:
37121     case V2DF_FTYPE_V8DF_INT_V2DF_QI:
37122     case V2DI_FTYPE_V8DI_INT_V2DI_QI:
37123     case V4SF_FTYPE_V8SF_INT_V4SF_QI:
37124     case V4SI_FTYPE_V8SI_INT_V4SI_QI:
37125     case V8HI_FTYPE_V8SF_INT_V8HI_QI:
37126     case V8HI_FTYPE_V4SF_INT_V8HI_QI:
37127     case V32HI_FTYPE_V32HI_INT_V32HI_SI:
37128     case V16HI_FTYPE_V16HI_INT_V16HI_HI:
37129     case V8HI_FTYPE_V8HI_INT_V8HI_QI:
37130     case V4DI_FTYPE_V4DI_INT_V4DI_QI:
37131     case V2DI_FTYPE_V2DI_INT_V2DI_QI:
37132     case V8SI_FTYPE_V8SI_INT_V8SI_QI:
37133     case V4SI_FTYPE_V4SI_INT_V4SI_QI:
37134     case V4DF_FTYPE_V4DF_INT_V4DF_QI:
37135     case V2DF_FTYPE_V2DF_INT_V2DF_QI:
37136     case V8DF_FTYPE_V8DF_INT_V8DF_QI:
37137     case V16SF_FTYPE_V16SF_INT_V16SF_HI:
37138     case V16HI_FTYPE_V16SF_INT_V16HI_HI:
37139     case V16SI_FTYPE_V16SI_INT_V16SI_HI:
37140     case V4SI_FTYPE_V16SI_INT_V4SI_QI:
37141     case V4DI_FTYPE_V8DI_INT_V4DI_QI:
37142     case V4DF_FTYPE_V8DF_INT_V4DF_QI:
37143     case V4SF_FTYPE_V16SF_INT_V4SF_QI:
37144     case V8DI_FTYPE_V8DI_INT_V8DI_QI:
37145       nargs = 4;
37146       mask_pos = 2;
37147       nargs_constant = 1;
37148       break;
37149     case V16SF_FTYPE_V16SF_V4SF_INT_V16SF_HI:
37150     case V16SI_FTYPE_V16SI_V4SI_INT_V16SI_HI:
37151     case V8DF_FTYPE_V8DF_V8DF_INT_V8DF_QI:
37152     case V8DI_FTYPE_V8DI_V8DI_INT_V8DI_QI:
37153     case V16SF_FTYPE_V16SF_V16SF_INT_V16SF_HI:
37154     case V16SI_FTYPE_V16SI_V16SI_INT_V16SI_HI:
37155     case V4SF_FTYPE_V4SF_V4SF_INT_V4SF_QI:
37156     case V2DF_FTYPE_V2DF_V2DF_INT_V2DF_QI:
37157     case V8DF_FTYPE_V8DF_V4DF_INT_V8DF_QI:
37158     case V8DI_FTYPE_V8DI_V4DI_INT_V8DI_QI:
37159     case V4DF_FTYPE_V4DF_V4DF_INT_V4DF_QI:
37160     case V8SF_FTYPE_V8SF_V8SF_INT_V8SF_QI:
37161     case V8DF_FTYPE_V8DF_V2DF_INT_V8DF_QI:
37162     case V8DI_FTYPE_V8DI_V2DI_INT_V8DI_QI:
37163     case V8SI_FTYPE_V8SI_V8SI_INT_V8SI_QI:
37164     case V4DI_FTYPE_V4DI_V4DI_INT_V4DI_QI:
37165     case V4SI_FTYPE_V4SI_V4SI_INT_V4SI_QI:
37166     case V2DI_FTYPE_V2DI_V2DI_INT_V2DI_QI:
37167     case V32HI_FTYPE_V64QI_V64QI_INT_V32HI_SI:
37168     case V16HI_FTYPE_V32QI_V32QI_INT_V16HI_HI:
37169     case V8HI_FTYPE_V16QI_V16QI_INT_V8HI_QI:
37170     case V16SF_FTYPE_V16SF_V8SF_INT_V16SF_HI:
37171     case V16SI_FTYPE_V16SI_V8SI_INT_V16SI_HI:
37172     case V8SF_FTYPE_V8SF_V4SF_INT_V8SF_QI:
37173     case V8SI_FTYPE_V8SI_V4SI_INT_V8SI_QI:
37174     case V4DI_FTYPE_V4DI_V2DI_INT_V4DI_QI:
37175     case V4DF_FTYPE_V4DF_V2DF_INT_V4DF_QI:
37176       nargs = 5;
37177       mask_pos = 2;
37178       nargs_constant = 1;
37179       break;
37180     case V8DI_FTYPE_V8DI_V8DI_V8DI_INT_QI:
37181     case V16SF_FTYPE_V16SF_V16SF_V16SI_INT_HI:
37182     case V16SI_FTYPE_V16SI_V16SI_V16SI_INT_HI:
37183     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI:
37184     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI:
37185     case V8SF_FTYPE_V8SF_V8SF_V8SI_INT_QI:
37186     case V8SI_FTYPE_V8SI_V8SI_V8SI_INT_QI:
37187     case V4DF_FTYPE_V4DF_V4DF_V4DI_INT_QI:
37188     case V4DI_FTYPE_V4DI_V4DI_V4DI_INT_QI:
37189     case V4SI_FTYPE_V4SI_V4SI_V4SI_INT_QI:
37190     case V2DI_FTYPE_V2DI_V2DI_V2DI_INT_QI:
37191        nargs = 5;
37192       nargs = 5;
37193       mask_pos = 1;
37194       nargs_constant = 1;
37195       break;
37196
37197     default:
37198       gcc_unreachable ();
37199     }
37200
37201   gcc_assert (nargs <= ARRAY_SIZE (args));
37202
37203   if (comparison != UNKNOWN)
37204     {
37205       gcc_assert (nargs == 2);
37206       return ix86_expand_sse_compare (d, exp, target, swap);
37207     }
37208
37209   if (rmode == VOIDmode || rmode == tmode)
37210     {
37211       if (optimize
37212           || target == 0
37213           || GET_MODE (target) != tmode
37214           || !insn_p->operand[0].predicate (target, tmode))
37215         target = gen_reg_rtx (tmode);
37216       real_target = target;
37217     }
37218   else
37219     {
37220       real_target = gen_reg_rtx (tmode);
37221       target = simplify_gen_subreg (rmode, real_target, tmode, 0);
37222     }
37223
37224   for (i = 0; i < nargs; i++)
37225     {
37226       tree arg = CALL_EXPR_ARG (exp, i);
37227       rtx op = expand_normal (arg);
37228       machine_mode mode = insn_p->operand[i + 1].mode;
37229       bool match = insn_p->operand[i + 1].predicate (op, mode);
37230
37231       if (last_arg_count && (i + 1) == nargs)
37232         {
37233           /* SIMD shift insns take either an 8-bit immediate or
37234              register as count.  But builtin functions take int as
37235              count.  If count doesn't match, we put it in register.  */
37236           if (!match)
37237             {
37238               op = simplify_gen_subreg (SImode, op, GET_MODE (op), 0);
37239               if (!insn_p->operand[i + 1].predicate (op, mode))
37240                 op = copy_to_reg (op);
37241             }
37242         }
37243       else if ((mask_pos && (nargs - i - mask_pos) == nargs_constant) ||
37244                (!mask_pos && (nargs - i) <= nargs_constant))
37245         {
37246           if (!match)
37247             switch (icode)
37248               {
37249               case CODE_FOR_avx_vinsertf128v4di:
37250               case CODE_FOR_avx_vextractf128v4di:
37251                 error ("the last argument must be an 1-bit immediate");
37252                 return const0_rtx;
37253
37254               case CODE_FOR_avx512f_cmpv8di3_mask:
37255               case CODE_FOR_avx512f_cmpv16si3_mask:
37256               case CODE_FOR_avx512f_ucmpv8di3_mask:
37257               case CODE_FOR_avx512f_ucmpv16si3_mask:
37258               case CODE_FOR_avx512vl_cmpv4di3_mask:
37259               case CODE_FOR_avx512vl_cmpv8si3_mask:
37260               case CODE_FOR_avx512vl_ucmpv4di3_mask:
37261               case CODE_FOR_avx512vl_ucmpv8si3_mask:
37262               case CODE_FOR_avx512vl_cmpv2di3_mask:
37263               case CODE_FOR_avx512vl_cmpv4si3_mask:
37264               case CODE_FOR_avx512vl_ucmpv2di3_mask:
37265               case CODE_FOR_avx512vl_ucmpv4si3_mask:
37266                 error ("the last argument must be a 3-bit immediate");
37267                 return const0_rtx;
37268
37269               case CODE_FOR_sse4_1_roundsd:
37270               case CODE_FOR_sse4_1_roundss:
37271
37272               case CODE_FOR_sse4_1_roundpd:
37273               case CODE_FOR_sse4_1_roundps:
37274               case CODE_FOR_avx_roundpd256:
37275               case CODE_FOR_avx_roundps256:
37276
37277               case CODE_FOR_sse4_1_roundpd_vec_pack_sfix:
37278               case CODE_FOR_sse4_1_roundps_sfix:
37279               case CODE_FOR_avx_roundpd_vec_pack_sfix256:
37280               case CODE_FOR_avx_roundps_sfix256:
37281
37282               case CODE_FOR_sse4_1_blendps:
37283               case CODE_FOR_avx_blendpd256:
37284               case CODE_FOR_avx_vpermilv4df:
37285               case CODE_FOR_avx_vpermilv4df_mask:
37286               case CODE_FOR_avx512f_getmantv8df_mask:
37287               case CODE_FOR_avx512f_getmantv16sf_mask:
37288               case CODE_FOR_avx512vl_getmantv8sf_mask:
37289               case CODE_FOR_avx512vl_getmantv4df_mask:
37290               case CODE_FOR_avx512vl_getmantv4sf_mask:
37291               case CODE_FOR_avx512vl_getmantv2df_mask:
37292               case CODE_FOR_avx512dq_rangepv8df_mask_round:
37293               case CODE_FOR_avx512dq_rangepv16sf_mask_round:
37294               case CODE_FOR_avx512dq_rangepv4df_mask:
37295               case CODE_FOR_avx512dq_rangepv8sf_mask:
37296               case CODE_FOR_avx512dq_rangepv2df_mask:
37297               case CODE_FOR_avx512dq_rangepv4sf_mask:
37298               case CODE_FOR_avx_shufpd256_mask:
37299                 error ("the last argument must be a 4-bit immediate");
37300                 return const0_rtx;
37301
37302               case CODE_FOR_sha1rnds4:
37303               case CODE_FOR_sse4_1_blendpd:
37304               case CODE_FOR_avx_vpermilv2df:
37305               case CODE_FOR_avx_vpermilv2df_mask:
37306               case CODE_FOR_xop_vpermil2v2df3:
37307               case CODE_FOR_xop_vpermil2v4sf3:
37308               case CODE_FOR_xop_vpermil2v4df3:
37309               case CODE_FOR_xop_vpermil2v8sf3:
37310               case CODE_FOR_avx512f_vinsertf32x4_mask:
37311               case CODE_FOR_avx512f_vinserti32x4_mask:
37312               case CODE_FOR_avx512f_vextractf32x4_mask:
37313               case CODE_FOR_avx512f_vextracti32x4_mask:
37314               case CODE_FOR_sse2_shufpd:
37315               case CODE_FOR_sse2_shufpd_mask:
37316               case CODE_FOR_avx512dq_shuf_f64x2_mask:
37317               case CODE_FOR_avx512dq_shuf_i64x2_mask:
37318               case CODE_FOR_avx512vl_shuf_i32x4_mask:
37319               case CODE_FOR_avx512vl_shuf_f32x4_mask:
37320                 error ("the last argument must be a 2-bit immediate");
37321                 return const0_rtx;
37322
37323               case CODE_FOR_avx_vextractf128v4df:
37324               case CODE_FOR_avx_vextractf128v8sf:
37325               case CODE_FOR_avx_vextractf128v8si:
37326               case CODE_FOR_avx_vinsertf128v4df:
37327               case CODE_FOR_avx_vinsertf128v8sf:
37328               case CODE_FOR_avx_vinsertf128v8si:
37329               case CODE_FOR_avx512f_vinsertf64x4_mask:
37330               case CODE_FOR_avx512f_vinserti64x4_mask:
37331               case CODE_FOR_avx512f_vextractf64x4_mask:
37332               case CODE_FOR_avx512f_vextracti64x4_mask:
37333               case CODE_FOR_avx512dq_vinsertf32x8_mask:
37334               case CODE_FOR_avx512dq_vinserti32x8_mask:
37335               case CODE_FOR_avx512vl_vinsertv4df:
37336               case CODE_FOR_avx512vl_vinsertv4di:
37337               case CODE_FOR_avx512vl_vinsertv8sf:
37338               case CODE_FOR_avx512vl_vinsertv8si:
37339                 error ("the last argument must be a 1-bit immediate");
37340                 return const0_rtx;
37341
37342               case CODE_FOR_avx_vmcmpv2df3:
37343               case CODE_FOR_avx_vmcmpv4sf3:
37344               case CODE_FOR_avx_cmpv2df3:
37345               case CODE_FOR_avx_cmpv4sf3:
37346               case CODE_FOR_avx_cmpv4df3:
37347               case CODE_FOR_avx_cmpv8sf3:
37348               case CODE_FOR_avx512f_cmpv8df3_mask:
37349               case CODE_FOR_avx512f_cmpv16sf3_mask:
37350               case CODE_FOR_avx512f_vmcmpv2df3_mask:
37351               case CODE_FOR_avx512f_vmcmpv4sf3_mask:
37352                 error ("the last argument must be a 5-bit immediate");
37353                 return const0_rtx;
37354
37355               default:
37356                 switch (nargs_constant)
37357                   {
37358                   case 2:
37359                     if ((mask_pos && (nargs - i - mask_pos) == nargs_constant) ||
37360                         (!mask_pos && (nargs - i) == nargs_constant))
37361                       {
37362                         error ("the next to last argument must be an 8-bit immediate");
37363                         break;
37364                       }
37365                   case 1:
37366                     error ("the last argument must be an 8-bit immediate");
37367                     break;
37368                   default:
37369                     gcc_unreachable ();
37370                   }
37371                 return const0_rtx;
37372               }
37373         }
37374       else
37375         {
37376           if (VECTOR_MODE_P (mode))
37377             op = safe_vector_operand (op, mode);
37378
37379           /* If we aren't optimizing, only allow one memory operand to
37380              be generated.  */
37381           if (memory_operand (op, mode))
37382             num_memory++;
37383
37384           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
37385             {
37386               if (optimize || !match || num_memory > 1)
37387                 op = copy_to_mode_reg (mode, op);
37388             }
37389           else
37390             {
37391               op = copy_to_reg (op);
37392               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
37393             }
37394         }
37395
37396       args[i].op = op;
37397       args[i].mode = mode;
37398     }
37399
37400   switch (nargs)
37401     {
37402     case 1:
37403       pat = GEN_FCN (icode) (real_target, args[0].op);
37404       break;
37405     case 2:
37406       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op);
37407       break;
37408     case 3:
37409       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37410                              args[2].op);
37411       break;
37412     case 4:
37413       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37414                              args[2].op, args[3].op);
37415       break;
37416     case 5:
37417       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37418                              args[2].op, args[3].op, args[4].op);
37419     case 6:
37420       pat = GEN_FCN (icode) (real_target, args[0].op, args[1].op,
37421                              args[2].op, args[3].op, args[4].op,
37422                              args[5].op);
37423       break;
37424     default:
37425       gcc_unreachable ();
37426     }
37427
37428   if (! pat)
37429     return 0;
37430
37431   emit_insn (pat);
37432   return target;
37433 }
37434
37435 /* Transform pattern of following layout:
37436      (parallel [
37437        set (A B)
37438        (unspec [C] UNSPEC_EMBEDDED_ROUNDING)])
37439      ])
37440    into:
37441      (set (A B))
37442
37443    Or:
37444      (parallel [ A B
37445      ...
37446      (unspec [C] UNSPEC_EMBEDDED_ROUNDING)
37447      ...
37448      ])
37449    into:
37450      (parallel [ A B ... ])  */
37451
37452 static rtx
37453 ix86_erase_embedded_rounding (rtx pat)
37454 {
37455   if (GET_CODE (pat) == INSN)
37456     pat = PATTERN (pat);
37457
37458   gcc_assert (GET_CODE (pat) == PARALLEL);
37459
37460   if (XVECLEN (pat, 0) == 2)
37461     {
37462       rtx p0 = XVECEXP (pat, 0, 0);
37463       rtx p1 = XVECEXP (pat, 0, 1);
37464
37465       gcc_assert (GET_CODE (p0) == SET
37466                   && GET_CODE (p1) == UNSPEC
37467                   && XINT (p1, 1) == UNSPEC_EMBEDDED_ROUNDING);
37468
37469       return p0;
37470     }
37471   else
37472     {
37473       rtx *res = XALLOCAVEC (rtx, XVECLEN (pat, 0));
37474       int i = 0;
37475       int j = 0;
37476
37477       for (; i < XVECLEN (pat, 0); ++i)
37478         {
37479           rtx elem = XVECEXP (pat, 0, i);
37480           if (GET_CODE (elem) != UNSPEC
37481               || XINT (elem, 1) != UNSPEC_EMBEDDED_ROUNDING)
37482             res [j++] = elem;
37483         }
37484
37485       /*  No more than 1 occurence was removed.  */
37486       gcc_assert (j >= XVECLEN (pat, 0) - 1);
37487
37488       return gen_rtx_PARALLEL (GET_MODE (pat), gen_rtvec_v (j, res));
37489     }
37490 }
37491
37492 /* Subroutine of ix86_expand_round_builtin to take care of comi insns
37493    with rounding.  */
37494 static rtx
37495 ix86_expand_sse_comi_round (const struct builtin_description *d,
37496                             tree exp, rtx target)
37497 {
37498   rtx pat, set_dst;
37499   tree arg0 = CALL_EXPR_ARG (exp, 0);
37500   tree arg1 = CALL_EXPR_ARG (exp, 1);
37501   tree arg2 = CALL_EXPR_ARG (exp, 2);
37502   tree arg3 = CALL_EXPR_ARG (exp, 3);
37503   rtx op0 = expand_normal (arg0);
37504   rtx op1 = expand_normal (arg1);
37505   rtx op2 = expand_normal (arg2);
37506   rtx op3 = expand_normal (arg3);
37507   enum insn_code icode = d->icode;
37508   const struct insn_data_d *insn_p = &insn_data[icode];
37509   machine_mode mode0 = insn_p->operand[0].mode;
37510   machine_mode mode1 = insn_p->operand[1].mode;
37511   enum rtx_code comparison = UNEQ;
37512   bool need_ucomi = false;
37513
37514   /* See avxintrin.h for values.  */
37515   enum rtx_code comi_comparisons[32] =
37516     {
37517       UNEQ, GT, GE, UNORDERED, LTGT, UNLE, UNLT, ORDERED, UNEQ, UNLT,
37518       UNLE, LT, LTGT, GE, GT, LT, UNEQ, GT, GE, UNORDERED, LTGT, UNLE,
37519       UNLT, ORDERED, UNEQ, UNLT, UNLE, LT, LTGT, GE, GT, LT
37520     };
37521   bool need_ucomi_values[32] =
37522     {
37523       true,  false, false, true,  true,  false, false, true,
37524       true,  false, false, true,  true,  false, false, true,
37525       false, true,  true,  false, false, true,  true,  false,
37526       false, true,  true,  false, false, true,  true,  false
37527     };
37528
37529   if (!CONST_INT_P (op2))
37530     {
37531       error ("the third argument must be comparison constant");
37532       return const0_rtx;
37533     }
37534   if (INTVAL (op2) < 0 || INTVAL (op2) >= 32)
37535     {
37536       error ("incorect comparison mode");
37537       return const0_rtx;
37538     }
37539
37540   if (!insn_p->operand[2].predicate (op3, SImode))
37541     {
37542       error ("incorrect rounding operand");
37543       return const0_rtx;
37544     }
37545
37546   comparison = comi_comparisons[INTVAL (op2)];
37547   need_ucomi = need_ucomi_values[INTVAL (op2)];
37548
37549   if (VECTOR_MODE_P (mode0))
37550     op0 = safe_vector_operand (op0, mode0);
37551   if (VECTOR_MODE_P (mode1))
37552     op1 = safe_vector_operand (op1, mode1);
37553
37554   target = gen_reg_rtx (SImode);
37555   emit_move_insn (target, const0_rtx);
37556   target = gen_rtx_SUBREG (QImode, target, 0);
37557
37558   if ((optimize && !register_operand (op0, mode0))
37559       || !insn_p->operand[0].predicate (op0, mode0))
37560     op0 = copy_to_mode_reg (mode0, op0);
37561   if ((optimize && !register_operand (op1, mode1))
37562       || !insn_p->operand[1].predicate (op1, mode1))
37563     op1 = copy_to_mode_reg (mode1, op1);
37564
37565   if (need_ucomi)
37566     icode = icode == CODE_FOR_sse_comi_round
37567                      ? CODE_FOR_sse_ucomi_round
37568                      : CODE_FOR_sse2_ucomi_round;
37569
37570   pat = GEN_FCN (icode) (op0, op1, op3);
37571   if (! pat)
37572     return 0;
37573
37574   /* Rounding operand can be either NO_ROUND or ROUND_SAE at this point.  */
37575   if (INTVAL (op3) == NO_ROUND)
37576     {
37577       pat = ix86_erase_embedded_rounding (pat);
37578       if (! pat)
37579         return 0;
37580
37581       set_dst = SET_DEST (pat);
37582     }
37583   else
37584     {
37585       gcc_assert (GET_CODE (XVECEXP (pat, 0, 0)) == SET);
37586       set_dst = SET_DEST (XVECEXP (pat, 0, 0));
37587     }
37588
37589   emit_insn (pat);
37590   emit_insn (gen_rtx_SET (VOIDmode,
37591                           gen_rtx_STRICT_LOW_PART (VOIDmode, target),
37592                           gen_rtx_fmt_ee (comparison, QImode,
37593                                           set_dst,
37594                                           const0_rtx)));
37595
37596   return SUBREG_REG (target);
37597 }
37598
37599 static rtx
37600 ix86_expand_round_builtin (const struct builtin_description *d,
37601                            tree exp, rtx target)
37602 {
37603   rtx pat;
37604   unsigned int i, nargs;
37605   struct
37606     {
37607       rtx op;
37608       machine_mode mode;
37609     } args[6];
37610   enum insn_code icode = d->icode;
37611   const struct insn_data_d *insn_p = &insn_data[icode];
37612   machine_mode tmode = insn_p->operand[0].mode;
37613   unsigned int nargs_constant = 0;
37614   unsigned int redundant_embed_rnd = 0;
37615
37616   switch ((enum ix86_builtin_func_type) d->flag)
37617     {
37618     case UINT64_FTYPE_V2DF_INT:
37619     case UINT64_FTYPE_V4SF_INT:
37620     case UINT_FTYPE_V2DF_INT:
37621     case UINT_FTYPE_V4SF_INT:
37622     case INT64_FTYPE_V2DF_INT:
37623     case INT64_FTYPE_V4SF_INT:
37624     case INT_FTYPE_V2DF_INT:
37625     case INT_FTYPE_V4SF_INT:
37626       nargs = 2;
37627       break;
37628     case V4SF_FTYPE_V4SF_UINT_INT:
37629     case V4SF_FTYPE_V4SF_UINT64_INT:
37630     case V2DF_FTYPE_V2DF_UINT64_INT:
37631     case V4SF_FTYPE_V4SF_INT_INT:
37632     case V4SF_FTYPE_V4SF_INT64_INT:
37633     case V2DF_FTYPE_V2DF_INT64_INT:
37634     case V4SF_FTYPE_V4SF_V4SF_INT:
37635     case V2DF_FTYPE_V2DF_V2DF_INT:
37636     case V4SF_FTYPE_V4SF_V2DF_INT:
37637     case V2DF_FTYPE_V2DF_V4SF_INT:
37638       nargs = 3;
37639       break;
37640     case V8SF_FTYPE_V8DF_V8SF_QI_INT:
37641     case V8DF_FTYPE_V8DF_V8DF_QI_INT:
37642     case V8SI_FTYPE_V8DF_V8SI_QI_INT:
37643     case V8DI_FTYPE_V8DF_V8DI_QI_INT:
37644     case V8SF_FTYPE_V8DI_V8SF_QI_INT:
37645     case V8DF_FTYPE_V8DI_V8DF_QI_INT:
37646     case V16SF_FTYPE_V16SF_V16SF_HI_INT:
37647     case V8DI_FTYPE_V8SF_V8DI_QI_INT:
37648     case V16SF_FTYPE_V16SI_V16SF_HI_INT:
37649     case V16SI_FTYPE_V16SF_V16SI_HI_INT:
37650     case V8DF_FTYPE_V8SF_V8DF_QI_INT:
37651     case V16SF_FTYPE_V16HI_V16SF_HI_INT:
37652     case V2DF_FTYPE_V2DF_V2DF_V2DF_INT:
37653     case V4SF_FTYPE_V4SF_V4SF_V4SF_INT:
37654       nargs = 4;
37655       break;
37656     case V4SF_FTYPE_V4SF_V4SF_INT_INT:
37657     case V2DF_FTYPE_V2DF_V2DF_INT_INT:
37658       nargs_constant = 2;
37659       nargs = 4;
37660       break;
37661     case INT_FTYPE_V4SF_V4SF_INT_INT:
37662     case INT_FTYPE_V2DF_V2DF_INT_INT:
37663       return ix86_expand_sse_comi_round (d, exp, target);
37664     case V8DF_FTYPE_V8DF_V8DF_V8DF_QI_INT:
37665     case V16SF_FTYPE_V16SF_V16SF_V16SF_HI_INT:
37666     case V2DF_FTYPE_V2DF_V2DF_V2DF_QI_INT:
37667     case V2DF_FTYPE_V2DF_V4SF_V2DF_QI_INT:
37668     case V4SF_FTYPE_V4SF_V4SF_V4SF_QI_INT:
37669     case V4SF_FTYPE_V4SF_V2DF_V4SF_QI_INT:
37670       nargs = 5;
37671       break;
37672     case V16SF_FTYPE_V16SF_INT_V16SF_HI_INT:
37673     case V8DF_FTYPE_V8DF_INT_V8DF_QI_INT:
37674       nargs_constant = 4;
37675       nargs = 5;
37676       break;
37677     case QI_FTYPE_V8DF_V8DF_INT_QI_INT:
37678     case QI_FTYPE_V2DF_V2DF_INT_QI_INT:
37679     case HI_FTYPE_V16SF_V16SF_INT_HI_INT:
37680     case QI_FTYPE_V4SF_V4SF_INT_QI_INT:
37681       nargs_constant = 3;
37682       nargs = 5;
37683       break;
37684     case V16SF_FTYPE_V16SF_V16SF_INT_V16SF_HI_INT:
37685     case V8DF_FTYPE_V8DF_V8DF_INT_V8DF_QI_INT:
37686     case V4SF_FTYPE_V4SF_V4SF_INT_V4SF_QI_INT:
37687     case V2DF_FTYPE_V2DF_V2DF_INT_V2DF_QI_INT:
37688       nargs = 6;
37689       nargs_constant = 4;
37690       break;
37691     case V8DF_FTYPE_V8DF_V8DF_V8DI_INT_QI_INT:
37692     case V16SF_FTYPE_V16SF_V16SF_V16SI_INT_HI_INT:
37693     case V2DF_FTYPE_V2DF_V2DF_V2DI_INT_QI_INT:
37694     case V4SF_FTYPE_V4SF_V4SF_V4SI_INT_QI_INT:
37695       nargs = 6;
37696       nargs_constant = 3;
37697       break;
37698     default:
37699       gcc_unreachable ();
37700     }
37701   gcc_assert (nargs <= ARRAY_SIZE (args));
37702
37703   if (optimize
37704       || target == 0
37705       || GET_MODE (target) != tmode
37706       || !insn_p->operand[0].predicate (target, tmode))
37707     target = gen_reg_rtx (tmode);
37708
37709   for (i = 0; i < nargs; i++)
37710     {
37711       tree arg = CALL_EXPR_ARG (exp, i);
37712       rtx op = expand_normal (arg);
37713       machine_mode mode = insn_p->operand[i + 1].mode;
37714       bool match = insn_p->operand[i + 1].predicate (op, mode);
37715
37716       if (i == nargs - nargs_constant)
37717         {
37718           if (!match)
37719             {
37720               switch (icode)
37721                 {
37722                 case CODE_FOR_avx512f_getmantv8df_mask_round:
37723                 case CODE_FOR_avx512f_getmantv16sf_mask_round:
37724                 case CODE_FOR_avx512f_vgetmantv2df_round:
37725                 case CODE_FOR_avx512f_vgetmantv4sf_round:
37726                   error ("the immediate argument must be a 4-bit immediate");
37727                   return const0_rtx;
37728                 case CODE_FOR_avx512f_cmpv8df3_mask_round:
37729                 case CODE_FOR_avx512f_cmpv16sf3_mask_round:
37730                 case CODE_FOR_avx512f_vmcmpv2df3_mask_round:
37731                 case CODE_FOR_avx512f_vmcmpv4sf3_mask_round:
37732                   error ("the immediate argument must be a 5-bit immediate");
37733                   return const0_rtx;
37734                 default:
37735                   error ("the immediate argument must be an 8-bit immediate");
37736                   return const0_rtx;
37737                 }
37738             }
37739         }
37740       else if (i == nargs-1)
37741         {
37742           if (!insn_p->operand[nargs].predicate (op, SImode))
37743             {
37744               error ("incorrect rounding operand");
37745               return const0_rtx;
37746             }
37747
37748           /* If there is no rounding use normal version of the pattern.  */
37749           if (INTVAL (op) == NO_ROUND)
37750             redundant_embed_rnd = 1;
37751         }
37752       else
37753         {
37754           if (VECTOR_MODE_P (mode))
37755             op = safe_vector_operand (op, mode);
37756
37757           if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
37758             {
37759               if (optimize || !match)
37760                 op = copy_to_mode_reg (mode, op);
37761             }
37762           else
37763             {
37764               op = copy_to_reg (op);
37765               op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
37766             }
37767         }
37768
37769       args[i].op = op;
37770       args[i].mode = mode;
37771     }
37772
37773   switch (nargs)
37774     {
37775     case 1:
37776       pat = GEN_FCN (icode) (target, args[0].op);
37777       break;
37778     case 2:
37779       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
37780       break;
37781     case 3:
37782       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37783                              args[2].op);
37784       break;
37785     case 4:
37786       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37787                              args[2].op, args[3].op);
37788       break;
37789     case 5:
37790       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37791                              args[2].op, args[3].op, args[4].op);
37792     case 6:
37793       pat = GEN_FCN (icode) (target, args[0].op, args[1].op,
37794                              args[2].op, args[3].op, args[4].op,
37795                              args[5].op);
37796       break;
37797     default:
37798       gcc_unreachable ();
37799     }
37800
37801   if (!pat)
37802     return 0;
37803
37804   if (redundant_embed_rnd)
37805     pat = ix86_erase_embedded_rounding (pat);
37806
37807   emit_insn (pat);
37808   return target;
37809 }
37810
37811 /* Subroutine of ix86_expand_builtin to take care of special insns
37812    with variable number of operands.  */
37813
37814 static rtx
37815 ix86_expand_special_args_builtin (const struct builtin_description *d,
37816                                   tree exp, rtx target)
37817 {
37818   tree arg;
37819   rtx pat, op;
37820   unsigned int i, nargs, arg_adjust, memory;
37821   bool aligned_mem = false;
37822   struct
37823     {
37824       rtx op;
37825       machine_mode mode;
37826     } args[3];
37827   enum insn_code icode = d->icode;
37828   bool last_arg_constant = false;
37829   const struct insn_data_d *insn_p = &insn_data[icode];
37830   machine_mode tmode = insn_p->operand[0].mode;
37831   enum { load, store } klass;
37832
37833   switch ((enum ix86_builtin_func_type) d->flag)
37834     {
37835     case VOID_FTYPE_VOID:
37836       emit_insn (GEN_FCN (icode) (target));
37837       return 0;
37838     case VOID_FTYPE_UINT64:
37839     case VOID_FTYPE_UNSIGNED:
37840       nargs = 0;
37841       klass = store;
37842       memory = 0;
37843       break;
37844
37845     case INT_FTYPE_VOID:
37846     case USHORT_FTYPE_VOID:
37847     case UINT64_FTYPE_VOID:
37848     case UNSIGNED_FTYPE_VOID:
37849       nargs = 0;
37850       klass = load;
37851       memory = 0;
37852       break;
37853     case UINT64_FTYPE_PUNSIGNED:
37854     case V2DI_FTYPE_PV2DI:
37855     case V4DI_FTYPE_PV4DI:
37856     case V32QI_FTYPE_PCCHAR:
37857     case V16QI_FTYPE_PCCHAR:
37858     case V8SF_FTYPE_PCV4SF:
37859     case V8SF_FTYPE_PCFLOAT:
37860     case V4SF_FTYPE_PCFLOAT:
37861     case V4DF_FTYPE_PCV2DF:
37862     case V4DF_FTYPE_PCDOUBLE:
37863     case V2DF_FTYPE_PCDOUBLE:
37864     case VOID_FTYPE_PVOID:
37865     case V16SI_FTYPE_PV4SI:
37866     case V16SF_FTYPE_PV4SF:
37867     case V8DI_FTYPE_PV4DI:
37868     case V8DI_FTYPE_PV8DI:
37869     case V8DF_FTYPE_PV4DF:
37870       nargs = 1;
37871       klass = load;
37872       memory = 0;
37873       switch (icode)
37874         {
37875         case CODE_FOR_sse4_1_movntdqa:
37876         case CODE_FOR_avx2_movntdqa:
37877         case CODE_FOR_avx512f_movntdqa:
37878           aligned_mem = true;
37879           break;
37880         default:
37881           break;
37882         }
37883       break;
37884     case VOID_FTYPE_PV2SF_V4SF:
37885     case VOID_FTYPE_PV8DI_V8DI:
37886     case VOID_FTYPE_PV4DI_V4DI:
37887     case VOID_FTYPE_PV2DI_V2DI:
37888     case VOID_FTYPE_PCHAR_V32QI:
37889     case VOID_FTYPE_PCHAR_V16QI:
37890     case VOID_FTYPE_PFLOAT_V16SF:
37891     case VOID_FTYPE_PFLOAT_V8SF:
37892     case VOID_FTYPE_PFLOAT_V4SF:
37893     case VOID_FTYPE_PDOUBLE_V8DF:
37894     case VOID_FTYPE_PDOUBLE_V4DF:
37895     case VOID_FTYPE_PDOUBLE_V2DF:
37896     case VOID_FTYPE_PLONGLONG_LONGLONG:
37897     case VOID_FTYPE_PULONGLONG_ULONGLONG:
37898     case VOID_FTYPE_PINT_INT:
37899       nargs = 1;
37900       klass = store;
37901       /* Reserve memory operand for target.  */
37902       memory = ARRAY_SIZE (args);
37903       switch (icode)
37904         {
37905         /* These builtins and instructions require the memory
37906            to be properly aligned.  */
37907         case CODE_FOR_avx_movntv4di:
37908         case CODE_FOR_sse2_movntv2di:
37909         case CODE_FOR_avx_movntv8sf:
37910         case CODE_FOR_sse_movntv4sf:
37911         case CODE_FOR_sse4a_vmmovntv4sf:
37912         case CODE_FOR_avx_movntv4df:
37913         case CODE_FOR_sse2_movntv2df:
37914         case CODE_FOR_sse4a_vmmovntv2df:
37915         case CODE_FOR_sse2_movntidi:
37916         case CODE_FOR_sse_movntq:
37917         case CODE_FOR_sse2_movntisi:
37918         case CODE_FOR_avx512f_movntv16sf:
37919         case CODE_FOR_avx512f_movntv8df:
37920         case CODE_FOR_avx512f_movntv8di:
37921           aligned_mem = true;
37922           break;
37923         default:
37924           break;
37925         }
37926       break;
37927     case V4SF_FTYPE_V4SF_PCV2SF:
37928     case V2DF_FTYPE_V2DF_PCDOUBLE:
37929       nargs = 2;
37930       klass = load;
37931       memory = 1;
37932       break;
37933     case V8SF_FTYPE_PCV8SF_V8SI:
37934     case V4DF_FTYPE_PCV4DF_V4DI:
37935     case V4SF_FTYPE_PCV4SF_V4SI:
37936     case V2DF_FTYPE_PCV2DF_V2DI:
37937     case V8SI_FTYPE_PCV8SI_V8SI:
37938     case V4DI_FTYPE_PCV4DI_V4DI:
37939     case V4SI_FTYPE_PCV4SI_V4SI:
37940     case V2DI_FTYPE_PCV2DI_V2DI:
37941       nargs = 2;
37942       klass = load;
37943       memory = 0;
37944       break;
37945     case VOID_FTYPE_PV8DF_V8DF_QI:
37946     case VOID_FTYPE_PV16SF_V16SF_HI:
37947     case VOID_FTYPE_PV8DI_V8DI_QI:
37948     case VOID_FTYPE_PV4DI_V4DI_QI:
37949     case VOID_FTYPE_PV2DI_V2DI_QI:
37950     case VOID_FTYPE_PV16SI_V16SI_HI:
37951     case VOID_FTYPE_PV8SI_V8SI_QI:
37952     case VOID_FTYPE_PV4SI_V4SI_QI:
37953       switch (icode)
37954         {
37955         /* These builtins and instructions require the memory
37956            to be properly aligned.  */
37957         case CODE_FOR_avx512f_storev16sf_mask:
37958         case CODE_FOR_avx512f_storev16si_mask:
37959         case CODE_FOR_avx512f_storev8df_mask:
37960         case CODE_FOR_avx512f_storev8di_mask:
37961         case CODE_FOR_avx512vl_storev8sf_mask:
37962         case CODE_FOR_avx512vl_storev8si_mask:
37963         case CODE_FOR_avx512vl_storev4df_mask:
37964         case CODE_FOR_avx512vl_storev4di_mask:
37965         case CODE_FOR_avx512vl_storev4sf_mask:
37966         case CODE_FOR_avx512vl_storev4si_mask:
37967         case CODE_FOR_avx512vl_storev2df_mask:
37968         case CODE_FOR_avx512vl_storev2di_mask:
37969           aligned_mem = true;
37970           break;
37971         default:
37972           break;
37973         }
37974       /* FALLTHRU */
37975     case VOID_FTYPE_PV8SF_V8SI_V8SF:
37976     case VOID_FTYPE_PV4DF_V4DI_V4DF:
37977     case VOID_FTYPE_PV4SF_V4SI_V4SF:
37978     case VOID_FTYPE_PV2DF_V2DI_V2DF:
37979     case VOID_FTYPE_PV8SI_V8SI_V8SI:
37980     case VOID_FTYPE_PV4DI_V4DI_V4DI:
37981     case VOID_FTYPE_PV4SI_V4SI_V4SI:
37982     case VOID_FTYPE_PV2DI_V2DI_V2DI:
37983     case VOID_FTYPE_PDOUBLE_V2DF_QI:
37984     case VOID_FTYPE_PFLOAT_V4SF_QI:
37985     case VOID_FTYPE_PV8SI_V8DI_QI:
37986     case VOID_FTYPE_PV8HI_V8DI_QI:
37987     case VOID_FTYPE_PV16HI_V16SI_HI:
37988     case VOID_FTYPE_PV16QI_V8DI_QI:
37989     case VOID_FTYPE_PV16QI_V16SI_HI:
37990     case VOID_FTYPE_PV4SI_V4DI_QI:
37991     case VOID_FTYPE_PV4SI_V2DI_QI:
37992     case VOID_FTYPE_PV8HI_V4DI_QI:
37993     case VOID_FTYPE_PV8HI_V2DI_QI:
37994     case VOID_FTYPE_PV8HI_V8SI_QI:
37995     case VOID_FTYPE_PV8HI_V4SI_QI:
37996     case VOID_FTYPE_PV16QI_V4DI_QI:
37997     case VOID_FTYPE_PV16QI_V2DI_QI:
37998     case VOID_FTYPE_PV16QI_V8SI_QI:
37999     case VOID_FTYPE_PV16QI_V4SI_QI:
38000     case VOID_FTYPE_PV8HI_V8HI_QI:
38001     case VOID_FTYPE_PV16HI_V16HI_HI:
38002     case VOID_FTYPE_PV32HI_V32HI_SI:
38003     case VOID_FTYPE_PV16QI_V16QI_HI:
38004     case VOID_FTYPE_PV32QI_V32QI_SI:
38005     case VOID_FTYPE_PV64QI_V64QI_DI:
38006     case VOID_FTYPE_PV4DF_V4DF_QI:
38007     case VOID_FTYPE_PV2DF_V2DF_QI:
38008     case VOID_FTYPE_PV8SF_V8SF_QI:
38009     case VOID_FTYPE_PV4SF_V4SF_QI:
38010       nargs = 2;
38011       klass = store;
38012       /* Reserve memory operand for target.  */
38013       memory = ARRAY_SIZE (args);
38014       break;
38015     case V4SF_FTYPE_PCV4SF_V4SF_QI:
38016     case V8SF_FTYPE_PCV8SF_V8SF_QI:
38017     case V16SF_FTYPE_PCV16SF_V16SF_HI:
38018     case V4SI_FTYPE_PCV4SI_V4SI_QI:
38019     case V8SI_FTYPE_PCV8SI_V8SI_QI:
38020     case V16SI_FTYPE_PCV16SI_V16SI_HI:
38021     case V2DF_FTYPE_PCV2DF_V2DF_QI:
38022     case V4DF_FTYPE_PCV4DF_V4DF_QI:
38023     case V8DF_FTYPE_PCV8DF_V8DF_QI:
38024     case V2DI_FTYPE_PCV2DI_V2DI_QI:
38025     case V4DI_FTYPE_PCV4DI_V4DI_QI:
38026     case V8DI_FTYPE_PCV8DI_V8DI_QI:
38027     case V2DF_FTYPE_PCDOUBLE_V2DF_QI:
38028     case V4SF_FTYPE_PCFLOAT_V4SF_QI:
38029     case V8HI_FTYPE_PCV8HI_V8HI_QI:
38030     case V16HI_FTYPE_PCV16HI_V16HI_HI:
38031     case V32HI_FTYPE_PCV32HI_V32HI_SI:
38032     case V16QI_FTYPE_PCV16QI_V16QI_HI:
38033     case V32QI_FTYPE_PCV32QI_V32QI_SI:
38034     case V64QI_FTYPE_PCV64QI_V64QI_DI:
38035       nargs = 3;
38036       klass = load;
38037       memory = 0;
38038       switch (icode)
38039         {
38040         /* These builtins and instructions require the memory
38041            to be properly aligned.  */
38042         case CODE_FOR_avx512f_loadv16sf_mask:
38043         case CODE_FOR_avx512f_loadv16si_mask:
38044         case CODE_FOR_avx512f_loadv8df_mask:
38045         case CODE_FOR_avx512f_loadv8di_mask:
38046         case CODE_FOR_avx512vl_loadv8sf_mask:
38047         case CODE_FOR_avx512vl_loadv8si_mask:
38048         case CODE_FOR_avx512vl_loadv4df_mask:
38049         case CODE_FOR_avx512vl_loadv4di_mask:
38050         case CODE_FOR_avx512vl_loadv4sf_mask:
38051         case CODE_FOR_avx512vl_loadv4si_mask:
38052         case CODE_FOR_avx512vl_loadv2df_mask:
38053         case CODE_FOR_avx512vl_loadv2di_mask:
38054         case CODE_FOR_avx512bw_loadv64qi_mask:
38055         case CODE_FOR_avx512vl_loadv32qi_mask:
38056         case CODE_FOR_avx512vl_loadv16qi_mask:
38057         case CODE_FOR_avx512bw_loadv32hi_mask:
38058         case CODE_FOR_avx512vl_loadv16hi_mask:
38059         case CODE_FOR_avx512vl_loadv8hi_mask:
38060           aligned_mem = true;
38061           break;
38062         default:
38063           break;
38064         }
38065       break;
38066     case VOID_FTYPE_UINT_UINT_UINT:
38067     case VOID_FTYPE_UINT64_UINT_UINT:
38068     case UCHAR_FTYPE_UINT_UINT_UINT:
38069     case UCHAR_FTYPE_UINT64_UINT_UINT:
38070       nargs = 3;
38071       klass = load;
38072       memory = ARRAY_SIZE (args);
38073       last_arg_constant = true;
38074       break;
38075     default:
38076       gcc_unreachable ();
38077     }
38078
38079   gcc_assert (nargs <= ARRAY_SIZE (args));
38080
38081   if (klass == store)
38082     {
38083       arg = CALL_EXPR_ARG (exp, 0);
38084       op = expand_normal (arg);
38085       gcc_assert (target == 0);
38086       if (memory)
38087         {
38088           op = ix86_zero_extend_to_Pmode (op);
38089           target = gen_rtx_MEM (tmode, op);
38090           /* target at this point has just BITS_PER_UNIT MEM_ALIGN
38091              on it.  Try to improve it using get_pointer_alignment,
38092              and if the special builtin is one that requires strict
38093              mode alignment, also from it's GET_MODE_ALIGNMENT.
38094              Failure to do so could lead to ix86_legitimate_combined_insn
38095              rejecting all changes to such insns.  */
38096           unsigned int align = get_pointer_alignment (arg);
38097           if (aligned_mem && align < GET_MODE_ALIGNMENT (tmode))
38098             align = GET_MODE_ALIGNMENT (tmode);
38099           if (MEM_ALIGN (target) < align)
38100             set_mem_align (target, align);
38101         }
38102       else
38103         target = force_reg (tmode, op);
38104       arg_adjust = 1;
38105     }
38106   else
38107     {
38108       arg_adjust = 0;
38109       if (optimize
38110           || target == 0
38111           || !register_operand (target, tmode)
38112           || GET_MODE (target) != tmode)
38113         target = gen_reg_rtx (tmode);
38114     }
38115
38116   for (i = 0; i < nargs; i++)
38117     {
38118       machine_mode mode = insn_p->operand[i + 1].mode;
38119       bool match;
38120
38121       arg = CALL_EXPR_ARG (exp, i + arg_adjust);
38122       op = expand_normal (arg);
38123       match = insn_p->operand[i + 1].predicate (op, mode);
38124
38125       if (last_arg_constant && (i + 1) == nargs)
38126         {
38127           if (!match)
38128             {
38129               if (icode == CODE_FOR_lwp_lwpvalsi3
38130                   || icode == CODE_FOR_lwp_lwpinssi3
38131                   || icode == CODE_FOR_lwp_lwpvaldi3
38132                   || icode == CODE_FOR_lwp_lwpinsdi3)
38133                 error ("the last argument must be a 32-bit immediate");
38134               else
38135                 error ("the last argument must be an 8-bit immediate");
38136               return const0_rtx;
38137             }
38138         }
38139       else
38140         {
38141           if (i == memory)
38142             {
38143               /* This must be the memory operand.  */
38144               op = ix86_zero_extend_to_Pmode (op);
38145               op = gen_rtx_MEM (mode, op);
38146               /* op at this point has just BITS_PER_UNIT MEM_ALIGN
38147                  on it.  Try to improve it using get_pointer_alignment,
38148                  and if the special builtin is one that requires strict
38149                  mode alignment, also from it's GET_MODE_ALIGNMENT.
38150                  Failure to do so could lead to ix86_legitimate_combined_insn
38151                  rejecting all changes to such insns.  */
38152               unsigned int align = get_pointer_alignment (arg);
38153               if (aligned_mem && align < GET_MODE_ALIGNMENT (mode))
38154                 align = GET_MODE_ALIGNMENT (mode);
38155               if (MEM_ALIGN (op) < align)
38156                 set_mem_align (op, align);
38157             }
38158           else
38159             {
38160               /* This must be register.  */
38161               if (VECTOR_MODE_P (mode))
38162                 op = safe_vector_operand (op, mode);
38163
38164               if (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode)
38165                 op = copy_to_mode_reg (mode, op);
38166               else
38167                 {
38168                   op = copy_to_reg (op);
38169                   op = simplify_gen_subreg (mode, op, GET_MODE (op), 0);
38170                 }
38171             }
38172         }
38173
38174       args[i].op = op;
38175       args[i].mode = mode;
38176     }
38177
38178   switch (nargs)
38179     {
38180     case 0:
38181       pat = GEN_FCN (icode) (target);
38182       break;
38183     case 1:
38184       pat = GEN_FCN (icode) (target, args[0].op);
38185       break;
38186     case 2:
38187       pat = GEN_FCN (icode) (target, args[0].op, args[1].op);
38188       break;
38189     case 3:
38190       pat = GEN_FCN (icode) (target, args[0].op, args[1].op, args[2].op);
38191       break;
38192     default:
38193       gcc_unreachable ();
38194     }
38195
38196   if (! pat)
38197     return 0;
38198   emit_insn (pat);
38199   return klass == store ? 0 : target;
38200 }
38201
38202 /* Return the integer constant in ARG.  Constrain it to be in the range
38203    of the subparts of VEC_TYPE; issue an error if not.  */
38204
38205 static int
38206 get_element_number (tree vec_type, tree arg)
38207 {
38208   unsigned HOST_WIDE_INT elt, max = TYPE_VECTOR_SUBPARTS (vec_type) - 1;
38209
38210   if (!tree_fits_uhwi_p (arg)
38211       || (elt = tree_to_uhwi (arg), elt > max))
38212     {
38213       error ("selector must be an integer constant in the range 0..%wi", max);
38214       return 0;
38215     }
38216
38217   return elt;
38218 }
38219
38220 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
38221    ix86_expand_vector_init.  We DO have language-level syntax for this, in
38222    the form of  (type){ init-list }.  Except that since we can't place emms
38223    instructions from inside the compiler, we can't allow the use of MMX
38224    registers unless the user explicitly asks for it.  So we do *not* define
38225    vec_set/vec_extract/vec_init patterns for MMX modes in mmx.md.  Instead
38226    we have builtins invoked by mmintrin.h that gives us license to emit
38227    these sorts of instructions.  */
38228
38229 static rtx
38230 ix86_expand_vec_init_builtin (tree type, tree exp, rtx target)
38231 {
38232   machine_mode tmode = TYPE_MODE (type);
38233   machine_mode inner_mode = GET_MODE_INNER (tmode);
38234   int i, n_elt = GET_MODE_NUNITS (tmode);
38235   rtvec v = rtvec_alloc (n_elt);
38236
38237   gcc_assert (VECTOR_MODE_P (tmode));
38238   gcc_assert (call_expr_nargs (exp) == n_elt);
38239
38240   for (i = 0; i < n_elt; ++i)
38241     {
38242       rtx x = expand_normal (CALL_EXPR_ARG (exp, i));
38243       RTVEC_ELT (v, i) = gen_lowpart (inner_mode, x);
38244     }
38245
38246   if (!target || !register_operand (target, tmode))
38247     target = gen_reg_rtx (tmode);
38248
38249   ix86_expand_vector_init (true, target, gen_rtx_PARALLEL (tmode, v));
38250   return target;
38251 }
38252
38253 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
38254    ix86_expand_vector_extract.  They would be redundant (for non-MMX) if we
38255    had a language-level syntax for referencing vector elements.  */
38256
38257 static rtx
38258 ix86_expand_vec_ext_builtin (tree exp, rtx target)
38259 {
38260   machine_mode tmode, mode0;
38261   tree arg0, arg1;
38262   int elt;
38263   rtx op0;
38264
38265   arg0 = CALL_EXPR_ARG (exp, 0);
38266   arg1 = CALL_EXPR_ARG (exp, 1);
38267
38268   op0 = expand_normal (arg0);
38269   elt = get_element_number (TREE_TYPE (arg0), arg1);
38270
38271   tmode = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
38272   mode0 = TYPE_MODE (TREE_TYPE (arg0));
38273   gcc_assert (VECTOR_MODE_P (mode0));
38274
38275   op0 = force_reg (mode0, op0);
38276
38277   if (optimize || !target || !register_operand (target, tmode))
38278     target = gen_reg_rtx (tmode);
38279
38280   ix86_expand_vector_extract (true, target, op0, elt);
38281
38282   return target;
38283 }
38284
38285 /* A subroutine of ix86_expand_builtin.  These builtins are a wrapper around
38286    ix86_expand_vector_set.  They would be redundant (for non-MMX) if we had
38287    a language-level syntax for referencing vector elements.  */
38288
38289 static rtx
38290 ix86_expand_vec_set_builtin (tree exp)
38291 {
38292   machine_mode tmode, mode1;
38293   tree arg0, arg1, arg2;
38294   int elt;
38295   rtx op0, op1, target;
38296
38297   arg0 = CALL_EXPR_ARG (exp, 0);
38298   arg1 = CALL_EXPR_ARG (exp, 1);
38299   arg2 = CALL_EXPR_ARG (exp, 2);
38300
38301   tmode = TYPE_MODE (TREE_TYPE (arg0));
38302   mode1 = TYPE_MODE (TREE_TYPE (TREE_TYPE (arg0)));
38303   gcc_assert (VECTOR_MODE_P (tmode));
38304
38305   op0 = expand_expr (arg0, NULL_RTX, tmode, EXPAND_NORMAL);
38306   op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
38307   elt = get_element_number (TREE_TYPE (arg0), arg2);
38308
38309   if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
38310     op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
38311
38312   op0 = force_reg (tmode, op0);
38313   op1 = force_reg (mode1, op1);
38314
38315   /* OP0 is the source of these builtin functions and shouldn't be
38316      modified.  Create a copy, use it and return it as target.  */
38317   target = gen_reg_rtx (tmode);
38318   emit_move_insn (target, op0);
38319   ix86_expand_vector_set (true, target, op1, elt);
38320
38321   return target;
38322 }
38323
38324 /* Emit conditional move of SRC to DST with condition
38325    OP1 CODE OP2.  */
38326 static void
38327 ix86_emit_cmove (rtx dst, rtx src, enum rtx_code code, rtx op1, rtx op2)
38328 {
38329   rtx t;
38330
38331   if (TARGET_CMOVE)
38332     {
38333       t = ix86_expand_compare (code, op1, op2);
38334       emit_insn (gen_rtx_SET (VOIDmode, dst,
38335                               gen_rtx_IF_THEN_ELSE (GET_MODE (dst), t,
38336                                                     src, dst)));
38337     }
38338   else
38339     {
38340       rtx nomove = gen_label_rtx ();
38341       emit_cmp_and_jump_insns (op1, op2, reverse_condition (code),
38342                                const0_rtx, GET_MODE (op1), 1, nomove);
38343       emit_move_insn (dst, src);
38344       emit_label (nomove);
38345     }
38346 }
38347
38348 /* Choose max of DST and SRC and put it to DST.  */
38349 static void
38350 ix86_emit_move_max (rtx dst, rtx src)
38351 {
38352   ix86_emit_cmove (dst, src, LTU, dst, src);
38353 }
38354
38355 /* Expand an expression EXP that calls a built-in function,
38356    with result going to TARGET if that's convenient
38357    (and in mode MODE if that's convenient).
38358    SUBTARGET may be used as the target for computing one of EXP's operands.
38359    IGNORE is nonzero if the value is to be ignored.  */
38360
38361 static rtx
38362 ix86_expand_builtin (tree exp, rtx target, rtx subtarget,
38363                      machine_mode mode, int ignore)
38364 {
38365   const struct builtin_description *d;
38366   size_t i;
38367   enum insn_code icode;
38368   tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
38369   tree arg0, arg1, arg2, arg3, arg4;
38370   rtx op0, op1, op2, op3, op4, pat, insn;
38371   machine_mode mode0, mode1, mode2, mode3, mode4;
38372   unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
38373
38374   /* For CPU builtins that can be folded, fold first and expand the fold.  */
38375   switch (fcode)
38376     {
38377     case IX86_BUILTIN_CPU_INIT:
38378       {
38379         /* Make it call __cpu_indicator_init in libgcc. */
38380         tree call_expr, fndecl, type;
38381         type = build_function_type_list (integer_type_node, NULL_TREE); 
38382         fndecl = build_fn_decl ("__cpu_indicator_init", type);
38383         call_expr = build_call_expr (fndecl, 0); 
38384         return expand_expr (call_expr, target, mode, EXPAND_NORMAL);
38385       }
38386     case IX86_BUILTIN_CPU_IS:
38387     case IX86_BUILTIN_CPU_SUPPORTS:
38388       {
38389         tree arg0 = CALL_EXPR_ARG (exp, 0);
38390         tree fold_expr = fold_builtin_cpu (fndecl, &arg0);
38391         gcc_assert (fold_expr != NULL_TREE);
38392         return expand_expr (fold_expr, target, mode, EXPAND_NORMAL);
38393       }
38394     }
38395
38396   /* Determine whether the builtin function is available under the current ISA.
38397      Originally the builtin was not created if it wasn't applicable to the
38398      current ISA based on the command line switches.  With function specific
38399      options, we need to check in the context of the function making the call
38400      whether it is supported.  */
38401   if (ix86_builtins_isa[fcode].isa
38402       && !(ix86_builtins_isa[fcode].isa & ix86_isa_flags))
38403     {
38404       char *opts = ix86_target_string (ix86_builtins_isa[fcode].isa, 0, NULL,
38405                                        NULL, (enum fpmath_unit) 0, false);
38406
38407       if (!opts)
38408         error ("%qE needs unknown isa option", fndecl);
38409       else
38410         {
38411           gcc_assert (opts != NULL);
38412           error ("%qE needs isa option %s", fndecl, opts);
38413           free (opts);
38414         }
38415       return const0_rtx;
38416     }
38417
38418   switch (fcode)
38419     {
38420     case IX86_BUILTIN_BNDMK:
38421       if (!target
38422           || GET_MODE (target) != BNDmode
38423           || !register_operand (target, BNDmode))
38424         target = gen_reg_rtx (BNDmode);
38425
38426       arg0 = CALL_EXPR_ARG (exp, 0);
38427       arg1 = CALL_EXPR_ARG (exp, 1);
38428
38429       op0 = expand_normal (arg0);
38430       op1 = expand_normal (arg1);
38431
38432       if (!register_operand (op0, Pmode))
38433         op0 = ix86_zero_extend_to_Pmode (op0);
38434       if (!register_operand (op1, Pmode))
38435         op1 = ix86_zero_extend_to_Pmode (op1);
38436
38437       /* Builtin arg1 is size of block but instruction op1 should
38438          be (size - 1).  */
38439       op1 = expand_simple_binop (Pmode, PLUS, op1, constm1_rtx,
38440                                  NULL_RTX, 1, OPTAB_DIRECT);
38441
38442       emit_insn (BNDmode == BND64mode
38443                  ? gen_bnd64_mk (target, op0, op1)
38444                  : gen_bnd32_mk (target, op0, op1));
38445       return target;
38446
38447     case IX86_BUILTIN_BNDSTX:
38448       arg0 = CALL_EXPR_ARG (exp, 0);
38449       arg1 = CALL_EXPR_ARG (exp, 1);
38450       arg2 = CALL_EXPR_ARG (exp, 2);
38451
38452       op0 = expand_normal (arg0);
38453       op1 = expand_normal (arg1);
38454       op2 = expand_normal (arg2);
38455
38456       if (!register_operand (op0, Pmode))
38457         op0 = ix86_zero_extend_to_Pmode (op0);
38458       if (!register_operand (op1, BNDmode))
38459         op1 = copy_to_mode_reg (BNDmode, op1);
38460       if (!register_operand (op2, Pmode))
38461         op2 = ix86_zero_extend_to_Pmode (op2);
38462
38463       emit_insn (BNDmode == BND64mode
38464                  ? gen_bnd64_stx (op2, op0, op1)
38465                  : gen_bnd32_stx (op2, op0, op1));
38466       return 0;
38467
38468     case IX86_BUILTIN_BNDLDX:
38469       if (!target
38470           || GET_MODE (target) != BNDmode
38471           || !register_operand (target, BNDmode))
38472         target = gen_reg_rtx (BNDmode);
38473
38474       arg0 = CALL_EXPR_ARG (exp, 0);
38475       arg1 = CALL_EXPR_ARG (exp, 1);
38476
38477       op0 = expand_normal (arg0);
38478       op1 = expand_normal (arg1);
38479
38480       if (!register_operand (op0, Pmode))
38481         op0 = ix86_zero_extend_to_Pmode (op0);
38482       if (!register_operand (op1, Pmode))
38483         op1 = ix86_zero_extend_to_Pmode (op1);
38484
38485       emit_insn (BNDmode == BND64mode
38486                  ? gen_bnd64_ldx (target, op0, op1)
38487                  : gen_bnd32_ldx (target, op0, op1));
38488       return target;
38489
38490     case IX86_BUILTIN_BNDCL:
38491       arg0 = CALL_EXPR_ARG (exp, 0);
38492       arg1 = CALL_EXPR_ARG (exp, 1);
38493
38494       op0 = expand_normal (arg0);
38495       op1 = expand_normal (arg1);
38496
38497       if (!register_operand (op0, Pmode))
38498         op0 = ix86_zero_extend_to_Pmode (op0);
38499       if (!register_operand (op1, BNDmode))
38500         op1 = copy_to_mode_reg (BNDmode, op1);
38501
38502       emit_insn (BNDmode == BND64mode
38503                  ? gen_bnd64_cl (op1, op0)
38504                  : gen_bnd32_cl (op1, op0));
38505       return 0;
38506
38507     case IX86_BUILTIN_BNDCU:
38508       arg0 = CALL_EXPR_ARG (exp, 0);
38509       arg1 = CALL_EXPR_ARG (exp, 1);
38510
38511       op0 = expand_normal (arg0);
38512       op1 = expand_normal (arg1);
38513
38514       if (!register_operand (op0, Pmode))
38515         op0 = ix86_zero_extend_to_Pmode (op0);
38516       if (!register_operand (op1, BNDmode))
38517         op1 = copy_to_mode_reg (BNDmode, op1);
38518
38519       emit_insn (BNDmode == BND64mode
38520                  ? gen_bnd64_cu (op1, op0)
38521                  : gen_bnd32_cu (op1, op0));
38522       return 0;
38523
38524     case IX86_BUILTIN_BNDRET:
38525       arg0 = CALL_EXPR_ARG (exp, 0);
38526       gcc_assert (TREE_CODE (arg0) == SSA_NAME);
38527       target = chkp_get_rtl_bounds (arg0);
38528
38529       /* If no bounds were specified for returned value,
38530          then use INIT bounds.  It usually happens when
38531          some built-in function is expanded.  */
38532       if (!target)
38533         {
38534           rtx t1 = gen_reg_rtx (Pmode);
38535           rtx t2 = gen_reg_rtx (Pmode);
38536           target = gen_reg_rtx (BNDmode);
38537           emit_move_insn (t1, const0_rtx);
38538           emit_move_insn (t2, constm1_rtx);
38539           emit_insn (BNDmode == BND64mode
38540                      ? gen_bnd64_mk (target, t1, t2)
38541                      : gen_bnd32_mk (target, t1, t2));
38542         }
38543
38544       gcc_assert (target && REG_P (target));
38545       return target;
38546
38547     case IX86_BUILTIN_BNDNARROW:
38548       {
38549         rtx m1, m1h1, m1h2, lb, ub, t1;
38550
38551         /* Return value and lb.  */
38552         arg0 = CALL_EXPR_ARG (exp, 0);
38553         /* Bounds.  */
38554         arg1 = CALL_EXPR_ARG (exp, 1);
38555         /* Size.  */
38556         arg2 = CALL_EXPR_ARG (exp, 2);
38557
38558         lb = expand_normal (arg0);
38559         op1 = expand_normal (arg1);
38560         op2 = expand_normal (arg2);
38561
38562         /* Size was passed but we need to use (size - 1) as for bndmk.  */
38563         op2 = expand_simple_binop (Pmode, PLUS, op2, constm1_rtx,
38564                                    NULL_RTX, 1, OPTAB_DIRECT);
38565
38566         /* Add LB to size and inverse to get UB.  */
38567         op2 = expand_simple_binop (Pmode, PLUS, op2, lb,
38568                                    op2, 1, OPTAB_DIRECT);
38569         ub = expand_simple_unop (Pmode, NOT, op2, op2, 1);
38570
38571         if (!register_operand (lb, Pmode))
38572           lb = ix86_zero_extend_to_Pmode (lb);
38573         if (!register_operand (ub, Pmode))
38574           ub = ix86_zero_extend_to_Pmode (ub);
38575
38576         /* We need to move bounds to memory before any computations.  */
38577         if (MEM_P (op1))
38578           m1 = op1;
38579         else
38580           {
38581             m1 = assign_386_stack_local (BNDmode, SLOT_TEMP);
38582             emit_move_insn (m1, op1);
38583           }
38584
38585         /* Generate mem expression to be used for access to LB and UB.  */
38586         m1h1 = adjust_address (m1, Pmode, 0);
38587         m1h2 = adjust_address (m1, Pmode, GET_MODE_SIZE (Pmode));
38588
38589         t1 = gen_reg_rtx (Pmode);
38590
38591         /* Compute LB.  */
38592         emit_move_insn (t1, m1h1);
38593         ix86_emit_move_max (t1, lb);
38594         emit_move_insn (m1h1, t1);
38595
38596         /* Compute UB.  UB is stored in 1's complement form.  Therefore
38597            we also use max here.  */
38598         emit_move_insn (t1, m1h2);
38599         ix86_emit_move_max (t1, ub);
38600         emit_move_insn (m1h2, t1);
38601
38602         op2 = gen_reg_rtx (BNDmode);
38603         emit_move_insn (op2, m1);
38604
38605         return chkp_join_splitted_slot (lb, op2);
38606       }
38607
38608     case IX86_BUILTIN_BNDINT:
38609       {
38610         rtx res, rh1, rh2, lb1, lb2, ub1, ub2;
38611
38612         if (!target
38613             || GET_MODE (target) != BNDmode
38614             || !register_operand (target, BNDmode))
38615           target = gen_reg_rtx (BNDmode);
38616
38617         arg0 = CALL_EXPR_ARG (exp, 0);
38618         arg1 = CALL_EXPR_ARG (exp, 1);
38619
38620         op0 = expand_normal (arg0);
38621         op1 = expand_normal (arg1);
38622
38623         res = assign_386_stack_local (BNDmode, SLOT_TEMP);
38624         rh1 = adjust_address (res, Pmode, 0);
38625         rh2 = adjust_address (res, Pmode, GET_MODE_SIZE (Pmode));
38626
38627         /* Put first bounds to temporaries.  */
38628         lb1 = gen_reg_rtx (Pmode);
38629         ub1 = gen_reg_rtx (Pmode);
38630         if (MEM_P (op0))
38631           {
38632             emit_move_insn (lb1, adjust_address (op0, Pmode, 0));
38633             emit_move_insn (ub1, adjust_address (op0, Pmode,
38634                                                  GET_MODE_SIZE (Pmode)));
38635           }
38636         else
38637           {
38638             emit_move_insn (res, op0);
38639             emit_move_insn (lb1, rh1);
38640             emit_move_insn (ub1, rh2);
38641           }
38642
38643         /* Put second bounds to temporaries.  */
38644         lb2 = gen_reg_rtx (Pmode);
38645         ub2 = gen_reg_rtx (Pmode);
38646         if (MEM_P (op1))
38647           {
38648             emit_move_insn (lb2, adjust_address (op1, Pmode, 0));
38649             emit_move_insn (ub2, adjust_address (op1, Pmode,
38650                                                  GET_MODE_SIZE (Pmode)));
38651           }
38652         else
38653           {
38654             emit_move_insn (res, op1);
38655             emit_move_insn (lb2, rh1);
38656             emit_move_insn (ub2, rh2);
38657           }
38658
38659         /* Compute LB.  */
38660         ix86_emit_move_max (lb1, lb2);
38661         emit_move_insn (rh1, lb1);
38662
38663         /* Compute UB.  UB is stored in 1's complement form.  Therefore
38664            we also use max here.  */
38665         ix86_emit_move_max (ub1, ub2);
38666         emit_move_insn (rh2, ub1);
38667
38668         emit_move_insn (target, res);
38669
38670         return target;
38671       }
38672
38673     case IX86_BUILTIN_SIZEOF:
38674       {
38675         tree name;
38676         rtx symbol;
38677
38678         if (!target
38679             || GET_MODE (target) != Pmode
38680             || !register_operand (target, Pmode))
38681           target = gen_reg_rtx (Pmode);
38682
38683         arg0 = CALL_EXPR_ARG (exp, 0);
38684         gcc_assert (TREE_CODE (arg0) == VAR_DECL);
38685
38686         name = DECL_ASSEMBLER_NAME (arg0);
38687         symbol = gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (name));
38688
38689         emit_insn (Pmode == SImode
38690                    ? gen_move_size_reloc_si (target, symbol)
38691                    : gen_move_size_reloc_di (target, symbol));
38692
38693         return target;
38694       }
38695
38696     case IX86_BUILTIN_BNDLOWER:
38697       {
38698         rtx mem, hmem;
38699
38700         if (!target
38701             || GET_MODE (target) != Pmode
38702             || !register_operand (target, Pmode))
38703           target = gen_reg_rtx (Pmode);
38704
38705         arg0 = CALL_EXPR_ARG (exp, 0);
38706         op0 = expand_normal (arg0);
38707
38708         /* We need to move bounds to memory first.  */
38709         if (MEM_P (op0))
38710           mem = op0;
38711         else
38712           {
38713             mem = assign_386_stack_local (BNDmode, SLOT_TEMP);
38714             emit_move_insn (mem, op0);
38715           }
38716
38717         /* Generate mem expression to access LB and load it.  */
38718         hmem = adjust_address (mem, Pmode, 0);
38719         emit_move_insn (target, hmem);
38720
38721         return target;
38722       }
38723
38724     case IX86_BUILTIN_BNDUPPER:
38725       {
38726         rtx mem, hmem, res;
38727
38728         if (!target
38729             || GET_MODE (target) != Pmode
38730             || !register_operand (target, Pmode))
38731           target = gen_reg_rtx (Pmode);
38732
38733         arg0 = CALL_EXPR_ARG (exp, 0);
38734         op0 = expand_normal (arg0);
38735
38736         /* We need to move bounds to memory first.  */
38737         if (MEM_P (op0))
38738           mem = op0;
38739         else
38740           {
38741             mem = assign_386_stack_local (BNDmode, SLOT_TEMP);
38742             emit_move_insn (mem, op0);
38743           }
38744
38745         /* Generate mem expression to access UB.  */
38746         hmem = adjust_address (mem, Pmode, GET_MODE_SIZE (Pmode));
38747
38748         /* We need to inverse all bits of UB.  */
38749         res = expand_simple_unop (Pmode, NOT, hmem, target, 1);
38750
38751         if (res != target)
38752           emit_move_insn (target, res);
38753
38754         return target;
38755       }
38756
38757     case IX86_BUILTIN_MASKMOVQ:
38758     case IX86_BUILTIN_MASKMOVDQU:
38759       icode = (fcode == IX86_BUILTIN_MASKMOVQ
38760                ? CODE_FOR_mmx_maskmovq
38761                : CODE_FOR_sse2_maskmovdqu);
38762       /* Note the arg order is different from the operand order.  */
38763       arg1 = CALL_EXPR_ARG (exp, 0);
38764       arg2 = CALL_EXPR_ARG (exp, 1);
38765       arg0 = CALL_EXPR_ARG (exp, 2);
38766       op0 = expand_normal (arg0);
38767       op1 = expand_normal (arg1);
38768       op2 = expand_normal (arg2);
38769       mode0 = insn_data[icode].operand[0].mode;
38770       mode1 = insn_data[icode].operand[1].mode;
38771       mode2 = insn_data[icode].operand[2].mode;
38772
38773       op0 = ix86_zero_extend_to_Pmode (op0);
38774       op0 = gen_rtx_MEM (mode1, op0);
38775
38776       if (!insn_data[icode].operand[0].predicate (op0, mode0))
38777         op0 = copy_to_mode_reg (mode0, op0);
38778       if (!insn_data[icode].operand[1].predicate (op1, mode1))
38779         op1 = copy_to_mode_reg (mode1, op1);
38780       if (!insn_data[icode].operand[2].predicate (op2, mode2))
38781         op2 = copy_to_mode_reg (mode2, op2);
38782       pat = GEN_FCN (icode) (op0, op1, op2);
38783       if (! pat)
38784         return 0;
38785       emit_insn (pat);
38786       return 0;
38787
38788     case IX86_BUILTIN_LDMXCSR:
38789       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
38790       target = assign_386_stack_local (SImode, SLOT_TEMP);
38791       emit_move_insn (target, op0);
38792       emit_insn (gen_sse_ldmxcsr (target));
38793       return 0;
38794
38795     case IX86_BUILTIN_STMXCSR:
38796       target = assign_386_stack_local (SImode, SLOT_TEMP);
38797       emit_insn (gen_sse_stmxcsr (target));
38798       return copy_to_mode_reg (SImode, target);
38799
38800     case IX86_BUILTIN_CLFLUSH:
38801         arg0 = CALL_EXPR_ARG (exp, 0);
38802         op0 = expand_normal (arg0);
38803         icode = CODE_FOR_sse2_clflush;
38804         if (!insn_data[icode].operand[0].predicate (op0, Pmode))
38805           op0 = ix86_zero_extend_to_Pmode (op0);
38806
38807         emit_insn (gen_sse2_clflush (op0));
38808         return 0;
38809
38810     case IX86_BUILTIN_CLWB:
38811         arg0 = CALL_EXPR_ARG (exp, 0);
38812         op0 = expand_normal (arg0);
38813         icode = CODE_FOR_clwb;
38814         if (!insn_data[icode].operand[0].predicate (op0, Pmode))
38815           op0 = ix86_zero_extend_to_Pmode (op0);
38816
38817         emit_insn (gen_clwb (op0));
38818         return 0;
38819
38820     case IX86_BUILTIN_CLFLUSHOPT:
38821         arg0 = CALL_EXPR_ARG (exp, 0);
38822         op0 = expand_normal (arg0);
38823         icode = CODE_FOR_clflushopt;
38824         if (!insn_data[icode].operand[0].predicate (op0, Pmode))
38825           op0 = ix86_zero_extend_to_Pmode (op0);
38826
38827         emit_insn (gen_clflushopt (op0));
38828         return 0;
38829
38830     case IX86_BUILTIN_MONITOR:
38831       arg0 = CALL_EXPR_ARG (exp, 0);
38832       arg1 = CALL_EXPR_ARG (exp, 1);
38833       arg2 = CALL_EXPR_ARG (exp, 2);
38834       op0 = expand_normal (arg0);
38835       op1 = expand_normal (arg1);
38836       op2 = expand_normal (arg2);
38837       if (!REG_P (op0))
38838         op0 = ix86_zero_extend_to_Pmode (op0);
38839       if (!REG_P (op1))
38840         op1 = copy_to_mode_reg (SImode, op1);
38841       if (!REG_P (op2))
38842         op2 = copy_to_mode_reg (SImode, op2);
38843       emit_insn (ix86_gen_monitor (op0, op1, op2));
38844       return 0;
38845
38846     case IX86_BUILTIN_MWAIT:
38847       arg0 = CALL_EXPR_ARG (exp, 0);
38848       arg1 = CALL_EXPR_ARG (exp, 1);
38849       op0 = expand_normal (arg0);
38850       op1 = expand_normal (arg1);
38851       if (!REG_P (op0))
38852         op0 = copy_to_mode_reg (SImode, op0);
38853       if (!REG_P (op1))
38854         op1 = copy_to_mode_reg (SImode, op1);
38855       emit_insn (gen_sse3_mwait (op0, op1));
38856       return 0;
38857
38858     case IX86_BUILTIN_VEC_INIT_V2SI:
38859     case IX86_BUILTIN_VEC_INIT_V4HI:
38860     case IX86_BUILTIN_VEC_INIT_V8QI:
38861       return ix86_expand_vec_init_builtin (TREE_TYPE (exp), exp, target);
38862
38863     case IX86_BUILTIN_VEC_EXT_V2DF:
38864     case IX86_BUILTIN_VEC_EXT_V2DI:
38865     case IX86_BUILTIN_VEC_EXT_V4SF:
38866     case IX86_BUILTIN_VEC_EXT_V4SI:
38867     case IX86_BUILTIN_VEC_EXT_V8HI:
38868     case IX86_BUILTIN_VEC_EXT_V2SI:
38869     case IX86_BUILTIN_VEC_EXT_V4HI:
38870     case IX86_BUILTIN_VEC_EXT_V16QI:
38871       return ix86_expand_vec_ext_builtin (exp, target);
38872
38873     case IX86_BUILTIN_VEC_SET_V2DI:
38874     case IX86_BUILTIN_VEC_SET_V4SF:
38875     case IX86_BUILTIN_VEC_SET_V4SI:
38876     case IX86_BUILTIN_VEC_SET_V8HI:
38877     case IX86_BUILTIN_VEC_SET_V4HI:
38878     case IX86_BUILTIN_VEC_SET_V16QI:
38879       return ix86_expand_vec_set_builtin (exp);
38880
38881     case IX86_BUILTIN_INFQ:
38882     case IX86_BUILTIN_HUGE_VALQ:
38883       {
38884         REAL_VALUE_TYPE inf;
38885         rtx tmp;
38886
38887         real_inf (&inf);
38888         tmp = CONST_DOUBLE_FROM_REAL_VALUE (inf, mode);
38889
38890         tmp = validize_mem (force_const_mem (mode, tmp));
38891
38892         if (target == 0)
38893           target = gen_reg_rtx (mode);
38894
38895         emit_move_insn (target, tmp);
38896         return target;
38897       }
38898
38899     case IX86_BUILTIN_RDPMC:
38900     case IX86_BUILTIN_RDTSC:
38901     case IX86_BUILTIN_RDTSCP:
38902
38903       op0 = gen_reg_rtx (DImode);
38904       op1 = gen_reg_rtx (DImode);
38905
38906       if (fcode == IX86_BUILTIN_RDPMC)
38907         {
38908           arg0 = CALL_EXPR_ARG (exp, 0);
38909           op2 = expand_normal (arg0);
38910           if (!register_operand (op2, SImode))
38911             op2 = copy_to_mode_reg (SImode, op2);
38912
38913           insn = (TARGET_64BIT
38914                   ? gen_rdpmc_rex64 (op0, op1, op2)
38915                   : gen_rdpmc (op0, op2));
38916           emit_insn (insn);
38917         }
38918       else if (fcode == IX86_BUILTIN_RDTSC)
38919         {
38920           insn = (TARGET_64BIT
38921                   ? gen_rdtsc_rex64 (op0, op1)
38922                   : gen_rdtsc (op0));
38923           emit_insn (insn);
38924         }
38925       else
38926         {
38927           op2 = gen_reg_rtx (SImode);
38928
38929           insn = (TARGET_64BIT
38930                   ? gen_rdtscp_rex64 (op0, op1, op2)
38931                   : gen_rdtscp (op0, op2));
38932           emit_insn (insn);
38933
38934           arg0 = CALL_EXPR_ARG (exp, 0);
38935           op4 = expand_normal (arg0);
38936           if (!address_operand (op4, VOIDmode))
38937             {
38938               op4 = convert_memory_address (Pmode, op4);
38939               op4 = copy_addr_to_reg (op4);
38940             }
38941           emit_move_insn (gen_rtx_MEM (SImode, op4), op2);
38942         }
38943
38944       if (target == 0)
38945         {
38946           /* mode is VOIDmode if __builtin_rd* has been called
38947              without lhs.  */
38948           if (mode == VOIDmode)
38949             return target;
38950           target = gen_reg_rtx (mode);
38951         }
38952
38953       if (TARGET_64BIT)
38954         {
38955           op1 = expand_simple_binop (DImode, ASHIFT, op1, GEN_INT (32),
38956                                      op1, 1, OPTAB_DIRECT);
38957           op0 = expand_simple_binop (DImode, IOR, op0, op1,
38958                                      op0, 1, OPTAB_DIRECT);
38959         }
38960
38961       emit_move_insn (target, op0);
38962       return target;
38963
38964     case IX86_BUILTIN_FXSAVE:
38965     case IX86_BUILTIN_FXRSTOR:
38966     case IX86_BUILTIN_FXSAVE64:
38967     case IX86_BUILTIN_FXRSTOR64:
38968     case IX86_BUILTIN_FNSTENV:
38969     case IX86_BUILTIN_FLDENV:
38970       mode0 = BLKmode;
38971       switch (fcode)
38972         {
38973         case IX86_BUILTIN_FXSAVE:
38974           icode = CODE_FOR_fxsave;
38975           break;
38976         case IX86_BUILTIN_FXRSTOR:
38977           icode = CODE_FOR_fxrstor;
38978           break;
38979         case IX86_BUILTIN_FXSAVE64:
38980           icode = CODE_FOR_fxsave64;
38981           break;
38982         case IX86_BUILTIN_FXRSTOR64:
38983           icode = CODE_FOR_fxrstor64;
38984           break;
38985         case IX86_BUILTIN_FNSTENV:
38986           icode = CODE_FOR_fnstenv;
38987           break;
38988         case IX86_BUILTIN_FLDENV:
38989           icode = CODE_FOR_fldenv;
38990           break;
38991         default:
38992           gcc_unreachable ();
38993         }
38994
38995       arg0 = CALL_EXPR_ARG (exp, 0);
38996       op0 = expand_normal (arg0);
38997
38998       if (!address_operand (op0, VOIDmode))
38999         {
39000           op0 = convert_memory_address (Pmode, op0);
39001           op0 = copy_addr_to_reg (op0);
39002         }
39003       op0 = gen_rtx_MEM (mode0, op0);
39004
39005       pat = GEN_FCN (icode) (op0);
39006       if (pat)
39007         emit_insn (pat);
39008       return 0;
39009
39010     case IX86_BUILTIN_XSAVE:
39011     case IX86_BUILTIN_XRSTOR:
39012     case IX86_BUILTIN_XSAVE64:
39013     case IX86_BUILTIN_XRSTOR64:
39014     case IX86_BUILTIN_XSAVEOPT:
39015     case IX86_BUILTIN_XSAVEOPT64:
39016     case IX86_BUILTIN_XSAVES:
39017     case IX86_BUILTIN_XRSTORS:
39018     case IX86_BUILTIN_XSAVES64:
39019     case IX86_BUILTIN_XRSTORS64:
39020     case IX86_BUILTIN_XSAVEC:
39021     case IX86_BUILTIN_XSAVEC64:
39022       arg0 = CALL_EXPR_ARG (exp, 0);
39023       arg1 = CALL_EXPR_ARG (exp, 1);
39024       op0 = expand_normal (arg0);
39025       op1 = expand_normal (arg1);
39026
39027       if (!address_operand (op0, VOIDmode))
39028         {
39029           op0 = convert_memory_address (Pmode, op0);
39030           op0 = copy_addr_to_reg (op0);
39031         }
39032       op0 = gen_rtx_MEM (BLKmode, op0);
39033
39034       op1 = force_reg (DImode, op1);
39035
39036       if (TARGET_64BIT)
39037         {
39038           op2 = expand_simple_binop (DImode, LSHIFTRT, op1, GEN_INT (32),
39039                                      NULL, 1, OPTAB_DIRECT);
39040           switch (fcode)
39041             {
39042             case IX86_BUILTIN_XSAVE:
39043               icode = CODE_FOR_xsave_rex64;
39044               break;
39045             case IX86_BUILTIN_XRSTOR:
39046               icode = CODE_FOR_xrstor_rex64;
39047               break;
39048             case IX86_BUILTIN_XSAVE64:
39049               icode = CODE_FOR_xsave64;
39050               break;
39051             case IX86_BUILTIN_XRSTOR64:
39052               icode = CODE_FOR_xrstor64;
39053               break;
39054             case IX86_BUILTIN_XSAVEOPT:
39055               icode = CODE_FOR_xsaveopt_rex64;
39056               break;
39057             case IX86_BUILTIN_XSAVEOPT64:
39058               icode = CODE_FOR_xsaveopt64;
39059               break;
39060             case IX86_BUILTIN_XSAVES:
39061               icode = CODE_FOR_xsaves_rex64;
39062               break;
39063             case IX86_BUILTIN_XRSTORS:
39064               icode = CODE_FOR_xrstors_rex64;
39065               break;
39066             case IX86_BUILTIN_XSAVES64:
39067               icode = CODE_FOR_xsaves64;
39068               break;
39069             case IX86_BUILTIN_XRSTORS64:
39070               icode = CODE_FOR_xrstors64;
39071               break;
39072             case IX86_BUILTIN_XSAVEC:
39073               icode = CODE_FOR_xsavec_rex64;
39074               break;
39075             case IX86_BUILTIN_XSAVEC64:
39076               icode = CODE_FOR_xsavec64;
39077               break;
39078             default:
39079               gcc_unreachable ();
39080             }
39081
39082           op2 = gen_lowpart (SImode, op2);
39083           op1 = gen_lowpart (SImode, op1);
39084           pat = GEN_FCN (icode) (op0, op1, op2);
39085         }
39086       else
39087         {
39088           switch (fcode)
39089             {
39090             case IX86_BUILTIN_XSAVE:
39091               icode = CODE_FOR_xsave;
39092               break;
39093             case IX86_BUILTIN_XRSTOR:
39094               icode = CODE_FOR_xrstor;
39095               break;
39096             case IX86_BUILTIN_XSAVEOPT:
39097               icode = CODE_FOR_xsaveopt;
39098               break;
39099             case IX86_BUILTIN_XSAVES:
39100               icode = CODE_FOR_xsaves;
39101               break;
39102             case IX86_BUILTIN_XRSTORS:
39103               icode = CODE_FOR_xrstors;
39104               break;
39105             case IX86_BUILTIN_XSAVEC:
39106               icode = CODE_FOR_xsavec;
39107               break;
39108             default:
39109               gcc_unreachable ();
39110             }
39111           pat = GEN_FCN (icode) (op0, op1);
39112         }
39113
39114       if (pat)
39115         emit_insn (pat);
39116       return 0;
39117
39118     case IX86_BUILTIN_LLWPCB:
39119       arg0 = CALL_EXPR_ARG (exp, 0);
39120       op0 = expand_normal (arg0);
39121       icode = CODE_FOR_lwp_llwpcb;
39122       if (!insn_data[icode].operand[0].predicate (op0, Pmode))
39123         op0 = ix86_zero_extend_to_Pmode (op0);
39124       emit_insn (gen_lwp_llwpcb (op0));
39125       return 0;
39126
39127     case IX86_BUILTIN_SLWPCB:
39128       icode = CODE_FOR_lwp_slwpcb;
39129       if (!target
39130           || !insn_data[icode].operand[0].predicate (target, Pmode))
39131         target = gen_reg_rtx (Pmode);
39132       emit_insn (gen_lwp_slwpcb (target));
39133       return target;
39134
39135     case IX86_BUILTIN_BEXTRI32:
39136     case IX86_BUILTIN_BEXTRI64:
39137       arg0 = CALL_EXPR_ARG (exp, 0);
39138       arg1 = CALL_EXPR_ARG (exp, 1);
39139       op0 = expand_normal (arg0);
39140       op1 = expand_normal (arg1);
39141       icode = (fcode == IX86_BUILTIN_BEXTRI32
39142           ? CODE_FOR_tbm_bextri_si
39143           : CODE_FOR_tbm_bextri_di);
39144       if (!CONST_INT_P (op1))
39145         {
39146           error ("last argument must be an immediate");
39147           return const0_rtx;
39148         }
39149       else
39150         {
39151           unsigned char length = (INTVAL (op1) >> 8) & 0xFF;
39152           unsigned char lsb_index = INTVAL (op1) & 0xFF;
39153           op1 = GEN_INT (length);
39154           op2 = GEN_INT (lsb_index);
39155           pat = GEN_FCN (icode) (target, op0, op1, op2);
39156           if (pat)
39157             emit_insn (pat);
39158           return target;
39159         }
39160
39161     case IX86_BUILTIN_RDRAND16_STEP:
39162       icode = CODE_FOR_rdrandhi_1;
39163       mode0 = HImode;
39164       goto rdrand_step;
39165
39166     case IX86_BUILTIN_RDRAND32_STEP:
39167       icode = CODE_FOR_rdrandsi_1;
39168       mode0 = SImode;
39169       goto rdrand_step;
39170
39171     case IX86_BUILTIN_RDRAND64_STEP:
39172       icode = CODE_FOR_rdranddi_1;
39173       mode0 = DImode;
39174
39175 rdrand_step:
39176       op0 = gen_reg_rtx (mode0);
39177       emit_insn (GEN_FCN (icode) (op0));
39178
39179       arg0 = CALL_EXPR_ARG (exp, 0);
39180       op1 = expand_normal (arg0);
39181       if (!address_operand (op1, VOIDmode))
39182         {
39183           op1 = convert_memory_address (Pmode, op1);
39184           op1 = copy_addr_to_reg (op1);
39185         }
39186       emit_move_insn (gen_rtx_MEM (mode0, op1), op0);
39187
39188       op1 = gen_reg_rtx (SImode);
39189       emit_move_insn (op1, CONST1_RTX (SImode));
39190
39191       /* Emit SImode conditional move.  */
39192       if (mode0 == HImode)
39193         {
39194           op2 = gen_reg_rtx (SImode);
39195           emit_insn (gen_zero_extendhisi2 (op2, op0));
39196         }
39197       else if (mode0 == SImode)
39198         op2 = op0;
39199       else
39200         op2 = gen_rtx_SUBREG (SImode, op0, 0);
39201
39202       if (target == 0
39203           || !register_operand (target, SImode))
39204         target = gen_reg_rtx (SImode);
39205
39206       pat = gen_rtx_GEU (VOIDmode, gen_rtx_REG (CCCmode, FLAGS_REG),
39207                          const0_rtx);
39208       emit_insn (gen_rtx_SET (VOIDmode, target,
39209                               gen_rtx_IF_THEN_ELSE (SImode, pat, op2, op1)));
39210       return target;
39211
39212     case IX86_BUILTIN_RDSEED16_STEP:
39213       icode = CODE_FOR_rdseedhi_1;
39214       mode0 = HImode;
39215       goto rdseed_step;
39216
39217     case IX86_BUILTIN_RDSEED32_STEP:
39218       icode = CODE_FOR_rdseedsi_1;
39219       mode0 = SImode;
39220       goto rdseed_step;
39221
39222     case IX86_BUILTIN_RDSEED64_STEP:
39223       icode = CODE_FOR_rdseeddi_1;
39224       mode0 = DImode;
39225
39226 rdseed_step:
39227       op0 = gen_reg_rtx (mode0);
39228       emit_insn (GEN_FCN (icode) (op0));
39229
39230       arg0 = CALL_EXPR_ARG (exp, 0);
39231       op1 = expand_normal (arg0);
39232       if (!address_operand (op1, VOIDmode))
39233         {
39234           op1 = convert_memory_address (Pmode, op1);
39235           op1 = copy_addr_to_reg (op1);
39236         }
39237       emit_move_insn (gen_rtx_MEM (mode0, op1), op0);
39238
39239       op2 = gen_reg_rtx (QImode);
39240
39241       pat = gen_rtx_LTU (QImode, gen_rtx_REG (CCCmode, FLAGS_REG),
39242                          const0_rtx);
39243       emit_insn (gen_rtx_SET (VOIDmode, op2, pat));
39244
39245       if (target == 0
39246           || !register_operand (target, SImode))
39247         target = gen_reg_rtx (SImode);
39248
39249       emit_insn (gen_zero_extendqisi2 (target, op2));
39250       return target;
39251
39252     case IX86_BUILTIN_SBB32:
39253       icode = CODE_FOR_subsi3_carry;
39254       mode0 = SImode;
39255       goto addcarryx;
39256
39257     case IX86_BUILTIN_SBB64:
39258       icode = CODE_FOR_subdi3_carry;
39259       mode0 = DImode;
39260       goto addcarryx;
39261
39262     case IX86_BUILTIN_ADDCARRYX32:
39263       icode = TARGET_ADX ? CODE_FOR_adcxsi3 : CODE_FOR_addsi3_carry;
39264       mode0 = SImode;
39265       goto addcarryx;
39266
39267     case IX86_BUILTIN_ADDCARRYX64:
39268       icode = TARGET_ADX ? CODE_FOR_adcxdi3 : CODE_FOR_adddi3_carry;
39269       mode0 = DImode;
39270
39271 addcarryx:
39272       arg0 = CALL_EXPR_ARG (exp, 0); /* unsigned char c_in.  */
39273       arg1 = CALL_EXPR_ARG (exp, 1); /* unsigned int src1.  */
39274       arg2 = CALL_EXPR_ARG (exp, 2); /* unsigned int src2.  */
39275       arg3 = CALL_EXPR_ARG (exp, 3); /* unsigned int *sum_out.  */
39276
39277       op0 = gen_reg_rtx (QImode);
39278
39279       /* Generate CF from input operand.  */
39280       op1 = expand_normal (arg0);
39281       op1 = copy_to_mode_reg (QImode, convert_to_mode (QImode, op1, 1));
39282       emit_insn (gen_addqi3_cc (op0, op1, constm1_rtx));
39283
39284       /* Gen ADCX instruction to compute X+Y+CF.  */
39285       op2 = expand_normal (arg1);
39286       op3 = expand_normal (arg2);
39287
39288       if (!REG_P (op2))
39289         op2 = copy_to_mode_reg (mode0, op2);
39290       if (!REG_P (op3))
39291         op3 = copy_to_mode_reg (mode0, op3);
39292
39293       op0 = gen_reg_rtx (mode0);
39294
39295       op4 = gen_rtx_REG (CCCmode, FLAGS_REG);
39296       pat = gen_rtx_LTU (VOIDmode, op4, const0_rtx);
39297       emit_insn (GEN_FCN (icode) (op0, op2, op3, op4, pat));
39298
39299       /* Store the result.  */
39300       op4 = expand_normal (arg3);
39301       if (!address_operand (op4, VOIDmode))
39302         {
39303           op4 = convert_memory_address (Pmode, op4);
39304           op4 = copy_addr_to_reg (op4);
39305         }
39306       emit_move_insn (gen_rtx_MEM (mode0, op4), op0);
39307
39308       /* Return current CF value.  */
39309       if (target == 0)
39310         target = gen_reg_rtx (QImode);
39311
39312       PUT_MODE (pat, QImode);
39313       emit_insn (gen_rtx_SET (VOIDmode, target, pat));
39314       return target;
39315
39316     case IX86_BUILTIN_READ_FLAGS:
39317       emit_insn (gen_push (gen_rtx_REG (word_mode, FLAGS_REG)));
39318
39319       if (optimize
39320           || target == NULL_RTX
39321           || !nonimmediate_operand (target, word_mode)
39322           || GET_MODE (target) != word_mode)
39323         target = gen_reg_rtx (word_mode);
39324
39325       emit_insn (gen_pop (target));
39326       return target;
39327
39328     case IX86_BUILTIN_WRITE_FLAGS:
39329
39330       arg0 = CALL_EXPR_ARG (exp, 0);
39331       op0 = expand_normal (arg0);
39332       if (!general_no_elim_operand (op0, word_mode))
39333         op0 = copy_to_mode_reg (word_mode, op0);
39334
39335       emit_insn (gen_push (op0));
39336       emit_insn (gen_pop (gen_rtx_REG (word_mode, FLAGS_REG)));
39337       return 0;
39338
39339     case IX86_BUILTIN_KORTESTC16:
39340       icode = CODE_FOR_kortestchi;
39341       mode0 = HImode;
39342       mode1 = CCCmode;
39343       goto kortest;
39344
39345     case IX86_BUILTIN_KORTESTZ16:
39346       icode = CODE_FOR_kortestzhi;
39347       mode0 = HImode;
39348       mode1 = CCZmode;
39349
39350     kortest:
39351       arg0 = CALL_EXPR_ARG (exp, 0); /* Mask reg src1.  */
39352       arg1 = CALL_EXPR_ARG (exp, 1); /* Mask reg src2.  */
39353       op0 = expand_normal (arg0);
39354       op1 = expand_normal (arg1);
39355
39356       op0 = copy_to_reg (op0);
39357       op0 = simplify_gen_subreg (mode0, op0, GET_MODE (op0), 0);
39358       op1 = copy_to_reg (op1);
39359       op1 = simplify_gen_subreg (mode0, op1, GET_MODE (op1), 0);
39360
39361       target = gen_reg_rtx (QImode);
39362       emit_insn (gen_rtx_SET (mode0, target, const0_rtx));
39363
39364       /* Emit kortest.  */
39365       emit_insn (GEN_FCN (icode) (op0, op1));
39366       /* And use setcc to return result from flags.  */
39367       ix86_expand_setcc (target, EQ,
39368                          gen_rtx_REG (mode1, FLAGS_REG), const0_rtx);
39369       return target;
39370
39371     case IX86_BUILTIN_GATHERSIV2DF:
39372       icode = CODE_FOR_avx2_gathersiv2df;
39373       goto gather_gen;
39374     case IX86_BUILTIN_GATHERSIV4DF:
39375       icode = CODE_FOR_avx2_gathersiv4df;
39376       goto gather_gen;
39377     case IX86_BUILTIN_GATHERDIV2DF:
39378       icode = CODE_FOR_avx2_gatherdiv2df;
39379       goto gather_gen;
39380     case IX86_BUILTIN_GATHERDIV4DF:
39381       icode = CODE_FOR_avx2_gatherdiv4df;
39382       goto gather_gen;
39383     case IX86_BUILTIN_GATHERSIV4SF:
39384       icode = CODE_FOR_avx2_gathersiv4sf;
39385       goto gather_gen;
39386     case IX86_BUILTIN_GATHERSIV8SF:
39387       icode = CODE_FOR_avx2_gathersiv8sf;
39388       goto gather_gen;
39389     case IX86_BUILTIN_GATHERDIV4SF:
39390       icode = CODE_FOR_avx2_gatherdiv4sf;
39391       goto gather_gen;
39392     case IX86_BUILTIN_GATHERDIV8SF:
39393       icode = CODE_FOR_avx2_gatherdiv8sf;
39394       goto gather_gen;
39395     case IX86_BUILTIN_GATHERSIV2DI:
39396       icode = CODE_FOR_avx2_gathersiv2di;
39397       goto gather_gen;
39398     case IX86_BUILTIN_GATHERSIV4DI:
39399       icode = CODE_FOR_avx2_gathersiv4di;
39400       goto gather_gen;
39401     case IX86_BUILTIN_GATHERDIV2DI:
39402       icode = CODE_FOR_avx2_gatherdiv2di;
39403       goto gather_gen;
39404     case IX86_BUILTIN_GATHERDIV4DI:
39405       icode = CODE_FOR_avx2_gatherdiv4di;
39406       goto gather_gen;
39407     case IX86_BUILTIN_GATHERSIV4SI:
39408       icode = CODE_FOR_avx2_gathersiv4si;
39409       goto gather_gen;
39410     case IX86_BUILTIN_GATHERSIV8SI:
39411       icode = CODE_FOR_avx2_gathersiv8si;
39412       goto gather_gen;
39413     case IX86_BUILTIN_GATHERDIV4SI:
39414       icode = CODE_FOR_avx2_gatherdiv4si;
39415       goto gather_gen;
39416     case IX86_BUILTIN_GATHERDIV8SI:
39417       icode = CODE_FOR_avx2_gatherdiv8si;
39418       goto gather_gen;
39419     case IX86_BUILTIN_GATHERALTSIV4DF:
39420       icode = CODE_FOR_avx2_gathersiv4df;
39421       goto gather_gen;
39422     case IX86_BUILTIN_GATHERALTDIV8SF:
39423       icode = CODE_FOR_avx2_gatherdiv8sf;
39424       goto gather_gen;
39425     case IX86_BUILTIN_GATHERALTSIV4DI:
39426       icode = CODE_FOR_avx2_gathersiv4di;
39427       goto gather_gen;
39428     case IX86_BUILTIN_GATHERALTDIV8SI:
39429       icode = CODE_FOR_avx2_gatherdiv8si;
39430       goto gather_gen;
39431     case IX86_BUILTIN_GATHER3SIV16SF:
39432       icode = CODE_FOR_avx512f_gathersiv16sf;
39433       goto gather_gen;
39434     case IX86_BUILTIN_GATHER3SIV8DF:
39435       icode = CODE_FOR_avx512f_gathersiv8df;
39436       goto gather_gen;
39437     case IX86_BUILTIN_GATHER3DIV16SF:
39438       icode = CODE_FOR_avx512f_gatherdiv16sf;
39439       goto gather_gen;
39440     case IX86_BUILTIN_GATHER3DIV8DF:
39441       icode = CODE_FOR_avx512f_gatherdiv8df;
39442       goto gather_gen;
39443     case IX86_BUILTIN_GATHER3SIV16SI:
39444       icode = CODE_FOR_avx512f_gathersiv16si;
39445       goto gather_gen;
39446     case IX86_BUILTIN_GATHER3SIV8DI:
39447       icode = CODE_FOR_avx512f_gathersiv8di;
39448       goto gather_gen;
39449     case IX86_BUILTIN_GATHER3DIV16SI:
39450       icode = CODE_FOR_avx512f_gatherdiv16si;
39451       goto gather_gen;
39452     case IX86_BUILTIN_GATHER3DIV8DI:
39453       icode = CODE_FOR_avx512f_gatherdiv8di;
39454       goto gather_gen;
39455     case IX86_BUILTIN_GATHER3ALTSIV8DF:
39456       icode = CODE_FOR_avx512f_gathersiv8df;
39457       goto gather_gen;
39458     case IX86_BUILTIN_GATHER3ALTDIV16SF:
39459       icode = CODE_FOR_avx512f_gatherdiv16sf;
39460       goto gather_gen;
39461     case IX86_BUILTIN_GATHER3ALTSIV8DI:
39462       icode = CODE_FOR_avx512f_gathersiv8di;
39463       goto gather_gen;
39464     case IX86_BUILTIN_GATHER3ALTDIV16SI:
39465       icode = CODE_FOR_avx512f_gatherdiv16si;
39466       goto gather_gen;
39467     case IX86_BUILTIN_GATHER3SIV2DF:
39468       icode = CODE_FOR_avx512vl_gathersiv2df;
39469       goto gather_gen;
39470     case IX86_BUILTIN_GATHER3SIV4DF:
39471       icode = CODE_FOR_avx512vl_gathersiv4df;
39472       goto gather_gen;
39473     case IX86_BUILTIN_GATHER3DIV2DF:
39474       icode = CODE_FOR_avx512vl_gatherdiv2df;
39475       goto gather_gen;
39476     case IX86_BUILTIN_GATHER3DIV4DF:
39477       icode = CODE_FOR_avx512vl_gatherdiv4df;
39478       goto gather_gen;
39479     case IX86_BUILTIN_GATHER3SIV4SF:
39480       icode = CODE_FOR_avx512vl_gathersiv4sf;
39481       goto gather_gen;
39482     case IX86_BUILTIN_GATHER3SIV8SF:
39483       icode = CODE_FOR_avx512vl_gathersiv8sf;
39484       goto gather_gen;
39485     case IX86_BUILTIN_GATHER3DIV4SF:
39486       icode = CODE_FOR_avx512vl_gatherdiv4sf;
39487       goto gather_gen;
39488     case IX86_BUILTIN_GATHER3DIV8SF:
39489       icode = CODE_FOR_avx512vl_gatherdiv8sf;
39490       goto gather_gen;
39491     case IX86_BUILTIN_GATHER3SIV2DI:
39492       icode = CODE_FOR_avx512vl_gathersiv2di;
39493       goto gather_gen;
39494     case IX86_BUILTIN_GATHER3SIV4DI:
39495       icode = CODE_FOR_avx512vl_gathersiv4di;
39496       goto gather_gen;
39497     case IX86_BUILTIN_GATHER3DIV2DI:
39498       icode = CODE_FOR_avx512vl_gatherdiv2di;
39499       goto gather_gen;
39500     case IX86_BUILTIN_GATHER3DIV4DI:
39501       icode = CODE_FOR_avx512vl_gatherdiv4di;
39502       goto gather_gen;
39503     case IX86_BUILTIN_GATHER3SIV4SI:
39504       icode = CODE_FOR_avx512vl_gathersiv4si;
39505       goto gather_gen;
39506     case IX86_BUILTIN_GATHER3SIV8SI:
39507       icode = CODE_FOR_avx512vl_gathersiv8si;
39508       goto gather_gen;
39509     case IX86_BUILTIN_GATHER3DIV4SI:
39510       icode = CODE_FOR_avx512vl_gatherdiv4si;
39511       goto gather_gen;
39512     case IX86_BUILTIN_GATHER3DIV8SI:
39513       icode = CODE_FOR_avx512vl_gatherdiv8si;
39514       goto gather_gen;
39515     case IX86_BUILTIN_GATHER3ALTSIV4DF:
39516       icode = CODE_FOR_avx512vl_gathersiv4df;
39517       goto gather_gen;
39518     case IX86_BUILTIN_GATHER3ALTDIV8SF:
39519       icode = CODE_FOR_avx512vl_gatherdiv8sf;
39520       goto gather_gen;
39521     case IX86_BUILTIN_GATHER3ALTSIV4DI:
39522       icode = CODE_FOR_avx512vl_gathersiv4di;
39523       goto gather_gen;
39524     case IX86_BUILTIN_GATHER3ALTDIV8SI:
39525       icode = CODE_FOR_avx512vl_gatherdiv8si;
39526       goto gather_gen;
39527     case IX86_BUILTIN_SCATTERSIV16SF:
39528       icode = CODE_FOR_avx512f_scattersiv16sf;
39529       goto scatter_gen;
39530     case IX86_BUILTIN_SCATTERSIV8DF:
39531       icode = CODE_FOR_avx512f_scattersiv8df;
39532       goto scatter_gen;
39533     case IX86_BUILTIN_SCATTERDIV16SF:
39534       icode = CODE_FOR_avx512f_scatterdiv16sf;
39535       goto scatter_gen;
39536     case IX86_BUILTIN_SCATTERDIV8DF:
39537       icode = CODE_FOR_avx512f_scatterdiv8df;
39538       goto scatter_gen;
39539     case IX86_BUILTIN_SCATTERSIV16SI:
39540       icode = CODE_FOR_avx512f_scattersiv16si;
39541       goto scatter_gen;
39542     case IX86_BUILTIN_SCATTERSIV8DI:
39543       icode = CODE_FOR_avx512f_scattersiv8di;
39544       goto scatter_gen;
39545     case IX86_BUILTIN_SCATTERDIV16SI:
39546       icode = CODE_FOR_avx512f_scatterdiv16si;
39547       goto scatter_gen;
39548     case IX86_BUILTIN_SCATTERDIV8DI:
39549       icode = CODE_FOR_avx512f_scatterdiv8di;
39550       goto scatter_gen;
39551     case IX86_BUILTIN_SCATTERSIV8SF:
39552       icode = CODE_FOR_avx512vl_scattersiv8sf;
39553       goto scatter_gen;
39554     case IX86_BUILTIN_SCATTERSIV4SF:
39555       icode = CODE_FOR_avx512vl_scattersiv4sf;
39556       goto scatter_gen;
39557     case IX86_BUILTIN_SCATTERSIV4DF:
39558       icode = CODE_FOR_avx512vl_scattersiv4df;
39559       goto scatter_gen;
39560     case IX86_BUILTIN_SCATTERSIV2DF:
39561       icode = CODE_FOR_avx512vl_scattersiv2df;
39562       goto scatter_gen;
39563     case IX86_BUILTIN_SCATTERDIV8SF:
39564       icode = CODE_FOR_avx512vl_scatterdiv8sf;
39565       goto scatter_gen;
39566     case IX86_BUILTIN_SCATTERDIV4SF:
39567       icode = CODE_FOR_avx512vl_scatterdiv4sf;
39568       goto scatter_gen;
39569     case IX86_BUILTIN_SCATTERDIV4DF:
39570       icode = CODE_FOR_avx512vl_scatterdiv4df;
39571       goto scatter_gen;
39572     case IX86_BUILTIN_SCATTERDIV2DF:
39573       icode = CODE_FOR_avx512vl_scatterdiv2df;
39574       goto scatter_gen;
39575     case IX86_BUILTIN_SCATTERSIV8SI:
39576       icode = CODE_FOR_avx512vl_scattersiv8si;
39577       goto scatter_gen;
39578     case IX86_BUILTIN_SCATTERSIV4SI:
39579       icode = CODE_FOR_avx512vl_scattersiv4si;
39580       goto scatter_gen;
39581     case IX86_BUILTIN_SCATTERSIV4DI:
39582       icode = CODE_FOR_avx512vl_scattersiv4di;
39583       goto scatter_gen;
39584     case IX86_BUILTIN_SCATTERSIV2DI:
39585       icode = CODE_FOR_avx512vl_scattersiv2di;
39586       goto scatter_gen;
39587     case IX86_BUILTIN_SCATTERDIV8SI:
39588       icode = CODE_FOR_avx512vl_scatterdiv8si;
39589       goto scatter_gen;
39590     case IX86_BUILTIN_SCATTERDIV4SI:
39591       icode = CODE_FOR_avx512vl_scatterdiv4si;
39592       goto scatter_gen;
39593     case IX86_BUILTIN_SCATTERDIV4DI:
39594       icode = CODE_FOR_avx512vl_scatterdiv4di;
39595       goto scatter_gen;
39596     case IX86_BUILTIN_SCATTERDIV2DI:
39597       icode = CODE_FOR_avx512vl_scatterdiv2di;
39598       goto scatter_gen;
39599     case IX86_BUILTIN_GATHERPFDPD:
39600       icode = CODE_FOR_avx512pf_gatherpfv8sidf;
39601       goto vec_prefetch_gen;
39602     case IX86_BUILTIN_GATHERPFDPS:
39603       icode = CODE_FOR_avx512pf_gatherpfv16sisf;
39604       goto vec_prefetch_gen;
39605     case IX86_BUILTIN_GATHERPFQPD:
39606       icode = CODE_FOR_avx512pf_gatherpfv8didf;
39607       goto vec_prefetch_gen;
39608     case IX86_BUILTIN_GATHERPFQPS:
39609       icode = CODE_FOR_avx512pf_gatherpfv8disf;
39610       goto vec_prefetch_gen;
39611     case IX86_BUILTIN_SCATTERPFDPD:
39612       icode = CODE_FOR_avx512pf_scatterpfv8sidf;
39613       goto vec_prefetch_gen;
39614     case IX86_BUILTIN_SCATTERPFDPS:
39615       icode = CODE_FOR_avx512pf_scatterpfv16sisf;
39616       goto vec_prefetch_gen;
39617     case IX86_BUILTIN_SCATTERPFQPD:
39618       icode = CODE_FOR_avx512pf_scatterpfv8didf;
39619       goto vec_prefetch_gen;
39620     case IX86_BUILTIN_SCATTERPFQPS:
39621       icode = CODE_FOR_avx512pf_scatterpfv8disf;
39622       goto vec_prefetch_gen;
39623
39624     gather_gen:
39625       rtx half;
39626       rtx (*gen) (rtx, rtx);
39627
39628       arg0 = CALL_EXPR_ARG (exp, 0);
39629       arg1 = CALL_EXPR_ARG (exp, 1);
39630       arg2 = CALL_EXPR_ARG (exp, 2);
39631       arg3 = CALL_EXPR_ARG (exp, 3);
39632       arg4 = CALL_EXPR_ARG (exp, 4);
39633       op0 = expand_normal (arg0);
39634       op1 = expand_normal (arg1);
39635       op2 = expand_normal (arg2);
39636       op3 = expand_normal (arg3);
39637       op4 = expand_normal (arg4);
39638       /* Note the arg order is different from the operand order.  */
39639       mode0 = insn_data[icode].operand[1].mode;
39640       mode2 = insn_data[icode].operand[3].mode;
39641       mode3 = insn_data[icode].operand[4].mode;
39642       mode4 = insn_data[icode].operand[5].mode;
39643
39644       if (target == NULL_RTX
39645           || GET_MODE (target) != insn_data[icode].operand[0].mode
39646           || !insn_data[icode].operand[0].predicate (target,
39647                                                      GET_MODE (target)))
39648         subtarget = gen_reg_rtx (insn_data[icode].operand[0].mode);
39649       else
39650         subtarget = target;
39651
39652       switch (fcode)
39653         {
39654         case IX86_BUILTIN_GATHER3ALTSIV8DF:
39655         case IX86_BUILTIN_GATHER3ALTSIV8DI:
39656           half = gen_reg_rtx (V8SImode);
39657           if (!nonimmediate_operand (op2, V16SImode))
39658             op2 = copy_to_mode_reg (V16SImode, op2);
39659           emit_insn (gen_vec_extract_lo_v16si (half, op2));
39660           op2 = half;
39661           break;
39662         case IX86_BUILTIN_GATHER3ALTSIV4DF:
39663         case IX86_BUILTIN_GATHER3ALTSIV4DI:
39664         case IX86_BUILTIN_GATHERALTSIV4DF:
39665         case IX86_BUILTIN_GATHERALTSIV4DI:
39666           half = gen_reg_rtx (V4SImode);
39667           if (!nonimmediate_operand (op2, V8SImode))
39668             op2 = copy_to_mode_reg (V8SImode, op2);
39669           emit_insn (gen_vec_extract_lo_v8si (half, op2));
39670           op2 = half;
39671           break;
39672         case IX86_BUILTIN_GATHER3ALTDIV16SF:
39673         case IX86_BUILTIN_GATHER3ALTDIV16SI:
39674           half = gen_reg_rtx (mode0);
39675           if (mode0 == V8SFmode)
39676             gen = gen_vec_extract_lo_v16sf;
39677           else
39678             gen = gen_vec_extract_lo_v16si;
39679           if (!nonimmediate_operand (op0, GET_MODE (op0)))
39680             op0 = copy_to_mode_reg (GET_MODE (op0), op0);
39681           emit_insn (gen (half, op0));
39682           op0 = half;
39683           if (GET_MODE (op3) != VOIDmode)
39684             {
39685               if (!nonimmediate_operand (op3, GET_MODE (op3)))
39686                 op3 = copy_to_mode_reg (GET_MODE (op3), op3);
39687               emit_insn (gen (half, op3));
39688               op3 = half;
39689             }
39690           break;
39691         case IX86_BUILTIN_GATHER3ALTDIV8SF:
39692         case IX86_BUILTIN_GATHER3ALTDIV8SI:
39693         case IX86_BUILTIN_GATHERALTDIV8SF:
39694         case IX86_BUILTIN_GATHERALTDIV8SI:
39695           half = gen_reg_rtx (mode0);
39696           if (mode0 == V4SFmode)
39697             gen = gen_vec_extract_lo_v8sf;
39698           else
39699             gen = gen_vec_extract_lo_v8si;
39700           if (!nonimmediate_operand (op0, GET_MODE (op0)))
39701             op0 = copy_to_mode_reg (GET_MODE (op0), op0);
39702           emit_insn (gen (half, op0));
39703           op0 = half;
39704           if (GET_MODE (op3) != VOIDmode)
39705             {
39706               if (!nonimmediate_operand (op3, GET_MODE (op3)))
39707                 op3 = copy_to_mode_reg (GET_MODE (op3), op3);
39708               emit_insn (gen (half, op3));
39709               op3 = half;
39710             }
39711           break;
39712         default:
39713           break;
39714         }
39715
39716       /* Force memory operand only with base register here.  But we
39717          don't want to do it on memory operand for other builtin
39718          functions.  */
39719       op1 = ix86_zero_extend_to_Pmode (op1);
39720
39721       if (!insn_data[icode].operand[1].predicate (op0, mode0))
39722         op0 = copy_to_mode_reg (mode0, op0);
39723       if (!insn_data[icode].operand[2].predicate (op1, Pmode))
39724         op1 = copy_to_mode_reg (Pmode, op1);
39725       if (!insn_data[icode].operand[3].predicate (op2, mode2))
39726         op2 = copy_to_mode_reg (mode2, op2);
39727       if (GET_MODE (op3) == mode3 || GET_MODE (op3) == VOIDmode)
39728         {
39729           if (!insn_data[icode].operand[4].predicate (op3, mode3))
39730             op3 = copy_to_mode_reg (mode3, op3);
39731         }
39732       else
39733         {
39734           op3 = copy_to_reg (op3);
39735           op3 = simplify_gen_subreg (mode3, op3, GET_MODE (op3), 0);
39736         }
39737       if (!insn_data[icode].operand[5].predicate (op4, mode4))
39738         {
39739           error ("the last argument must be scale 1, 2, 4, 8");
39740           return const0_rtx;
39741         }
39742
39743       /* Optimize.  If mask is known to have all high bits set,
39744          replace op0 with pc_rtx to signal that the instruction
39745          overwrites the whole destination and doesn't use its
39746          previous contents.  */
39747       if (optimize)
39748         {
39749           if (TREE_CODE (arg3) == INTEGER_CST)
39750             {
39751               if (integer_all_onesp (arg3))
39752                 op0 = pc_rtx;
39753             }
39754           else if (TREE_CODE (arg3) == VECTOR_CST)
39755             {
39756               unsigned int negative = 0;
39757               for (i = 0; i < VECTOR_CST_NELTS (arg3); ++i)
39758                 {
39759                   tree cst = VECTOR_CST_ELT (arg3, i);
39760                   if (TREE_CODE (cst) == INTEGER_CST
39761                       && tree_int_cst_sign_bit (cst))
39762                     negative++;
39763                   else if (TREE_CODE (cst) == REAL_CST
39764                            && REAL_VALUE_NEGATIVE (TREE_REAL_CST (cst)))
39765                     negative++;
39766                 }
39767               if (negative == TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg3)))
39768                 op0 = pc_rtx;
39769             }
39770           else if (TREE_CODE (arg3) == SSA_NAME
39771                    && TREE_CODE (TREE_TYPE (arg3)) == VECTOR_TYPE)
39772             {
39773               /* Recognize also when mask is like:
39774                  __v2df src = _mm_setzero_pd ();
39775                  __v2df mask = _mm_cmpeq_pd (src, src);
39776                  or
39777                  __v8sf src = _mm256_setzero_ps ();
39778                  __v8sf mask = _mm256_cmp_ps (src, src, _CMP_EQ_OQ);
39779                  as that is a cheaper way to load all ones into
39780                  a register than having to load a constant from
39781                  memory.  */
39782               gimple def_stmt = SSA_NAME_DEF_STMT (arg3);
39783               if (is_gimple_call (def_stmt))
39784                 {
39785                   tree fndecl = gimple_call_fndecl (def_stmt);
39786                   if (fndecl
39787                       && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
39788                     switch ((unsigned int) DECL_FUNCTION_CODE (fndecl))
39789                       {
39790                       case IX86_BUILTIN_CMPPD:
39791                       case IX86_BUILTIN_CMPPS:
39792                       case IX86_BUILTIN_CMPPD256:
39793                       case IX86_BUILTIN_CMPPS256:
39794                         if (!integer_zerop (gimple_call_arg (def_stmt, 2)))
39795                           break;
39796                         /* FALLTHRU */
39797                       case IX86_BUILTIN_CMPEQPD:
39798                       case IX86_BUILTIN_CMPEQPS:
39799                         if (initializer_zerop (gimple_call_arg (def_stmt, 0))
39800                             && initializer_zerop (gimple_call_arg (def_stmt,
39801                                                                    1)))
39802                           op0 = pc_rtx;
39803                         break;
39804                       default:
39805                         break;
39806                       }
39807                 }
39808             }
39809         }
39810
39811       pat = GEN_FCN (icode) (subtarget, op0, op1, op2, op3, op4);
39812       if (! pat)
39813         return const0_rtx;
39814       emit_insn (pat);
39815
39816       switch (fcode)
39817         {
39818         case IX86_BUILTIN_GATHER3DIV16SF:
39819           if (target == NULL_RTX)
39820             target = gen_reg_rtx (V8SFmode);
39821           emit_insn (gen_vec_extract_lo_v16sf (target, subtarget));
39822           break;
39823         case IX86_BUILTIN_GATHER3DIV16SI:
39824           if (target == NULL_RTX)
39825             target = gen_reg_rtx (V8SImode);
39826           emit_insn (gen_vec_extract_lo_v16si (target, subtarget));
39827           break;
39828         case IX86_BUILTIN_GATHER3DIV8SF:
39829         case IX86_BUILTIN_GATHERDIV8SF:
39830           if (target == NULL_RTX)
39831             target = gen_reg_rtx (V4SFmode);
39832           emit_insn (gen_vec_extract_lo_v8sf (target, subtarget));
39833           break;
39834         case IX86_BUILTIN_GATHER3DIV8SI:
39835         case IX86_BUILTIN_GATHERDIV8SI:
39836           if (target == NULL_RTX)
39837             target = gen_reg_rtx (V4SImode);
39838           emit_insn (gen_vec_extract_lo_v8si (target, subtarget));
39839           break;
39840         default:
39841           target = subtarget;
39842           break;
39843         }
39844       return target;
39845
39846     scatter_gen:
39847       arg0 = CALL_EXPR_ARG (exp, 0);
39848       arg1 = CALL_EXPR_ARG (exp, 1);
39849       arg2 = CALL_EXPR_ARG (exp, 2);
39850       arg3 = CALL_EXPR_ARG (exp, 3);
39851       arg4 = CALL_EXPR_ARG (exp, 4);
39852       op0 = expand_normal (arg0);
39853       op1 = expand_normal (arg1);
39854       op2 = expand_normal (arg2);
39855       op3 = expand_normal (arg3);
39856       op4 = expand_normal (arg4);
39857       mode1 = insn_data[icode].operand[1].mode;
39858       mode2 = insn_data[icode].operand[2].mode;
39859       mode3 = insn_data[icode].operand[3].mode;
39860       mode4 = insn_data[icode].operand[4].mode;
39861
39862       /* Force memory operand only with base register here.  But we
39863          don't want to do it on memory operand for other builtin
39864          functions.  */
39865       op0 = force_reg (Pmode, convert_to_mode (Pmode, op0, 1));
39866
39867       if (!insn_data[icode].operand[0].predicate (op0, Pmode))
39868         op0 = copy_to_mode_reg (Pmode, op0);
39869
39870       if (GET_MODE (op1) == mode1 || GET_MODE (op1) == VOIDmode)
39871         {
39872           if (!insn_data[icode].operand[1].predicate (op1, mode1))
39873             op1 = copy_to_mode_reg (mode1, op1);
39874         }
39875       else
39876         {
39877           op1 = copy_to_reg (op1);
39878           op1 = simplify_gen_subreg (mode1, op1, GET_MODE (op1), 0);
39879         }
39880
39881       if (!insn_data[icode].operand[2].predicate (op2, mode2))
39882         op2 = copy_to_mode_reg (mode2, op2);
39883
39884       if (!insn_data[icode].operand[3].predicate (op3, mode3))
39885         op3 = copy_to_mode_reg (mode3, op3);
39886
39887       if (!insn_data[icode].operand[4].predicate (op4, mode4))
39888         {
39889           error ("the last argument must be scale 1, 2, 4, 8");
39890           return const0_rtx;
39891         }
39892
39893       pat = GEN_FCN (icode) (op0, op1, op2, op3, op4);
39894       if (! pat)
39895         return const0_rtx;
39896
39897       emit_insn (pat);
39898       return 0;
39899
39900     vec_prefetch_gen:
39901       arg0 = CALL_EXPR_ARG (exp, 0);
39902       arg1 = CALL_EXPR_ARG (exp, 1);
39903       arg2 = CALL_EXPR_ARG (exp, 2);
39904       arg3 = CALL_EXPR_ARG (exp, 3);
39905       arg4 = CALL_EXPR_ARG (exp, 4);
39906       op0 = expand_normal (arg0);
39907       op1 = expand_normal (arg1);
39908       op2 = expand_normal (arg2);
39909       op3 = expand_normal (arg3);
39910       op4 = expand_normal (arg4);
39911       mode0 = insn_data[icode].operand[0].mode;
39912       mode1 = insn_data[icode].operand[1].mode;
39913       mode3 = insn_data[icode].operand[3].mode;
39914       mode4 = insn_data[icode].operand[4].mode;
39915
39916       if (GET_MODE (op0) == mode0
39917           || (GET_MODE (op0) == VOIDmode && op0 != constm1_rtx))
39918         {
39919           if (!insn_data[icode].operand[0].predicate (op0, mode0))
39920             op0 = copy_to_mode_reg (mode0, op0);
39921         }
39922       else if (op0 != constm1_rtx)
39923         {
39924           op0 = copy_to_reg (op0);
39925           op0 = simplify_gen_subreg (mode0, op0, GET_MODE (op0), 0);
39926         }
39927
39928       if (!insn_data[icode].operand[1].predicate (op1, mode1))
39929         op1 = copy_to_mode_reg (mode1, op1);
39930
39931       /* Force memory operand only with base register here.  But we
39932          don't want to do it on memory operand for other builtin
39933          functions.  */
39934       op2 = force_reg (Pmode, convert_to_mode (Pmode, op2, 1));
39935
39936       if (!insn_data[icode].operand[2].predicate (op2, Pmode))
39937         op2 = copy_to_mode_reg (Pmode, op2);
39938
39939       if (!insn_data[icode].operand[3].predicate (op3, mode3))
39940         {
39941           error ("the forth argument must be scale 1, 2, 4, 8");
39942           return const0_rtx;
39943         }
39944
39945       if (!insn_data[icode].operand[4].predicate (op4, mode4))
39946         {
39947           error ("incorrect hint operand");
39948           return const0_rtx;
39949         }
39950
39951       pat = GEN_FCN (icode) (op0, op1, op2, op3, op4);
39952       if (! pat)
39953         return const0_rtx;
39954
39955       emit_insn (pat);
39956
39957       return 0;
39958
39959     case IX86_BUILTIN_XABORT:
39960       icode = CODE_FOR_xabort;
39961       arg0 = CALL_EXPR_ARG (exp, 0);
39962       op0 = expand_normal (arg0);
39963       mode0 = insn_data[icode].operand[0].mode;
39964       if (!insn_data[icode].operand[0].predicate (op0, mode0))
39965         {
39966           error ("the xabort's argument must be an 8-bit immediate");
39967           return const0_rtx;
39968         }
39969       emit_insn (gen_xabort (op0));
39970       return 0;
39971
39972     default:
39973       break;
39974     }
39975
39976   for (i = 0, d = bdesc_special_args;
39977        i < ARRAY_SIZE (bdesc_special_args);
39978        i++, d++)
39979     if (d->code == fcode)
39980       return ix86_expand_special_args_builtin (d, exp, target);
39981
39982   for (i = 0, d = bdesc_args;
39983        i < ARRAY_SIZE (bdesc_args);
39984        i++, d++)
39985     if (d->code == fcode)
39986       switch (fcode)
39987         {
39988         case IX86_BUILTIN_FABSQ:
39989         case IX86_BUILTIN_COPYSIGNQ:
39990           if (!TARGET_SSE)
39991             /* Emit a normal call if SSE isn't available.  */
39992             return expand_call (exp, target, ignore);
39993         default:
39994           return ix86_expand_args_builtin (d, exp, target);
39995         }
39996
39997   for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
39998     if (d->code == fcode)
39999       return ix86_expand_sse_comi (d, exp, target);
40000
40001   for (i = 0, d = bdesc_round_args; i < ARRAY_SIZE (bdesc_round_args); i++, d++)
40002     if (d->code == fcode)
40003       return ix86_expand_round_builtin (d, exp, target);
40004
40005   for (i = 0, d = bdesc_pcmpestr;
40006        i < ARRAY_SIZE (bdesc_pcmpestr);
40007        i++, d++)
40008     if (d->code == fcode)
40009       return ix86_expand_sse_pcmpestr (d, exp, target);
40010
40011   for (i = 0, d = bdesc_pcmpistr;
40012        i < ARRAY_SIZE (bdesc_pcmpistr);
40013        i++, d++)
40014     if (d->code == fcode)
40015       return ix86_expand_sse_pcmpistr (d, exp, target);
40016
40017   for (i = 0, d = bdesc_multi_arg; i < ARRAY_SIZE (bdesc_multi_arg); i++, d++)
40018     if (d->code == fcode)
40019       return ix86_expand_multi_arg_builtin (d->icode, exp, target,
40020                                             (enum ix86_builtin_func_type)
40021                                             d->flag, d->comparison);
40022
40023   gcc_unreachable ();
40024 }
40025
40026 /* This returns the target-specific builtin with code CODE if
40027    current_function_decl has visibility on this builtin, which is checked
40028    using isa flags.  Returns NULL_TREE otherwise.  */
40029
40030 static tree ix86_get_builtin (enum ix86_builtins code)
40031 {
40032   struct cl_target_option *opts;
40033   tree target_tree = NULL_TREE;
40034
40035   /* Determine the isa flags of current_function_decl.  */
40036
40037   if (current_function_decl)
40038     target_tree = DECL_FUNCTION_SPECIFIC_TARGET (current_function_decl);
40039
40040   if (target_tree == NULL)
40041     target_tree = target_option_default_node;
40042
40043   opts = TREE_TARGET_OPTION (target_tree);
40044
40045   if (ix86_builtins_isa[(int) code].isa & opts->x_ix86_isa_flags)
40046     return ix86_builtin_decl (code, true);
40047   else
40048     return NULL_TREE;
40049 }
40050
40051 /* Return function decl for target specific builtin
40052    for given MPX builtin passed i FCODE.  */
40053 static tree
40054 ix86_builtin_mpx_function (unsigned fcode)
40055 {
40056   switch (fcode)
40057     {
40058     case BUILT_IN_CHKP_BNDMK:
40059       return ix86_builtins[IX86_BUILTIN_BNDMK];
40060
40061     case BUILT_IN_CHKP_BNDSTX:
40062       return ix86_builtins[IX86_BUILTIN_BNDSTX];
40063
40064     case BUILT_IN_CHKP_BNDLDX:
40065       return ix86_builtins[IX86_BUILTIN_BNDLDX];
40066
40067     case BUILT_IN_CHKP_BNDCL:
40068       return ix86_builtins[IX86_BUILTIN_BNDCL];
40069
40070     case BUILT_IN_CHKP_BNDCU:
40071       return ix86_builtins[IX86_BUILTIN_BNDCU];
40072
40073     case BUILT_IN_CHKP_BNDRET:
40074       return ix86_builtins[IX86_BUILTIN_BNDRET];
40075
40076     case BUILT_IN_CHKP_INTERSECT:
40077       return ix86_builtins[IX86_BUILTIN_BNDINT];
40078
40079     case BUILT_IN_CHKP_NARROW:
40080       return ix86_builtins[IX86_BUILTIN_BNDNARROW];
40081
40082     case BUILT_IN_CHKP_SIZEOF:
40083       return ix86_builtins[IX86_BUILTIN_SIZEOF];
40084
40085     case BUILT_IN_CHKP_EXTRACT_LOWER:
40086       return ix86_builtins[IX86_BUILTIN_BNDLOWER];
40087
40088     case BUILT_IN_CHKP_EXTRACT_UPPER:
40089       return ix86_builtins[IX86_BUILTIN_BNDUPPER];
40090
40091     default:
40092       return NULL_TREE;
40093     }
40094
40095   gcc_unreachable ();
40096 }
40097
40098 /* Helper function for ix86_load_bounds and ix86_store_bounds.
40099
40100    Return an address to be used to load/store bounds for pointer
40101    passed in SLOT.
40102
40103    SLOT_NO is an integer constant holding number of a target
40104    dependent special slot to be used in case SLOT is not a memory.
40105
40106    SPECIAL_BASE is a pointer to be used as a base of fake address
40107    to access special slots in Bounds Table.  SPECIAL_BASE[-1],
40108    SPECIAL_BASE[-2] etc. will be used as fake pointer locations.  */
40109
40110 static rtx
40111 ix86_get_arg_address_for_bt (rtx slot, rtx slot_no, rtx special_base)
40112 {
40113   rtx addr = NULL;
40114
40115   /* NULL slot means we pass bounds for pointer not passed to the
40116      function at all.  Register slot means we pass pointer in a
40117      register.  In both these cases bounds are passed via Bounds
40118      Table.  Since we do not have actual pointer stored in memory,
40119      we have to use fake addresses to access Bounds Table.  We
40120      start with (special_base - sizeof (void*)) and decrease this
40121      address by pointer size to get addresses for other slots.  */
40122   if (!slot || REG_P (slot))
40123     {
40124       gcc_assert (CONST_INT_P (slot_no));
40125       addr = plus_constant (Pmode, special_base,
40126                             -(INTVAL (slot_no) + 1) * GET_MODE_SIZE (Pmode));
40127     }
40128   /* If pointer is passed in a memory then its address is used to
40129      access Bounds Table.  */
40130   else if (MEM_P (slot))
40131     {
40132       addr = XEXP (slot, 0);
40133       if (!register_operand (addr, Pmode))
40134         addr = copy_addr_to_reg (addr);
40135     }
40136   else
40137     gcc_unreachable ();
40138
40139   return addr;
40140 }
40141
40142 /* Expand pass uses this hook to load bounds for function parameter
40143    PTR passed in SLOT in case its bounds are not passed in a register.
40144
40145    If SLOT is a memory, then bounds are loaded as for regular pointer
40146    loaded from memory.  PTR may be NULL in case SLOT is a memory.
40147    In such case value of PTR (if required) may be loaded from SLOT.
40148
40149    If SLOT is NULL or a register then SLOT_NO is an integer constant
40150    holding number of the target dependent special slot which should be
40151    used to obtain bounds.
40152
40153    Return loaded bounds.  */
40154
40155 static rtx
40156 ix86_load_bounds (rtx slot, rtx ptr, rtx slot_no)
40157 {
40158   rtx reg = gen_reg_rtx (BNDmode);
40159   rtx addr;
40160
40161   /* Get address to be used to access Bounds Table.  Special slots start
40162      at the location of return address of the current function.  */
40163   addr = ix86_get_arg_address_for_bt (slot, slot_no, arg_pointer_rtx);
40164
40165   /* Load pointer value from a memory if we don't have it.  */
40166   if (!ptr)
40167     {
40168       gcc_assert (MEM_P (slot));
40169       ptr = copy_addr_to_reg (slot);
40170     }
40171
40172   emit_insn (BNDmode == BND64mode
40173              ? gen_bnd64_ldx (reg, addr, ptr)
40174              : gen_bnd32_ldx (reg, addr, ptr));
40175
40176   return reg;
40177 }
40178
40179 /* Expand pass uses this hook to store BOUNDS for call argument PTR
40180    passed in SLOT in case BOUNDS are not passed in a register.
40181
40182    If SLOT is a memory, then BOUNDS are stored as for regular pointer
40183    stored in memory.  PTR may be NULL in case SLOT is a memory.
40184    In such case value of PTR (if required) may be loaded from SLOT.
40185
40186    If SLOT is NULL or a register then SLOT_NO is an integer constant
40187    holding number of the target dependent special slot which should be
40188    used to store BOUNDS.  */
40189
40190 static void
40191 ix86_store_bounds (rtx ptr, rtx slot, rtx bounds, rtx slot_no)
40192 {
40193   rtx addr;
40194
40195   /* Get address to be used to access Bounds Table.  Special slots start
40196      at the location of return address of a called function.  */
40197   addr = ix86_get_arg_address_for_bt (slot, slot_no, stack_pointer_rtx);
40198
40199   /* Load pointer value from a memory if we don't have it.  */
40200   if (!ptr)
40201     {
40202       gcc_assert (MEM_P (slot));
40203       ptr = copy_addr_to_reg (slot);
40204     }
40205
40206   gcc_assert (POINTER_BOUNDS_MODE_P (GET_MODE (bounds)));
40207   if (!register_operand (bounds, BNDmode))
40208     bounds = copy_to_mode_reg (BNDmode, bounds);
40209
40210   emit_insn (BNDmode == BND64mode
40211              ? gen_bnd64_stx (addr, ptr, bounds)
40212              : gen_bnd32_stx (addr, ptr, bounds));
40213 }
40214
40215 /* Load and return bounds returned by function in SLOT.  */
40216
40217 static rtx
40218 ix86_load_returned_bounds (rtx slot)
40219 {
40220   rtx res;
40221
40222   gcc_assert (REG_P (slot));
40223   res = gen_reg_rtx (BNDmode);
40224   emit_move_insn (res, slot);
40225
40226   return res;
40227 }
40228
40229 /* Store BOUNDS returned by function into SLOT.  */
40230
40231 static void
40232 ix86_store_returned_bounds (rtx slot, rtx bounds)
40233 {
40234   gcc_assert (REG_P (slot));
40235   emit_move_insn (slot, bounds);
40236 }
40237
40238 /* Returns a function decl for a vectorized version of the builtin function
40239    with builtin function code FN and the result vector type TYPE, or NULL_TREE
40240    if it is not available.  */
40241
40242 static tree
40243 ix86_builtin_vectorized_function (tree fndecl, tree type_out,
40244                                   tree type_in)
40245 {
40246   machine_mode in_mode, out_mode;
40247   int in_n, out_n;
40248   enum built_in_function fn = DECL_FUNCTION_CODE (fndecl);
40249
40250   if (TREE_CODE (type_out) != VECTOR_TYPE
40251       || TREE_CODE (type_in) != VECTOR_TYPE
40252       || DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
40253     return NULL_TREE;
40254
40255   out_mode = TYPE_MODE (TREE_TYPE (type_out));
40256   out_n = TYPE_VECTOR_SUBPARTS (type_out);
40257   in_mode = TYPE_MODE (TREE_TYPE (type_in));
40258   in_n = TYPE_VECTOR_SUBPARTS (type_in);
40259
40260   switch (fn)
40261     {
40262     case BUILT_IN_SQRT:
40263       if (out_mode == DFmode && in_mode == DFmode)
40264         {
40265           if (out_n == 2 && in_n == 2)
40266             return ix86_get_builtin (IX86_BUILTIN_SQRTPD);
40267           else if (out_n == 4 && in_n == 4)
40268             return ix86_get_builtin (IX86_BUILTIN_SQRTPD256);
40269           else if (out_n == 8 && in_n == 8)
40270             return ix86_get_builtin (IX86_BUILTIN_SQRTPD512);
40271         }
40272       break;
40273
40274     case BUILT_IN_EXP2F:
40275       if (out_mode == SFmode && in_mode == SFmode)
40276         {
40277           if (out_n == 16 && in_n == 16)
40278             return ix86_get_builtin (IX86_BUILTIN_EXP2PS);
40279         }
40280       break;
40281
40282     case BUILT_IN_SQRTF:
40283       if (out_mode == SFmode && in_mode == SFmode)
40284         {
40285           if (out_n == 4 && in_n == 4)
40286             return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR);
40287           else if (out_n == 8 && in_n == 8)
40288             return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR256);
40289           else if (out_n == 16 && in_n == 16)
40290             return ix86_get_builtin (IX86_BUILTIN_SQRTPS_NR512);
40291         }
40292       break;
40293
40294     case BUILT_IN_IFLOOR:
40295     case BUILT_IN_LFLOOR:
40296     case BUILT_IN_LLFLOOR:
40297       /* The round insn does not trap on denormals.  */
40298       if (flag_trapping_math || !TARGET_ROUND)
40299         break;
40300
40301       if (out_mode == SImode && in_mode == DFmode)
40302         {
40303           if (out_n == 4 && in_n == 2)
40304             return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX);
40305           else if (out_n == 8 && in_n == 4)
40306             return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX256);
40307           else if (out_n == 16 && in_n == 8)
40308             return ix86_get_builtin (IX86_BUILTIN_FLOORPD_VEC_PACK_SFIX512);
40309         }
40310       break;
40311
40312     case BUILT_IN_IFLOORF:
40313     case BUILT_IN_LFLOORF:
40314     case BUILT_IN_LLFLOORF:
40315       /* The round insn does not trap on denormals.  */
40316       if (flag_trapping_math || !TARGET_ROUND)
40317         break;
40318
40319       if (out_mode == SImode && in_mode == SFmode)
40320         {
40321           if (out_n == 4 && in_n == 4)
40322             return ix86_get_builtin (IX86_BUILTIN_FLOORPS_SFIX);
40323           else if (out_n == 8 && in_n == 8)
40324             return ix86_get_builtin (IX86_BUILTIN_FLOORPS_SFIX256);
40325         }
40326       break;
40327
40328     case BUILT_IN_ICEIL:
40329     case BUILT_IN_LCEIL:
40330     case BUILT_IN_LLCEIL:
40331       /* The round insn does not trap on denormals.  */
40332       if (flag_trapping_math || !TARGET_ROUND)
40333         break;
40334
40335       if (out_mode == SImode && in_mode == DFmode)
40336         {
40337           if (out_n == 4 && in_n == 2)
40338             return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX);
40339           else if (out_n == 8 && in_n == 4)
40340             return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX256);
40341           else if (out_n == 16 && in_n == 8)
40342             return ix86_get_builtin (IX86_BUILTIN_CEILPD_VEC_PACK_SFIX512);
40343         }
40344       break;
40345
40346     case BUILT_IN_ICEILF:
40347     case BUILT_IN_LCEILF:
40348     case BUILT_IN_LLCEILF:
40349       /* The round insn does not trap on denormals.  */
40350       if (flag_trapping_math || !TARGET_ROUND)
40351         break;
40352
40353       if (out_mode == SImode && in_mode == SFmode)
40354         {
40355           if (out_n == 4 && in_n == 4)
40356             return ix86_get_builtin (IX86_BUILTIN_CEILPS_SFIX);
40357           else if (out_n == 8 && in_n == 8)
40358             return ix86_get_builtin (IX86_BUILTIN_CEILPS_SFIX256);
40359         }
40360       break;
40361
40362     case BUILT_IN_IRINT:
40363     case BUILT_IN_LRINT:
40364     case BUILT_IN_LLRINT:
40365       if (out_mode == SImode && in_mode == DFmode)
40366         {
40367           if (out_n == 4 && in_n == 2)
40368             return ix86_get_builtin (IX86_BUILTIN_VEC_PACK_SFIX);
40369           else if (out_n == 8 && in_n == 4)
40370             return ix86_get_builtin (IX86_BUILTIN_VEC_PACK_SFIX256);
40371         }
40372       break;
40373
40374     case BUILT_IN_IRINTF:
40375     case BUILT_IN_LRINTF:
40376     case BUILT_IN_LLRINTF:
40377       if (out_mode == SImode && in_mode == SFmode)
40378         {
40379           if (out_n == 4 && in_n == 4)
40380             return ix86_get_builtin (IX86_BUILTIN_CVTPS2DQ);
40381           else if (out_n == 8 && in_n == 8)
40382             return ix86_get_builtin (IX86_BUILTIN_CVTPS2DQ256);
40383         }
40384       break;
40385
40386     case BUILT_IN_IROUND:
40387     case BUILT_IN_LROUND:
40388     case BUILT_IN_LLROUND:
40389       /* The round insn does not trap on denormals.  */
40390       if (flag_trapping_math || !TARGET_ROUND)
40391         break;
40392
40393       if (out_mode == SImode && in_mode == DFmode)
40394         {
40395           if (out_n == 4 && in_n == 2)
40396             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX);
40397           else if (out_n == 8 && in_n == 4)
40398             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX256);
40399           else if (out_n == 16 && in_n == 8)
40400             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ_VEC_PACK_SFIX512);
40401         }
40402       break;
40403
40404     case BUILT_IN_IROUNDF:
40405     case BUILT_IN_LROUNDF:
40406     case BUILT_IN_LLROUNDF:
40407       /* The round insn does not trap on denormals.  */
40408       if (flag_trapping_math || !TARGET_ROUND)
40409         break;
40410
40411       if (out_mode == SImode && in_mode == SFmode)
40412         {
40413           if (out_n == 4 && in_n == 4)
40414             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ_SFIX);
40415           else if (out_n == 8 && in_n == 8)
40416             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ_SFIX256);
40417         }
40418       break;
40419
40420     case BUILT_IN_COPYSIGN:
40421       if (out_mode == DFmode && in_mode == DFmode)
40422         {
40423           if (out_n == 2 && in_n == 2)
40424             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD);
40425           else if (out_n == 4 && in_n == 4)
40426             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD256);
40427           else if (out_n == 8 && in_n == 8)
40428             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPD512);
40429         }
40430       break;
40431
40432     case BUILT_IN_COPYSIGNF:
40433       if (out_mode == SFmode && in_mode == SFmode)
40434         {
40435           if (out_n == 4 && in_n == 4)
40436             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS);
40437           else if (out_n == 8 && in_n == 8)
40438             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS256);
40439           else if (out_n == 16 && in_n == 16)
40440             return ix86_get_builtin (IX86_BUILTIN_CPYSGNPS512);
40441         }
40442       break;
40443
40444     case BUILT_IN_FLOOR:
40445       /* The round insn does not trap on denormals.  */
40446       if (flag_trapping_math || !TARGET_ROUND)
40447         break;
40448
40449       if (out_mode == DFmode && in_mode == DFmode)
40450         {
40451           if (out_n == 2 && in_n == 2)
40452             return ix86_get_builtin (IX86_BUILTIN_FLOORPD);
40453           else if (out_n == 4 && in_n == 4)
40454             return ix86_get_builtin (IX86_BUILTIN_FLOORPD256);
40455         }
40456       break;
40457
40458     case BUILT_IN_FLOORF:
40459       /* The round insn does not trap on denormals.  */
40460       if (flag_trapping_math || !TARGET_ROUND)
40461         break;
40462
40463       if (out_mode == SFmode && in_mode == SFmode)
40464         {
40465           if (out_n == 4 && in_n == 4)
40466             return ix86_get_builtin (IX86_BUILTIN_FLOORPS);
40467           else if (out_n == 8 && in_n == 8)
40468             return ix86_get_builtin (IX86_BUILTIN_FLOORPS256);
40469         }
40470       break;
40471
40472     case BUILT_IN_CEIL:
40473       /* The round insn does not trap on denormals.  */
40474       if (flag_trapping_math || !TARGET_ROUND)
40475         break;
40476
40477       if (out_mode == DFmode && in_mode == DFmode)
40478         {
40479           if (out_n == 2 && in_n == 2)
40480             return ix86_get_builtin (IX86_BUILTIN_CEILPD);
40481           else if (out_n == 4 && in_n == 4)
40482             return ix86_get_builtin (IX86_BUILTIN_CEILPD256);
40483         }
40484       break;
40485
40486     case BUILT_IN_CEILF:
40487       /* The round insn does not trap on denormals.  */
40488       if (flag_trapping_math || !TARGET_ROUND)
40489         break;
40490
40491       if (out_mode == SFmode && in_mode == SFmode)
40492         {
40493           if (out_n == 4 && in_n == 4)
40494             return ix86_get_builtin (IX86_BUILTIN_CEILPS);
40495           else if (out_n == 8 && in_n == 8)
40496             return ix86_get_builtin (IX86_BUILTIN_CEILPS256);
40497         }
40498       break;
40499
40500     case BUILT_IN_TRUNC:
40501       /* The round insn does not trap on denormals.  */
40502       if (flag_trapping_math || !TARGET_ROUND)
40503         break;
40504
40505       if (out_mode == DFmode && in_mode == DFmode)
40506         {
40507           if (out_n == 2 && in_n == 2)
40508             return ix86_get_builtin (IX86_BUILTIN_TRUNCPD);
40509           else if (out_n == 4 && in_n == 4)
40510             return ix86_get_builtin (IX86_BUILTIN_TRUNCPD256);
40511         }
40512       break;
40513
40514     case BUILT_IN_TRUNCF:
40515       /* The round insn does not trap on denormals.  */
40516       if (flag_trapping_math || !TARGET_ROUND)
40517         break;
40518
40519       if (out_mode == SFmode && in_mode == SFmode)
40520         {
40521           if (out_n == 4 && in_n == 4)
40522             return ix86_get_builtin (IX86_BUILTIN_TRUNCPS);
40523           else if (out_n == 8 && in_n == 8)
40524             return ix86_get_builtin (IX86_BUILTIN_TRUNCPS256);
40525         }
40526       break;
40527
40528     case BUILT_IN_RINT:
40529       /* The round insn does not trap on denormals.  */
40530       if (flag_trapping_math || !TARGET_ROUND)
40531         break;
40532
40533       if (out_mode == DFmode && in_mode == DFmode)
40534         {
40535           if (out_n == 2 && in_n == 2)
40536             return ix86_get_builtin (IX86_BUILTIN_RINTPD);
40537           else if (out_n == 4 && in_n == 4)
40538             return ix86_get_builtin (IX86_BUILTIN_RINTPD256);
40539         }
40540       break;
40541
40542     case BUILT_IN_RINTF:
40543       /* The round insn does not trap on denormals.  */
40544       if (flag_trapping_math || !TARGET_ROUND)
40545         break;
40546
40547       if (out_mode == SFmode && in_mode == SFmode)
40548         {
40549           if (out_n == 4 && in_n == 4)
40550             return ix86_get_builtin (IX86_BUILTIN_RINTPS);
40551           else if (out_n == 8 && in_n == 8)
40552             return ix86_get_builtin (IX86_BUILTIN_RINTPS256);
40553         }
40554       break;
40555
40556     case BUILT_IN_ROUND:
40557       /* The round insn does not trap on denormals.  */
40558       if (flag_trapping_math || !TARGET_ROUND)
40559         break;
40560
40561       if (out_mode == DFmode && in_mode == DFmode)
40562         {
40563           if (out_n == 2 && in_n == 2)
40564             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ);
40565           else if (out_n == 4 && in_n == 4)
40566             return ix86_get_builtin (IX86_BUILTIN_ROUNDPD_AZ256);
40567         }
40568       break;
40569
40570     case BUILT_IN_ROUNDF:
40571       /* The round insn does not trap on denormals.  */
40572       if (flag_trapping_math || !TARGET_ROUND)
40573         break;
40574
40575       if (out_mode == SFmode && in_mode == SFmode)
40576         {
40577           if (out_n == 4 && in_n == 4)
40578             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ);
40579           else if (out_n == 8 && in_n == 8)
40580             return ix86_get_builtin (IX86_BUILTIN_ROUNDPS_AZ256);
40581         }
40582       break;
40583
40584     case BUILT_IN_FMA:
40585       if (out_mode == DFmode && in_mode == DFmode)
40586         {
40587           if (out_n == 2 && in_n == 2)
40588             return ix86_get_builtin (IX86_BUILTIN_VFMADDPD);
40589           if (out_n == 4 && in_n == 4)
40590             return ix86_get_builtin (IX86_BUILTIN_VFMADDPD256);
40591         }
40592       break;
40593
40594     case BUILT_IN_FMAF:
40595       if (out_mode == SFmode && in_mode == SFmode)
40596         {
40597           if (out_n == 4 && in_n == 4)
40598             return ix86_get_builtin (IX86_BUILTIN_VFMADDPS);
40599           if (out_n == 8 && in_n == 8)
40600             return ix86_get_builtin (IX86_BUILTIN_VFMADDPS256);
40601         }
40602       break;
40603
40604     default:
40605       break;
40606     }
40607
40608   /* Dispatch to a handler for a vectorization library.  */
40609   if (ix86_veclib_handler)
40610     return ix86_veclib_handler ((enum built_in_function) fn, type_out,
40611                                 type_in);
40612
40613   return NULL_TREE;
40614 }
40615
40616 /* Handler for an SVML-style interface to
40617    a library with vectorized intrinsics.  */
40618
40619 static tree
40620 ix86_veclibabi_svml (enum built_in_function fn, tree type_out, tree type_in)
40621 {
40622   char name[20];
40623   tree fntype, new_fndecl, args;
40624   unsigned arity;
40625   const char *bname;
40626   machine_mode el_mode, in_mode;
40627   int n, in_n;
40628
40629   /* The SVML is suitable for unsafe math only.  */
40630   if (!flag_unsafe_math_optimizations)
40631     return NULL_TREE;
40632
40633   el_mode = TYPE_MODE (TREE_TYPE (type_out));
40634   n = TYPE_VECTOR_SUBPARTS (type_out);
40635   in_mode = TYPE_MODE (TREE_TYPE (type_in));
40636   in_n = TYPE_VECTOR_SUBPARTS (type_in);
40637   if (el_mode != in_mode
40638       || n != in_n)
40639     return NULL_TREE;
40640
40641   switch (fn)
40642     {
40643     case BUILT_IN_EXP:
40644     case BUILT_IN_LOG:
40645     case BUILT_IN_LOG10:
40646     case BUILT_IN_POW:
40647     case BUILT_IN_TANH:
40648     case BUILT_IN_TAN:
40649     case BUILT_IN_ATAN:
40650     case BUILT_IN_ATAN2:
40651     case BUILT_IN_ATANH:
40652     case BUILT_IN_CBRT:
40653     case BUILT_IN_SINH:
40654     case BUILT_IN_SIN:
40655     case BUILT_IN_ASINH:
40656     case BUILT_IN_ASIN:
40657     case BUILT_IN_COSH:
40658     case BUILT_IN_COS:
40659     case BUILT_IN_ACOSH:
40660     case BUILT_IN_ACOS:
40661       if (el_mode != DFmode || n != 2)
40662         return NULL_TREE;
40663       break;
40664
40665     case BUILT_IN_EXPF:
40666     case BUILT_IN_LOGF:
40667     case BUILT_IN_LOG10F:
40668     case BUILT_IN_POWF:
40669     case BUILT_IN_TANHF:
40670     case BUILT_IN_TANF:
40671     case BUILT_IN_ATANF:
40672     case BUILT_IN_ATAN2F:
40673     case BUILT_IN_ATANHF:
40674     case BUILT_IN_CBRTF:
40675     case BUILT_IN_SINHF:
40676     case BUILT_IN_SINF:
40677     case BUILT_IN_ASINHF:
40678     case BUILT_IN_ASINF:
40679     case BUILT_IN_COSHF:
40680     case BUILT_IN_COSF:
40681     case BUILT_IN_ACOSHF:
40682     case BUILT_IN_ACOSF:
40683       if (el_mode != SFmode || n != 4)
40684         return NULL_TREE;
40685       break;
40686
40687     default:
40688       return NULL_TREE;
40689     }
40690
40691   bname = IDENTIFIER_POINTER (DECL_NAME (builtin_decl_implicit (fn)));
40692
40693   if (fn == BUILT_IN_LOGF)
40694     strcpy (name, "vmlsLn4");
40695   else if (fn == BUILT_IN_LOG)
40696     strcpy (name, "vmldLn2");
40697   else if (n == 4)
40698     {
40699       sprintf (name, "vmls%s", bname+10);
40700       name[strlen (name)-1] = '4';
40701     }
40702   else
40703     sprintf (name, "vmld%s2", bname+10);
40704
40705   /* Convert to uppercase. */
40706   name[4] &= ~0x20;
40707
40708   arity = 0;
40709   for (args = DECL_ARGUMENTS (builtin_decl_implicit (fn));
40710        args;
40711        args = TREE_CHAIN (args))
40712     arity++;
40713
40714   if (arity == 1)
40715     fntype = build_function_type_list (type_out, type_in, NULL);
40716   else
40717     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
40718
40719   /* Build a function declaration for the vectorized function.  */
40720   new_fndecl = build_decl (BUILTINS_LOCATION,
40721                            FUNCTION_DECL, get_identifier (name), fntype);
40722   TREE_PUBLIC (new_fndecl) = 1;
40723   DECL_EXTERNAL (new_fndecl) = 1;
40724   DECL_IS_NOVOPS (new_fndecl) = 1;
40725   TREE_READONLY (new_fndecl) = 1;
40726
40727   return new_fndecl;
40728 }
40729
40730 /* Handler for an ACML-style interface to
40731    a library with vectorized intrinsics.  */
40732
40733 static tree
40734 ix86_veclibabi_acml (enum built_in_function fn, tree type_out, tree type_in)
40735 {
40736   char name[20] = "__vr.._";
40737   tree fntype, new_fndecl, args;
40738   unsigned arity;
40739   const char *bname;
40740   machine_mode el_mode, in_mode;
40741   int n, in_n;
40742
40743   /* The ACML is 64bits only and suitable for unsafe math only as
40744      it does not correctly support parts of IEEE with the required
40745      precision such as denormals.  */
40746   if (!TARGET_64BIT
40747       || !flag_unsafe_math_optimizations)
40748     return NULL_TREE;
40749
40750   el_mode = TYPE_MODE (TREE_TYPE (type_out));
40751   n = TYPE_VECTOR_SUBPARTS (type_out);
40752   in_mode = TYPE_MODE (TREE_TYPE (type_in));
40753   in_n = TYPE_VECTOR_SUBPARTS (type_in);
40754   if (el_mode != in_mode
40755       || n != in_n)
40756     return NULL_TREE;
40757
40758   switch (fn)
40759     {
40760     case BUILT_IN_SIN:
40761     case BUILT_IN_COS:
40762     case BUILT_IN_EXP:
40763     case BUILT_IN_LOG:
40764     case BUILT_IN_LOG2:
40765     case BUILT_IN_LOG10:
40766       name[4] = 'd';
40767       name[5] = '2';
40768       if (el_mode != DFmode
40769           || n != 2)
40770         return NULL_TREE;
40771       break;
40772
40773     case BUILT_IN_SINF:
40774     case BUILT_IN_COSF:
40775     case BUILT_IN_EXPF:
40776     case BUILT_IN_POWF:
40777     case BUILT_IN_LOGF:
40778     case BUILT_IN_LOG2F:
40779     case BUILT_IN_LOG10F:
40780       name[4] = 's';
40781       name[5] = '4';
40782       if (el_mode != SFmode
40783           || n != 4)
40784         return NULL_TREE;
40785       break;
40786
40787     default:
40788       return NULL_TREE;
40789     }
40790
40791   bname = IDENTIFIER_POINTER (DECL_NAME (builtin_decl_implicit (fn)));
40792   sprintf (name + 7, "%s", bname+10);
40793
40794   arity = 0;
40795   for (args = DECL_ARGUMENTS (builtin_decl_implicit (fn));
40796        args;
40797        args = TREE_CHAIN (args))
40798     arity++;
40799
40800   if (arity == 1)
40801     fntype = build_function_type_list (type_out, type_in, NULL);
40802   else
40803     fntype = build_function_type_list (type_out, type_in, type_in, NULL);
40804
40805   /* Build a function declaration for the vectorized function.  */
40806   new_fndecl = build_decl (BUILTINS_LOCATION,
40807                            FUNCTION_DECL, get_identifier (name), fntype);
40808   TREE_PUBLIC (new_fndecl) = 1;
40809   DECL_EXTERNAL (new_fndecl) = 1;
40810   DECL_IS_NOVOPS (new_fndecl) = 1;
40811   TREE_READONLY (new_fndecl) = 1;
40812
40813   return new_fndecl;
40814 }
40815
40816 /* Returns a decl of a function that implements gather load with
40817    memory type MEM_VECTYPE and index type INDEX_VECTYPE and SCALE.
40818    Return NULL_TREE if it is not available.  */
40819
40820 static tree
40821 ix86_vectorize_builtin_gather (const_tree mem_vectype,
40822                                const_tree index_type, int scale)
40823 {
40824   bool si;
40825   enum ix86_builtins code;
40826
40827   if (! TARGET_AVX2)
40828     return NULL_TREE;
40829
40830   if ((TREE_CODE (index_type) != INTEGER_TYPE
40831        && !POINTER_TYPE_P (index_type))
40832       || (TYPE_MODE (index_type) != SImode
40833           && TYPE_MODE (index_type) != DImode))
40834     return NULL_TREE;
40835
40836   if (TYPE_PRECISION (index_type) > POINTER_SIZE)
40837     return NULL_TREE;
40838
40839   /* v*gather* insn sign extends index to pointer mode.  */
40840   if (TYPE_PRECISION (index_type) < POINTER_SIZE
40841       && TYPE_UNSIGNED (index_type))
40842     return NULL_TREE;
40843
40844   if (scale <= 0
40845       || scale > 8
40846       || (scale & (scale - 1)) != 0)
40847     return NULL_TREE;
40848
40849   si = TYPE_MODE (index_type) == SImode;
40850   switch (TYPE_MODE (mem_vectype))
40851     {
40852     case V2DFmode:
40853       if (TARGET_AVX512VL)
40854         code = si ? IX86_BUILTIN_GATHER3SIV2DF : IX86_BUILTIN_GATHER3DIV2DF;
40855       else
40856         code = si ? IX86_BUILTIN_GATHERSIV2DF : IX86_BUILTIN_GATHERDIV2DF;
40857       break;
40858     case V4DFmode:
40859       if (TARGET_AVX512VL)
40860         code = si ? IX86_BUILTIN_GATHER3ALTSIV4DF : IX86_BUILTIN_GATHER3DIV4DF;
40861       else
40862         code = si ? IX86_BUILTIN_GATHERALTSIV4DF : IX86_BUILTIN_GATHERDIV4DF;
40863       break;
40864     case V2DImode:
40865       if (TARGET_AVX512VL)
40866         code = si ? IX86_BUILTIN_GATHER3SIV2DI : IX86_BUILTIN_GATHER3DIV2DI;
40867       else
40868         code = si ? IX86_BUILTIN_GATHERSIV2DI : IX86_BUILTIN_GATHERDIV2DI;
40869       break;
40870     case V4DImode:
40871       if (TARGET_AVX512VL)
40872         code = si ? IX86_BUILTIN_GATHER3ALTSIV4DI : IX86_BUILTIN_GATHER3DIV4DI;
40873       else
40874         code = si ? IX86_BUILTIN_GATHERALTSIV4DI : IX86_BUILTIN_GATHERDIV4DI;
40875       break;
40876     case V4SFmode:
40877       if (TARGET_AVX512VL)
40878         code = si ? IX86_BUILTIN_GATHER3SIV4SF : IX86_BUILTIN_GATHER3DIV4SF;
40879       else
40880         code = si ? IX86_BUILTIN_GATHERSIV4SF : IX86_BUILTIN_GATHERDIV4SF;
40881       break;
40882     case V8SFmode:
40883       if (TARGET_AVX512VL)
40884         code = si ? IX86_BUILTIN_GATHER3SIV8SF : IX86_BUILTIN_GATHER3ALTDIV8SF;
40885       else
40886         code = si ? IX86_BUILTIN_GATHERSIV8SF : IX86_BUILTIN_GATHERALTDIV8SF;
40887       break;
40888     case V4SImode:
40889       if (TARGET_AVX512VL)
40890         code = si ? IX86_BUILTIN_GATHER3SIV4SI : IX86_BUILTIN_GATHER3DIV4SI;
40891       else
40892         code = si ? IX86_BUILTIN_GATHERSIV4SI : IX86_BUILTIN_GATHERDIV4SI;
40893       break;
40894     case V8SImode:
40895       if (TARGET_AVX512VL)
40896         code = si ? IX86_BUILTIN_GATHER3SIV8SI : IX86_BUILTIN_GATHER3ALTDIV8SI;
40897       else
40898         code = si ? IX86_BUILTIN_GATHERSIV8SI : IX86_BUILTIN_GATHERALTDIV8SI;
40899       break;
40900     case V8DFmode:
40901       if (TARGET_AVX512F)
40902         code = si ? IX86_BUILTIN_GATHER3ALTSIV8DF : IX86_BUILTIN_GATHER3DIV8DF;
40903       else
40904         return NULL_TREE;
40905       break;
40906     case V8DImode:
40907       if (TARGET_AVX512F)
40908         code = si ? IX86_BUILTIN_GATHER3ALTSIV8DI : IX86_BUILTIN_GATHER3DIV8DI;
40909       else
40910         return NULL_TREE;
40911       break;
40912     case V16SFmode:
40913       if (TARGET_AVX512F)
40914         code = si ? IX86_BUILTIN_GATHER3SIV16SF : IX86_BUILTIN_GATHER3ALTDIV16SF;
40915       else
40916         return NULL_TREE;
40917       break;
40918     case V16SImode:
40919       if (TARGET_AVX512F)
40920         code = si ? IX86_BUILTIN_GATHER3SIV16SI : IX86_BUILTIN_GATHER3ALTDIV16SI;
40921       else
40922         return NULL_TREE;
40923       break;
40924     default:
40925       return NULL_TREE;
40926     }
40927
40928   return ix86_get_builtin (code);
40929 }
40930
40931 /* Returns a code for a target-specific builtin that implements
40932    reciprocal of the function, or NULL_TREE if not available.  */
40933
40934 static tree
40935 ix86_builtin_reciprocal (unsigned int fn, bool md_fn, bool)
40936 {
40937   if (! (TARGET_SSE_MATH && !optimize_insn_for_size_p ()
40938          && flag_finite_math_only && !flag_trapping_math
40939          && flag_unsafe_math_optimizations))
40940     return NULL_TREE;
40941
40942   if (md_fn)
40943     /* Machine dependent builtins.  */
40944     switch (fn)
40945       {
40946         /* Vectorized version of sqrt to rsqrt conversion.  */
40947       case IX86_BUILTIN_SQRTPS_NR:
40948         return ix86_get_builtin (IX86_BUILTIN_RSQRTPS_NR);
40949
40950       case IX86_BUILTIN_SQRTPS_NR256:
40951         return ix86_get_builtin (IX86_BUILTIN_RSQRTPS_NR256);
40952
40953       default:
40954         return NULL_TREE;
40955       }
40956   else
40957     /* Normal builtins.  */
40958     switch (fn)
40959       {
40960         /* Sqrt to rsqrt conversion.  */
40961       case BUILT_IN_SQRTF:
40962         return ix86_get_builtin (IX86_BUILTIN_RSQRTF);
40963
40964       default:
40965         return NULL_TREE;
40966       }
40967 }
40968 \f
40969 /* Helper for avx_vpermilps256_operand et al.  This is also used by
40970    the expansion functions to turn the parallel back into a mask.
40971    The return value is 0 for no match and the imm8+1 for a match.  */
40972
40973 int
40974 avx_vpermilp_parallel (rtx par, machine_mode mode)
40975 {
40976   unsigned i, nelt = GET_MODE_NUNITS (mode);
40977   unsigned mask = 0;
40978   unsigned char ipar[16] = {};  /* Silence -Wuninitialized warning.  */
40979
40980   if (XVECLEN (par, 0) != (int) nelt)
40981     return 0;
40982
40983   /* Validate that all of the elements are constants, and not totally
40984      out of range.  Copy the data into an integral array to make the
40985      subsequent checks easier.  */
40986   for (i = 0; i < nelt; ++i)
40987     {
40988       rtx er = XVECEXP (par, 0, i);
40989       unsigned HOST_WIDE_INT ei;
40990
40991       if (!CONST_INT_P (er))
40992         return 0;
40993       ei = INTVAL (er);
40994       if (ei >= nelt)
40995         return 0;
40996       ipar[i] = ei;
40997     }
40998
40999   switch (mode)
41000     {
41001     case V8DFmode:
41002       /* In the 512-bit DFmode case, we can only move elements within
41003          a 128-bit lane.  First fill the second part of the mask,
41004          then fallthru.  */
41005       for (i = 4; i < 6; ++i)
41006         {
41007           if (ipar[i] < 4 || ipar[i] >= 6)
41008             return 0;
41009           mask |= (ipar[i] - 4) << i;
41010         }
41011       for (i = 6; i < 8; ++i)
41012         {
41013           if (ipar[i] < 6)
41014             return 0;
41015           mask |= (ipar[i] - 6) << i;
41016         }
41017       /* FALLTHRU */
41018
41019     case V4DFmode:
41020       /* In the 256-bit DFmode case, we can only move elements within
41021          a 128-bit lane.  */
41022       for (i = 0; i < 2; ++i)
41023         {
41024           if (ipar[i] >= 2)
41025             return 0;
41026           mask |= ipar[i] << i;
41027         }
41028       for (i = 2; i < 4; ++i)
41029         {
41030           if (ipar[i] < 2)
41031             return 0;
41032           mask |= (ipar[i] - 2) << i;
41033         }
41034       break;
41035
41036     case V16SFmode:
41037       /* In 512 bit SFmode case, permutation in the upper 256 bits
41038          must mirror the permutation in the lower 256-bits.  */
41039       for (i = 0; i < 8; ++i)
41040         if (ipar[i] + 8 != ipar[i + 8])
41041           return 0;
41042       /* FALLTHRU */
41043
41044     case V8SFmode:
41045       /* In 256 bit SFmode case, we have full freedom of
41046          movement within the low 128-bit lane, but the high 128-bit
41047          lane must mirror the exact same pattern.  */
41048       for (i = 0; i < 4; ++i)
41049         if (ipar[i] + 4 != ipar[i + 4])
41050           return 0;
41051       nelt = 4;
41052       /* FALLTHRU */
41053
41054     case V2DFmode:
41055     case V4SFmode:
41056       /* In the 128-bit case, we've full freedom in the placement of
41057          the elements from the source operand.  */
41058       for (i = 0; i < nelt; ++i)
41059         mask |= ipar[i] << (i * (nelt / 2));
41060       break;
41061
41062     default:
41063       gcc_unreachable ();
41064     }
41065
41066   /* Make sure success has a non-zero value by adding one.  */
41067   return mask + 1;
41068 }
41069
41070 /* Helper for avx_vperm2f128_v4df_operand et al.  This is also used by
41071    the expansion functions to turn the parallel back into a mask.
41072    The return value is 0 for no match and the imm8+1 for a match.  */
41073
41074 int
41075 avx_vperm2f128_parallel (rtx par, machine_mode mode)
41076 {
41077   unsigned i, nelt = GET_MODE_NUNITS (mode), nelt2 = nelt / 2;
41078   unsigned mask = 0;
41079   unsigned char ipar[8] = {};  /* Silence -Wuninitialized warning.  */
41080
41081   if (XVECLEN (par, 0) != (int) nelt)
41082     return 0;
41083
41084   /* Validate that all of the elements are constants, and not totally
41085      out of range.  Copy the data into an integral array to make the
41086      subsequent checks easier.  */
41087   for (i = 0; i < nelt; ++i)
41088     {
41089       rtx er = XVECEXP (par, 0, i);
41090       unsigned HOST_WIDE_INT ei;
41091
41092       if (!CONST_INT_P (er))
41093         return 0;
41094       ei = INTVAL (er);
41095       if (ei >= 2 * nelt)
41096         return 0;
41097       ipar[i] = ei;
41098     }
41099
41100   /* Validate that the halves of the permute are halves.  */
41101   for (i = 0; i < nelt2 - 1; ++i)
41102     if (ipar[i] + 1 != ipar[i + 1])
41103       return 0;
41104   for (i = nelt2; i < nelt - 1; ++i)
41105     if (ipar[i] + 1 != ipar[i + 1])
41106       return 0;
41107
41108   /* Reconstruct the mask.  */
41109   for (i = 0; i < 2; ++i)
41110     {
41111       unsigned e = ipar[i * nelt2];
41112       if (e % nelt2)
41113         return 0;
41114       e /= nelt2;
41115       mask |= e << (i * 4);
41116     }
41117
41118   /* Make sure success has a non-zero value by adding one.  */
41119   return mask + 1;
41120 }
41121 \f
41122 /* Return a register priority for hard reg REGNO.  */
41123 static int
41124 ix86_register_priority (int hard_regno)
41125 {
41126   /* ebp and r13 as the base always wants a displacement, r12 as the
41127      base always wants an index.  So discourage their usage in an
41128      address.  */
41129   if (hard_regno == R12_REG || hard_regno == R13_REG)
41130     return 0;
41131   if (hard_regno == BP_REG)
41132     return 1;
41133   /* New x86-64 int registers result in bigger code size.  Discourage
41134      them.  */
41135   if (FIRST_REX_INT_REG <= hard_regno && hard_regno <= LAST_REX_INT_REG)
41136     return 2;
41137   /* New x86-64 SSE registers result in bigger code size.  Discourage
41138      them.  */
41139   if (FIRST_REX_SSE_REG <= hard_regno && hard_regno <= LAST_REX_SSE_REG)
41140     return 2;
41141   /* Usage of AX register results in smaller code.  Prefer it.  */
41142   if (hard_regno == 0)
41143     return 4;
41144   return 3;
41145 }
41146
41147 /* Implement TARGET_PREFERRED_RELOAD_CLASS.
41148
41149    Put float CONST_DOUBLE in the constant pool instead of fp regs.
41150    QImode must go into class Q_REGS.
41151    Narrow ALL_REGS to GENERAL_REGS.  This supports allowing movsf and
41152    movdf to do mem-to-mem moves through integer regs.  */
41153
41154 static reg_class_t
41155 ix86_preferred_reload_class (rtx x, reg_class_t regclass)
41156 {
41157   machine_mode mode = GET_MODE (x);
41158
41159   /* We're only allowed to return a subclass of CLASS.  Many of the
41160      following checks fail for NO_REGS, so eliminate that early.  */
41161   if (regclass == NO_REGS)
41162     return NO_REGS;
41163
41164   /* All classes can load zeros.  */
41165   if (x == CONST0_RTX (mode))
41166     return regclass;
41167
41168   /* Force constants into memory if we are loading a (nonzero) constant into
41169      an MMX, SSE or MASK register.  This is because there are no MMX/SSE/MASK
41170      instructions to load from a constant.  */
41171   if (CONSTANT_P (x)
41172       && (MAYBE_MMX_CLASS_P (regclass)
41173           || MAYBE_SSE_CLASS_P (regclass)
41174           || MAYBE_MASK_CLASS_P (regclass)))
41175     return NO_REGS;
41176
41177   /* Prefer SSE regs only, if we can use them for math.  */
41178   if (TARGET_SSE_MATH && !TARGET_MIX_SSE_I387 && SSE_FLOAT_MODE_P (mode))
41179     return SSE_CLASS_P (regclass) ? regclass : NO_REGS;
41180
41181   /* Floating-point constants need more complex checks.  */
41182   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
41183     {
41184       /* General regs can load everything.  */
41185       if (reg_class_subset_p (regclass, GENERAL_REGS))
41186         return regclass;
41187
41188       /* Floats can load 0 and 1 plus some others.  Note that we eliminated
41189          zero above.  We only want to wind up preferring 80387 registers if
41190          we plan on doing computation with them.  */
41191       if (TARGET_80387
41192           && standard_80387_constant_p (x) > 0)
41193         {
41194           /* Limit class to non-sse.  */
41195           if (regclass == FLOAT_SSE_REGS)
41196             return FLOAT_REGS;
41197           if (regclass == FP_TOP_SSE_REGS)
41198             return FP_TOP_REG;
41199           if (regclass == FP_SECOND_SSE_REGS)
41200             return FP_SECOND_REG;
41201           if (regclass == FLOAT_INT_REGS || regclass == FLOAT_REGS)
41202             return regclass;
41203         }
41204
41205       return NO_REGS;
41206     }
41207
41208   /* Generally when we see PLUS here, it's the function invariant
41209      (plus soft-fp const_int).  Which can only be computed into general
41210      regs.  */
41211   if (GET_CODE (x) == PLUS)
41212     return reg_class_subset_p (regclass, GENERAL_REGS) ? regclass : NO_REGS;
41213
41214   /* QImode constants are easy to load, but non-constant QImode data
41215      must go into Q_REGS.  */
41216   if (GET_MODE (x) == QImode && !CONSTANT_P (x))
41217     {
41218       if (reg_class_subset_p (regclass, Q_REGS))
41219         return regclass;
41220       if (reg_class_subset_p (Q_REGS, regclass))
41221         return Q_REGS;
41222       return NO_REGS;
41223     }
41224
41225   return regclass;
41226 }
41227
41228 /* Discourage putting floating-point values in SSE registers unless
41229    SSE math is being used, and likewise for the 387 registers.  */
41230 static reg_class_t
41231 ix86_preferred_output_reload_class (rtx x, reg_class_t regclass)
41232 {
41233   machine_mode mode = GET_MODE (x);
41234
41235   /* Restrict the output reload class to the register bank that we are doing
41236      math on.  If we would like not to return a subset of CLASS, reject this
41237      alternative: if reload cannot do this, it will still use its choice.  */
41238   mode = GET_MODE (x);
41239   if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (mode))
41240     return MAYBE_SSE_CLASS_P (regclass) ? ALL_SSE_REGS : NO_REGS;
41241
41242   if (X87_FLOAT_MODE_P (mode))
41243     {
41244       if (regclass == FP_TOP_SSE_REGS)
41245         return FP_TOP_REG;
41246       else if (regclass == FP_SECOND_SSE_REGS)
41247         return FP_SECOND_REG;
41248       else
41249         return FLOAT_CLASS_P (regclass) ? regclass : NO_REGS;
41250     }
41251
41252   return regclass;
41253 }
41254
41255 static reg_class_t
41256 ix86_secondary_reload (bool in_p, rtx x, reg_class_t rclass,
41257                        machine_mode mode, secondary_reload_info *sri)
41258 {
41259   /* Double-word spills from general registers to non-offsettable memory
41260      references (zero-extended addresses) require special handling.  */
41261   if (TARGET_64BIT
41262       && MEM_P (x)
41263       && GET_MODE_SIZE (mode) > UNITS_PER_WORD
41264       && INTEGER_CLASS_P (rclass)
41265       && !offsettable_memref_p (x))
41266     {
41267       sri->icode = (in_p
41268                     ? CODE_FOR_reload_noff_load
41269                     : CODE_FOR_reload_noff_store);
41270       /* Add the cost of moving address to a temporary.  */
41271       sri->extra_cost = 1;
41272
41273       return NO_REGS;
41274     }
41275
41276   /* QImode spills from non-QI registers require
41277      intermediate register on 32bit targets.  */
41278   if (mode == QImode
41279       && (MAYBE_MASK_CLASS_P (rclass)
41280           || (!TARGET_64BIT && !in_p
41281               && INTEGER_CLASS_P (rclass)
41282               && MAYBE_NON_Q_CLASS_P (rclass))))
41283     {
41284       int regno;
41285
41286       if (REG_P (x))
41287         regno = REGNO (x);
41288       else
41289         regno = -1;
41290
41291       if (regno >= FIRST_PSEUDO_REGISTER || GET_CODE (x) == SUBREG)
41292         regno = true_regnum (x);
41293
41294       /* Return Q_REGS if the operand is in memory.  */
41295       if (regno == -1)
41296         return Q_REGS;
41297     }
41298
41299   /* This condition handles corner case where an expression involving
41300      pointers gets vectorized.  We're trying to use the address of a
41301      stack slot as a vector initializer.
41302
41303      (set (reg:V2DI 74 [ vect_cst_.2 ])
41304           (vec_duplicate:V2DI (reg/f:DI 20 frame)))
41305
41306      Eventually frame gets turned into sp+offset like this:
41307
41308      (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41309           (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
41310                                        (const_int 392 [0x188]))))
41311
41312      That later gets turned into:
41313
41314      (set (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41315           (vec_duplicate:V2DI (plus:DI (reg/f:DI 7 sp)
41316             (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))))
41317
41318      We'll have the following reload recorded:
41319
41320      Reload 0: reload_in (DI) =
41321            (plus:DI (reg/f:DI 7 sp)
41322             (mem/u/c/i:DI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S8 A64]))
41323      reload_out (V2DI) = (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41324      SSE_REGS, RELOAD_OTHER (opnum = 0), can't combine
41325      reload_in_reg: (plus:DI (reg/f:DI 7 sp) (const_int 392 [0x188]))
41326      reload_out_reg: (reg:V2DI 21 xmm0 [orig:74 vect_cst_.2 ] [74])
41327      reload_reg_rtx: (reg:V2DI 22 xmm1)
41328
41329      Which isn't going to work since SSE instructions can't handle scalar
41330      additions.  Returning GENERAL_REGS forces the addition into integer
41331      register and reload can handle subsequent reloads without problems.  */
41332
41333   if (in_p && GET_CODE (x) == PLUS
41334       && SSE_CLASS_P (rclass)
41335       && SCALAR_INT_MODE_P (mode))
41336     return GENERAL_REGS;
41337
41338   return NO_REGS;
41339 }
41340
41341 /* Implement TARGET_CLASS_LIKELY_SPILLED_P.  */
41342
41343 static bool
41344 ix86_class_likely_spilled_p (reg_class_t rclass)
41345 {
41346   switch (rclass)
41347     {
41348       case AREG:
41349       case DREG:
41350       case CREG:
41351       case BREG:
41352       case AD_REGS:
41353       case SIREG:
41354       case DIREG:
41355       case SSE_FIRST_REG:
41356       case FP_TOP_REG:
41357       case FP_SECOND_REG:
41358       case BND_REGS:
41359         return true;
41360
41361       default:
41362         break;
41363     }
41364
41365   return false;
41366 }
41367
41368 /* If we are copying between general and FP registers, we need a memory
41369    location. The same is true for SSE and MMX registers.
41370
41371    To optimize register_move_cost performance, allow inline variant.
41372
41373    The macro can't work reliably when one of the CLASSES is class containing
41374    registers from multiple units (SSE, MMX, integer).  We avoid this by never
41375    combining those units in single alternative in the machine description.
41376    Ensure that this constraint holds to avoid unexpected surprises.
41377
41378    When STRICT is false, we are being called from REGISTER_MOVE_COST, so do not
41379    enforce these sanity checks.  */
41380
41381 static inline bool
41382 inline_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
41383                                 machine_mode mode, int strict)
41384 {
41385   if (lra_in_progress && (class1 == NO_REGS || class2 == NO_REGS))
41386     return false;
41387   if (MAYBE_FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class1)
41388       || MAYBE_FLOAT_CLASS_P (class2) != FLOAT_CLASS_P (class2)
41389       || MAYBE_SSE_CLASS_P (class1) != SSE_CLASS_P (class1)
41390       || MAYBE_SSE_CLASS_P (class2) != SSE_CLASS_P (class2)
41391       || MAYBE_MMX_CLASS_P (class1) != MMX_CLASS_P (class1)
41392       || MAYBE_MMX_CLASS_P (class2) != MMX_CLASS_P (class2))
41393     {
41394       gcc_assert (!strict || lra_in_progress);
41395       return true;
41396     }
41397
41398   if (FLOAT_CLASS_P (class1) != FLOAT_CLASS_P (class2))
41399     return true;
41400
41401   /* Between mask and general, we have moves no larger than word size.  */
41402   if ((MAYBE_MASK_CLASS_P (class1) != MAYBE_MASK_CLASS_P (class2))
41403       && (GET_MODE_SIZE (mode) > UNITS_PER_WORD))
41404   return true;
41405
41406   /* ??? This is a lie.  We do have moves between mmx/general, and for
41407      mmx/sse2.  But by saying we need secondary memory we discourage the
41408      register allocator from using the mmx registers unless needed.  */
41409   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2))
41410     return true;
41411
41412   if (SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
41413     {
41414       /* SSE1 doesn't have any direct moves from other classes.  */
41415       if (!TARGET_SSE2)
41416         return true;
41417
41418       /* If the target says that inter-unit moves are more expensive
41419          than moving through memory, then don't generate them.  */
41420       if ((SSE_CLASS_P (class1) && !TARGET_INTER_UNIT_MOVES_FROM_VEC)
41421           || (SSE_CLASS_P (class2) && !TARGET_INTER_UNIT_MOVES_TO_VEC))
41422         return true;
41423
41424       /* Between SSE and general, we have moves no larger than word size.  */
41425       if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
41426         return true;
41427     }
41428
41429   return false;
41430 }
41431
41432 bool
41433 ix86_secondary_memory_needed (enum reg_class class1, enum reg_class class2,
41434                               machine_mode mode, int strict)
41435 {
41436   return inline_secondary_memory_needed (class1, class2, mode, strict);
41437 }
41438
41439 /* Implement the TARGET_CLASS_MAX_NREGS hook.
41440
41441    On the 80386, this is the size of MODE in words,
41442    except in the FP regs, where a single reg is always enough.  */
41443
41444 static unsigned char
41445 ix86_class_max_nregs (reg_class_t rclass, machine_mode mode)
41446 {
41447   if (MAYBE_INTEGER_CLASS_P (rclass))
41448     {
41449       if (mode == XFmode)
41450         return (TARGET_64BIT ? 2 : 3);
41451       else if (mode == XCmode)
41452         return (TARGET_64BIT ? 4 : 6);
41453       else
41454         return ((GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD);
41455     }
41456   else
41457     {
41458       if (COMPLEX_MODE_P (mode))
41459         return 2;
41460       else
41461         return 1;
41462     }
41463 }
41464
41465 /* Return true if the registers in CLASS cannot represent the change from
41466    modes FROM to TO.  */
41467
41468 bool
41469 ix86_cannot_change_mode_class (machine_mode from, machine_mode to,
41470                                enum reg_class regclass)
41471 {
41472   if (from == to)
41473     return false;
41474
41475   /* x87 registers can't do subreg at all, as all values are reformatted
41476      to extended precision.  */
41477   if (MAYBE_FLOAT_CLASS_P (regclass))
41478     return true;
41479
41480   if (MAYBE_SSE_CLASS_P (regclass) || MAYBE_MMX_CLASS_P (regclass))
41481     {
41482       /* Vector registers do not support QI or HImode loads.  If we don't
41483          disallow a change to these modes, reload will assume it's ok to
41484          drop the subreg from (subreg:SI (reg:HI 100) 0).  This affects
41485          the vec_dupv4hi pattern.  */
41486       if (GET_MODE_SIZE (from) < 4)
41487         return true;
41488     }
41489
41490   return false;
41491 }
41492
41493 /* Return the cost of moving data of mode M between a
41494    register and memory.  A value of 2 is the default; this cost is
41495    relative to those in `REGISTER_MOVE_COST'.
41496
41497    This function is used extensively by register_move_cost that is used to
41498    build tables at startup.  Make it inline in this case.
41499    When IN is 2, return maximum of in and out move cost.
41500
41501    If moving between registers and memory is more expensive than
41502    between two registers, you should define this macro to express the
41503    relative cost.
41504
41505    Model also increased moving costs of QImode registers in non
41506    Q_REGS classes.
41507  */
41508 static inline int
41509 inline_memory_move_cost (machine_mode mode, enum reg_class regclass,
41510                          int in)
41511 {
41512   int cost;
41513   if (FLOAT_CLASS_P (regclass))
41514     {
41515       int index;
41516       switch (mode)
41517         {
41518           case SFmode:
41519             index = 0;
41520             break;
41521           case DFmode:
41522             index = 1;
41523             break;
41524           case XFmode:
41525             index = 2;
41526             break;
41527           default:
41528             return 100;
41529         }
41530       if (in == 2)
41531         return MAX (ix86_cost->fp_load [index], ix86_cost->fp_store [index]);
41532       return in ? ix86_cost->fp_load [index] : ix86_cost->fp_store [index];
41533     }
41534   if (SSE_CLASS_P (regclass))
41535     {
41536       int index;
41537       switch (GET_MODE_SIZE (mode))
41538         {
41539           case 4:
41540             index = 0;
41541             break;
41542           case 8:
41543             index = 1;
41544             break;
41545           case 16:
41546             index = 2;
41547             break;
41548           default:
41549             return 100;
41550         }
41551       if (in == 2)
41552         return MAX (ix86_cost->sse_load [index], ix86_cost->sse_store [index]);
41553       return in ? ix86_cost->sse_load [index] : ix86_cost->sse_store [index];
41554     }
41555   if (MMX_CLASS_P (regclass))
41556     {
41557       int index;
41558       switch (GET_MODE_SIZE (mode))
41559         {
41560           case 4:
41561             index = 0;
41562             break;
41563           case 8:
41564             index = 1;
41565             break;
41566           default:
41567             return 100;
41568         }
41569       if (in)
41570         return MAX (ix86_cost->mmx_load [index], ix86_cost->mmx_store [index]);
41571       return in ? ix86_cost->mmx_load [index] : ix86_cost->mmx_store [index];
41572     }
41573   switch (GET_MODE_SIZE (mode))
41574     {
41575       case 1:
41576         if (Q_CLASS_P (regclass) || TARGET_64BIT)
41577           {
41578             if (!in)
41579               return ix86_cost->int_store[0];
41580             if (TARGET_PARTIAL_REG_DEPENDENCY
41581                 && optimize_function_for_speed_p (cfun))
41582               cost = ix86_cost->movzbl_load;
41583             else
41584               cost = ix86_cost->int_load[0];
41585             if (in == 2)
41586               return MAX (cost, ix86_cost->int_store[0]);
41587             return cost;
41588           }
41589         else
41590           {
41591            if (in == 2)
41592              return MAX (ix86_cost->movzbl_load, ix86_cost->int_store[0] + 4);
41593            if (in)
41594              return ix86_cost->movzbl_load;
41595            else
41596              return ix86_cost->int_store[0] + 4;
41597           }
41598         break;
41599       case 2:
41600         if (in == 2)
41601           return MAX (ix86_cost->int_load[1], ix86_cost->int_store[1]);
41602         return in ? ix86_cost->int_load[1] : ix86_cost->int_store[1];
41603       default:
41604         /* Compute number of 32bit moves needed.  TFmode is moved as XFmode.  */
41605         if (mode == TFmode)
41606           mode = XFmode;
41607         if (in == 2)
41608           cost = MAX (ix86_cost->int_load[2] , ix86_cost->int_store[2]);
41609         else if (in)
41610           cost = ix86_cost->int_load[2];
41611         else
41612           cost = ix86_cost->int_store[2];
41613         return (cost * (((int) GET_MODE_SIZE (mode)
41614                         + UNITS_PER_WORD - 1) / UNITS_PER_WORD));
41615     }
41616 }
41617
41618 static int
41619 ix86_memory_move_cost (machine_mode mode, reg_class_t regclass,
41620                        bool in)
41621 {
41622   return inline_memory_move_cost (mode, (enum reg_class) regclass, in ? 1 : 0);
41623 }
41624
41625
41626 /* Return the cost of moving data from a register in class CLASS1 to
41627    one in class CLASS2.
41628
41629    It is not required that the cost always equal 2 when FROM is the same as TO;
41630    on some machines it is expensive to move between registers if they are not
41631    general registers.  */
41632
41633 static int
41634 ix86_register_move_cost (machine_mode mode, reg_class_t class1_i,
41635                          reg_class_t class2_i)
41636 {
41637   enum reg_class class1 = (enum reg_class) class1_i;
41638   enum reg_class class2 = (enum reg_class) class2_i;
41639
41640   /* In case we require secondary memory, compute cost of the store followed
41641      by load.  In order to avoid bad register allocation choices, we need
41642      for this to be *at least* as high as the symmetric MEMORY_MOVE_COST.  */
41643
41644   if (inline_secondary_memory_needed (class1, class2, mode, 0))
41645     {
41646       int cost = 1;
41647
41648       cost += inline_memory_move_cost (mode, class1, 2);
41649       cost += inline_memory_move_cost (mode, class2, 2);
41650
41651       /* In case of copying from general_purpose_register we may emit multiple
41652          stores followed by single load causing memory size mismatch stall.
41653          Count this as arbitrarily high cost of 20.  */
41654       if (targetm.class_max_nregs (class1, mode)
41655           > targetm.class_max_nregs (class2, mode))
41656         cost += 20;
41657
41658       /* In the case of FP/MMX moves, the registers actually overlap, and we
41659          have to switch modes in order to treat them differently.  */
41660       if ((MMX_CLASS_P (class1) && MAYBE_FLOAT_CLASS_P (class2))
41661           || (MMX_CLASS_P (class2) && MAYBE_FLOAT_CLASS_P (class1)))
41662         cost += 20;
41663
41664       return cost;
41665     }
41666
41667   /* Moves between SSE/MMX and integer unit are expensive.  */
41668   if (MMX_CLASS_P (class1) != MMX_CLASS_P (class2)
41669       || SSE_CLASS_P (class1) != SSE_CLASS_P (class2))
41670
41671     /* ??? By keeping returned value relatively high, we limit the number
41672        of moves between integer and MMX/SSE registers for all targets.
41673        Additionally, high value prevents problem with x86_modes_tieable_p(),
41674        where integer modes in MMX/SSE registers are not tieable
41675        because of missing QImode and HImode moves to, from or between
41676        MMX/SSE registers.  */
41677     return MAX (8, ix86_cost->mmxsse_to_integer);
41678
41679   if (MAYBE_FLOAT_CLASS_P (class1))
41680     return ix86_cost->fp_move;
41681   if (MAYBE_SSE_CLASS_P (class1))
41682     return ix86_cost->sse_move;
41683   if (MAYBE_MMX_CLASS_P (class1))
41684     return ix86_cost->mmx_move;
41685   return 2;
41686 }
41687
41688 /* Return TRUE if hard register REGNO can hold a value of machine-mode
41689    MODE.  */
41690
41691 bool
41692 ix86_hard_regno_mode_ok (int regno, machine_mode mode)
41693 {
41694   /* Flags and only flags can only hold CCmode values.  */
41695   if (CC_REGNO_P (regno))
41696     return GET_MODE_CLASS (mode) == MODE_CC;
41697   if (GET_MODE_CLASS (mode) == MODE_CC
41698       || GET_MODE_CLASS (mode) == MODE_RANDOM
41699       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
41700     return false;
41701   if (STACK_REGNO_P (regno))
41702     return VALID_FP_MODE_P (mode);
41703   if (MASK_REGNO_P (regno))
41704     return (VALID_MASK_REG_MODE (mode)
41705             || (TARGET_AVX512BW
41706                 && VALID_MASK_AVX512BW_MODE (mode)));
41707   if (BND_REGNO_P (regno))
41708     return VALID_BND_REG_MODE (mode);
41709   if (SSE_REGNO_P (regno))
41710     {
41711       /* We implement the move patterns for all vector modes into and
41712          out of SSE registers, even when no operation instructions
41713          are available.  */
41714
41715       /* For AVX-512 we allow, regardless of regno:
41716           - XI mode
41717           - any of 512-bit wide vector mode
41718           - any scalar mode.  */
41719       if (TARGET_AVX512F
41720           && (mode == XImode
41721               || VALID_AVX512F_REG_MODE (mode)
41722               || VALID_AVX512F_SCALAR_MODE (mode)))
41723         return true;
41724
41725       /* TODO check for QI/HI scalars.  */
41726       /* AVX512VL allows sse regs16+ for 128/256 bit modes.  */
41727       if (TARGET_AVX512VL
41728           && (mode == OImode
41729               || mode == TImode
41730               || VALID_AVX256_REG_MODE (mode)
41731               || VALID_AVX512VL_128_REG_MODE (mode)))
41732         return true;
41733
41734       /* xmm16-xmm31 are only available for AVX-512.  */
41735       if (EXT_REX_SSE_REGNO_P (regno))
41736         return false;
41737
41738       /* OImode and AVX modes are available only when AVX is enabled.  */
41739       return ((TARGET_AVX
41740                && VALID_AVX256_REG_OR_OI_MODE (mode))
41741               || VALID_SSE_REG_MODE (mode)
41742               || VALID_SSE2_REG_MODE (mode)
41743               || VALID_MMX_REG_MODE (mode)
41744               || VALID_MMX_REG_MODE_3DNOW (mode));
41745     }
41746   if (MMX_REGNO_P (regno))
41747     {
41748       /* We implement the move patterns for 3DNOW modes even in MMX mode,
41749          so if the register is available at all, then we can move data of
41750          the given mode into or out of it.  */
41751       return (VALID_MMX_REG_MODE (mode)
41752               || VALID_MMX_REG_MODE_3DNOW (mode));
41753     }
41754
41755   if (mode == QImode)
41756     {
41757       /* Take care for QImode values - they can be in non-QI regs,
41758          but then they do cause partial register stalls.  */
41759       if (ANY_QI_REGNO_P (regno))
41760         return true;
41761       if (!TARGET_PARTIAL_REG_STALL)
41762         return true;
41763       /* LRA checks if the hard register is OK for the given mode.
41764          QImode values can live in non-QI regs, so we allow all
41765          registers here.  */
41766       if (lra_in_progress)
41767        return true;
41768       return !can_create_pseudo_p ();
41769     }
41770   /* We handle both integer and floats in the general purpose registers.  */
41771   else if (VALID_INT_MODE_P (mode))
41772     return true;
41773   else if (VALID_FP_MODE_P (mode))
41774     return true;
41775   else if (VALID_DFP_MODE_P (mode))
41776     return true;
41777   /* Lots of MMX code casts 8 byte vector modes to DImode.  If we then go
41778      on to use that value in smaller contexts, this can easily force a
41779      pseudo to be allocated to GENERAL_REGS.  Since this is no worse than
41780      supporting DImode, allow it.  */
41781   else if (VALID_MMX_REG_MODE_3DNOW (mode) || VALID_MMX_REG_MODE (mode))
41782     return true;
41783
41784   return false;
41785 }
41786
41787 /* A subroutine of ix86_modes_tieable_p.  Return true if MODE is a
41788    tieable integer mode.  */
41789
41790 static bool
41791 ix86_tieable_integer_mode_p (machine_mode mode)
41792 {
41793   switch (mode)
41794     {
41795     case HImode:
41796     case SImode:
41797       return true;
41798
41799     case QImode:
41800       return TARGET_64BIT || !TARGET_PARTIAL_REG_STALL;
41801
41802     case DImode:
41803       return TARGET_64BIT;
41804
41805     default:
41806       return false;
41807     }
41808 }
41809
41810 /* Return true if MODE1 is accessible in a register that can hold MODE2
41811    without copying.  That is, all register classes that can hold MODE2
41812    can also hold MODE1.  */
41813
41814 bool
41815 ix86_modes_tieable_p (machine_mode mode1, machine_mode mode2)
41816 {
41817   if (mode1 == mode2)
41818     return true;
41819
41820   if (ix86_tieable_integer_mode_p (mode1)
41821       && ix86_tieable_integer_mode_p (mode2))
41822     return true;
41823
41824   /* MODE2 being XFmode implies fp stack or general regs, which means we
41825      can tie any smaller floating point modes to it.  Note that we do not
41826      tie this with TFmode.  */
41827   if (mode2 == XFmode)
41828     return mode1 == SFmode || mode1 == DFmode;
41829
41830   /* MODE2 being DFmode implies fp stack, general or sse regs, which means
41831      that we can tie it with SFmode.  */
41832   if (mode2 == DFmode)
41833     return mode1 == SFmode;
41834
41835   /* If MODE2 is only appropriate for an SSE register, then tie with
41836      any other mode acceptable to SSE registers.  */
41837   if (GET_MODE_SIZE (mode2) == 32
41838       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
41839     return (GET_MODE_SIZE (mode1) == 32
41840             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
41841   if (GET_MODE_SIZE (mode2) == 16
41842       && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode2))
41843     return (GET_MODE_SIZE (mode1) == 16
41844             && ix86_hard_regno_mode_ok (FIRST_SSE_REG, mode1));
41845
41846   /* If MODE2 is appropriate for an MMX register, then tie
41847      with any other mode acceptable to MMX registers.  */
41848   if (GET_MODE_SIZE (mode2) == 8
41849       && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode2))
41850     return (GET_MODE_SIZE (mode1) == 8
41851             && ix86_hard_regno_mode_ok (FIRST_MMX_REG, mode1));
41852
41853   return false;
41854 }
41855
41856 /* Return the cost of moving between two registers of mode MODE.  */
41857
41858 static int
41859 ix86_set_reg_reg_cost (machine_mode mode)
41860 {
41861   unsigned int units = UNITS_PER_WORD;
41862
41863   switch (GET_MODE_CLASS (mode))
41864     {
41865     default:
41866       break;
41867
41868     case MODE_CC:
41869       units = GET_MODE_SIZE (CCmode);
41870       break;
41871
41872     case MODE_FLOAT:
41873       if ((TARGET_SSE && mode == TFmode)
41874           || (TARGET_80387 && mode == XFmode)
41875           || ((TARGET_80387 || TARGET_SSE2) && mode == DFmode)
41876           || ((TARGET_80387 || TARGET_SSE) && mode == SFmode))
41877         units = GET_MODE_SIZE (mode);
41878       break;
41879
41880     case MODE_COMPLEX_FLOAT:
41881       if ((TARGET_SSE && mode == TCmode)
41882           || (TARGET_80387 && mode == XCmode)
41883           || ((TARGET_80387 || TARGET_SSE2) && mode == DCmode)
41884           || ((TARGET_80387 || TARGET_SSE) && mode == SCmode))
41885         units = GET_MODE_SIZE (mode);
41886       break;
41887
41888     case MODE_VECTOR_INT:
41889     case MODE_VECTOR_FLOAT:
41890       if ((TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
41891           || (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
41892           || (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
41893           || (TARGET_SSE && VALID_SSE_REG_MODE (mode))
41894           || (TARGET_MMX && VALID_MMX_REG_MODE (mode)))
41895         units = GET_MODE_SIZE (mode);
41896     }
41897
41898   /* Return the cost of moving between two registers of mode MODE,
41899      assuming that the move will be in pieces of at most UNITS bytes.  */
41900   return COSTS_N_INSNS ((GET_MODE_SIZE (mode) + units - 1) / units);
41901 }
41902
41903 /* Compute a (partial) cost for rtx X.  Return true if the complete
41904    cost has been computed, and false if subexpressions should be
41905    scanned.  In either case, *TOTAL contains the cost result.  */
41906
41907 static bool
41908 ix86_rtx_costs (rtx x, int code_i, int outer_code_i, int opno, int *total,
41909                 bool speed)
41910 {
41911   rtx mask;
41912   enum rtx_code code = (enum rtx_code) code_i;
41913   enum rtx_code outer_code = (enum rtx_code) outer_code_i;
41914   machine_mode mode = GET_MODE (x);
41915   const struct processor_costs *cost = speed ? ix86_cost : &ix86_size_cost;
41916
41917   switch (code)
41918     {
41919     case SET:
41920       if (register_operand (SET_DEST (x), VOIDmode)
41921           && reg_or_0_operand (SET_SRC (x), VOIDmode))
41922         {
41923           *total = ix86_set_reg_reg_cost (GET_MODE (SET_DEST (x)));
41924           return true;
41925         }
41926       return false;
41927
41928     case CONST_INT:
41929     case CONST:
41930     case LABEL_REF:
41931     case SYMBOL_REF:
41932       if (TARGET_64BIT && !x86_64_immediate_operand (x, VOIDmode))
41933         *total = 3;
41934       else if (TARGET_64BIT && !x86_64_zext_immediate_operand (x, VOIDmode))
41935         *total = 2;
41936       else if (flag_pic && SYMBOLIC_CONST (x)
41937                && !(TARGET_64BIT
41938                     && (GET_CODE (x) == LABEL_REF
41939                         || (GET_CODE (x) == SYMBOL_REF
41940                             && SYMBOL_REF_LOCAL_P (x)))))
41941         *total = 1;
41942       else
41943         *total = 0;
41944       return true;
41945
41946     case CONST_DOUBLE:
41947       if (mode == VOIDmode)
41948         {
41949           *total = 0;
41950           return true;
41951         }
41952       switch (standard_80387_constant_p (x))
41953         {
41954         case 1: /* 0.0 */
41955           *total = 1;
41956           return true;
41957         default: /* Other constants */
41958           *total = 2;
41959           return true;
41960         case 0:
41961         case -1:
41962           break;
41963         }
41964       if (SSE_FLOAT_MODE_P (mode))
41965         {
41966     case CONST_VECTOR:
41967           switch (standard_sse_constant_p (x))
41968             {
41969             case 0:
41970               break;
41971             case 1:  /* 0: xor eliminates false dependency */
41972               *total = 0;
41973               return true;
41974             default: /* -1: cmp contains false dependency */
41975               *total = 1;
41976               return true;
41977             }
41978         }
41979       /* Fall back to (MEM (SYMBOL_REF)), since that's where
41980          it'll probably end up.  Add a penalty for size.  */
41981       *total = (COSTS_N_INSNS (1)
41982                 + (flag_pic != 0 && !TARGET_64BIT)
41983                 + (mode == SFmode ? 0 : mode == DFmode ? 1 : 2));
41984       return true;
41985
41986     case ZERO_EXTEND:
41987       /* The zero extensions is often completely free on x86_64, so make
41988          it as cheap as possible.  */
41989       if (TARGET_64BIT && mode == DImode
41990           && GET_MODE (XEXP (x, 0)) == SImode)
41991         *total = 1;
41992       else if (TARGET_ZERO_EXTEND_WITH_AND)
41993         *total = cost->add;
41994       else
41995         *total = cost->movzx;
41996       return false;
41997
41998     case SIGN_EXTEND:
41999       *total = cost->movsx;
42000       return false;
42001
42002     case ASHIFT:
42003       if (SCALAR_INT_MODE_P (mode)
42004           && GET_MODE_SIZE (mode) < UNITS_PER_WORD
42005           && CONST_INT_P (XEXP (x, 1)))
42006         {
42007           HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
42008           if (value == 1)
42009             {
42010               *total = cost->add;
42011               return false;
42012             }
42013           if ((value == 2 || value == 3)
42014               && cost->lea <= cost->shift_const)
42015             {
42016               *total = cost->lea;
42017               return false;
42018             }
42019         }
42020       /* FALLTHRU */
42021
42022     case ROTATE:
42023     case ASHIFTRT:
42024     case LSHIFTRT:
42025     case ROTATERT:
42026       if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
42027         {
42028           /* ??? Should be SSE vector operation cost.  */
42029           /* At least for published AMD latencies, this really is the same
42030              as the latency for a simple fpu operation like fabs.  */
42031           /* V*QImode is emulated with 1-11 insns.  */
42032           if (mode == V16QImode || mode == V32QImode)
42033             {
42034               int count = 11;
42035               if (TARGET_XOP && mode == V16QImode)
42036                 {
42037                   /* For XOP we use vpshab, which requires a broadcast of the
42038                      value to the variable shift insn.  For constants this
42039                      means a V16Q const in mem; even when we can perform the
42040                      shift with one insn set the cost to prefer paddb.  */
42041                   if (CONSTANT_P (XEXP (x, 1)))
42042                     {
42043                       *total = (cost->fabs
42044                                 + rtx_cost (XEXP (x, 0), code, 0, speed)
42045                                 + (speed ? 2 : COSTS_N_BYTES (16)));
42046                       return true;
42047                     }
42048                   count = 3;
42049                 }
42050               else if (TARGET_SSSE3)
42051                 count = 7;
42052               *total = cost->fabs * count;
42053             }
42054           else
42055             *total = cost->fabs;
42056         }
42057       else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
42058         {
42059           if (CONST_INT_P (XEXP (x, 1)))
42060             {
42061               if (INTVAL (XEXP (x, 1)) > 32)
42062                 *total = cost->shift_const + COSTS_N_INSNS (2);
42063               else
42064                 *total = cost->shift_const * 2;
42065             }
42066           else
42067             {
42068               if (GET_CODE (XEXP (x, 1)) == AND)
42069                 *total = cost->shift_var * 2;
42070               else
42071                 *total = cost->shift_var * 6 + COSTS_N_INSNS (2);
42072             }
42073         }
42074       else
42075         {
42076           if (CONST_INT_P (XEXP (x, 1)))
42077             *total = cost->shift_const;
42078           else if (GET_CODE (XEXP (x, 1)) == SUBREG
42079                    && GET_CODE (XEXP (XEXP (x, 1), 0)) == AND)
42080             {
42081               /* Return the cost after shift-and truncation.  */
42082               *total = cost->shift_var;
42083               return true;
42084             }
42085           else
42086             *total = cost->shift_var;
42087         }
42088       return false;
42089
42090     case FMA:
42091       {
42092         rtx sub;
42093
42094         gcc_assert (FLOAT_MODE_P (mode));
42095         gcc_assert (TARGET_FMA || TARGET_FMA4 || TARGET_AVX512F);
42096
42097         /* ??? SSE scalar/vector cost should be used here.  */
42098         /* ??? Bald assumption that fma has the same cost as fmul.  */
42099         *total = cost->fmul;
42100         *total += rtx_cost (XEXP (x, 1), FMA, 1, speed);
42101
42102         /* Negate in op0 or op2 is free: FMS, FNMA, FNMS.  */
42103         sub = XEXP (x, 0);
42104         if (GET_CODE (sub) == NEG)
42105           sub = XEXP (sub, 0);
42106         *total += rtx_cost (sub, FMA, 0, speed);
42107
42108         sub = XEXP (x, 2);
42109         if (GET_CODE (sub) == NEG)
42110           sub = XEXP (sub, 0);
42111         *total += rtx_cost (sub, FMA, 2, speed);
42112         return true;
42113       }
42114
42115     case MULT:
42116       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42117         {
42118           /* ??? SSE scalar cost should be used here.  */
42119           *total = cost->fmul;
42120           return false;
42121         }
42122       else if (X87_FLOAT_MODE_P (mode))
42123         {
42124           *total = cost->fmul;
42125           return false;
42126         }
42127       else if (FLOAT_MODE_P (mode))
42128         {
42129           /* ??? SSE vector cost should be used here.  */
42130           *total = cost->fmul;
42131           return false;
42132         }
42133       else if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
42134         {
42135           /* V*QImode is emulated with 7-13 insns.  */
42136           if (mode == V16QImode || mode == V32QImode)
42137             {
42138               int extra = 11;
42139               if (TARGET_XOP && mode == V16QImode)
42140                 extra = 5;
42141               else if (TARGET_SSSE3)
42142                 extra = 6;
42143               *total = cost->fmul * 2 + cost->fabs * extra;
42144             }
42145           /* V*DImode is emulated with 5-8 insns.  */
42146           else if (mode == V2DImode || mode == V4DImode)
42147             {
42148               if (TARGET_XOP && mode == V2DImode)
42149                 *total = cost->fmul * 2 + cost->fabs * 3;
42150               else
42151                 *total = cost->fmul * 3 + cost->fabs * 5;
42152             }
42153           /* Without sse4.1, we don't have PMULLD; it's emulated with 7
42154              insns, including two PMULUDQ.  */
42155           else if (mode == V4SImode && !(TARGET_SSE4_1 || TARGET_AVX))
42156             *total = cost->fmul * 2 + cost->fabs * 5;
42157           else
42158             *total = cost->fmul;
42159           return false;
42160         }
42161       else
42162         {
42163           rtx op0 = XEXP (x, 0);
42164           rtx op1 = XEXP (x, 1);
42165           int nbits;
42166           if (CONST_INT_P (XEXP (x, 1)))
42167             {
42168               unsigned HOST_WIDE_INT value = INTVAL (XEXP (x, 1));
42169               for (nbits = 0; value != 0; value &= value - 1)
42170                 nbits++;
42171             }
42172           else
42173             /* This is arbitrary.  */
42174             nbits = 7;
42175
42176           /* Compute costs correctly for widening multiplication.  */
42177           if ((GET_CODE (op0) == SIGN_EXTEND || GET_CODE (op0) == ZERO_EXTEND)
42178               && GET_MODE_SIZE (GET_MODE (XEXP (op0, 0))) * 2
42179                  == GET_MODE_SIZE (mode))
42180             {
42181               int is_mulwiden = 0;
42182               machine_mode inner_mode = GET_MODE (op0);
42183
42184               if (GET_CODE (op0) == GET_CODE (op1))
42185                 is_mulwiden = 1, op1 = XEXP (op1, 0);
42186               else if (CONST_INT_P (op1))
42187                 {
42188                   if (GET_CODE (op0) == SIGN_EXTEND)
42189                     is_mulwiden = trunc_int_for_mode (INTVAL (op1), inner_mode)
42190                                   == INTVAL (op1);
42191                   else
42192                     is_mulwiden = !(INTVAL (op1) & ~GET_MODE_MASK (inner_mode));
42193                 }
42194
42195               if (is_mulwiden)
42196                 op0 = XEXP (op0, 0), mode = GET_MODE (op0);
42197             }
42198
42199           *total = (cost->mult_init[MODE_INDEX (mode)]
42200                     + nbits * cost->mult_bit
42201                     + rtx_cost (op0, outer_code, opno, speed)
42202                     + rtx_cost (op1, outer_code, opno, speed));
42203
42204           return true;
42205         }
42206
42207     case DIV:
42208     case UDIV:
42209     case MOD:
42210     case UMOD:
42211       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42212         /* ??? SSE cost should be used here.  */
42213         *total = cost->fdiv;
42214       else if (X87_FLOAT_MODE_P (mode))
42215         *total = cost->fdiv;
42216       else if (FLOAT_MODE_P (mode))
42217         /* ??? SSE vector cost should be used here.  */
42218         *total = cost->fdiv;
42219       else
42220         *total = cost->divide[MODE_INDEX (mode)];
42221       return false;
42222
42223     case PLUS:
42224       if (GET_MODE_CLASS (mode) == MODE_INT
42225           && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)
42226         {
42227           if (GET_CODE (XEXP (x, 0)) == PLUS
42228               && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT
42229               && CONST_INT_P (XEXP (XEXP (XEXP (x, 0), 0), 1))
42230               && CONSTANT_P (XEXP (x, 1)))
42231             {
42232               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (XEXP (x, 0), 0), 1));
42233               if (val == 2 || val == 4 || val == 8)
42234                 {
42235                   *total = cost->lea;
42236                   *total += rtx_cost (XEXP (XEXP (x, 0), 1),
42237                                       outer_code, opno, speed);
42238                   *total += rtx_cost (XEXP (XEXP (XEXP (x, 0), 0), 0),
42239                                       outer_code, opno, speed);
42240                   *total += rtx_cost (XEXP (x, 1), outer_code, opno, speed);
42241                   return true;
42242                 }
42243             }
42244           else if (GET_CODE (XEXP (x, 0)) == MULT
42245                    && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
42246             {
42247               HOST_WIDE_INT val = INTVAL (XEXP (XEXP (x, 0), 1));
42248               if (val == 2 || val == 4 || val == 8)
42249                 {
42250                   *total = cost->lea;
42251                   *total += rtx_cost (XEXP (XEXP (x, 0), 0),
42252                                       outer_code, opno, speed);
42253                   *total += rtx_cost (XEXP (x, 1), outer_code, opno, speed);
42254                   return true;
42255                 }
42256             }
42257           else if (GET_CODE (XEXP (x, 0)) == PLUS)
42258             {
42259               *total = cost->lea;
42260               *total += rtx_cost (XEXP (XEXP (x, 0), 0),
42261                                   outer_code, opno, speed);
42262               *total += rtx_cost (XEXP (XEXP (x, 0), 1),
42263                                   outer_code, opno, speed);
42264               *total += rtx_cost (XEXP (x, 1), outer_code, opno, speed);
42265               return true;
42266             }
42267         }
42268       /* FALLTHRU */
42269
42270     case MINUS:
42271       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42272         {
42273           /* ??? SSE cost should be used here.  */
42274           *total = cost->fadd;
42275           return false;
42276         }
42277       else if (X87_FLOAT_MODE_P (mode))
42278         {
42279           *total = cost->fadd;
42280           return false;
42281         }
42282       else if (FLOAT_MODE_P (mode))
42283         {
42284           /* ??? SSE vector cost should be used here.  */
42285           *total = cost->fadd;
42286           return false;
42287         }
42288       /* FALLTHRU */
42289
42290     case AND:
42291     case IOR:
42292     case XOR:
42293       if (GET_MODE_CLASS (mode) == MODE_INT
42294           && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
42295         {
42296           *total = (cost->add * 2
42297                     + (rtx_cost (XEXP (x, 0), outer_code, opno, speed)
42298                        << (GET_MODE (XEXP (x, 0)) != DImode))
42299                     + (rtx_cost (XEXP (x, 1), outer_code, opno, speed)
42300                        << (GET_MODE (XEXP (x, 1)) != DImode)));
42301           return true;
42302         }
42303       /* FALLTHRU */
42304
42305     case NEG:
42306       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42307         {
42308           /* ??? SSE cost should be used here.  */
42309           *total = cost->fchs;
42310           return false;
42311         }
42312       else if (X87_FLOAT_MODE_P (mode))
42313         {
42314           *total = cost->fchs;
42315           return false;
42316         }
42317       else if (FLOAT_MODE_P (mode))
42318         {
42319           /* ??? SSE vector cost should be used here.  */
42320           *total = cost->fchs;
42321           return false;
42322         }
42323       /* FALLTHRU */
42324
42325     case NOT:
42326       if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
42327         {
42328           /* ??? Should be SSE vector operation cost.  */
42329           /* At least for published AMD latencies, this really is the same
42330              as the latency for a simple fpu operation like fabs.  */
42331           *total = cost->fabs;
42332         }
42333       else if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
42334         *total = cost->add * 2;
42335       else
42336         *total = cost->add;
42337       return false;
42338
42339     case COMPARE:
42340       if (GET_CODE (XEXP (x, 0)) == ZERO_EXTRACT
42341           && XEXP (XEXP (x, 0), 1) == const1_rtx
42342           && CONST_INT_P (XEXP (XEXP (x, 0), 2))
42343           && XEXP (x, 1) == const0_rtx)
42344         {
42345           /* This kind of construct is implemented using test[bwl].
42346              Treat it as if we had an AND.  */
42347           *total = (cost->add
42348                     + rtx_cost (XEXP (XEXP (x, 0), 0), outer_code, opno, speed)
42349                     + rtx_cost (const1_rtx, outer_code, opno, speed));
42350           return true;
42351         }
42352       return false;
42353
42354     case FLOAT_EXTEND:
42355       if (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH))
42356         *total = 0;
42357       return false;
42358
42359     case ABS:
42360       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42361         /* ??? SSE cost should be used here.  */
42362         *total = cost->fabs;
42363       else if (X87_FLOAT_MODE_P (mode))
42364         *total = cost->fabs;
42365       else if (FLOAT_MODE_P (mode))
42366         /* ??? SSE vector cost should be used here.  */
42367         *total = cost->fabs;
42368       return false;
42369
42370     case SQRT:
42371       if (SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH)
42372         /* ??? SSE cost should be used here.  */
42373         *total = cost->fsqrt;
42374       else if (X87_FLOAT_MODE_P (mode))
42375         *total = cost->fsqrt;
42376       else if (FLOAT_MODE_P (mode))
42377         /* ??? SSE vector cost should be used here.  */
42378         *total = cost->fsqrt;
42379       return false;
42380
42381     case UNSPEC:
42382       if (XINT (x, 1) == UNSPEC_TP)
42383         *total = 0;
42384       return false;
42385
42386     case VEC_SELECT:
42387     case VEC_CONCAT:
42388     case VEC_DUPLICATE:
42389       /* ??? Assume all of these vector manipulation patterns are
42390          recognizable.  In which case they all pretty much have the
42391          same cost.  */
42392      *total = cost->fabs;
42393      return true;
42394     case VEC_MERGE:
42395       mask = XEXP (x, 2);
42396       /* This is masked instruction, assume the same cost,
42397          as nonmasked variant.  */
42398       if (TARGET_AVX512F && register_operand (mask, GET_MODE (mask)))
42399         *total = rtx_cost (XEXP (x, 0), outer_code, opno, speed);
42400       else
42401         *total = cost->fabs;
42402       return true;
42403
42404     default:
42405       return false;
42406     }
42407 }
42408
42409 #if TARGET_MACHO
42410
42411 static int current_machopic_label_num;
42412
42413 /* Given a symbol name and its associated stub, write out the
42414    definition of the stub.  */
42415
42416 void
42417 machopic_output_stub (FILE *file, const char *symb, const char *stub)
42418 {
42419   unsigned int length;
42420   char *binder_name, *symbol_name, lazy_ptr_name[32];
42421   int label = ++current_machopic_label_num;
42422
42423   /* For 64-bit we shouldn't get here.  */
42424   gcc_assert (!TARGET_64BIT);
42425
42426   /* Lose our funky encoding stuff so it doesn't contaminate the stub.  */
42427   symb = targetm.strip_name_encoding (symb);
42428
42429   length = strlen (stub);
42430   binder_name = XALLOCAVEC (char, length + 32);
42431   GEN_BINDER_NAME_FOR_STUB (binder_name, stub, length);
42432
42433   length = strlen (symb);
42434   symbol_name = XALLOCAVEC (char, length + 32);
42435   GEN_SYMBOL_NAME_FOR_SYMBOL (symbol_name, symb, length);
42436
42437   sprintf (lazy_ptr_name, "L%d$lz", label);
42438
42439   if (MACHOPIC_ATT_STUB)
42440     switch_to_section (darwin_sections[machopic_picsymbol_stub3_section]);
42441   else if (MACHOPIC_PURE)
42442     switch_to_section (darwin_sections[machopic_picsymbol_stub2_section]);
42443   else
42444     switch_to_section (darwin_sections[machopic_symbol_stub_section]);
42445
42446   fprintf (file, "%s:\n", stub);
42447   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
42448
42449   if (MACHOPIC_ATT_STUB)
42450     {
42451       fprintf (file, "\thlt ; hlt ; hlt ; hlt ; hlt\n");
42452     }
42453   else if (MACHOPIC_PURE)
42454     {
42455       /* PIC stub.  */
42456       /* 25-byte PIC stub using "CALL get_pc_thunk".  */
42457       rtx tmp = gen_rtx_REG (SImode, 2 /* ECX */);
42458       output_set_got (tmp, NULL_RTX);   /* "CALL ___<cpu>.get_pc_thunk.cx".  */
42459       fprintf (file, "LPC$%d:\tmovl\t%s-LPC$%d(%%ecx),%%ecx\n",
42460                label, lazy_ptr_name, label);
42461       fprintf (file, "\tjmp\t*%%ecx\n");
42462     }
42463   else
42464     fprintf (file, "\tjmp\t*%s\n", lazy_ptr_name);
42465
42466   /* The AT&T-style ("self-modifying") stub is not lazily bound, thus
42467      it needs no stub-binding-helper.  */
42468   if (MACHOPIC_ATT_STUB)
42469     return;
42470
42471   fprintf (file, "%s:\n", binder_name);
42472
42473   if (MACHOPIC_PURE)
42474     {
42475       fprintf (file, "\tlea\t%s-%s(%%ecx),%%ecx\n", lazy_ptr_name, binder_name);
42476       fprintf (file, "\tpushl\t%%ecx\n");
42477     }
42478   else
42479     fprintf (file, "\tpushl\t$%s\n", lazy_ptr_name);
42480
42481   fputs ("\tjmp\tdyld_stub_binding_helper\n", file);
42482
42483   /* N.B. Keep the correspondence of these
42484      'symbol_ptr/symbol_ptr2/symbol_ptr3' sections consistent with the
42485      old-pic/new-pic/non-pic stubs; altering this will break
42486      compatibility with existing dylibs.  */
42487   if (MACHOPIC_PURE)
42488     {
42489       /* 25-byte PIC stub using "CALL get_pc_thunk".  */
42490       switch_to_section (darwin_sections[machopic_lazy_symbol_ptr2_section]);
42491     }
42492   else
42493     /* 16-byte -mdynamic-no-pic stub.  */
42494     switch_to_section(darwin_sections[machopic_lazy_symbol_ptr3_section]);
42495
42496   fprintf (file, "%s:\n", lazy_ptr_name);
42497   fprintf (file, "\t.indirect_symbol %s\n", symbol_name);
42498   fprintf (file, ASM_LONG "%s\n", binder_name);
42499 }
42500 #endif /* TARGET_MACHO */
42501
42502 /* Order the registers for register allocator.  */
42503
42504 void
42505 x86_order_regs_for_local_alloc (void)
42506 {
42507    int pos = 0;
42508    int i;
42509
42510    /* First allocate the local general purpose registers.  */
42511    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
42512      if (GENERAL_REGNO_P (i) && call_used_regs[i])
42513         reg_alloc_order [pos++] = i;
42514
42515    /* Global general purpose registers.  */
42516    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
42517      if (GENERAL_REGNO_P (i) && !call_used_regs[i])
42518         reg_alloc_order [pos++] = i;
42519
42520    /* x87 registers come first in case we are doing FP math
42521       using them.  */
42522    if (!TARGET_SSE_MATH)
42523      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
42524        reg_alloc_order [pos++] = i;
42525
42526    /* SSE registers.  */
42527    for (i = FIRST_SSE_REG; i <= LAST_SSE_REG; i++)
42528      reg_alloc_order [pos++] = i;
42529    for (i = FIRST_REX_SSE_REG; i <= LAST_REX_SSE_REG; i++)
42530      reg_alloc_order [pos++] = i;
42531
42532    /* Extended REX SSE registers.  */
42533    for (i = FIRST_EXT_REX_SSE_REG; i <= LAST_EXT_REX_SSE_REG; i++)
42534      reg_alloc_order [pos++] = i;
42535
42536    /* Mask register.  */
42537    for (i = FIRST_MASK_REG; i <= LAST_MASK_REG; i++)
42538      reg_alloc_order [pos++] = i;
42539
42540    /* MPX bound registers.  */
42541    for (i = FIRST_BND_REG; i <= LAST_BND_REG; i++)
42542      reg_alloc_order [pos++] = i;
42543
42544    /* x87 registers.  */
42545    if (TARGET_SSE_MATH)
42546      for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
42547        reg_alloc_order [pos++] = i;
42548
42549    for (i = FIRST_MMX_REG; i <= LAST_MMX_REG; i++)
42550      reg_alloc_order [pos++] = i;
42551
42552    /* Initialize the rest of array as we do not allocate some registers
42553       at all.  */
42554    while (pos < FIRST_PSEUDO_REGISTER)
42555      reg_alloc_order [pos++] = 0;
42556 }
42557
42558 /* Handle a "callee_pop_aggregate_return" attribute; arguments as
42559    in struct attribute_spec handler.  */
42560 static tree
42561 ix86_handle_callee_pop_aggregate_return (tree *node, tree name,
42562                                               tree args,
42563                                               int,
42564                                               bool *no_add_attrs)
42565 {
42566   if (TREE_CODE (*node) != FUNCTION_TYPE
42567       && TREE_CODE (*node) != METHOD_TYPE
42568       && TREE_CODE (*node) != FIELD_DECL
42569       && TREE_CODE (*node) != TYPE_DECL)
42570     {
42571       warning (OPT_Wattributes, "%qE attribute only applies to functions",
42572                name);
42573       *no_add_attrs = true;
42574       return NULL_TREE;
42575     }
42576   if (TARGET_64BIT)
42577     {
42578       warning (OPT_Wattributes, "%qE attribute only available for 32-bit",
42579                name);
42580       *no_add_attrs = true;
42581       return NULL_TREE;
42582     }
42583   if (is_attribute_p ("callee_pop_aggregate_return", name))
42584     {
42585       tree cst;
42586
42587       cst = TREE_VALUE (args);
42588       if (TREE_CODE (cst) != INTEGER_CST)
42589         {
42590           warning (OPT_Wattributes,
42591                    "%qE attribute requires an integer constant argument",
42592                    name);
42593           *no_add_attrs = true;
42594         }
42595       else if (compare_tree_int (cst, 0) != 0
42596                && compare_tree_int (cst, 1) != 0)
42597         {
42598           warning (OPT_Wattributes,
42599                    "argument to %qE attribute is neither zero, nor one",
42600                    name);
42601           *no_add_attrs = true;
42602         }
42603
42604       return NULL_TREE;
42605     }
42606
42607   return NULL_TREE;
42608 }
42609
42610 /* Handle a "ms_abi" or "sysv" attribute; arguments as in
42611    struct attribute_spec.handler.  */
42612 static tree
42613 ix86_handle_abi_attribute (tree *node, tree name, tree, int,
42614                            bool *no_add_attrs)
42615 {
42616   if (TREE_CODE (*node) != FUNCTION_TYPE
42617       && TREE_CODE (*node) != METHOD_TYPE
42618       && TREE_CODE (*node) != FIELD_DECL
42619       && TREE_CODE (*node) != TYPE_DECL)
42620     {
42621       warning (OPT_Wattributes, "%qE attribute only applies to functions",
42622                name);
42623       *no_add_attrs = true;
42624       return NULL_TREE;
42625     }
42626
42627   /* Can combine regparm with all attributes but fastcall.  */
42628   if (is_attribute_p ("ms_abi", name))
42629     {
42630       if (lookup_attribute ("sysv_abi", TYPE_ATTRIBUTES (*node)))
42631         {
42632           error ("ms_abi and sysv_abi attributes are not compatible");
42633         }
42634
42635       return NULL_TREE;
42636     }
42637   else if (is_attribute_p ("sysv_abi", name))
42638     {
42639       if (lookup_attribute ("ms_abi", TYPE_ATTRIBUTES (*node)))
42640         {
42641           error ("ms_abi and sysv_abi attributes are not compatible");
42642         }
42643
42644       return NULL_TREE;
42645     }
42646
42647   return NULL_TREE;
42648 }
42649
42650 /* Handle a "ms_struct" or "gcc_struct" attribute; arguments as in
42651    struct attribute_spec.handler.  */
42652 static tree
42653 ix86_handle_struct_attribute (tree *node, tree name, tree, int,
42654                               bool *no_add_attrs)
42655 {
42656   tree *type = NULL;
42657   if (DECL_P (*node))
42658     {
42659       if (TREE_CODE (*node) == TYPE_DECL)
42660         type = &TREE_TYPE (*node);
42661     }
42662   else
42663     type = node;
42664
42665   if (!(type && RECORD_OR_UNION_TYPE_P (*type)))
42666     {
42667       warning (OPT_Wattributes, "%qE attribute ignored",
42668                name);
42669       *no_add_attrs = true;
42670     }
42671
42672   else if ((is_attribute_p ("ms_struct", name)
42673             && lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (*type)))
42674            || ((is_attribute_p ("gcc_struct", name)
42675                 && lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (*type)))))
42676     {
42677       warning (OPT_Wattributes, "%qE incompatible attribute ignored",
42678                name);
42679       *no_add_attrs = true;
42680     }
42681
42682   return NULL_TREE;
42683 }
42684
42685 static tree
42686 ix86_handle_fndecl_attribute (tree *node, tree name, tree, int,
42687                               bool *no_add_attrs)
42688 {
42689   if (TREE_CODE (*node) != FUNCTION_DECL)
42690     {
42691       warning (OPT_Wattributes, "%qE attribute only applies to functions",
42692                name);
42693       *no_add_attrs = true;
42694     }
42695   return NULL_TREE;
42696 }
42697
42698 static bool
42699 ix86_ms_bitfield_layout_p (const_tree record_type)
42700 {
42701   return ((TARGET_MS_BITFIELD_LAYOUT
42702            && !lookup_attribute ("gcc_struct", TYPE_ATTRIBUTES (record_type)))
42703           || lookup_attribute ("ms_struct", TYPE_ATTRIBUTES (record_type)));
42704 }
42705
42706 /* Returns an expression indicating where the this parameter is
42707    located on entry to the FUNCTION.  */
42708
42709 static rtx
42710 x86_this_parameter (tree function)
42711 {
42712   tree type = TREE_TYPE (function);
42713   bool aggr = aggregate_value_p (TREE_TYPE (type), type) != 0;
42714   int nregs;
42715
42716   if (TARGET_64BIT)
42717     {
42718       const int *parm_regs;
42719
42720       if (ix86_function_type_abi (type) == MS_ABI)
42721         parm_regs = x86_64_ms_abi_int_parameter_registers;
42722       else
42723         parm_regs = x86_64_int_parameter_registers;
42724       return gen_rtx_REG (Pmode, parm_regs[aggr]);
42725     }
42726
42727   nregs = ix86_function_regparm (type, function);
42728
42729   if (nregs > 0 && !stdarg_p (type))
42730     {
42731       int regno;
42732       unsigned int ccvt = ix86_get_callcvt (type);
42733
42734       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
42735         regno = aggr ? DX_REG : CX_REG;
42736       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
42737         {
42738           regno = CX_REG;
42739           if (aggr)
42740             return gen_rtx_MEM (SImode,
42741                                 plus_constant (Pmode, stack_pointer_rtx, 4));
42742         }
42743       else
42744         {
42745           regno = AX_REG;
42746           if (aggr)
42747             {
42748               regno = DX_REG;
42749               if (nregs == 1)
42750                 return gen_rtx_MEM (SImode,
42751                                     plus_constant (Pmode,
42752                                                    stack_pointer_rtx, 4));
42753             }
42754         }
42755       return gen_rtx_REG (SImode, regno);
42756     }
42757
42758   return gen_rtx_MEM (SImode, plus_constant (Pmode, stack_pointer_rtx,
42759                                              aggr ? 8 : 4));
42760 }
42761
42762 /* Determine whether x86_output_mi_thunk can succeed.  */
42763
42764 static bool
42765 x86_can_output_mi_thunk (const_tree, HOST_WIDE_INT, HOST_WIDE_INT vcall_offset,
42766                          const_tree function)
42767 {
42768   /* 64-bit can handle anything.  */
42769   if (TARGET_64BIT)
42770     return true;
42771
42772   /* For 32-bit, everything's fine if we have one free register.  */
42773   if (ix86_function_regparm (TREE_TYPE (function), function) < 3)
42774     return true;
42775
42776   /* Need a free register for vcall_offset.  */
42777   if (vcall_offset)
42778     return false;
42779
42780   /* Need a free register for GOT references.  */
42781   if (flag_pic && !targetm.binds_local_p (function))
42782     return false;
42783
42784   /* Otherwise ok.  */
42785   return true;
42786 }
42787
42788 /* Output the assembler code for a thunk function.  THUNK_DECL is the
42789    declaration for the thunk function itself, FUNCTION is the decl for
42790    the target function.  DELTA is an immediate constant offset to be
42791    added to THIS.  If VCALL_OFFSET is nonzero, the word at
42792    *(*this + vcall_offset) should be added to THIS.  */
42793
42794 static void
42795 x86_output_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta,
42796                      HOST_WIDE_INT vcall_offset, tree function)
42797 {
42798   rtx this_param = x86_this_parameter (function);
42799   rtx this_reg, tmp, fnaddr;
42800   unsigned int tmp_regno;
42801   rtx_insn *insn;
42802
42803   if (TARGET_64BIT)
42804     tmp_regno = R10_REG;
42805   else
42806     {
42807       unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function));
42808       if ((ccvt & IX86_CALLCVT_FASTCALL) != 0)
42809         tmp_regno = AX_REG;
42810       else if ((ccvt & IX86_CALLCVT_THISCALL) != 0)
42811         tmp_regno = DX_REG;
42812       else
42813         tmp_regno = CX_REG;
42814     }
42815
42816   emit_note (NOTE_INSN_PROLOGUE_END);
42817
42818   /* If VCALL_OFFSET, we'll need THIS in a register.  Might as well
42819      pull it in now and let DELTA benefit.  */
42820   if (REG_P (this_param))
42821     this_reg = this_param;
42822   else if (vcall_offset)
42823     {
42824       /* Put the this parameter into %eax.  */
42825       this_reg = gen_rtx_REG (Pmode, AX_REG);
42826       emit_move_insn (this_reg, this_param);
42827     }
42828   else
42829     this_reg = NULL_RTX;
42830
42831   /* Adjust the this parameter by a fixed constant.  */
42832   if (delta)
42833     {
42834       rtx delta_rtx = GEN_INT (delta);
42835       rtx delta_dst = this_reg ? this_reg : this_param;
42836
42837       if (TARGET_64BIT)
42838         {
42839           if (!x86_64_general_operand (delta_rtx, Pmode))
42840             {
42841               tmp = gen_rtx_REG (Pmode, tmp_regno);
42842               emit_move_insn (tmp, delta_rtx);
42843               delta_rtx = tmp;
42844             }
42845         }
42846
42847       ix86_emit_binop (PLUS, Pmode, delta_dst, delta_rtx);
42848     }
42849
42850   /* Adjust the this parameter by a value stored in the vtable.  */
42851   if (vcall_offset)
42852     {
42853       rtx vcall_addr, vcall_mem, this_mem;
42854
42855       tmp = gen_rtx_REG (Pmode, tmp_regno);
42856
42857       this_mem = gen_rtx_MEM (ptr_mode, this_reg);
42858       if (Pmode != ptr_mode)
42859         this_mem = gen_rtx_ZERO_EXTEND (Pmode, this_mem);
42860       emit_move_insn (tmp, this_mem);
42861
42862       /* Adjust the this parameter.  */
42863       vcall_addr = plus_constant (Pmode, tmp, vcall_offset);
42864       if (TARGET_64BIT
42865           && !ix86_legitimate_address_p (ptr_mode, vcall_addr, true))
42866         {
42867           rtx tmp2 = gen_rtx_REG (Pmode, R11_REG);
42868           emit_move_insn (tmp2, GEN_INT (vcall_offset));
42869           vcall_addr = gen_rtx_PLUS (Pmode, tmp, tmp2);
42870         }
42871
42872       vcall_mem = gen_rtx_MEM (ptr_mode, vcall_addr);
42873       if (Pmode != ptr_mode)
42874         emit_insn (gen_addsi_1_zext (this_reg,
42875                                      gen_rtx_REG (ptr_mode,
42876                                                   REGNO (this_reg)),
42877                                      vcall_mem));
42878       else
42879         ix86_emit_binop (PLUS, Pmode, this_reg, vcall_mem);
42880     }
42881
42882   /* If necessary, drop THIS back to its stack slot.  */
42883   if (this_reg && this_reg != this_param)
42884     emit_move_insn (this_param, this_reg);
42885
42886   fnaddr = XEXP (DECL_RTL (function), 0);
42887   if (TARGET_64BIT)
42888     {
42889       if (!flag_pic || targetm.binds_local_p (function)
42890           || TARGET_PECOFF)
42891         ;
42892       else
42893         {
42894           tmp = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOTPCREL);
42895           tmp = gen_rtx_CONST (Pmode, tmp);
42896           fnaddr = gen_const_mem (Pmode, tmp);
42897         }
42898     }
42899   else
42900     {
42901       if (!flag_pic || targetm.binds_local_p (function))
42902         ;
42903 #if TARGET_MACHO
42904       else if (TARGET_MACHO)
42905         {
42906           fnaddr = machopic_indirect_call_target (DECL_RTL (function));
42907           fnaddr = XEXP (fnaddr, 0);
42908         }
42909 #endif /* TARGET_MACHO */
42910       else
42911         {
42912           tmp = gen_rtx_REG (Pmode, CX_REG);
42913           output_set_got (tmp, NULL_RTX);
42914
42915           fnaddr = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, fnaddr), UNSPEC_GOT);
42916           fnaddr = gen_rtx_CONST (Pmode, fnaddr);
42917           fnaddr = gen_rtx_PLUS (Pmode, tmp, fnaddr);
42918           fnaddr = gen_const_mem (Pmode, fnaddr);
42919         }
42920     }
42921
42922   /* Our sibling call patterns do not allow memories, because we have no
42923      predicate that can distinguish between frame and non-frame memory.
42924      For our purposes here, we can get away with (ab)using a jump pattern,
42925      because we're going to do no optimization.  */
42926   if (MEM_P (fnaddr))
42927     {
42928       if (sibcall_insn_operand (fnaddr, word_mode))
42929         {
42930           fnaddr = XEXP (DECL_RTL (function), 0);
42931           tmp = gen_rtx_MEM (QImode, fnaddr);
42932           tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
42933           tmp = emit_call_insn (tmp);
42934           SIBLING_CALL_P (tmp) = 1;
42935         }
42936       else
42937         emit_jump_insn (gen_indirect_jump (fnaddr));
42938     }
42939   else
42940     {
42941       if (ix86_cmodel == CM_LARGE_PIC && SYMBOLIC_CONST (fnaddr))
42942         {
42943           // CM_LARGE_PIC always uses pseudo PIC register which is
42944           // uninitialized.  Since FUNCTION is local and calling it
42945           // doesn't go through PLT, we use scratch register %r11 as
42946           // PIC register and initialize it here.
42947           pic_offset_table_rtx = gen_rtx_REG (Pmode, R11_REG);
42948           ix86_init_large_pic_reg (tmp_regno);
42949           fnaddr = legitimize_pic_address (fnaddr,
42950                                            gen_rtx_REG (Pmode, tmp_regno));
42951         }
42952
42953       if (!sibcall_insn_operand (fnaddr, word_mode))
42954         {
42955           tmp = gen_rtx_REG (word_mode, tmp_regno);
42956           if (GET_MODE (fnaddr) != word_mode)
42957             fnaddr = gen_rtx_ZERO_EXTEND (word_mode, fnaddr);
42958           emit_move_insn (tmp, fnaddr);
42959           fnaddr = tmp;
42960         }
42961
42962       tmp = gen_rtx_MEM (QImode, fnaddr);
42963       tmp = gen_rtx_CALL (VOIDmode, tmp, const0_rtx);
42964       tmp = emit_call_insn (tmp);
42965       SIBLING_CALL_P (tmp) = 1;
42966     }
42967   emit_barrier ();
42968
42969   /* Emit just enough of rest_of_compilation to get the insns emitted.
42970      Note that use_thunk calls assemble_start_function et al.  */
42971   insn = get_insns ();
42972   shorten_branches (insn);
42973   final_start_function (insn, file, 1);
42974   final (insn, file, 1);
42975   final_end_function ();
42976 }
42977
42978 static void
42979 x86_file_start (void)
42980 {
42981   default_file_start ();
42982   if (TARGET_16BIT)
42983     fputs ("\t.code16gcc\n", asm_out_file);
42984 #if TARGET_MACHO
42985   darwin_file_start ();
42986 #endif
42987   if (X86_FILE_START_VERSION_DIRECTIVE)
42988     fputs ("\t.version\t\"01.01\"\n", asm_out_file);
42989   if (X86_FILE_START_FLTUSED)
42990     fputs ("\t.global\t__fltused\n", asm_out_file);
42991   if (ix86_asm_dialect == ASM_INTEL)
42992     fputs ("\t.intel_syntax noprefix\n", asm_out_file);
42993 }
42994
42995 int
42996 x86_field_alignment (tree field, int computed)
42997 {
42998   machine_mode mode;
42999   tree type = TREE_TYPE (field);
43000
43001   if (TARGET_64BIT || TARGET_ALIGN_DOUBLE)
43002     return computed;
43003   mode = TYPE_MODE (strip_array_types (type));
43004   if (mode == DFmode || mode == DCmode
43005       || GET_MODE_CLASS (mode) == MODE_INT
43006       || GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
43007     return MIN (32, computed);
43008   return computed;
43009 }
43010
43011 /* Print call to TARGET to FILE.  */
43012
43013 static void
43014 x86_print_call_or_nop (FILE *file, const char *target)
43015 {
43016   if (flag_nop_mcount)
43017     fprintf (file, "1:\tnopl 0x00(%%eax,%%eax,1)\n"); /* 5 byte nop.  */
43018   else
43019     fprintf (file, "1:\tcall\t%s\n", target);
43020 }
43021
43022 /* Output assembler code to FILE to increment profiler label # LABELNO
43023    for profiling a function entry.  */
43024 void
43025 x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED)
43026 {
43027   const char *mcount_name = (flag_fentry ? MCOUNT_NAME_BEFORE_PROLOGUE
43028                                          : MCOUNT_NAME);
43029   if (TARGET_64BIT)
43030     {
43031 #ifndef NO_PROFILE_COUNTERS
43032       fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno);
43033 #endif
43034
43035       if (!TARGET_PECOFF && flag_pic)
43036         fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name);
43037       else
43038         x86_print_call_or_nop (file, mcount_name);
43039     }
43040   else if (flag_pic)
43041     {
43042 #ifndef NO_PROFILE_COUNTERS
43043       fprintf (file, "\tleal\t%sP%d@GOTOFF(%%ebx),%%" PROFILE_COUNT_REGISTER "\n",
43044                LPREFIX, labelno);
43045 #endif
43046       fprintf (file, "1:\tcall\t*%s@GOT(%%ebx)\n", mcount_name);
43047     }
43048   else
43049     {
43050 #ifndef NO_PROFILE_COUNTERS
43051       fprintf (file, "\tmovl\t$%sP%d,%%" PROFILE_COUNT_REGISTER "\n",
43052                LPREFIX, labelno);
43053 #endif
43054       x86_print_call_or_nop (file, mcount_name);
43055     }
43056
43057   if (flag_record_mcount)
43058     {
43059       fprintf (file, "\t.section __mcount_loc, \"a\",@progbits\n");
43060       fprintf (file, "\t.%s 1b\n", TARGET_64BIT ? "quad" : "long");
43061       fprintf (file, "\t.previous\n");
43062     }
43063 }
43064
43065 /* We don't have exact information about the insn sizes, but we may assume
43066    quite safely that we are informed about all 1 byte insns and memory
43067    address sizes.  This is enough to eliminate unnecessary padding in
43068    99% of cases.  */
43069
43070 static int
43071 min_insn_size (rtx_insn *insn)
43072 {
43073   int l = 0, len;
43074
43075   if (!INSN_P (insn) || !active_insn_p (insn))
43076     return 0;
43077
43078   /* Discard alignments we've emit and jump instructions.  */
43079   if (GET_CODE (PATTERN (insn)) == UNSPEC_VOLATILE
43080       && XINT (PATTERN (insn), 1) == UNSPECV_ALIGN)
43081     return 0;
43082
43083   /* Important case - calls are always 5 bytes.
43084      It is common to have many calls in the row.  */
43085   if (CALL_P (insn)
43086       && symbolic_reference_mentioned_p (PATTERN (insn))
43087       && !SIBLING_CALL_P (insn))
43088     return 5;
43089   len = get_attr_length (insn);
43090   if (len <= 1)
43091     return 1;
43092
43093   /* For normal instructions we rely on get_attr_length being exact,
43094      with a few exceptions.  */
43095   if (!JUMP_P (insn))
43096     {
43097       enum attr_type type = get_attr_type (insn);
43098
43099       switch (type)
43100         {
43101         case TYPE_MULTI:
43102           if (GET_CODE (PATTERN (insn)) == ASM_INPUT
43103               || asm_noperands (PATTERN (insn)) >= 0)
43104             return 0;
43105           break;
43106         case TYPE_OTHER:
43107         case TYPE_FCMP:
43108           break;
43109         default:
43110           /* Otherwise trust get_attr_length.  */
43111           return len;
43112         }
43113
43114       l = get_attr_length_address (insn);
43115       if (l < 4 && symbolic_reference_mentioned_p (PATTERN (insn)))
43116         l = 4;
43117     }
43118   if (l)
43119     return 1+l;
43120   else
43121     return 2;
43122 }
43123
43124 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
43125
43126 /* AMD K8 core mispredicts jumps when there are more than 3 jumps in 16 byte
43127    window.  */
43128
43129 static void
43130 ix86_avoid_jump_mispredicts (void)
43131 {
43132   rtx_insn *insn, *start = get_insns ();
43133   int nbytes = 0, njumps = 0;
43134   bool isjump = false;
43135
43136   /* Look for all minimal intervals of instructions containing 4 jumps.
43137      The intervals are bounded by START and INSN.  NBYTES is the total
43138      size of instructions in the interval including INSN and not including
43139      START.  When the NBYTES is smaller than 16 bytes, it is possible
43140      that the end of START and INSN ends up in the same 16byte page.
43141
43142      The smallest offset in the page INSN can start is the case where START
43143      ends on the offset 0.  Offset of INSN is then NBYTES - sizeof (INSN).
43144      We add p2align to 16byte window with maxskip 15 - NBYTES + sizeof (INSN).
43145
43146      Don't consider asm goto as jump, while it can contain a jump, it doesn't
43147      have to, control transfer to label(s) can be performed through other
43148      means, and also we estimate minimum length of all asm stmts as 0.  */
43149   for (insn = start; insn; insn = NEXT_INSN (insn))
43150     {
43151       int min_size;
43152
43153       if (LABEL_P (insn))
43154         {
43155           int align = label_to_alignment (insn);
43156           int max_skip = label_to_max_skip (insn);
43157
43158           if (max_skip > 15)
43159             max_skip = 15;
43160           /* If align > 3, only up to 16 - max_skip - 1 bytes can be
43161              already in the current 16 byte page, because otherwise
43162              ASM_OUTPUT_MAX_SKIP_ALIGN could skip max_skip or fewer
43163              bytes to reach 16 byte boundary.  */
43164           if (align <= 0
43165               || (align <= 3 && max_skip != (1 << align) - 1))
43166             max_skip = 0;
43167           if (dump_file)
43168             fprintf (dump_file, "Label %i with max_skip %i\n",
43169                      INSN_UID (insn), max_skip);
43170           if (max_skip)
43171             {
43172               while (nbytes + max_skip >= 16)
43173                 {
43174                   start = NEXT_INSN (start);
43175                   if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
43176                       || CALL_P (start))
43177                     njumps--, isjump = true;
43178                   else
43179                     isjump = false;
43180                   nbytes -= min_insn_size (start);
43181                 }
43182             }
43183           continue;
43184         }
43185
43186       min_size = min_insn_size (insn);
43187       nbytes += min_size;
43188       if (dump_file)
43189         fprintf (dump_file, "Insn %i estimated to %i bytes\n",
43190                  INSN_UID (insn), min_size);
43191       if ((JUMP_P (insn) && asm_noperands (PATTERN (insn)) < 0)
43192           || CALL_P (insn))
43193         njumps++;
43194       else
43195         continue;
43196
43197       while (njumps > 3)
43198         {
43199           start = NEXT_INSN (start);
43200           if ((JUMP_P (start) && asm_noperands (PATTERN (start)) < 0)
43201               || CALL_P (start))
43202             njumps--, isjump = true;
43203           else
43204             isjump = false;
43205           nbytes -= min_insn_size (start);
43206         }
43207       gcc_assert (njumps >= 0);
43208       if (dump_file)
43209         fprintf (dump_file, "Interval %i to %i has %i bytes\n",
43210                  INSN_UID (start), INSN_UID (insn), nbytes);
43211
43212       if (njumps == 3 && isjump && nbytes < 16)
43213         {
43214           int padsize = 15 - nbytes + min_insn_size (insn);
43215
43216           if (dump_file)
43217             fprintf (dump_file, "Padding insn %i by %i bytes!\n",
43218                      INSN_UID (insn), padsize);
43219           emit_insn_before (gen_pad (GEN_INT (padsize)), insn);
43220         }
43221     }
43222 }
43223 #endif
43224
43225 /* AMD Athlon works faster
43226    when RET is not destination of conditional jump or directly preceded
43227    by other jump instruction.  We avoid the penalty by inserting NOP just
43228    before the RET instructions in such cases.  */
43229 static void
43230 ix86_pad_returns (void)
43231 {
43232   edge e;
43233   edge_iterator ei;
43234
43235   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
43236     {
43237       basic_block bb = e->src;
43238       rtx_insn *ret = BB_END (bb);
43239       rtx_insn *prev;
43240       bool replace = false;
43241
43242       if (!JUMP_P (ret) || !ANY_RETURN_P (PATTERN (ret))
43243           || optimize_bb_for_size_p (bb))
43244         continue;
43245       for (prev = PREV_INSN (ret); prev; prev = PREV_INSN (prev))
43246         if (active_insn_p (prev) || LABEL_P (prev))
43247           break;
43248       if (prev && LABEL_P (prev))
43249         {
43250           edge e;
43251           edge_iterator ei;
43252
43253           FOR_EACH_EDGE (e, ei, bb->preds)
43254             if (EDGE_FREQUENCY (e) && e->src->index >= 0
43255                 && !(e->flags & EDGE_FALLTHRU))
43256               {
43257                 replace = true;
43258                 break;
43259               }
43260         }
43261       if (!replace)
43262         {
43263           prev = prev_active_insn (ret);
43264           if (prev
43265               && ((JUMP_P (prev) && any_condjump_p (prev))
43266                   || CALL_P (prev)))
43267             replace = true;
43268           /* Empty functions get branch mispredict even when
43269              the jump destination is not visible to us.  */
43270           if (!prev && !optimize_function_for_size_p (cfun))
43271             replace = true;
43272         }
43273       if (replace)
43274         {
43275           emit_jump_insn_before (gen_simple_return_internal_long (), ret);
43276           delete_insn (ret);
43277         }
43278     }
43279 }
43280
43281 /* Count the minimum number of instructions in BB.  Return 4 if the
43282    number of instructions >= 4.  */
43283
43284 static int
43285 ix86_count_insn_bb (basic_block bb)
43286 {
43287   rtx_insn *insn;
43288   int insn_count = 0;
43289
43290   /* Count number of instructions in this block.  Return 4 if the number
43291      of instructions >= 4.  */
43292   FOR_BB_INSNS (bb, insn)
43293     {
43294       /* Only happen in exit blocks.  */
43295       if (JUMP_P (insn)
43296           && ANY_RETURN_P (PATTERN (insn)))
43297         break;
43298
43299       if (NONDEBUG_INSN_P (insn)
43300           && GET_CODE (PATTERN (insn)) != USE
43301           && GET_CODE (PATTERN (insn)) != CLOBBER)
43302         {
43303           insn_count++;
43304           if (insn_count >= 4)
43305             return insn_count;
43306         }
43307     }
43308
43309   return insn_count;
43310 }
43311
43312
43313 /* Count the minimum number of instructions in code path in BB.
43314    Return 4 if the number of instructions >= 4.  */
43315
43316 static int
43317 ix86_count_insn (basic_block bb)
43318 {
43319   edge e;
43320   edge_iterator ei;
43321   int min_prev_count;
43322
43323   /* Only bother counting instructions along paths with no
43324      more than 2 basic blocks between entry and exit.  Given
43325      that BB has an edge to exit, determine if a predecessor
43326      of BB has an edge from entry.  If so, compute the number
43327      of instructions in the predecessor block.  If there
43328      happen to be multiple such blocks, compute the minimum.  */
43329   min_prev_count = 4;
43330   FOR_EACH_EDGE (e, ei, bb->preds)
43331     {
43332       edge prev_e;
43333       edge_iterator prev_ei;
43334
43335       if (e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
43336         {
43337           min_prev_count = 0;
43338           break;
43339         }
43340       FOR_EACH_EDGE (prev_e, prev_ei, e->src->preds)
43341         {
43342           if (prev_e->src == ENTRY_BLOCK_PTR_FOR_FN (cfun))
43343             {
43344               int count = ix86_count_insn_bb (e->src);
43345               if (count < min_prev_count)
43346                 min_prev_count = count;
43347               break;
43348             }
43349         }
43350     }
43351
43352   if (min_prev_count < 4)
43353     min_prev_count += ix86_count_insn_bb (bb);
43354
43355   return min_prev_count;
43356 }
43357
43358 /* Pad short function to 4 instructions.   */
43359
43360 static void
43361 ix86_pad_short_function (void)
43362 {
43363   edge e;
43364   edge_iterator ei;
43365
43366   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
43367     {
43368       rtx_insn *ret = BB_END (e->src);
43369       if (JUMP_P (ret) && ANY_RETURN_P (PATTERN (ret)))
43370         {
43371           int insn_count = ix86_count_insn (e->src);
43372
43373           /* Pad short function.  */
43374           if (insn_count < 4)
43375             {
43376               rtx_insn *insn = ret;
43377
43378               /* Find epilogue.  */
43379               while (insn
43380                      && (!NOTE_P (insn)
43381                          || NOTE_KIND (insn) != NOTE_INSN_EPILOGUE_BEG))
43382                 insn = PREV_INSN (insn);
43383
43384               if (!insn)
43385                 insn = ret;
43386
43387               /* Two NOPs count as one instruction.  */
43388               insn_count = 2 * (4 - insn_count);
43389               emit_insn_before (gen_nops (GEN_INT (insn_count)), insn);
43390             }
43391         }
43392     }
43393 }
43394
43395 /* Fix up a Windows system unwinder issue.  If an EH region falls through into
43396    the epilogue, the Windows system unwinder will apply epilogue logic and
43397    produce incorrect offsets.  This can be avoided by adding a nop between
43398    the last insn that can throw and the first insn of the epilogue.  */
43399
43400 static void
43401 ix86_seh_fixup_eh_fallthru (void)
43402 {
43403   edge e;
43404   edge_iterator ei;
43405
43406   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
43407     {
43408       rtx_insn *insn, *next;
43409
43410       /* Find the beginning of the epilogue.  */
43411       for (insn = BB_END (e->src); insn != NULL; insn = PREV_INSN (insn))
43412         if (NOTE_P (insn) && NOTE_KIND (insn) == NOTE_INSN_EPILOGUE_BEG)
43413           break;
43414       if (insn == NULL)
43415         continue;
43416
43417       /* We only care about preceding insns that can throw.  */
43418       insn = prev_active_insn (insn);
43419       if (insn == NULL || !can_throw_internal (insn))
43420         continue;
43421
43422       /* Do not separate calls from their debug information.  */
43423       for (next = NEXT_INSN (insn); next != NULL; next = NEXT_INSN (next))
43424         if (NOTE_P (next)
43425             && (NOTE_KIND (next) == NOTE_INSN_VAR_LOCATION
43426                 || NOTE_KIND (next) == NOTE_INSN_CALL_ARG_LOCATION))
43427           insn = next;
43428         else
43429           break;
43430
43431       emit_insn_after (gen_nops (const1_rtx), insn);
43432     }
43433 }
43434
43435 /* Implement machine specific optimizations.  We implement padding of returns
43436    for K8 CPUs and pass to avoid 4 jumps in the single 16 byte window.  */
43437 static void
43438 ix86_reorg (void)
43439 {
43440   /* We are freeing block_for_insn in the toplev to keep compatibility
43441      with old MDEP_REORGS that are not CFG based.  Recompute it now.  */
43442   compute_bb_for_insn ();
43443
43444   if (TARGET_SEH && current_function_has_exception_handlers ())
43445     ix86_seh_fixup_eh_fallthru ();
43446
43447   if (optimize && optimize_function_for_speed_p (cfun))
43448     {
43449       if (TARGET_PAD_SHORT_FUNCTION)
43450         ix86_pad_short_function ();
43451       else if (TARGET_PAD_RETURNS)
43452         ix86_pad_returns ();
43453 #ifdef ASM_OUTPUT_MAX_SKIP_PAD
43454       if (TARGET_FOUR_JUMP_LIMIT)
43455         ix86_avoid_jump_mispredicts ();
43456 #endif
43457     }
43458 }
43459
43460 /* Return nonzero when QImode register that must be represented via REX prefix
43461    is used.  */
43462 bool
43463 x86_extended_QIreg_mentioned_p (rtx_insn *insn)
43464 {
43465   int i;
43466   extract_insn_cached (insn);
43467   for (i = 0; i < recog_data.n_operands; i++)
43468     if (GENERAL_REG_P (recog_data.operand[i])
43469         && !QI_REGNO_P (REGNO (recog_data.operand[i])))
43470        return true;
43471   return false;
43472 }
43473
43474 /* Return true when INSN mentions register that must be encoded using REX
43475    prefix.  */
43476 bool
43477 x86_extended_reg_mentioned_p (rtx insn)
43478 {
43479   subrtx_iterator::array_type array;
43480   FOR_EACH_SUBRTX (iter, array, INSN_P (insn) ? PATTERN (insn) : insn, NONCONST)
43481     {
43482       const_rtx x = *iter;
43483       if (REG_P (x)
43484           && (REX_INT_REGNO_P (REGNO (x)) || REX_SSE_REGNO_P (REGNO (x))))
43485         return true;
43486     }
43487   return false;
43488 }
43489
43490 /* If profitable, negate (without causing overflow) integer constant
43491    of mode MODE at location LOC.  Return true in this case.  */
43492 bool
43493 x86_maybe_negate_const_int (rtx *loc, machine_mode mode)
43494 {
43495   HOST_WIDE_INT val;
43496
43497   if (!CONST_INT_P (*loc))
43498     return false;
43499
43500   switch (mode)
43501     {
43502     case DImode:
43503       /* DImode x86_64 constants must fit in 32 bits.  */
43504       gcc_assert (x86_64_immediate_operand (*loc, mode));
43505
43506       mode = SImode;
43507       break;
43508
43509     case SImode:
43510     case HImode:
43511     case QImode:
43512       break;
43513
43514     default:
43515       gcc_unreachable ();
43516     }
43517
43518   /* Avoid overflows.  */
43519   if (mode_signbit_p (mode, *loc))
43520     return false;
43521
43522   val = INTVAL (*loc);
43523
43524   /* Make things pretty and `subl $4,%eax' rather than `addl $-4,%eax'.
43525      Exceptions: -128 encodes smaller than 128, so swap sign and op.  */
43526   if ((val < 0 && val != -128)
43527       || val == 128)
43528     {
43529       *loc = GEN_INT (-val);
43530       return true;
43531     }
43532
43533   return false;
43534 }
43535
43536 /* Generate an unsigned DImode/SImode to FP conversion.  This is the same code
43537    optabs would emit if we didn't have TFmode patterns.  */
43538
43539 void
43540 x86_emit_floatuns (rtx operands[2])
43541 {
43542   rtx_code_label *neglab, *donelab;
43543   rtx i0, i1, f0, in, out;
43544   machine_mode mode, inmode;
43545
43546   inmode = GET_MODE (operands[1]);
43547   gcc_assert (inmode == SImode || inmode == DImode);
43548
43549   out = operands[0];
43550   in = force_reg (inmode, operands[1]);
43551   mode = GET_MODE (out);
43552   neglab = gen_label_rtx ();
43553   donelab = gen_label_rtx ();
43554   f0 = gen_reg_rtx (mode);
43555
43556   emit_cmp_and_jump_insns (in, const0_rtx, LT, const0_rtx, inmode, 0, neglab);
43557
43558   expand_float (out, in, 0);
43559
43560   emit_jump_insn (gen_jump (donelab));
43561   emit_barrier ();
43562
43563   emit_label (neglab);
43564
43565   i0 = expand_simple_binop (inmode, LSHIFTRT, in, const1_rtx, NULL,
43566                             1, OPTAB_DIRECT);
43567   i1 = expand_simple_binop (inmode, AND, in, const1_rtx, NULL,
43568                             1, OPTAB_DIRECT);
43569   i0 = expand_simple_binop (inmode, IOR, i0, i1, i0, 1, OPTAB_DIRECT);
43570
43571   expand_float (f0, i0, 0);
43572
43573   emit_insn (gen_rtx_SET (VOIDmode, out, gen_rtx_PLUS (mode, f0, f0)));
43574
43575   emit_label (donelab);
43576 }
43577 \f
43578 static bool canonicalize_perm (struct expand_vec_perm_d *d);
43579 static bool expand_vec_perm_1 (struct expand_vec_perm_d *d);
43580 static bool expand_vec_perm_broadcast_1 (struct expand_vec_perm_d *d);
43581 static bool expand_vec_perm_palignr (struct expand_vec_perm_d *d, bool);
43582
43583 /* Get a vector mode of the same size as the original but with elements
43584    twice as wide.  This is only guaranteed to apply to integral vectors.  */
43585
43586 static inline machine_mode
43587 get_mode_wider_vector (machine_mode o)
43588 {
43589   /* ??? Rely on the ordering that genmodes.c gives to vectors.  */
43590   machine_mode n = GET_MODE_WIDER_MODE (o);
43591   gcc_assert (GET_MODE_NUNITS (o) == GET_MODE_NUNITS (n) * 2);
43592   gcc_assert (GET_MODE_SIZE (o) == GET_MODE_SIZE (n));
43593   return n;
43594 }
43595
43596 /* A subroutine of ix86_expand_vector_init_duplicate.  Tries to
43597    fill target with val via vec_duplicate.  */
43598
43599 static bool
43600 ix86_vector_duplicate_value (machine_mode mode, rtx target, rtx val)
43601 {
43602   bool ok;
43603   rtx_insn *insn;
43604   rtx dup;
43605
43606   /* First attempt to recognize VAL as-is.  */
43607   dup = gen_rtx_VEC_DUPLICATE (mode, val);
43608   insn = emit_insn (gen_rtx_SET (VOIDmode, target, dup));
43609   if (recog_memoized (insn) < 0)
43610     {
43611       rtx_insn *seq;
43612       /* If that fails, force VAL into a register.  */
43613
43614       start_sequence ();
43615       XEXP (dup, 0) = force_reg (GET_MODE_INNER (mode), val);
43616       seq = get_insns ();
43617       end_sequence ();
43618       if (seq)
43619         emit_insn_before (seq, insn);
43620
43621       ok = recog_memoized (insn) >= 0;
43622       gcc_assert (ok);
43623     }
43624   return true;
43625 }
43626
43627 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
43628    with all elements equal to VAR.  Return true if successful.  */
43629
43630 static bool
43631 ix86_expand_vector_init_duplicate (bool mmx_ok, machine_mode mode,
43632                                    rtx target, rtx val)
43633 {
43634   bool ok;
43635
43636   switch (mode)
43637     {
43638     case V2SImode:
43639     case V2SFmode:
43640       if (!mmx_ok)
43641         return false;
43642       /* FALLTHRU */
43643
43644     case V4DFmode:
43645     case V4DImode:
43646     case V8SFmode:
43647     case V8SImode:
43648     case V2DFmode:
43649     case V2DImode:
43650     case V4SFmode:
43651     case V4SImode:
43652     case V16SImode:
43653     case V8DImode:
43654     case V16SFmode:
43655     case V8DFmode:
43656       return ix86_vector_duplicate_value (mode, target, val);
43657
43658     case V4HImode:
43659       if (!mmx_ok)
43660         return false;
43661       if (TARGET_SSE || TARGET_3DNOW_A)
43662         {
43663           rtx x;
43664
43665           val = gen_lowpart (SImode, val);
43666           x = gen_rtx_TRUNCATE (HImode, val);
43667           x = gen_rtx_VEC_DUPLICATE (mode, x);
43668           emit_insn (gen_rtx_SET (VOIDmode, target, x));
43669           return true;
43670         }
43671       goto widen;
43672
43673     case V8QImode:
43674       if (!mmx_ok)
43675         return false;
43676       goto widen;
43677
43678     case V8HImode:
43679       if (TARGET_AVX2)
43680         return ix86_vector_duplicate_value (mode, target, val);
43681
43682       if (TARGET_SSE2)
43683         {
43684           struct expand_vec_perm_d dperm;
43685           rtx tmp1, tmp2;
43686
43687         permute:
43688           memset (&dperm, 0, sizeof (dperm));
43689           dperm.target = target;
43690           dperm.vmode = mode;
43691           dperm.nelt = GET_MODE_NUNITS (mode);
43692           dperm.op0 = dperm.op1 = gen_reg_rtx (mode);
43693           dperm.one_operand_p = true;
43694
43695           /* Extend to SImode using a paradoxical SUBREG.  */
43696           tmp1 = gen_reg_rtx (SImode);
43697           emit_move_insn (tmp1, gen_lowpart (SImode, val));
43698
43699           /* Insert the SImode value as low element of a V4SImode vector. */
43700           tmp2 = gen_reg_rtx (V4SImode);
43701           emit_insn (gen_vec_setv4si_0 (tmp2, CONST0_RTX (V4SImode), tmp1));
43702           emit_move_insn (dperm.op0, gen_lowpart (mode, tmp2));
43703
43704           ok = (expand_vec_perm_1 (&dperm)
43705                 || expand_vec_perm_broadcast_1 (&dperm));
43706           gcc_assert (ok);
43707           return ok;
43708         }
43709       goto widen;
43710
43711     case V16QImode:
43712       if (TARGET_AVX2)
43713         return ix86_vector_duplicate_value (mode, target, val);
43714
43715       if (TARGET_SSE2)
43716         goto permute;
43717       goto widen;
43718
43719     widen:
43720       /* Replicate the value once into the next wider mode and recurse.  */
43721       {
43722         machine_mode smode, wsmode, wvmode;
43723         rtx x;
43724
43725         smode = GET_MODE_INNER (mode);
43726         wvmode = get_mode_wider_vector (mode);
43727         wsmode = GET_MODE_INNER (wvmode);
43728
43729         val = convert_modes (wsmode, smode, val, true);
43730         x = expand_simple_binop (wsmode, ASHIFT, val,
43731                                  GEN_INT (GET_MODE_BITSIZE (smode)),
43732                                  NULL_RTX, 1, OPTAB_LIB_WIDEN);
43733         val = expand_simple_binop (wsmode, IOR, val, x, x, 1, OPTAB_LIB_WIDEN);
43734
43735         x = gen_reg_rtx (wvmode);
43736         ok = ix86_expand_vector_init_duplicate (mmx_ok, wvmode, x, val);
43737         gcc_assert (ok);
43738         emit_move_insn (target, gen_lowpart (GET_MODE (target), x));
43739         return ok;
43740       }
43741
43742     case V16HImode:
43743     case V32QImode:
43744       if (TARGET_AVX2)
43745         return ix86_vector_duplicate_value (mode, target, val);
43746       else
43747         {
43748           machine_mode hvmode = (mode == V16HImode ? V8HImode : V16QImode);
43749           rtx x = gen_reg_rtx (hvmode);
43750
43751           ok = ix86_expand_vector_init_duplicate (false, hvmode, x, val);
43752           gcc_assert (ok);
43753
43754           x = gen_rtx_VEC_CONCAT (mode, x, x);
43755           emit_insn (gen_rtx_SET (VOIDmode, target, x));
43756         }
43757       return true;
43758
43759     case V64QImode:
43760     case V32HImode:
43761       if (TARGET_AVX512BW)
43762         return ix86_vector_duplicate_value (mode, target, val);
43763       else
43764         {
43765           machine_mode hvmode = (mode == V32HImode ? V16HImode : V32QImode);
43766           rtx x = gen_reg_rtx (hvmode);
43767
43768           ok = ix86_expand_vector_init_duplicate (false, hvmode, x, val);
43769           gcc_assert (ok);
43770
43771           x = gen_rtx_VEC_CONCAT (mode, x, x);
43772           emit_insn (gen_rtx_SET (VOIDmode, target, x));
43773         }
43774       return true;
43775
43776     default:
43777       return false;
43778     }
43779 }
43780
43781 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
43782    whose ONE_VAR element is VAR, and other elements are zero.  Return true
43783    if successful.  */
43784
43785 static bool
43786 ix86_expand_vector_init_one_nonzero (bool mmx_ok, machine_mode mode,
43787                                      rtx target, rtx var, int one_var)
43788 {
43789   machine_mode vsimode;
43790   rtx new_target;
43791   rtx x, tmp;
43792   bool use_vector_set = false;
43793
43794   switch (mode)
43795     {
43796     case V2DImode:
43797       /* For SSE4.1, we normally use vector set.  But if the second
43798          element is zero and inter-unit moves are OK, we use movq
43799          instead.  */
43800       use_vector_set = (TARGET_64BIT && TARGET_SSE4_1
43801                         && !(TARGET_INTER_UNIT_MOVES_TO_VEC
43802                              && one_var == 0));
43803       break;
43804     case V16QImode:
43805     case V4SImode:
43806     case V4SFmode:
43807       use_vector_set = TARGET_SSE4_1;
43808       break;
43809     case V8HImode:
43810       use_vector_set = TARGET_SSE2;
43811       break;
43812     case V4HImode:
43813       use_vector_set = TARGET_SSE || TARGET_3DNOW_A;
43814       break;
43815     case V32QImode:
43816     case V16HImode:
43817     case V8SImode:
43818     case V8SFmode:
43819     case V4DFmode:
43820       use_vector_set = TARGET_AVX;
43821       break;
43822     case V4DImode:
43823       /* Use ix86_expand_vector_set in 64bit mode only.  */
43824       use_vector_set = TARGET_AVX && TARGET_64BIT;
43825       break;
43826     default:
43827       break;
43828     }
43829
43830   if (use_vector_set)
43831     {
43832       emit_insn (gen_rtx_SET (VOIDmode, target, CONST0_RTX (mode)));
43833       var = force_reg (GET_MODE_INNER (mode), var);
43834       ix86_expand_vector_set (mmx_ok, target, var, one_var);
43835       return true;
43836     }
43837
43838   switch (mode)
43839     {
43840     case V2SFmode:
43841     case V2SImode:
43842       if (!mmx_ok)
43843         return false;
43844       /* FALLTHRU */
43845
43846     case V2DFmode:
43847     case V2DImode:
43848       if (one_var != 0)
43849         return false;
43850       var = force_reg (GET_MODE_INNER (mode), var);
43851       x = gen_rtx_VEC_CONCAT (mode, var, CONST0_RTX (GET_MODE_INNER (mode)));
43852       emit_insn (gen_rtx_SET (VOIDmode, target, x));
43853       return true;
43854
43855     case V4SFmode:
43856     case V4SImode:
43857       if (!REG_P (target) || REGNO (target) < FIRST_PSEUDO_REGISTER)
43858         new_target = gen_reg_rtx (mode);
43859       else
43860         new_target = target;
43861       var = force_reg (GET_MODE_INNER (mode), var);
43862       x = gen_rtx_VEC_DUPLICATE (mode, var);
43863       x = gen_rtx_VEC_MERGE (mode, x, CONST0_RTX (mode), const1_rtx);
43864       emit_insn (gen_rtx_SET (VOIDmode, new_target, x));
43865       if (one_var != 0)
43866         {
43867           /* We need to shuffle the value to the correct position, so
43868              create a new pseudo to store the intermediate result.  */
43869
43870           /* With SSE2, we can use the integer shuffle insns.  */
43871           if (mode != V4SFmode && TARGET_SSE2)
43872             {
43873               emit_insn (gen_sse2_pshufd_1 (new_target, new_target,
43874                                             const1_rtx,
43875                                             GEN_INT (one_var == 1 ? 0 : 1),
43876                                             GEN_INT (one_var == 2 ? 0 : 1),
43877                                             GEN_INT (one_var == 3 ? 0 : 1)));
43878               if (target != new_target)
43879                 emit_move_insn (target, new_target);
43880               return true;
43881             }
43882
43883           /* Otherwise convert the intermediate result to V4SFmode and
43884              use the SSE1 shuffle instructions.  */
43885           if (mode != V4SFmode)
43886             {
43887               tmp = gen_reg_rtx (V4SFmode);
43888               emit_move_insn (tmp, gen_lowpart (V4SFmode, new_target));
43889             }
43890           else
43891             tmp = new_target;
43892
43893           emit_insn (gen_sse_shufps_v4sf (tmp, tmp, tmp,
43894                                        const1_rtx,
43895                                        GEN_INT (one_var == 1 ? 0 : 1),
43896                                        GEN_INT (one_var == 2 ? 0+4 : 1+4),
43897                                        GEN_INT (one_var == 3 ? 0+4 : 1+4)));
43898
43899           if (mode != V4SFmode)
43900             emit_move_insn (target, gen_lowpart (V4SImode, tmp));
43901           else if (tmp != target)
43902             emit_move_insn (target, tmp);
43903         }
43904       else if (target != new_target)
43905         emit_move_insn (target, new_target);
43906       return true;
43907
43908     case V8HImode:
43909     case V16QImode:
43910       vsimode = V4SImode;
43911       goto widen;
43912     case V4HImode:
43913     case V8QImode:
43914       if (!mmx_ok)
43915         return false;
43916       vsimode = V2SImode;
43917       goto widen;
43918     widen:
43919       if (one_var != 0)
43920         return false;
43921
43922       /* Zero extend the variable element to SImode and recurse.  */
43923       var = convert_modes (SImode, GET_MODE_INNER (mode), var, true);
43924
43925       x = gen_reg_rtx (vsimode);
43926       if (!ix86_expand_vector_init_one_nonzero (mmx_ok, vsimode, x,
43927                                                 var, one_var))
43928         gcc_unreachable ();
43929
43930       emit_move_insn (target, gen_lowpart (mode, x));
43931       return true;
43932
43933     default:
43934       return false;
43935     }
43936 }
43937
43938 /* A subroutine of ix86_expand_vector_init.  Store into TARGET a vector
43939    consisting of the values in VALS.  It is known that all elements
43940    except ONE_VAR are constants.  Return true if successful.  */
43941
43942 static bool
43943 ix86_expand_vector_init_one_var (bool mmx_ok, machine_mode mode,
43944                                  rtx target, rtx vals, int one_var)
43945 {
43946   rtx var = XVECEXP (vals, 0, one_var);
43947   machine_mode wmode;
43948   rtx const_vec, x;
43949
43950   const_vec = copy_rtx (vals);
43951   XVECEXP (const_vec, 0, one_var) = CONST0_RTX (GET_MODE_INNER (mode));
43952   const_vec = gen_rtx_CONST_VECTOR (mode, XVEC (const_vec, 0));
43953
43954   switch (mode)
43955     {
43956     case V2DFmode:
43957     case V2DImode:
43958     case V2SFmode:
43959     case V2SImode:
43960       /* For the two element vectors, it's just as easy to use
43961          the general case.  */
43962       return false;
43963
43964     case V4DImode:
43965       /* Use ix86_expand_vector_set in 64bit mode only.  */
43966       if (!TARGET_64BIT)
43967         return false;
43968     case V4DFmode:
43969     case V8SFmode:
43970     case V8SImode:
43971     case V16HImode:
43972     case V32QImode:
43973     case V4SFmode:
43974     case V4SImode:
43975     case V8HImode:
43976     case V4HImode:
43977       break;
43978
43979     case V16QImode:
43980       if (TARGET_SSE4_1)
43981         break;
43982       wmode = V8HImode;
43983       goto widen;
43984     case V8QImode:
43985       wmode = V4HImode;
43986       goto widen;
43987     widen:
43988       /* There's no way to set one QImode entry easily.  Combine
43989          the variable value with its adjacent constant value, and
43990          promote to an HImode set.  */
43991       x = XVECEXP (vals, 0, one_var ^ 1);
43992       if (one_var & 1)
43993         {
43994           var = convert_modes (HImode, QImode, var, true);
43995           var = expand_simple_binop (HImode, ASHIFT, var, GEN_INT (8),
43996                                      NULL_RTX, 1, OPTAB_LIB_WIDEN);
43997           x = GEN_INT (INTVAL (x) & 0xff);
43998         }
43999       else
44000         {
44001           var = convert_modes (HImode, QImode, var, true);
44002           x = gen_int_mode (INTVAL (x) << 8, HImode);
44003         }
44004       if (x != const0_rtx)
44005         var = expand_simple_binop (HImode, IOR, var, x, var,
44006                                    1, OPTAB_LIB_WIDEN);
44007
44008       x = gen_reg_rtx (wmode);
44009       emit_move_insn (x, gen_lowpart (wmode, const_vec));
44010       ix86_expand_vector_set (mmx_ok, x, var, one_var >> 1);
44011
44012       emit_move_insn (target, gen_lowpart (mode, x));
44013       return true;
44014
44015     default:
44016       return false;
44017     }
44018
44019   emit_move_insn (target, const_vec);
44020   ix86_expand_vector_set (mmx_ok, target, var, one_var);
44021   return true;
44022 }
44023
44024 /* A subroutine of ix86_expand_vector_init_general.  Use vector
44025    concatenate to handle the most general case: all values variable,
44026    and none identical.  */
44027
44028 static void
44029 ix86_expand_vector_init_concat (machine_mode mode,
44030                                 rtx target, rtx *ops, int n)
44031 {
44032   machine_mode cmode, hmode = VOIDmode, gmode = VOIDmode;
44033   rtx first[16], second[8], third[4];
44034   rtvec v;
44035   int i, j;
44036
44037   switch (n)
44038     {
44039     case 2:
44040       switch (mode)
44041         {
44042         case V16SImode:
44043           cmode = V8SImode;
44044           break;
44045         case V16SFmode:
44046           cmode = V8SFmode;
44047           break;
44048         case V8DImode:
44049           cmode = V4DImode;
44050           break;
44051         case V8DFmode:
44052           cmode = V4DFmode;
44053           break;
44054         case V8SImode:
44055           cmode = V4SImode;
44056           break;
44057         case V8SFmode:
44058           cmode = V4SFmode;
44059           break;
44060         case V4DImode:
44061           cmode = V2DImode;
44062           break;
44063         case V4DFmode:
44064           cmode = V2DFmode;
44065           break;
44066         case V4SImode:
44067           cmode = V2SImode;
44068           break;
44069         case V4SFmode:
44070           cmode = V2SFmode;
44071           break;
44072         case V2DImode:
44073           cmode = DImode;
44074           break;
44075         case V2SImode:
44076           cmode = SImode;
44077           break;
44078         case V2DFmode:
44079           cmode = DFmode;
44080           break;
44081         case V2SFmode:
44082           cmode = SFmode;
44083           break;
44084         default:
44085           gcc_unreachable ();
44086         }
44087
44088       if (!register_operand (ops[1], cmode))
44089         ops[1] = force_reg (cmode, ops[1]);
44090       if (!register_operand (ops[0], cmode))
44091         ops[0] = force_reg (cmode, ops[0]);
44092       emit_insn (gen_rtx_SET (VOIDmode, target,
44093                               gen_rtx_VEC_CONCAT (mode, ops[0],
44094                                                   ops[1])));
44095       break;
44096
44097     case 4:
44098       switch (mode)
44099         {
44100         case V4DImode:
44101           cmode = V2DImode;
44102           break;
44103         case V4DFmode:
44104           cmode = V2DFmode;
44105           break;
44106         case V4SImode:
44107           cmode = V2SImode;
44108           break;
44109         case V4SFmode:
44110           cmode = V2SFmode;
44111           break;
44112         default:
44113           gcc_unreachable ();
44114         }
44115       goto half;
44116
44117     case 8:
44118       switch (mode)
44119         {
44120         case V8DImode:
44121           cmode = V2DImode;
44122           hmode = V4DImode;
44123           break;
44124         case V8DFmode:
44125           cmode = V2DFmode;
44126           hmode = V4DFmode;
44127           break;
44128         case V8SImode:
44129           cmode = V2SImode;
44130           hmode = V4SImode;
44131           break;
44132         case V8SFmode:
44133           cmode = V2SFmode;
44134           hmode = V4SFmode;
44135           break;
44136         default:
44137           gcc_unreachable ();
44138         }
44139       goto half;
44140
44141     case 16:
44142       switch (mode)
44143         {
44144         case V16SImode:
44145           cmode = V2SImode;
44146           hmode = V4SImode;
44147           gmode = V8SImode;
44148           break;
44149         case V16SFmode:
44150           cmode = V2SFmode;
44151           hmode = V4SFmode;
44152           gmode = V8SFmode;
44153           break;
44154         default:
44155           gcc_unreachable ();
44156         }
44157       goto half;
44158
44159 half:
44160       /* FIXME: We process inputs backward to help RA.  PR 36222.  */
44161       i = n - 1;
44162       j = (n >> 1) - 1;
44163       for (; i > 0; i -= 2, j--)
44164         {
44165           first[j] = gen_reg_rtx (cmode);
44166           v = gen_rtvec (2, ops[i - 1], ops[i]);
44167           ix86_expand_vector_init (false, first[j],
44168                                    gen_rtx_PARALLEL (cmode, v));
44169         }
44170
44171       n >>= 1;
44172       if (n > 4)
44173         {
44174           gcc_assert (hmode != VOIDmode);
44175           gcc_assert (gmode != VOIDmode);
44176           for (i = j = 0; i < n; i += 2, j++)
44177             {
44178               second[j] = gen_reg_rtx (hmode);
44179               ix86_expand_vector_init_concat (hmode, second [j],
44180                                               &first [i], 2);
44181             }
44182           n >>= 1;
44183           for (i = j = 0; i < n; i += 2, j++)
44184             {
44185               third[j] = gen_reg_rtx (gmode);
44186               ix86_expand_vector_init_concat (gmode, third[j],
44187                                               &second[i], 2);
44188             }
44189           n >>= 1;
44190           ix86_expand_vector_init_concat (mode, target, third, n);
44191         }
44192       else if (n > 2)
44193         {
44194           gcc_assert (hmode != VOIDmode);
44195           for (i = j = 0; i < n; i += 2, j++)
44196             {
44197               second[j] = gen_reg_rtx (hmode);
44198               ix86_expand_vector_init_concat (hmode, second [j],
44199                                               &first [i], 2);
44200             }
44201           n >>= 1;
44202           ix86_expand_vector_init_concat (mode, target, second, n);
44203         }
44204       else
44205         ix86_expand_vector_init_concat (mode, target, first, n);
44206       break;
44207
44208     default:
44209       gcc_unreachable ();
44210     }
44211 }
44212
44213 /* A subroutine of ix86_expand_vector_init_general.  Use vector
44214    interleave to handle the most general case: all values variable,
44215    and none identical.  */
44216
44217 static void
44218 ix86_expand_vector_init_interleave (machine_mode mode,
44219                                     rtx target, rtx *ops, int n)
44220 {
44221   machine_mode first_imode, second_imode, third_imode, inner_mode;
44222   int i, j;
44223   rtx op0, op1;
44224   rtx (*gen_load_even) (rtx, rtx, rtx);
44225   rtx (*gen_interleave_first_low) (rtx, rtx, rtx);
44226   rtx (*gen_interleave_second_low) (rtx, rtx, rtx);
44227
44228   switch (mode)
44229     {
44230     case V8HImode:
44231       gen_load_even = gen_vec_setv8hi;
44232       gen_interleave_first_low = gen_vec_interleave_lowv4si;
44233       gen_interleave_second_low = gen_vec_interleave_lowv2di;
44234       inner_mode = HImode;
44235       first_imode = V4SImode;
44236       second_imode = V2DImode;
44237       third_imode = VOIDmode;
44238       break;
44239     case V16QImode:
44240       gen_load_even = gen_vec_setv16qi;
44241       gen_interleave_first_low = gen_vec_interleave_lowv8hi;
44242       gen_interleave_second_low = gen_vec_interleave_lowv4si;
44243       inner_mode = QImode;
44244       first_imode = V8HImode;
44245       second_imode = V4SImode;
44246       third_imode = V2DImode;
44247       break;
44248     default:
44249       gcc_unreachable ();
44250     }
44251
44252   for (i = 0; i < n; i++)
44253     {
44254       /* Extend the odd elment to SImode using a paradoxical SUBREG.  */
44255       op0 = gen_reg_rtx (SImode);
44256       emit_move_insn (op0, gen_lowpart (SImode, ops [i + i]));
44257
44258       /* Insert the SImode value as low element of V4SImode vector. */
44259       op1 = gen_reg_rtx (V4SImode);
44260       op0 = gen_rtx_VEC_MERGE (V4SImode,
44261                                gen_rtx_VEC_DUPLICATE (V4SImode,
44262                                                       op0),
44263                                CONST0_RTX (V4SImode),
44264                                const1_rtx);
44265       emit_insn (gen_rtx_SET (VOIDmode, op1, op0));
44266
44267       /* Cast the V4SImode vector back to a vector in orignal mode.  */
44268       op0 = gen_reg_rtx (mode);
44269       emit_move_insn (op0, gen_lowpart (mode, op1));
44270
44271       /* Load even elements into the second position.  */
44272       emit_insn (gen_load_even (op0,
44273                                 force_reg (inner_mode,
44274                                            ops [i + i + 1]),
44275                                 const1_rtx));
44276
44277       /* Cast vector to FIRST_IMODE vector.  */
44278       ops[i] = gen_reg_rtx (first_imode);
44279       emit_move_insn (ops[i], gen_lowpart (first_imode, op0));
44280     }
44281
44282   /* Interleave low FIRST_IMODE vectors.  */
44283   for (i = j = 0; i < n; i += 2, j++)
44284     {
44285       op0 = gen_reg_rtx (first_imode);
44286       emit_insn (gen_interleave_first_low (op0, ops[i], ops[i + 1]));
44287
44288       /* Cast FIRST_IMODE vector to SECOND_IMODE vector.  */
44289       ops[j] = gen_reg_rtx (second_imode);
44290       emit_move_insn (ops[j], gen_lowpart (second_imode, op0));
44291     }
44292
44293   /* Interleave low SECOND_IMODE vectors.  */
44294   switch (second_imode)
44295     {
44296     case V4SImode:
44297       for (i = j = 0; i < n / 2; i += 2, j++)
44298         {
44299           op0 = gen_reg_rtx (second_imode);
44300           emit_insn (gen_interleave_second_low (op0, ops[i],
44301                                                 ops[i + 1]));
44302
44303           /* Cast the SECOND_IMODE vector to the THIRD_IMODE
44304              vector.  */
44305           ops[j] = gen_reg_rtx (third_imode);
44306           emit_move_insn (ops[j], gen_lowpart (third_imode, op0));
44307         }
44308       second_imode = V2DImode;
44309       gen_interleave_second_low = gen_vec_interleave_lowv2di;
44310       /* FALLTHRU */
44311
44312     case V2DImode:
44313       op0 = gen_reg_rtx (second_imode);
44314       emit_insn (gen_interleave_second_low (op0, ops[0],
44315                                             ops[1]));
44316
44317       /* Cast the SECOND_IMODE vector back to a vector on original
44318          mode.  */
44319       emit_insn (gen_rtx_SET (VOIDmode, target,
44320                               gen_lowpart (mode, op0)));
44321       break;
44322
44323     default:
44324       gcc_unreachable ();
44325     }
44326 }
44327
44328 /* A subroutine of ix86_expand_vector_init.  Handle the most general case:
44329    all values variable, and none identical.  */
44330
44331 static void
44332 ix86_expand_vector_init_general (bool mmx_ok, machine_mode mode,
44333                                  rtx target, rtx vals)
44334 {
44335   rtx ops[64], op0, op1, op2, op3, op4, op5;
44336   machine_mode half_mode = VOIDmode;
44337   machine_mode quarter_mode = VOIDmode;
44338   int n, i;
44339
44340   switch (mode)
44341     {
44342     case V2SFmode:
44343     case V2SImode:
44344       if (!mmx_ok && !TARGET_SSE)
44345         break;
44346       /* FALLTHRU */
44347
44348     case V16SImode:
44349     case V16SFmode:
44350     case V8DFmode:
44351     case V8DImode:
44352     case V8SFmode:
44353     case V8SImode:
44354     case V4DFmode:
44355     case V4DImode:
44356     case V4SFmode:
44357     case V4SImode:
44358     case V2DFmode:
44359     case V2DImode:
44360       n = GET_MODE_NUNITS (mode);
44361       for (i = 0; i < n; i++)
44362         ops[i] = XVECEXP (vals, 0, i);
44363       ix86_expand_vector_init_concat (mode, target, ops, n);
44364       return;
44365
44366     case V32QImode:
44367       half_mode = V16QImode;
44368       goto half;
44369
44370     case V16HImode:
44371       half_mode = V8HImode;
44372       goto half;
44373
44374 half:
44375       n = GET_MODE_NUNITS (mode);
44376       for (i = 0; i < n; i++)
44377         ops[i] = XVECEXP (vals, 0, i);
44378       op0 = gen_reg_rtx (half_mode);
44379       op1 = gen_reg_rtx (half_mode);
44380       ix86_expand_vector_init_interleave (half_mode, op0, ops,
44381                                           n >> 2);
44382       ix86_expand_vector_init_interleave (half_mode, op1,
44383                                           &ops [n >> 1], n >> 2);
44384       emit_insn (gen_rtx_SET (VOIDmode, target,
44385                               gen_rtx_VEC_CONCAT (mode, op0, op1)));
44386       return;
44387
44388     case V64QImode:
44389       quarter_mode = V16QImode;
44390       half_mode = V32QImode;
44391       goto quarter;
44392
44393     case V32HImode:
44394       quarter_mode = V8HImode;
44395       half_mode = V16HImode;
44396       goto quarter;
44397
44398 quarter:
44399       n = GET_MODE_NUNITS (mode);
44400       for (i = 0; i < n; i++)
44401         ops[i] = XVECEXP (vals, 0, i);
44402       op0 = gen_reg_rtx (quarter_mode);
44403       op1 = gen_reg_rtx (quarter_mode);
44404       op2 = gen_reg_rtx (quarter_mode);
44405       op3 = gen_reg_rtx (quarter_mode);
44406       op4 = gen_reg_rtx (half_mode);
44407       op5 = gen_reg_rtx (half_mode);
44408       ix86_expand_vector_init_interleave (quarter_mode, op0, ops,
44409                                           n >> 3);
44410       ix86_expand_vector_init_interleave (quarter_mode, op1,
44411                                           &ops [n >> 2], n >> 3);
44412       ix86_expand_vector_init_interleave (quarter_mode, op2,
44413                                           &ops [n >> 1], n >> 3);
44414       ix86_expand_vector_init_interleave (quarter_mode, op3,
44415                                           &ops [(n >> 1) | (n >> 2)], n >> 3);
44416       emit_insn (gen_rtx_SET (VOIDmode, op4,
44417                               gen_rtx_VEC_CONCAT (half_mode, op0, op1)));
44418       emit_insn (gen_rtx_SET (VOIDmode, op5,
44419                               gen_rtx_VEC_CONCAT (half_mode, op2, op3)));
44420       emit_insn (gen_rtx_SET (VOIDmode, target,
44421                               gen_rtx_VEC_CONCAT (mode, op4, op5)));
44422       return;
44423
44424     case V16QImode:
44425       if (!TARGET_SSE4_1)
44426         break;
44427       /* FALLTHRU */
44428
44429     case V8HImode:
44430       if (!TARGET_SSE2)
44431         break;
44432
44433       /* Don't use ix86_expand_vector_init_interleave if we can't
44434          move from GPR to SSE register directly.  */
44435       if (!TARGET_INTER_UNIT_MOVES_TO_VEC)
44436         break;
44437
44438       n = GET_MODE_NUNITS (mode);
44439       for (i = 0; i < n; i++)
44440         ops[i] = XVECEXP (vals, 0, i);
44441       ix86_expand_vector_init_interleave (mode, target, ops, n >> 1);
44442       return;
44443
44444     case V4HImode:
44445     case V8QImode:
44446       break;
44447
44448     default:
44449       gcc_unreachable ();
44450     }
44451
44452     {
44453       int i, j, n_elts, n_words, n_elt_per_word;
44454       machine_mode inner_mode;
44455       rtx words[4], shift;
44456
44457       inner_mode = GET_MODE_INNER (mode);
44458       n_elts = GET_MODE_NUNITS (mode);
44459       n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
44460       n_elt_per_word = n_elts / n_words;
44461       shift = GEN_INT (GET_MODE_BITSIZE (inner_mode));
44462
44463       for (i = 0; i < n_words; ++i)
44464         {
44465           rtx word = NULL_RTX;
44466
44467           for (j = 0; j < n_elt_per_word; ++j)
44468             {
44469               rtx elt = XVECEXP (vals, 0, (i+1)*n_elt_per_word - j - 1);
44470               elt = convert_modes (word_mode, inner_mode, elt, true);
44471
44472               if (j == 0)
44473                 word = elt;
44474               else
44475                 {
44476                   word = expand_simple_binop (word_mode, ASHIFT, word, shift,
44477                                               word, 1, OPTAB_LIB_WIDEN);
44478                   word = expand_simple_binop (word_mode, IOR, word, elt,
44479                                               word, 1, OPTAB_LIB_WIDEN);
44480                 }
44481             }
44482
44483           words[i] = word;
44484         }
44485
44486       if (n_words == 1)
44487         emit_move_insn (target, gen_lowpart (mode, words[0]));
44488       else if (n_words == 2)
44489         {
44490           rtx tmp = gen_reg_rtx (mode);
44491           emit_clobber (tmp);
44492           emit_move_insn (gen_lowpart (word_mode, tmp), words[0]);
44493           emit_move_insn (gen_highpart (word_mode, tmp), words[1]);
44494           emit_move_insn (target, tmp);
44495         }
44496       else if (n_words == 4)
44497         {
44498           rtx tmp = gen_reg_rtx (V4SImode);
44499           gcc_assert (word_mode == SImode);
44500           vals = gen_rtx_PARALLEL (V4SImode, gen_rtvec_v (4, words));
44501           ix86_expand_vector_init_general (false, V4SImode, tmp, vals);
44502           emit_move_insn (target, gen_lowpart (mode, tmp));
44503         }
44504       else
44505         gcc_unreachable ();
44506     }
44507 }
44508
44509 /* Initialize vector TARGET via VALS.  Suppress the use of MMX
44510    instructions unless MMX_OK is true.  */
44511
44512 void
44513 ix86_expand_vector_init (bool mmx_ok, rtx target, rtx vals)
44514 {
44515   machine_mode mode = GET_MODE (target);
44516   machine_mode inner_mode = GET_MODE_INNER (mode);
44517   int n_elts = GET_MODE_NUNITS (mode);
44518   int n_var = 0, one_var = -1;
44519   bool all_same = true, all_const_zero = true;
44520   int i;
44521   rtx x;
44522
44523   for (i = 0; i < n_elts; ++i)
44524     {
44525       x = XVECEXP (vals, 0, i);
44526       if (!(CONST_INT_P (x)
44527             || GET_CODE (x) == CONST_DOUBLE
44528             || GET_CODE (x) == CONST_FIXED))
44529         n_var++, one_var = i;
44530       else if (x != CONST0_RTX (inner_mode))
44531         all_const_zero = false;
44532       if (i > 0 && !rtx_equal_p (x, XVECEXP (vals, 0, 0)))
44533         all_same = false;
44534     }
44535
44536   /* Constants are best loaded from the constant pool.  */
44537   if (n_var == 0)
44538     {
44539       emit_move_insn (target, gen_rtx_CONST_VECTOR (mode, XVEC (vals, 0)));
44540       return;
44541     }
44542
44543   /* If all values are identical, broadcast the value.  */
44544   if (all_same
44545       && ix86_expand_vector_init_duplicate (mmx_ok, mode, target,
44546                                             XVECEXP (vals, 0, 0)))
44547     return;
44548
44549   /* Values where only one field is non-constant are best loaded from
44550      the pool and overwritten via move later.  */
44551   if (n_var == 1)
44552     {
44553       if (all_const_zero
44554           && ix86_expand_vector_init_one_nonzero (mmx_ok, mode, target,
44555                                                   XVECEXP (vals, 0, one_var),
44556                                                   one_var))
44557         return;
44558
44559       if (ix86_expand_vector_init_one_var (mmx_ok, mode, target, vals, one_var))
44560         return;
44561     }
44562
44563   ix86_expand_vector_init_general (mmx_ok, mode, target, vals);
44564 }
44565
44566 void
44567 ix86_expand_vector_set (bool mmx_ok, rtx target, rtx val, int elt)
44568 {
44569   machine_mode mode = GET_MODE (target);
44570   machine_mode inner_mode = GET_MODE_INNER (mode);
44571   machine_mode half_mode;
44572   bool use_vec_merge = false;
44573   rtx tmp;
44574   static rtx (*gen_extract[6][2]) (rtx, rtx)
44575     = {
44576         { gen_vec_extract_lo_v32qi, gen_vec_extract_hi_v32qi },
44577         { gen_vec_extract_lo_v16hi, gen_vec_extract_hi_v16hi },
44578         { gen_vec_extract_lo_v8si, gen_vec_extract_hi_v8si },
44579         { gen_vec_extract_lo_v4di, gen_vec_extract_hi_v4di },
44580         { gen_vec_extract_lo_v8sf, gen_vec_extract_hi_v8sf },
44581         { gen_vec_extract_lo_v4df, gen_vec_extract_hi_v4df }
44582       };
44583   static rtx (*gen_insert[6][2]) (rtx, rtx, rtx)
44584     = {
44585         { gen_vec_set_lo_v32qi, gen_vec_set_hi_v32qi },
44586         { gen_vec_set_lo_v16hi, gen_vec_set_hi_v16hi },
44587         { gen_vec_set_lo_v8si, gen_vec_set_hi_v8si },
44588         { gen_vec_set_lo_v4di, gen_vec_set_hi_v4di },
44589         { gen_vec_set_lo_v8sf, gen_vec_set_hi_v8sf },
44590         { gen_vec_set_lo_v4df, gen_vec_set_hi_v4df }
44591       };
44592   int i, j, n;
44593
44594   switch (mode)
44595     {
44596     case V2SFmode:
44597     case V2SImode:
44598       if (mmx_ok)
44599         {
44600           tmp = gen_reg_rtx (GET_MODE_INNER (mode));
44601           ix86_expand_vector_extract (true, tmp, target, 1 - elt);
44602           if (elt == 0)
44603             tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
44604           else
44605             tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
44606           emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
44607           return;
44608         }
44609       break;
44610
44611     case V2DImode:
44612       use_vec_merge = TARGET_SSE4_1 && TARGET_64BIT;
44613       if (use_vec_merge)
44614         break;
44615
44616       tmp = gen_reg_rtx (GET_MODE_INNER (mode));
44617       ix86_expand_vector_extract (false, tmp, target, 1 - elt);
44618       if (elt == 0)
44619         tmp = gen_rtx_VEC_CONCAT (mode, val, tmp);
44620       else
44621         tmp = gen_rtx_VEC_CONCAT (mode, tmp, val);
44622       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
44623       return;
44624
44625     case V2DFmode:
44626       {
44627         rtx op0, op1;
44628
44629         /* For the two element vectors, we implement a VEC_CONCAT with
44630            the extraction of the other element.  */
44631
44632         tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (1 - elt)));
44633         tmp = gen_rtx_VEC_SELECT (inner_mode, target, tmp);
44634
44635         if (elt == 0)
44636           op0 = val, op1 = tmp;
44637         else
44638           op0 = tmp, op1 = val;
44639
44640         tmp = gen_rtx_VEC_CONCAT (mode, op0, op1);
44641         emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
44642       }
44643       return;
44644
44645     case V4SFmode:
44646       use_vec_merge = TARGET_SSE4_1;
44647       if (use_vec_merge)
44648         break;
44649
44650       switch (elt)
44651         {
44652         case 0:
44653           use_vec_merge = true;
44654           break;
44655
44656         case 1:
44657           /* tmp = target = A B C D */
44658           tmp = copy_to_reg (target);
44659           /* target = A A B B */
44660           emit_insn (gen_vec_interleave_lowv4sf (target, target, target));
44661           /* target = X A B B */
44662           ix86_expand_vector_set (false, target, val, 0);
44663           /* target = A X C D  */
44664           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
44665                                           const1_rtx, const0_rtx,
44666                                           GEN_INT (2+4), GEN_INT (3+4)));
44667           return;
44668
44669         case 2:
44670           /* tmp = target = A B C D */
44671           tmp = copy_to_reg (target);
44672           /* tmp = X B C D */
44673           ix86_expand_vector_set (false, tmp, val, 0);
44674           /* target = A B X D */
44675           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
44676                                           const0_rtx, const1_rtx,
44677                                           GEN_INT (0+4), GEN_INT (3+4)));
44678           return;
44679
44680         case 3:
44681           /* tmp = target = A B C D */
44682           tmp = copy_to_reg (target);
44683           /* tmp = X B C D */
44684           ix86_expand_vector_set (false, tmp, val, 0);
44685           /* target = A B X D */
44686           emit_insn (gen_sse_shufps_v4sf (target, target, tmp,
44687                                           const0_rtx, const1_rtx,
44688                                           GEN_INT (2+4), GEN_INT (0+4)));
44689           return;
44690
44691         default:
44692           gcc_unreachable ();
44693         }
44694       break;
44695
44696     case V4SImode:
44697       use_vec_merge = TARGET_SSE4_1;
44698       if (use_vec_merge)
44699         break;
44700
44701       /* Element 0 handled by vec_merge below.  */
44702       if (elt == 0)
44703         {
44704           use_vec_merge = true;
44705           break;
44706         }
44707
44708       if (TARGET_SSE2)
44709         {
44710           /* With SSE2, use integer shuffles to swap element 0 and ELT,
44711              store into element 0, then shuffle them back.  */
44712
44713           rtx order[4];
44714
44715           order[0] = GEN_INT (elt);
44716           order[1] = const1_rtx;
44717           order[2] = const2_rtx;
44718           order[3] = GEN_INT (3);
44719           order[elt] = const0_rtx;
44720
44721           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
44722                                         order[1], order[2], order[3]));
44723
44724           ix86_expand_vector_set (false, target, val, 0);
44725
44726           emit_insn (gen_sse2_pshufd_1 (target, target, order[0],
44727                                         order[1], order[2], order[3]));
44728         }
44729       else
44730         {
44731           /* For SSE1, we have to reuse the V4SF code.  */
44732           rtx t = gen_reg_rtx (V4SFmode);
44733           ix86_expand_vector_set (false, t, gen_lowpart (SFmode, val), elt);
44734           emit_move_insn (target, gen_lowpart (mode, t));
44735         }
44736       return;
44737
44738     case V8HImode:
44739       use_vec_merge = TARGET_SSE2;
44740       break;
44741     case V4HImode:
44742       use_vec_merge = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
44743       break;
44744
44745     case V16QImode:
44746       use_vec_merge = TARGET_SSE4_1;
44747       break;
44748
44749     case V8QImode:
44750       break;
44751
44752     case V32QImode:
44753       half_mode = V16QImode;
44754       j = 0;
44755       n = 16;
44756       goto half;
44757
44758     case V16HImode:
44759       half_mode = V8HImode;
44760       j = 1;
44761       n = 8;
44762       goto half;
44763
44764     case V8SImode:
44765       half_mode = V4SImode;
44766       j = 2;
44767       n = 4;
44768       goto half;
44769
44770     case V4DImode:
44771       half_mode = V2DImode;
44772       j = 3;
44773       n = 2;
44774       goto half;
44775
44776     case V8SFmode:
44777       half_mode = V4SFmode;
44778       j = 4;
44779       n = 4;
44780       goto half;
44781
44782     case V4DFmode:
44783       half_mode = V2DFmode;
44784       j = 5;
44785       n = 2;
44786       goto half;
44787
44788 half:
44789       /* Compute offset.  */
44790       i = elt / n;
44791       elt %= n;
44792
44793       gcc_assert (i <= 1);
44794
44795       /* Extract the half.  */
44796       tmp = gen_reg_rtx (half_mode);
44797       emit_insn (gen_extract[j][i] (tmp, target));
44798
44799       /* Put val in tmp at elt.  */
44800       ix86_expand_vector_set (false, tmp, val, elt);
44801
44802       /* Put it back.  */
44803       emit_insn (gen_insert[j][i] (target, target, tmp));
44804       return;
44805
44806     case V8DFmode:
44807       if (TARGET_AVX512F)
44808         {
44809           tmp = gen_reg_rtx (mode);
44810           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44811                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44812           emit_insn (gen_avx512f_blendmv8df (target, tmp, target,
44813                                              force_reg (QImode, GEN_INT (1 << elt))));
44814           return;
44815         }
44816       else
44817         break;
44818     case V8DImode:
44819       if (TARGET_AVX512F)
44820         {
44821           tmp = gen_reg_rtx (mode);
44822           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44823                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44824           emit_insn (gen_avx512f_blendmv8di (target, tmp, target,
44825                                              force_reg (QImode, GEN_INT (1 << elt))));
44826           return;
44827         }
44828       else
44829         break;
44830     case V16SFmode:
44831       if (TARGET_AVX512F)
44832         {
44833           tmp = gen_reg_rtx (mode);
44834           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44835                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44836           emit_insn (gen_avx512f_blendmv16sf (target, tmp, target,
44837                                               force_reg (HImode, GEN_INT (1 << elt))));
44838           return;
44839         }
44840       else
44841         break;
44842     case V16SImode:
44843       if (TARGET_AVX512F)
44844         {
44845           tmp = gen_reg_rtx (mode);
44846           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44847                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44848           emit_insn (gen_avx512f_blendmv16si (target, tmp, target,
44849                                               force_reg (HImode, GEN_INT (1 << elt))));
44850           return;
44851         }
44852       else
44853         break;
44854     case V32HImode:
44855       if (TARGET_AVX512F && TARGET_AVX512BW)
44856         {
44857           tmp = gen_reg_rtx (mode);
44858           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44859                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44860           emit_insn (gen_avx512bw_blendmv32hi (target, tmp, target,
44861                                                force_reg (SImode, GEN_INT (1 << elt))));
44862           return;
44863         }
44864       else
44865         break;
44866     case V64QImode:
44867       if (TARGET_AVX512F && TARGET_AVX512BW)
44868         {
44869           tmp = gen_reg_rtx (mode);
44870           emit_insn (gen_rtx_SET (VOIDmode, tmp,
44871                                   gen_rtx_VEC_DUPLICATE (mode, val)));
44872           emit_insn (gen_avx512bw_blendmv64qi (target, tmp, target,
44873                                                force_reg (DImode, GEN_INT (1 << elt))));
44874           return;
44875         }
44876       else
44877         break;
44878
44879     default:
44880       break;
44881     }
44882
44883   if (use_vec_merge)
44884     {
44885       tmp = gen_rtx_VEC_DUPLICATE (mode, val);
44886       tmp = gen_rtx_VEC_MERGE (mode, tmp, target, GEN_INT (1 << elt));
44887       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
44888     }
44889   else
44890     {
44891       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
44892
44893       emit_move_insn (mem, target);
44894
44895       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
44896       emit_move_insn (tmp, val);
44897
44898       emit_move_insn (target, mem);
44899     }
44900 }
44901
44902 void
44903 ix86_expand_vector_extract (bool mmx_ok, rtx target, rtx vec, int elt)
44904 {
44905   machine_mode mode = GET_MODE (vec);
44906   machine_mode inner_mode = GET_MODE_INNER (mode);
44907   bool use_vec_extr = false;
44908   rtx tmp;
44909
44910   switch (mode)
44911     {
44912     case V2SImode:
44913     case V2SFmode:
44914       if (!mmx_ok)
44915         break;
44916       /* FALLTHRU */
44917
44918     case V2DFmode:
44919     case V2DImode:
44920       use_vec_extr = true;
44921       break;
44922
44923     case V4SFmode:
44924       use_vec_extr = TARGET_SSE4_1;
44925       if (use_vec_extr)
44926         break;
44927
44928       switch (elt)
44929         {
44930         case 0:
44931           tmp = vec;
44932           break;
44933
44934         case 1:
44935         case 3:
44936           tmp = gen_reg_rtx (mode);
44937           emit_insn (gen_sse_shufps_v4sf (tmp, vec, vec,
44938                                        GEN_INT (elt), GEN_INT (elt),
44939                                        GEN_INT (elt+4), GEN_INT (elt+4)));
44940           break;
44941
44942         case 2:
44943           tmp = gen_reg_rtx (mode);
44944           emit_insn (gen_vec_interleave_highv4sf (tmp, vec, vec));
44945           break;
44946
44947         default:
44948           gcc_unreachable ();
44949         }
44950       vec = tmp;
44951       use_vec_extr = true;
44952       elt = 0;
44953       break;
44954
44955     case V4SImode:
44956       use_vec_extr = TARGET_SSE4_1;
44957       if (use_vec_extr)
44958         break;
44959
44960       if (TARGET_SSE2)
44961         {
44962           switch (elt)
44963             {
44964             case 0:
44965               tmp = vec;
44966               break;
44967
44968             case 1:
44969             case 3:
44970               tmp = gen_reg_rtx (mode);
44971               emit_insn (gen_sse2_pshufd_1 (tmp, vec,
44972                                             GEN_INT (elt), GEN_INT (elt),
44973                                             GEN_INT (elt), GEN_INT (elt)));
44974               break;
44975
44976             case 2:
44977               tmp = gen_reg_rtx (mode);
44978               emit_insn (gen_vec_interleave_highv4si (tmp, vec, vec));
44979               break;
44980
44981             default:
44982               gcc_unreachable ();
44983             }
44984           vec = tmp;
44985           use_vec_extr = true;
44986           elt = 0;
44987         }
44988       else
44989         {
44990           /* For SSE1, we have to reuse the V4SF code.  */
44991           ix86_expand_vector_extract (false, gen_lowpart (SFmode, target),
44992                                       gen_lowpart (V4SFmode, vec), elt);
44993           return;
44994         }
44995       break;
44996
44997     case V8HImode:
44998       use_vec_extr = TARGET_SSE2;
44999       break;
45000     case V4HImode:
45001       use_vec_extr = mmx_ok && (TARGET_SSE || TARGET_3DNOW_A);
45002       break;
45003
45004     case V16QImode:
45005       use_vec_extr = TARGET_SSE4_1;
45006       break;
45007
45008     case V8SFmode:
45009       if (TARGET_AVX)
45010         {
45011           tmp = gen_reg_rtx (V4SFmode);
45012           if (elt < 4)
45013             emit_insn (gen_vec_extract_lo_v8sf (tmp, vec));
45014           else
45015             emit_insn (gen_vec_extract_hi_v8sf (tmp, vec));
45016           ix86_expand_vector_extract (false, target, tmp, elt & 3);
45017           return;
45018         }
45019       break;
45020
45021     case V4DFmode:
45022       if (TARGET_AVX)
45023         {
45024           tmp = gen_reg_rtx (V2DFmode);
45025           if (elt < 2)
45026             emit_insn (gen_vec_extract_lo_v4df (tmp, vec));
45027           else
45028             emit_insn (gen_vec_extract_hi_v4df (tmp, vec));
45029           ix86_expand_vector_extract (false, target, tmp, elt & 1);
45030           return;
45031         }
45032       break;
45033
45034     case V32QImode:
45035       if (TARGET_AVX)
45036         {
45037           tmp = gen_reg_rtx (V16QImode);
45038           if (elt < 16)
45039             emit_insn (gen_vec_extract_lo_v32qi (tmp, vec));
45040           else
45041             emit_insn (gen_vec_extract_hi_v32qi (tmp, vec));
45042           ix86_expand_vector_extract (false, target, tmp, elt & 15);
45043           return;
45044         }
45045       break;
45046
45047     case V16HImode:
45048       if (TARGET_AVX)
45049         {
45050           tmp = gen_reg_rtx (V8HImode);
45051           if (elt < 8)
45052             emit_insn (gen_vec_extract_lo_v16hi (tmp, vec));
45053           else
45054             emit_insn (gen_vec_extract_hi_v16hi (tmp, vec));
45055           ix86_expand_vector_extract (false, target, tmp, elt & 7);
45056           return;
45057         }
45058       break;
45059
45060     case V8SImode:
45061       if (TARGET_AVX)
45062         {
45063           tmp = gen_reg_rtx (V4SImode);
45064           if (elt < 4)
45065             emit_insn (gen_vec_extract_lo_v8si (tmp, vec));
45066           else
45067             emit_insn (gen_vec_extract_hi_v8si (tmp, vec));
45068           ix86_expand_vector_extract (false, target, tmp, elt & 3);
45069           return;
45070         }
45071       break;
45072
45073     case V4DImode:
45074       if (TARGET_AVX)
45075         {
45076           tmp = gen_reg_rtx (V2DImode);
45077           if (elt < 2)
45078             emit_insn (gen_vec_extract_lo_v4di (tmp, vec));
45079           else
45080             emit_insn (gen_vec_extract_hi_v4di (tmp, vec));
45081           ix86_expand_vector_extract (false, target, tmp, elt & 1);
45082           return;
45083         }
45084       break;
45085
45086     case V32HImode:
45087       if (TARGET_AVX512BW)
45088         {
45089           tmp = gen_reg_rtx (V16HImode);
45090           if (elt < 16)
45091             emit_insn (gen_vec_extract_lo_v32hi (tmp, vec));
45092           else
45093             emit_insn (gen_vec_extract_hi_v32hi (tmp, vec));
45094           ix86_expand_vector_extract (false, target, tmp, elt & 15);
45095           return;
45096         }
45097       break;
45098
45099     case V64QImode:
45100       if (TARGET_AVX512BW)
45101         {
45102           tmp = gen_reg_rtx (V32QImode);
45103           if (elt < 32)
45104             emit_insn (gen_vec_extract_lo_v64qi (tmp, vec));
45105           else
45106             emit_insn (gen_vec_extract_hi_v64qi (tmp, vec));
45107           ix86_expand_vector_extract (false, target, tmp, elt & 31);
45108           return;
45109         }
45110       break;
45111
45112     case V16SFmode:
45113       tmp = gen_reg_rtx (V8SFmode);
45114       if (elt < 8)
45115         emit_insn (gen_vec_extract_lo_v16sf (tmp, vec));
45116       else
45117         emit_insn (gen_vec_extract_hi_v16sf (tmp, vec));
45118       ix86_expand_vector_extract (false, target, tmp, elt & 7);
45119       return;
45120
45121     case V8DFmode:
45122       tmp = gen_reg_rtx (V4DFmode);
45123       if (elt < 4)
45124         emit_insn (gen_vec_extract_lo_v8df (tmp, vec));
45125       else
45126         emit_insn (gen_vec_extract_hi_v8df (tmp, vec));
45127       ix86_expand_vector_extract (false, target, tmp, elt & 3);
45128       return;
45129
45130     case V16SImode:
45131       tmp = gen_reg_rtx (V8SImode);
45132       if (elt < 8)
45133         emit_insn (gen_vec_extract_lo_v16si (tmp, vec));
45134       else
45135         emit_insn (gen_vec_extract_hi_v16si (tmp, vec));
45136       ix86_expand_vector_extract (false, target, tmp, elt & 7);
45137       return;
45138
45139     case V8DImode:
45140       tmp = gen_reg_rtx (V4DImode);
45141       if (elt < 4)
45142         emit_insn (gen_vec_extract_lo_v8di (tmp, vec));
45143       else
45144         emit_insn (gen_vec_extract_hi_v8di (tmp, vec));
45145       ix86_expand_vector_extract (false, target, tmp, elt & 3);
45146       return;
45147
45148     case V8QImode:
45149       /* ??? Could extract the appropriate HImode element and shift.  */
45150     default:
45151       break;
45152     }
45153
45154   if (use_vec_extr)
45155     {
45156       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, GEN_INT (elt)));
45157       tmp = gen_rtx_VEC_SELECT (inner_mode, vec, tmp);
45158
45159       /* Let the rtl optimizers know about the zero extension performed.  */
45160       if (inner_mode == QImode || inner_mode == HImode)
45161         {
45162           tmp = gen_rtx_ZERO_EXTEND (SImode, tmp);
45163           target = gen_lowpart (SImode, target);
45164         }
45165
45166       emit_insn (gen_rtx_SET (VOIDmode, target, tmp));
45167     }
45168   else
45169     {
45170       rtx mem = assign_stack_temp (mode, GET_MODE_SIZE (mode));
45171
45172       emit_move_insn (mem, vec);
45173
45174       tmp = adjust_address (mem, inner_mode, elt*GET_MODE_SIZE (inner_mode));
45175       emit_move_insn (target, tmp);
45176     }
45177 }
45178
45179 /* Generate code to copy vector bits i / 2 ... i - 1 from vector SRC
45180    to bits 0 ... i / 2 - 1 of vector DEST, which has the same mode.
45181    The upper bits of DEST are undefined, though they shouldn't cause
45182    exceptions (some bits from src or all zeros are ok).  */
45183
45184 static void
45185 emit_reduc_half (rtx dest, rtx src, int i)
45186 {
45187   rtx tem, d = dest;
45188   switch (GET_MODE (src))
45189     {
45190     case V4SFmode:
45191       if (i == 128)
45192         tem = gen_sse_movhlps (dest, src, src);
45193       else
45194         tem = gen_sse_shufps_v4sf (dest, src, src, const1_rtx, const1_rtx,
45195                                    GEN_INT (1 + 4), GEN_INT (1 + 4));
45196       break;
45197     case V2DFmode:
45198       tem = gen_vec_interleave_highv2df (dest, src, src);
45199       break;
45200     case V16QImode:
45201     case V8HImode:
45202     case V4SImode:
45203     case V2DImode:
45204       d = gen_reg_rtx (V1TImode);
45205       tem = gen_sse2_lshrv1ti3 (d, gen_lowpart (V1TImode, src),
45206                                 GEN_INT (i / 2));
45207       break;
45208     case V8SFmode:
45209       if (i == 256)
45210         tem = gen_avx_vperm2f128v8sf3 (dest, src, src, const1_rtx);
45211       else
45212         tem = gen_avx_shufps256 (dest, src, src,
45213                                  GEN_INT (i == 128 ? 2 + (3 << 2) : 1));
45214       break;
45215     case V4DFmode:
45216       if (i == 256)
45217         tem = gen_avx_vperm2f128v4df3 (dest, src, src, const1_rtx);
45218       else
45219         tem = gen_avx_shufpd256 (dest, src, src, const1_rtx);
45220       break;
45221     case V32QImode:
45222     case V16HImode:
45223     case V8SImode:
45224     case V4DImode:
45225       if (i == 256)
45226         {
45227           if (GET_MODE (dest) != V4DImode)
45228             d = gen_reg_rtx (V4DImode);
45229           tem = gen_avx2_permv2ti (d, gen_lowpart (V4DImode, src),
45230                                    gen_lowpart (V4DImode, src),
45231                                    const1_rtx);
45232         }
45233       else
45234         {
45235           d = gen_reg_rtx (V2TImode);
45236           tem = gen_avx2_lshrv2ti3 (d, gen_lowpart (V2TImode, src),
45237                                     GEN_INT (i / 2));
45238         }
45239       break;
45240     case V64QImode:
45241     case V32HImode:
45242     case V16SImode:
45243     case V16SFmode:
45244     case V8DImode:
45245     case V8DFmode:
45246       if (i > 128)
45247         tem = gen_avx512f_shuf_i32x4_1 (gen_lowpart (V16SImode, dest),
45248                                       gen_lowpart (V16SImode, src),
45249                                       gen_lowpart (V16SImode, src),
45250                                       GEN_INT (0x4 + (i == 512 ? 4 : 0)),
45251                                       GEN_INT (0x5 + (i == 512 ? 4 : 0)),
45252                                       GEN_INT (0x6 + (i == 512 ? 4 : 0)),
45253                                       GEN_INT (0x7 + (i == 512 ? 4 : 0)),
45254                                       GEN_INT (0xC), GEN_INT (0xD),
45255                                       GEN_INT (0xE), GEN_INT (0xF),
45256                                       GEN_INT (0x10), GEN_INT (0x11),
45257                                       GEN_INT (0x12), GEN_INT (0x13),
45258                                       GEN_INT (0x14), GEN_INT (0x15),
45259                                       GEN_INT (0x16), GEN_INT (0x17));
45260       else
45261         tem = gen_avx512f_pshufd_1 (gen_lowpart (V16SImode, dest),
45262                                    gen_lowpart (V16SImode, src),
45263                                    GEN_INT (i == 128 ? 0x2 : 0x1),
45264                                    GEN_INT (0x3),
45265                                    GEN_INT (0x3),
45266                                    GEN_INT (0x3),
45267                                    GEN_INT (i == 128 ? 0x6 : 0x5),
45268                                    GEN_INT (0x7),
45269                                    GEN_INT (0x7),
45270                                    GEN_INT (0x7),
45271                                    GEN_INT (i == 128 ? 0xA : 0x9),
45272                                    GEN_INT (0xB),
45273                                    GEN_INT (0xB),
45274                                    GEN_INT (0xB),
45275                                    GEN_INT (i == 128 ? 0xE : 0xD),
45276                                    GEN_INT (0xF),
45277                                    GEN_INT (0xF),
45278                                    GEN_INT (0xF));
45279       break;
45280     default:
45281       gcc_unreachable ();
45282     }
45283   emit_insn (tem);
45284   if (d != dest)
45285     emit_move_insn (dest, gen_lowpart (GET_MODE (dest), d));
45286 }
45287
45288 /* Expand a vector reduction.  FN is the binary pattern to reduce;
45289    DEST is the destination; IN is the input vector.  */
45290
45291 void
45292 ix86_expand_reduc (rtx (*fn) (rtx, rtx, rtx), rtx dest, rtx in)
45293 {
45294   rtx half, dst, vec = in;
45295   machine_mode mode = GET_MODE (in);
45296   int i;
45297
45298   /* SSE4 has a special instruction for V8HImode UMIN reduction.  */
45299   if (TARGET_SSE4_1
45300       && mode == V8HImode
45301       && fn == gen_uminv8hi3)
45302     {
45303       emit_insn (gen_sse4_1_phminposuw (dest, in));
45304       return;
45305     }
45306
45307   for (i = GET_MODE_BITSIZE (mode);
45308        i > GET_MODE_BITSIZE (GET_MODE_INNER (mode));
45309        i >>= 1)
45310     {
45311       half = gen_reg_rtx (mode);
45312       emit_reduc_half (half, vec, i);
45313       if (i == GET_MODE_BITSIZE (GET_MODE_INNER (mode)) * 2)
45314         dst = dest;
45315       else
45316         dst = gen_reg_rtx (mode);
45317       emit_insn (fn (dst, half, vec));
45318       vec = dst;
45319     }
45320 }
45321 \f
45322 /* Target hook for scalar_mode_supported_p.  */
45323 static bool
45324 ix86_scalar_mode_supported_p (machine_mode mode)
45325 {
45326   if (DECIMAL_FLOAT_MODE_P (mode))
45327     return default_decimal_float_supported_p ();
45328   else if (mode == TFmode)
45329     return true;
45330   else
45331     return default_scalar_mode_supported_p (mode);
45332 }
45333
45334 /* Implements target hook vector_mode_supported_p.  */
45335 static bool
45336 ix86_vector_mode_supported_p (machine_mode mode)
45337 {
45338   if (TARGET_SSE && VALID_SSE_REG_MODE (mode))
45339     return true;
45340   if (TARGET_SSE2 && VALID_SSE2_REG_MODE (mode))
45341     return true;
45342   if (TARGET_AVX && VALID_AVX256_REG_MODE (mode))
45343     return true;
45344   if (TARGET_AVX512F && VALID_AVX512F_REG_MODE (mode))
45345     return true;
45346   if (TARGET_MMX && VALID_MMX_REG_MODE (mode))
45347     return true;
45348   if (TARGET_3DNOW && VALID_MMX_REG_MODE_3DNOW (mode))
45349     return true;
45350   return false;
45351 }
45352
45353 /* Implement target hook libgcc_floating_mode_supported_p.  */
45354 static bool
45355 ix86_libgcc_floating_mode_supported_p (machine_mode mode)
45356 {
45357   switch (mode)
45358     {
45359     case SFmode:
45360     case DFmode:
45361     case XFmode:
45362       return true;
45363
45364     case TFmode:
45365 #ifdef IX86_NO_LIBGCC_TFMODE
45366       return false;
45367 #elif defined IX86_MAYBE_NO_LIBGCC_TFMODE
45368       return TARGET_LONG_DOUBLE_128;
45369 #else
45370       return true;
45371 #endif
45372
45373     default:
45374       return false;
45375     }
45376 }
45377
45378 /* Target hook for c_mode_for_suffix.  */
45379 static machine_mode
45380 ix86_c_mode_for_suffix (char suffix)
45381 {
45382   if (suffix == 'q')
45383     return TFmode;
45384   if (suffix == 'w')
45385     return XFmode;
45386
45387   return VOIDmode;
45388 }
45389
45390 /* Worker function for TARGET_MD_ASM_CLOBBERS.
45391
45392    We do this in the new i386 backend to maintain source compatibility
45393    with the old cc0-based compiler.  */
45394
45395 static tree
45396 ix86_md_asm_clobbers (tree, tree, tree clobbers)
45397 {
45398   clobbers = tree_cons (NULL_TREE, build_string (5, "flags"),
45399                         clobbers);
45400   clobbers = tree_cons (NULL_TREE, build_string (4, "fpsr"),
45401                         clobbers);
45402   return clobbers;
45403 }
45404
45405 /* Implements target vector targetm.asm.encode_section_info.  */
45406
45407 static void ATTRIBUTE_UNUSED
45408 ix86_encode_section_info (tree decl, rtx rtl, int first)
45409 {
45410   default_encode_section_info (decl, rtl, first);
45411
45412   if (ix86_in_large_data_p (decl))
45413     SYMBOL_REF_FLAGS (XEXP (rtl, 0)) |= SYMBOL_FLAG_FAR_ADDR;
45414 }
45415
45416 /* Worker function for REVERSE_CONDITION.  */
45417
45418 enum rtx_code
45419 ix86_reverse_condition (enum rtx_code code, machine_mode mode)
45420 {
45421   return (mode != CCFPmode && mode != CCFPUmode
45422           ? reverse_condition (code)
45423           : reverse_condition_maybe_unordered (code));
45424 }
45425
45426 /* Output code to perform an x87 FP register move, from OPERANDS[1]
45427    to OPERANDS[0].  */
45428
45429 const char *
45430 output_387_reg_move (rtx insn, rtx *operands)
45431 {
45432   if (REG_P (operands[0]))
45433     {
45434       if (REG_P (operands[1])
45435           && find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
45436         {
45437           if (REGNO (operands[0]) == FIRST_STACK_REG)
45438             return output_387_ffreep (operands, 0);
45439           return "fstp\t%y0";
45440         }
45441       if (STACK_TOP_P (operands[0]))
45442         return "fld%Z1\t%y1";
45443       return "fst\t%y0";
45444     }
45445   else if (MEM_P (operands[0]))
45446     {
45447       gcc_assert (REG_P (operands[1]));
45448       if (find_regno_note (insn, REG_DEAD, REGNO (operands[1])))
45449         return "fstp%Z0\t%y0";
45450       else
45451         {
45452           /* There is no non-popping store to memory for XFmode.
45453              So if we need one, follow the store with a load.  */
45454           if (GET_MODE (operands[0]) == XFmode)
45455             return "fstp%Z0\t%y0\n\tfld%Z0\t%y0";
45456           else
45457             return "fst%Z0\t%y0";
45458         }
45459     }
45460   else
45461     gcc_unreachable();
45462 }
45463
45464 /* Output code to perform a conditional jump to LABEL, if C2 flag in
45465    FP status register is set.  */
45466
45467 void
45468 ix86_emit_fp_unordered_jump (rtx label)
45469 {
45470   rtx reg = gen_reg_rtx (HImode);
45471   rtx temp;
45472
45473   emit_insn (gen_x86_fnstsw_1 (reg));
45474
45475   if (TARGET_SAHF && (TARGET_USE_SAHF || optimize_insn_for_size_p ()))
45476     {
45477       emit_insn (gen_x86_sahf_1 (reg));
45478
45479       temp = gen_rtx_REG (CCmode, FLAGS_REG);
45480       temp = gen_rtx_UNORDERED (VOIDmode, temp, const0_rtx);
45481     }
45482   else
45483     {
45484       emit_insn (gen_testqi_ext_ccno_0 (reg, GEN_INT (0x04)));
45485
45486       temp = gen_rtx_REG (CCNOmode, FLAGS_REG);
45487       temp = gen_rtx_NE (VOIDmode, temp, const0_rtx);
45488     }
45489
45490   temp = gen_rtx_IF_THEN_ELSE (VOIDmode, temp,
45491                               gen_rtx_LABEL_REF (VOIDmode, label),
45492                               pc_rtx);
45493   temp = gen_rtx_SET (VOIDmode, pc_rtx, temp);
45494
45495   emit_jump_insn (temp);
45496   predict_jump (REG_BR_PROB_BASE * 10 / 100);
45497 }
45498
45499 /* Output code to perform a log1p XFmode calculation.  */
45500
45501 void ix86_emit_i387_log1p (rtx op0, rtx op1)
45502 {
45503   rtx_code_label *label1 = gen_label_rtx ();
45504   rtx_code_label *label2 = gen_label_rtx ();
45505
45506   rtx tmp = gen_reg_rtx (XFmode);
45507   rtx tmp2 = gen_reg_rtx (XFmode);
45508   rtx test;
45509
45510   emit_insn (gen_absxf2 (tmp, op1));
45511   test = gen_rtx_GE (VOIDmode, tmp,
45512     CONST_DOUBLE_FROM_REAL_VALUE (
45513        REAL_VALUE_ATOF ("0.29289321881345247561810596348408353", XFmode),
45514        XFmode));
45515   emit_jump_insn (gen_cbranchxf4 (test, XEXP (test, 0), XEXP (test, 1), label1));
45516
45517   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
45518   emit_insn (gen_fyl2xp1xf3_i387 (op0, op1, tmp2));
45519   emit_jump (label2);
45520
45521   emit_label (label1);
45522   emit_move_insn (tmp, CONST1_RTX (XFmode));
45523   emit_insn (gen_addxf3 (tmp, op1, tmp));
45524   emit_move_insn (tmp2, standard_80387_constant_rtx (4)); /* fldln2 */
45525   emit_insn (gen_fyl2xxf3_i387 (op0, tmp, tmp2));
45526
45527   emit_label (label2);
45528 }
45529
45530 /* Emit code for round calculation.  */
45531 void ix86_emit_i387_round (rtx op0, rtx op1)
45532 {
45533   machine_mode inmode = GET_MODE (op1);
45534   machine_mode outmode = GET_MODE (op0);
45535   rtx e1, e2, res, tmp, tmp1, half;
45536   rtx scratch = gen_reg_rtx (HImode);
45537   rtx flags = gen_rtx_REG (CCNOmode, FLAGS_REG);
45538   rtx_code_label *jump_label = gen_label_rtx ();
45539   rtx insn;
45540   rtx (*gen_abs) (rtx, rtx);
45541   rtx (*gen_neg) (rtx, rtx);
45542
45543   switch (inmode)
45544     {
45545     case SFmode:
45546       gen_abs = gen_abssf2;
45547       break;
45548     case DFmode:
45549       gen_abs = gen_absdf2;
45550       break;
45551     case XFmode:
45552       gen_abs = gen_absxf2;
45553       break;
45554     default:
45555       gcc_unreachable ();
45556     }
45557
45558   switch (outmode)
45559     {
45560     case SFmode:
45561       gen_neg = gen_negsf2;
45562       break;
45563     case DFmode:
45564       gen_neg = gen_negdf2;
45565       break;
45566     case XFmode:
45567       gen_neg = gen_negxf2;
45568       break;
45569     case HImode:
45570       gen_neg = gen_neghi2;
45571       break;
45572     case SImode:
45573       gen_neg = gen_negsi2;
45574       break;
45575     case DImode:
45576       gen_neg = gen_negdi2;
45577       break;
45578     default:
45579       gcc_unreachable ();
45580     }
45581
45582   e1 = gen_reg_rtx (inmode);
45583   e2 = gen_reg_rtx (inmode);
45584   res = gen_reg_rtx (outmode);
45585
45586   half = CONST_DOUBLE_FROM_REAL_VALUE (dconsthalf, inmode);
45587
45588   /* round(a) = sgn(a) * floor(fabs(a) + 0.5) */
45589
45590   /* scratch = fxam(op1) */
45591   emit_insn (gen_rtx_SET (VOIDmode, scratch,
45592                           gen_rtx_UNSPEC (HImode, gen_rtvec (1, op1),
45593                                           UNSPEC_FXAM)));
45594   /* e1 = fabs(op1) */
45595   emit_insn (gen_abs (e1, op1));
45596
45597   /* e2 = e1 + 0.5 */
45598   half = force_reg (inmode, half);
45599   emit_insn (gen_rtx_SET (VOIDmode, e2,
45600                           gen_rtx_PLUS (inmode, e1, half)));
45601
45602   /* res = floor(e2) */
45603   if (inmode != XFmode)
45604     {
45605       tmp1 = gen_reg_rtx (XFmode);
45606
45607       emit_insn (gen_rtx_SET (VOIDmode, tmp1,
45608                               gen_rtx_FLOAT_EXTEND (XFmode, e2)));
45609     }
45610   else
45611     tmp1 = e2;
45612
45613   switch (outmode)
45614     {
45615     case SFmode:
45616     case DFmode:
45617       {
45618         rtx tmp0 = gen_reg_rtx (XFmode);
45619
45620         emit_insn (gen_frndintxf2_floor (tmp0, tmp1));
45621
45622         emit_insn (gen_rtx_SET (VOIDmode, res,
45623                                 gen_rtx_UNSPEC (outmode, gen_rtvec (1, tmp0),
45624                                                 UNSPEC_TRUNC_NOOP)));
45625       }
45626       break;
45627     case XFmode:
45628       emit_insn (gen_frndintxf2_floor (res, tmp1));
45629       break;
45630     case HImode:
45631       emit_insn (gen_lfloorxfhi2 (res, tmp1));
45632       break;
45633     case SImode:
45634       emit_insn (gen_lfloorxfsi2 (res, tmp1));
45635       break;
45636     case DImode:
45637       emit_insn (gen_lfloorxfdi2 (res, tmp1));
45638         break;
45639     default:
45640       gcc_unreachable ();
45641     }
45642
45643   /* flags = signbit(a) */
45644   emit_insn (gen_testqi_ext_ccno_0 (scratch, GEN_INT (0x02)));
45645
45646   /* if (flags) then res = -res */
45647   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode,
45648                               gen_rtx_EQ (VOIDmode, flags, const0_rtx),
45649                               gen_rtx_LABEL_REF (VOIDmode, jump_label),
45650                               pc_rtx);
45651   insn = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
45652   predict_jump (REG_BR_PROB_BASE * 50 / 100);
45653   JUMP_LABEL (insn) = jump_label;
45654
45655   emit_insn (gen_neg (res, res));
45656
45657   emit_label (jump_label);
45658   LABEL_NUSES (jump_label) = 1;
45659
45660   emit_move_insn (op0, res);
45661 }
45662
45663 /* Output code to perform a Newton-Rhapson approximation of a single precision
45664    floating point divide [http://en.wikipedia.org/wiki/N-th_root_algorithm].  */
45665
45666 void ix86_emit_swdivsf (rtx res, rtx a, rtx b, machine_mode mode)
45667 {
45668   rtx x0, x1, e0, e1;
45669
45670   x0 = gen_reg_rtx (mode);
45671   e0 = gen_reg_rtx (mode);
45672   e1 = gen_reg_rtx (mode);
45673   x1 = gen_reg_rtx (mode);
45674
45675   /* a / b = a * ((rcp(b) + rcp(b)) - (b * rcp(b) * rcp (b))) */
45676
45677   b = force_reg (mode, b);
45678
45679   /* x0 = rcp(b) estimate */
45680   if (mode == V16SFmode || mode == V8DFmode)
45681     emit_insn (gen_rtx_SET (VOIDmode, x0,
45682                             gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
45683                                             UNSPEC_RCP14)));
45684   else
45685     emit_insn (gen_rtx_SET (VOIDmode, x0,
45686                             gen_rtx_UNSPEC (mode, gen_rtvec (1, b),
45687                                             UNSPEC_RCP)));
45688
45689   /* e0 = x0 * b */
45690   emit_insn (gen_rtx_SET (VOIDmode, e0,
45691                           gen_rtx_MULT (mode, x0, b)));
45692
45693   /* e0 = x0 * e0 */
45694   emit_insn (gen_rtx_SET (VOIDmode, e0,
45695                           gen_rtx_MULT (mode, x0, e0)));
45696
45697   /* e1 = x0 + x0 */
45698   emit_insn (gen_rtx_SET (VOIDmode, e1,
45699                           gen_rtx_PLUS (mode, x0, x0)));
45700
45701   /* x1 = e1 - e0 */
45702   emit_insn (gen_rtx_SET (VOIDmode, x1,
45703                           gen_rtx_MINUS (mode, e1, e0)));
45704
45705   /* res = a * x1 */
45706   emit_insn (gen_rtx_SET (VOIDmode, res,
45707                           gen_rtx_MULT (mode, a, x1)));
45708 }
45709
45710 /* Output code to perform a Newton-Rhapson approximation of a
45711    single precision floating point [reciprocal] square root.  */
45712
45713 void ix86_emit_swsqrtsf (rtx res, rtx a, machine_mode mode,
45714                          bool recip)
45715 {
45716   rtx x0, e0, e1, e2, e3, mthree, mhalf;
45717   REAL_VALUE_TYPE r;
45718   int unspec;
45719
45720   x0 = gen_reg_rtx (mode);
45721   e0 = gen_reg_rtx (mode);
45722   e1 = gen_reg_rtx (mode);
45723   e2 = gen_reg_rtx (mode);
45724   e3 = gen_reg_rtx (mode);
45725
45726   real_from_integer (&r, VOIDmode, -3, SIGNED);
45727   mthree = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
45728
45729   real_arithmetic (&r, NEGATE_EXPR, &dconsthalf, NULL);
45730   mhalf = CONST_DOUBLE_FROM_REAL_VALUE (r, SFmode);
45731   unspec = UNSPEC_RSQRT;
45732
45733   if (VECTOR_MODE_P (mode))
45734     {
45735       mthree = ix86_build_const_vector (mode, true, mthree);
45736       mhalf = ix86_build_const_vector (mode, true, mhalf);
45737       /* There is no 512-bit rsqrt.  There is however rsqrt14.  */
45738       if (GET_MODE_SIZE (mode) == 64)
45739         unspec = UNSPEC_RSQRT14;
45740     }
45741
45742   /* sqrt(a)  = -0.5 * a * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0)
45743      rsqrt(a) = -0.5     * rsqrtss(a) * (a * rsqrtss(a) * rsqrtss(a) - 3.0) */
45744
45745   a = force_reg (mode, a);
45746
45747   /* x0 = rsqrt(a) estimate */
45748   emit_insn (gen_rtx_SET (VOIDmode, x0,
45749                           gen_rtx_UNSPEC (mode, gen_rtvec (1, a),
45750                                           unspec)));
45751
45752   /* If (a == 0.0) Filter out infinity to prevent NaN for sqrt(0.0).  */
45753   if (!recip)
45754     {
45755       rtx zero, mask;
45756
45757       zero = gen_reg_rtx (mode);
45758       mask = gen_reg_rtx (mode);
45759
45760       zero = force_reg (mode, CONST0_RTX(mode));
45761
45762       /* Handle masked compare.  */
45763       if (VECTOR_MODE_P (mode) && GET_MODE_SIZE (mode) == 64)
45764         {
45765           mask = gen_reg_rtx (HImode);
45766           /* Imm value 0x4 corresponds to not-equal comparison.  */
45767           emit_insn (gen_avx512f_cmpv16sf3 (mask, zero, a, GEN_INT (0x4)));
45768           emit_insn (gen_avx512f_blendmv16sf (x0, zero, x0, mask));
45769         }
45770       else
45771         {
45772           emit_insn (gen_rtx_SET (VOIDmode, mask,
45773                                   gen_rtx_NE (mode, zero, a)));
45774
45775           emit_insn (gen_rtx_SET (VOIDmode, x0,
45776                                   gen_rtx_AND (mode, x0, mask)));
45777         }
45778     }
45779
45780   /* e0 = x0 * a */
45781   emit_insn (gen_rtx_SET (VOIDmode, e0,
45782                           gen_rtx_MULT (mode, x0, a)));
45783   /* e1 = e0 * x0 */
45784   emit_insn (gen_rtx_SET (VOIDmode, e1,
45785                           gen_rtx_MULT (mode, e0, x0)));
45786
45787   /* e2 = e1 - 3. */
45788   mthree = force_reg (mode, mthree);
45789   emit_insn (gen_rtx_SET (VOIDmode, e2,
45790                           gen_rtx_PLUS (mode, e1, mthree)));
45791
45792   mhalf = force_reg (mode, mhalf);
45793   if (recip)
45794     /* e3 = -.5 * x0 */
45795     emit_insn (gen_rtx_SET (VOIDmode, e3,
45796                             gen_rtx_MULT (mode, x0, mhalf)));
45797   else
45798     /* e3 = -.5 * e0 */
45799     emit_insn (gen_rtx_SET (VOIDmode, e3,
45800                             gen_rtx_MULT (mode, e0, mhalf)));
45801   /* ret = e2 * e3 */
45802   emit_insn (gen_rtx_SET (VOIDmode, res,
45803                           gen_rtx_MULT (mode, e2, e3)));
45804 }
45805
45806 #ifdef TARGET_SOLARIS
45807 /* Solaris implementation of TARGET_ASM_NAMED_SECTION.  */
45808
45809 static void
45810 i386_solaris_elf_named_section (const char *name, unsigned int flags,
45811                                 tree decl)
45812 {
45813   /* With Binutils 2.15, the "@unwind" marker must be specified on
45814      every occurrence of the ".eh_frame" section, not just the first
45815      one.  */
45816   if (TARGET_64BIT
45817       && strcmp (name, ".eh_frame") == 0)
45818     {
45819       fprintf (asm_out_file, "\t.section\t%s,\"%s\",@unwind\n", name,
45820                flags & SECTION_WRITE ? "aw" : "a");
45821       return;
45822     }
45823
45824 #ifndef USE_GAS
45825   if (HAVE_COMDAT_GROUP && flags & SECTION_LINKONCE)
45826     {
45827       solaris_elf_asm_comdat_section (name, flags, decl);
45828       return;
45829     }
45830 #endif
45831
45832   default_elf_asm_named_section (name, flags, decl);
45833 }
45834 #endif /* TARGET_SOLARIS */
45835
45836 /* Return the mangling of TYPE if it is an extended fundamental type.  */
45837
45838 static const char *
45839 ix86_mangle_type (const_tree type)
45840 {
45841   type = TYPE_MAIN_VARIANT (type);
45842
45843   if (TREE_CODE (type) != VOID_TYPE && TREE_CODE (type) != BOOLEAN_TYPE
45844       && TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
45845     return NULL;
45846
45847   switch (TYPE_MODE (type))
45848     {
45849     case TFmode:
45850       /* __float128 is "g".  */
45851       return "g";
45852     case XFmode:
45853       /* "long double" or __float80 is "e".  */
45854       return "e";
45855     default:
45856       return NULL;
45857     }
45858 }
45859
45860 /* For 32-bit code we can save PIC register setup by using
45861    __stack_chk_fail_local hidden function instead of calling
45862    __stack_chk_fail directly.  64-bit code doesn't need to setup any PIC
45863    register, so it is better to call __stack_chk_fail directly.  */
45864
45865 static tree ATTRIBUTE_UNUSED
45866 ix86_stack_protect_fail (void)
45867 {
45868   return TARGET_64BIT
45869          ? default_external_stack_protect_fail ()
45870          : default_hidden_stack_protect_fail ();
45871 }
45872
45873 /* Select a format to encode pointers in exception handling data.  CODE
45874    is 0 for data, 1 for code labels, 2 for function pointers.  GLOBAL is
45875    true if the symbol may be affected by dynamic relocations.
45876
45877    ??? All x86 object file formats are capable of representing this.
45878    After all, the relocation needed is the same as for the call insn.
45879    Whether or not a particular assembler allows us to enter such, I
45880    guess we'll have to see.  */
45881 int
45882 asm_preferred_eh_data_format (int code, int global)
45883 {
45884   if (flag_pic)
45885     {
45886       int type = DW_EH_PE_sdata8;
45887       if (!TARGET_64BIT
45888           || ix86_cmodel == CM_SMALL_PIC
45889           || (ix86_cmodel == CM_MEDIUM_PIC && (global || code)))
45890         type = DW_EH_PE_sdata4;
45891       return (global ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | type;
45892     }
45893   if (ix86_cmodel == CM_SMALL
45894       || (ix86_cmodel == CM_MEDIUM && code))
45895     return DW_EH_PE_udata4;
45896   return DW_EH_PE_absptr;
45897 }
45898 \f
45899 /* Expand copysign from SIGN to the positive value ABS_VALUE
45900    storing in RESULT.  If MASK is non-null, it shall be a mask to mask out
45901    the sign-bit.  */
45902 static void
45903 ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask)
45904 {
45905   machine_mode mode = GET_MODE (sign);
45906   rtx sgn = gen_reg_rtx (mode);
45907   if (mask == NULL_RTX)
45908     {
45909       machine_mode vmode;
45910
45911       if (mode == SFmode)
45912         vmode = V4SFmode;
45913       else if (mode == DFmode)
45914         vmode = V2DFmode;
45915       else
45916         vmode = mode;
45917
45918       mask = ix86_build_signbit_mask (vmode, VECTOR_MODE_P (mode), false);
45919       if (!VECTOR_MODE_P (mode))
45920         {
45921           /* We need to generate a scalar mode mask in this case.  */
45922           rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
45923           tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
45924           mask = gen_reg_rtx (mode);
45925           emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
45926         }
45927     }
45928   else
45929     mask = gen_rtx_NOT (mode, mask);
45930   emit_insn (gen_rtx_SET (VOIDmode, sgn,
45931                           gen_rtx_AND (mode, mask, sign)));
45932   emit_insn (gen_rtx_SET (VOIDmode, result,
45933                           gen_rtx_IOR (mode, abs_value, sgn)));
45934 }
45935
45936 /* Expand fabs (OP0) and return a new rtx that holds the result.  The
45937    mask for masking out the sign-bit is stored in *SMASK, if that is
45938    non-null.  */
45939 static rtx
45940 ix86_expand_sse_fabs (rtx op0, rtx *smask)
45941 {
45942   machine_mode vmode, mode = GET_MODE (op0);
45943   rtx xa, mask;
45944
45945   xa = gen_reg_rtx (mode);
45946   if (mode == SFmode)
45947     vmode = V4SFmode;
45948   else if (mode == DFmode)
45949     vmode = V2DFmode;
45950   else
45951     vmode = mode;
45952   mask = ix86_build_signbit_mask (vmode, VECTOR_MODE_P (mode), true);
45953   if (!VECTOR_MODE_P (mode))
45954     {
45955       /* We need to generate a scalar mode mask in this case.  */
45956       rtx tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (1, const0_rtx));
45957       tmp = gen_rtx_VEC_SELECT (mode, mask, tmp);
45958       mask = gen_reg_rtx (mode);
45959       emit_insn (gen_rtx_SET (VOIDmode, mask, tmp));
45960     }
45961   emit_insn (gen_rtx_SET (VOIDmode, xa,
45962                           gen_rtx_AND (mode, op0, mask)));
45963
45964   if (smask)
45965     *smask = mask;
45966
45967   return xa;
45968 }
45969
45970 /* Expands a comparison of OP0 with OP1 using comparison code CODE,
45971    swapping the operands if SWAP_OPERANDS is true.  The expanded
45972    code is a forward jump to a newly created label in case the
45973    comparison is true.  The generated label rtx is returned.  */
45974 static rtx_code_label *
45975 ix86_expand_sse_compare_and_jump (enum rtx_code code, rtx op0, rtx op1,
45976                                   bool swap_operands)
45977 {
45978   machine_mode fpcmp_mode = ix86_fp_compare_mode (code);
45979   rtx_code_label *label;
45980   rtx tmp;
45981
45982   if (swap_operands)
45983     std::swap (op0, op1);
45984
45985   label = gen_label_rtx ();
45986   tmp = gen_rtx_REG (fpcmp_mode, FLAGS_REG);
45987   emit_insn (gen_rtx_SET (VOIDmode, tmp,
45988                           gen_rtx_COMPARE (fpcmp_mode, op0, op1)));
45989   tmp = gen_rtx_fmt_ee (code, VOIDmode, tmp, const0_rtx);
45990   tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
45991                               gen_rtx_LABEL_REF (VOIDmode, label), pc_rtx);
45992   tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
45993   JUMP_LABEL (tmp) = label;
45994
45995   return label;
45996 }
45997
45998 /* Expand a mask generating SSE comparison instruction comparing OP0 with OP1
45999    using comparison code CODE.  Operands are swapped for the comparison if
46000    SWAP_OPERANDS is true.  Returns a rtx for the generated mask.  */
46001 static rtx
46002 ix86_expand_sse_compare_mask (enum rtx_code code, rtx op0, rtx op1,
46003                               bool swap_operands)
46004 {
46005   rtx (*insn)(rtx, rtx, rtx, rtx);
46006   machine_mode mode = GET_MODE (op0);
46007   rtx mask = gen_reg_rtx (mode);
46008
46009   if (swap_operands)
46010     std::swap (op0, op1);
46011
46012   insn = mode == DFmode ? gen_setcc_df_sse : gen_setcc_sf_sse;
46013
46014   emit_insn (insn (mask, op0, op1,
46015                    gen_rtx_fmt_ee (code, mode, op0, op1)));
46016   return mask;
46017 }
46018
46019 /* Generate and return a rtx of mode MODE for 2**n where n is the number
46020    of bits of the mantissa of MODE, which must be one of DFmode or SFmode.  */
46021 static rtx
46022 ix86_gen_TWO52 (machine_mode mode)
46023 {
46024   REAL_VALUE_TYPE TWO52r;
46025   rtx TWO52;
46026
46027   real_ldexp (&TWO52r, &dconst1, mode == DFmode ? 52 : 23);
46028   TWO52 = const_double_from_real_value (TWO52r, mode);
46029   TWO52 = force_reg (mode, TWO52);
46030
46031   return TWO52;
46032 }
46033
46034 /* Expand SSE sequence for computing lround from OP1 storing
46035    into OP0.  */
46036 void
46037 ix86_expand_lround (rtx op0, rtx op1)
46038 {
46039   /* C code for the stuff we're doing below:
46040        tmp = op1 + copysign (nextafter (0.5, 0.0), op1)
46041        return (long)tmp;
46042    */
46043   machine_mode mode = GET_MODE (op1);
46044   const struct real_format *fmt;
46045   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
46046   rtx adj;
46047
46048   /* load nextafter (0.5, 0.0) */
46049   fmt = REAL_MODE_FORMAT (mode);
46050   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
46051   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
46052
46053   /* adj = copysign (0.5, op1) */
46054   adj = force_reg (mode, const_double_from_real_value (pred_half, mode));
46055   ix86_sse_copysign_to_positive (adj, adj, force_reg (mode, op1), NULL_RTX);
46056
46057   /* adj = op1 + adj */
46058   adj = expand_simple_binop (mode, PLUS, adj, op1, NULL_RTX, 0, OPTAB_DIRECT);
46059
46060   /* op0 = (imode)adj */
46061   expand_fix (op0, adj, 0);
46062 }
46063
46064 /* Expand SSE2 sequence for computing lround from OPERAND1 storing
46065    into OPERAND0.  */
46066 void
46067 ix86_expand_lfloorceil (rtx op0, rtx op1, bool do_floor)
46068 {
46069   /* C code for the stuff we're doing below (for do_floor):
46070         xi = (long)op1;
46071         xi -= (double)xi > op1 ? 1 : 0;
46072         return xi;
46073    */
46074   machine_mode fmode = GET_MODE (op1);
46075   machine_mode imode = GET_MODE (op0);
46076   rtx ireg, freg, tmp;
46077   rtx_code_label *label;
46078
46079   /* reg = (long)op1 */
46080   ireg = gen_reg_rtx (imode);
46081   expand_fix (ireg, op1, 0);
46082
46083   /* freg = (double)reg */
46084   freg = gen_reg_rtx (fmode);
46085   expand_float (freg, ireg, 0);
46086
46087   /* ireg = (freg > op1) ? ireg - 1 : ireg */
46088   label = ix86_expand_sse_compare_and_jump (UNLE,
46089                                             freg, op1, !do_floor);
46090   tmp = expand_simple_binop (imode, do_floor ? MINUS : PLUS,
46091                              ireg, const1_rtx, NULL_RTX, 0, OPTAB_DIRECT);
46092   emit_move_insn (ireg, tmp);
46093
46094   emit_label (label);
46095   LABEL_NUSES (label) = 1;
46096
46097   emit_move_insn (op0, ireg);
46098 }
46099
46100 /* Expand rint (IEEE round to nearest) rounding OPERAND1 and storing the
46101    result in OPERAND0.  */
46102 void
46103 ix86_expand_rint (rtx operand0, rtx operand1)
46104 {
46105   /* C code for the stuff we're doing below:
46106         xa = fabs (operand1);
46107         if (!isless (xa, 2**52))
46108           return operand1;
46109         xa = xa + 2**52 - 2**52;
46110         return copysign (xa, operand1);
46111    */
46112   machine_mode mode = GET_MODE (operand0);
46113   rtx res, xa, TWO52, mask;
46114   rtx_code_label *label;
46115
46116   res = gen_reg_rtx (mode);
46117   emit_move_insn (res, operand1);
46118
46119   /* xa = abs (operand1) */
46120   xa = ix86_expand_sse_fabs (res, &mask);
46121
46122   /* if (!isless (xa, TWO52)) goto label; */
46123   TWO52 = ix86_gen_TWO52 (mode);
46124   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46125
46126   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46127   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
46128
46129   ix86_sse_copysign_to_positive (res, xa, res, mask);
46130
46131   emit_label (label);
46132   LABEL_NUSES (label) = 1;
46133
46134   emit_move_insn (operand0, res);
46135 }
46136
46137 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
46138    into OPERAND0.  */
46139 void
46140 ix86_expand_floorceildf_32 (rtx operand0, rtx operand1, bool do_floor)
46141 {
46142   /* C code for the stuff we expand below.
46143         double xa = fabs (x), x2;
46144         if (!isless (xa, TWO52))
46145           return x;
46146         xa = xa + TWO52 - TWO52;
46147         x2 = copysign (xa, x);
46148      Compensate.  Floor:
46149         if (x2 > x)
46150           x2 -= 1;
46151      Compensate.  Ceil:
46152         if (x2 < x)
46153           x2 -= -1;
46154         return x2;
46155    */
46156   machine_mode mode = GET_MODE (operand0);
46157   rtx xa, TWO52, tmp, one, res, mask;
46158   rtx_code_label *label;
46159
46160   TWO52 = ix86_gen_TWO52 (mode);
46161
46162   /* Temporary for holding the result, initialized to the input
46163      operand to ease control flow.  */
46164   res = gen_reg_rtx (mode);
46165   emit_move_insn (res, operand1);
46166
46167   /* xa = abs (operand1) */
46168   xa = ix86_expand_sse_fabs (res, &mask);
46169
46170   /* if (!isless (xa, TWO52)) goto label; */
46171   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46172
46173   /* xa = xa + TWO52 - TWO52; */
46174   xa = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46175   xa = expand_simple_binop (mode, MINUS, xa, TWO52, xa, 0, OPTAB_DIRECT);
46176
46177   /* xa = copysign (xa, operand1) */
46178   ix86_sse_copysign_to_positive (xa, xa, res, mask);
46179
46180   /* generate 1.0 or -1.0 */
46181   one = force_reg (mode,
46182                    const_double_from_real_value (do_floor
46183                                                  ? dconst1 : dconstm1, mode));
46184
46185   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
46186   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
46187   emit_insn (gen_rtx_SET (VOIDmode, tmp,
46188                           gen_rtx_AND (mode, one, tmp)));
46189   /* We always need to subtract here to preserve signed zero.  */
46190   tmp = expand_simple_binop (mode, MINUS,
46191                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46192   emit_move_insn (res, tmp);
46193
46194   emit_label (label);
46195   LABEL_NUSES (label) = 1;
46196
46197   emit_move_insn (operand0, res);
46198 }
46199
46200 /* Expand SSE2 sequence for computing floor or ceil from OPERAND1 storing
46201    into OPERAND0.  */
46202 void
46203 ix86_expand_floorceil (rtx operand0, rtx operand1, bool do_floor)
46204 {
46205   /* C code for the stuff we expand below.
46206         double xa = fabs (x), x2;
46207         if (!isless (xa, TWO52))
46208           return x;
46209         x2 = (double)(long)x;
46210      Compensate.  Floor:
46211         if (x2 > x)
46212           x2 -= 1;
46213      Compensate.  Ceil:
46214         if (x2 < x)
46215           x2 += 1;
46216         if (HONOR_SIGNED_ZEROS (mode))
46217           return copysign (x2, x);
46218         return x2;
46219    */
46220   machine_mode mode = GET_MODE (operand0);
46221   rtx xa, xi, TWO52, tmp, one, res, mask;
46222   rtx_code_label *label;
46223
46224   TWO52 = ix86_gen_TWO52 (mode);
46225
46226   /* Temporary for holding the result, initialized to the input
46227      operand to ease control flow.  */
46228   res = gen_reg_rtx (mode);
46229   emit_move_insn (res, operand1);
46230
46231   /* xa = abs (operand1) */
46232   xa = ix86_expand_sse_fabs (res, &mask);
46233
46234   /* if (!isless (xa, TWO52)) goto label; */
46235   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46236
46237   /* xa = (double)(long)x */
46238   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
46239   expand_fix (xi, res, 0);
46240   expand_float (xa, xi, 0);
46241
46242   /* generate 1.0 */
46243   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
46244
46245   /* Compensate: xa = xa - (xa > operand1 ? 1 : 0) */
46246   tmp = ix86_expand_sse_compare_mask (UNGT, xa, res, !do_floor);
46247   emit_insn (gen_rtx_SET (VOIDmode, tmp,
46248                           gen_rtx_AND (mode, one, tmp)));
46249   tmp = expand_simple_binop (mode, do_floor ? MINUS : PLUS,
46250                              xa, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46251   emit_move_insn (res, tmp);
46252
46253   if (HONOR_SIGNED_ZEROS (mode))
46254     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
46255
46256   emit_label (label);
46257   LABEL_NUSES (label) = 1;
46258
46259   emit_move_insn (operand0, res);
46260 }
46261
46262 /* Expand SSE sequence for computing round from OPERAND1 storing
46263    into OPERAND0.  Sequence that works without relying on DImode truncation
46264    via cvttsd2siq that is only available on 64bit targets.  */
46265 void
46266 ix86_expand_rounddf_32 (rtx operand0, rtx operand1)
46267 {
46268   /* C code for the stuff we expand below.
46269         double xa = fabs (x), xa2, x2;
46270         if (!isless (xa, TWO52))
46271           return x;
46272      Using the absolute value and copying back sign makes
46273      -0.0 -> -0.0 correct.
46274         xa2 = xa + TWO52 - TWO52;
46275      Compensate.
46276         dxa = xa2 - xa;
46277         if (dxa <= -0.5)
46278           xa2 += 1;
46279         else if (dxa > 0.5)
46280           xa2 -= 1;
46281         x2 = copysign (xa2, x);
46282         return x2;
46283    */
46284   machine_mode mode = GET_MODE (operand0);
46285   rtx xa, xa2, dxa, TWO52, tmp, half, mhalf, one, res, mask;
46286   rtx_code_label *label;
46287
46288   TWO52 = ix86_gen_TWO52 (mode);
46289
46290   /* Temporary for holding the result, initialized to the input
46291      operand to ease control flow.  */
46292   res = gen_reg_rtx (mode);
46293   emit_move_insn (res, operand1);
46294
46295   /* xa = abs (operand1) */
46296   xa = ix86_expand_sse_fabs (res, &mask);
46297
46298   /* if (!isless (xa, TWO52)) goto label; */
46299   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46300
46301   /* xa2 = xa + TWO52 - TWO52; */
46302   xa2 = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46303   xa2 = expand_simple_binop (mode, MINUS, xa2, TWO52, xa2, 0, OPTAB_DIRECT);
46304
46305   /* dxa = xa2 - xa; */
46306   dxa = expand_simple_binop (mode, MINUS, xa2, xa, NULL_RTX, 0, OPTAB_DIRECT);
46307
46308   /* generate 0.5, 1.0 and -0.5 */
46309   half = force_reg (mode, const_double_from_real_value (dconsthalf, mode));
46310   one = expand_simple_binop (mode, PLUS, half, half, NULL_RTX, 0, OPTAB_DIRECT);
46311   mhalf = expand_simple_binop (mode, MINUS, half, one, NULL_RTX,
46312                                0, OPTAB_DIRECT);
46313
46314   /* Compensate.  */
46315   tmp = gen_reg_rtx (mode);
46316   /* xa2 = xa2 - (dxa > 0.5 ? 1 : 0) */
46317   tmp = ix86_expand_sse_compare_mask (UNGT, dxa, half, false);
46318   emit_insn (gen_rtx_SET (VOIDmode, tmp,
46319                           gen_rtx_AND (mode, one, tmp)));
46320   xa2 = expand_simple_binop (mode, MINUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46321   /* xa2 = xa2 + (dxa <= -0.5 ? 1 : 0) */
46322   tmp = ix86_expand_sse_compare_mask (UNGE, mhalf, dxa, false);
46323   emit_insn (gen_rtx_SET (VOIDmode, tmp,
46324                           gen_rtx_AND (mode, one, tmp)));
46325   xa2 = expand_simple_binop (mode, PLUS, xa2, tmp, NULL_RTX, 0, OPTAB_DIRECT);
46326
46327   /* res = copysign (xa2, operand1) */
46328   ix86_sse_copysign_to_positive (res, xa2, force_reg (mode, operand1), mask);
46329
46330   emit_label (label);
46331   LABEL_NUSES (label) = 1;
46332
46333   emit_move_insn (operand0, res);
46334 }
46335
46336 /* Expand SSE sequence for computing trunc from OPERAND1 storing
46337    into OPERAND0.  */
46338 void
46339 ix86_expand_trunc (rtx operand0, rtx operand1)
46340 {
46341   /* C code for SSE variant we expand below.
46342         double xa = fabs (x), x2;
46343         if (!isless (xa, TWO52))
46344           return x;
46345         x2 = (double)(long)x;
46346         if (HONOR_SIGNED_ZEROS (mode))
46347           return copysign (x2, x);
46348         return x2;
46349    */
46350   machine_mode mode = GET_MODE (operand0);
46351   rtx xa, xi, TWO52, res, mask;
46352   rtx_code_label *label;
46353
46354   TWO52 = ix86_gen_TWO52 (mode);
46355
46356   /* Temporary for holding the result, initialized to the input
46357      operand to ease control flow.  */
46358   res = gen_reg_rtx (mode);
46359   emit_move_insn (res, operand1);
46360
46361   /* xa = abs (operand1) */
46362   xa = ix86_expand_sse_fabs (res, &mask);
46363
46364   /* if (!isless (xa, TWO52)) goto label; */
46365   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46366
46367   /* x = (double)(long)x */
46368   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
46369   expand_fix (xi, res, 0);
46370   expand_float (res, xi, 0);
46371
46372   if (HONOR_SIGNED_ZEROS (mode))
46373     ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), mask);
46374
46375   emit_label (label);
46376   LABEL_NUSES (label) = 1;
46377
46378   emit_move_insn (operand0, res);
46379 }
46380
46381 /* Expand SSE sequence for computing trunc from OPERAND1 storing
46382    into OPERAND0.  */
46383 void
46384 ix86_expand_truncdf_32 (rtx operand0, rtx operand1)
46385 {
46386   machine_mode mode = GET_MODE (operand0);
46387   rtx xa, mask, TWO52, one, res, smask, tmp;
46388   rtx_code_label *label;
46389
46390   /* C code for SSE variant we expand below.
46391         double xa = fabs (x), x2;
46392         if (!isless (xa, TWO52))
46393           return x;
46394         xa2 = xa + TWO52 - TWO52;
46395      Compensate:
46396         if (xa2 > xa)
46397           xa2 -= 1.0;
46398         x2 = copysign (xa2, x);
46399         return x2;
46400    */
46401
46402   TWO52 = ix86_gen_TWO52 (mode);
46403
46404   /* Temporary for holding the result, initialized to the input
46405      operand to ease control flow.  */
46406   res = gen_reg_rtx (mode);
46407   emit_move_insn (res, operand1);
46408
46409   /* xa = abs (operand1) */
46410   xa = ix86_expand_sse_fabs (res, &smask);
46411
46412   /* if (!isless (xa, TWO52)) goto label; */
46413   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46414
46415   /* res = xa + TWO52 - TWO52; */
46416   tmp = expand_simple_binop (mode, PLUS, xa, TWO52, NULL_RTX, 0, OPTAB_DIRECT);
46417   tmp = expand_simple_binop (mode, MINUS, tmp, TWO52, tmp, 0, OPTAB_DIRECT);
46418   emit_move_insn (res, tmp);
46419
46420   /* generate 1.0 */
46421   one = force_reg (mode, const_double_from_real_value (dconst1, mode));
46422
46423   /* Compensate: res = xa2 - (res > xa ? 1 : 0)  */
46424   mask = ix86_expand_sse_compare_mask (UNGT, res, xa, false);
46425   emit_insn (gen_rtx_SET (VOIDmode, mask,
46426                           gen_rtx_AND (mode, mask, one)));
46427   tmp = expand_simple_binop (mode, MINUS,
46428                              res, mask, NULL_RTX, 0, OPTAB_DIRECT);
46429   emit_move_insn (res, tmp);
46430
46431   /* res = copysign (res, operand1) */
46432   ix86_sse_copysign_to_positive (res, res, force_reg (mode, operand1), smask);
46433
46434   emit_label (label);
46435   LABEL_NUSES (label) = 1;
46436
46437   emit_move_insn (operand0, res);
46438 }
46439
46440 /* Expand SSE sequence for computing round from OPERAND1 storing
46441    into OPERAND0.  */
46442 void
46443 ix86_expand_round (rtx operand0, rtx operand1)
46444 {
46445   /* C code for the stuff we're doing below:
46446         double xa = fabs (x);
46447         if (!isless (xa, TWO52))
46448           return x;
46449         xa = (double)(long)(xa + nextafter (0.5, 0.0));
46450         return copysign (xa, x);
46451    */
46452   machine_mode mode = GET_MODE (operand0);
46453   rtx res, TWO52, xa, xi, half, mask;
46454   rtx_code_label *label;
46455   const struct real_format *fmt;
46456   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
46457
46458   /* Temporary for holding the result, initialized to the input
46459      operand to ease control flow.  */
46460   res = gen_reg_rtx (mode);
46461   emit_move_insn (res, operand1);
46462
46463   TWO52 = ix86_gen_TWO52 (mode);
46464   xa = ix86_expand_sse_fabs (res, &mask);
46465   label = ix86_expand_sse_compare_and_jump (UNLE, TWO52, xa, false);
46466
46467   /* load nextafter (0.5, 0.0) */
46468   fmt = REAL_MODE_FORMAT (mode);
46469   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
46470   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
46471
46472   /* xa = xa + 0.5 */
46473   half = force_reg (mode, const_double_from_real_value (pred_half, mode));
46474   xa = expand_simple_binop (mode, PLUS, xa, half, NULL_RTX, 0, OPTAB_DIRECT);
46475
46476   /* xa = (double)(int64_t)xa */
46477   xi = gen_reg_rtx (mode == DFmode ? DImode : SImode);
46478   expand_fix (xi, xa, 0);
46479   expand_float (xa, xi, 0);
46480
46481   /* res = copysign (xa, operand1) */
46482   ix86_sse_copysign_to_positive (res, xa, force_reg (mode, operand1), mask);
46483
46484   emit_label (label);
46485   LABEL_NUSES (label) = 1;
46486
46487   emit_move_insn (operand0, res);
46488 }
46489
46490 /* Expand SSE sequence for computing round
46491    from OP1 storing into OP0 using sse4 round insn.  */
46492 void
46493 ix86_expand_round_sse4 (rtx op0, rtx op1)
46494 {
46495   machine_mode mode = GET_MODE (op0);
46496   rtx e1, e2, res, half;
46497   const struct real_format *fmt;
46498   REAL_VALUE_TYPE pred_half, half_minus_pred_half;
46499   rtx (*gen_copysign) (rtx, rtx, rtx);
46500   rtx (*gen_round) (rtx, rtx, rtx);
46501
46502   switch (mode)
46503     {
46504     case SFmode:
46505       gen_copysign = gen_copysignsf3;
46506       gen_round = gen_sse4_1_roundsf2;
46507       break;
46508     case DFmode:
46509       gen_copysign = gen_copysigndf3;
46510       gen_round = gen_sse4_1_rounddf2;
46511       break;
46512     default:
46513       gcc_unreachable ();
46514     }
46515
46516   /* round (a) = trunc (a + copysign (0.5, a)) */
46517
46518   /* load nextafter (0.5, 0.0) */
46519   fmt = REAL_MODE_FORMAT (mode);
46520   real_2expN (&half_minus_pred_half, -(fmt->p) - 1, mode);
46521   REAL_ARITHMETIC (pred_half, MINUS_EXPR, dconsthalf, half_minus_pred_half);
46522   half = const_double_from_real_value (pred_half, mode);
46523
46524   /* e1 = copysign (0.5, op1) */
46525   e1 = gen_reg_rtx (mode);
46526   emit_insn (gen_copysign (e1, half, op1));
46527
46528   /* e2 = op1 + e1 */
46529   e2 = expand_simple_binop (mode, PLUS, op1, e1, NULL_RTX, 0, OPTAB_DIRECT);
46530
46531   /* res = trunc (e2) */
46532   res = gen_reg_rtx (mode);
46533   emit_insn (gen_round (res, e2, GEN_INT (ROUND_TRUNC)));
46534
46535   emit_move_insn (op0, res);
46536 }
46537 \f
46538
46539 /* Table of valid machine attributes.  */
46540 static const struct attribute_spec ix86_attribute_table[] =
46541 {
46542   /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
46543        affects_type_identity } */
46544   /* Stdcall attribute says callee is responsible for popping arguments
46545      if they are not variable.  */
46546   { "stdcall",   0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46547     true },
46548   /* Fastcall attribute says callee is responsible for popping arguments
46549      if they are not variable.  */
46550   { "fastcall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46551     true },
46552   /* Thiscall attribute says callee is responsible for popping arguments
46553      if they are not variable.  */
46554   { "thiscall",  0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46555     true },
46556   /* Cdecl attribute says the callee is a normal C declaration */
46557   { "cdecl",     0, 0, false, true,  true,  ix86_handle_cconv_attribute,
46558     true },
46559   /* Regparm attribute specifies how many integer arguments are to be
46560      passed in registers.  */
46561   { "regparm",   1, 1, false, true,  true,  ix86_handle_cconv_attribute,
46562     true },
46563   /* Sseregparm attribute says we are using x86_64 calling conventions
46564      for FP arguments.  */
46565   { "sseregparm", 0, 0, false, true, true, ix86_handle_cconv_attribute,
46566     true },
46567   /* The transactional memory builtins are implicitly regparm or fastcall
46568      depending on the ABI.  Override the generic do-nothing attribute that
46569      these builtins were declared with.  */
46570   { "*tm regparm", 0, 0, false, true, true, ix86_handle_tm_regparm_attribute,
46571     true },
46572   /* force_align_arg_pointer says this function realigns the stack at entry.  */
46573   { (const char *)&ix86_force_align_arg_pointer_string, 0, 0,
46574     false, true,  true, ix86_handle_cconv_attribute, false },
46575 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
46576   { "dllimport", 0, 0, false, false, false, handle_dll_attribute, false },
46577   { "dllexport", 0, 0, false, false, false, handle_dll_attribute, false },
46578   { "shared",    0, 0, true,  false, false, ix86_handle_shared_attribute,
46579     false },
46580 #endif
46581   { "ms_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute,
46582     false },
46583   { "gcc_struct", 0, 0, false, false,  false, ix86_handle_struct_attribute,
46584     false },
46585 #ifdef SUBTARGET_ATTRIBUTE_TABLE
46586   SUBTARGET_ATTRIBUTE_TABLE,
46587 #endif
46588   /* ms_abi and sysv_abi calling convention function attributes.  */
46589   { "ms_abi", 0, 0, false, true, true, ix86_handle_abi_attribute, true },
46590   { "sysv_abi", 0, 0, false, true, true, ix86_handle_abi_attribute, true },
46591   { "ms_hook_prologue", 0, 0, true, false, false, ix86_handle_fndecl_attribute,
46592     false },
46593   { "callee_pop_aggregate_return", 1, 1, false, true, true,
46594     ix86_handle_callee_pop_aggregate_return, true },
46595   /* End element.  */
46596   { NULL,        0, 0, false, false, false, NULL, false }
46597 };
46598
46599 /* Implement targetm.vectorize.builtin_vectorization_cost.  */
46600 static int
46601 ix86_builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
46602                                  tree vectype, int)
46603 {
46604   unsigned elements;
46605
46606   switch (type_of_cost)
46607     {
46608       case scalar_stmt:
46609         return ix86_cost->scalar_stmt_cost;
46610
46611       case scalar_load:
46612         return ix86_cost->scalar_load_cost;
46613
46614       case scalar_store:
46615         return ix86_cost->scalar_store_cost;
46616
46617       case vector_stmt:
46618         return ix86_cost->vec_stmt_cost;
46619
46620       case vector_load:
46621         return ix86_cost->vec_align_load_cost;
46622
46623       case vector_store:
46624         return ix86_cost->vec_store_cost;
46625
46626       case vec_to_scalar:
46627         return ix86_cost->vec_to_scalar_cost;
46628
46629       case scalar_to_vec:
46630         return ix86_cost->scalar_to_vec_cost;
46631
46632       case unaligned_load:
46633       case unaligned_store:
46634         return ix86_cost->vec_unalign_load_cost;
46635
46636       case cond_branch_taken:
46637         return ix86_cost->cond_taken_branch_cost;
46638
46639       case cond_branch_not_taken:
46640         return ix86_cost->cond_not_taken_branch_cost;
46641
46642       case vec_perm:
46643       case vec_promote_demote:
46644         return ix86_cost->vec_stmt_cost;
46645
46646       case vec_construct:
46647         elements = TYPE_VECTOR_SUBPARTS (vectype);
46648         return elements / 2 + 1;
46649
46650       default:
46651         gcc_unreachable ();
46652     }
46653 }
46654
46655 /* A cached (set (nil) (vselect (vconcat (nil) (nil)) (parallel [])))
46656    insn, so that expand_vselect{,_vconcat} doesn't have to create a fresh
46657    insn every time.  */
46658
46659 static GTY(()) rtx_insn *vselect_insn;
46660
46661 /* Initialize vselect_insn.  */
46662
46663 static void
46664 init_vselect_insn (void)
46665 {
46666   unsigned i;
46667   rtx x;
46668
46669   x = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (MAX_VECT_LEN));
46670   for (i = 0; i < MAX_VECT_LEN; ++i)
46671     XVECEXP (x, 0, i) = const0_rtx;
46672   x = gen_rtx_VEC_SELECT (V2DFmode, gen_rtx_VEC_CONCAT (V4DFmode, const0_rtx,
46673                                                         const0_rtx), x);
46674   x = gen_rtx_SET (VOIDmode, const0_rtx, x);
46675   start_sequence ();
46676   vselect_insn = emit_insn (x);
46677   end_sequence ();
46678 }
46679
46680 /* Construct (set target (vec_select op0 (parallel perm))) and
46681    return true if that's a valid instruction in the active ISA.  */
46682
46683 static bool
46684 expand_vselect (rtx target, rtx op0, const unsigned char *perm,
46685                 unsigned nelt, bool testing_p)
46686 {
46687   unsigned int i;
46688   rtx x, save_vconcat;
46689   int icode;
46690
46691   if (vselect_insn == NULL_RTX)
46692     init_vselect_insn ();
46693
46694   x = XEXP (SET_SRC (PATTERN (vselect_insn)), 1);
46695   PUT_NUM_ELEM (XVEC (x, 0), nelt);
46696   for (i = 0; i < nelt; ++i)
46697     XVECEXP (x, 0, i) = GEN_INT (perm[i]);
46698   save_vconcat = XEXP (SET_SRC (PATTERN (vselect_insn)), 0);
46699   XEXP (SET_SRC (PATTERN (vselect_insn)), 0) = op0;
46700   PUT_MODE (SET_SRC (PATTERN (vselect_insn)), GET_MODE (target));
46701   SET_DEST (PATTERN (vselect_insn)) = target;
46702   icode = recog_memoized (vselect_insn);
46703
46704   if (icode >= 0 && !testing_p)
46705     emit_insn (copy_rtx (PATTERN (vselect_insn)));
46706
46707   SET_DEST (PATTERN (vselect_insn)) = const0_rtx;
46708   XEXP (SET_SRC (PATTERN (vselect_insn)), 0) = save_vconcat;
46709   INSN_CODE (vselect_insn) = -1;
46710
46711   return icode >= 0;
46712 }
46713
46714 /* Similar, but generate a vec_concat from op0 and op1 as well.  */
46715
46716 static bool
46717 expand_vselect_vconcat (rtx target, rtx op0, rtx op1,
46718                         const unsigned char *perm, unsigned nelt,
46719                         bool testing_p)
46720 {
46721   machine_mode v2mode;
46722   rtx x;
46723   bool ok;
46724
46725   if (vselect_insn == NULL_RTX)
46726     init_vselect_insn ();
46727
46728   v2mode = GET_MODE_2XWIDER_MODE (GET_MODE (op0));
46729   x = XEXP (SET_SRC (PATTERN (vselect_insn)), 0);
46730   PUT_MODE (x, v2mode);
46731   XEXP (x, 0) = op0;
46732   XEXP (x, 1) = op1;
46733   ok = expand_vselect (target, x, perm, nelt, testing_p);
46734   XEXP (x, 0) = const0_rtx;
46735   XEXP (x, 1) = const0_rtx;
46736   return ok;
46737 }
46738
46739 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
46740    in terms of blendp[sd] / pblendw / pblendvb / vpblendd.  */
46741
46742 static bool
46743 expand_vec_perm_blend (struct expand_vec_perm_d *d)
46744 {
46745   machine_mode vmode = d->vmode;
46746   unsigned i, mask, nelt = d->nelt;
46747   rtx target, op0, op1, x;
46748   rtx rperm[32], vperm;
46749
46750   if (d->one_operand_p)
46751     return false;
46752   if (TARGET_AVX512F && GET_MODE_SIZE (vmode) == 64
46753       && GET_MODE_SIZE (GET_MODE_INNER (vmode)) >= 4)
46754     ;
46755   else if (TARGET_AVX2 && GET_MODE_SIZE (vmode) == 32)
46756     ;
46757   else if (TARGET_AVX && (vmode == V4DFmode || vmode == V8SFmode))
46758     ;
46759   else if (TARGET_SSE4_1 && GET_MODE_SIZE (vmode) == 16)
46760     ;
46761   else
46762     return false;
46763
46764   /* This is a blend, not a permute.  Elements must stay in their
46765      respective lanes.  */
46766   for (i = 0; i < nelt; ++i)
46767     {
46768       unsigned e = d->perm[i];
46769       if (!(e == i || e == i + nelt))
46770         return false;
46771     }
46772
46773   if (d->testing_p)
46774     return true;
46775
46776   /* ??? Without SSE4.1, we could implement this with and/andn/or.  This
46777      decision should be extracted elsewhere, so that we only try that
46778      sequence once all budget==3 options have been tried.  */
46779   target = d->target;
46780   op0 = d->op0;
46781   op1 = d->op1;
46782   mask = 0;
46783
46784   switch (vmode)
46785     {
46786     case V8DFmode:
46787     case V16SFmode:
46788     case V4DFmode:
46789     case V8SFmode:
46790     case V2DFmode:
46791     case V4SFmode:
46792     case V8HImode:
46793     case V8SImode:
46794     case V32HImode:
46795     case V64QImode:
46796     case V16SImode:
46797     case V8DImode:
46798       for (i = 0; i < nelt; ++i)
46799         mask |= (d->perm[i] >= nelt) << i;
46800       break;
46801
46802     case V2DImode:
46803       for (i = 0; i < 2; ++i)
46804         mask |= (d->perm[i] >= 2 ? 15 : 0) << (i * 4);
46805       vmode = V8HImode;
46806       goto do_subreg;
46807
46808     case V4SImode:
46809       for (i = 0; i < 4; ++i)
46810         mask |= (d->perm[i] >= 4 ? 3 : 0) << (i * 2);
46811       vmode = V8HImode;
46812       goto do_subreg;
46813
46814     case V16QImode:
46815       /* See if bytes move in pairs so we can use pblendw with
46816          an immediate argument, rather than pblendvb with a vector
46817          argument.  */
46818       for (i = 0; i < 16; i += 2)
46819         if (d->perm[i] + 1 != d->perm[i + 1])
46820           {
46821           use_pblendvb:
46822             for (i = 0; i < nelt; ++i)
46823               rperm[i] = (d->perm[i] < nelt ? const0_rtx : constm1_rtx);
46824
46825           finish_pblendvb:
46826             vperm = gen_rtx_CONST_VECTOR (vmode, gen_rtvec_v (nelt, rperm));
46827             vperm = force_reg (vmode, vperm);
46828
46829             if (GET_MODE_SIZE (vmode) == 16)
46830               emit_insn (gen_sse4_1_pblendvb (target, op0, op1, vperm));
46831             else
46832               emit_insn (gen_avx2_pblendvb (target, op0, op1, vperm));
46833             if (target != d->target)
46834               emit_move_insn (d->target, gen_lowpart (d->vmode, target));
46835             return true;
46836           }
46837
46838       for (i = 0; i < 8; ++i)
46839         mask |= (d->perm[i * 2] >= 16) << i;
46840       vmode = V8HImode;
46841       /* FALLTHRU */
46842
46843     do_subreg:
46844       target = gen_reg_rtx (vmode);
46845       op0 = gen_lowpart (vmode, op0);
46846       op1 = gen_lowpart (vmode, op1);
46847       break;
46848
46849     case V32QImode:
46850       /* See if bytes move in pairs.  If not, vpblendvb must be used.  */
46851       for (i = 0; i < 32; i += 2)
46852         if (d->perm[i] + 1 != d->perm[i + 1])
46853           goto use_pblendvb;
46854       /* See if bytes move in quadruplets.  If yes, vpblendd
46855          with immediate can be used.  */
46856       for (i = 0; i < 32; i += 4)
46857         if (d->perm[i] + 2 != d->perm[i + 2])
46858           break;
46859       if (i < 32)
46860         {
46861           /* See if bytes move the same in both lanes.  If yes,
46862              vpblendw with immediate can be used.  */
46863           for (i = 0; i < 16; i += 2)
46864             if (d->perm[i] + 16 != d->perm[i + 16])
46865               goto use_pblendvb;
46866
46867           /* Use vpblendw.  */
46868           for (i = 0; i < 16; ++i)
46869             mask |= (d->perm[i * 2] >= 32) << i;
46870           vmode = V16HImode;
46871           goto do_subreg;
46872         }
46873
46874       /* Use vpblendd.  */
46875       for (i = 0; i < 8; ++i)
46876         mask |= (d->perm[i * 4] >= 32) << i;
46877       vmode = V8SImode;
46878       goto do_subreg;
46879
46880     case V16HImode:
46881       /* See if words move in pairs.  If yes, vpblendd can be used.  */
46882       for (i = 0; i < 16; i += 2)
46883         if (d->perm[i] + 1 != d->perm[i + 1])
46884           break;
46885       if (i < 16)
46886         {
46887           /* See if words move the same in both lanes.  If not,
46888              vpblendvb must be used.  */
46889           for (i = 0; i < 8; i++)
46890             if (d->perm[i] + 8 != d->perm[i + 8])
46891               {
46892                 /* Use vpblendvb.  */
46893                 for (i = 0; i < 32; ++i)
46894                   rperm[i] = (d->perm[i / 2] < 16 ? const0_rtx : constm1_rtx);
46895
46896                 vmode = V32QImode;
46897                 nelt = 32;
46898                 target = gen_reg_rtx (vmode);
46899                 op0 = gen_lowpart (vmode, op0);
46900                 op1 = gen_lowpart (vmode, op1);
46901                 goto finish_pblendvb;
46902               }
46903
46904           /* Use vpblendw.  */
46905           for (i = 0; i < 16; ++i)
46906             mask |= (d->perm[i] >= 16) << i;
46907           break;
46908         }
46909
46910       /* Use vpblendd.  */
46911       for (i = 0; i < 8; ++i)
46912         mask |= (d->perm[i * 2] >= 16) << i;
46913       vmode = V8SImode;
46914       goto do_subreg;
46915
46916     case V4DImode:
46917       /* Use vpblendd.  */
46918       for (i = 0; i < 4; ++i)
46919         mask |= (d->perm[i] >= 4 ? 3 : 0) << (i * 2);
46920       vmode = V8SImode;
46921       goto do_subreg;
46922
46923     default:
46924       gcc_unreachable ();
46925     }
46926
46927   /* This matches five different patterns with the different modes.  */
46928   x = gen_rtx_VEC_MERGE (vmode, op1, op0, GEN_INT (mask));
46929   x = gen_rtx_SET (VOIDmode, target, x);
46930   emit_insn (x);
46931   if (target != d->target)
46932     emit_move_insn (d->target, gen_lowpart (d->vmode, target));
46933
46934   return true;
46935 }
46936
46937 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
46938    in terms of the variable form of vpermilps.
46939
46940    Note that we will have already failed the immediate input vpermilps,
46941    which requires that the high and low part shuffle be identical; the
46942    variable form doesn't require that.  */
46943
46944 static bool
46945 expand_vec_perm_vpermil (struct expand_vec_perm_d *d)
46946 {
46947   rtx rperm[8], vperm;
46948   unsigned i;
46949
46950   if (!TARGET_AVX || d->vmode != V8SFmode || !d->one_operand_p)
46951     return false;
46952
46953   /* We can only permute within the 128-bit lane.  */
46954   for (i = 0; i < 8; ++i)
46955     {
46956       unsigned e = d->perm[i];
46957       if (i < 4 ? e >= 4 : e < 4)
46958         return false;
46959     }
46960
46961   if (d->testing_p)
46962     return true;
46963
46964   for (i = 0; i < 8; ++i)
46965     {
46966       unsigned e = d->perm[i];
46967
46968       /* Within each 128-bit lane, the elements of op0 are numbered
46969          from 0 and the elements of op1 are numbered from 4.  */
46970       if (e >= 8 + 4)
46971         e -= 8;
46972       else if (e >= 4)
46973         e -= 4;
46974
46975       rperm[i] = GEN_INT (e);
46976     }
46977
46978   vperm = gen_rtx_CONST_VECTOR (V8SImode, gen_rtvec_v (8, rperm));
46979   vperm = force_reg (V8SImode, vperm);
46980   emit_insn (gen_avx_vpermilvarv8sf3 (d->target, d->op0, vperm));
46981
46982   return true;
46983 }
46984
46985 /* Return true if permutation D can be performed as VMODE permutation
46986    instead.  */
46987
46988 static bool
46989 valid_perm_using_mode_p (machine_mode vmode, struct expand_vec_perm_d *d)
46990 {
46991   unsigned int i, j, chunk;
46992
46993   if (GET_MODE_CLASS (vmode) != MODE_VECTOR_INT
46994       || GET_MODE_CLASS (d->vmode) != MODE_VECTOR_INT
46995       || GET_MODE_SIZE (vmode) != GET_MODE_SIZE (d->vmode))
46996     return false;
46997
46998   if (GET_MODE_NUNITS (vmode) >= d->nelt)
46999     return true;
47000
47001   chunk = d->nelt / GET_MODE_NUNITS (vmode);
47002   for (i = 0; i < d->nelt; i += chunk)
47003     if (d->perm[i] & (chunk - 1))
47004       return false;
47005     else
47006       for (j = 1; j < chunk; ++j)
47007         if (d->perm[i] + j != d->perm[i + j])
47008           return false;
47009
47010   return true;
47011 }
47012
47013 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
47014    in terms of pshufb, vpperm, vpermq, vpermd, vpermps or vperm2i128.  */
47015
47016 static bool
47017 expand_vec_perm_pshufb (struct expand_vec_perm_d *d)
47018 {
47019   unsigned i, nelt, eltsz, mask;
47020   unsigned char perm[64];
47021   machine_mode vmode = V16QImode;
47022   rtx rperm[64], vperm, target, op0, op1;
47023
47024   nelt = d->nelt;
47025
47026   if (!d->one_operand_p)
47027     {
47028       if (!TARGET_XOP || GET_MODE_SIZE (d->vmode) != 16)
47029         {
47030           if (TARGET_AVX2
47031               && valid_perm_using_mode_p (V2TImode, d))
47032             {
47033               if (d->testing_p)
47034                 return true;
47035
47036               /* Use vperm2i128 insn.  The pattern uses
47037                  V4DImode instead of V2TImode.  */
47038               target = d->target;
47039               if (d->vmode != V4DImode)
47040                 target = gen_reg_rtx (V4DImode);
47041               op0 = gen_lowpart (V4DImode, d->op0);
47042               op1 = gen_lowpart (V4DImode, d->op1);
47043               rperm[0]
47044                 = GEN_INT ((d->perm[0] / (nelt / 2))
47045                            | ((d->perm[nelt / 2] / (nelt / 2)) * 16));
47046               emit_insn (gen_avx2_permv2ti (target, op0, op1, rperm[0]));
47047               if (target != d->target)
47048                 emit_move_insn (d->target, gen_lowpart (d->vmode, target));
47049               return true;
47050             }
47051           return false;
47052         }
47053     }
47054   else
47055     {
47056       if (GET_MODE_SIZE (d->vmode) == 16)
47057         {
47058           if (!TARGET_SSSE3)
47059             return false;
47060         }
47061       else if (GET_MODE_SIZE (d->vmode) == 32)
47062         {
47063           if (!TARGET_AVX2)
47064             return false;
47065
47066           /* V4DImode should be already handled through
47067              expand_vselect by vpermq instruction.  */
47068           gcc_assert (d->vmode != V4DImode);
47069
47070           vmode = V32QImode;
47071           if (d->vmode == V8SImode
47072               || d->vmode == V16HImode
47073               || d->vmode == V32QImode)
47074             {
47075               /* First see if vpermq can be used for
47076                  V8SImode/V16HImode/V32QImode.  */
47077               if (valid_perm_using_mode_p (V4DImode, d))
47078                 {
47079                   for (i = 0; i < 4; i++)
47080                     perm[i] = (d->perm[i * nelt / 4] * 4 / nelt) & 3;
47081                   if (d->testing_p)
47082                     return true;
47083                   target = gen_reg_rtx (V4DImode);
47084                   if (expand_vselect (target, gen_lowpart (V4DImode, d->op0),
47085                                       perm, 4, false))
47086                     {
47087                       emit_move_insn (d->target,
47088                                       gen_lowpart (d->vmode, target));
47089                       return true;
47090                     }
47091                   return false;
47092                 }
47093
47094               /* Next see if vpermd can be used.  */
47095               if (valid_perm_using_mode_p (V8SImode, d))
47096                 vmode = V8SImode;
47097             }
47098           /* Or if vpermps can be used.  */
47099           else if (d->vmode == V8SFmode)
47100             vmode = V8SImode;
47101
47102           if (vmode == V32QImode)
47103             {
47104               /* vpshufb only works intra lanes, it is not
47105                  possible to shuffle bytes in between the lanes.  */
47106               for (i = 0; i < nelt; ++i)
47107                 if ((d->perm[i] ^ i) & (nelt / 2))
47108                   return false;
47109             }
47110         }
47111       else if (GET_MODE_SIZE (d->vmode) == 64)
47112         {
47113           if (!TARGET_AVX512BW)
47114             return false;
47115
47116           /* If vpermq didn't work, vpshufb won't work either.  */
47117           if (d->vmode == V8DFmode || d->vmode == V8DImode)
47118             return false;
47119
47120           vmode = V64QImode;
47121           if (d->vmode == V16SImode
47122               || d->vmode == V32HImode
47123               || d->vmode == V64QImode)
47124             {
47125               /* First see if vpermq can be used for
47126                  V16SImode/V32HImode/V64QImode.  */
47127               if (valid_perm_using_mode_p (V8DImode, d))
47128                 {
47129                   for (i = 0; i < 8; i++)
47130                     perm[i] = (d->perm[i * nelt / 8] * 8 / nelt) & 7;
47131                   if (d->testing_p)
47132                     return true;
47133                   target = gen_reg_rtx (V8DImode);
47134                   if (expand_vselect (target, gen_lowpart (V8DImode, d->op0),
47135                                       perm, 8, false))
47136                     {
47137                       emit_move_insn (d->target,
47138                                       gen_lowpart (d->vmode, target));
47139                       return true;
47140                     }
47141                   return false;
47142                 }
47143
47144               /* Next see if vpermd can be used.  */
47145               if (valid_perm_using_mode_p (V16SImode, d))
47146                 vmode = V16SImode;
47147             }
47148           /* Or if vpermps can be used.  */
47149           else if (d->vmode == V16SFmode)
47150             vmode = V16SImode;
47151           if (vmode == V64QImode)
47152             {
47153               /* vpshufb only works intra lanes, it is not
47154                  possible to shuffle bytes in between the lanes.  */
47155               for (i = 0; i < nelt; ++i)
47156                 if ((d->perm[i] ^ i) & (nelt / 4))
47157                   return false;
47158             }
47159         }
47160       else
47161         return false;
47162     }
47163
47164   if (d->testing_p)
47165     return true;
47166
47167   if (vmode == V8SImode)
47168     for (i = 0; i < 8; ++i)
47169       rperm[i] = GEN_INT ((d->perm[i * nelt / 8] * 8 / nelt) & 7);
47170   else if (vmode == V16SImode)
47171     for (i = 0; i < 16; ++i)
47172       rperm[i] = GEN_INT ((d->perm[i * nelt / 16] * 16 / nelt) & 15);
47173   else
47174     {
47175       eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
47176       if (!d->one_operand_p)
47177         mask = 2 * nelt - 1;
47178       else if (vmode == V16QImode)
47179         mask = nelt - 1;
47180       else if (vmode == V64QImode)
47181         mask = nelt / 4 - 1;
47182       else
47183         mask = nelt / 2 - 1;
47184
47185       for (i = 0; i < nelt; ++i)
47186         {
47187           unsigned j, e = d->perm[i] & mask;
47188           for (j = 0; j < eltsz; ++j)
47189             rperm[i * eltsz + j] = GEN_INT (e * eltsz + j);
47190         }
47191     }
47192
47193   vperm = gen_rtx_CONST_VECTOR (vmode,
47194                                 gen_rtvec_v (GET_MODE_NUNITS (vmode), rperm));
47195   vperm = force_reg (vmode, vperm);
47196
47197   target = d->target;
47198   if (d->vmode != vmode)
47199     target = gen_reg_rtx (vmode);
47200   op0 = gen_lowpart (vmode, d->op0);
47201   if (d->one_operand_p)
47202     {
47203       if (vmode == V16QImode)
47204         emit_insn (gen_ssse3_pshufbv16qi3 (target, op0, vperm));
47205       else if (vmode == V32QImode)
47206         emit_insn (gen_avx2_pshufbv32qi3 (target, op0, vperm));
47207       else if (vmode == V64QImode)
47208         emit_insn (gen_avx512bw_pshufbv64qi3 (target, op0, vperm));
47209       else if (vmode == V8SFmode)
47210         emit_insn (gen_avx2_permvarv8sf (target, op0, vperm));
47211       else if (vmode == V8SImode)
47212         emit_insn (gen_avx2_permvarv8si (target, op0, vperm));
47213       else if (vmode == V16SFmode)
47214         emit_insn (gen_avx512f_permvarv16sf (target, op0, vperm));
47215       else if (vmode == V16SImode)
47216         emit_insn (gen_avx512f_permvarv16si (target, op0, vperm));
47217       else
47218         gcc_unreachable ();
47219     }
47220   else
47221     {
47222       op1 = gen_lowpart (vmode, d->op1);
47223       emit_insn (gen_xop_pperm (target, op0, op1, vperm));
47224     }
47225   if (target != d->target)
47226     emit_move_insn (d->target, gen_lowpart (d->vmode, target));
47227
47228   return true;
47229 }
47230
47231 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to instantiate D
47232    in a single instruction.  */
47233
47234 static bool
47235 expand_vec_perm_1 (struct expand_vec_perm_d *d)
47236 {
47237   unsigned i, nelt = d->nelt;
47238   unsigned char perm2[MAX_VECT_LEN];
47239
47240   /* Check plain VEC_SELECT first, because AVX has instructions that could
47241      match both SEL and SEL+CONCAT, but the plain SEL will allow a memory
47242      input where SEL+CONCAT may not.  */
47243   if (d->one_operand_p)
47244     {
47245       int mask = nelt - 1;
47246       bool identity_perm = true;
47247       bool broadcast_perm = true;
47248
47249       for (i = 0; i < nelt; i++)
47250         {
47251           perm2[i] = d->perm[i] & mask;
47252           if (perm2[i] != i)
47253             identity_perm = false;
47254           if (perm2[i])
47255             broadcast_perm = false;
47256         }
47257
47258       if (identity_perm)
47259         {
47260           if (!d->testing_p)
47261             emit_move_insn (d->target, d->op0);
47262           return true;
47263         }
47264       else if (broadcast_perm && TARGET_AVX2)
47265         {
47266           /* Use vpbroadcast{b,w,d}.  */
47267           rtx (*gen) (rtx, rtx) = NULL;
47268           switch (d->vmode)
47269             {
47270             case V64QImode:
47271               if (TARGET_AVX512BW)
47272                 gen = gen_avx512bw_vec_dupv64qi_1;
47273               break;
47274             case V32QImode:
47275               gen = gen_avx2_pbroadcastv32qi_1;
47276               break;
47277             case V32HImode:
47278               if (TARGET_AVX512BW)
47279                 gen = gen_avx512bw_vec_dupv32hi_1;
47280               break;
47281             case V16HImode:
47282               gen = gen_avx2_pbroadcastv16hi_1;
47283               break;
47284             case V16SImode:
47285               if (TARGET_AVX512F)
47286                 gen = gen_avx512f_vec_dupv16si_1;
47287               break;
47288             case V8SImode:
47289               gen = gen_avx2_pbroadcastv8si_1;
47290               break;
47291             case V16QImode:
47292               gen = gen_avx2_pbroadcastv16qi;
47293               break;
47294             case V8HImode:
47295               gen = gen_avx2_pbroadcastv8hi;
47296               break;
47297             case V16SFmode:
47298               if (TARGET_AVX512F)
47299                 gen = gen_avx512f_vec_dupv16sf_1;
47300               break;
47301             case V8SFmode:
47302               gen = gen_avx2_vec_dupv8sf_1;
47303               break;
47304             case V8DFmode:
47305               if (TARGET_AVX512F)
47306                 gen = gen_avx512f_vec_dupv8df_1;
47307               break;
47308             case V8DImode:
47309               if (TARGET_AVX512F)
47310                 gen = gen_avx512f_vec_dupv8di_1;
47311               break;
47312             /* For other modes prefer other shuffles this function creates.  */
47313             default: break;
47314             }
47315           if (gen != NULL)
47316             {
47317               if (!d->testing_p)
47318                 emit_insn (gen (d->target, d->op0));
47319               return true;
47320             }
47321         }
47322
47323       if (expand_vselect (d->target, d->op0, perm2, nelt, d->testing_p))
47324         return true;
47325
47326       /* There are plenty of patterns in sse.md that are written for
47327          SEL+CONCAT and are not replicated for a single op.  Perhaps
47328          that should be changed, to avoid the nastiness here.  */
47329
47330       /* Recognize interleave style patterns, which means incrementing
47331          every other permutation operand.  */
47332       for (i = 0; i < nelt; i += 2)
47333         {
47334           perm2[i] = d->perm[i] & mask;
47335           perm2[i + 1] = (d->perm[i + 1] & mask) + nelt;
47336         }
47337       if (expand_vselect_vconcat (d->target, d->op0, d->op0, perm2, nelt,
47338                                   d->testing_p))
47339         return true;
47340
47341       /* Recognize shufps, which means adding {0, 0, nelt, nelt}.  */
47342       if (nelt >= 4)
47343         {
47344           for (i = 0; i < nelt; i += 4)
47345             {
47346               perm2[i + 0] = d->perm[i + 0] & mask;
47347               perm2[i + 1] = d->perm[i + 1] & mask;
47348               perm2[i + 2] = (d->perm[i + 2] & mask) + nelt;
47349               perm2[i + 3] = (d->perm[i + 3] & mask) + nelt;
47350             }
47351
47352           if (expand_vselect_vconcat (d->target, d->op0, d->op0, perm2, nelt,
47353                                       d->testing_p))
47354             return true;
47355         }
47356     }
47357
47358   /* Finally, try the fully general two operand permute.  */
47359   if (expand_vselect_vconcat (d->target, d->op0, d->op1, d->perm, nelt,
47360                               d->testing_p))
47361     return true;
47362
47363   /* Recognize interleave style patterns with reversed operands.  */
47364   if (!d->one_operand_p)
47365     {
47366       for (i = 0; i < nelt; ++i)
47367         {
47368           unsigned e = d->perm[i];
47369           if (e >= nelt)
47370             e -= nelt;
47371           else
47372             e += nelt;
47373           perm2[i] = e;
47374         }
47375
47376       if (expand_vselect_vconcat (d->target, d->op1, d->op0, perm2, nelt,
47377                                   d->testing_p))
47378         return true;
47379     }
47380
47381   /* Try the SSE4.1 blend variable merge instructions.  */
47382   if (expand_vec_perm_blend (d))
47383     return true;
47384
47385   /* Try one of the AVX vpermil variable permutations.  */
47386   if (expand_vec_perm_vpermil (d))
47387     return true;
47388
47389   /* Try the SSSE3 pshufb or XOP vpperm or AVX2 vperm2i128,
47390      vpshufb, vpermd, vpermps or vpermq variable permutation.  */
47391   if (expand_vec_perm_pshufb (d))
47392     return true;
47393
47394   /* Try the AVX2 vpalignr instruction.  */
47395   if (expand_vec_perm_palignr (d, true))
47396     return true;
47397
47398   /* Try the AVX512F vpermi2 instructions.  */
47399   if (ix86_expand_vec_perm_vpermi2 (NULL_RTX, NULL_RTX, NULL_RTX, NULL_RTX, d))
47400     return true;
47401
47402   return false;
47403 }
47404
47405 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement D
47406    in terms of a pair of pshuflw + pshufhw instructions.  */
47407
47408 static bool
47409 expand_vec_perm_pshuflw_pshufhw (struct expand_vec_perm_d *d)
47410 {
47411   unsigned char perm2[MAX_VECT_LEN];
47412   unsigned i;
47413   bool ok;
47414
47415   if (d->vmode != V8HImode || !d->one_operand_p)
47416     return false;
47417
47418   /* The two permutations only operate in 64-bit lanes.  */
47419   for (i = 0; i < 4; ++i)
47420     if (d->perm[i] >= 4)
47421       return false;
47422   for (i = 4; i < 8; ++i)
47423     if (d->perm[i] < 4)
47424       return false;
47425
47426   if (d->testing_p)
47427     return true;
47428
47429   /* Emit the pshuflw.  */
47430   memcpy (perm2, d->perm, 4);
47431   for (i = 4; i < 8; ++i)
47432     perm2[i] = i;
47433   ok = expand_vselect (d->target, d->op0, perm2, 8, d->testing_p);
47434   gcc_assert (ok);
47435
47436   /* Emit the pshufhw.  */
47437   memcpy (perm2 + 4, d->perm + 4, 4);
47438   for (i = 0; i < 4; ++i)
47439     perm2[i] = i;
47440   ok = expand_vselect (d->target, d->target, perm2, 8, d->testing_p);
47441   gcc_assert (ok);
47442
47443   return true;
47444 }
47445
47446 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
47447    the permutation using the SSSE3 palignr instruction.  This succeeds
47448    when all of the elements in PERM fit within one vector and we merely
47449    need to shift them down so that a single vector permutation has a
47450    chance to succeed.  If SINGLE_INSN_ONLY_P, succeed if only
47451    the vpalignr instruction itself can perform the requested permutation.  */
47452
47453 static bool
47454 expand_vec_perm_palignr (struct expand_vec_perm_d *d, bool single_insn_only_p)
47455 {
47456   unsigned i, nelt = d->nelt;
47457   unsigned min, max, minswap, maxswap;
47458   bool in_order, ok, swap = false;
47459   rtx shift, target;
47460   struct expand_vec_perm_d dcopy;
47461
47462   /* Even with AVX, palignr only operates on 128-bit vectors,
47463      in AVX2 palignr operates on both 128-bit lanes.  */
47464   if ((!TARGET_SSSE3 || GET_MODE_SIZE (d->vmode) != 16)
47465       && (!TARGET_AVX2 || GET_MODE_SIZE (d->vmode) != 32))
47466     return false;
47467
47468   min = 2 * nelt;
47469   max = 0;
47470   minswap = 2 * nelt;
47471   maxswap = 0;
47472   for (i = 0; i < nelt; ++i)
47473     {
47474       unsigned e = d->perm[i];
47475       unsigned eswap = d->perm[i] ^ nelt;
47476       if (GET_MODE_SIZE (d->vmode) == 32)
47477         {
47478           e = (e & ((nelt / 2) - 1)) | ((e & nelt) >> 1);
47479           eswap = e ^ (nelt / 2);
47480         }
47481       if (e < min)
47482         min = e;
47483       if (e > max)
47484         max = e;
47485       if (eswap < minswap)
47486         minswap = eswap;
47487       if (eswap > maxswap)
47488         maxswap = eswap;
47489     }
47490   if (min == 0
47491       || max - min >= (GET_MODE_SIZE (d->vmode) == 32 ? nelt / 2 : nelt))
47492     {
47493       if (d->one_operand_p
47494           || minswap == 0
47495           || maxswap - minswap >= (GET_MODE_SIZE (d->vmode) == 32
47496                                    ? nelt / 2 : nelt))
47497         return false;
47498       swap = true;
47499       min = minswap;
47500       max = maxswap;
47501     }
47502
47503   /* Given that we have SSSE3, we know we'll be able to implement the
47504      single operand permutation after the palignr with pshufb for
47505      128-bit vectors.  If SINGLE_INSN_ONLY_P, in_order has to be computed
47506      first.  */
47507   if (d->testing_p && GET_MODE_SIZE (d->vmode) == 16 && !single_insn_only_p)
47508     return true;
47509
47510   dcopy = *d;
47511   if (swap)
47512     {
47513       dcopy.op0 = d->op1;
47514       dcopy.op1 = d->op0;
47515       for (i = 0; i < nelt; ++i)
47516         dcopy.perm[i] ^= nelt;
47517     }
47518
47519   in_order = true;
47520   for (i = 0; i < nelt; ++i)
47521     {
47522       unsigned e = dcopy.perm[i];
47523       if (GET_MODE_SIZE (d->vmode) == 32
47524           && e >= nelt
47525           && (e & (nelt / 2 - 1)) < min)
47526         e = e - min - (nelt / 2);
47527       else
47528         e = e - min;
47529       if (e != i)
47530         in_order = false;
47531       dcopy.perm[i] = e;
47532     }
47533   dcopy.one_operand_p = true;
47534
47535   if (single_insn_only_p && !in_order)
47536     return false;
47537
47538   /* For AVX2, test whether we can permute the result in one instruction.  */
47539   if (d->testing_p)
47540     {
47541       if (in_order)
47542         return true;
47543       dcopy.op1 = dcopy.op0;
47544       return expand_vec_perm_1 (&dcopy);
47545     }
47546
47547   shift = GEN_INT (min * GET_MODE_BITSIZE (GET_MODE_INNER (d->vmode)));
47548   if (GET_MODE_SIZE (d->vmode) == 16)
47549     {
47550       target = gen_reg_rtx (TImode);
47551       emit_insn (gen_ssse3_palignrti (target, gen_lowpart (TImode, dcopy.op1),
47552                                       gen_lowpart (TImode, dcopy.op0), shift));
47553     }
47554   else
47555     {
47556       target = gen_reg_rtx (V2TImode);
47557       emit_insn (gen_avx2_palignrv2ti (target,
47558                                        gen_lowpart (V2TImode, dcopy.op1),
47559                                        gen_lowpart (V2TImode, dcopy.op0),
47560                                        shift));
47561     }
47562
47563   dcopy.op0 = dcopy.op1 = gen_lowpart (d->vmode, target);
47564
47565   /* Test for the degenerate case where the alignment by itself
47566      produces the desired permutation.  */
47567   if (in_order)
47568     {
47569       emit_move_insn (d->target, dcopy.op0);
47570       return true;
47571     }
47572
47573   ok = expand_vec_perm_1 (&dcopy);
47574   gcc_assert (ok || GET_MODE_SIZE (d->vmode) == 32);
47575
47576   return ok;
47577 }
47578
47579 /* A subroutine of ix86_expand_vec_perm_const_1.  Try to simplify
47580    the permutation using the SSE4_1 pblendv instruction.  Potentially
47581    reduces permutation from 2 pshufb and or to 1 pshufb and pblendv.  */
47582
47583 static bool
47584 expand_vec_perm_pblendv (struct expand_vec_perm_d *d)
47585 {
47586   unsigned i, which, nelt = d->nelt;
47587   struct expand_vec_perm_d dcopy, dcopy1;
47588   machine_mode vmode = d->vmode;
47589   bool ok;
47590
47591   /* Use the same checks as in expand_vec_perm_blend.  */
47592   if (d->one_operand_p)
47593     return false;
47594   if (TARGET_AVX2 && GET_MODE_SIZE (vmode) == 32)
47595     ;
47596   else if (TARGET_AVX && (vmode == V4DFmode || vmode == V8SFmode))
47597     ;
47598   else if (TARGET_SSE4_1 && GET_MODE_SIZE (vmode) == 16)
47599     ;
47600   else
47601     return false;
47602
47603   /* Figure out where permutation elements stay not in their
47604      respective lanes.  */
47605   for (i = 0, which = 0; i < nelt; ++i)
47606     {
47607       unsigned e = d->perm[i];
47608       if (e != i)
47609         which |= (e < nelt ? 1 : 2);
47610     }
47611   /* We can pblend the part where elements stay not in their
47612      respective lanes only when these elements are all in one
47613      half of a permutation.
47614      {0 1 8 3 4 5 9 7} is ok as 8, 9 are at not at their respective
47615      lanes, but both 8 and 9 >= 8
47616      {0 1 8 3 4 5 2 7} is not ok as 2 and 8 are not at their
47617      respective lanes and 8 >= 8, but 2 not.  */
47618   if (which != 1 && which != 2)
47619     return false;
47620   if (d->testing_p && GET_MODE_SIZE (vmode) == 16)
47621     return true;
47622
47623   /* First we apply one operand permutation to the part where
47624      elements stay not in their respective lanes.  */
47625   dcopy = *d;
47626   if (which == 2)
47627     dcopy.op0 = dcopy.op1 = d->op1;
47628   else
47629     dcopy.op0 = dcopy.op1 = d->op0;
47630   if (!d->testing_p)
47631     dcopy.target = gen_reg_rtx (vmode);
47632   dcopy.one_operand_p = true;
47633
47634   for (i = 0; i < nelt; ++i)
47635     dcopy.perm[i] = d->perm[i] & (nelt - 1);
47636
47637   ok = expand_vec_perm_1 (&dcopy);
47638   if (GET_MODE_SIZE (vmode) != 16 && !ok)
47639     return false;
47640   else
47641     gcc_assert (ok);
47642   if (d->testing_p)
47643     return true;
47644
47645   /* Next we put permuted elements into their positions.  */
47646   dcopy1 = *d;
47647   if (which == 2)
47648     dcopy1.op1 = dcopy.target;
47649   else
47650     dcopy1.op0 = dcopy.target;
47651
47652   for (i = 0; i < nelt; ++i)
47653     dcopy1.perm[i] = ((d->perm[i] >= nelt) ? (nelt + i) : i);
47654
47655   ok = expand_vec_perm_blend (&dcopy1);
47656   gcc_assert (ok);
47657
47658   return true;
47659 }
47660
47661 static bool expand_vec_perm_interleave3 (struct expand_vec_perm_d *d);
47662
47663 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
47664    a two vector permutation into a single vector permutation by using
47665    an interleave operation to merge the vectors.  */
47666
47667 static bool
47668 expand_vec_perm_interleave2 (struct expand_vec_perm_d *d)
47669 {
47670   struct expand_vec_perm_d dremap, dfinal;
47671   unsigned i, nelt = d->nelt, nelt2 = nelt / 2;
47672   unsigned HOST_WIDE_INT contents;
47673   unsigned char remap[2 * MAX_VECT_LEN];
47674   rtx_insn *seq;
47675   bool ok, same_halves = false;
47676
47677   if (GET_MODE_SIZE (d->vmode) == 16)
47678     {
47679       if (d->one_operand_p)
47680         return false;
47681     }
47682   else if (GET_MODE_SIZE (d->vmode) == 32)
47683     {
47684       if (!TARGET_AVX)
47685         return false;
47686       /* For 32-byte modes allow even d->one_operand_p.
47687          The lack of cross-lane shuffling in some instructions
47688          might prevent a single insn shuffle.  */
47689       dfinal = *d;
47690       dfinal.testing_p = true;
47691       /* If expand_vec_perm_interleave3 can expand this into
47692          a 3 insn sequence, give up and let it be expanded as
47693          3 insn sequence.  While that is one insn longer,
47694          it doesn't need a memory operand and in the common
47695          case that both interleave low and high permutations
47696          with the same operands are adjacent needs 4 insns
47697          for both after CSE.  */
47698       if (expand_vec_perm_interleave3 (&dfinal))
47699         return false;
47700     }
47701   else
47702     return false;
47703
47704   /* Examine from whence the elements come.  */
47705   contents = 0;
47706   for (i = 0; i < nelt; ++i)
47707     contents |= ((unsigned HOST_WIDE_INT) 1) << d->perm[i];
47708
47709   memset (remap, 0xff, sizeof (remap));
47710   dremap = *d;
47711
47712   if (GET_MODE_SIZE (d->vmode) == 16)
47713     {
47714       unsigned HOST_WIDE_INT h1, h2, h3, h4;
47715
47716       /* Split the two input vectors into 4 halves.  */
47717       h1 = (((unsigned HOST_WIDE_INT) 1) << nelt2) - 1;
47718       h2 = h1 << nelt2;
47719       h3 = h2 << nelt2;
47720       h4 = h3 << nelt2;
47721
47722       /* If the elements from the low halves use interleave low, and similarly
47723          for interleave high.  If the elements are from mis-matched halves, we
47724          can use shufps for V4SF/V4SI or do a DImode shuffle.  */
47725       if ((contents & (h1 | h3)) == contents)
47726         {
47727           /* punpckl* */
47728           for (i = 0; i < nelt2; ++i)
47729             {
47730               remap[i] = i * 2;
47731               remap[i + nelt] = i * 2 + 1;
47732               dremap.perm[i * 2] = i;
47733               dremap.perm[i * 2 + 1] = i + nelt;
47734             }
47735           if (!TARGET_SSE2 && d->vmode == V4SImode)
47736             dremap.vmode = V4SFmode;
47737         }
47738       else if ((contents & (h2 | h4)) == contents)
47739         {
47740           /* punpckh* */
47741           for (i = 0; i < nelt2; ++i)
47742             {
47743               remap[i + nelt2] = i * 2;
47744               remap[i + nelt + nelt2] = i * 2 + 1;
47745               dremap.perm[i * 2] = i + nelt2;
47746               dremap.perm[i * 2 + 1] = i + nelt + nelt2;
47747             }
47748           if (!TARGET_SSE2 && d->vmode == V4SImode)
47749             dremap.vmode = V4SFmode;
47750         }
47751       else if ((contents & (h1 | h4)) == contents)
47752         {
47753           /* shufps */
47754           for (i = 0; i < nelt2; ++i)
47755             {
47756               remap[i] = i;
47757               remap[i + nelt + nelt2] = i + nelt2;
47758               dremap.perm[i] = i;
47759               dremap.perm[i + nelt2] = i + nelt + nelt2;
47760             }
47761           if (nelt != 4)
47762             {
47763               /* shufpd */
47764               dremap.vmode = V2DImode;
47765               dremap.nelt = 2;
47766               dremap.perm[0] = 0;
47767               dremap.perm[1] = 3;
47768             }
47769         }
47770       else if ((contents & (h2 | h3)) == contents)
47771         {
47772           /* shufps */
47773           for (i = 0; i < nelt2; ++i)
47774             {
47775               remap[i + nelt2] = i;
47776               remap[i + nelt] = i + nelt2;
47777               dremap.perm[i] = i + nelt2;
47778               dremap.perm[i + nelt2] = i + nelt;
47779             }
47780           if (nelt != 4)
47781             {
47782               /* shufpd */
47783               dremap.vmode = V2DImode;
47784               dremap.nelt = 2;
47785               dremap.perm[0] = 1;
47786               dremap.perm[1] = 2;
47787             }
47788         }
47789       else
47790         return false;
47791     }
47792   else
47793     {
47794       unsigned int nelt4 = nelt / 4, nzcnt = 0;
47795       unsigned HOST_WIDE_INT q[8];
47796       unsigned int nonzero_halves[4];
47797
47798       /* Split the two input vectors into 8 quarters.  */
47799       q[0] = (((unsigned HOST_WIDE_INT) 1) << nelt4) - 1;
47800       for (i = 1; i < 8; ++i)
47801         q[i] = q[0] << (nelt4 * i);
47802       for (i = 0; i < 4; ++i)
47803         if (((q[2 * i] | q[2 * i + 1]) & contents) != 0)
47804           {
47805             nonzero_halves[nzcnt] = i;
47806             ++nzcnt;
47807           }
47808
47809       if (nzcnt == 1)
47810         {
47811           gcc_assert (d->one_operand_p);
47812           nonzero_halves[1] = nonzero_halves[0];
47813           same_halves = true;
47814         }
47815       else if (d->one_operand_p)
47816         {
47817           gcc_assert (nonzero_halves[0] == 0);
47818           gcc_assert (nonzero_halves[1] == 1);
47819         }
47820
47821       if (nzcnt <= 2)
47822         {
47823           if (d->perm[0] / nelt2 == nonzero_halves[1])
47824             {
47825               /* Attempt to increase the likelihood that dfinal
47826                  shuffle will be intra-lane.  */
47827               char tmph = nonzero_halves[0];
47828               nonzero_halves[0] = nonzero_halves[1];
47829               nonzero_halves[1] = tmph;
47830             }
47831
47832           /* vperm2f128 or vperm2i128.  */
47833           for (i = 0; i < nelt2; ++i)
47834             {
47835               remap[i + nonzero_halves[1] * nelt2] = i + nelt2;
47836               remap[i + nonzero_halves[0] * nelt2] = i;
47837               dremap.perm[i + nelt2] = i + nonzero_halves[1] * nelt2;
47838               dremap.perm[i] = i + nonzero_halves[0] * nelt2;
47839             }
47840
47841           if (d->vmode != V8SFmode
47842               && d->vmode != V4DFmode
47843               && d->vmode != V8SImode)
47844             {
47845               dremap.vmode = V8SImode;
47846               dremap.nelt = 8;
47847               for (i = 0; i < 4; ++i)
47848                 {
47849                   dremap.perm[i] = i + nonzero_halves[0] * 4;
47850                   dremap.perm[i + 4] = i + nonzero_halves[1] * 4;
47851                 }
47852             }
47853         }
47854       else if (d->one_operand_p)
47855         return false;
47856       else if (TARGET_AVX2
47857                && (contents & (q[0] | q[2] | q[4] | q[6])) == contents)
47858         {
47859           /* vpunpckl* */
47860           for (i = 0; i < nelt4; ++i)
47861             {
47862               remap[i] = i * 2;
47863               remap[i + nelt] = i * 2 + 1;
47864               remap[i + nelt2] = i * 2 + nelt2;
47865               remap[i + nelt + nelt2] = i * 2 + nelt2 + 1;
47866               dremap.perm[i * 2] = i;
47867               dremap.perm[i * 2 + 1] = i + nelt;
47868               dremap.perm[i * 2 + nelt2] = i + nelt2;
47869               dremap.perm[i * 2 + nelt2 + 1] = i + nelt + nelt2;
47870             }
47871         }
47872       else if (TARGET_AVX2
47873                && (contents & (q[1] | q[3] | q[5] | q[7])) == contents)
47874         {
47875           /* vpunpckh* */
47876           for (i = 0; i < nelt4; ++i)
47877             {
47878               remap[i + nelt4] = i * 2;
47879               remap[i + nelt + nelt4] = i * 2 + 1;
47880               remap[i + nelt2 + nelt4] = i * 2 + nelt2;
47881               remap[i + nelt + nelt2 + nelt4] = i * 2 + nelt2 + 1;
47882               dremap.perm[i * 2] = i + nelt4;
47883               dremap.perm[i * 2 + 1] = i + nelt + nelt4;
47884               dremap.perm[i * 2 + nelt2] = i + nelt2 + nelt4;
47885               dremap.perm[i * 2 + nelt2 + 1] = i + nelt + nelt2 + nelt4;
47886             }
47887         }
47888       else
47889         return false;
47890     }
47891
47892   /* Use the remapping array set up above to move the elements from their
47893      swizzled locations into their final destinations.  */
47894   dfinal = *d;
47895   for (i = 0; i < nelt; ++i)
47896     {
47897       unsigned e = remap[d->perm[i]];
47898       gcc_assert (e < nelt);
47899       /* If same_halves is true, both halves of the remapped vector are the
47900          same.  Avoid cross-lane accesses if possible.  */
47901       if (same_halves && i >= nelt2)
47902         {
47903           gcc_assert (e < nelt2);
47904           dfinal.perm[i] = e + nelt2;
47905         }
47906       else
47907         dfinal.perm[i] = e;
47908     }
47909   if (!d->testing_p)
47910     {
47911       dremap.target = gen_reg_rtx (dremap.vmode);
47912       dfinal.op0 = gen_lowpart (dfinal.vmode, dremap.target);
47913     }
47914   dfinal.op1 = dfinal.op0;
47915   dfinal.one_operand_p = true;
47916
47917   /* Test if the final remap can be done with a single insn.  For V4SFmode or
47918      V4SImode this *will* succeed.  For V8HImode or V16QImode it may not.  */
47919   start_sequence ();
47920   ok = expand_vec_perm_1 (&dfinal);
47921   seq = get_insns ();
47922   end_sequence ();
47923
47924   if (!ok)
47925     return false;
47926
47927   if (d->testing_p)
47928     return true;
47929
47930   if (dremap.vmode != dfinal.vmode)
47931     {
47932       dremap.op0 = gen_lowpart (dremap.vmode, dremap.op0);
47933       dremap.op1 = gen_lowpart (dremap.vmode, dremap.op1);
47934     }
47935
47936   ok = expand_vec_perm_1 (&dremap);
47937   gcc_assert (ok);
47938
47939   emit_insn (seq);
47940   return true;
47941 }
47942
47943 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
47944    a single vector cross-lane permutation into vpermq followed
47945    by any of the single insn permutations.  */
47946
47947 static bool
47948 expand_vec_perm_vpermq_perm_1 (struct expand_vec_perm_d *d)
47949 {
47950   struct expand_vec_perm_d dremap, dfinal;
47951   unsigned i, j, nelt = d->nelt, nelt2 = nelt / 2, nelt4 = nelt / 4;
47952   unsigned contents[2];
47953   bool ok;
47954
47955   if (!(TARGET_AVX2
47956         && (d->vmode == V32QImode || d->vmode == V16HImode)
47957         && d->one_operand_p))
47958     return false;
47959
47960   contents[0] = 0;
47961   contents[1] = 0;
47962   for (i = 0; i < nelt2; ++i)
47963     {
47964       contents[0] |= 1u << (d->perm[i] / nelt4);
47965       contents[1] |= 1u << (d->perm[i + nelt2] / nelt4);
47966     }
47967
47968   for (i = 0; i < 2; ++i)
47969     {
47970       unsigned int cnt = 0;
47971       for (j = 0; j < 4; ++j)
47972         if ((contents[i] & (1u << j)) != 0 && ++cnt > 2)
47973           return false;
47974     }
47975
47976   if (d->testing_p)
47977     return true;
47978
47979   dremap = *d;
47980   dremap.vmode = V4DImode;
47981   dremap.nelt = 4;
47982   dremap.target = gen_reg_rtx (V4DImode);
47983   dremap.op0 = gen_lowpart (V4DImode, d->op0);
47984   dremap.op1 = dremap.op0;
47985   dremap.one_operand_p = true;
47986   for (i = 0; i < 2; ++i)
47987     {
47988       unsigned int cnt = 0;
47989       for (j = 0; j < 4; ++j)
47990         if ((contents[i] & (1u << j)) != 0)
47991           dremap.perm[2 * i + cnt++] = j;
47992       for (; cnt < 2; ++cnt)
47993         dremap.perm[2 * i + cnt] = 0;
47994     }
47995
47996   dfinal = *d;
47997   dfinal.op0 = gen_lowpart (dfinal.vmode, dremap.target);
47998   dfinal.op1 = dfinal.op0;
47999   dfinal.one_operand_p = true;
48000   for (i = 0, j = 0; i < nelt; ++i)
48001     {
48002       if (i == nelt2)
48003         j = 2;
48004       dfinal.perm[i] = (d->perm[i] & (nelt4 - 1)) | (j ? nelt2 : 0);
48005       if ((d->perm[i] / nelt4) == dremap.perm[j])
48006         ;
48007       else if ((d->perm[i] / nelt4) == dremap.perm[j + 1])
48008         dfinal.perm[i] |= nelt4;
48009       else
48010         gcc_unreachable ();
48011     }
48012
48013   ok = expand_vec_perm_1 (&dremap);
48014   gcc_assert (ok);
48015
48016   ok = expand_vec_perm_1 (&dfinal);
48017   gcc_assert (ok);
48018
48019   return true;
48020 }
48021
48022 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to expand
48023    a vector permutation using two instructions, vperm2f128 resp.
48024    vperm2i128 followed by any single in-lane permutation.  */
48025
48026 static bool
48027 expand_vec_perm_vperm2f128 (struct expand_vec_perm_d *d)
48028 {
48029   struct expand_vec_perm_d dfirst, dsecond;
48030   unsigned i, j, nelt = d->nelt, nelt2 = nelt / 2, perm;
48031   bool ok;
48032
48033   if (!TARGET_AVX
48034       || GET_MODE_SIZE (d->vmode) != 32
48035       || (d->vmode != V8SFmode && d->vmode != V4DFmode && !TARGET_AVX2))
48036     return false;
48037
48038   dsecond = *d;
48039   dsecond.one_operand_p = false;
48040   dsecond.testing_p = true;
48041
48042   /* ((perm << 2)|perm) & 0x33 is the vperm2[fi]128
48043      immediate.  For perm < 16 the second permutation uses
48044      d->op0 as first operand, for perm >= 16 it uses d->op1
48045      as first operand.  The second operand is the result of
48046      vperm2[fi]128.  */
48047   for (perm = 0; perm < 32; perm++)
48048     {
48049       /* Ignore permutations which do not move anything cross-lane.  */
48050       if (perm < 16)
48051         {
48052           /* The second shuffle for e.g. V4DFmode has
48053              0123 and ABCD operands.
48054              Ignore AB23, as 23 is already in the second lane
48055              of the first operand.  */
48056           if ((perm & 0xc) == (1 << 2)) continue;
48057           /* And 01CD, as 01 is in the first lane of the first
48058              operand.  */
48059           if ((perm & 3) == 0) continue;
48060           /* And 4567, as then the vperm2[fi]128 doesn't change
48061              anything on the original 4567 second operand.  */
48062           if ((perm & 0xf) == ((3 << 2) | 2)) continue;
48063         }
48064       else
48065         {
48066           /* The second shuffle for e.g. V4DFmode has
48067              4567 and ABCD operands.
48068              Ignore AB67, as 67 is already in the second lane
48069              of the first operand.  */
48070           if ((perm & 0xc) == (3 << 2)) continue;
48071           /* And 45CD, as 45 is in the first lane of the first
48072              operand.  */
48073           if ((perm & 3) == 2) continue;
48074           /* And 0123, as then the vperm2[fi]128 doesn't change
48075              anything on the original 0123 first operand.  */
48076           if ((perm & 0xf) == (1 << 2)) continue;
48077         }
48078
48079       for (i = 0; i < nelt; i++)
48080         {
48081           j = d->perm[i] / nelt2;
48082           if (j == ((perm >> (2 * (i >= nelt2))) & 3))
48083             dsecond.perm[i] = nelt + (i & nelt2) + (d->perm[i] & (nelt2 - 1));
48084           else if (j == (unsigned) (i >= nelt2) + 2 * (perm >= 16))
48085             dsecond.perm[i] = d->perm[i] & (nelt - 1);
48086           else
48087             break;
48088         }
48089
48090       if (i == nelt)
48091         {
48092           start_sequence ();
48093           ok = expand_vec_perm_1 (&dsecond);
48094           end_sequence ();
48095         }
48096       else
48097         ok = false;
48098
48099       if (ok)
48100         {
48101           if (d->testing_p)
48102             return true;
48103
48104           /* Found a usable second shuffle.  dfirst will be
48105              vperm2f128 on d->op0 and d->op1.  */
48106           dsecond.testing_p = false;
48107           dfirst = *d;
48108           dfirst.target = gen_reg_rtx (d->vmode);
48109           for (i = 0; i < nelt; i++)
48110             dfirst.perm[i] = (i & (nelt2 - 1))
48111                              + ((perm >> (2 * (i >= nelt2))) & 3) * nelt2;
48112
48113           canonicalize_perm (&dfirst);
48114           ok = expand_vec_perm_1 (&dfirst);
48115           gcc_assert (ok);
48116
48117           /* And dsecond is some single insn shuffle, taking
48118              d->op0 and result of vperm2f128 (if perm < 16) or
48119              d->op1 and result of vperm2f128 (otherwise).  */
48120           if (perm >= 16)
48121             dsecond.op0 = dsecond.op1;
48122           dsecond.op1 = dfirst.target;
48123
48124           ok = expand_vec_perm_1 (&dsecond);
48125           gcc_assert (ok);
48126
48127           return true;
48128         }
48129
48130       /* For one operand, the only useful vperm2f128 permutation is 0x01
48131          aka lanes swap.  */
48132       if (d->one_operand_p)
48133         return false;
48134     }
48135
48136   return false;
48137 }
48138
48139 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to simplify
48140    a two vector permutation using 2 intra-lane interleave insns
48141    and cross-lane shuffle for 32-byte vectors.  */
48142
48143 static bool
48144 expand_vec_perm_interleave3 (struct expand_vec_perm_d *d)
48145 {
48146   unsigned i, nelt;
48147   rtx (*gen) (rtx, rtx, rtx);
48148
48149   if (d->one_operand_p)
48150     return false;
48151   if (TARGET_AVX2 && GET_MODE_SIZE (d->vmode) == 32)
48152     ;
48153   else if (TARGET_AVX && (d->vmode == V8SFmode || d->vmode == V4DFmode))
48154     ;
48155   else
48156     return false;
48157
48158   nelt = d->nelt;
48159   if (d->perm[0] != 0 && d->perm[0] != nelt / 2)
48160     return false;
48161   for (i = 0; i < nelt; i += 2)
48162     if (d->perm[i] != d->perm[0] + i / 2
48163         || d->perm[i + 1] != d->perm[0] + i / 2 + nelt)
48164       return false;
48165
48166   if (d->testing_p)
48167     return true;
48168
48169   switch (d->vmode)
48170     {
48171     case V32QImode:
48172       if (d->perm[0])
48173         gen = gen_vec_interleave_highv32qi;
48174       else
48175         gen = gen_vec_interleave_lowv32qi;
48176       break;
48177     case V16HImode:
48178       if (d->perm[0])
48179         gen = gen_vec_interleave_highv16hi;
48180       else
48181         gen = gen_vec_interleave_lowv16hi;
48182       break;
48183     case V8SImode:
48184       if (d->perm[0])
48185         gen = gen_vec_interleave_highv8si;
48186       else
48187         gen = gen_vec_interleave_lowv8si;
48188       break;
48189     case V4DImode:
48190       if (d->perm[0])
48191         gen = gen_vec_interleave_highv4di;
48192       else
48193         gen = gen_vec_interleave_lowv4di;
48194       break;
48195     case V8SFmode:
48196       if (d->perm[0])
48197         gen = gen_vec_interleave_highv8sf;
48198       else
48199         gen = gen_vec_interleave_lowv8sf;
48200       break;
48201     case V4DFmode:
48202       if (d->perm[0])
48203         gen = gen_vec_interleave_highv4df;
48204       else
48205         gen = gen_vec_interleave_lowv4df;
48206       break;
48207     default:
48208       gcc_unreachable ();
48209     }
48210
48211   emit_insn (gen (d->target, d->op0, d->op1));
48212   return true;
48213 }
48214
48215 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Try to implement
48216    a single vector permutation using a single intra-lane vector
48217    permutation, vperm2f128 swapping the lanes and vblend* insn blending
48218    the non-swapped and swapped vectors together.  */
48219
48220 static bool
48221 expand_vec_perm_vperm2f128_vblend (struct expand_vec_perm_d *d)
48222 {
48223   struct expand_vec_perm_d dfirst, dsecond;
48224   unsigned i, j, msk, nelt = d->nelt, nelt2 = nelt / 2;
48225   rtx_insn *seq;
48226   bool ok;
48227   rtx (*blend) (rtx, rtx, rtx, rtx) = NULL;
48228
48229   if (!TARGET_AVX
48230       || TARGET_AVX2
48231       || (d->vmode != V8SFmode && d->vmode != V4DFmode)
48232       || !d->one_operand_p)
48233     return false;
48234
48235   dfirst = *d;
48236   for (i = 0; i < nelt; i++)
48237     dfirst.perm[i] = 0xff;
48238   for (i = 0, msk = 0; i < nelt; i++)
48239     {
48240       j = (d->perm[i] & nelt2) ? i | nelt2 : i & ~nelt2;
48241       if (dfirst.perm[j] != 0xff && dfirst.perm[j] != d->perm[i])
48242         return false;
48243       dfirst.perm[j] = d->perm[i];
48244       if (j != i)
48245         msk |= (1 << i);
48246     }
48247   for (i = 0; i < nelt; i++)
48248     if (dfirst.perm[i] == 0xff)
48249       dfirst.perm[i] = i;
48250
48251   if (!d->testing_p)
48252     dfirst.target = gen_reg_rtx (dfirst.vmode);
48253
48254   start_sequence ();
48255   ok = expand_vec_perm_1 (&dfirst);
48256   seq = get_insns ();
48257   end_sequence ();
48258
48259   if (!ok)
48260     return false;
48261
48262   if (d->testing_p)
48263     return true;
48264
48265   emit_insn (seq);
48266
48267   dsecond = *d;
48268   dsecond.op0 = dfirst.target;
48269   dsecond.op1 = dfirst.target;
48270   dsecond.one_operand_p = true;
48271   dsecond.target = gen_reg_rtx (dsecond.vmode);
48272   for (i = 0; i < nelt; i++)
48273     dsecond.perm[i] = i ^ nelt2;
48274
48275   ok = expand_vec_perm_1 (&dsecond);
48276   gcc_assert (ok);
48277
48278   blend = d->vmode == V8SFmode ? gen_avx_blendps256 : gen_avx_blendpd256;
48279   emit_insn (blend (d->target, dfirst.target, dsecond.target, GEN_INT (msk)));
48280   return true;
48281 }
48282
48283 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Implement a V4DF
48284    permutation using two vperm2f128, followed by a vshufpd insn blending
48285    the two vectors together.  */
48286
48287 static bool
48288 expand_vec_perm_2vperm2f128_vshuf (struct expand_vec_perm_d *d)
48289 {
48290   struct expand_vec_perm_d dfirst, dsecond, dthird;
48291   bool ok;
48292
48293   if (!TARGET_AVX || (d->vmode != V4DFmode))
48294     return false;
48295
48296   if (d->testing_p)
48297     return true;
48298
48299   dfirst = *d;
48300   dsecond = *d;
48301   dthird = *d;
48302
48303   dfirst.perm[0] = (d->perm[0] & ~1);
48304   dfirst.perm[1] = (d->perm[0] & ~1) + 1;
48305   dfirst.perm[2] = (d->perm[2] & ~1);
48306   dfirst.perm[3] = (d->perm[2] & ~1) + 1;
48307   dsecond.perm[0] = (d->perm[1] & ~1);
48308   dsecond.perm[1] = (d->perm[1] & ~1) + 1;
48309   dsecond.perm[2] = (d->perm[3] & ~1);
48310   dsecond.perm[3] = (d->perm[3] & ~1) + 1;
48311   dthird.perm[0] = (d->perm[0] % 2);
48312   dthird.perm[1] = (d->perm[1] % 2) + 4;
48313   dthird.perm[2] = (d->perm[2] % 2) + 2;
48314   dthird.perm[3] = (d->perm[3] % 2) + 6;
48315
48316   dfirst.target = gen_reg_rtx (dfirst.vmode);
48317   dsecond.target = gen_reg_rtx (dsecond.vmode);
48318   dthird.op0 = dfirst.target;
48319   dthird.op1 = dsecond.target;
48320   dthird.one_operand_p = false;
48321
48322   canonicalize_perm (&dfirst);
48323   canonicalize_perm (&dsecond);
48324
48325   ok = expand_vec_perm_1 (&dfirst)
48326        && expand_vec_perm_1 (&dsecond)
48327        && expand_vec_perm_1 (&dthird);
48328
48329   gcc_assert (ok);
48330
48331   return true;
48332 }
48333
48334 /* A subroutine of expand_vec_perm_even_odd_1.  Implement the double-word
48335    permutation with two pshufb insns and an ior.  We should have already
48336    failed all two instruction sequences.  */
48337
48338 static bool
48339 expand_vec_perm_pshufb2 (struct expand_vec_perm_d *d)
48340 {
48341   rtx rperm[2][16], vperm, l, h, op, m128;
48342   unsigned int i, nelt, eltsz;
48343
48344   if (!TARGET_SSSE3 || GET_MODE_SIZE (d->vmode) != 16)
48345     return false;
48346   gcc_assert (!d->one_operand_p);
48347
48348   if (d->testing_p)
48349     return true;
48350
48351   nelt = d->nelt;
48352   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
48353
48354   /* Generate two permutation masks.  If the required element is within
48355      the given vector it is shuffled into the proper lane.  If the required
48356      element is in the other vector, force a zero into the lane by setting
48357      bit 7 in the permutation mask.  */
48358   m128 = GEN_INT (-128);
48359   for (i = 0; i < nelt; ++i)
48360     {
48361       unsigned j, e = d->perm[i];
48362       unsigned which = (e >= nelt);
48363       if (e >= nelt)
48364         e -= nelt;
48365
48366       for (j = 0; j < eltsz; ++j)
48367         {
48368           rperm[which][i*eltsz + j] = GEN_INT (e*eltsz + j);
48369           rperm[1-which][i*eltsz + j] = m128;
48370         }
48371     }
48372
48373   vperm = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, rperm[0]));
48374   vperm = force_reg (V16QImode, vperm);
48375
48376   l = gen_reg_rtx (V16QImode);
48377   op = gen_lowpart (V16QImode, d->op0);
48378   emit_insn (gen_ssse3_pshufbv16qi3 (l, op, vperm));
48379
48380   vperm = gen_rtx_CONST_VECTOR (V16QImode, gen_rtvec_v (16, rperm[1]));
48381   vperm = force_reg (V16QImode, vperm);
48382
48383   h = gen_reg_rtx (V16QImode);
48384   op = gen_lowpart (V16QImode, d->op1);
48385   emit_insn (gen_ssse3_pshufbv16qi3 (h, op, vperm));
48386
48387   op = d->target;
48388   if (d->vmode != V16QImode)
48389     op = gen_reg_rtx (V16QImode);
48390   emit_insn (gen_iorv16qi3 (op, l, h));
48391   if (op != d->target)
48392     emit_move_insn (d->target, gen_lowpart (d->vmode, op));
48393
48394   return true;
48395 }
48396
48397 /* Implement arbitrary permutation of one V32QImode and V16QImode operand
48398    with two vpshufb insns, vpermq and vpor.  We should have already failed
48399    all two or three instruction sequences.  */
48400
48401 static bool
48402 expand_vec_perm_vpshufb2_vpermq (struct expand_vec_perm_d *d)
48403 {
48404   rtx rperm[2][32], vperm, l, h, hp, op, m128;
48405   unsigned int i, nelt, eltsz;
48406
48407   if (!TARGET_AVX2
48408       || !d->one_operand_p
48409       || (d->vmode != V32QImode && d->vmode != V16HImode))
48410     return false;
48411
48412   if (d->testing_p)
48413     return true;
48414
48415   nelt = d->nelt;
48416   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
48417
48418   /* Generate two permutation masks.  If the required element is within
48419      the same lane, it is shuffled in.  If the required element from the
48420      other lane, force a zero by setting bit 7 in the permutation mask.
48421      In the other mask the mask has non-negative elements if element
48422      is requested from the other lane, but also moved to the other lane,
48423      so that the result of vpshufb can have the two V2TImode halves
48424      swapped.  */
48425   m128 = GEN_INT (-128);
48426   for (i = 0; i < nelt; ++i)
48427     {
48428       unsigned j, e = d->perm[i] & (nelt / 2 - 1);
48429       unsigned which = ((d->perm[i] ^ i) & (nelt / 2)) * eltsz;
48430
48431       for (j = 0; j < eltsz; ++j)
48432         {
48433           rperm[!!which][(i * eltsz + j) ^ which] = GEN_INT (e * eltsz + j);
48434           rperm[!which][(i * eltsz + j) ^ (which ^ 16)] = m128;
48435         }
48436     }
48437
48438   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[1]));
48439   vperm = force_reg (V32QImode, vperm);
48440
48441   h = gen_reg_rtx (V32QImode);
48442   op = gen_lowpart (V32QImode, d->op0);
48443   emit_insn (gen_avx2_pshufbv32qi3 (h, op, vperm));
48444
48445   /* Swap the 128-byte lanes of h into hp.  */
48446   hp = gen_reg_rtx (V4DImode);
48447   op = gen_lowpart (V4DImode, h);
48448   emit_insn (gen_avx2_permv4di_1 (hp, op, const2_rtx, GEN_INT (3), const0_rtx,
48449                                   const1_rtx));
48450
48451   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[0]));
48452   vperm = force_reg (V32QImode, vperm);
48453
48454   l = gen_reg_rtx (V32QImode);
48455   op = gen_lowpart (V32QImode, d->op0);
48456   emit_insn (gen_avx2_pshufbv32qi3 (l, op, vperm));
48457
48458   op = d->target;
48459   if (d->vmode != V32QImode)
48460     op = gen_reg_rtx (V32QImode);
48461   emit_insn (gen_iorv32qi3 (op, l, gen_lowpart (V32QImode, hp)));
48462   if (op != d->target)
48463     emit_move_insn (d->target, gen_lowpart (d->vmode, op));
48464
48465   return true;
48466 }
48467
48468 /* A subroutine of expand_vec_perm_even_odd_1.  Implement extract-even
48469    and extract-odd permutations of two V32QImode and V16QImode operand
48470    with two vpshufb insns, vpor and vpermq.  We should have already
48471    failed all two or three instruction sequences.  */
48472
48473 static bool
48474 expand_vec_perm_vpshufb2_vpermq_even_odd (struct expand_vec_perm_d *d)
48475 {
48476   rtx rperm[2][32], vperm, l, h, ior, op, m128;
48477   unsigned int i, nelt, eltsz;
48478
48479   if (!TARGET_AVX2
48480       || d->one_operand_p
48481       || (d->vmode != V32QImode && d->vmode != V16HImode))
48482     return false;
48483
48484   for (i = 0; i < d->nelt; ++i)
48485     if ((d->perm[i] ^ (i * 2)) & (3 * d->nelt / 2))
48486       return false;
48487
48488   if (d->testing_p)
48489     return true;
48490
48491   nelt = d->nelt;
48492   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
48493
48494   /* Generate two permutation masks.  In the first permutation mask
48495      the first quarter will contain indexes for the first half
48496      of the op0, the second quarter will contain bit 7 set, third quarter
48497      will contain indexes for the second half of the op0 and the
48498      last quarter bit 7 set.  In the second permutation mask
48499      the first quarter will contain bit 7 set, the second quarter
48500      indexes for the first half of the op1, the third quarter bit 7 set
48501      and last quarter indexes for the second half of the op1.
48502      I.e. the first mask e.g. for V32QImode extract even will be:
48503      0, 2, ..., 0xe, -128, ..., -128, 0, 2, ..., 0xe, -128, ..., -128
48504      (all values masked with 0xf except for -128) and second mask
48505      for extract even will be
48506      -128, ..., -128, 0, 2, ..., 0xe, -128, ..., -128, 0, 2, ..., 0xe.  */
48507   m128 = GEN_INT (-128);
48508   for (i = 0; i < nelt; ++i)
48509     {
48510       unsigned j, e = d->perm[i] & (nelt / 2 - 1);
48511       unsigned which = d->perm[i] >= nelt;
48512       unsigned xorv = (i >= nelt / 4 && i < 3 * nelt / 4) ? 24 : 0;
48513
48514       for (j = 0; j < eltsz; ++j)
48515         {
48516           rperm[which][(i * eltsz + j) ^ xorv] = GEN_INT (e * eltsz + j);
48517           rperm[1 - which][(i * eltsz + j) ^ xorv] = m128;
48518         }
48519     }
48520
48521   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[0]));
48522   vperm = force_reg (V32QImode, vperm);
48523
48524   l = gen_reg_rtx (V32QImode);
48525   op = gen_lowpart (V32QImode, d->op0);
48526   emit_insn (gen_avx2_pshufbv32qi3 (l, op, vperm));
48527
48528   vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[1]));
48529   vperm = force_reg (V32QImode, vperm);
48530
48531   h = gen_reg_rtx (V32QImode);
48532   op = gen_lowpart (V32QImode, d->op1);
48533   emit_insn (gen_avx2_pshufbv32qi3 (h, op, vperm));
48534
48535   ior = gen_reg_rtx (V32QImode);
48536   emit_insn (gen_iorv32qi3 (ior, l, h));
48537
48538   /* Permute the V4DImode quarters using { 0, 2, 1, 3 } permutation.  */
48539   op = gen_reg_rtx (V4DImode);
48540   ior = gen_lowpart (V4DImode, ior);
48541   emit_insn (gen_avx2_permv4di_1 (op, ior, const0_rtx, const2_rtx,
48542                                   const1_rtx, GEN_INT (3)));
48543   emit_move_insn (d->target, gen_lowpart (d->vmode, op));
48544
48545   return true;
48546 }
48547
48548 /* A subroutine of expand_vec_perm_even_odd_1.  Implement extract-even
48549    and extract-odd permutations of two V16QI, V8HI, V16HI or V32QI operands
48550    with two "and" and "pack" or two "shift" and "pack" insns.  We should
48551    have already failed all two instruction sequences.  */
48552
48553 static bool
48554 expand_vec_perm_even_odd_pack (struct expand_vec_perm_d *d)
48555 {
48556   rtx op, dop0, dop1, t, rperm[16];
48557   unsigned i, odd, c, s, nelt = d->nelt;
48558   bool end_perm = false;
48559   machine_mode half_mode;
48560   rtx (*gen_and) (rtx, rtx, rtx);
48561   rtx (*gen_pack) (rtx, rtx, rtx);
48562   rtx (*gen_shift) (rtx, rtx, rtx);
48563
48564   if (d->one_operand_p)
48565     return false;
48566
48567   switch (d->vmode)
48568     {
48569     case V8HImode:
48570       /* Required for "pack".  */
48571       if (!TARGET_SSE4_1)
48572         return false;
48573       c = 0xffff;
48574       s = 16;
48575       half_mode = V4SImode;
48576       gen_and = gen_andv4si3;
48577       gen_pack = gen_sse4_1_packusdw;
48578       gen_shift = gen_lshrv4si3;
48579       break;
48580     case V16QImode:
48581       /* No check as all instructions are SSE2.  */
48582       c = 0xff;
48583       s = 8;
48584       half_mode = V8HImode;
48585       gen_and = gen_andv8hi3;
48586       gen_pack = gen_sse2_packuswb;
48587       gen_shift = gen_lshrv8hi3;
48588       break;
48589     case V16HImode:
48590       if (!TARGET_AVX2)
48591         return false;
48592       c = 0xffff;
48593       s = 16;
48594       half_mode = V8SImode;
48595       gen_and = gen_andv8si3;
48596       gen_pack = gen_avx2_packusdw;
48597       gen_shift = gen_lshrv8si3;
48598       end_perm = true;
48599       break;
48600     case V32QImode:
48601       if (!TARGET_AVX2)
48602         return false;
48603       c = 0xff;
48604       s = 8;
48605       half_mode = V16HImode;
48606       gen_and = gen_andv16hi3;
48607       gen_pack = gen_avx2_packuswb;
48608       gen_shift = gen_lshrv16hi3;
48609       end_perm = true;
48610       break;
48611     default:
48612       /* Only V8HI, V16QI, V16HI and V32QI modes are more profitable than
48613          general shuffles.  */
48614       return false;
48615     }
48616
48617   /* Check that permutation is even or odd.  */
48618   odd = d->perm[0];
48619   if (odd > 1)
48620     return false;
48621
48622   for (i = 1; i < nelt; ++i)
48623     if (d->perm[i] != 2 * i + odd)
48624       return false;
48625
48626   if (d->testing_p)
48627     return true;
48628
48629   dop0 = gen_reg_rtx (half_mode);
48630   dop1 = gen_reg_rtx (half_mode);
48631   if (odd == 0)
48632     {
48633       for (i = 0; i < nelt / 2; i++)
48634         rperm[i] = GEN_INT (c);
48635       t = gen_rtx_CONST_VECTOR (half_mode, gen_rtvec_v (nelt / 2, rperm));
48636       t = force_reg (half_mode, t);
48637       emit_insn (gen_and (dop0, t, gen_lowpart (half_mode, d->op0)));
48638       emit_insn (gen_and (dop1, t, gen_lowpart (half_mode, d->op1)));
48639     }
48640   else
48641     {
48642       emit_insn (gen_shift (dop0,
48643                             gen_lowpart (half_mode, d->op0),
48644                             GEN_INT (s)));
48645       emit_insn (gen_shift (dop1,
48646                             gen_lowpart (half_mode, d->op1),
48647                             GEN_INT (s)));
48648     }
48649   /* In AVX2 for 256 bit case we need to permute pack result.  */
48650   if (TARGET_AVX2 && end_perm)
48651     {
48652       op = gen_reg_rtx (d->vmode);
48653       t = gen_reg_rtx (V4DImode);
48654       emit_insn (gen_pack (op, dop0, dop1));
48655       emit_insn (gen_avx2_permv4di_1 (t,
48656                                       gen_lowpart (V4DImode, op),
48657                                       const0_rtx,
48658                                       const2_rtx,
48659                                       const1_rtx,
48660                                       GEN_INT (3)));
48661       emit_move_insn (d->target, gen_lowpart (d->vmode, t));
48662     }
48663   else
48664     emit_insn (gen_pack (d->target, dop0, dop1));
48665
48666   return true;
48667 }
48668
48669 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Implement extract-even
48670    and extract-odd permutations.  */
48671
48672 static bool
48673 expand_vec_perm_even_odd_1 (struct expand_vec_perm_d *d, unsigned odd)
48674 {
48675   rtx t1, t2, t3, t4, t5;
48676
48677   switch (d->vmode)
48678     {
48679     case V4DFmode:
48680       if (d->testing_p)
48681         break;
48682       t1 = gen_reg_rtx (V4DFmode);
48683       t2 = gen_reg_rtx (V4DFmode);
48684
48685       /* Shuffle the lanes around into { 0 1 4 5 } and { 2 3 6 7 }.  */
48686       emit_insn (gen_avx_vperm2f128v4df3 (t1, d->op0, d->op1, GEN_INT (0x20)));
48687       emit_insn (gen_avx_vperm2f128v4df3 (t2, d->op0, d->op1, GEN_INT (0x31)));
48688
48689       /* Now an unpck[lh]pd will produce the result required.  */
48690       if (odd)
48691         t3 = gen_avx_unpckhpd256 (d->target, t1, t2);
48692       else
48693         t3 = gen_avx_unpcklpd256 (d->target, t1, t2);
48694       emit_insn (t3);
48695       break;
48696
48697     case V8SFmode:
48698       {
48699         int mask = odd ? 0xdd : 0x88;
48700
48701         if (d->testing_p)
48702           break;
48703         t1 = gen_reg_rtx (V8SFmode);
48704         t2 = gen_reg_rtx (V8SFmode);
48705         t3 = gen_reg_rtx (V8SFmode);
48706
48707         /* Shuffle within the 128-bit lanes to produce:
48708            { 0 2 8 a 4 6 c e } | { 1 3 9 b 5 7 d f }.  */
48709         emit_insn (gen_avx_shufps256 (t1, d->op0, d->op1,
48710                                       GEN_INT (mask)));
48711
48712         /* Shuffle the lanes around to produce:
48713            { 4 6 c e 0 2 8 a } and { 5 7 d f 1 3 9 b }.  */
48714         emit_insn (gen_avx_vperm2f128v8sf3 (t2, t1, t1,
48715                                             GEN_INT (0x3)));
48716
48717         /* Shuffle within the 128-bit lanes to produce:
48718            { 0 2 4 6 4 6 0 2 } | { 1 3 5 7 5 7 1 3 }.  */
48719         emit_insn (gen_avx_shufps256 (t3, t1, t2, GEN_INT (0x44)));
48720
48721         /* Shuffle within the 128-bit lanes to produce:
48722            { 8 a c e c e 8 a } | { 9 b d f d f 9 b }.  */
48723         emit_insn (gen_avx_shufps256 (t2, t1, t2, GEN_INT (0xee)));
48724
48725         /* Shuffle the lanes around to produce:
48726            { 0 2 4 6 8 a c e } | { 1 3 5 7 9 b d f }.  */
48727         emit_insn (gen_avx_vperm2f128v8sf3 (d->target, t3, t2,
48728                                             GEN_INT (0x20)));
48729       }
48730       break;
48731
48732     case V2DFmode:
48733     case V4SFmode:
48734     case V2DImode:
48735     case V4SImode:
48736       /* These are always directly implementable by expand_vec_perm_1.  */
48737       gcc_unreachable ();
48738
48739     case V8HImode:
48740       if (TARGET_SSE4_1)
48741         return expand_vec_perm_even_odd_pack (d);
48742       else if (TARGET_SSSE3 && !TARGET_SLOW_PSHUFB)
48743         return expand_vec_perm_pshufb2 (d);
48744       else
48745         {
48746           if (d->testing_p)
48747             break;
48748           /* We need 2*log2(N)-1 operations to achieve odd/even
48749              with interleave. */
48750           t1 = gen_reg_rtx (V8HImode);
48751           t2 = gen_reg_rtx (V8HImode);
48752           emit_insn (gen_vec_interleave_highv8hi (t1, d->op0, d->op1));
48753           emit_insn (gen_vec_interleave_lowv8hi (d->target, d->op0, d->op1));
48754           emit_insn (gen_vec_interleave_highv8hi (t2, d->target, t1));
48755           emit_insn (gen_vec_interleave_lowv8hi (d->target, d->target, t1));
48756           if (odd)
48757             t3 = gen_vec_interleave_highv8hi (d->target, d->target, t2);
48758           else
48759             t3 = gen_vec_interleave_lowv8hi (d->target, d->target, t2);
48760           emit_insn (t3);
48761         }
48762       break;
48763
48764     case V16QImode:
48765       return expand_vec_perm_even_odd_pack (d);
48766
48767     case V16HImode:
48768     case V32QImode:
48769       return expand_vec_perm_even_odd_pack (d);
48770
48771     case V4DImode:
48772       if (!TARGET_AVX2)
48773         {
48774           struct expand_vec_perm_d d_copy = *d;
48775           d_copy.vmode = V4DFmode;
48776           if (d->testing_p)
48777             d_copy.target = gen_lowpart (V4DFmode, d->target);
48778           else
48779             d_copy.target = gen_reg_rtx (V4DFmode);
48780           d_copy.op0 = gen_lowpart (V4DFmode, d->op0);
48781           d_copy.op1 = gen_lowpart (V4DFmode, d->op1);
48782           if (expand_vec_perm_even_odd_1 (&d_copy, odd))
48783             {
48784               if (!d->testing_p)
48785                 emit_move_insn (d->target,
48786                                 gen_lowpart (V4DImode, d_copy.target));
48787               return true;
48788             }
48789           return false;
48790         }
48791
48792       if (d->testing_p)
48793         break;
48794
48795       t1 = gen_reg_rtx (V4DImode);
48796       t2 = gen_reg_rtx (V4DImode);
48797
48798       /* Shuffle the lanes around into { 0 1 4 5 } and { 2 3 6 7 }.  */
48799       emit_insn (gen_avx2_permv2ti (t1, d->op0, d->op1, GEN_INT (0x20)));
48800       emit_insn (gen_avx2_permv2ti (t2, d->op0, d->op1, GEN_INT (0x31)));
48801
48802       /* Now an vpunpck[lh]qdq will produce the result required.  */
48803       if (odd)
48804         t3 = gen_avx2_interleave_highv4di (d->target, t1, t2);
48805       else
48806         t3 = gen_avx2_interleave_lowv4di (d->target, t1, t2);
48807       emit_insn (t3);
48808       break;
48809
48810     case V8SImode:
48811       if (!TARGET_AVX2)
48812         {
48813           struct expand_vec_perm_d d_copy = *d;
48814           d_copy.vmode = V8SFmode;
48815           if (d->testing_p)
48816             d_copy.target = gen_lowpart (V8SFmode, d->target);
48817           else
48818             d_copy.target = gen_reg_rtx (V8SFmode);
48819           d_copy.op0 = gen_lowpart (V8SFmode, d->op0);
48820           d_copy.op1 = gen_lowpart (V8SFmode, d->op1);
48821           if (expand_vec_perm_even_odd_1 (&d_copy, odd))
48822             {
48823               if (!d->testing_p)
48824                 emit_move_insn (d->target,
48825                                 gen_lowpart (V8SImode, d_copy.target));
48826               return true;
48827             }
48828           return false;
48829         }
48830
48831       if (d->testing_p)
48832         break;
48833
48834       t1 = gen_reg_rtx (V8SImode);
48835       t2 = gen_reg_rtx (V8SImode);
48836       t3 = gen_reg_rtx (V4DImode);
48837       t4 = gen_reg_rtx (V4DImode);
48838       t5 = gen_reg_rtx (V4DImode);
48839
48840       /* Shuffle the lanes around into
48841          { 0 1 2 3 8 9 a b } and { 4 5 6 7 c d e f }.  */
48842       emit_insn (gen_avx2_permv2ti (t3, gen_lowpart (V4DImode, d->op0),
48843                                     gen_lowpart (V4DImode, d->op1),
48844                                     GEN_INT (0x20)));
48845       emit_insn (gen_avx2_permv2ti (t4, gen_lowpart (V4DImode, d->op0),
48846                                     gen_lowpart (V4DImode, d->op1),
48847                                     GEN_INT (0x31)));
48848
48849       /* Swap the 2nd and 3rd position in each lane into
48850          { 0 2 1 3 8 a 9 b } and { 4 6 5 7 c e d f }.  */
48851       emit_insn (gen_avx2_pshufdv3 (t1, gen_lowpart (V8SImode, t3),
48852                                     GEN_INT (2 * 4 + 1 * 16 + 3 * 64)));
48853       emit_insn (gen_avx2_pshufdv3 (t2, gen_lowpart (V8SImode, t4),
48854                                     GEN_INT (2 * 4 + 1 * 16 + 3 * 64)));
48855
48856       /* Now an vpunpck[lh]qdq will produce
48857          { 0 2 4 6 8 a c e } resp. { 1 3 5 7 9 b d f }.  */
48858       if (odd)
48859         t3 = gen_avx2_interleave_highv4di (t5, gen_lowpart (V4DImode, t1),
48860                                            gen_lowpart (V4DImode, t2));
48861       else
48862         t3 = gen_avx2_interleave_lowv4di (t5, gen_lowpart (V4DImode, t1),
48863                                           gen_lowpart (V4DImode, t2));
48864       emit_insn (t3);
48865       emit_move_insn (d->target, gen_lowpart (V8SImode, t5));
48866       break;
48867
48868     default:
48869       gcc_unreachable ();
48870     }
48871
48872   return true;
48873 }
48874
48875 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Pattern match
48876    extract-even and extract-odd permutations.  */
48877
48878 static bool
48879 expand_vec_perm_even_odd (struct expand_vec_perm_d *d)
48880 {
48881   unsigned i, odd, nelt = d->nelt;
48882
48883   odd = d->perm[0];
48884   if (odd != 0 && odd != 1)
48885     return false;
48886
48887   for (i = 1; i < nelt; ++i)
48888     if (d->perm[i] != 2 * i + odd)
48889       return false;
48890
48891   return expand_vec_perm_even_odd_1 (d, odd);
48892 }
48893
48894 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Implement broadcast
48895    permutations.  We assume that expand_vec_perm_1 has already failed.  */
48896
48897 static bool
48898 expand_vec_perm_broadcast_1 (struct expand_vec_perm_d *d)
48899 {
48900   unsigned elt = d->perm[0], nelt2 = d->nelt / 2;
48901   machine_mode vmode = d->vmode;
48902   unsigned char perm2[4];
48903   rtx op0 = d->op0, dest;
48904   bool ok;
48905
48906   switch (vmode)
48907     {
48908     case V4DFmode:
48909     case V8SFmode:
48910       /* These are special-cased in sse.md so that we can optionally
48911          use the vbroadcast instruction.  They expand to two insns
48912          if the input happens to be in a register.  */
48913       gcc_unreachable ();
48914
48915     case V2DFmode:
48916     case V2DImode:
48917     case V4SFmode:
48918     case V4SImode:
48919       /* These are always implementable using standard shuffle patterns.  */
48920       gcc_unreachable ();
48921
48922     case V8HImode:
48923     case V16QImode:
48924       /* These can be implemented via interleave.  We save one insn by
48925          stopping once we have promoted to V4SImode and then use pshufd.  */
48926       if (d->testing_p)
48927         return true;
48928       do
48929         {
48930           rtx dest;
48931           rtx (*gen) (rtx, rtx, rtx)
48932             = vmode == V16QImode ? gen_vec_interleave_lowv16qi
48933                                  : gen_vec_interleave_lowv8hi;
48934
48935           if (elt >= nelt2)
48936             {
48937               gen = vmode == V16QImode ? gen_vec_interleave_highv16qi
48938                                        : gen_vec_interleave_highv8hi;
48939               elt -= nelt2;
48940             }
48941           nelt2 /= 2;
48942
48943           dest = gen_reg_rtx (vmode);
48944           emit_insn (gen (dest, op0, op0));
48945           vmode = get_mode_wider_vector (vmode);
48946           op0 = gen_lowpart (vmode, dest);
48947         }
48948       while (vmode != V4SImode);
48949
48950       memset (perm2, elt, 4);
48951       dest = gen_reg_rtx (V4SImode);
48952       ok = expand_vselect (dest, op0, perm2, 4, d->testing_p);
48953       gcc_assert (ok);
48954       if (!d->testing_p)
48955         emit_move_insn (d->target, gen_lowpart (d->vmode, dest));
48956       return true;
48957
48958     case V64QImode:
48959     case V32QImode:
48960     case V16HImode:
48961     case V8SImode:
48962     case V4DImode:
48963       /* For AVX2 broadcasts of the first element vpbroadcast* or
48964          vpermq should be used by expand_vec_perm_1.  */
48965       gcc_assert (!TARGET_AVX2 || d->perm[0]);
48966       return false;
48967
48968     default:
48969       gcc_unreachable ();
48970     }
48971 }
48972
48973 /* A subroutine of ix86_expand_vec_perm_builtin_1.  Pattern match
48974    broadcast permutations.  */
48975
48976 static bool
48977 expand_vec_perm_broadcast (struct expand_vec_perm_d *d)
48978 {
48979   unsigned i, elt, nelt = d->nelt;
48980
48981   if (!d->one_operand_p)
48982     return false;
48983
48984   elt = d->perm[0];
48985   for (i = 1; i < nelt; ++i)
48986     if (d->perm[i] != elt)
48987       return false;
48988
48989   return expand_vec_perm_broadcast_1 (d);
48990 }
48991
48992 /* Implement arbitrary permutations of two V64QImode operands
48993    will 2 vpermi2w, 2 vpshufb and one vpor instruction.  */
48994 static bool
48995 expand_vec_perm_vpermi2_vpshub2 (struct expand_vec_perm_d *d)
48996 {
48997   if (!TARGET_AVX512BW || !(d->vmode == V64QImode))
48998     return false;
48999
49000   if (d->testing_p)
49001     return true;
49002
49003   struct expand_vec_perm_d ds[2];
49004   rtx rperm[128], vperm, target0, target1;
49005   unsigned int i, nelt;
49006   machine_mode vmode;
49007
49008   nelt = d->nelt;
49009   vmode = V64QImode;
49010
49011   for (i = 0; i < 2; i++)
49012     {
49013       ds[i] = *d;
49014       ds[i].vmode = V32HImode;
49015       ds[i].nelt = 32;
49016       ds[i].target = gen_reg_rtx (V32HImode);
49017       ds[i].op0 = gen_lowpart (V32HImode, d->op0);
49018       ds[i].op1 = gen_lowpart (V32HImode, d->op1);
49019     }
49020
49021   /* Prepare permutations such that the first one takes care of
49022      putting the even bytes into the right positions or one higher
49023      positions (ds[0]) and the second one takes care of
49024      putting the odd bytes into the right positions or one below
49025      (ds[1]).  */
49026
49027   for (i = 0; i < nelt; i++)
49028     {
49029       ds[i & 1].perm[i / 2] = d->perm[i] / 2;
49030       if (i & 1)
49031         {
49032           rperm[i] = constm1_rtx;
49033           rperm[i + 64] = GEN_INT ((i & 14) + (d->perm[i] & 1));
49034         }
49035       else
49036         {
49037           rperm[i] = GEN_INT ((i & 14) + (d->perm[i] & 1));
49038           rperm[i + 64] = constm1_rtx;
49039         }
49040     }
49041
49042   bool ok = expand_vec_perm_1 (&ds[0]);
49043   gcc_assert (ok);
49044   ds[0].target = gen_lowpart (V64QImode, ds[0].target);
49045
49046   ok = expand_vec_perm_1 (&ds[1]);
49047   gcc_assert (ok);
49048   ds[1].target = gen_lowpart (V64QImode, ds[1].target);
49049
49050   vperm = gen_rtx_CONST_VECTOR (V64QImode, gen_rtvec_v (64, rperm));
49051   vperm = force_reg (vmode, vperm);
49052   target0 = gen_reg_rtx (V64QImode);
49053   emit_insn (gen_avx512bw_pshufbv64qi3 (target0, ds[0].target, vperm));
49054
49055   vperm = gen_rtx_CONST_VECTOR (V64QImode, gen_rtvec_v (64, rperm + 64));
49056   vperm = force_reg (vmode, vperm);
49057   target1 = gen_reg_rtx (V64QImode);
49058   emit_insn (gen_avx512bw_pshufbv64qi3 (target1, ds[1].target, vperm));
49059
49060   emit_insn (gen_iorv64qi3 (d->target, target0, target1));
49061   return true;
49062 }
49063
49064 /* Implement arbitrary permutation of two V32QImode and V16QImode operands
49065    with 4 vpshufb insns, 2 vpermq and 3 vpor.  We should have already failed
49066    all the shorter instruction sequences.  */
49067
49068 static bool
49069 expand_vec_perm_vpshufb4_vpermq2 (struct expand_vec_perm_d *d)
49070 {
49071   rtx rperm[4][32], vperm, l[2], h[2], op, m128;
49072   unsigned int i, nelt, eltsz;
49073   bool used[4];
49074
49075   if (!TARGET_AVX2
49076       || d->one_operand_p
49077       || (d->vmode != V32QImode && d->vmode != V16HImode))
49078     return false;
49079
49080   if (d->testing_p)
49081     return true;
49082
49083   nelt = d->nelt;
49084   eltsz = GET_MODE_SIZE (GET_MODE_INNER (d->vmode));
49085
49086   /* Generate 4 permutation masks.  If the required element is within
49087      the same lane, it is shuffled in.  If the required element from the
49088      other lane, force a zero by setting bit 7 in the permutation mask.
49089      In the other mask the mask has non-negative elements if element
49090      is requested from the other lane, but also moved to the other lane,
49091      so that the result of vpshufb can have the two V2TImode halves
49092      swapped.  */
49093   m128 = GEN_INT (-128);
49094   for (i = 0; i < 32; ++i)
49095     {
49096       rperm[0][i] = m128;
49097       rperm[1][i] = m128;
49098       rperm[2][i] = m128;
49099       rperm[3][i] = m128;
49100     }
49101   used[0] = false;
49102   used[1] = false;
49103   used[2] = false;
49104   used[3] = false;
49105   for (i = 0; i < nelt; ++i)
49106     {
49107       unsigned j, e = d->perm[i] & (nelt / 2 - 1);
49108       unsigned xlane = ((d->perm[i] ^ i) & (nelt / 2)) * eltsz;
49109       unsigned int which = ((d->perm[i] & nelt) ? 2 : 0) + (xlane ? 1 : 0);
49110
49111       for (j = 0; j < eltsz; ++j)
49112         rperm[which][(i * eltsz + j) ^ xlane] = GEN_INT (e * eltsz + j);
49113       used[which] = true;
49114     }
49115
49116   for (i = 0; i < 2; ++i)
49117     {
49118       if (!used[2 * i + 1])
49119         {
49120           h[i] = NULL_RTX;
49121           continue;
49122         }
49123       vperm = gen_rtx_CONST_VECTOR (V32QImode,
49124                                     gen_rtvec_v (32, rperm[2 * i + 1]));
49125       vperm = force_reg (V32QImode, vperm);
49126       h[i] = gen_reg_rtx (V32QImode);
49127       op = gen_lowpart (V32QImode, i ? d->op1 : d->op0);
49128       emit_insn (gen_avx2_pshufbv32qi3 (h[i], op, vperm));
49129     }
49130
49131   /* Swap the 128-byte lanes of h[X].  */
49132   for (i = 0; i < 2; ++i)
49133    {
49134      if (h[i] == NULL_RTX)
49135        continue;
49136      op = gen_reg_rtx (V4DImode);
49137      emit_insn (gen_avx2_permv4di_1 (op, gen_lowpart (V4DImode, h[i]),
49138                                      const2_rtx, GEN_INT (3), const0_rtx,
49139                                      const1_rtx));
49140      h[i] = gen_lowpart (V32QImode, op);
49141    }
49142
49143   for (i = 0; i < 2; ++i)
49144     {
49145       if (!used[2 * i])
49146         {
49147           l[i] = NULL_RTX;
49148           continue;
49149         }
49150       vperm = gen_rtx_CONST_VECTOR (V32QImode, gen_rtvec_v (32, rperm[2 * i]));
49151       vperm = force_reg (V32QImode, vperm);
49152       l[i] = gen_reg_rtx (V32QImode);
49153       op = gen_lowpart (V32QImode, i ? d->op1 : d->op0);
49154       emit_insn (gen_avx2_pshufbv32qi3 (l[i], op, vperm));
49155     }
49156
49157   for (i = 0; i < 2; ++i)
49158     {
49159       if (h[i] && l[i])
49160         {
49161           op = gen_reg_rtx (V32QImode);
49162           emit_insn (gen_iorv32qi3 (op, l[i], h[i]));
49163           l[i] = op;
49164         }
49165       else if (h[i])
49166         l[i] = h[i];
49167     }
49168
49169   gcc_assert (l[0] && l[1]);
49170   op = d->target;
49171   if (d->vmode != V32QImode)
49172     op = gen_reg_rtx (V32QImode);
49173   emit_insn (gen_iorv32qi3 (op, l[0], l[1]));
49174   if (op != d->target)
49175     emit_move_insn (d->target, gen_lowpart (d->vmode, op));
49176   return true;
49177 }
49178
49179 /* The guts of ix86_expand_vec_perm_const, also used by the ok hook.
49180    With all of the interface bits taken care of, perform the expansion
49181    in D and return true on success.  */
49182
49183 static bool
49184 ix86_expand_vec_perm_const_1 (struct expand_vec_perm_d *d)
49185 {
49186   /* Try a single instruction expansion.  */
49187   if (expand_vec_perm_1 (d))
49188     return true;
49189
49190   /* Try sequences of two instructions.  */
49191
49192   if (expand_vec_perm_pshuflw_pshufhw (d))
49193     return true;
49194
49195   if (expand_vec_perm_palignr (d, false))
49196     return true;
49197
49198   if (expand_vec_perm_interleave2 (d))
49199     return true;
49200
49201   if (expand_vec_perm_broadcast (d))
49202     return true;
49203
49204   if (expand_vec_perm_vpermq_perm_1 (d))
49205     return true;
49206
49207   if (expand_vec_perm_vperm2f128 (d))
49208     return true;
49209
49210   if (expand_vec_perm_pblendv (d))
49211     return true;
49212
49213   /* Try sequences of three instructions.  */
49214
49215   if (expand_vec_perm_even_odd_pack (d))
49216     return true;
49217
49218   if (expand_vec_perm_2vperm2f128_vshuf (d))
49219     return true;
49220
49221   if (expand_vec_perm_pshufb2 (d))
49222     return true;
49223
49224   if (expand_vec_perm_interleave3 (d))
49225     return true;
49226
49227   if (expand_vec_perm_vperm2f128_vblend (d))
49228     return true;
49229
49230   /* Try sequences of four instructions.  */
49231
49232   if (expand_vec_perm_vpshufb2_vpermq (d))
49233     return true;
49234
49235   if (expand_vec_perm_vpshufb2_vpermq_even_odd (d))
49236     return true;
49237
49238   if (expand_vec_perm_vpermi2_vpshub2 (d))
49239     return true;
49240
49241   /* ??? Look for narrow permutations whose element orderings would
49242      allow the promotion to a wider mode.  */
49243
49244   /* ??? Look for sequences of interleave or a wider permute that place
49245      the data into the correct lanes for a half-vector shuffle like
49246      pshuf[lh]w or vpermilps.  */
49247
49248   /* ??? Look for sequences of interleave that produce the desired results.
49249      The combinatorics of punpck[lh] get pretty ugly... */
49250
49251   if (expand_vec_perm_even_odd (d))
49252     return true;
49253
49254   /* Even longer sequences.  */
49255   if (expand_vec_perm_vpshufb4_vpermq2 (d))
49256     return true;
49257
49258   return false;
49259 }
49260
49261 /* If a permutation only uses one operand, make it clear. Returns true
49262    if the permutation references both operands.  */
49263
49264 static bool
49265 canonicalize_perm (struct expand_vec_perm_d *d)
49266 {
49267   int i, which, nelt = d->nelt;
49268
49269   for (i = which = 0; i < nelt; ++i)
49270       which |= (d->perm[i] < nelt ? 1 : 2);
49271
49272   d->one_operand_p = true;
49273   switch (which)
49274     {
49275     default:
49276       gcc_unreachable();
49277
49278     case 3:
49279       if (!rtx_equal_p (d->op0, d->op1))
49280         {
49281           d->one_operand_p = false;
49282           break;
49283         }
49284       /* The elements of PERM do not suggest that only the first operand
49285          is used, but both operands are identical.  Allow easier matching
49286          of the permutation by folding the permutation into the single
49287          input vector.  */
49288       /* FALLTHRU */
49289
49290     case 2:
49291       for (i = 0; i < nelt; ++i)
49292         d->perm[i] &= nelt - 1;
49293       d->op0 = d->op1;
49294       break;
49295
49296     case 1:
49297       d->op1 = d->op0;
49298       break;
49299     }
49300
49301   return (which == 3);
49302 }
49303
49304 bool
49305 ix86_expand_vec_perm_const (rtx operands[4])
49306 {
49307   struct expand_vec_perm_d d;
49308   unsigned char perm[MAX_VECT_LEN];
49309   int i, nelt;
49310   bool two_args;
49311   rtx sel;
49312
49313   d.target = operands[0];
49314   d.op0 = operands[1];
49315   d.op1 = operands[2];
49316   sel = operands[3];
49317
49318   d.vmode = GET_MODE (d.target);
49319   gcc_assert (VECTOR_MODE_P (d.vmode));
49320   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49321   d.testing_p = false;
49322
49323   gcc_assert (GET_CODE (sel) == CONST_VECTOR);
49324   gcc_assert (XVECLEN (sel, 0) == nelt);
49325   gcc_checking_assert (sizeof (d.perm) == sizeof (perm));
49326
49327   for (i = 0; i < nelt; ++i)
49328     {
49329       rtx e = XVECEXP (sel, 0, i);
49330       int ei = INTVAL (e) & (2 * nelt - 1);
49331       d.perm[i] = ei;
49332       perm[i] = ei;
49333     }
49334
49335   two_args = canonicalize_perm (&d);
49336
49337   if (ix86_expand_vec_perm_const_1 (&d))
49338     return true;
49339
49340   /* If the selector says both arguments are needed, but the operands are the
49341      same, the above tried to expand with one_operand_p and flattened selector.
49342      If that didn't work, retry without one_operand_p; we succeeded with that
49343      during testing.  */
49344   if (two_args && d.one_operand_p)
49345     {
49346       d.one_operand_p = false;
49347       memcpy (d.perm, perm, sizeof (perm));
49348       return ix86_expand_vec_perm_const_1 (&d);
49349     }
49350
49351   return false;
49352 }
49353
49354 /* Implement targetm.vectorize.vec_perm_const_ok.  */
49355
49356 static bool
49357 ix86_vectorize_vec_perm_const_ok (machine_mode vmode,
49358                                   const unsigned char *sel)
49359 {
49360   struct expand_vec_perm_d d;
49361   unsigned int i, nelt, which;
49362   bool ret;
49363
49364   d.vmode = vmode;
49365   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49366   d.testing_p = true;
49367
49368   /* Given sufficient ISA support we can just return true here
49369      for selected vector modes.  */
49370   switch (d.vmode)
49371     {
49372     case V16SFmode:
49373     case V16SImode:
49374     case V8DImode:
49375     case V8DFmode:
49376       if (TARGET_AVX512F)
49377         /* All implementable with a single vpermi2 insn.  */
49378         return true;
49379       break;
49380     case V32HImode:
49381       if (TARGET_AVX512BW)
49382         /* All implementable with a single vpermi2 insn.  */
49383         return true;
49384       break;
49385     case V64QImode:
49386       if (TARGET_AVX512BW)
49387         /* Implementable with 2 vpermi2, 2 vpshufb and 1 or insn.  */
49388         return true;
49389       break;
49390     case V8SImode:
49391     case V8SFmode:
49392     case V4DFmode:
49393     case V4DImode:
49394       if (TARGET_AVX512VL)
49395         /* All implementable with a single vpermi2 insn.  */
49396         return true;
49397       break;
49398     case V16HImode:
49399       if (TARGET_AVX2)
49400         /* Implementable with 4 vpshufb insns, 2 vpermq and 3 vpor insns.  */
49401         return true;
49402       break;
49403     case V32QImode:
49404       if (TARGET_AVX2)
49405         /* Implementable with 4 vpshufb insns, 2 vpermq and 3 vpor insns.  */
49406         return true;
49407       break;
49408     case V4SImode:
49409     case V4SFmode:
49410     case V8HImode:
49411     case V16QImode:
49412       /* All implementable with a single vpperm insn.  */
49413       if (TARGET_XOP)
49414         return true;
49415       /* All implementable with 2 pshufb + 1 ior.  */
49416       if (TARGET_SSSE3)
49417         return true;
49418       break;
49419     case V2DImode:
49420     case V2DFmode:
49421       /* All implementable with shufpd or unpck[lh]pd.  */
49422       return true;
49423     default:
49424       return false;
49425     }
49426
49427   /* Extract the values from the vector CST into the permutation
49428      array in D.  */
49429   memcpy (d.perm, sel, nelt);
49430   for (i = which = 0; i < nelt; ++i)
49431     {
49432       unsigned char e = d.perm[i];
49433       gcc_assert (e < 2 * nelt);
49434       which |= (e < nelt ? 1 : 2);
49435     }
49436
49437   /* For all elements from second vector, fold the elements to first.  */
49438   if (which == 2)
49439     for (i = 0; i < nelt; ++i)
49440       d.perm[i] -= nelt;
49441
49442   /* Check whether the mask can be applied to the vector type.  */
49443   d.one_operand_p = (which != 3);
49444
49445   /* Implementable with shufps or pshufd.  */
49446   if (d.one_operand_p && (d.vmode == V4SFmode || d.vmode == V4SImode))
49447     return true;
49448
49449   /* Otherwise we have to go through the motions and see if we can
49450      figure out how to generate the requested permutation.  */
49451   d.target = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 1);
49452   d.op1 = d.op0 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 2);
49453   if (!d.one_operand_p)
49454     d.op1 = gen_raw_REG (d.vmode, LAST_VIRTUAL_REGISTER + 3);
49455
49456   start_sequence ();
49457   ret = ix86_expand_vec_perm_const_1 (&d);
49458   end_sequence ();
49459
49460   return ret;
49461 }
49462
49463 void
49464 ix86_expand_vec_extract_even_odd (rtx targ, rtx op0, rtx op1, unsigned odd)
49465 {
49466   struct expand_vec_perm_d d;
49467   unsigned i, nelt;
49468
49469   d.target = targ;
49470   d.op0 = op0;
49471   d.op1 = op1;
49472   d.vmode = GET_MODE (targ);
49473   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49474   d.one_operand_p = false;
49475   d.testing_p = false;
49476
49477   for (i = 0; i < nelt; ++i)
49478     d.perm[i] = i * 2 + odd;
49479
49480   /* We'll either be able to implement the permutation directly...  */
49481   if (expand_vec_perm_1 (&d))
49482     return;
49483
49484   /* ... or we use the special-case patterns.  */
49485   expand_vec_perm_even_odd_1 (&d, odd);
49486 }
49487
49488 static void
49489 ix86_expand_vec_interleave (rtx targ, rtx op0, rtx op1, bool high_p)
49490 {
49491   struct expand_vec_perm_d d;
49492   unsigned i, nelt, base;
49493   bool ok;
49494
49495   d.target = targ;
49496   d.op0 = op0;
49497   d.op1 = op1;
49498   d.vmode = GET_MODE (targ);
49499   d.nelt = nelt = GET_MODE_NUNITS (d.vmode);
49500   d.one_operand_p = false;
49501   d.testing_p = false;
49502
49503   base = high_p ? nelt / 2 : 0;
49504   for (i = 0; i < nelt / 2; ++i)
49505     {
49506       d.perm[i * 2] = i + base;
49507       d.perm[i * 2 + 1] = i + base + nelt;
49508     }
49509
49510   /* Note that for AVX this isn't one instruction.  */
49511   ok = ix86_expand_vec_perm_const_1 (&d);
49512   gcc_assert (ok);
49513 }
49514
49515
49516 /* Expand a vector operation CODE for a V*QImode in terms of the
49517    same operation on V*HImode.  */
49518
49519 void
49520 ix86_expand_vecop_qihi (enum rtx_code code, rtx dest, rtx op1, rtx op2)
49521 {
49522   machine_mode qimode = GET_MODE (dest);
49523   machine_mode himode;
49524   rtx (*gen_il) (rtx, rtx, rtx);
49525   rtx (*gen_ih) (rtx, rtx, rtx);
49526   rtx op1_l, op1_h, op2_l, op2_h, res_l, res_h;
49527   struct expand_vec_perm_d d;
49528   bool ok, full_interleave;
49529   bool uns_p = false;
49530   int i;
49531
49532   switch (qimode)
49533     {
49534     case V16QImode:
49535       himode = V8HImode;
49536       gen_il = gen_vec_interleave_lowv16qi;
49537       gen_ih = gen_vec_interleave_highv16qi;
49538       break;
49539     case V32QImode:
49540       himode = V16HImode;
49541       gen_il = gen_avx2_interleave_lowv32qi;
49542       gen_ih = gen_avx2_interleave_highv32qi;
49543       break;
49544     case V64QImode:
49545       himode = V32HImode;
49546       gen_il = gen_avx512bw_interleave_lowv64qi;
49547       gen_ih = gen_avx512bw_interleave_highv64qi;
49548       break;
49549     default:
49550       gcc_unreachable ();
49551     }
49552
49553   op2_l = op2_h = op2;
49554   switch (code)
49555     {
49556     case MULT:
49557       /* Unpack data such that we've got a source byte in each low byte of
49558          each word.  We don't care what goes into the high byte of each word.
49559          Rather than trying to get zero in there, most convenient is to let
49560          it be a copy of the low byte.  */
49561       op2_l = gen_reg_rtx (qimode);
49562       op2_h = gen_reg_rtx (qimode);
49563       emit_insn (gen_il (op2_l, op2, op2));
49564       emit_insn (gen_ih (op2_h, op2, op2));
49565       /* FALLTHRU */
49566
49567       op1_l = gen_reg_rtx (qimode);
49568       op1_h = gen_reg_rtx (qimode);
49569       emit_insn (gen_il (op1_l, op1, op1));
49570       emit_insn (gen_ih (op1_h, op1, op1));
49571       full_interleave = qimode == V16QImode;
49572       break;
49573
49574     case ASHIFT:
49575     case LSHIFTRT:
49576       uns_p = true;
49577       /* FALLTHRU */
49578     case ASHIFTRT:
49579       op1_l = gen_reg_rtx (himode);
49580       op1_h = gen_reg_rtx (himode);
49581       ix86_expand_sse_unpack (op1_l, op1, uns_p, false);
49582       ix86_expand_sse_unpack (op1_h, op1, uns_p, true);
49583       full_interleave = true;
49584       break;
49585     default:
49586       gcc_unreachable ();
49587     }
49588
49589   /* Perform the operation.  */
49590   res_l = expand_simple_binop (himode, code, op1_l, op2_l, NULL_RTX,
49591                                1, OPTAB_DIRECT);
49592   res_h = expand_simple_binop (himode, code, op1_h, op2_h, NULL_RTX,
49593                                1, OPTAB_DIRECT);
49594   gcc_assert (res_l && res_h);
49595
49596   /* Merge the data back into the right place.  */
49597   d.target = dest;
49598   d.op0 = gen_lowpart (qimode, res_l);
49599   d.op1 = gen_lowpart (qimode, res_h);
49600   d.vmode = qimode;
49601   d.nelt = GET_MODE_NUNITS (qimode);
49602   d.one_operand_p = false;
49603   d.testing_p = false;
49604
49605   if (full_interleave)
49606     {
49607       /* For SSE2, we used an full interleave, so the desired
49608          results are in the even elements.  */
49609       for (i = 0; i < 64; ++i)
49610         d.perm[i] = i * 2;
49611     }
49612   else
49613     {
49614       /* For AVX, the interleave used above was not cross-lane.  So the
49615          extraction is evens but with the second and third quarter swapped.
49616          Happily, that is even one insn shorter than even extraction.  */
49617       for (i = 0; i < 64; ++i)
49618         d.perm[i] = i * 2 + ((i & 24) == 8 ? 16 : (i & 24) == 16 ? -16 : 0);
49619     }
49620
49621   ok = ix86_expand_vec_perm_const_1 (&d);
49622   gcc_assert (ok);
49623
49624   set_unique_reg_note (get_last_insn (), REG_EQUAL,
49625                        gen_rtx_fmt_ee (code, qimode, op1, op2));
49626 }
49627
49628 /* Helper function of ix86_expand_mul_widen_evenodd.  Return true
49629    if op is CONST_VECTOR with all odd elements equal to their
49630    preceding element.  */
49631
49632 static bool
49633 const_vector_equal_evenodd_p (rtx op)
49634 {
49635   machine_mode mode = GET_MODE (op);
49636   int i, nunits = GET_MODE_NUNITS (mode);
49637   if (GET_CODE (op) != CONST_VECTOR
49638       || nunits != CONST_VECTOR_NUNITS (op))
49639     return false;
49640   for (i = 0; i < nunits; i += 2)
49641     if (CONST_VECTOR_ELT (op, i) != CONST_VECTOR_ELT (op, i + 1))
49642       return false;
49643   return true;
49644 }
49645
49646 void
49647 ix86_expand_mul_widen_evenodd (rtx dest, rtx op1, rtx op2,
49648                                bool uns_p, bool odd_p)
49649 {
49650   machine_mode mode = GET_MODE (op1);
49651   machine_mode wmode = GET_MODE (dest);
49652   rtx x;
49653   rtx orig_op1 = op1, orig_op2 = op2;
49654
49655   if (!nonimmediate_operand (op1, mode))
49656     op1 = force_reg (mode, op1);
49657   if (!nonimmediate_operand (op2, mode))
49658     op2 = force_reg (mode, op2);
49659
49660   /* We only play even/odd games with vectors of SImode.  */
49661   gcc_assert (mode == V4SImode || mode == V8SImode || mode == V16SImode);
49662
49663   /* If we're looking for the odd results, shift those members down to
49664      the even slots.  For some cpus this is faster than a PSHUFD.  */
49665   if (odd_p)
49666     {
49667       /* For XOP use vpmacsdqh, but only for smult, as it is only
49668          signed.  */
49669       if (TARGET_XOP && mode == V4SImode && !uns_p)
49670         {
49671           x = force_reg (wmode, CONST0_RTX (wmode));
49672           emit_insn (gen_xop_pmacsdqh (dest, op1, op2, x));
49673           return;
49674         }
49675
49676       x = GEN_INT (GET_MODE_UNIT_BITSIZE (mode));
49677       if (!const_vector_equal_evenodd_p (orig_op1))
49678         op1 = expand_binop (wmode, lshr_optab, gen_lowpart (wmode, op1),
49679                             x, NULL, 1, OPTAB_DIRECT);
49680       if (!const_vector_equal_evenodd_p (orig_op2))
49681         op2 = expand_binop (wmode, lshr_optab, gen_lowpart (wmode, op2),
49682                             x, NULL, 1, OPTAB_DIRECT);
49683       op1 = gen_lowpart (mode, op1);
49684       op2 = gen_lowpart (mode, op2);
49685     }
49686
49687   if (mode == V16SImode)
49688     {
49689       if (uns_p)
49690         x = gen_vec_widen_umult_even_v16si (dest, op1, op2);
49691       else
49692         x = gen_vec_widen_smult_even_v16si (dest, op1, op2);
49693     }
49694   else if (mode == V8SImode)
49695     {
49696       if (uns_p)
49697         x = gen_vec_widen_umult_even_v8si (dest, op1, op2);
49698       else
49699         x = gen_vec_widen_smult_even_v8si (dest, op1, op2);
49700     }
49701   else if (uns_p)
49702     x = gen_vec_widen_umult_even_v4si (dest, op1, op2);
49703   else if (TARGET_SSE4_1)
49704     x = gen_sse4_1_mulv2siv2di3 (dest, op1, op2);
49705   else
49706     {
49707       rtx s1, s2, t0, t1, t2;
49708
49709       /* The easiest way to implement this without PMULDQ is to go through
49710          the motions as if we are performing a full 64-bit multiply.  With
49711          the exception that we need to do less shuffling of the elements.  */
49712
49713       /* Compute the sign-extension, aka highparts, of the two operands.  */
49714       s1 = ix86_expand_sse_cmp (gen_reg_rtx (mode), GT, CONST0_RTX (mode),
49715                                 op1, pc_rtx, pc_rtx);
49716       s2 = ix86_expand_sse_cmp (gen_reg_rtx (mode), GT, CONST0_RTX (mode),
49717                                 op2, pc_rtx, pc_rtx);
49718
49719       /* Multiply LO(A) * HI(B), and vice-versa.  */
49720       t1 = gen_reg_rtx (wmode);
49721       t2 = gen_reg_rtx (wmode);
49722       emit_insn (gen_vec_widen_umult_even_v4si (t1, s1, op2));
49723       emit_insn (gen_vec_widen_umult_even_v4si (t2, s2, op1));
49724
49725       /* Multiply LO(A) * LO(B).  */
49726       t0 = gen_reg_rtx (wmode);
49727       emit_insn (gen_vec_widen_umult_even_v4si (t0, op1, op2));
49728
49729       /* Combine and shift the highparts into place.  */
49730       t1 = expand_binop (wmode, add_optab, t1, t2, t1, 1, OPTAB_DIRECT);
49731       t1 = expand_binop (wmode, ashl_optab, t1, GEN_INT (32), t1,
49732                          1, OPTAB_DIRECT);
49733
49734       /* Combine high and low parts.  */
49735       force_expand_binop (wmode, add_optab, t0, t1, dest, 1, OPTAB_DIRECT);
49736       return;
49737     }
49738   emit_insn (x);
49739 }
49740
49741 void
49742 ix86_expand_mul_widen_hilo (rtx dest, rtx op1, rtx op2,
49743                             bool uns_p, bool high_p)
49744 {
49745   machine_mode wmode = GET_MODE (dest);
49746   machine_mode mode = GET_MODE (op1);
49747   rtx t1, t2, t3, t4, mask;
49748
49749   switch (mode)
49750     {
49751     case V4SImode:
49752       t1 = gen_reg_rtx (mode);
49753       t2 = gen_reg_rtx (mode);
49754       if (TARGET_XOP && !uns_p)
49755         {
49756           /* With XOP, we have pmacsdqh, aka mul_widen_odd.  In this case,
49757              shuffle the elements once so that all elements are in the right
49758              place for immediate use: { A C B D }.  */
49759           emit_insn (gen_sse2_pshufd_1 (t1, op1, const0_rtx, const2_rtx,
49760                                         const1_rtx, GEN_INT (3)));
49761           emit_insn (gen_sse2_pshufd_1 (t2, op2, const0_rtx, const2_rtx,
49762                                         const1_rtx, GEN_INT (3)));
49763         }
49764       else
49765         {
49766           /* Put the elements into place for the multiply.  */
49767           ix86_expand_vec_interleave (t1, op1, op1, high_p);
49768           ix86_expand_vec_interleave (t2, op2, op2, high_p);
49769           high_p = false;
49770         }
49771       ix86_expand_mul_widen_evenodd (dest, t1, t2, uns_p, high_p);
49772       break;
49773
49774     case V8SImode:
49775       /* Shuffle the elements between the lanes.  After this we
49776          have { A B E F | C D G H } for each operand.  */
49777       t1 = gen_reg_rtx (V4DImode);
49778       t2 = gen_reg_rtx (V4DImode);
49779       emit_insn (gen_avx2_permv4di_1 (t1, gen_lowpart (V4DImode, op1),
49780                                       const0_rtx, const2_rtx,
49781                                       const1_rtx, GEN_INT (3)));
49782       emit_insn (gen_avx2_permv4di_1 (t2, gen_lowpart (V4DImode, op2),
49783                                       const0_rtx, const2_rtx,
49784                                       const1_rtx, GEN_INT (3)));
49785
49786       /* Shuffle the elements within the lanes.  After this we
49787          have { A A B B | C C D D } or { E E F F | G G H H }.  */
49788       t3 = gen_reg_rtx (V8SImode);
49789       t4 = gen_reg_rtx (V8SImode);
49790       mask = GEN_INT (high_p
49791                       ? 2 + (2 << 2) + (3 << 4) + (3 << 6)
49792                       : 0 + (0 << 2) + (1 << 4) + (1 << 6));
49793       emit_insn (gen_avx2_pshufdv3 (t3, gen_lowpart (V8SImode, t1), mask));
49794       emit_insn (gen_avx2_pshufdv3 (t4, gen_lowpart (V8SImode, t2), mask));
49795
49796       ix86_expand_mul_widen_evenodd (dest, t3, t4, uns_p, false);
49797       break;
49798
49799     case V8HImode:
49800     case V16HImode:
49801       t1 = expand_binop (mode, smul_optab, op1, op2, NULL_RTX,
49802                          uns_p, OPTAB_DIRECT);
49803       t2 = expand_binop (mode,
49804                          uns_p ? umul_highpart_optab : smul_highpart_optab,
49805                          op1, op2, NULL_RTX, uns_p, OPTAB_DIRECT);
49806       gcc_assert (t1 && t2);
49807
49808       t3 = gen_reg_rtx (mode);
49809       ix86_expand_vec_interleave (t3, t1, t2, high_p);
49810       emit_move_insn (dest, gen_lowpart (wmode, t3));
49811       break;
49812
49813     case V16QImode:
49814     case V32QImode:
49815     case V32HImode:
49816     case V16SImode:
49817     case V64QImode:
49818       t1 = gen_reg_rtx (wmode);
49819       t2 = gen_reg_rtx (wmode);
49820       ix86_expand_sse_unpack (t1, op1, uns_p, high_p);
49821       ix86_expand_sse_unpack (t2, op2, uns_p, high_p);
49822
49823       emit_insn (gen_rtx_SET (VOIDmode, dest, gen_rtx_MULT (wmode, t1, t2)));
49824       break;
49825
49826     default:
49827       gcc_unreachable ();
49828     }
49829 }
49830
49831 void
49832 ix86_expand_sse2_mulv4si3 (rtx op0, rtx op1, rtx op2)
49833 {
49834   rtx res_1, res_2, res_3, res_4;
49835
49836   res_1 = gen_reg_rtx (V4SImode);
49837   res_2 = gen_reg_rtx (V4SImode);
49838   res_3 = gen_reg_rtx (V2DImode);
49839   res_4 = gen_reg_rtx (V2DImode);
49840   ix86_expand_mul_widen_evenodd (res_3, op1, op2, true, false);
49841   ix86_expand_mul_widen_evenodd (res_4, op1, op2, true, true);
49842
49843   /* Move the results in element 2 down to element 1; we don't care
49844      what goes in elements 2 and 3.  Then we can merge the parts
49845      back together with an interleave.
49846
49847      Note that two other sequences were tried:
49848      (1) Use interleaves at the start instead of psrldq, which allows
49849      us to use a single shufps to merge things back at the end.
49850      (2) Use shufps here to combine the two vectors, then pshufd to
49851      put the elements in the correct order.
49852      In both cases the cost of the reformatting stall was too high
49853      and the overall sequence slower.  */
49854
49855   emit_insn (gen_sse2_pshufd_1 (res_1, gen_lowpart (V4SImode, res_3),
49856                                 const0_rtx, const2_rtx,
49857                                 const0_rtx, const0_rtx));
49858   emit_insn (gen_sse2_pshufd_1 (res_2, gen_lowpart (V4SImode, res_4),
49859                                 const0_rtx, const2_rtx,
49860                                 const0_rtx, const0_rtx));
49861   res_1 = emit_insn (gen_vec_interleave_lowv4si (op0, res_1, res_2));
49862
49863   set_unique_reg_note (res_1, REG_EQUAL, gen_rtx_MULT (V4SImode, op1, op2));
49864 }
49865
49866 void
49867 ix86_expand_sse2_mulvxdi3 (rtx op0, rtx op1, rtx op2)
49868 {
49869   machine_mode mode = GET_MODE (op0);
49870   rtx t1, t2, t3, t4, t5, t6;
49871
49872   if (TARGET_AVX512DQ && mode == V8DImode)
49873     emit_insn (gen_avx512dq_mulv8di3 (op0, op1, op2));
49874   else if (TARGET_AVX512DQ && TARGET_AVX512VL && mode == V4DImode)
49875     emit_insn (gen_avx512dq_mulv4di3 (op0, op1, op2));
49876   else if (TARGET_AVX512DQ && TARGET_AVX512VL && mode == V2DImode)
49877     emit_insn (gen_avx512dq_mulv2di3 (op0, op1, op2));
49878   else if (TARGET_XOP && mode == V2DImode)
49879     {
49880       /* op1: A,B,C,D, op2: E,F,G,H */
49881       op1 = gen_lowpart (V4SImode, op1);
49882       op2 = gen_lowpart (V4SImode, op2);
49883
49884       t1 = gen_reg_rtx (V4SImode);
49885       t2 = gen_reg_rtx (V4SImode);
49886       t3 = gen_reg_rtx (V2DImode);
49887       t4 = gen_reg_rtx (V2DImode);
49888
49889       /* t1: B,A,D,C */
49890       emit_insn (gen_sse2_pshufd_1 (t1, op1,
49891                                     GEN_INT (1),
49892                                     GEN_INT (0),
49893                                     GEN_INT (3),
49894                                     GEN_INT (2)));
49895
49896       /* t2: (B*E),(A*F),(D*G),(C*H) */
49897       emit_insn (gen_mulv4si3 (t2, t1, op2));
49898
49899       /* t3: (B*E)+(A*F), (D*G)+(C*H) */
49900       emit_insn (gen_xop_phadddq (t3, t2));
49901
49902       /* t4: ((B*E)+(A*F))<<32, ((D*G)+(C*H))<<32 */
49903       emit_insn (gen_ashlv2di3 (t4, t3, GEN_INT (32)));
49904
49905       /* Multiply lower parts and add all */
49906       t5 = gen_reg_rtx (V2DImode);
49907       emit_insn (gen_vec_widen_umult_even_v4si (t5, 
49908                                         gen_lowpart (V4SImode, op1),
49909                                         gen_lowpart (V4SImode, op2)));
49910       op0 = expand_binop (mode, add_optab, t5, t4, op0, 1, OPTAB_DIRECT);
49911
49912     }
49913   else
49914     {
49915       machine_mode nmode;
49916       rtx (*umul) (rtx, rtx, rtx);
49917
49918       if (mode == V2DImode)
49919         {
49920           umul = gen_vec_widen_umult_even_v4si;
49921           nmode = V4SImode;
49922         }
49923       else if (mode == V4DImode)
49924         {
49925           umul = gen_vec_widen_umult_even_v8si;
49926           nmode = V8SImode;
49927         }
49928       else if (mode == V8DImode)
49929         {
49930           umul = gen_vec_widen_umult_even_v16si;
49931           nmode = V16SImode;
49932         }
49933       else
49934         gcc_unreachable ();
49935
49936
49937       /* Multiply low parts.  */
49938       t1 = gen_reg_rtx (mode);
49939       emit_insn (umul (t1, gen_lowpart (nmode, op1), gen_lowpart (nmode, op2)));
49940
49941       /* Shift input vectors right 32 bits so we can multiply high parts.  */
49942       t6 = GEN_INT (32);
49943       t2 = expand_binop (mode, lshr_optab, op1, t6, NULL, 1, OPTAB_DIRECT);
49944       t3 = expand_binop (mode, lshr_optab, op2, t6, NULL, 1, OPTAB_DIRECT);
49945
49946       /* Multiply high parts by low parts.  */
49947       t4 = gen_reg_rtx (mode);
49948       t5 = gen_reg_rtx (mode);
49949       emit_insn (umul (t4, gen_lowpart (nmode, t2), gen_lowpart (nmode, op2)));
49950       emit_insn (umul (t5, gen_lowpart (nmode, t3), gen_lowpart (nmode, op1)));
49951
49952       /* Combine and shift the highparts back.  */
49953       t4 = expand_binop (mode, add_optab, t4, t5, t4, 1, OPTAB_DIRECT);
49954       t4 = expand_binop (mode, ashl_optab, t4, t6, t4, 1, OPTAB_DIRECT);
49955
49956       /* Combine high and low parts.  */
49957       force_expand_binop (mode, add_optab, t1, t4, op0, 1, OPTAB_DIRECT);
49958     }
49959
49960   set_unique_reg_note (get_last_insn (), REG_EQUAL,
49961                        gen_rtx_MULT (mode, op1, op2));
49962 }
49963
49964 /* Return 1 if control tansfer instruction INSN
49965    should be encoded with bnd prefix.
49966    If insn is NULL then return 1 when control
49967    transfer instructions should be prefixed with
49968    bnd by default for current function.  */
49969
49970 bool
49971 ix86_bnd_prefixed_insn_p (rtx insn)
49972 {
49973   /* For call insns check special flag.  */
49974   if (insn && CALL_P (insn))
49975     {
49976       rtx call = get_call_rtx_from (insn);
49977       if (call)
49978         return CALL_EXPR_WITH_BOUNDS_P (call);
49979     }
49980
49981   /* All other insns are prefixed only if function is instrumented.  */
49982   return chkp_function_instrumented_p (current_function_decl);
49983 }
49984
49985 /* Calculate integer abs() using only SSE2 instructions.  */
49986
49987 void
49988 ix86_expand_sse2_abs (rtx target, rtx input)
49989 {
49990   machine_mode mode = GET_MODE (target);
49991   rtx tmp0, tmp1, x;
49992
49993   switch (mode)
49994     {
49995       /* For 32-bit signed integer X, the best way to calculate the absolute
49996          value of X is (((signed) X >> (W-1)) ^ X) - ((signed) X >> (W-1)).  */
49997       case V4SImode:
49998         tmp0 = expand_simple_binop (mode, ASHIFTRT, input,
49999                                     GEN_INT (GET_MODE_BITSIZE
50000                                              (GET_MODE_INNER (mode)) - 1),
50001                                     NULL, 0, OPTAB_DIRECT);
50002         tmp1 = expand_simple_binop (mode, XOR, tmp0, input,
50003                                     NULL, 0, OPTAB_DIRECT);
50004         x = expand_simple_binop (mode, MINUS, tmp1, tmp0,
50005                                  target, 0, OPTAB_DIRECT);
50006         break;
50007
50008       /* For 16-bit signed integer X, the best way to calculate the absolute
50009          value of X is max (X, -X), as SSE2 provides the PMAXSW insn.  */
50010       case V8HImode:
50011         tmp0 = expand_unop (mode, neg_optab, input, NULL_RTX, 0);
50012
50013         x = expand_simple_binop (mode, SMAX, tmp0, input,
50014                                  target, 0, OPTAB_DIRECT);
50015         break;
50016
50017       /* For 8-bit signed integer X, the best way to calculate the absolute
50018          value of X is min ((unsigned char) X, (unsigned char) (-X)),
50019          as SSE2 provides the PMINUB insn.  */
50020       case V16QImode:
50021         tmp0 = expand_unop (mode, neg_optab, input, NULL_RTX, 0);
50022
50023         x = expand_simple_binop (V16QImode, UMIN, tmp0, input,
50024                                  target, 0, OPTAB_DIRECT);
50025         break;
50026
50027       default:
50028         gcc_unreachable ();
50029     }
50030
50031   if (x != target)
50032     emit_move_insn (target, x);
50033 }
50034
50035 /* Expand an insert into a vector register through pinsr insn.
50036    Return true if successful.  */
50037
50038 bool
50039 ix86_expand_pinsr (rtx *operands)
50040 {
50041   rtx dst = operands[0];
50042   rtx src = operands[3];
50043
50044   unsigned int size = INTVAL (operands[1]);
50045   unsigned int pos = INTVAL (operands[2]);
50046
50047   if (GET_CODE (dst) == SUBREG)
50048     {
50049       pos += SUBREG_BYTE (dst) * BITS_PER_UNIT;
50050       dst = SUBREG_REG (dst);
50051     }
50052
50053   if (GET_CODE (src) == SUBREG)
50054     src = SUBREG_REG (src);
50055
50056   switch (GET_MODE (dst))
50057     {
50058     case V16QImode:
50059     case V8HImode:
50060     case V4SImode:
50061     case V2DImode:
50062       {
50063         machine_mode srcmode, dstmode;
50064         rtx (*pinsr)(rtx, rtx, rtx, rtx);
50065
50066         srcmode = mode_for_size (size, MODE_INT, 0);
50067
50068         switch (srcmode)
50069           {
50070           case QImode:
50071             if (!TARGET_SSE4_1)
50072               return false;
50073             dstmode = V16QImode;
50074             pinsr = gen_sse4_1_pinsrb;
50075             break;
50076
50077           case HImode:
50078             if (!TARGET_SSE2)
50079               return false;
50080             dstmode = V8HImode;
50081             pinsr = gen_sse2_pinsrw;
50082             break;
50083
50084           case SImode:
50085             if (!TARGET_SSE4_1)
50086               return false;
50087             dstmode = V4SImode;
50088             pinsr = gen_sse4_1_pinsrd;
50089             break;
50090
50091           case DImode:
50092             gcc_assert (TARGET_64BIT);
50093             if (!TARGET_SSE4_1)
50094               return false;
50095             dstmode = V2DImode;
50096             pinsr = gen_sse4_1_pinsrq;
50097             break;
50098
50099           default:
50100             return false;
50101           }
50102
50103         rtx d = dst;
50104         if (GET_MODE (dst) != dstmode)
50105           d = gen_reg_rtx (dstmode);
50106         src = gen_lowpart (srcmode, src);
50107
50108         pos /= size;
50109
50110         emit_insn (pinsr (d, gen_lowpart (dstmode, dst), src,
50111                           GEN_INT (1 << pos)));
50112         if (d != dst)
50113           emit_move_insn (dst, gen_lowpart (GET_MODE (dst), d));
50114         return true;
50115       }
50116
50117     default:
50118       return false;
50119     }
50120 }
50121 \f
50122 /* This function returns the calling abi specific va_list type node.
50123    It returns  the FNDECL specific va_list type.  */
50124
50125 static tree
50126 ix86_fn_abi_va_list (tree fndecl)
50127 {
50128   if (!TARGET_64BIT)
50129     return va_list_type_node;
50130   gcc_assert (fndecl != NULL_TREE);
50131
50132   if (ix86_function_abi ((const_tree) fndecl) == MS_ABI)
50133     return ms_va_list_type_node;
50134   else
50135     return sysv_va_list_type_node;
50136 }
50137
50138 /* Returns the canonical va_list type specified by TYPE. If there
50139    is no valid TYPE provided, it return NULL_TREE.  */
50140
50141 static tree
50142 ix86_canonical_va_list_type (tree type)
50143 {
50144   tree wtype, htype;
50145
50146   /* Resolve references and pointers to va_list type.  */
50147   if (TREE_CODE (type) == MEM_REF)
50148     type = TREE_TYPE (type);
50149   else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
50150     type = TREE_TYPE (type);
50151   else if (POINTER_TYPE_P (type) && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
50152     type = TREE_TYPE (type);
50153
50154   if (TARGET_64BIT && va_list_type_node != NULL_TREE)
50155     {
50156       wtype = va_list_type_node;
50157           gcc_assert (wtype != NULL_TREE);
50158       htype = type;
50159       if (TREE_CODE (wtype) == ARRAY_TYPE)
50160         {
50161           /* If va_list is an array type, the argument may have decayed
50162              to a pointer type, e.g. by being passed to another function.
50163              In that case, unwrap both types so that we can compare the
50164              underlying records.  */
50165           if (TREE_CODE (htype) == ARRAY_TYPE
50166               || POINTER_TYPE_P (htype))
50167             {
50168               wtype = TREE_TYPE (wtype);
50169               htype = TREE_TYPE (htype);
50170             }
50171         }
50172       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
50173         return va_list_type_node;
50174       wtype = sysv_va_list_type_node;
50175           gcc_assert (wtype != NULL_TREE);
50176       htype = type;
50177       if (TREE_CODE (wtype) == ARRAY_TYPE)
50178         {
50179           /* If va_list is an array type, the argument may have decayed
50180              to a pointer type, e.g. by being passed to another function.
50181              In that case, unwrap both types so that we can compare the
50182              underlying records.  */
50183           if (TREE_CODE (htype) == ARRAY_TYPE
50184               || POINTER_TYPE_P (htype))
50185             {
50186               wtype = TREE_TYPE (wtype);
50187               htype = TREE_TYPE (htype);
50188             }
50189         }
50190       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
50191         return sysv_va_list_type_node;
50192       wtype = ms_va_list_type_node;
50193           gcc_assert (wtype != NULL_TREE);
50194       htype = type;
50195       if (TREE_CODE (wtype) == ARRAY_TYPE)
50196         {
50197           /* If va_list is an array type, the argument may have decayed
50198              to a pointer type, e.g. by being passed to another function.
50199              In that case, unwrap both types so that we can compare the
50200              underlying records.  */
50201           if (TREE_CODE (htype) == ARRAY_TYPE
50202               || POINTER_TYPE_P (htype))
50203             {
50204               wtype = TREE_TYPE (wtype);
50205               htype = TREE_TYPE (htype);
50206             }
50207         }
50208       if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
50209         return ms_va_list_type_node;
50210       return NULL_TREE;
50211     }
50212   return std_canonical_va_list_type (type);
50213 }
50214
50215 /* Iterate through the target-specific builtin types for va_list.
50216    IDX denotes the iterator, *PTREE is set to the result type of
50217    the va_list builtin, and *PNAME to its internal type.
50218    Returns zero if there is no element for this index, otherwise
50219    IDX should be increased upon the next call.
50220    Note, do not iterate a base builtin's name like __builtin_va_list.
50221    Used from c_common_nodes_and_builtins.  */
50222
50223 static int
50224 ix86_enum_va_list (int idx, const char **pname, tree *ptree)
50225 {
50226   if (TARGET_64BIT)
50227     {
50228       switch (idx)
50229         {
50230         default:
50231           break;
50232
50233         case 0:
50234           *ptree = ms_va_list_type_node;
50235           *pname = "__builtin_ms_va_list";
50236           return 1;
50237
50238         case 1:
50239           *ptree = sysv_va_list_type_node;
50240           *pname = "__builtin_sysv_va_list";
50241           return 1;
50242         }
50243     }
50244
50245   return 0;
50246 }
50247
50248 #undef TARGET_SCHED_DISPATCH
50249 #define TARGET_SCHED_DISPATCH has_dispatch
50250 #undef TARGET_SCHED_DISPATCH_DO
50251 #define TARGET_SCHED_DISPATCH_DO do_dispatch
50252 #undef TARGET_SCHED_REASSOCIATION_WIDTH
50253 #define TARGET_SCHED_REASSOCIATION_WIDTH ix86_reassociation_width
50254 #undef TARGET_SCHED_REORDER
50255 #define TARGET_SCHED_REORDER ix86_sched_reorder
50256 #undef TARGET_SCHED_ADJUST_PRIORITY
50257 #define TARGET_SCHED_ADJUST_PRIORITY ix86_adjust_priority
50258 #undef TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK
50259 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK \
50260   ix86_dependencies_evaluation_hook
50261
50262 /* The size of the dispatch window is the total number of bytes of
50263    object code allowed in a window.  */
50264 #define DISPATCH_WINDOW_SIZE 16
50265
50266 /* Number of dispatch windows considered for scheduling.  */
50267 #define MAX_DISPATCH_WINDOWS 3
50268
50269 /* Maximum number of instructions in a window.  */
50270 #define MAX_INSN 4
50271
50272 /* Maximum number of immediate operands in a window.  */
50273 #define MAX_IMM 4
50274
50275 /* Maximum number of immediate bits allowed in a window.  */
50276 #define MAX_IMM_SIZE 128
50277
50278 /* Maximum number of 32 bit immediates allowed in a window.  */
50279 #define MAX_IMM_32 4
50280
50281 /* Maximum number of 64 bit immediates allowed in a window.  */
50282 #define MAX_IMM_64 2
50283
50284 /* Maximum total of loads or prefetches allowed in a window.  */
50285 #define MAX_LOAD 2
50286
50287 /* Maximum total of stores allowed in a window.  */
50288 #define MAX_STORE 1
50289
50290 #undef BIG
50291 #define BIG 100
50292
50293
50294 /* Dispatch groups.  Istructions that affect the mix in a dispatch window.  */
50295 enum dispatch_group {
50296   disp_no_group = 0,
50297   disp_load,
50298   disp_store,
50299   disp_load_store,
50300   disp_prefetch,
50301   disp_imm,
50302   disp_imm_32,
50303   disp_imm_64,
50304   disp_branch,
50305   disp_cmp,
50306   disp_jcc,
50307   disp_last
50308 };
50309
50310 /* Number of allowable groups in a dispatch window.  It is an array
50311    indexed by dispatch_group enum.  100 is used as a big number,
50312    because the number of these kind of operations does not have any
50313    effect in dispatch window, but we need them for other reasons in
50314    the table.  */
50315 static unsigned int num_allowable_groups[disp_last] = {
50316   0, 2, 1, 1, 2, 4, 4, 2, 1, BIG, BIG
50317 };
50318
50319 char group_name[disp_last + 1][16] = {
50320   "disp_no_group", "disp_load", "disp_store", "disp_load_store",
50321   "disp_prefetch", "disp_imm", "disp_imm_32", "disp_imm_64",
50322   "disp_branch", "disp_cmp", "disp_jcc", "disp_last"
50323 };
50324
50325 /* Instruction path.  */
50326 enum insn_path {
50327   no_path = 0,
50328   path_single, /* Single micro op.  */
50329   path_double, /* Double micro op.  */
50330   path_multi,  /* Instructions with more than 2 micro op..  */
50331   last_path
50332 };
50333
50334 /* sched_insn_info defines a window to the instructions scheduled in
50335    the basic block.  It contains a pointer to the insn_info table and
50336    the instruction scheduled.
50337
50338    Windows are allocated for each basic block and are linked
50339    together.  */
50340 typedef struct sched_insn_info_s {
50341   rtx insn;
50342   enum dispatch_group group;
50343   enum insn_path path;
50344   int byte_len;
50345   int imm_bytes;
50346 } sched_insn_info;
50347
50348 /* Linked list of dispatch windows.  This is a two way list of
50349    dispatch windows of a basic block.  It contains information about
50350    the number of uops in the window and the total number of
50351    instructions and of bytes in the object code for this dispatch
50352    window.  */
50353 typedef struct dispatch_windows_s {
50354   int num_insn;            /* Number of insn in the window.  */
50355   int num_uops;            /* Number of uops in the window.  */
50356   int window_size;         /* Number of bytes in the window.  */
50357   int window_num;          /* Window number between 0 or 1.  */
50358   int num_imm;             /* Number of immediates in an insn.  */
50359   int num_imm_32;          /* Number of 32 bit immediates in an insn.  */
50360   int num_imm_64;          /* Number of 64 bit immediates in an insn.  */
50361   int imm_size;            /* Total immediates in the window.  */
50362   int num_loads;           /* Total memory loads in the window.  */
50363   int num_stores;          /* Total memory stores in the window.  */
50364   int violation;          /* Violation exists in window.  */
50365   sched_insn_info *window; /* Pointer to the window.  */
50366   struct dispatch_windows_s *next;
50367   struct dispatch_windows_s *prev;
50368 } dispatch_windows;
50369
50370 /* Immediate valuse used in an insn.  */
50371 typedef struct imm_info_s
50372   {
50373     int imm;
50374     int imm32;
50375     int imm64;
50376   } imm_info;
50377
50378 static dispatch_windows *dispatch_window_list;
50379 static dispatch_windows *dispatch_window_list1;
50380
50381 /* Get dispatch group of insn.  */
50382
50383 static enum dispatch_group
50384 get_mem_group (rtx_insn *insn)
50385 {
50386   enum attr_memory memory;
50387
50388   if (INSN_CODE (insn) < 0)
50389     return disp_no_group;
50390   memory = get_attr_memory (insn);
50391   if (memory == MEMORY_STORE)
50392     return disp_store;
50393
50394   if (memory == MEMORY_LOAD)
50395     return disp_load;
50396
50397   if (memory == MEMORY_BOTH)
50398     return disp_load_store;
50399
50400   return disp_no_group;
50401 }
50402
50403 /* Return true if insn is a compare instruction.  */
50404
50405 static bool
50406 is_cmp (rtx_insn *insn)
50407 {
50408   enum attr_type type;
50409
50410   type = get_attr_type (insn);
50411   return (type == TYPE_TEST
50412           || type == TYPE_ICMP
50413           || type == TYPE_FCMP
50414           || GET_CODE (PATTERN (insn)) == COMPARE);
50415 }
50416
50417 /* Return true if a dispatch violation encountered.  */
50418
50419 static bool
50420 dispatch_violation (void)
50421 {
50422   if (dispatch_window_list->next)
50423     return dispatch_window_list->next->violation;
50424   return dispatch_window_list->violation;
50425 }
50426
50427 /* Return true if insn is a branch instruction.  */
50428
50429 static bool
50430 is_branch (rtx insn)
50431 {
50432   return (CALL_P (insn) || JUMP_P (insn));
50433 }
50434
50435 /* Return true if insn is a prefetch instruction.  */
50436
50437 static bool
50438 is_prefetch (rtx insn)
50439 {
50440   return NONJUMP_INSN_P (insn) && GET_CODE (PATTERN (insn)) == PREFETCH;
50441 }
50442
50443 /* This function initializes a dispatch window and the list container holding a
50444    pointer to the window.  */
50445
50446 static void
50447 init_window (int window_num)
50448 {
50449   int i;
50450   dispatch_windows *new_list;
50451
50452   if (window_num == 0)
50453     new_list = dispatch_window_list;
50454   else
50455     new_list = dispatch_window_list1;
50456
50457   new_list->num_insn = 0;
50458   new_list->num_uops = 0;
50459   new_list->window_size = 0;
50460   new_list->next = NULL;
50461   new_list->prev = NULL;
50462   new_list->window_num = window_num;
50463   new_list->num_imm = 0;
50464   new_list->num_imm_32 = 0;
50465   new_list->num_imm_64 = 0;
50466   new_list->imm_size = 0;
50467   new_list->num_loads = 0;
50468   new_list->num_stores = 0;
50469   new_list->violation = false;
50470
50471   for (i = 0; i < MAX_INSN; i++)
50472     {
50473       new_list->window[i].insn = NULL;
50474       new_list->window[i].group = disp_no_group;
50475       new_list->window[i].path = no_path;
50476       new_list->window[i].byte_len = 0;
50477       new_list->window[i].imm_bytes = 0;
50478     }
50479   return;
50480 }
50481
50482 /* This function allocates and initializes a dispatch window and the
50483    list container holding a pointer to the window.  */
50484
50485 static dispatch_windows *
50486 allocate_window (void)
50487 {
50488   dispatch_windows *new_list = XNEW (struct dispatch_windows_s);
50489   new_list->window = XNEWVEC (struct sched_insn_info_s, MAX_INSN + 1);
50490
50491   return new_list;
50492 }
50493
50494 /* This routine initializes the dispatch scheduling information.  It
50495    initiates building dispatch scheduler tables and constructs the
50496    first dispatch window.  */
50497
50498 static void
50499 init_dispatch_sched (void)
50500 {
50501   /* Allocate a dispatch list and a window.  */
50502   dispatch_window_list = allocate_window ();
50503   dispatch_window_list1 = allocate_window ();
50504   init_window (0);
50505   init_window (1);
50506 }
50507
50508 /* This function returns true if a branch is detected.  End of a basic block
50509    does not have to be a branch, but here we assume only branches end a
50510    window.  */
50511
50512 static bool
50513 is_end_basic_block (enum dispatch_group group)
50514 {
50515   return group == disp_branch;
50516 }
50517
50518 /* This function is called when the end of a window processing is reached.  */
50519
50520 static void
50521 process_end_window (void)
50522 {
50523   gcc_assert (dispatch_window_list->num_insn <= MAX_INSN);
50524   if (dispatch_window_list->next)
50525     {
50526       gcc_assert (dispatch_window_list1->num_insn <= MAX_INSN);
50527       gcc_assert (dispatch_window_list->window_size
50528                   + dispatch_window_list1->window_size <= 48);
50529       init_window (1);
50530     }
50531   init_window (0);
50532 }
50533
50534 /* Allocates a new dispatch window and adds it to WINDOW_LIST.
50535    WINDOW_NUM is either 0 or 1.  A maximum of two windows are generated
50536    for 48 bytes of instructions.  Note that these windows are not dispatch
50537    windows that their sizes are DISPATCH_WINDOW_SIZE.  */
50538
50539 static dispatch_windows *
50540 allocate_next_window (int window_num)
50541 {
50542   if (window_num == 0)
50543     {
50544       if (dispatch_window_list->next)
50545           init_window (1);
50546       init_window (0);
50547       return dispatch_window_list;
50548     }
50549
50550   dispatch_window_list->next = dispatch_window_list1;
50551   dispatch_window_list1->prev = dispatch_window_list;
50552
50553   return dispatch_window_list1;
50554 }
50555
50556 /* Compute number of immediate operands of an instruction.  */
50557
50558 static void
50559 find_constant (rtx in_rtx, imm_info *imm_values)
50560 {
50561   if (INSN_P (in_rtx))
50562     in_rtx = PATTERN (in_rtx);
50563   subrtx_iterator::array_type array;
50564   FOR_EACH_SUBRTX (iter, array, in_rtx, ALL)
50565     if (const_rtx x = *iter)
50566       switch (GET_CODE (x))
50567         {
50568         case CONST:
50569         case SYMBOL_REF:
50570         case CONST_INT:
50571           (imm_values->imm)++;
50572           if (x86_64_immediate_operand (CONST_CAST_RTX (x), SImode))
50573             (imm_values->imm32)++;
50574           else
50575             (imm_values->imm64)++;
50576           break;
50577
50578         case CONST_DOUBLE:
50579           (imm_values->imm)++;
50580           (imm_values->imm64)++;
50581           break;
50582
50583         case CODE_LABEL:
50584           if (LABEL_KIND (x) == LABEL_NORMAL)
50585             {
50586               (imm_values->imm)++;
50587               (imm_values->imm32)++;
50588             }
50589           break;
50590
50591         default:
50592           break;
50593         }
50594 }
50595
50596 /* Return total size of immediate operands of an instruction along with number
50597    of corresponding immediate-operands.  It initializes its parameters to zero
50598    befor calling FIND_CONSTANT.
50599    INSN is the input instruction.  IMM is the total of immediates.
50600    IMM32 is the number of 32 bit immediates.  IMM64 is the number of 64
50601    bit immediates.  */
50602
50603 static int
50604 get_num_immediates (rtx insn, int *imm, int *imm32, int *imm64)
50605 {
50606   imm_info imm_values = {0, 0, 0};
50607
50608   find_constant (insn, &imm_values);
50609   *imm = imm_values.imm;
50610   *imm32 = imm_values.imm32;
50611   *imm64 = imm_values.imm64;
50612   return imm_values.imm32 * 4 + imm_values.imm64 * 8;
50613 }
50614
50615 /* This function indicates if an operand of an instruction is an
50616    immediate.  */
50617
50618 static bool
50619 has_immediate (rtx insn)
50620 {
50621   int num_imm_operand;
50622   int num_imm32_operand;
50623   int num_imm64_operand;
50624
50625   if (insn)
50626     return get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50627                                &num_imm64_operand);
50628   return false;
50629 }
50630
50631 /* Return single or double path for instructions.  */
50632
50633 static enum insn_path
50634 get_insn_path (rtx_insn *insn)
50635 {
50636   enum attr_amdfam10_decode path = get_attr_amdfam10_decode (insn);
50637
50638   if ((int)path == 0)
50639     return path_single;
50640
50641   if ((int)path == 1)
50642     return path_double;
50643
50644   return path_multi;
50645 }
50646
50647 /* Return insn dispatch group.  */
50648
50649 static enum dispatch_group
50650 get_insn_group (rtx_insn *insn)
50651 {
50652   enum dispatch_group group = get_mem_group (insn);
50653   if (group)
50654     return group;
50655
50656   if (is_branch (insn))
50657     return disp_branch;
50658
50659   if (is_cmp (insn))
50660     return disp_cmp;
50661
50662   if (has_immediate (insn))
50663     return disp_imm;
50664
50665   if (is_prefetch (insn))
50666     return disp_prefetch;
50667
50668   return disp_no_group;
50669 }
50670
50671 /* Count number of GROUP restricted instructions in a dispatch
50672    window WINDOW_LIST.  */
50673
50674 static int
50675 count_num_restricted (rtx_insn *insn, dispatch_windows *window_list)
50676 {
50677   enum dispatch_group group = get_insn_group (insn);
50678   int imm_size;
50679   int num_imm_operand;
50680   int num_imm32_operand;
50681   int num_imm64_operand;
50682
50683   if (group == disp_no_group)
50684     return 0;
50685
50686   if (group == disp_imm)
50687     {
50688       imm_size = get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50689                               &num_imm64_operand);
50690       if (window_list->imm_size + imm_size > MAX_IMM_SIZE
50691           || num_imm_operand + window_list->num_imm > MAX_IMM
50692           || (num_imm32_operand > 0
50693               && (window_list->num_imm_32 + num_imm32_operand > MAX_IMM_32
50694                   || window_list->num_imm_64 * 2 + num_imm32_operand > MAX_IMM_32))
50695           || (num_imm64_operand > 0
50696               && (window_list->num_imm_64 + num_imm64_operand > MAX_IMM_64
50697                   || window_list->num_imm_32 + num_imm64_operand * 2 > MAX_IMM_32))
50698           || (window_list->imm_size + imm_size == MAX_IMM_SIZE
50699               && num_imm64_operand > 0
50700               && ((window_list->num_imm_64 > 0
50701                    && window_list->num_insn >= 2)
50702                   || window_list->num_insn >= 3)))
50703         return BIG;
50704
50705       return 1;
50706     }
50707
50708   if ((group == disp_load_store
50709        && (window_list->num_loads >= MAX_LOAD
50710            || window_list->num_stores >= MAX_STORE))
50711       || ((group == disp_load
50712            || group == disp_prefetch)
50713           && window_list->num_loads >= MAX_LOAD)
50714       || (group == disp_store
50715           && window_list->num_stores >= MAX_STORE))
50716     return BIG;
50717
50718   return 1;
50719 }
50720
50721 /* This function returns true if insn satisfies dispatch rules on the
50722    last window scheduled.  */
50723
50724 static bool
50725 fits_dispatch_window (rtx_insn *insn)
50726 {
50727   dispatch_windows *window_list = dispatch_window_list;
50728   dispatch_windows *window_list_next = dispatch_window_list->next;
50729   unsigned int num_restrict;
50730   enum dispatch_group group = get_insn_group (insn);
50731   enum insn_path path = get_insn_path (insn);
50732   int sum;
50733
50734   /* Make disp_cmp and disp_jcc get scheduled at the latest.  These
50735      instructions should be given the lowest priority in the
50736      scheduling process in Haifa scheduler to make sure they will be
50737      scheduled in the same dispatch window as the reference to them.  */
50738   if (group == disp_jcc || group == disp_cmp)
50739     return false;
50740
50741   /* Check nonrestricted.  */
50742   if (group == disp_no_group || group == disp_branch)
50743     return true;
50744
50745   /* Get last dispatch window.  */
50746   if (window_list_next)
50747     window_list = window_list_next;
50748
50749   if (window_list->window_num == 1)
50750     {
50751       sum = window_list->prev->window_size + window_list->window_size;
50752
50753       if (sum == 32
50754           || (min_insn_size (insn) + sum) >= 48)
50755         /* Window 1 is full.  Go for next window.  */
50756         return true;
50757     }
50758
50759   num_restrict = count_num_restricted (insn, window_list);
50760
50761   if (num_restrict > num_allowable_groups[group])
50762     return false;
50763
50764   /* See if it fits in the first window.  */
50765   if (window_list->window_num == 0)
50766     {
50767       /* The first widow should have only single and double path
50768          uops.  */
50769       if (path == path_double
50770           && (window_list->num_uops + 2) > MAX_INSN)
50771         return false;
50772       else if (path != path_single)
50773         return false;
50774     }
50775   return true;
50776 }
50777
50778 /* Add an instruction INSN with NUM_UOPS micro-operations to the
50779    dispatch window WINDOW_LIST.  */
50780
50781 static void
50782 add_insn_window (rtx_insn *insn, dispatch_windows *window_list, int num_uops)
50783 {
50784   int byte_len = min_insn_size (insn);
50785   int num_insn = window_list->num_insn;
50786   int imm_size;
50787   sched_insn_info *window = window_list->window;
50788   enum dispatch_group group = get_insn_group (insn);
50789   enum insn_path path = get_insn_path (insn);
50790   int num_imm_operand;
50791   int num_imm32_operand;
50792   int num_imm64_operand;
50793
50794   if (!window_list->violation && group != disp_cmp
50795       && !fits_dispatch_window (insn))
50796     window_list->violation = true;
50797
50798   imm_size = get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50799                                  &num_imm64_operand);
50800
50801   /* Initialize window with new instruction.  */
50802   window[num_insn].insn = insn;
50803   window[num_insn].byte_len = byte_len;
50804   window[num_insn].group = group;
50805   window[num_insn].path = path;
50806   window[num_insn].imm_bytes = imm_size;
50807
50808   window_list->window_size += byte_len;
50809   window_list->num_insn = num_insn + 1;
50810   window_list->num_uops = window_list->num_uops + num_uops;
50811   window_list->imm_size += imm_size;
50812   window_list->num_imm += num_imm_operand;
50813   window_list->num_imm_32 += num_imm32_operand;
50814   window_list->num_imm_64 += num_imm64_operand;
50815
50816   if (group == disp_store)
50817     window_list->num_stores += 1;
50818   else if (group == disp_load
50819            || group == disp_prefetch)
50820     window_list->num_loads += 1;
50821   else if (group == disp_load_store)
50822     {
50823       window_list->num_stores += 1;
50824       window_list->num_loads += 1;
50825     }
50826 }
50827
50828 /* Adds a scheduled instruction, INSN, to the current dispatch window.
50829    If the total bytes of instructions or the number of instructions in
50830    the window exceed allowable, it allocates a new window.  */
50831
50832 static void
50833 add_to_dispatch_window (rtx_insn *insn)
50834 {
50835   int byte_len;
50836   dispatch_windows *window_list;
50837   dispatch_windows *next_list;
50838   dispatch_windows *window0_list;
50839   enum insn_path path;
50840   enum dispatch_group insn_group;
50841   bool insn_fits;
50842   int num_insn;
50843   int num_uops;
50844   int window_num;
50845   int insn_num_uops;
50846   int sum;
50847
50848   if (INSN_CODE (insn) < 0)
50849     return;
50850
50851   byte_len = min_insn_size (insn);
50852   window_list = dispatch_window_list;
50853   next_list = window_list->next;
50854   path = get_insn_path (insn);
50855   insn_group = get_insn_group (insn);
50856
50857   /* Get the last dispatch window.  */
50858   if (next_list)
50859       window_list = dispatch_window_list->next;
50860
50861   if (path == path_single)
50862     insn_num_uops = 1;
50863   else if (path == path_double)
50864     insn_num_uops = 2;
50865   else
50866     insn_num_uops = (int) path;
50867
50868   /* If current window is full, get a new window.
50869      Window number zero is full, if MAX_INSN uops are scheduled in it.
50870      Window number one is full, if window zero's bytes plus window
50871      one's bytes is 32, or if the bytes of the new instruction added
50872      to the total makes it greater than 48, or it has already MAX_INSN
50873      instructions in it.  */
50874   num_insn = window_list->num_insn;
50875   num_uops = window_list->num_uops;
50876   window_num = window_list->window_num;
50877   insn_fits = fits_dispatch_window (insn);
50878
50879   if (num_insn >= MAX_INSN
50880       || num_uops + insn_num_uops > MAX_INSN
50881       || !(insn_fits))
50882     {
50883       window_num = ~window_num & 1;
50884       window_list = allocate_next_window (window_num);
50885     }
50886
50887   if (window_num == 0)
50888     {
50889       add_insn_window (insn, window_list, insn_num_uops);
50890       if (window_list->num_insn >= MAX_INSN
50891           && insn_group == disp_branch)
50892         {
50893           process_end_window ();
50894           return;
50895         }
50896     }
50897   else if (window_num == 1)
50898     {
50899       window0_list = window_list->prev;
50900       sum = window0_list->window_size + window_list->window_size;
50901       if (sum == 32
50902           || (byte_len + sum) >= 48)
50903         {
50904           process_end_window ();
50905           window_list = dispatch_window_list;
50906         }
50907
50908       add_insn_window (insn, window_list, insn_num_uops);
50909     }
50910   else
50911     gcc_unreachable ();
50912
50913   if (is_end_basic_block (insn_group))
50914     {
50915       /* End of basic block is reached do end-basic-block process.  */
50916       process_end_window ();
50917       return;
50918     }
50919 }
50920
50921 /* Print the dispatch window, WINDOW_NUM, to FILE.  */
50922
50923 DEBUG_FUNCTION static void
50924 debug_dispatch_window_file (FILE *file, int window_num)
50925 {
50926   dispatch_windows *list;
50927   int i;
50928
50929   if (window_num == 0)
50930     list = dispatch_window_list;
50931   else
50932     list = dispatch_window_list1;
50933
50934   fprintf (file, "Window #%d:\n", list->window_num);
50935   fprintf (file, "  num_insn = %d, num_uops = %d, window_size = %d\n",
50936           list->num_insn, list->num_uops, list->window_size);
50937   fprintf (file, "  num_imm = %d, num_imm_32 = %d, num_imm_64 = %d, imm_size = %d\n",
50938            list->num_imm, list->num_imm_32, list->num_imm_64, list->imm_size);
50939
50940   fprintf (file, "  num_loads = %d, num_stores = %d\n", list->num_loads,
50941           list->num_stores);
50942   fprintf (file, " insn info:\n");
50943
50944   for (i = 0; i < MAX_INSN; i++)
50945     {
50946       if (!list->window[i].insn)
50947         break;
50948       fprintf (file, "    group[%d] = %s, insn[%d] = %p, path[%d] = %d byte_len[%d] = %d, imm_bytes[%d] = %d\n",
50949               i, group_name[list->window[i].group],
50950               i, (void *)list->window[i].insn,
50951               i, list->window[i].path,
50952               i, list->window[i].byte_len,
50953               i, list->window[i].imm_bytes);
50954     }
50955 }
50956
50957 /* Print to stdout a dispatch window.  */
50958
50959 DEBUG_FUNCTION void
50960 debug_dispatch_window (int window_num)
50961 {
50962   debug_dispatch_window_file (stdout, window_num);
50963 }
50964
50965 /* Print INSN dispatch information to FILE.  */
50966
50967 DEBUG_FUNCTION static void
50968 debug_insn_dispatch_info_file (FILE *file, rtx_insn *insn)
50969 {
50970   int byte_len;
50971   enum insn_path path;
50972   enum dispatch_group group;
50973   int imm_size;
50974   int num_imm_operand;
50975   int num_imm32_operand;
50976   int num_imm64_operand;
50977
50978   if (INSN_CODE (insn) < 0)
50979     return;
50980
50981   byte_len = min_insn_size (insn);
50982   path = get_insn_path (insn);
50983   group = get_insn_group (insn);
50984   imm_size = get_num_immediates (insn, &num_imm_operand, &num_imm32_operand,
50985                                  &num_imm64_operand);
50986
50987   fprintf (file, " insn info:\n");
50988   fprintf (file, "  group = %s, path = %d, byte_len = %d\n",
50989            group_name[group], path, byte_len);
50990   fprintf (file, "  num_imm = %d, num_imm_32 = %d, num_imm_64 = %d, imm_size = %d\n",
50991            num_imm_operand, num_imm32_operand, num_imm64_operand, imm_size);
50992 }
50993
50994 /* Print to STDERR the status of the ready list with respect to
50995    dispatch windows.  */
50996
50997 DEBUG_FUNCTION void
50998 debug_ready_dispatch (void)
50999 {
51000   int i;
51001   int no_ready = number_in_ready ();
51002
51003   fprintf (stdout, "Number of ready: %d\n", no_ready);
51004
51005   for (i = 0; i < no_ready; i++)
51006     debug_insn_dispatch_info_file (stdout, get_ready_element (i));
51007 }
51008
51009 /* This routine is the driver of the dispatch scheduler.  */
51010
51011 static void
51012 do_dispatch (rtx_insn *insn, int mode)
51013 {
51014   if (mode == DISPATCH_INIT)
51015     init_dispatch_sched ();
51016   else if (mode == ADD_TO_DISPATCH_WINDOW)
51017     add_to_dispatch_window (insn);
51018 }
51019
51020 /* Return TRUE if Dispatch Scheduling is supported.  */
51021
51022 static bool
51023 has_dispatch (rtx_insn *insn, int action)
51024 {
51025   if ((TARGET_BDVER1 || TARGET_BDVER2 || TARGET_BDVER3 || TARGET_BDVER4)
51026       && flag_dispatch_scheduler)
51027     switch (action)
51028       {
51029       default:
51030         return false;
51031
51032       case IS_DISPATCH_ON:
51033         return true;
51034         break;
51035
51036       case IS_CMP:
51037         return is_cmp (insn);
51038
51039       case DISPATCH_VIOLATION:
51040         return dispatch_violation ();
51041
51042       case FITS_DISPATCH_WINDOW:
51043         return fits_dispatch_window (insn);
51044       }
51045
51046   return false;
51047 }
51048
51049 /* Implementation of reassociation_width target hook used by
51050    reassoc phase to identify parallelism level in reassociated
51051    tree.  Statements tree_code is passed in OPC.  Arguments type
51052    is passed in MODE.
51053
51054    Currently parallel reassociation is enabled for Atom
51055    processors only and we set reassociation width to be 2
51056    because Atom may issue up to 2 instructions per cycle.
51057
51058    Return value should be fixed if parallel reassociation is
51059    enabled for other processors.  */
51060
51061 static int
51062 ix86_reassociation_width (unsigned int, machine_mode mode)
51063 {
51064   /* Vector part.  */
51065   if (VECTOR_MODE_P (mode))
51066     {
51067       if (TARGET_VECTOR_PARALLEL_EXECUTION)
51068         return 2;
51069       else
51070         return 1;
51071     }
51072
51073   /* Scalar part.  */
51074   if (INTEGRAL_MODE_P (mode) && TARGET_REASSOC_INT_TO_PARALLEL)
51075     return 2;
51076   else if (FLOAT_MODE_P (mode) && TARGET_REASSOC_FP_TO_PARALLEL)
51077     return 2;
51078   else
51079     return 1;
51080 }
51081
51082 /* ??? No autovectorization into MMX or 3DNOW until we can reliably
51083    place emms and femms instructions.  */
51084
51085 static machine_mode
51086 ix86_preferred_simd_mode (machine_mode mode)
51087 {
51088   if (!TARGET_SSE)
51089     return word_mode;
51090
51091   switch (mode)
51092     {
51093     case QImode:
51094       return TARGET_AVX512BW ? V64QImode :
51095        (TARGET_AVX && !TARGET_PREFER_AVX128) ? V32QImode : V16QImode;
51096     case HImode:
51097       return TARGET_AVX512BW ? V32HImode :
51098        (TARGET_AVX && !TARGET_PREFER_AVX128) ? V16HImode : V8HImode;
51099     case SImode:
51100       return TARGET_AVX512F ? V16SImode :
51101         (TARGET_AVX && !TARGET_PREFER_AVX128) ? V8SImode : V4SImode;
51102     case DImode:
51103       return TARGET_AVX512F ? V8DImode :
51104         (TARGET_AVX && !TARGET_PREFER_AVX128) ? V4DImode : V2DImode;
51105
51106     case SFmode:
51107       if (TARGET_AVX512F)
51108         return V16SFmode;
51109       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
51110         return V8SFmode;
51111       else
51112         return V4SFmode;
51113
51114     case DFmode:
51115       if (!TARGET_VECTORIZE_DOUBLE)
51116         return word_mode;
51117       else if (TARGET_AVX512F)
51118         return V8DFmode;
51119       else if (TARGET_AVX && !TARGET_PREFER_AVX128)
51120         return V4DFmode;
51121       else if (TARGET_SSE2)
51122         return V2DFmode;
51123       /* FALLTHRU */
51124
51125     default:
51126       return word_mode;
51127     }
51128 }
51129
51130 /* If AVX is enabled then try vectorizing with both 256bit and 128bit
51131    vectors.  If AVX512F is enabled then try vectorizing with 512bit,
51132    256bit and 128bit vectors.  */
51133
51134 static unsigned int
51135 ix86_autovectorize_vector_sizes (void)
51136 {
51137   return TARGET_AVX512F ? 64 | 32 | 16 :
51138     (TARGET_AVX && !TARGET_PREFER_AVX128) ? 32 | 16 : 0;
51139 }
51140
51141 \f
51142
51143 /* Return class of registers which could be used for pseudo of MODE
51144    and of class RCLASS for spilling instead of memory.  Return NO_REGS
51145    if it is not possible or non-profitable.  */
51146 static reg_class_t
51147 ix86_spill_class (reg_class_t rclass, machine_mode mode)
51148 {
51149   if (TARGET_SSE && TARGET_GENERAL_REGS_SSE_SPILL && ! TARGET_MMX
51150       && (mode == SImode || (TARGET_64BIT && mode == DImode))
51151       && rclass != NO_REGS && INTEGER_CLASS_P (rclass))
51152     return ALL_SSE_REGS;
51153   return NO_REGS;
51154 }
51155
51156 /* Implement targetm.vectorize.init_cost.  */
51157
51158 static void *
51159 ix86_init_cost (struct loop *)
51160 {
51161   unsigned *cost = XNEWVEC (unsigned, 3);
51162   cost[vect_prologue] = cost[vect_body] = cost[vect_epilogue] = 0;
51163   return cost;
51164 }
51165
51166 /* Implement targetm.vectorize.add_stmt_cost.  */
51167
51168 static unsigned
51169 ix86_add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
51170                     struct _stmt_vec_info *stmt_info, int misalign,
51171                     enum vect_cost_model_location where)
51172 {
51173   unsigned *cost = (unsigned *) data;
51174   unsigned retval = 0;
51175
51176   tree vectype = stmt_info ? stmt_vectype (stmt_info) : NULL_TREE;
51177   int stmt_cost = ix86_builtin_vectorization_cost (kind, vectype, misalign);
51178
51179   /* Statements in an inner loop relative to the loop being
51180      vectorized are weighted more heavily.  The value here is
51181       arbitrary and could potentially be improved with analysis.  */
51182   if (where == vect_body && stmt_info && stmt_in_inner_loop_p (stmt_info))
51183     count *= 50;  /* FIXME.  */
51184
51185   retval = (unsigned) (count * stmt_cost);
51186
51187   /* We need to multiply all vector stmt cost by 1.7 (estimated cost)
51188      for Silvermont as it has out of order integer pipeline and can execute
51189      2 scalar instruction per tick, but has in order SIMD pipeline.  */
51190   if (TARGET_SILVERMONT || TARGET_INTEL)
51191     if (stmt_info && stmt_info->stmt)
51192       {
51193         tree lhs_op = gimple_get_lhs (stmt_info->stmt);
51194         if (lhs_op && TREE_CODE (TREE_TYPE (lhs_op)) == INTEGER_TYPE)
51195           retval = (retval * 17) / 10;
51196       }
51197
51198   cost[where] += retval;
51199
51200   return retval;
51201 }
51202
51203 /* Implement targetm.vectorize.finish_cost.  */
51204
51205 static void
51206 ix86_finish_cost (void *data, unsigned *prologue_cost,
51207                   unsigned *body_cost, unsigned *epilogue_cost)
51208 {
51209   unsigned *cost = (unsigned *) data;
51210   *prologue_cost = cost[vect_prologue];
51211   *body_cost     = cost[vect_body];
51212   *epilogue_cost = cost[vect_epilogue];
51213 }
51214
51215 /* Implement targetm.vectorize.destroy_cost_data.  */
51216
51217 static void
51218 ix86_destroy_cost_data (void *data)
51219 {
51220   free (data);
51221 }
51222
51223 /* Validate target specific memory model bits in VAL. */
51224
51225 static unsigned HOST_WIDE_INT
51226 ix86_memmodel_check (unsigned HOST_WIDE_INT val)
51227 {
51228   unsigned HOST_WIDE_INT model = val & MEMMODEL_MASK;
51229   bool strong;
51230
51231   if (val & ~(unsigned HOST_WIDE_INT)(IX86_HLE_ACQUIRE|IX86_HLE_RELEASE
51232                                       |MEMMODEL_MASK)
51233       || ((val & IX86_HLE_ACQUIRE) && (val & IX86_HLE_RELEASE)))
51234     {
51235       warning (OPT_Winvalid_memory_model,
51236                "Unknown architecture specific memory model");
51237       return MEMMODEL_SEQ_CST;
51238     }
51239   strong = (model == MEMMODEL_ACQ_REL || model == MEMMODEL_SEQ_CST);
51240   if (val & IX86_HLE_ACQUIRE && !(model == MEMMODEL_ACQUIRE || strong))
51241     {
51242       warning (OPT_Winvalid_memory_model,
51243               "HLE_ACQUIRE not used with ACQUIRE or stronger memory model");
51244       return MEMMODEL_SEQ_CST | IX86_HLE_ACQUIRE;
51245     }
51246    if (val & IX86_HLE_RELEASE && !(model == MEMMODEL_RELEASE || strong))
51247     {
51248       warning (OPT_Winvalid_memory_model,
51249               "HLE_RELEASE not used with RELEASE or stronger memory model");
51250       return MEMMODEL_SEQ_CST | IX86_HLE_RELEASE;
51251     }
51252   return val;
51253 }
51254
51255 /* Set CLONEI->vecsize_mangle, CLONEI->vecsize_int,
51256    CLONEI->vecsize_float and if CLONEI->simdlen is 0, also
51257    CLONEI->simdlen.  Return 0 if SIMD clones shouldn't be emitted,
51258    or number of vecsize_mangle variants that should be emitted.  */
51259
51260 static int
51261 ix86_simd_clone_compute_vecsize_and_simdlen (struct cgraph_node *node,
51262                                              struct cgraph_simd_clone *clonei,
51263                                              tree base_type, int num)
51264 {
51265   int ret = 1;
51266
51267   if (clonei->simdlen
51268       && (clonei->simdlen < 2
51269           || clonei->simdlen > 16
51270           || (clonei->simdlen & (clonei->simdlen - 1)) != 0))
51271     {
51272       warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
51273                   "unsupported simdlen %d", clonei->simdlen);
51274       return 0;
51275     }
51276
51277   tree ret_type = TREE_TYPE (TREE_TYPE (node->decl));
51278   if (TREE_CODE (ret_type) != VOID_TYPE)
51279     switch (TYPE_MODE (ret_type))
51280       {
51281       case QImode:
51282       case HImode:
51283       case SImode:
51284       case DImode:
51285       case SFmode:
51286       case DFmode:
51287       /* case SCmode: */
51288       /* case DCmode: */
51289         break;
51290       default:
51291         warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
51292                     "unsupported return type %qT for simd\n", ret_type);
51293         return 0;
51294       }
51295
51296   tree t;
51297   int i;
51298
51299   for (t = DECL_ARGUMENTS (node->decl), i = 0; t; t = DECL_CHAIN (t), i++)
51300     /* FIXME: Shouldn't we allow such arguments if they are uniform?  */
51301     switch (TYPE_MODE (TREE_TYPE (t)))
51302       {
51303       case QImode:
51304       case HImode:
51305       case SImode:
51306       case DImode:
51307       case SFmode:
51308       case DFmode:
51309       /* case SCmode: */
51310       /* case DCmode: */
51311         break;
51312       default:
51313         warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
51314                     "unsupported argument type %qT for simd\n", TREE_TYPE (t));
51315         return 0;
51316       }
51317
51318   if (clonei->cilk_elemental)
51319     {
51320       /* Parse here processor clause.  If not present, default to 'b'.  */
51321       clonei->vecsize_mangle = 'b';
51322     }
51323   else if (!TREE_PUBLIC (node->decl))
51324     {
51325       /* If the function isn't exported, we can pick up just one ISA
51326          for the clones.  */
51327       if (TARGET_AVX2)
51328         clonei->vecsize_mangle = 'd';
51329       else if (TARGET_AVX)
51330         clonei->vecsize_mangle = 'c';
51331       else
51332         clonei->vecsize_mangle = 'b';
51333       ret = 1;
51334     }
51335   else
51336     {
51337       clonei->vecsize_mangle = "bcd"[num];
51338       ret = 3;
51339     }
51340   switch (clonei->vecsize_mangle)
51341     {
51342     case 'b':
51343       clonei->vecsize_int = 128;
51344       clonei->vecsize_float = 128;
51345       break;
51346     case 'c':
51347       clonei->vecsize_int = 128;
51348       clonei->vecsize_float = 256;
51349       break;
51350     case 'd':
51351       clonei->vecsize_int = 256;
51352       clonei->vecsize_float = 256;
51353       break;
51354     }
51355   if (clonei->simdlen == 0)
51356     {
51357       if (SCALAR_INT_MODE_P (TYPE_MODE (base_type)))
51358         clonei->simdlen = clonei->vecsize_int;
51359       else
51360         clonei->simdlen = clonei->vecsize_float;
51361       clonei->simdlen /= GET_MODE_BITSIZE (TYPE_MODE (base_type));
51362       if (clonei->simdlen > 16)
51363         clonei->simdlen = 16;
51364     }
51365   return ret;
51366 }
51367
51368 /* Add target attribute to SIMD clone NODE if needed.  */
51369
51370 static void
51371 ix86_simd_clone_adjust (struct cgraph_node *node)
51372 {
51373   const char *str = NULL;
51374   gcc_assert (node->decl == cfun->decl);
51375   switch (node->simdclone->vecsize_mangle)
51376     {
51377     case 'b':
51378       if (!TARGET_SSE2)
51379         str = "sse2";
51380       break;
51381     case 'c':
51382       if (!TARGET_AVX)
51383         str = "avx";
51384       break;
51385     case 'd':
51386       if (!TARGET_AVX2)
51387         str = "avx2";
51388       break;
51389     default:
51390       gcc_unreachable ();
51391     }
51392   if (str == NULL)
51393     return;
51394   push_cfun (NULL);
51395   tree args = build_tree_list (NULL_TREE, build_string (strlen (str), str));
51396   bool ok = ix86_valid_target_attribute_p (node->decl, NULL, args, 0);
51397   gcc_assert (ok);
51398   pop_cfun ();
51399   ix86_reset_previous_fndecl ();
51400   ix86_set_current_function (node->decl);
51401 }
51402
51403 /* If SIMD clone NODE can't be used in a vectorized loop
51404    in current function, return -1, otherwise return a badness of using it
51405    (0 if it is most desirable from vecsize_mangle point of view, 1
51406    slightly less desirable, etc.).  */
51407
51408 static int
51409 ix86_simd_clone_usable (struct cgraph_node *node)
51410 {
51411   switch (node->simdclone->vecsize_mangle)
51412     {
51413     case 'b':
51414       if (!TARGET_SSE2)
51415         return -1;
51416       if (!TARGET_AVX)
51417         return 0;
51418       return TARGET_AVX2 ? 2 : 1;
51419     case 'c':
51420       if (!TARGET_AVX)
51421         return -1;
51422       return TARGET_AVX2 ? 1 : 0;
51423       break;
51424     case 'd':
51425       if (!TARGET_AVX2)
51426         return -1;
51427       return 0;
51428     default:
51429       gcc_unreachable ();
51430     }
51431 }
51432
51433 /* This function adjusts the unroll factor based on
51434    the hardware capabilities. For ex, bdver3 has
51435    a loop buffer which makes unrolling of smaller
51436    loops less important. This function decides the
51437    unroll factor using number of memory references
51438    (value 32 is used) as a heuristic. */
51439
51440 static unsigned
51441 ix86_loop_unroll_adjust (unsigned nunroll, struct loop *loop)
51442 {
51443   basic_block *bbs;
51444   rtx_insn *insn;
51445   unsigned i;
51446   unsigned mem_count = 0;
51447
51448   if (!TARGET_ADJUST_UNROLL)
51449      return nunroll;
51450
51451   /* Count the number of memory references within the loop body.
51452      This value determines the unrolling factor for bdver3 and bdver4
51453      architectures. */
51454   subrtx_iterator::array_type array;
51455   bbs = get_loop_body (loop);
51456   for (i = 0; i < loop->num_nodes; i++)
51457     FOR_BB_INSNS (bbs[i], insn)
51458       if (NONDEBUG_INSN_P (insn))
51459         FOR_EACH_SUBRTX (iter, array, insn, NONCONST)
51460           if (const_rtx x = *iter)
51461             if (MEM_P (x))
51462               {
51463                 machine_mode mode = GET_MODE (x);
51464                 unsigned int n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD;
51465                 if (n_words > 4)
51466                   mem_count += 2;
51467                 else
51468                   mem_count += 1;
51469               }
51470   free (bbs);
51471
51472   if (mem_count && mem_count <=32)
51473     return 32/mem_count;
51474
51475   return nunroll;
51476 }
51477
51478
51479 /* Implement TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P.  */
51480
51481 static bool
51482 ix86_float_exceptions_rounding_supported_p (void)
51483 {
51484   /* For x87 floating point with standard excess precision handling,
51485      there is no adddf3 pattern (since x87 floating point only has
51486      XFmode operations) so the default hook implementation gets this
51487      wrong.  */
51488   return TARGET_80387 || TARGET_SSE_MATH;
51489 }
51490
51491 /* Implement TARGET_ATOMIC_ASSIGN_EXPAND_FENV.  */
51492
51493 static void
51494 ix86_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update)
51495 {
51496   if (!TARGET_80387 && !TARGET_SSE_MATH)
51497     return;
51498   tree exceptions_var = create_tmp_var (integer_type_node);
51499   if (TARGET_80387)
51500     {
51501       tree fenv_index_type = build_index_type (size_int (6));
51502       tree fenv_type = build_array_type (unsigned_type_node, fenv_index_type);
51503       tree fenv_var = create_tmp_var (fenv_type);
51504       mark_addressable (fenv_var);
51505       tree fenv_ptr = build_pointer_type (fenv_type);
51506       tree fenv_addr = build1 (ADDR_EXPR, fenv_ptr, fenv_var);
51507       fenv_addr = fold_convert (ptr_type_node, fenv_addr);
51508       tree fnstenv = ix86_builtins[IX86_BUILTIN_FNSTENV];
51509       tree fldenv = ix86_builtins[IX86_BUILTIN_FLDENV];
51510       tree fnstsw = ix86_builtins[IX86_BUILTIN_FNSTSW];
51511       tree fnclex = ix86_builtins[IX86_BUILTIN_FNCLEX];
51512       tree hold_fnstenv = build_call_expr (fnstenv, 1, fenv_addr);
51513       tree hold_fnclex = build_call_expr (fnclex, 0);
51514       *hold = build2 (COMPOUND_EXPR, void_type_node, hold_fnstenv,
51515                       hold_fnclex);
51516       *clear = build_call_expr (fnclex, 0);
51517       tree sw_var = create_tmp_var (short_unsigned_type_node);
51518       tree fnstsw_call = build_call_expr (fnstsw, 0);
51519       tree sw_mod = build2 (MODIFY_EXPR, short_unsigned_type_node,
51520                             sw_var, fnstsw_call);
51521       tree exceptions_x87 = fold_convert (integer_type_node, sw_var);
51522       tree update_mod = build2 (MODIFY_EXPR, integer_type_node,
51523                                 exceptions_var, exceptions_x87);
51524       *update = build2 (COMPOUND_EXPR, integer_type_node,
51525                         sw_mod, update_mod);
51526       tree update_fldenv = build_call_expr (fldenv, 1, fenv_addr);
51527       *update = build2 (COMPOUND_EXPR, void_type_node, *update, update_fldenv);
51528     }
51529   if (TARGET_SSE_MATH)
51530     {
51531       tree mxcsr_orig_var = create_tmp_var (unsigned_type_node);
51532       tree mxcsr_mod_var = create_tmp_var (unsigned_type_node);
51533       tree stmxcsr = ix86_builtins[IX86_BUILTIN_STMXCSR];
51534       tree ldmxcsr = ix86_builtins[IX86_BUILTIN_LDMXCSR];
51535       tree stmxcsr_hold_call = build_call_expr (stmxcsr, 0);
51536       tree hold_assign_orig = build2 (MODIFY_EXPR, unsigned_type_node,
51537                                       mxcsr_orig_var, stmxcsr_hold_call);
51538       tree hold_mod_val = build2 (BIT_IOR_EXPR, unsigned_type_node,
51539                                   mxcsr_orig_var,
51540                                   build_int_cst (unsigned_type_node, 0x1f80));
51541       hold_mod_val = build2 (BIT_AND_EXPR, unsigned_type_node, hold_mod_val,
51542                              build_int_cst (unsigned_type_node, 0xffffffc0));
51543       tree hold_assign_mod = build2 (MODIFY_EXPR, unsigned_type_node,
51544                                      mxcsr_mod_var, hold_mod_val);
51545       tree ldmxcsr_hold_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
51546       tree hold_all = build2 (COMPOUND_EXPR, unsigned_type_node,
51547                               hold_assign_orig, hold_assign_mod);
51548       hold_all = build2 (COMPOUND_EXPR, void_type_node, hold_all,
51549                          ldmxcsr_hold_call);
51550       if (*hold)
51551         *hold = build2 (COMPOUND_EXPR, void_type_node, *hold, hold_all);
51552       else
51553         *hold = hold_all;
51554       tree ldmxcsr_clear_call = build_call_expr (ldmxcsr, 1, mxcsr_mod_var);
51555       if (*clear)
51556         *clear = build2 (COMPOUND_EXPR, void_type_node, *clear,
51557                          ldmxcsr_clear_call);
51558       else
51559         *clear = ldmxcsr_clear_call;
51560       tree stxmcsr_update_call = build_call_expr (stmxcsr, 0);
51561       tree exceptions_sse = fold_convert (integer_type_node,
51562                                           stxmcsr_update_call);
51563       if (*update)
51564         {
51565           tree exceptions_mod = build2 (BIT_IOR_EXPR, integer_type_node,
51566                                         exceptions_var, exceptions_sse);
51567           tree exceptions_assign = build2 (MODIFY_EXPR, integer_type_node,
51568                                            exceptions_var, exceptions_mod);
51569           *update = build2 (COMPOUND_EXPR, integer_type_node, *update,
51570                             exceptions_assign);
51571         }
51572       else
51573         *update = build2 (MODIFY_EXPR, integer_type_node,
51574                           exceptions_var, exceptions_sse);
51575       tree ldmxcsr_update_call = build_call_expr (ldmxcsr, 1, mxcsr_orig_var);
51576       *update = build2 (COMPOUND_EXPR, void_type_node, *update,
51577                         ldmxcsr_update_call);
51578     }
51579   tree atomic_feraiseexcept
51580     = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT);
51581   tree atomic_feraiseexcept_call = build_call_expr (atomic_feraiseexcept,
51582                                                     1, exceptions_var);
51583   *update = build2 (COMPOUND_EXPR, void_type_node, *update,
51584                     atomic_feraiseexcept_call);
51585 }
51586
51587 /* Return mode to be used for bounds or VOIDmode
51588    if bounds are not supported.  */
51589
51590 static enum machine_mode
51591 ix86_mpx_bound_mode ()
51592 {
51593   /* Do not support pointer checker if MPX
51594      is not enabled.  */
51595   if (!TARGET_MPX)
51596     {
51597       if (flag_check_pointer_bounds)
51598         warning (0, "Pointer Checker requires MPX support on this target."
51599                  " Use -mmpx options to enable MPX.");
51600       return VOIDmode;
51601     }
51602
51603   return BNDmode;
51604 }
51605
51606 /*  Return constant used to statically initialize constant bounds.
51607
51608     This function is used to create special bound values.  For now
51609     only INIT bounds and NONE bounds are expected.  More special
51610     values may be added later.  */
51611
51612 static tree
51613 ix86_make_bounds_constant (HOST_WIDE_INT lb, HOST_WIDE_INT ub)
51614 {
51615   tree low = lb ? build_minus_one_cst (pointer_sized_int_node)
51616     : build_zero_cst (pointer_sized_int_node);
51617   tree high = ub ? build_zero_cst (pointer_sized_int_node)
51618     : build_minus_one_cst (pointer_sized_int_node);
51619
51620   /* This function is supposed to be used to create INIT and
51621      NONE bounds only.  */
51622   gcc_assert ((lb == 0 && ub == -1)
51623               || (lb == -1 && ub == 0));
51624
51625   return build_complex (NULL, low, high);
51626 }
51627
51628 /* Generate a list of statements STMTS to initialize pointer bounds
51629    variable VAR with bounds LB and UB.  Return the number of generated
51630    statements.  */
51631
51632 static int
51633 ix86_initialize_bounds (tree var, tree lb, tree ub, tree *stmts)
51634 {
51635   tree bnd_ptr = build_pointer_type (pointer_sized_int_node);
51636   tree lhs, modify, var_p;
51637
51638   ub = build1 (BIT_NOT_EXPR, pointer_sized_int_node, ub);
51639   var_p = fold_convert (bnd_ptr, build_fold_addr_expr (var));
51640
51641   lhs = build1 (INDIRECT_REF, pointer_sized_int_node, var_p);
51642   modify = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, lb);
51643   append_to_statement_list (modify, stmts);
51644
51645   lhs = build1 (INDIRECT_REF, pointer_sized_int_node,
51646                 build2 (POINTER_PLUS_EXPR, bnd_ptr, var_p,
51647                         TYPE_SIZE_UNIT (pointer_sized_int_node)));
51648   modify = build2 (MODIFY_EXPR, TREE_TYPE (lhs), lhs, ub);
51649   append_to_statement_list (modify, stmts);
51650
51651   return 2;
51652 }
51653
51654 /* Initialize the GCC target structure.  */
51655 #undef TARGET_RETURN_IN_MEMORY
51656 #define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
51657
51658 #undef TARGET_LEGITIMIZE_ADDRESS
51659 #define TARGET_LEGITIMIZE_ADDRESS ix86_legitimize_address
51660
51661 #undef TARGET_ATTRIBUTE_TABLE
51662 #define TARGET_ATTRIBUTE_TABLE ix86_attribute_table
51663 #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
51664 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_const_tree_true
51665 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
51666 #  undef TARGET_MERGE_DECL_ATTRIBUTES
51667 #  define TARGET_MERGE_DECL_ATTRIBUTES merge_dllimport_decl_attributes
51668 #endif
51669
51670 #undef TARGET_COMP_TYPE_ATTRIBUTES
51671 #define TARGET_COMP_TYPE_ATTRIBUTES ix86_comp_type_attributes
51672
51673 #undef TARGET_INIT_BUILTINS
51674 #define TARGET_INIT_BUILTINS ix86_init_builtins
51675 #undef TARGET_BUILTIN_DECL
51676 #define TARGET_BUILTIN_DECL ix86_builtin_decl
51677 #undef TARGET_EXPAND_BUILTIN
51678 #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
51679
51680 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION
51681 #define TARGET_VECTORIZE_BUILTIN_VECTORIZED_FUNCTION \
51682   ix86_builtin_vectorized_function
51683
51684 #undef TARGET_VECTORIZE_BUILTIN_TM_LOAD
51685 #define TARGET_VECTORIZE_BUILTIN_TM_LOAD ix86_builtin_tm_load
51686
51687 #undef TARGET_VECTORIZE_BUILTIN_TM_STORE
51688 #define TARGET_VECTORIZE_BUILTIN_TM_STORE ix86_builtin_tm_store
51689
51690 #undef TARGET_VECTORIZE_BUILTIN_GATHER
51691 #define TARGET_VECTORIZE_BUILTIN_GATHER ix86_vectorize_builtin_gather
51692
51693 #undef TARGET_BUILTIN_RECIPROCAL
51694 #define TARGET_BUILTIN_RECIPROCAL ix86_builtin_reciprocal
51695
51696 #undef TARGET_ASM_FUNCTION_EPILOGUE
51697 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
51698
51699 #undef TARGET_ENCODE_SECTION_INFO
51700 #ifndef SUBTARGET_ENCODE_SECTION_INFO
51701 #define TARGET_ENCODE_SECTION_INFO ix86_encode_section_info
51702 #else
51703 #define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
51704 #endif
51705
51706 #undef TARGET_ASM_OPEN_PAREN
51707 #define TARGET_ASM_OPEN_PAREN ""
51708 #undef TARGET_ASM_CLOSE_PAREN
51709 #define TARGET_ASM_CLOSE_PAREN ""
51710
51711 #undef TARGET_ASM_BYTE_OP
51712 #define TARGET_ASM_BYTE_OP ASM_BYTE
51713
51714 #undef TARGET_ASM_ALIGNED_HI_OP
51715 #define TARGET_ASM_ALIGNED_HI_OP ASM_SHORT
51716 #undef TARGET_ASM_ALIGNED_SI_OP
51717 #define TARGET_ASM_ALIGNED_SI_OP ASM_LONG
51718 #ifdef ASM_QUAD
51719 #undef TARGET_ASM_ALIGNED_DI_OP
51720 #define TARGET_ASM_ALIGNED_DI_OP ASM_QUAD
51721 #endif
51722
51723 #undef TARGET_PROFILE_BEFORE_PROLOGUE
51724 #define TARGET_PROFILE_BEFORE_PROLOGUE ix86_profile_before_prologue
51725
51726 #undef TARGET_MANGLE_DECL_ASSEMBLER_NAME
51727 #define TARGET_MANGLE_DECL_ASSEMBLER_NAME ix86_mangle_decl_assembler_name
51728
51729 #undef TARGET_ASM_UNALIGNED_HI_OP
51730 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
51731 #undef TARGET_ASM_UNALIGNED_SI_OP
51732 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
51733 #undef TARGET_ASM_UNALIGNED_DI_OP
51734 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
51735
51736 #undef TARGET_PRINT_OPERAND
51737 #define TARGET_PRINT_OPERAND ix86_print_operand
51738 #undef TARGET_PRINT_OPERAND_ADDRESS
51739 #define TARGET_PRINT_OPERAND_ADDRESS ix86_print_operand_address
51740 #undef TARGET_PRINT_OPERAND_PUNCT_VALID_P
51741 #define TARGET_PRINT_OPERAND_PUNCT_VALID_P ix86_print_operand_punct_valid_p
51742 #undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA
51743 #define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA i386_asm_output_addr_const_extra
51744
51745 #undef TARGET_SCHED_INIT_GLOBAL
51746 #define TARGET_SCHED_INIT_GLOBAL ix86_sched_init_global
51747 #undef TARGET_SCHED_ADJUST_COST
51748 #define TARGET_SCHED_ADJUST_COST ix86_adjust_cost
51749 #undef TARGET_SCHED_ISSUE_RATE
51750 #define TARGET_SCHED_ISSUE_RATE ix86_issue_rate
51751 #undef TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD
51752 #define TARGET_SCHED_FIRST_CYCLE_MULTIPASS_DFA_LOOKAHEAD \
51753   ia32_multipass_dfa_lookahead
51754 #undef TARGET_SCHED_MACRO_FUSION_P
51755 #define TARGET_SCHED_MACRO_FUSION_P ix86_macro_fusion_p
51756 #undef TARGET_SCHED_MACRO_FUSION_PAIR_P
51757 #define TARGET_SCHED_MACRO_FUSION_PAIR_P ix86_macro_fusion_pair_p
51758
51759 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
51760 #define TARGET_FUNCTION_OK_FOR_SIBCALL ix86_function_ok_for_sibcall
51761
51762 #undef TARGET_MEMMODEL_CHECK
51763 #define TARGET_MEMMODEL_CHECK ix86_memmodel_check
51764
51765 #undef TARGET_ATOMIC_ASSIGN_EXPAND_FENV
51766 #define TARGET_ATOMIC_ASSIGN_EXPAND_FENV ix86_atomic_assign_expand_fenv
51767
51768 #ifdef HAVE_AS_TLS
51769 #undef TARGET_HAVE_TLS
51770 #define TARGET_HAVE_TLS true
51771 #endif
51772 #undef TARGET_CANNOT_FORCE_CONST_MEM
51773 #define TARGET_CANNOT_FORCE_CONST_MEM ix86_cannot_force_const_mem
51774 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
51775 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
51776
51777 #undef TARGET_DELEGITIMIZE_ADDRESS
51778 #define TARGET_DELEGITIMIZE_ADDRESS ix86_delegitimize_address
51779
51780 #undef TARGET_MS_BITFIELD_LAYOUT_P
51781 #define TARGET_MS_BITFIELD_LAYOUT_P ix86_ms_bitfield_layout_p
51782
51783 #if TARGET_MACHO
51784 #undef TARGET_BINDS_LOCAL_P
51785 #define TARGET_BINDS_LOCAL_P darwin_binds_local_p
51786 #endif
51787 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
51788 #undef TARGET_BINDS_LOCAL_P
51789 #define TARGET_BINDS_LOCAL_P i386_pe_binds_local_p
51790 #endif
51791
51792 #undef TARGET_ASM_OUTPUT_MI_THUNK
51793 #define TARGET_ASM_OUTPUT_MI_THUNK x86_output_mi_thunk
51794 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
51795 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK x86_can_output_mi_thunk
51796
51797 #undef TARGET_ASM_FILE_START
51798 #define TARGET_ASM_FILE_START x86_file_start
51799
51800 #undef TARGET_OPTION_OVERRIDE
51801 #define TARGET_OPTION_OVERRIDE ix86_option_override
51802
51803 #undef TARGET_REGISTER_MOVE_COST
51804 #define TARGET_REGISTER_MOVE_COST ix86_register_move_cost
51805 #undef TARGET_MEMORY_MOVE_COST
51806 #define TARGET_MEMORY_MOVE_COST ix86_memory_move_cost
51807 #undef TARGET_RTX_COSTS
51808 #define TARGET_RTX_COSTS ix86_rtx_costs
51809 #undef TARGET_ADDRESS_COST
51810 #define TARGET_ADDRESS_COST ix86_address_cost
51811
51812 #undef TARGET_FIXED_CONDITION_CODE_REGS
51813 #define TARGET_FIXED_CONDITION_CODE_REGS ix86_fixed_condition_code_regs
51814 #undef TARGET_CC_MODES_COMPATIBLE
51815 #define TARGET_CC_MODES_COMPATIBLE ix86_cc_modes_compatible
51816
51817 #undef TARGET_MACHINE_DEPENDENT_REORG
51818 #define TARGET_MACHINE_DEPENDENT_REORG ix86_reorg
51819
51820 #undef TARGET_BUILTIN_SETJMP_FRAME_VALUE
51821 #define TARGET_BUILTIN_SETJMP_FRAME_VALUE ix86_builtin_setjmp_frame_value
51822
51823 #undef TARGET_BUILD_BUILTIN_VA_LIST
51824 #define TARGET_BUILD_BUILTIN_VA_LIST ix86_build_builtin_va_list
51825
51826 #undef TARGET_FOLD_BUILTIN
51827 #define TARGET_FOLD_BUILTIN ix86_fold_builtin
51828
51829 #undef TARGET_COMPARE_VERSION_PRIORITY
51830 #define TARGET_COMPARE_VERSION_PRIORITY ix86_compare_version_priority
51831
51832 #undef TARGET_GENERATE_VERSION_DISPATCHER_BODY
51833 #define TARGET_GENERATE_VERSION_DISPATCHER_BODY \
51834   ix86_generate_version_dispatcher_body
51835
51836 #undef TARGET_GET_FUNCTION_VERSIONS_DISPATCHER
51837 #define TARGET_GET_FUNCTION_VERSIONS_DISPATCHER \
51838   ix86_get_function_versions_dispatcher
51839
51840 #undef TARGET_ENUM_VA_LIST_P
51841 #define TARGET_ENUM_VA_LIST_P ix86_enum_va_list
51842
51843 #undef TARGET_FN_ABI_VA_LIST
51844 #define TARGET_FN_ABI_VA_LIST ix86_fn_abi_va_list
51845
51846 #undef TARGET_CANONICAL_VA_LIST_TYPE
51847 #define TARGET_CANONICAL_VA_LIST_TYPE ix86_canonical_va_list_type
51848
51849 #undef TARGET_EXPAND_BUILTIN_VA_START
51850 #define TARGET_EXPAND_BUILTIN_VA_START ix86_va_start
51851
51852 #undef TARGET_MD_ASM_CLOBBERS
51853 #define TARGET_MD_ASM_CLOBBERS ix86_md_asm_clobbers
51854
51855 #undef TARGET_PROMOTE_PROTOTYPES
51856 #define TARGET_PROMOTE_PROTOTYPES hook_bool_const_tree_true
51857 #undef TARGET_SETUP_INCOMING_VARARGS
51858 #define TARGET_SETUP_INCOMING_VARARGS ix86_setup_incoming_varargs
51859 #undef TARGET_MUST_PASS_IN_STACK
51860 #define TARGET_MUST_PASS_IN_STACK ix86_must_pass_in_stack
51861 #undef TARGET_FUNCTION_ARG_ADVANCE
51862 #define TARGET_FUNCTION_ARG_ADVANCE ix86_function_arg_advance
51863 #undef TARGET_FUNCTION_ARG
51864 #define TARGET_FUNCTION_ARG ix86_function_arg
51865 #undef TARGET_INIT_PIC_REG
51866 #define TARGET_INIT_PIC_REG ix86_init_pic_reg
51867 #undef TARGET_USE_PSEUDO_PIC_REG
51868 #define TARGET_USE_PSEUDO_PIC_REG ix86_use_pseudo_pic_reg
51869 #undef TARGET_FUNCTION_ARG_BOUNDARY
51870 #define TARGET_FUNCTION_ARG_BOUNDARY ix86_function_arg_boundary
51871 #undef TARGET_PASS_BY_REFERENCE
51872 #define TARGET_PASS_BY_REFERENCE ix86_pass_by_reference
51873 #undef TARGET_INTERNAL_ARG_POINTER
51874 #define TARGET_INTERNAL_ARG_POINTER ix86_internal_arg_pointer
51875 #undef TARGET_UPDATE_STACK_BOUNDARY
51876 #define TARGET_UPDATE_STACK_BOUNDARY ix86_update_stack_boundary
51877 #undef TARGET_GET_DRAP_RTX
51878 #define TARGET_GET_DRAP_RTX ix86_get_drap_rtx
51879 #undef TARGET_STRICT_ARGUMENT_NAMING
51880 #define TARGET_STRICT_ARGUMENT_NAMING hook_bool_CUMULATIVE_ARGS_true
51881 #undef TARGET_STATIC_CHAIN
51882 #define TARGET_STATIC_CHAIN ix86_static_chain
51883 #undef TARGET_TRAMPOLINE_INIT
51884 #define TARGET_TRAMPOLINE_INIT ix86_trampoline_init
51885 #undef TARGET_RETURN_POPS_ARGS
51886 #define TARGET_RETURN_POPS_ARGS ix86_return_pops_args
51887
51888 #undef TARGET_LEGITIMATE_COMBINED_INSN
51889 #define TARGET_LEGITIMATE_COMBINED_INSN ix86_legitimate_combined_insn
51890
51891 #undef TARGET_ASAN_SHADOW_OFFSET
51892 #define TARGET_ASAN_SHADOW_OFFSET ix86_asan_shadow_offset
51893
51894 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
51895 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg
51896
51897 #undef TARGET_SCALAR_MODE_SUPPORTED_P
51898 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p
51899
51900 #undef TARGET_VECTOR_MODE_SUPPORTED_P
51901 #define TARGET_VECTOR_MODE_SUPPORTED_P ix86_vector_mode_supported_p
51902
51903 #undef TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P
51904 #define TARGET_LIBGCC_FLOATING_MODE_SUPPORTED_P \
51905   ix86_libgcc_floating_mode_supported_p
51906
51907 #undef TARGET_C_MODE_FOR_SUFFIX
51908 #define TARGET_C_MODE_FOR_SUFFIX ix86_c_mode_for_suffix
51909
51910 #ifdef HAVE_AS_TLS
51911 #undef TARGET_ASM_OUTPUT_DWARF_DTPREL
51912 #define TARGET_ASM_OUTPUT_DWARF_DTPREL i386_output_dwarf_dtprel
51913 #endif
51914
51915 #ifdef SUBTARGET_INSERT_ATTRIBUTES
51916 #undef TARGET_INSERT_ATTRIBUTES
51917 #define TARGET_INSERT_ATTRIBUTES SUBTARGET_INSERT_ATTRIBUTES
51918 #endif
51919
51920 #undef TARGET_MANGLE_TYPE
51921 #define TARGET_MANGLE_TYPE ix86_mangle_type
51922
51923 #if !TARGET_MACHO
51924 #undef TARGET_STACK_PROTECT_FAIL
51925 #define TARGET_STACK_PROTECT_FAIL ix86_stack_protect_fail
51926 #endif
51927
51928 #undef TARGET_FUNCTION_VALUE
51929 #define TARGET_FUNCTION_VALUE ix86_function_value
51930
51931 #undef TARGET_FUNCTION_VALUE_REGNO_P
51932 #define TARGET_FUNCTION_VALUE_REGNO_P ix86_function_value_regno_p
51933
51934 #undef TARGET_PROMOTE_FUNCTION_MODE
51935 #define TARGET_PROMOTE_FUNCTION_MODE ix86_promote_function_mode
51936
51937 #undef TARGET_MEMBER_TYPE_FORCES_BLK
51938 #define TARGET_MEMBER_TYPE_FORCES_BLK ix86_member_type_forces_blk
51939
51940 #undef TARGET_INSTANTIATE_DECLS
51941 #define TARGET_INSTANTIATE_DECLS ix86_instantiate_decls
51942
51943 #undef TARGET_SECONDARY_RELOAD
51944 #define TARGET_SECONDARY_RELOAD ix86_secondary_reload
51945
51946 #undef TARGET_CLASS_MAX_NREGS
51947 #define TARGET_CLASS_MAX_NREGS ix86_class_max_nregs
51948
51949 #undef TARGET_PREFERRED_RELOAD_CLASS
51950 #define TARGET_PREFERRED_RELOAD_CLASS ix86_preferred_reload_class
51951 #undef TARGET_PREFERRED_OUTPUT_RELOAD_CLASS
51952 #define TARGET_PREFERRED_OUTPUT_RELOAD_CLASS ix86_preferred_output_reload_class
51953 #undef TARGET_CLASS_LIKELY_SPILLED_P
51954 #define TARGET_CLASS_LIKELY_SPILLED_P ix86_class_likely_spilled_p
51955
51956 #undef TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST
51957 #define TARGET_VECTORIZE_BUILTIN_VECTORIZATION_COST \
51958   ix86_builtin_vectorization_cost
51959 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
51960 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK \
51961   ix86_vectorize_vec_perm_const_ok
51962 #undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
51963 #define TARGET_VECTORIZE_PREFERRED_SIMD_MODE \
51964   ix86_preferred_simd_mode
51965 #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
51966 #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
51967   ix86_autovectorize_vector_sizes
51968 #undef TARGET_VECTORIZE_INIT_COST
51969 #define TARGET_VECTORIZE_INIT_COST ix86_init_cost
51970 #undef TARGET_VECTORIZE_ADD_STMT_COST
51971 #define TARGET_VECTORIZE_ADD_STMT_COST ix86_add_stmt_cost
51972 #undef TARGET_VECTORIZE_FINISH_COST
51973 #define TARGET_VECTORIZE_FINISH_COST ix86_finish_cost
51974 #undef TARGET_VECTORIZE_DESTROY_COST_DATA
51975 #define TARGET_VECTORIZE_DESTROY_COST_DATA ix86_destroy_cost_data
51976
51977 #undef TARGET_SET_CURRENT_FUNCTION
51978 #define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
51979
51980 #undef TARGET_OPTION_VALID_ATTRIBUTE_P
51981 #define TARGET_OPTION_VALID_ATTRIBUTE_P ix86_valid_target_attribute_p
51982
51983 #undef TARGET_OPTION_SAVE
51984 #define TARGET_OPTION_SAVE ix86_function_specific_save
51985
51986 #undef TARGET_OPTION_RESTORE
51987 #define TARGET_OPTION_RESTORE ix86_function_specific_restore
51988
51989 #undef TARGET_OPTION_PRINT
51990 #define TARGET_OPTION_PRINT ix86_function_specific_print
51991
51992 #undef TARGET_OPTION_FUNCTION_VERSIONS
51993 #define TARGET_OPTION_FUNCTION_VERSIONS ix86_function_versions
51994
51995 #undef TARGET_CAN_INLINE_P
51996 #define TARGET_CAN_INLINE_P ix86_can_inline_p
51997
51998 #undef TARGET_EXPAND_TO_RTL_HOOK
51999 #define TARGET_EXPAND_TO_RTL_HOOK ix86_maybe_switch_abi
52000
52001 #undef TARGET_LEGITIMATE_ADDRESS_P
52002 #define TARGET_LEGITIMATE_ADDRESS_P ix86_legitimate_address_p
52003
52004 #undef TARGET_LRA_P
52005 #define TARGET_LRA_P hook_bool_void_true
52006
52007 #undef TARGET_REGISTER_PRIORITY
52008 #define TARGET_REGISTER_PRIORITY ix86_register_priority
52009
52010 #undef TARGET_REGISTER_USAGE_LEVELING_P
52011 #define TARGET_REGISTER_USAGE_LEVELING_P hook_bool_void_true
52012
52013 #undef TARGET_LEGITIMATE_CONSTANT_P
52014 #define TARGET_LEGITIMATE_CONSTANT_P ix86_legitimate_constant_p
52015
52016 #undef TARGET_FRAME_POINTER_REQUIRED
52017 #define TARGET_FRAME_POINTER_REQUIRED ix86_frame_pointer_required
52018
52019 #undef TARGET_CAN_ELIMINATE
52020 #define TARGET_CAN_ELIMINATE ix86_can_eliminate
52021
52022 #undef TARGET_EXTRA_LIVE_ON_ENTRY
52023 #define TARGET_EXTRA_LIVE_ON_ENTRY ix86_live_on_entry
52024
52025 #undef TARGET_ASM_CODE_END
52026 #define TARGET_ASM_CODE_END ix86_code_end
52027
52028 #undef TARGET_CONDITIONAL_REGISTER_USAGE
52029 #define TARGET_CONDITIONAL_REGISTER_USAGE ix86_conditional_register_usage
52030
52031 #if TARGET_MACHO
52032 #undef TARGET_INIT_LIBFUNCS
52033 #define TARGET_INIT_LIBFUNCS darwin_rename_builtins
52034 #endif
52035
52036 #undef TARGET_LOOP_UNROLL_ADJUST
52037 #define TARGET_LOOP_UNROLL_ADJUST ix86_loop_unroll_adjust
52038
52039 #undef TARGET_SPILL_CLASS
52040 #define TARGET_SPILL_CLASS ix86_spill_class
52041
52042 #undef TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN
52043 #define TARGET_SIMD_CLONE_COMPUTE_VECSIZE_AND_SIMDLEN \
52044   ix86_simd_clone_compute_vecsize_and_simdlen
52045
52046 #undef TARGET_SIMD_CLONE_ADJUST
52047 #define TARGET_SIMD_CLONE_ADJUST \
52048   ix86_simd_clone_adjust
52049
52050 #undef TARGET_SIMD_CLONE_USABLE
52051 #define TARGET_SIMD_CLONE_USABLE \
52052   ix86_simd_clone_usable
52053
52054 #undef TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P
52055 #define TARGET_FLOAT_EXCEPTIONS_ROUNDING_SUPPORTED_P \
52056   ix86_float_exceptions_rounding_supported_p
52057
52058 #undef TARGET_MODE_EMIT
52059 #define TARGET_MODE_EMIT ix86_emit_mode_set
52060
52061 #undef TARGET_MODE_NEEDED
52062 #define TARGET_MODE_NEEDED ix86_mode_needed
52063
52064 #undef TARGET_MODE_AFTER
52065 #define TARGET_MODE_AFTER ix86_mode_after
52066
52067 #undef TARGET_MODE_ENTRY
52068 #define TARGET_MODE_ENTRY ix86_mode_entry
52069
52070 #undef TARGET_MODE_EXIT
52071 #define TARGET_MODE_EXIT ix86_mode_exit
52072
52073 #undef TARGET_MODE_PRIORITY
52074 #define TARGET_MODE_PRIORITY ix86_mode_priority
52075
52076 #undef TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS
52077 #define TARGET_CALL_FUSAGE_CONTAINS_NON_CALLEE_CLOBBERS true
52078
52079 #undef TARGET_LOAD_BOUNDS_FOR_ARG
52080 #define TARGET_LOAD_BOUNDS_FOR_ARG ix86_load_bounds
52081
52082 #undef TARGET_STORE_BOUNDS_FOR_ARG
52083 #define TARGET_STORE_BOUNDS_FOR_ARG ix86_store_bounds
52084
52085 #undef TARGET_LOAD_RETURNED_BOUNDS
52086 #define TARGET_LOAD_RETURNED_BOUNDS ix86_load_returned_bounds
52087
52088 #undef TARGET_STORE_RETURNED_BOUNDS
52089 #define TARGET_STORE_RETURNED_BOUNDS ix86_store_returned_bounds
52090
52091 #undef TARGET_CHKP_BOUND_MODE
52092 #define TARGET_CHKP_BOUND_MODE ix86_mpx_bound_mode
52093
52094 #undef TARGET_BUILTIN_CHKP_FUNCTION
52095 #define TARGET_BUILTIN_CHKP_FUNCTION ix86_builtin_mpx_function
52096
52097 #undef TARGET_CHKP_FUNCTION_VALUE_BOUNDS
52098 #define TARGET_CHKP_FUNCTION_VALUE_BOUNDS ix86_function_value_bounds
52099
52100 #undef TARGET_CHKP_MAKE_BOUNDS_CONSTANT
52101 #define TARGET_CHKP_MAKE_BOUNDS_CONSTANT ix86_make_bounds_constant
52102
52103 #undef TARGET_CHKP_INITIALIZE_BOUNDS
52104 #define TARGET_CHKP_INITIALIZE_BOUNDS ix86_initialize_bounds
52105
52106 #undef TARGET_SETUP_INCOMING_VARARG_BOUNDS
52107 #define TARGET_SETUP_INCOMING_VARARG_BOUNDS ix86_setup_incoming_vararg_bounds
52108
52109 #undef TARGET_OFFLOAD_OPTIONS
52110 #define TARGET_OFFLOAD_OPTIONS \
52111   ix86_offload_options
52112
52113 struct gcc_target targetm = TARGET_INITIALIZER;
52114 \f
52115 #include "gt-i386.h"